Skip to content

Commit

Permalink
Fix test skipping (#1118)
Browse files Browse the repository at this point in the history
**Issue:**

The SKIP code worked in `aws-crt-cpp`'s tests, but not in any `aws-c-*` tests

**Description of changes:**

- Set SKIP_RETURN_CODE in CMake script that generates C test runner (the CPP script had it, but not the C script)
- Skip leak checks when a test is skipped
    - this keeps the tests simple, you can bail out in the middle without cleaning up
  • Loading branch information
graebm authored May 30, 2024
1 parent ce899b9 commit dae0e52
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 21 deletions.
1 change: 1 addition & 0 deletions cmake/AwsTestHarness.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ function(generate_test_driver driver_exe_name)

foreach(name IN LISTS TEST_CASES)
add_test(${name} ${driver_exe_name} "${name}")
set_tests_properties("${name}" PROPERTIES SKIP_RETURN_CODE ${SKIP_RETURN_CODE_VALUE})
endforeach()

# Clear test cases in case another driver needs to be generated
Expand Down
28 changes: 8 additions & 20 deletions include/aws/testing/aws_test_harness.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,6 @@ static int s_cunit_failure_message0(
* that may be returned from various tools (e.g. sanitizer). */
#define SKIP (103)

#define POSTSKIP_INTERNAL() \
do { \
return SKIP; \
} while (0)

#define RETURN_SKIP(format, ...) \
do { \
printf(format, ##__VA_ARGS__); \
printf("\n"); \
POSTSKIP_INTERNAL(); \
} while (0)

#define RETURN_SUCCESS(format, ...) \
do { \
printf(format, ##__VA_ARGS__); \
Expand Down Expand Up @@ -468,7 +456,7 @@ static inline int s_aws_run_test_case(struct aws_test_harness *harness) {
test_res |= harness->on_after(allocator, setup_res, harness->ctx);
}

if (test_res != AWS_OP_SUCCESS && test_res != AWS_OP_SKIP) {
if (test_res != AWS_OP_SUCCESS) {
goto fail;
}

Expand All @@ -492,21 +480,21 @@ static inline int s_aws_run_test_case(struct aws_test_harness *harness) {
aws_logger_set(NULL);
aws_logger_clean_up(&err_logger);

if (test_res == AWS_OP_SUCCESS) {
RETURN_SUCCESS("%s [ \033[32mOK\033[0m ]", harness->test_name);
} else if (test_res == AWS_OP_SKIP) {
RETURN_SKIP("%s [ \033[32mSKIP\033[0m ]", harness->test_name);
}
RETURN_SUCCESS("%s [ \033[32mOK\033[0m ]", harness->test_name);

fail:
PRINT_FAIL_WITHOUT_LOCATION("%s [ \033[31mFAILED\033[0m ]", harness->test_name);
if (test_res == AWS_OP_SKIP) {
fprintf(AWS_TESTING_REPORT_FD, "%s [ \033[32mSKIP\033[0m ]\n", harness->test_name);
} else {
PRINT_FAIL_WITHOUT_LOCATION("%s [ \033[31mFAILED\033[0m ]", harness->test_name);
}
/* Use _Exit() to terminate without cleaning up resources.
* This prevents LeakSanitizer spam (yes, we know failing tests don't bother cleaning up).
* It also prevents errors where threads that haven't cleaned are still using the logger declared in this fn. */
fflush(AWS_TESTING_REPORT_FD);
fflush(stdout);
fflush(stderr);
_Exit(FAILURE);
_Exit(test_res == AWS_OP_SKIP ? SKIP : FAILURE);
}

/* Enables terminal escape sequences for text coloring on Windows. */
Expand Down
2 changes: 1 addition & 1 deletion tests/thread_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ static int s_test_managed_thread_join_timeout(struct aws_allocator *allocator, v
/*
* Increase the timeout and shut down
*/
aws_thread_set_managed_join_timeout_ns(aws_timestamp_convert(5, AWS_TIMESTAMP_SECS, AWS_TIMESTAMP_NANOS, NULL));
aws_thread_set_managed_join_timeout_ns(aws_timestamp_convert(10, AWS_TIMESTAMP_SECS, AWS_TIMESTAMP_NANOS, NULL));

aws_common_library_clean_up();

Expand Down

0 comments on commit dae0e52

Please sign in to comment.