New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Buildbot embedded unittests #2755
Buildbot embedded unittests #2755
Conversation
+ add unittest clean artifacts target to Makefile
+ null ptr, empty string, verylong string, non-ascii buffer + modify makefile to compile uts against local libgpac not the one installed + add code to gf_sys_word_match() to handle null arguments
66dc9ca
to
977cce3
Compare
include/tests.h
Outdated
((expr) \ | ||
? gf_fatal_assert(0) \ | ||
: printf("Assertion failed: %s\nMessage: %s\n\tFile: %s\nLine: %d\nFunction: %s\n", #expr, msg, __FILE__, __LINE__, __ASSERT_FUNCTION)); \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In both scenarios, an assertion failure occurs. Within the if
statement, checks_passed
is incremented, but it results in a call to gf_fatal_assert
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I propose to remove all the elements in that section that are unused. @soheibthriber Let me know if you disagree.
include/tests.h
Outdated
((expr) \ | ||
? gf_fatal_assert(0) \ | ||
: (action, gf_fatal_assert(0))); \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here. in both cases, gf_fatal_assert
is called.
include/tests.h
Outdated
checks_passed++; \ | ||
} else { \ | ||
checks_failed++; \ | ||
gf_assert(0); \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any reason for alternating between gf_assert
and gf_fatal_assert
at times, given their similarity?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No but using similar names is confusing, for sure :/
include/tests.h
Outdated
#define assert_equal_str(str1, str2) \ | ||
do { \ | ||
if (!strcmp(str1, str2)) { \ | ||
if (verbose_ut) printf("Assertion passed: Value: (%s, %s), File: %s, Line: %d, Function: %s\n", #str1, #str2, __FILE__, __LINE__, __ASSERT_FUNCTION); \ | ||
checks_passed++; \ | ||
} else { \ | ||
checks_failed++; \ | ||
gf_assert(0); \ | ||
} \ | ||
} while (0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this be rewritten as follows?
#define assert_equal_str(str1, str2) \ | |
do { \ | |
if (!strcmp(str1, str2)) { \ | |
if (verbose_ut) printf("Assertion passed: Value: (%s, %s), File: %s, Line: %d, Function: %s\n", #str1, #str2, __FILE__, __LINE__, __ASSERT_FUNCTION); \ | |
checks_passed++; \ | |
} else { \ | |
checks_failed++; \ | |
gf_assert(0); \ | |
} \ | |
} while (0) | |
#define assert_equal_str(str1, str2) assert_false(strcmp(str1, str2)) |
include/tests.h
Outdated
} while (0) | ||
|
||
#define assert_false(expr) assert_true(!(expr)) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other macros could be added. Here are some suggestions:
#define assert_not_equal_str(str1, str2) assert_true(strcmp((str1), (str2))) | |
#define assert_equal(a, b) assert_true((a) == (b)) | |
#define assert_greater(a, b) assert_true((a) > (b)) | |
#define assert_greater_equal(a, b) assert_true((a) >= (b)) | |
#define assert_less(a, b) assert_true((a) < (b)) | |
#define assert_less_equal(a, b) assert_true((a) <= (b)) | |
#define assert_not_null(ptr) assert_true((ptr) != NULL) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like them.
-
Maybe I would put them in MAJ to make it clear this belongs to the UT framework (and not GPAC in general).
-
Also we could limit to ASSERT() and ASSERT_STR_EQ() I guess. Opinion?
unittests/README
Outdated
@@ -0,0 +1,30 @@ | |||
# Unit tests in GPAC |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please consider adding the .md
extension to the README
file to ensure it is recognized as a markdown file. This will improve readability and enable markdown rendering on platforms that support it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do, thanks!
include/tests.h
Outdated
checks_passed++; \ | ||
} else { \ | ||
checks_failed++; \ | ||
gf_assert(0); \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
currently if a test fails the whole testing is aborted because of the assert:
unittests: ut_os_config_init.c:36: test_gf_sys_word_match: Assertion `0' failed.
Aborted (core dumped)
and you don't get the summary with the number of tests passed/failed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's right, it is a design choice. Usually unit tests are executed at every build. So this is kind of some incremental approach. However we could add the option for failure to be non-fatal. Adding this in a7d736d.
include/tests.h
Outdated
checks_failed++; \ | ||
} \ | ||
((expr) \ | ||
? gf_fatal_assert(0) \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we assert(0) is the expr is true here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
outdated comment
extern int checks_passed; | ||
extern int checks_failed; | ||
|
||
static Bool verbose_ut = GF_FALSE; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a way to set this to true via compile flags / configure?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do. What option do you envision? At the moment we just have --unittests
.
unittests/build.sh
Outdated
int main(int argc, char *argv[]) | ||
{' | ||
|
||
calls=$(find "$scriptDir/.." -path "*/unittests/*.c" | grep -v bin | xargs grep unittest | cut -d ":" -f 2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since scriptDir contains "unittests" and -path checks the whole path, this will match every .c file (also maybe add a -type f to exclude directories)
maybe grep -v bin may exclude a bit too much stuff (maybe grep -v '/bin/' or use exclude features from find?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like readlink and realpath are non portable. I just put a 'cd' before 'find' in a8e7ddb.
@@ -2167,6 +2171,8 @@ if test $cpu = "mips"; then | |||
fi | |||
echo "" | |||
echo "** GPAC $version rev$revision Core Configuration **" | |||
echo "Unit Tests: $unit_tests ('make unit_tests')" | |||
echo "#define GF_STATIC static" >> $TMPH |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should also be defined in configuration.h (or setup.h?) for platforms that don't use configure/config.h ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added in 672f666. Should we also add a target in the msvc Solution ? xcode ? What's the usual way to add this?
Note from today's call:
|
Possible additional discussed tests:
|
it seems ok on the https://github.com/gpac/gpac/tree/buildbot-embedded-unittests branch since it's a different branch than the one in this PR, maybe create a new PR for the new branch with a reference to this PR so that we don't lose the discussion? (or you can just merge the main repo branch directly if you prefer) |
Both branches are now aligned. @jeanlf Please merge if ok for you! |
No description provided.