Skip to content
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

Merged
merged 21 commits into from May 6, 2024

Conversation

rbouqueau
Copy link
Member

No description provided.

@rbouqueau rbouqueau force-pushed the buildbot-embedded-unittests branch from 66dc9ca to 977cce3 Compare March 1, 2024 13:13
@rbouqueau rbouqueau marked this pull request as ready for review March 1, 2024 13:16
include/tests.h Outdated
Comment on lines 21 to 23
((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)); \
Copy link
Contributor

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.

Copy link
Member Author

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
Comment on lines 33 to 35
((expr) \
? gf_fatal_assert(0) \
: (action, gf_fatal_assert(0))); \
Copy link
Contributor

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); \
Copy link
Contributor

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?

Copy link
Member Author

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
Comment on lines 51 to 60
#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)
Copy link
Contributor

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?

Suggested change
#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))

Copy link
Contributor

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:

Suggested change
#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)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like them.

  1. Maybe I would put them in MAJ to make it clear this belongs to the UT framework (and not GPAC in general).

  2. Also we could limit to ASSERT() and ASSERT_STR_EQ() I guess. Opinion?

unittests/README Outdated
@@ -0,0 +1,30 @@
# Unit tests in GPAC
Copy link
Contributor

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.

Copy link
Member Author

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); \
Copy link
Member

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

Copy link
Member Author

@rbouqueau rbouqueau Mar 19, 2024

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) \
Copy link
Member

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?

Copy link
Member Author

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;
Copy link
Member

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?

Copy link
Member Author

@rbouqueau rbouqueau Mar 19, 2024

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.

int main(int argc, char *argv[])
{'

calls=$(find "$scriptDir/.." -path "*/unittests/*.c" | grep -v bin | xargs grep unittest | cut -d ":" -f 2)
Copy link
Member

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?)

Copy link
Member Author

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
Copy link
Member

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 ?

Copy link
Member Author

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?

@rbouqueau
Copy link
Member Author

rbouqueau commented Mar 25, 2024

Note from today's call:

  • This is ok as a first UT runtime. Existing unittests can run on any runtime anyway.
  • @aureliendavid to have a look at how to get rid of the double build.
  • Remarks that UTs should not leverage the configure script but a compile-time define (with -D) instead or with var env (as asan does).
  • These defines could also allow to get rid of the static variables.
  • Failing with if (fatal_ut) gf_assert(0); doesn't display the report when failing.

@rbouqueau
Copy link
Member Author

Possible additional discussed tests:

  • gpac -h dash doesn't return dasher.
  • 48e6376

@rbouqueau
Copy link
Member Author

@aureliendavid
Copy link
Member

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)

@rbouqueau
Copy link
Member Author

Both branches are now aligned. @jeanlf Please merge if ok for you!

@jeanlf jeanlf merged commit b7c020d into gpac:master May 6, 2024
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants