You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
How can I pass a runtime determined state from the main test process to the forked worker?
#include<stdio.h>#include"criterion/criterion.h"staticchar*STATE=NULL;
voidload_state() {
// STATE is (null) herecriterion_current_test->data->data=STATE;
}
Test(s, t, .init=load_state) {
// criterion_current_test->data->data is (nil)
}
intmain(intargc, char*argv[]) {
char*state="foobar"; // some runtime stateSTATE=state;
fprintf(stderr, "STATE %p\n", STATE);
structcriterion_test_set*tests=criterion_initialize();
if (!criterion_handle_args(argc, argv, false)) {
returnEXIT_FAILURE;
}
criterion_run_all_tests(tests);
criterion_finalize(tests);
returnEXIT_SUCCESS;
}
I understand using malloc is UB. However using cr_malloc requires cr_init to have been called already and that does not happen until the tests begin to run. cr_init is not idempotent, so invoking it in main manually before the tests begin would simply create a new arena again.
Here, state could be a random seed passed from the command line to the individual tests.
The text was updated successfully, but these errors were encountered:
How can I pass a runtime determined state from the main test process to the forked worker?
I understand using malloc is UB. However using
cr_malloc
requirescr_init
to have been called already and that does not happen until the tests begin to run.cr_init
is not idempotent, so invoking it inmain
manually before the tests begin would simply create a new arena again.Here,
state
could be a random seed passed from the command line to the individual tests.The text was updated successfully, but these errors were encountered: