in include/aws/testing/aws_test_harness.h [378:456]
static inline int s_aws_run_test_case(struct aws_test_harness *harness) {
AWS_ASSERT(harness->run);
#if defined(_WIN32)
SetUnhandledExceptionFilter(s_test_print_stack_trace);
/* Set working directory to path to this exe */
char cwd[512];
DWORD len = GetModuleFileNameA(NULL, cwd, sizeof(cwd));
DWORD idx = len - 1;
while (idx && cwd[idx] != '\\') {
idx--;
}
cwd[idx] = 0;
SetCurrentDirectory(cwd);
#elif defined(AWS_HAVE_EXECINFO)
struct sigaction sa;
memset(&sa, 0, sizeof(struct sigaction));
sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_NODEFER;
sa.sa_sigaction = s_print_stack_trace;
sigaction(SIGSEGV, &sa, NULL);
#endif
/* track allocations and report leaks in tests, unless suppressed */
struct aws_allocator *allocator = NULL;
if (harness->suppress_memcheck) {
allocator = aws_default_allocator();
} else {
allocator = aws_mem_tracer_new(aws_default_allocator(), NULL, AWS_MEMTRACE_STACKS, 8);
}
/* wire up a logger to stderr by default, may be replaced by some tests */
struct aws_logger err_logger;
struct aws_logger_standard_options options;
options.file = AWS_TESTING_REPORT_FD;
options.level = AWS_LL_TRACE;
options.filename = NULL;
aws_logger_init_standard(&err_logger, aws_default_allocator(), &options);
aws_logger_set(&err_logger);
int test_res = AWS_OP_ERR;
int setup_res = AWS_OP_SUCCESS;
if (harness->on_before) {
setup_res = harness->on_before(allocator, harness->ctx);
}
if (!setup_res) {
test_res = harness->run(allocator, harness->ctx);
}
if (harness->on_after) {
test_res |= harness->on_after(allocator, setup_res, harness->ctx);
}
if (!test_res) {
if (!harness->suppress_memcheck) {
const size_t leaked_bytes = aws_mem_tracer_count(allocator);
if (leaked_bytes) {
aws_mem_tracer_dump(allocator);
}
ASSERT_UINT_EQUALS(0, aws_mem_tracer_count(allocator));
}
}
/* clean up */
if (!harness->suppress_memcheck) {
aws_mem_tracer_destroy(allocator);
}
aws_logger_set(NULL);
aws_logger_clean_up(&err_logger);
if (!test_res) {
RETURN_SUCCESS("%s [ \033[32mOK\033[0m ]", harness->test_name);
} else {
FAIL("%s [ \033[31mFAILED\033[0m ]", harness->test_name);
}
}