Trying to Use Criterion with My Main Function #526
Replies: 4 comments 6 replies
-
|
Bumping the discussion so that someone might see it and reply. |
Beta Was this translation helpful? Give feedback.
-
|
Can you try to minimize your example down to something that happens to break? It definitely works for me if I compile the sample main. $ cat main.c
#include <stdio.h>
#include <criterion/criterion.h>
/* This is necessary on windows, as BoxFort needs the main to be exported
in order to find it. */
#if defined (_WIN32) || defined (__CYGWIN__)
# if defined (_MSC_VER)
# define DLLEXPORT __declspec(dllexport)
# elif defined (__GNUC__)
# define DLLEXPORT __attribute__((dllexport))
# else
# error No dllexport attribute
# endif
#else
# define DLLEXPORT
#endif
DLLEXPORT int main(int argc, char *argv[]) {
printf("Hello, World!\n");
struct criterion_test_set *tests = criterion_initialize();
int result = 0;
if (criterion_handle_args(argc, argv, true))
result = !criterion_run_all_tests(tests);
criterion_finalize(tests);
return result;
}
$ gcc -o test ./main.c -lcriterion
$ ./test
Hello, World!
[====] Synthesis: Tested: 0 | Passing: 0 | Failing: 0 | Crashing: 0 |
Beta Was this translation helpful? Give feedback.
-
Sure! Here is a much smaller code base that consistently breaks: main.c Michaels_Criterion_tests.c makefile Terminal Output: Oddly, I see "Hello, World! :)" printed twice to the terminal. |
Beta Was this translation helpful? Give feedback.
-
Assuming by LTO you mean Link Time Optimization, disabling LTO does not seem to have an effect. I used this link and Terminal Output: Did I go about disabling LTO correctly? If not, how should I disable LTO? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello All,
I am trying to use Criterion with my main function. To begin with, I can successfully run Criterion tests on my Ubuntu machine when I do not declare my own main function and instead use Criterion’s. However, I have reached the point where I would like to use my own main function and then call Criterion’s tests.
The documentation helpfully provides an example main to show how to accomplish this (https://criterion.readthedocs.io/en/master/internal.html#example-main). However, Criterion ends up throwing some pretty catastrophic errors before core dumping when I use it in conjunction with my set of Criterion tests (this last part is important). When I compile and run my code without the file where I have all my Criterion tests defined (
Michaels_Criterion_tests.c) while using my ownmain.ceverything is perfectly happy (Criterion will report zero tests run, zero tests passed, and zero tests failed --- this makes sense, I did not give it any test functions). When I compile and run my code withoutmain.c(and use Criterion’s default behavior), my eight Criterion tests will run, correctly producing four passing and four failing tests. Oddly, it is when I compile and run my code with bothmain.candMichaels_Criterion_tests.cwhere Criterion throws catastrophic errors before core dumping. See output:The core file does not seem to actually get created either.
When I am using my own main function, do I need to format the Criterion test file (
Michaels_Criterion_tests.c) differently then when I let Criterion use its own main function? Something else?Below is all the code that I am using:
makefile:
main.c:
fibonacci.c
fibonacci.h
Michaels_Criterion_tests.c
Michaels_Criterion_tests.h
Beta Was this translation helpful? Give feedback.
All reactions