-
Notifications
You must be signed in to change notification settings - Fork 254
tests/unit/: Small improvements #1383
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
Conversation
infinisil
left a comment
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 can confirm that this works under Nix, thank you!
Hmmmmmm, then I suspect it was due to inlining vasprintf(3). It was probably being inlined, and thus our interposition didn't work, so we couldn't make it fail in the test. Thanks! |
|
I've added Reported-by and Tested-by tags for you, @infinisil . |
|
I see many changes that are unrelated to the fix itself. Since you already know what's the exact fix, can you provide just that thing in a PR? |
The fix is the third commit (the commit that has the The fourth commit was unnecessary. I only added it because debugging this PR was painful, as there are many warnings in the tests, which made it difficult to find the actual errors. I could remove the 1st and 4th commits, if you want. |
|
Can you update the first commit message with an example of a more useful test result? |
Yup. I had never run cmocka manually, as it seemed complex, but your message prompted me to do so. Here it is, for posterity: alx@devuan:~/tmp$ cat cmocka.c
#include <string.h>
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <stdint.h>
#include <cmocka.h>
#define streq(a,b) (!strcmp(a,b))
static void a(void **)
{
const char *s = "foo";
assert_true(streq(s, "bar"));
}
static void b(void **)
{
const char *s = "foo";
assert_string_equal(s, "bar");
}
int
main(void)
{
const struct CMUnitTest tests[] = {
cmocka_unit_test(a),
cmocka_unit_test(b),
};
return cmocka_run_group_tests(tests, NULL, NULL);
}alx@devuan:~/tmp$ gcc cmocka.c -lcmocka
alx@devuan:~/tmp$ ./a.out
[==========] tests: Running 2 test(s).
[ RUN ] a
[ ERROR ] --- streq(s, "bar")
[ LINE ] --- cmocka.c:15: error: Failure!
[ FAILED ] a
[ RUN ] b
[ ERROR ] --- "foo" != "bar"
[ LINE ] --- cmocka.c:22: error: Failure!
[ FAILED ] b
[==========] tests: 2 test(s) run.
[ PASSED ] 0 test(s).
[ FAILED ] tests: 2 test(s), listed below:
[ FAILED ] a
[ FAILED ] b
2 FAILED TEST(S)This will allow us to debug issues with cmocka without having to tun the test suite. For your question, see that in test I'll update the commit message with that. |
This produces more useful test results.
With assert_true(streq(...)), we only see the line of code that
triggered the failure, while assert_string_equal() shows the contents
of the strings. See the following example:
alx@devuan:~/tmp$ cat cmocka.c
#include <string.h>
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <stdint.h>
#include <cmocka.h>
#define streq(a,b) (!strcmp(a,b))
static void a(void **)
{
const char *s = "foo";
assert_true(streq(s, "bar"));
}
static void b(void **)
{
const char *s = "foo";
assert_string_equal(s, "bar");
}
int
main(void)
{
const struct CMUnitTest tests[] = {
cmocka_unit_test(a),
cmocka_unit_test(b),
};
return cmocka_run_group_tests(tests, NULL, NULL);
}
alx@devuan:~/tmp$ gcc cmocka.c -lcmocka
alx@devuan:~/tmp$ ./a.out
[==========] tests: Running 2 test(s).
[ RUN ] a
[ ERROR ] --- streq(s, "bar")
[ LINE ] --- cmocka.c:15: error: Failure!
[ FAILED ] a
[ RUN ] b
[ ERROR ] --- "foo" != "bar"
[ LINE ] --- cmocka.c:22: error: Failure!
[ FAILED ] b
[==========] tests: 2 test(s) run.
[ PASSED ] 0 test(s).
[ FAILED ] tests: 2 test(s), listed below:
[ FAILED ] a
[ FAILED ] b
2 FAILED TEST(S)
Tested-by: Silvan Mosberger <github@infinisil.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
This silences diagnostics about unused parameters. Tested-by: Silvan Mosberger <github@infinisil.com> Signed-off-by: Alejandro Colomar <alx@kernel.org>
Done. |
See also: #1382
Cc: @infinisil, @ikerexxe
@infinisil, would you mind testing if after this patch you still see an error in Nix?
Revisions:
v1b
v1c
v2
v2b
v2c