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

Add a way to skip a test #1012

Merged
merged 4 commits into from
Apr 14, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
5 changes: 5 additions & 0 deletions cmake/AwsTestHarness.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ option(ENABLE_NET_TESTS "Run tests requiring an internet connection." ON)
define_property(GLOBAL PROPERTY AWS_TEST_CASES BRIEF_DOCS "Test Cases" FULL_DOCS "Test Cases")
set(AWS_TEST_CASES "" CACHE INTERNAL "Test cases valid for this configuration")

# The return value for the skipped test cases. Refer to the return code defined in aws_test_harness.h:
# #define SKIP (1)
set(SKIP_RETURN_CODE_VALUE 1)

# Registers a test case by name (the first argument to the AWS_TEST_CASE macro in aws_test_harness.h)
macro(add_test_case name)
list(APPEND TEST_CASES "${name}")
Expand Down Expand Up @@ -87,6 +91,7 @@ function(generate_cpp_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})
xiazhvera marked this conversation as resolved.
Show resolved Hide resolved
endforeach()

# Clear test cases in case another driver needsto be generated
Expand Down
29 changes: 27 additions & 2 deletions include/aws/testing/aws_test_harness.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
#include <stdlib.h>
#include <string.h>

/**
* The return code for skipped tests. Use the return code if the test should be skipped.
*/
#define AWS_OP_SKIP (-2)

#ifndef AWS_UNSTABLE_TESTING_API
# error The AWS Test Fixture is designed only for use by AWS owned libraries for the AWS C99 SDK. You are welcome to use it, \
but you should be aware we make no promises on the stability of this API. To enable use of the aws test fixtures, set \
Expand Down Expand Up @@ -62,9 +67,24 @@ static int s_cunit_failure_message0(
s_cunit_failure_message0(FAIL_PREFIX, func, file, line, format, #__VA_ARGS__)

static int total_failures;
static int total_skip;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The value reserved to record the total skipped tests count. Current not in use.


#define SUCCESS (0)
#define FAILURE (-1)
#define SKIP (1)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The skip code returned to cmake has to be in range [0,255]. Refer to cmake doc: https://cmake.org/cmake/help/latest/prop_test/SKIP_RETURN_CODE.html


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

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

#define RETURN_SUCCESS(format, ...) \
do { \
Expand Down Expand Up @@ -434,7 +454,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) {
if (test_res != AWS_OP_SUCCESS && test_res != AWS_OP_SKIP) {
goto fail;
}

Expand All @@ -456,7 +476,12 @@ static inline int s_aws_run_test_case(struct aws_test_harness *harness) {
aws_logger_set(NULL);
aws_logger_clean_up(&err_logger);

RETURN_SUCCESS("%s [ \033[32mOK\033[0m ]", harness->test_name);
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);
}

fail:
FAIL("%s [ \033[31mFAILED\033[0m ]", harness->test_name);
}
Expand Down