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

Flesh out spoofed_criterion for AArch64 #373

Merged
merged 5 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions misc/spoofed_criterion/include/criterion/criterion.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

struct fake_criterion_test {
void (*test)(void);
void (*init)(void);
int exit_code;
};

Expand Down
3 changes: 2 additions & 1 deletion misc/spoofed_criterion/include/criterion/logging.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <stdio.h>
#include <criterion/new/assert.h>

#define cr_log_info printf
#define cr_log_info(f, ...) printf(f "\n", ##__VA_ARGS__)
#define cr_log_error(f, ...) fprintf(stderr, f "\n", ##__VA_ARGS__)
10 changes: 7 additions & 3 deletions misc/spoofed_criterion/include/criterion/new/assert.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#include <assert.h>

#define cr_assert assert
#define cr_assert_eq(a,b) cr_assert((a) == (b))
#define cr_assert_lt(a,b) cr_assert((a) < (b))
#define cr_fatal assert
#define cr_assert_eq(a, b) cr_assert((a) == (b))
#define cr_assert_lt(a, b) cr_assert((a) < (b))
#define cr_fatal(s) \
do { \
fprintf(stderr, s "\n"); \
exit(1); \
} while (0)
8 changes: 5 additions & 3 deletions misc/spoofed_criterion/test_runner.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ int main() {
pid_t pid = fork();
bool in_child = pid == 0;
if (in_child) {
if (test_info->init) {
(*test_info->init)();
}
(*test_info->test)();
return 0;
}
Expand All @@ -27,11 +30,10 @@ int main() {
return 2;
}
int exit_status = WEXITSTATUS(stat);
if (exit_status == test_info->exit_code) {
return 0;
} else {
if (exit_status != test_info->exit_code) {
fprintf(stderr, "forked test child exited with status %d, but %d was expected\n", exit_status, test_info->exit_code);
return 1;
}
}
return 0;
}