diff --git a/.astyleignore b/.astyleignore index ba97ee2e08b..391d0762774 100644 --- a/.astyleignore +++ b/.astyleignore @@ -26,10 +26,11 @@ ^rtos/source/TARGET_CORTEX/rtx4 ^rtos/source/TARGET_CORTEX/rtx5 ^targets +^TESTS/COMMON/unity ^TESTS/mbed_hal/trng/pithy ^TESTS/mbed_hal/trng/pithy ^tools ^UNITTESTS ^storage/blockdevice/tests/UNITTESTS ^storage/kvstore/tests/UNITTESTS -^drivers/tests/UNITTESTS \ No newline at end of file +^drivers/tests/UNITTESTS diff --git a/.travis.yml b/.travis.yml index d30e45d00e0..b58b96428c4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -278,8 +278,8 @@ matrix: - sed -n '/``` cpp/,/```/{/```$/Q;/```/d;p;}' ${EVENTS}/README.md > main.cpp - | rm -r rtos/source/TARGET_CORTEX drivers/source/usb connectivity/cellular connectivity/drivers/cellular \ - connectivity/libraries/ppp connectivity/netsocket connectivity/nanostack connectivity/lwipstack features/frameworks/greentea-client \ - features/frameworks/utest features/frameworks/unity components BUILD + connectivity/libraries/ppp connectivity/netsocket connectivity/nanostack connectivity/lwipstack \ + components BUILD - python tools/make.py -t GCC_ARM -m NUCLEO_F103RB --source=. --build=BUILD/NUCLEO_F103RB/GCC_ARM -j0 # Run profiling tests - make -C ${EVENTS}/tests/unit prof | tee prof diff --git a/LICENSE.md b/LICENSE.md index 6a5d58ce557..878f79e3b13 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -15,7 +15,6 @@ Folders containing files under different permissive license than Apache 2.0 are - [features/lorawan](./features/lorawan) - Revised BSD - [connectivity/lwipstack](./connectivity/lwipstack) - BSD-style, MIT-style - [connectivity/nanostack/sal-stack-nanostack](./connectivity/nanostack/sal-stack-nanostack) - BSD-3-Clause -- [features/frameworks/unity/unity](./features/frameworks/unity/unity) - MIT - [features/unsupported](./features/unsupported) - MIT-style, BSD-style - [storage/blockdevice](./storage/blockdevice) - Apache 2.0, MIT - [storage/filesystem/littlefs](.storage/filesystem/littlefs) - [BSD-3-Clause](https://github.com/ARMmbed/littlefs/blob/master/LICENSE.md) @@ -23,6 +22,7 @@ Folders containing files under different permissive license than Apache 2.0 are - [rtos](./rtos) - MIT - [drivers](./drivers) - MIT - [TESTS/mbed_hal/trng/pithy](./TESTS/mbed_hal/trng/pithy) - BSD-3-Clause +- [TESTS/COMMON/unity](./TESTS/COMMON/unity) - MIT - [tools/data/rpc](./tools/data/rpc) - MIT - [targets](./targets) - PBL, BSD-style, MIT-style, Zlib-style, Public-domain, BSD-3-Clause diff --git a/features/frameworks/greentea-client/README.md b/TESTS/COMMON/greentea-client/README.md similarity index 98% rename from features/frameworks/greentea-client/README.md rename to TESTS/COMMON/greentea-client/README.md index e77b21a7bfa..a2dde7d9994 100644 --- a/features/frameworks/greentea-client/README.md +++ b/TESTS/COMMON/greentea-client/README.md @@ -11,7 +11,7 @@ `greentea-client` is a client library for [the Greentea test tool](https://github.com/ARMmbed/mbed-os-tools/tree/master/packages/mbed-greentea) when used in an [Mbed OS](https://os.mbed.com/) project. -This package implements the client side of the key-value protocol used for communication between the device under test (DUT) and the host. The `Greentea` tool implements the protocol's host behavior. We use [utest](https://github.com/ARMmbed/mbed-os/blob/master/features/frameworks/utest/README.md) as our test harness. +This package implements the client side of the key-value protocol used for communication between the device under test (DUT) and the host. The `Greentea` tool implements the protocol's host behavior. We use [utest](https://github.com/ARMmbed/mbed-os/blob/master/TESTS/COMMON/utest/README.md) as our test harness. ``` DUT <--- serial port connection ---> host diff --git a/features/frameworks/greentea-client/greentea-client/greentea_metrics.h b/TESTS/COMMON/greentea-client/include/greentea-client/greentea_metrics.h similarity index 100% rename from features/frameworks/greentea-client/greentea-client/greentea_metrics.h rename to TESTS/COMMON/greentea-client/include/greentea-client/greentea_metrics.h diff --git a/features/frameworks/greentea-client/greentea-client/test_env.h b/TESTS/COMMON/greentea-client/include/greentea-client/test_env.h similarity index 75% rename from features/frameworks/greentea-client/greentea-client/test_env.h rename to TESTS/COMMON/greentea-client/include/greentea-client/test_env.h index b21db6b181a..3d3a57a7d8d 100644 --- a/features/frameworks/greentea-client/greentea-client/test_env.h +++ b/TESTS/COMMON/greentea-client/include/greentea-client/test_env.h @@ -52,32 +52,32 @@ /** * Generic test suite transport protocol keys */ -extern const char* GREENTEA_TEST_ENV_END; -extern const char* GREENTEA_TEST_ENV_EXIT; -extern const char* GREENTEA_TEST_ENV_SYNC; -extern const char* GREENTEA_TEST_ENV_TIMEOUT; -extern const char* GREENTEA_TEST_ENV_HOST_TEST_NAME; -extern const char* GREENTEA_TEST_ENV_HOST_TEST_VERSION; +extern const char *GREENTEA_TEST_ENV_END; +extern const char *GREENTEA_TEST_ENV_EXIT; +extern const char *GREENTEA_TEST_ENV_SYNC; +extern const char *GREENTEA_TEST_ENV_TIMEOUT; +extern const char *GREENTEA_TEST_ENV_HOST_TEST_NAME; +extern const char *GREENTEA_TEST_ENV_HOST_TEST_VERSION; /** * Test suite success code strings */ -extern const char* GREENTEA_TEST_ENV_SUCCESS; -extern const char* GREENTEA_TEST_ENV_FAILURE; +extern const char *GREENTEA_TEST_ENV_SUCCESS; +extern const char *GREENTEA_TEST_ENV_FAILURE; /** * Test case transport protocol start/finish keys */ -extern const char* GREENTEA_TEST_ENV_TESTCASE_NAME; -extern const char* GREENTEA_TEST_ENV_TESTCASE_COUNT; -extern const char* GREENTEA_TEST_ENV_TESTCASE_START; -extern const char* GREENTEA_TEST_ENV_TESTCASE_FINISH; -extern const char* GREENTEA_TEST_ENV_TESTCASE_SUMMARY; +extern const char *GREENTEA_TEST_ENV_TESTCASE_NAME; +extern const char *GREENTEA_TEST_ENV_TESTCASE_COUNT; +extern const char *GREENTEA_TEST_ENV_TESTCASE_START; +extern const char *GREENTEA_TEST_ENV_TESTCASE_FINISH; +extern const char *GREENTEA_TEST_ENV_TESTCASE_SUMMARY; /** * Code Coverage (LCOV) transport protocol keys */ -extern const char* GREENTEA_TEST_ENV_LCOV_START; +extern const char *GREENTEA_TEST_ENV_LCOV_START; /** * Greentea-client related API for communication with host side @@ -112,10 +112,10 @@ extern "C" { /** * Greentea-client C API */ -void GREENTEA_SETUP(const int timeout, const char * host_test); -void greentea_send_kv(const char * key, const char * val); -int greentea_parse_kv(char * key, char * val, - const int key_len, const int val_len); +void GREENTEA_SETUP(const int timeout, const char *host_test); +void greentea_send_kv(const char *key, const char *val); +int greentea_parse_kv(char *key, char *val, + const int key_len, const int val_len); int greentea_getc(); void greentea_putc(int c); void greentea_write_string(const char *str); diff --git a/features/frameworks/greentea-client/mbed_lib.json b/TESTS/COMMON/greentea-client/mbed_lib.json similarity index 100% rename from features/frameworks/greentea-client/mbed_lib.json rename to TESTS/COMMON/greentea-client/mbed_lib.json diff --git a/features/frameworks/greentea-client/source/greentea_metrics.cpp b/TESTS/COMMON/greentea-client/source/greentea_metrics.cpp similarity index 97% rename from features/frameworks/greentea-client/source/greentea_metrics.cpp rename to TESTS/COMMON/greentea-client/source/greentea_metrics.cpp index 8437c8d89c9..a4b972786e3 100644 --- a/features/frameworks/greentea-client/source/greentea_metrics.cpp +++ b/TESTS/COMMON/greentea-client/source/greentea_metrics.cpp @@ -105,8 +105,8 @@ static void send_heap_info() { mbed_stats_heap_t heap_stats; mbed_stats_heap_get(&heap_stats); - greentea_send_kv("max_heap_usage",heap_stats.max_size); - greentea_send_kv("reserved_heap",heap_stats.reserved_size); + greentea_send_kv("max_heap_usage", heap_stats.max_size); + greentea_send_kv("reserved_heap", heap_stats.reserved_size); } #endif @@ -129,7 +129,7 @@ MBED_UNUSED static void send_stack_info() } thread_n = osThreadEnumerate(threads, thread_n); - for(size_t i = 0; i < thread_n; i++) { + for (size_t i = 0; i < thread_n; i++) { enqeue_thread_info(threads[i]); deque_and_print_thread_info(); } diff --git a/features/frameworks/greentea-client/source/greentea_test_env.cpp b/TESTS/COMMON/greentea-client/source/greentea_test_env.cpp similarity index 89% rename from features/frameworks/greentea-client/source/greentea_test_env.cpp rename to TESTS/COMMON/greentea-client/source/greentea_test_env.cpp index cda381f36d4..deaa97dac67 100644 --- a/features/frameworks/greentea-client/source/greentea_test_env.cpp +++ b/TESTS/COMMON/greentea-client/source/greentea_test_env.cpp @@ -26,29 +26,29 @@ /** * Generic test suite transport protocol keys */ -const char* GREENTEA_TEST_ENV_END = "end"; -const char* GREENTEA_TEST_ENV_EXIT = "__exit"; -const char* GREENTEA_TEST_ENV_SYNC = "__sync"; -const char* GREENTEA_TEST_ENV_TIMEOUT = "__timeout"; -const char* GREENTEA_TEST_ENV_HOST_TEST_NAME = "__host_test_name"; -const char* GREENTEA_TEST_ENV_HOST_TEST_VERSION = "__version"; +const char *GREENTEA_TEST_ENV_END = "end"; +const char *GREENTEA_TEST_ENV_EXIT = "__exit"; +const char *GREENTEA_TEST_ENV_SYNC = "__sync"; +const char *GREENTEA_TEST_ENV_TIMEOUT = "__timeout"; +const char *GREENTEA_TEST_ENV_HOST_TEST_NAME = "__host_test_name"; +const char *GREENTEA_TEST_ENV_HOST_TEST_VERSION = "__version"; /** * Test suite success code strings */ -const char* GREENTEA_TEST_ENV_SUCCESS = "success"; -const char* GREENTEA_TEST_ENV_FAILURE = "failure"; +const char *GREENTEA_TEST_ENV_SUCCESS = "success"; +const char *GREENTEA_TEST_ENV_FAILURE = "failure"; /** * Test case transport protocol start/finish keys */ -const char* GREENTEA_TEST_ENV_TESTCASE_NAME = "__testcase_name"; -const char* GREENTEA_TEST_ENV_TESTCASE_COUNT = "__testcase_count"; -const char* GREENTEA_TEST_ENV_TESTCASE_START = "__testcase_start"; -const char* GREENTEA_TEST_ENV_TESTCASE_FINISH = "__testcase_finish"; -const char* GREENTEA_TEST_ENV_TESTCASE_SUMMARY = "__testcase_summary"; +const char *GREENTEA_TEST_ENV_TESTCASE_NAME = "__testcase_name"; +const char *GREENTEA_TEST_ENV_TESTCASE_COUNT = "__testcase_count"; +const char *GREENTEA_TEST_ENV_TESTCASE_START = "__testcase_start"; +const char *GREENTEA_TEST_ENV_TESTCASE_FINISH = "__testcase_finish"; +const char *GREENTEA_TEST_ENV_TESTCASE_SUMMARY = "__testcase_summary"; // Code Coverage (LCOV) transport protocol keys -const char* GREENTEA_TEST_ENV_LCOV_START = "__coverage_start"; +const char *GREENTEA_TEST_ENV_LCOV_START = "__coverage_start"; /** * Auxilary functions @@ -63,7 +63,8 @@ static void greentea_notify_version(); * GREENTEA_SETUP and GREENTEA_SETUP_UUID. * This function is blocking. */ -void _GREENTEA_SETUP_COMMON(const int timeout, const char *host_test_name, char *buffer, size_t size) { +void _GREENTEA_SETUP_COMMON(const int timeout, const char *host_test_name, char *buffer, size_t size) +{ greentea_metrics_setup(); // Key-value protocol handshake function. Waits for {{__sync;...}} message // Sync preamble: "{{__sync;0dad4a9d-59a3-4aec-810d-d5fb09d852c1}}" @@ -96,7 +97,8 @@ void _GREENTEA_SETUP_COMMON(const int timeout, const char *host_test_name, char * and add host test's callback handlers to main event loop * This function is blocking. */ -extern "C" void GREENTEA_SETUP(const int timeout, const char *host_test_name) { +extern "C" void GREENTEA_SETUP(const int timeout, const char *host_test_name) +{ #if ! defined(NO_GREENTEA) char _value[GREENTEA_UUID_LENGTH] = {0}; _GREENTEA_SETUP_COMMON(timeout, host_test_name, _value, GREENTEA_UUID_LENGTH); @@ -111,7 +113,8 @@ extern "C" void GREENTEA_SETUP(const int timeout, const char *host_test_name) { * This function differs from GREENTEA_SETUP because it allows you to * preserve the UUID sent during the sync process. */ -void GREENTEA_SETUP_UUID(const int timeout, const char *host_test_name, char *buffer, size_t size) { +void GREENTEA_SETUP_UUID(const int timeout, const char *host_test_name, char *buffer, size_t size) +{ _GREENTEA_SETUP_COMMON(timeout, host_test_name, buffer, size); } @@ -119,7 +122,8 @@ void GREENTEA_SETUP_UUID(const int timeout, const char *host_test_name, char *bu * \result Test suite result * \details If __exit is not received by host side we will assume TIMEOUT */ -void GREENTEA_TESTSUITE_RESULT(const int result) { +void GREENTEA_TESTSUITE_RESULT(const int result) +{ greentea_notify_completion(result); } @@ -130,7 +134,8 @@ void GREENTEA_TESTSUITE_RESULT(const int result) { /** \brief Notify host side that test case started * \details test_case_name Test case name */ -void GREENTEA_TESTCASE_START(const char *test_case_name) { +void GREENTEA_TESTCASE_START(const char *test_case_name) +{ greentea_send_kv(GREENTEA_TEST_ENV_TESTCASE_START, test_case_name); } @@ -138,7 +143,8 @@ void GREENTEA_TESTCASE_START(const char *test_case_name) { * \details test_case_name Test case name * \details result Test case result (0 -OK, non zero...) */ -void GREENTEA_TESTCASE_FINISH(const char *test_case_name, const size_t passes, const size_t failed) { +void GREENTEA_TESTCASE_FINISH(const char *test_case_name, const size_t passes, const size_t failed) +{ greentea_send_kv(GREENTEA_TEST_ENV_TESTCASE_FINISH, test_case_name, passes, failed); } @@ -174,7 +180,8 @@ extern bool coverage_report; * \param path to file with code coverage payload (set by gcov instrumentation) * */ -void greentea_notify_coverage_start(const char *path) { +void greentea_notify_coverage_start(const char *path) +{ printf("{{%s;%s;", GREENTEA_TEST_ENV_LCOV_START, path); } @@ -192,7 +199,8 @@ void greentea_notify_coverage_start(const char *path) { * Companion function greentea_notify_coverage_start() defines code coverage message structure * */ -void greentea_notify_coverage_end() { +void greentea_notify_coverage_end() +{ printf("}}" NL); } @@ -291,7 +299,8 @@ static void greentea_write_int(const int val) * \param value Message payload, string value * */ -extern "C" void greentea_send_kv(const char *key, const char *val) { +extern "C" void greentea_send_kv(const char *key, const char *val) +{ if (key && val) { greentea_write_preamble(); greentea_write_string(key); @@ -314,7 +323,8 @@ extern "C" void greentea_send_kv(const char *key, const char *val) { * \param value Message payload, integer value * */ -void greentea_send_kv(const char *key, const int val) { +void greentea_send_kv(const char *key, const int val) +{ if (key) { greentea_write_preamble(); greentea_write_string(key); @@ -338,7 +348,8 @@ void greentea_send_kv(const char *key, const int val) { * \param result Send additional integer formatted data * */ -void greentea_send_kv(const char *key, const char *val, const int result) { +void greentea_send_kv(const char *key, const char *val, const int result) +{ if (key) { greentea_write_preamble(); greentea_write_string(key); @@ -371,7 +382,8 @@ void greentea_send_kv(const char *key, const char *val, const int result) { * \param failures Send additional integer formatted data * */ -void greentea_send_kv(const char *key, const char *val, const int passes, const int failures) { +void greentea_send_kv(const char *key, const char *val, const int passes, const int failures) +{ if (key) { greentea_write_preamble(); greentea_write_string(key); @@ -404,7 +416,8 @@ void greentea_send_kv(const char *key, const char *val, const int passes, const * \param failures Send additional integer formatted data * */ -void greentea_send_kv(const char *key, const int passes, const int failures) { +void greentea_send_kv(const char *key, const int passes, const int failures) +{ if (key) { greentea_write_preamble(); greentea_write_string(key); @@ -431,7 +444,8 @@ void greentea_send_kv(const char *key, const int passes, const int failures) { * \param timeout Test suite timeout in seconds * */ -static void greentea_notify_timeout(const int timeout) { +static void greentea_notify_timeout(const int timeout) +{ greentea_send_kv(GREENTEA_TEST_ENV_TIMEOUT, timeout); } @@ -449,7 +463,8 @@ static void greentea_notify_timeout(const int timeout) { * * \param host_test_name Host test name, host test will be loaded by mbedhtrun */ -static void greentea_notify_hosttest(const char *host_test_name) { +static void greentea_notify_hosttest(const char *host_test_name) +{ greentea_send_kv(GREENTEA_TEST_ENV_HOST_TEST_NAME, host_test_name); } @@ -470,7 +485,8 @@ static void greentea_notify_hosttest(const char *host_test_name) { * \param result Test suite result from DUT (0 - FAIl, !0 - SUCCESS) * */ -static void greentea_notify_completion(const int result) { +static void greentea_notify_completion(const int result) +{ const char *val = result ? GREENTEA_TEST_ENV_SUCCESS : GREENTEA_TEST_ENV_FAILURE; #ifdef MBED_CFG_DEBUG_OPTIONS_COVERAGE coverage_report = true; @@ -485,7 +501,8 @@ static void greentea_notify_completion(const int result) { /** * \brief Send to master greentea-client version */ -static void greentea_notify_version() { +static void greentea_notify_version() +{ greentea_send_kv(GREENTEA_TEST_ENV_HOST_TEST_VERSION, MBED_GREENTEA_CLIENT_VERSION_STRING); } @@ -552,7 +569,8 @@ enum Token { * \return Next character from the stream or EOF if stream has ended. * */ -extern "C" int greentea_getc() { +extern "C" int greentea_getc() +{ uint8_t c; read(STDOUT_FILENO, &c, 1); return c; @@ -565,7 +583,8 @@ extern "C" int greentea_getc() { * \return The number of bytes written * */ -extern "C" void greentea_putc(int c) { +extern "C" void greentea_putc(int c) +{ uint8_t _c = c; write(STDOUT_FILENO, &_c, 1); } @@ -586,26 +605,27 @@ extern "C" void greentea_putc(int c) { * */ extern "C" int greentea_parse_kv(char *out_key, - char *out_value, - const int out_key_size, - const int out_value_size) { + char *out_value, + const int out_key_size, + const int out_value_size) +{ getNextToken(0, 0); while (1) { switch (CurTok) { - case tok_eof: - return 0; + case tok_eof: + return 0; - case tok_open: - if (HandleKV(out_key, out_value, out_key_size, out_value_size)) { - // We've found {{ KEY ; VALUE }} expression - return 1; - } - break; + case tok_open: + if (HandleKV(out_key, out_value, out_key_size, out_value_size)) { + // We've found {{ KEY ; VALUE }} expression + return 1; + } + break; - default: - // Load next token and pray... - getNextToken(0, 0); - break; + default: + // Load next token and pray... + getNextToken(0, 0); + break; } } } @@ -622,7 +642,8 @@ extern "C" int greentea_parse_kv(char *out_key, * \param str_size Size of 'str' parameter in bytes (characters) * */ -static int getNextToken(char *str, const int str_size) { +static int getNextToken(char *str, const int str_size) +{ return CurTok = gettok(str, str_size); } @@ -639,9 +660,10 @@ static int getNextToken(char *str, const int str_size) { * \return Return 1 if character is allowed punctuation character, otherwise return false * */ -static int ispunctuation(int c) { +static int ispunctuation(int c) +{ static const char punctuation[] = "_-!@#$%^&*()=+:<>,./?\\\"'"; // No ";{}" - for (size_t i=0; i< sizeof(punctuation); ++i) { + for (size_t i = 0; i < sizeof(punctuation); ++i) { if (c == punctuation[i]) { return 1; } @@ -668,7 +690,8 @@ static int ispunctuation(int c) { * \return Return 1 if character is allowed punctuation character, otherwise return false * */ -static int isstring(int c) { +static int isstring(int c) +{ return (isalpha(c) || isdigit(c) || isspace(c) || @@ -694,7 +717,8 @@ static int isstring(int c) { * \return Return #Token enum value used by parser to check for key-value occurrences * */ -static int gettok(char *out_str, const int str_size) { +static int gettok(char *out_str, const int str_size) +{ static int LastChar = '!'; static int str_idx = 0; @@ -737,17 +761,18 @@ static int gettok(char *out_str, const int str_size) { } // close ::= '}' - if (LastChar == '}') { - LastChar = greentea_getc(); - if (LastChar == '}') { - greentea_getc(); //offset the extra '\n' send by Greentea python tool - LastChar = '!'; - return tok_close; - } - } - - if (LastChar == EOF) + if (LastChar == '}') { + LastChar = greentea_getc(); + if (LastChar == '}') { + greentea_getc(); //offset the extra '\n' send by Greentea python tool + LastChar = '!'; + return tok_close; + } + } + + if (LastChar == EOF) { return tok_eof; + } // Otherwise, just return the character as its ascii value. int ThisChar = LastChar; @@ -776,7 +801,8 @@ static int gettok(char *out_str, const int str_size) { static int HandleKV(char *out_key, char *out_value, const int out_key_size, - const int out_value_size) { + const int out_value_size) +{ // We already started with if (getNextToken(out_key, out_key_size) == tok_string) { if (getNextToken(0, 0) == tok_semicolon) { diff --git a/features/frameworks/unity/CHANGELOG.md b/TESTS/COMMON/unity/CHANGELOG.md similarity index 100% rename from features/frameworks/unity/CHANGELOG.md rename to TESTS/COMMON/unity/CHANGELOG.md diff --git a/features/frameworks/unity/README.md b/TESTS/COMMON/unity/README.md similarity index 100% rename from features/frameworks/unity/README.md rename to TESTS/COMMON/unity/README.md diff --git a/features/frameworks/unity/unity/unity.h b/TESTS/COMMON/unity/include/unity/unity.h similarity index 100% rename from features/frameworks/unity/unity/unity.h rename to TESTS/COMMON/unity/include/unity/unity.h diff --git a/features/frameworks/unity/unity/unity_config.h b/TESTS/COMMON/unity/include/unity/unity_config.h similarity index 95% rename from features/frameworks/unity/unity/unity_config.h rename to TESTS/COMMON/unity/include/unity/unity_config.h index 46cd5729cef..02e5b3d29e5 100644 --- a/features/frameworks/unity/unity/unity_config.h +++ b/TESTS/COMMON/unity/include/unity/unity_config.h @@ -22,22 +22,22 @@ #ifndef UNITY_CONFIG_H #define UNITY_CONFIG_H -/* When using unity with the mbed RTOS printing to the serial port using the stdlib is not +/* When using unity with the mbed RTOS printing to the serial port using the stdlib is not allowed as it causes a hardfault. Unity has the following define to control how failure messages are written: - + #ifndef UNITY_OUTPUT_CHAR #include #define UNITY_OUTPUT_CHAR(a) (void)putchar(a) #endif - - To make this safe we can define our own version of UNITY_OUTPUT_CHAR and make sure it is + + To make this safe we can define our own version of UNITY_OUTPUT_CHAR and make sure it is thread safe. */ #ifndef UNITY_OUTPUT_CHAR #define UNITY_OUTPUT_CHAR(a) utest_safe_putc(a) #endif //UNITY_OUTPUT_CHAR - + #endif // UNITY_CONFIG_H /** @}*/ diff --git a/features/frameworks/unity/unity/unity_internals.h b/TESTS/COMMON/unity/include/unity/unity_internals.h similarity index 89% rename from features/frameworks/unity/unity/unity_internals.h rename to TESTS/COMMON/unity/include/unity/unity_internals.h index 8a9de63e245..cf1ed0c545d 100644 --- a/features/frameworks/unity/unity/unity_internals.h +++ b/TESTS/COMMON/unity/include/unity/unity_internals.h @@ -53,65 +53,65 @@ * at this stage in the trnslation of the C program. * Therefore, infer it from UINT_MAX if possible. */ #ifndef UNITY_INT_WIDTH - #ifdef UINT_MAX - #if (UINT_MAX == 0xFFFF) - #define UNITY_INT_WIDTH (16) - #elif (UINT_MAX == 0xFFFFFFFF) - #define UNITY_INT_WIDTH (32) - #elif (UINT_MAX == 0xFFFFFFFFFFFFFFFF) - #define UNITY_INT_WIDTH (64) - #endif - #endif +#ifdef UINT_MAX +#if (UINT_MAX == 0xFFFF) +#define UNITY_INT_WIDTH (16) +#elif (UINT_MAX == 0xFFFFFFFF) +#define UNITY_INT_WIDTH (32) +#elif (UINT_MAX == 0xFFFFFFFFFFFFFFFF) +#define UNITY_INT_WIDTH (64) +#endif +#endif #endif #ifndef UNITY_INT_WIDTH - #define UNITY_INT_WIDTH (32) +#define UNITY_INT_WIDTH (32) #endif /* Determine the size of a long, if not already specified, * by following the process used above to define * UNITY_INT_WIDTH. */ #ifndef UNITY_LONG_WIDTH - #ifdef ULONG_MAX - #if (ULONG_MAX == 0xFFFF) - #define UNITY_LONG_WIDTH (16) - #elif (ULONG_MAX == 0xFFFFFFFF) - #define UNITY_LONG_WIDTH (32) - #elif (ULONG_MAX == 0xFFFFFFFFFFFFFFFF) - #define UNITY_LONG_WIDTH (64) - #endif - #endif +#ifdef ULONG_MAX +#if (ULONG_MAX == 0xFFFF) +#define UNITY_LONG_WIDTH (16) +#elif (ULONG_MAX == 0xFFFFFFFF) +#define UNITY_LONG_WIDTH (32) +#elif (ULONG_MAX == 0xFFFFFFFFFFFFFFFF) +#define UNITY_LONG_WIDTH (64) +#endif +#endif #endif #ifndef UNITY_LONG_WIDTH - #define UNITY_LONG_WIDTH (32) +#define UNITY_LONG_WIDTH (32) #endif /* Determine the size of a pointer, if not already specified, * by following the process used above to define * UNITY_INT_WIDTH. */ #ifndef UNITY_POINTER_WIDTH - #ifdef UINTPTR_MAX - #if (UINTPTR_MAX+0 <= 0xFFFF) - #define UNITY_POINTER_WIDTH (16) - #elif (UINTPTR_MAX+0 <= 0xFFFFFFFF) - #define UNITY_POINTER_WIDTH (32) - #elif (UINTPTR_MAX+0 <= 0xFFFFFFFFFFFFFFFF) - #define UNITY_POINTER_WIDTH (64) - #endif - #endif +#ifdef UINTPTR_MAX +#if (UINTPTR_MAX+0 <= 0xFFFF) +#define UNITY_POINTER_WIDTH (16) +#elif (UINTPTR_MAX+0 <= 0xFFFFFFFF) +#define UNITY_POINTER_WIDTH (32) +#elif (UINTPTR_MAX+0 <= 0xFFFFFFFFFFFFFFFF) +#define UNITY_POINTER_WIDTH (64) +#endif +#endif #endif #ifndef UNITY_POINTER_WIDTH - #ifdef INTPTR_MAX - #if (INTPTR_MAX+0 <= 0x7FFF) - #define UNITY_POINTER_WIDTH (16) - #elif (INTPTR_MAX+0 <= 0x7FFFFFFF) - #define UNITY_POINTER_WIDTH (32) - #elif (INTPTR_MAX+0 <= 0x7FFFFFFFFFFFFFFF) - #define UNITY_POINTER_WIDTH (64) - #endif - #endif +#ifdef INTPTR_MAX +#if (INTPTR_MAX+0 <= 0x7FFF) +#define UNITY_POINTER_WIDTH (16) +#elif (INTPTR_MAX+0 <= 0x7FFFFFFF) +#define UNITY_POINTER_WIDTH (32) +#elif (INTPTR_MAX+0 <= 0x7FFFFFFFFFFFFFFF) +#define UNITY_POINTER_WIDTH (64) +#endif +#endif #endif #ifndef UNITY_POINTER_WIDTH - #define UNITY_POINTER_WIDTH UNITY_LONG_WIDTH +#define UNITY_POINTER_WIDTH UNITY_LONG_WIDTH #endif /*------------------------------------------------------- @@ -119,21 +119,21 @@ *-------------------------------------------------------*/ #if (UNITY_INT_WIDTH == 32) - typedef unsigned char _UU8; - typedef unsigned short _UU16; - typedef unsigned int _UU32; - typedef signed char _US8; - typedef signed short _US16; - typedef signed int _US32; +typedef unsigned char _UU8; +typedef unsigned short _UU16; +typedef unsigned int _UU32; +typedef signed char _US8; +typedef signed short _US16; +typedef signed int _US32; #elif (UNITY_INT_WIDTH == 16) - typedef unsigned char _UU8; - typedef unsigned int _UU16; - typedef unsigned long _UU32; - typedef signed char _US8; - typedef signed int _US16; - typedef signed long _US32; +typedef unsigned char _UU8; +typedef unsigned int _UU16; +typedef unsigned long _UU32; +typedef signed char _US8; +typedef signed int _US16; +typedef signed long _US32; #else - #error Invalid UNITY_INT_WIDTH specified! (16 or 32 are supported) +#error Invalid UNITY_INT_WIDTH specified! (16 or 32 are supported) #endif /*------------------------------------------------------- @@ -161,13 +161,13 @@ typedef _US32 _U_SINT; /* 64-bit Support */ #if (UNITY_LONG_WIDTH == 32) - typedef unsigned long long _UU64; - typedef signed long long _US64; +typedef unsigned long long _UU64; +typedef signed long long _US64; #elif (UNITY_LONG_WIDTH == 64) - typedef unsigned long _UU64; - typedef signed long _US64; +typedef unsigned long _UU64; +typedef signed long _US64; #else - #error Invalid UNITY_LONG_WIDTH specified! (32 or 64 are supported) +#error Invalid UNITY_LONG_WIDTH specified! (32 or 64 are supported) #endif typedef _UU64 _U_UINT; typedef _US64 _U_SINT; @@ -179,16 +179,16 @@ typedef _US64 _U_SINT; *-------------------------------------------------------*/ #if (UNITY_POINTER_WIDTH == 32) - typedef _UU32 _UP; +typedef _UU32 _UP; #define UNITY_DISPLAY_STYLE_POINTER UNITY_DISPLAY_STYLE_HEX32 #elif (UNITY_POINTER_WIDTH == 64) - typedef _UU64 _UP; +typedef _UU64 _UP; #define UNITY_DISPLAY_STYLE_POINTER UNITY_DISPLAY_STYLE_HEX64 #elif (UNITY_POINTER_WIDTH == 16) - typedef _UU16 _UP; +typedef _UU16 _UP; #define UNITY_DISPLAY_STYLE_POINTER UNITY_DISPLAY_STYLE_HEX16 #else - #error Invalid UNITY_POINTER_WIDTH specified! (16, 32 or 64 are supported) +#error Invalid UNITY_POINTER_WIDTH specified! (16, 32 or 64 are supported) #endif #ifndef UNITY_PTR_ATTRIBUTE @@ -298,10 +298,10 @@ typedef UNITY_DOUBLE_TYPE _UD; #include #define UNITY_OUTPUT_CHAR(a) (void)putchar(a) #else - /* If defined as something else, make sure we declare it here so it's ready for use */ - #ifndef UNITY_OMIT_OUTPUT_CHAR_HEADER_DECLARATION +/* If defined as something else, make sure we declare it here so it's ready for use */ +#ifndef UNITY_OMIT_OUTPUT_CHAR_HEADER_DECLARATION extern void UNITY_OUTPUT_CHAR(int); - #endif +#endif #endif #ifndef UNITY_OUTPUT_FLUSH @@ -309,10 +309,10 @@ extern void UNITY_OUTPUT_CHAR(int); #include #define UNITY_OUTPUT_FLUSH() (void)fflush(stdout) #else - /* If defined as something else, make sure we declare it here so it's ready for use */ - #ifndef UNITY_OMIT_OUTPUT_FLUSH_HEADER_DECLARATION +/* If defined as something else, make sure we declare it here so it's ready for use */ +#ifndef UNITY_OMIT_OUTPUT_FLUSH_HEADER_DECLARATION extern void UNITY_OUTPUT_FLUSH(void); - #endif +#endif #endif #ifndef UNITY_PRINT_EOL @@ -367,8 +367,7 @@ typedef void (*UnityTestFunction)(void); #define UNITY_DISPLAY_RANGE_HEX (0x40) #define UNITY_DISPLAY_RANGE_AUTO (0x80) -typedef enum -{ +typedef enum { #if (UNITY_INT_WIDTH == 16) UNITY_DISPLAY_STYLE_INT = 2 + UNITY_DISPLAY_RANGE_INT + UNITY_DISPLAY_RANGE_AUTO, #elif (UNITY_INT_WIDTH == 32) @@ -406,8 +405,7 @@ typedef enum } UNITY_DISPLAY_STYLE_T; #ifndef UNITY_EXCLUDE_FLOAT -typedef enum _UNITY_FLOAT_TRAIT_T -{ +typedef enum _UNITY_FLOAT_TRAIT_T { UNITY_FLOAT_IS_NOT_INF = 0, UNITY_FLOAT_IS_INF, UNITY_FLOAT_IS_NOT_NEG_INF, @@ -420,13 +418,12 @@ typedef enum _UNITY_FLOAT_TRAIT_T } UNITY_FLOAT_TRAIT_T; #endif -struct _Unity -{ - const char* TestFile; - const char* CurrentTestName; +struct _Unity { + const char *TestFile; + const char *CurrentTestName; #ifndef UNITY_EXCLUDE_DETAILS - const char* CurrentDetail1; - const char* CurrentDetail2; + const char *CurrentDetail1; + const char *CurrentDetail2; #endif UNITY_LINE_TYPE CurrentTestLineNumber; UNITY_COUNTER_TYPE NumberOfTests; @@ -448,10 +445,10 @@ extern "C" { *-------------------------------------------------------*/ -void UnityBegin(const char* filename); +void UnityBegin(const char *filename); int UnityEnd(void); void UnityConcludeTest(void); -void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int FuncLineNum); +void UnityDefaultTestRun(UnityTestFunction Func, const char *FuncName, const int FuncLineNum); /*------------------------------------------------------- * Details Support @@ -479,7 +476,7 @@ void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int * Test Output *-------------------------------------------------------*/ -void UnityPrint(const char* string); +void UnityPrint(const char *string); void UnityPrintMask(const _U_UINT mask, const _U_UINT number); void UnityPrintNumberByStyle(const _U_SINT number, const UNITY_DISPLAY_STYLE_T style); void UnityPrintNumber(const _U_SINT number); @@ -500,75 +497,75 @@ void UnityPrintFloat(const _UF number); void UnityAssertEqualNumber(const _U_SINT expected, const _U_SINT actual, - const char* msg, + const char *msg, const UNITY_LINE_TYPE lineNumber, const UNITY_DISPLAY_STYLE_T style); void UnityAssertEqualIntArray(UNITY_INTERNAL_PTR expected, UNITY_INTERNAL_PTR actual, const _UU32 num_elements, - const char* msg, + const char *msg, const UNITY_LINE_TYPE lineNumber, const UNITY_DISPLAY_STYLE_T style); void UnityAssertBits(const _U_SINT mask, const _U_SINT expected, const _U_SINT actual, - const char* msg, + const char *msg, const UNITY_LINE_TYPE lineNumber); -void UnityAssertEqualString(const char* expected, - const char* actual, - const char* msg, +void UnityAssertEqualString(const char *expected, + const char *actual, + const char *msg, const UNITY_LINE_TYPE lineNumber); -void UnityAssertEqualStringLen(const char* expected, - const char* actual, +void UnityAssertEqualStringLen(const char *expected, + const char *actual, + const _UU32 length, + const char *msg, + const UNITY_LINE_TYPE lineNumber); + +void UnityAssertEqualStringArray(const char **expected, + const char **actual, + const _UU32 num_elements, + const char *msg, + const UNITY_LINE_TYPE lineNumber); + +void UnityAssertEqualMemory(UNITY_INTERNAL_PTR expected, + UNITY_INTERNAL_PTR actual, const _UU32 length, - const char* msg, + const _UU32 num_elements, + const char *msg, const UNITY_LINE_TYPE lineNumber); -void UnityAssertEqualStringArray( const char** expected, - const char** actual, - const _UU32 num_elements, - const char* msg, - const UNITY_LINE_TYPE lineNumber); - -void UnityAssertEqualMemory( UNITY_INTERNAL_PTR expected, - UNITY_INTERNAL_PTR actual, - const _UU32 length, - const _UU32 num_elements, - const char* msg, - const UNITY_LINE_TYPE lineNumber); - void UnityAssertNumbersWithin(const _U_UINT delta, const _U_SINT expected, const _U_SINT actual, - const char* msg, + const char *msg, const UNITY_LINE_TYPE lineNumber, const UNITY_DISPLAY_STYLE_T style); -void UnityFail(const char* message, const UNITY_LINE_TYPE line); +void UnityFail(const char *message, const UNITY_LINE_TYPE line); -void UnityIgnore(const char* message, const UNITY_LINE_TYPE line); +void UnityIgnore(const char *message, const UNITY_LINE_TYPE line); -void UnitySkipPrint(const char* message, const UNITY_LINE_TYPE line); +void UnitySkipPrint(const char *message, const UNITY_LINE_TYPE line); #ifndef UNITY_EXCLUDE_FLOAT void UnityAssertFloatsWithin(const _UF delta, const _UF expected, const _UF actual, - const char* msg, + const char *msg, const UNITY_LINE_TYPE lineNumber); -void UnityAssertEqualFloatArray(UNITY_PTR_ATTRIBUTE const _UF* expected, - UNITY_PTR_ATTRIBUTE const _UF* actual, +void UnityAssertEqualFloatArray(UNITY_PTR_ATTRIBUTE const _UF *expected, + UNITY_PTR_ATTRIBUTE const _UF *actual, const _UU32 num_elements, - const char* msg, + const char *msg, const UNITY_LINE_TYPE lineNumber); void UnityAssertFloatSpecial(const _UF actual, - const char* msg, + const char *msg, const UNITY_LINE_TYPE lineNumber, const UNITY_FLOAT_TRAIT_T style); #endif @@ -577,17 +574,17 @@ void UnityAssertFloatSpecial(const _UF actual, void UnityAssertDoublesWithin(const _UD delta, const _UD expected, const _UD actual, - const char* msg, + const char *msg, const UNITY_LINE_TYPE lineNumber); -void UnityAssertEqualDoubleArray(UNITY_PTR_ATTRIBUTE const _UD* expected, - UNITY_PTR_ATTRIBUTE const _UD* actual, +void UnityAssertEqualDoubleArray(UNITY_PTR_ATTRIBUTE const _UD *expected, + UNITY_PTR_ATTRIBUTE const _UD *actual, const _UU32 num_elements, - const char* msg, + const char *msg, const UNITY_LINE_TYPE lineNumber); void UnityAssertDoubleSpecial(const _UD actual, - const char* msg, + const char *msg, const UNITY_LINE_TYPE lineNumber, const UNITY_FLOAT_TRAIT_T style); #endif diff --git a/features/frameworks/unity/license.txt b/TESTS/COMMON/unity/license.txt similarity index 100% rename from features/frameworks/unity/license.txt rename to TESTS/COMMON/unity/license.txt diff --git a/features/frameworks/unity/mbed_lib.json b/TESTS/COMMON/unity/mbed_lib.json similarity index 100% rename from features/frameworks/unity/mbed_lib.json rename to TESTS/COMMON/unity/mbed_lib.json diff --git a/features/frameworks/unity/source/unity.c b/TESTS/COMMON/unity/source/unity.c similarity index 74% rename from features/frameworks/unity/source/unity.c rename to TESTS/COMMON/unity/source/unity.c index a1e6f3aa94a..1662739c9b0 100644 --- a/features/frameworks/unity/source/unity.c +++ b/TESTS/COMMON/unity/source/unity.c @@ -64,8 +64,7 @@ static const _UF f_zero = 0.0f; #endif /* compiler-generic print formatting masks */ -static const _U_UINT UnitySizeMask[] = -{ +static const _U_UINT UnitySizeMask[] = { 255u, /* 0xFF */ 65535u, /* 0xFFFF */ 65535u, @@ -74,7 +73,7 @@ static const _U_UINT UnitySizeMask[] = 4294967295u, 4294967295u #ifdef UNITY_SUPPORT_64 - ,0xFFFFFFFFFFFFFFFFull + , 0xFFFFFFFFFFFFFFFFull #endif }; @@ -82,34 +81,28 @@ static const _U_UINT UnitySizeMask[] = * Pretty Printers & Test Result Output Handlers *-----------------------------------------------*/ -void UnityPrint(const char* string) +void UnityPrint(const char *string) { - const char* pch = string; + const char *pch = string; - if (pch != NULL) - { - while (*pch) - { + if (pch != NULL) { + while (*pch) { /* printable characters plus CR & LF are printed */ - if ((*pch <= 126) && (*pch >= 32)) - { + if ((*pch <= 126) && (*pch >= 32)) { UNITY_OUTPUT_CHAR(*pch); } /* write escaped carriage returns */ - else if (*pch == 13) - { + else if (*pch == 13) { UNITY_OUTPUT_CHAR('\\'); UNITY_OUTPUT_CHAR('r'); } /* write escaped line feeds */ - else if (*pch == 10) - { + else if (*pch == 10) { UNITY_OUTPUT_CHAR('\\'); UNITY_OUTPUT_CHAR('n'); } /* unprintable characters are shown as codes */ - else - { + else { UNITY_OUTPUT_CHAR('\\'); UnityPrintNumberHex((_U_UINT)*pch, 2); } @@ -118,35 +111,29 @@ void UnityPrint(const char* string) } } -void UnityPrintLen(const char* string, const _UU32 length); -void UnityPrintLen(const char* string, const _UU32 length) +void UnityPrintLen(const char *string, const _UU32 length); +void UnityPrintLen(const char *string, const _UU32 length) { - const char* pch = string; + const char *pch = string; - if (pch != NULL) - { - while (*pch && (_UU32)(pch - string) < length) - { + if (pch != NULL) { + while (*pch && (_UU32)(pch - string) < length) { /* printable characters plus CR & LF are printed */ - if ((*pch <= 126) && (*pch >= 32)) - { + if ((*pch <= 126) && (*pch >= 32)) { UNITY_OUTPUT_CHAR(*pch); } /* write escaped carriage returns */ - else if (*pch == 13) - { + else if (*pch == 13) { UNITY_OUTPUT_CHAR('\\'); UNITY_OUTPUT_CHAR('r'); } /* write escaped line feeds */ - else if (*pch == 10) - { + else if (*pch == 10) { UNITY_OUTPUT_CHAR('\\'); UNITY_OUTPUT_CHAR('n'); } /* unprintable characters are shown as codes */ - else - { + else { UNITY_OUTPUT_CHAR('\\'); UnityPrintNumberHex((_U_UINT)*pch, 2); } @@ -158,16 +145,11 @@ void UnityPrintLen(const char* string, const _UU32 length) /*-----------------------------------------------*/ void UnityPrintNumberByStyle(const _U_SINT number, const UNITY_DISPLAY_STYLE_T style) { - if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT) - { + if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT) { UnityPrintNumber(number); - } - else if ((style & UNITY_DISPLAY_RANGE_UINT) == UNITY_DISPLAY_RANGE_UINT) - { - UnityPrintNumberUnsigned( (_U_UINT)number & UnitySizeMask[((_U_UINT)style & (_U_UINT)0x0F) - 1] ); - } - else - { + } else if ((style & UNITY_DISPLAY_RANGE_UINT) == UNITY_DISPLAY_RANGE_UINT) { + UnityPrintNumberUnsigned((_U_UINT)number & UnitySizeMask[((_U_UINT)style & (_U_UINT)0x0F) - 1]); + } else { UnityPrintNumberHex((_U_UINT)number, (char)((style & 0x000F) << 1)); } } @@ -177,8 +159,7 @@ void UnityPrintNumber(const _U_SINT number_to_print) { _U_UINT number = (_U_UINT)number_to_print; - if (number_to_print < 0) - { + if (number_to_print < 0) { /* A negative number, including MIN negative */ UNITY_OUTPUT_CHAR('-'); number = (_U_UINT)(-number_to_print); @@ -193,18 +174,15 @@ void UnityPrintNumberUnsigned(const _U_UINT number) _U_UINT divisor = 1; /* figure out initial divisor */ - while (number / divisor > 9) - { + while (number / divisor > 9) { divisor *= 10; } /* now mod and print, then divide divisor */ - do - { + do { UNITY_OUTPUT_CHAR((char)('0' + (number / divisor % 10))); divisor /= 10; - } - while (divisor > 0); + } while (divisor > 0); } /*-----------------------------------------------*/ @@ -215,15 +193,11 @@ void UnityPrintNumberHex(const _U_UINT number, const char nibbles_to_print) UNITY_OUTPUT_CHAR('0'); UNITY_OUTPUT_CHAR('x'); - while (nibbles > 0) - { + while (nibbles > 0) { nibble = (number >> (--nibbles << 2)) & 0x0000000F; - if (nibble <= 9) - { + if (nibble <= 9) { UNITY_OUTPUT_CHAR((char)('0' + nibble)); - } - else - { + } else { UNITY_OUTPUT_CHAR((char)('A' - 10 + nibble)); } } @@ -235,21 +209,14 @@ void UnityPrintMask(const _U_UINT mask, const _U_UINT number) _U_UINT current_bit = (_U_UINT)1 << (UNITY_INT_WIDTH - 1); _US32 i; - for (i = 0; i < UNITY_INT_WIDTH; i++) - { - if (current_bit & mask) - { - if (current_bit & number) - { + for (i = 0; i < UNITY_INT_WIDTH; i++) { + if (current_bit & mask) { + if (current_bit & number) { UNITY_OUTPUT_CHAR('1'); - } - else - { + } else { UNITY_OUTPUT_CHAR('0'); } - } - else - { + } else { UNITY_OUTPUT_CHAR('.'); } current_bit = current_bit >> 1; @@ -291,8 +258,8 @@ void UnityPrintOk(void) } /*-----------------------------------------------*/ -static void UnityTestResultsBegin(const char* file, const UNITY_LINE_TYPE line); -static void UnityTestResultsBegin(const char* file, const UNITY_LINE_TYPE line) +static void UnityTestResultsBegin(const char *file, const UNITY_LINE_TYPE line); +static void UnityTestResultsBegin(const char *file, const UNITY_LINE_TYPE line) { #ifndef UNITY_FIXTURES UnityPrint(file); @@ -323,17 +290,12 @@ static void UnityTestResultsFailBegin(const UNITY_LINE_TYPE line) /*-----------------------------------------------*/ void UnityConcludeTest(void) { - if (Unity.CurrentTestIgnored) - { + if (Unity.CurrentTestIgnored) { Unity.TestIgnores++; - } - else if (!Unity.CurrentTestFailed) - { + } else if (!Unity.CurrentTestFailed) { UnityTestResultsBegin(Unity.TestFile, Unity.CurrentTestLineNumber); UnityPrint(UnityStrPass); - } - else - { + } else { Unity.TestFailures++; } @@ -344,19 +306,16 @@ void UnityConcludeTest(void) } /*-----------------------------------------------*/ -static void UnityAddMsgIfSpecified(const char* msg); -static void UnityAddMsgIfSpecified(const char* msg) +static void UnityAddMsgIfSpecified(const char *msg); +static void UnityAddMsgIfSpecified(const char *msg) { - if (msg) - { + if (msg) { UnityPrint(UnityStrSpacer); #ifndef UNITY_EXCLUDE_DETAILS - if (Unity.CurrentDetail1) - { + if (Unity.CurrentDetail1) { UnityPrint(UnityStrDetail1Name); UnityPrint(Unity.CurrentDetail1); - if (Unity.CurrentDetail2) - { + if (Unity.CurrentDetail2) { UnityPrint(UnityStrDetail2Name); UnityPrint(Unity.CurrentDetail2); } @@ -368,57 +327,45 @@ static void UnityAddMsgIfSpecified(const char* msg) } /*-----------------------------------------------*/ -static void UnityPrintExpectedAndActualStrings(const char* expected, const char* actual); -static void UnityPrintExpectedAndActualStrings(const char* expected, const char* actual) +static void UnityPrintExpectedAndActualStrings(const char *expected, const char *actual); +static void UnityPrintExpectedAndActualStrings(const char *expected, const char *actual) { UnityPrint(UnityStrExpected); - if (expected != NULL) - { + if (expected != NULL) { UNITY_OUTPUT_CHAR('\''); UnityPrint(expected); UNITY_OUTPUT_CHAR('\''); - } - else - { - UnityPrint(UnityStrNull); + } else { + UnityPrint(UnityStrNull); } UnityPrint(UnityStrWas); - if (actual != NULL) - { + if (actual != NULL) { UNITY_OUTPUT_CHAR('\''); UnityPrint(actual); UNITY_OUTPUT_CHAR('\''); - } - else - { - UnityPrint(UnityStrNull); + } else { + UnityPrint(UnityStrNull); } } /*-----------------------------------------------*/ -static void UnityPrintExpectedAndActualStringsLen(const char* expected, const char* actual, const _UU32 length) +static void UnityPrintExpectedAndActualStringsLen(const char *expected, const char *actual, const _UU32 length) { UnityPrint(UnityStrExpected); - if (expected != NULL) - { + if (expected != NULL) { UNITY_OUTPUT_CHAR('\''); UnityPrintLen(expected, length); UNITY_OUTPUT_CHAR('\''); - } - else - { - UnityPrint(UnityStrNull); + } else { + UnityPrint(UnityStrNull); } UnityPrint(UnityStrWas); - if (actual != NULL) - { + if (actual != NULL) { UNITY_OUTPUT_CHAR('\''); UnityPrintLen(actual, length); UNITY_OUTPUT_CHAR('\''); - } - else - { - UnityPrint(UnityStrNull); + } else { + UnityPrint(UnityStrNull); } } @@ -428,15 +375,15 @@ static void UnityPrintExpectedAndActualStringsLen(const char* expected, const ch * Assertion & Control Helpers *-----------------------------------------------*/ -static int UnityCheckArraysForNull(UNITY_INTERNAL_PTR expected, UNITY_INTERNAL_PTR actual, const UNITY_LINE_TYPE lineNumber, const char* msg) +static int UnityCheckArraysForNull(UNITY_INTERNAL_PTR expected, UNITY_INTERNAL_PTR actual, const UNITY_LINE_TYPE lineNumber, const char *msg) { /* return true if they are both NULL */ - if ((expected == NULL) && (actual == NULL)) + if ((expected == NULL) && (actual == NULL)) { return 1; + } /* throw error if just expected is NULL */ - if (expected == NULL) - { + if (expected == NULL) { UnityTestResultsFailBegin(lineNumber); UnityPrint(UnityStrNullPointerForExpected); UnityAddMsgIfSpecified(msg); @@ -444,8 +391,7 @@ static int UnityCheckArraysForNull(UNITY_INTERNAL_PTR expected, UNITY_INTERNAL_P } /* throw error if just actual is NULL */ - if (actual == NULL) - { + if (actual == NULL) { UnityTestResultsFailBegin(lineNumber); UnityPrint(UnityStrNullPointerForActual); UnityAddMsgIfSpecified(msg); @@ -463,13 +409,12 @@ static int UnityCheckArraysForNull(UNITY_INTERNAL_PTR expected, UNITY_INTERNAL_P void UnityAssertBits(const _U_SINT mask, const _U_SINT expected, const _U_SINT actual, - const char* msg, + const char *msg, const UNITY_LINE_TYPE lineNumber) { UNITY_SKIP_EXECUTION; - if ((mask & expected) != (mask & actual)) - { + if ((mask & expected) != (mask & actual)) { UnityTestResultsFailBegin(lineNumber); UnityPrint(UnityStrExpected); UnityPrintMask((_U_UINT)mask, (_U_UINT)expected); @@ -483,14 +428,13 @@ void UnityAssertBits(const _U_SINT mask, /*-----------------------------------------------*/ void UnityAssertEqualNumber(const _U_SINT expected, const _U_SINT actual, - const char* msg, + const char *msg, const UNITY_LINE_TYPE lineNumber, const UNITY_DISPLAY_STYLE_T style) { UNITY_SKIP_EXECUTION; - if (expected != actual) - { + if (expected != actual) { UnityTestResultsFailBegin(lineNumber); UnityPrint(UnityStrExpected); UnityPrintNumberByStyle(expected, style); @@ -512,7 +456,7 @@ void UnityAssertEqualNumber(const _U_SINT expected, void UnityAssertEqualIntArray(UNITY_INTERNAL_PTR expected, UNITY_INTERNAL_PTR actual, const _UU32 num_elements, - const char* msg, + const char *msg, const UNITY_LINE_TYPE lineNumber, const UNITY_DISPLAY_STYLE_T style) { @@ -522,33 +466,30 @@ void UnityAssertEqualIntArray(UNITY_INTERNAL_PTR expected, UNITY_SKIP_EXECUTION; - if (elements == 0) - { + if (elements == 0) { UnityPrintPointlessAndBail(); } - if (UnityCheckArraysForNull((UNITY_INTERNAL_PTR)expected, (UNITY_INTERNAL_PTR)actual, lineNumber, msg) == 1) + if (UnityCheckArraysForNull((UNITY_INTERNAL_PTR)expected, (UNITY_INTERNAL_PTR)actual, lineNumber, msg) == 1) { return; + } /* If style is UNITY_DISPLAY_STYLE_INT, we'll fall into the default case rather than the INT16 or INT32 (etc) case * as UNITY_DISPLAY_STYLE_INT includes a flag for UNITY_DISPLAY_RANGE_AUTO, which the width-specific * variants do not. Therefore remove this flag. */ - switch(style & (UNITY_DISPLAY_STYLE_T)(~UNITY_DISPLAY_RANGE_AUTO)) - { + switch (style & (UNITY_DISPLAY_STYLE_T)(~UNITY_DISPLAY_RANGE_AUTO)) { case UNITY_DISPLAY_STYLE_HEX8: case UNITY_DISPLAY_STYLE_INT8: case UNITY_DISPLAY_STYLE_UINT8: - while (elements--) - { - if (*(UNITY_PTR_ATTRIBUTE const _US8*)ptr_exp != *(UNITY_PTR_ATTRIBUTE const _US8*)ptr_act) - { + while (elements--) { + if (*(UNITY_PTR_ATTRIBUTE const _US8 *)ptr_exp != *(UNITY_PTR_ATTRIBUTE const _US8 *)ptr_act) { UnityTestResultsFailBegin(lineNumber); UnityPrint(UnityStrElement); UnityPrintNumberUnsigned(num_elements - elements - 1); UnityPrint(UnityStrExpected); - UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE const _US8*)ptr_exp, style); + UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE const _US8 *)ptr_exp, style); UnityPrint(UnityStrWas); - UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE const _US8*)ptr_act, style); + UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE const _US8 *)ptr_act, style); UnityAddMsgIfSpecified(msg); UNITY_FAIL_AND_BAIL; } @@ -559,17 +500,15 @@ void UnityAssertEqualIntArray(UNITY_INTERNAL_PTR expected, case UNITY_DISPLAY_STYLE_HEX16: case UNITY_DISPLAY_STYLE_INT16: case UNITY_DISPLAY_STYLE_UINT16: - while (elements--) - { - if (*(UNITY_PTR_ATTRIBUTE const _US16*)ptr_exp != *(UNITY_PTR_ATTRIBUTE const _US16*)ptr_act) - { + while (elements--) { + if (*(UNITY_PTR_ATTRIBUTE const _US16 *)ptr_exp != *(UNITY_PTR_ATTRIBUTE const _US16 *)ptr_act) { UnityTestResultsFailBegin(lineNumber); UnityPrint(UnityStrElement); UnityPrintNumberUnsigned(num_elements - elements - 1); UnityPrint(UnityStrExpected); - UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE const _US16*)ptr_exp, style); + UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE const _US16 *)ptr_exp, style); UnityPrint(UnityStrWas); - UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE const _US16*)ptr_act, style); + UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE const _US16 *)ptr_act, style); UnityAddMsgIfSpecified(msg); UNITY_FAIL_AND_BAIL; } @@ -581,17 +520,15 @@ void UnityAssertEqualIntArray(UNITY_INTERNAL_PTR expected, case UNITY_DISPLAY_STYLE_HEX64: case UNITY_DISPLAY_STYLE_INT64: case UNITY_DISPLAY_STYLE_UINT64: - while (elements--) - { - if (*(UNITY_PTR_ATTRIBUTE const _US64*)ptr_exp != *(UNITY_PTR_ATTRIBUTE const _US64*)ptr_act) - { + while (elements--) { + if (*(UNITY_PTR_ATTRIBUTE const _US64 *)ptr_exp != *(UNITY_PTR_ATTRIBUTE const _US64 *)ptr_act) { UnityTestResultsFailBegin(lineNumber); UnityPrint(UnityStrElement); UnityPrintNumberUnsigned(num_elements - elements - 1); UnityPrint(UnityStrExpected); - UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE const _US64*)ptr_exp, style); + UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE const _US64 *)ptr_exp, style); UnityPrint(UnityStrWas); - UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE const _US64*)ptr_act, style); + UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE const _US64 *)ptr_act, style); UnityAddMsgIfSpecified(msg); UNITY_FAIL_AND_BAIL; } @@ -601,17 +538,15 @@ void UnityAssertEqualIntArray(UNITY_INTERNAL_PTR expected, break; #endif default: - while (elements--) - { - if (*(UNITY_PTR_ATTRIBUTE const _US32*)ptr_exp != *(UNITY_PTR_ATTRIBUTE const _US32*)ptr_act) - { + while (elements--) { + if (*(UNITY_PTR_ATTRIBUTE const _US32 *)ptr_exp != *(UNITY_PTR_ATTRIBUTE const _US32 *)ptr_act) { UnityTestResultsFailBegin(lineNumber); UnityPrint(UnityStrElement); UnityPrintNumberUnsigned(num_elements - elements - 1); UnityPrint(UnityStrExpected); - UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE const _US32*)ptr_exp, style); + UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE const _US32 *)ptr_exp, style); UnityPrint(UnityStrWas); - UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE const _US32*)ptr_act, style); + UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE const _US32 *)ptr_act, style); UnityAddMsgIfSpecified(msg); UNITY_FAIL_AND_BAIL; } @@ -624,39 +559,39 @@ void UnityAssertEqualIntArray(UNITY_INTERNAL_PTR expected, /*-----------------------------------------------*/ #ifndef UNITY_EXCLUDE_FLOAT -void UnityAssertEqualFloatArray(UNITY_PTR_ATTRIBUTE const _UF* expected, - UNITY_PTR_ATTRIBUTE const _UF* actual, +void UnityAssertEqualFloatArray(UNITY_PTR_ATTRIBUTE const _UF *expected, + UNITY_PTR_ATTRIBUTE const _UF *actual, const _UU32 num_elements, - const char* msg, + const char *msg, const UNITY_LINE_TYPE lineNumber) { _UU32 elements = num_elements; - UNITY_PTR_ATTRIBUTE const _UF* ptr_expected = expected; - UNITY_PTR_ATTRIBUTE const _UF* ptr_actual = actual; + UNITY_PTR_ATTRIBUTE const _UF *ptr_expected = expected; + UNITY_PTR_ATTRIBUTE const _UF *ptr_actual = actual; _UF diff, tol; UNITY_SKIP_EXECUTION; - if (elements == 0) - { + if (elements == 0) { UnityPrintPointlessAndBail(); } - if (UnityCheckArraysForNull((UNITY_INTERNAL_PTR)expected, (UNITY_INTERNAL_PTR)actual, lineNumber, msg) == 1) + if (UnityCheckArraysForNull((UNITY_INTERNAL_PTR)expected, (UNITY_INTERNAL_PTR)actual, lineNumber, msg) == 1) { return; + } - while (elements--) - { + while (elements--) { diff = *ptr_expected - *ptr_actual; - if (diff < 0.0f) + if (diff < 0.0f) { diff = 0.0f - diff; + } tol = UNITY_FLOAT_PRECISION * *ptr_expected; - if (tol < 0.0f) + if (tol < 0.0f) { tol = 0.0f - tol; + } /* This first part of this condition will catch any NaN or Infinite values */ - if (isnan(diff) || isinf(diff) || (diff > tol)) - { + if (isnan(diff) || isinf(diff) || (diff > tol)) { UnityTestResultsFailBegin(lineNumber); UnityPrint(UnityStrElement); UnityPrintNumberUnsigned(num_elements - elements - 1); @@ -680,7 +615,7 @@ void UnityAssertEqualFloatArray(UNITY_PTR_ATTRIBUTE const _UF* expected, void UnityAssertFloatsWithin(const _UF delta, const _UF expected, const _UF actual, - const char* msg, + const char *msg, const UNITY_LINE_TYPE lineNumber) { _UF diff = actual - expected; @@ -688,18 +623,15 @@ void UnityAssertFloatsWithin(const _UF delta, UNITY_SKIP_EXECUTION; - if (diff < 0.0f) - { + if (diff < 0.0f) { diff = 0.0f - diff; } - if (pos_delta < 0.0f) - { + if (pos_delta < 0.0f) { pos_delta = 0.0f - pos_delta; } /* This first part of this condition will catch any NaN or Infinite values */ - if (isnan(diff) || isinf(diff) || (pos_delta < diff)) - { + if (isnan(diff) || isinf(diff) || (pos_delta < diff)) { UnityTestResultsFailBegin(lineNumber); #ifdef UNITY_FLOAT_VERBOSE UnityPrint(UnityStrExpected); @@ -716,19 +648,18 @@ void UnityAssertFloatsWithin(const _UF delta, /*-----------------------------------------------*/ void UnityAssertFloatSpecial(const _UF actual, - const char* msg, + const char *msg, const UNITY_LINE_TYPE lineNumber, const UNITY_FLOAT_TRAIT_T style) { - const char* trait_names[] = { UnityStrInf, UnityStrNegInf, UnityStrNaN, UnityStrDet }; + const char *trait_names[] = { UnityStrInf, UnityStrNegInf, UnityStrNaN, UnityStrDet }; _U_SINT should_be_trait = ((_U_SINT)style & 1); _U_SINT is_trait = !should_be_trait; _U_SINT trait_index = (_U_SINT)(style >> 1); UNITY_SKIP_EXECUTION; - switch(style) - { + switch (style) { /* To determine Inf / Neg Inf, we compare to an Inf / Neg Inf value we create on the fly * We are using a variable to hold the zero value because some compilers complain about dividing by zero otherwise */ case UNITY_FLOAT_IS_INF: @@ -749,10 +680,11 @@ void UnityAssertFloatSpecial(const _UF actual, /* A determinate number is non infinite and not NaN. (therefore the opposite of the two above) */ case UNITY_FLOAT_IS_DET: case UNITY_FLOAT_IS_NOT_DET: - if (isinf(actual) | isnan(actual)) + if (isinf(actual) | isnan(actual)) { is_trait = 0; - else + } else { is_trait = 1; + } break; default: @@ -761,19 +693,20 @@ void UnityAssertFloatSpecial(const _UF actual, break; } - if (is_trait != should_be_trait) - { + if (is_trait != should_be_trait) { UnityTestResultsFailBegin(lineNumber); UnityPrint(UnityStrExpected); - if (!should_be_trait) + if (!should_be_trait) { UnityPrint(UnityStrNot); + } UnityPrint(trait_names[trait_index]); UnityPrint(UnityStrWas); #ifdef UNITY_FLOAT_VERBOSE UnityPrintFloat(actual); #else - if (should_be_trait) + if (should_be_trait) { UnityPrint(UnityStrNot); + } UnityPrint(trait_names[trait_index]); #endif UnityAddMsgIfSpecified(msg); @@ -785,39 +718,39 @@ void UnityAssertFloatSpecial(const _UF actual, /*-----------------------------------------------*/ #ifndef UNITY_EXCLUDE_DOUBLE -void UnityAssertEqualDoubleArray(UNITY_PTR_ATTRIBUTE const _UD* expected, - UNITY_PTR_ATTRIBUTE const _UD* actual, +void UnityAssertEqualDoubleArray(UNITY_PTR_ATTRIBUTE const _UD *expected, + UNITY_PTR_ATTRIBUTE const _UD *actual, const _UU32 num_elements, - const char* msg, + const char *msg, const UNITY_LINE_TYPE lineNumber) { _UU32 elements = num_elements; - UNITY_PTR_ATTRIBUTE const _UD* ptr_expected = expected; - UNITY_PTR_ATTRIBUTE const _UD* ptr_actual = actual; + UNITY_PTR_ATTRIBUTE const _UD *ptr_expected = expected; + UNITY_PTR_ATTRIBUTE const _UD *ptr_actual = actual; _UD diff, tol; UNITY_SKIP_EXECUTION; - if (elements == 0) - { + if (elements == 0) { UnityPrintPointlessAndBail(); } - if (UnityCheckArraysForNull((UNITY_INTERNAL_PTR)expected, (UNITY_INTERNAL_PTR)actual, lineNumber, msg) == 1) + if (UnityCheckArraysForNull((UNITY_INTERNAL_PTR)expected, (UNITY_INTERNAL_PTR)actual, lineNumber, msg) == 1) { return; + } - while (elements--) - { + while (elements--) { diff = *ptr_expected - *ptr_actual; - if (diff < 0.0) - diff = 0.0 - diff; + if (diff < 0.0) { + diff = 0.0 - diff; + } tol = UNITY_DOUBLE_PRECISION * *ptr_expected; - if (tol < 0.0) + if (tol < 0.0) { tol = 0.0 - tol; + } /* This first part of this condition will catch any NaN or Infinite values */ - if (isnan(diff) || isinf(diff) || (diff > tol)) - { + if (isnan(diff) || isinf(diff) || (diff > tol)) { UnityTestResultsFailBegin(lineNumber); UnityPrint(UnityStrElement); UnityPrintNumberUnsigned(num_elements - elements - 1); @@ -841,7 +774,7 @@ void UnityAssertEqualDoubleArray(UNITY_PTR_ATTRIBUTE const _UD* expected, void UnityAssertDoublesWithin(const _UD delta, const _UD expected, const _UD actual, - const char* msg, + const char *msg, const UNITY_LINE_TYPE lineNumber) { _UD diff = actual - expected; @@ -849,18 +782,15 @@ void UnityAssertDoublesWithin(const _UD delta, UNITY_SKIP_EXECUTION; - if (diff < 0.0) - { + if (diff < 0.0) { diff = 0.0 - diff; } - if (pos_delta < 0.0) - { + if (pos_delta < 0.0) { pos_delta = 0.0 - pos_delta; } /* This first part of this condition will catch any NaN or Infinite values */ - if (isnan(diff) || isinf(diff) || (pos_delta < diff)) - { + if (isnan(diff) || isinf(diff) || (pos_delta < diff)) { UnityTestResultsFailBegin(lineNumber); #ifdef UNITY_DOUBLE_VERBOSE UnityPrint(UnityStrExpected); @@ -878,19 +808,18 @@ void UnityAssertDoublesWithin(const _UD delta, /*-----------------------------------------------*/ void UnityAssertDoubleSpecial(const _UD actual, - const char* msg, + const char *msg, const UNITY_LINE_TYPE lineNumber, const UNITY_FLOAT_TRAIT_T style) { - const char* trait_names[] = { UnityStrInf, UnityStrNegInf, UnityStrNaN, UnityStrDet }; + const char *trait_names[] = { UnityStrInf, UnityStrNegInf, UnityStrNaN, UnityStrDet }; _U_SINT should_be_trait = ((_U_SINT)style & 1); _U_SINT is_trait = !should_be_trait; _U_SINT trait_index = (_U_SINT)(style >> 1); UNITY_SKIP_EXECUTION; - switch(style) - { + switch (style) { /* To determine Inf / Neg Inf, we compare to an Inf / Neg Inf value we create on the fly * We are using a variable to hold the zero value because some compilers complain about dividing by zero otherwise */ case UNITY_FLOAT_IS_INF: @@ -911,10 +840,11 @@ void UnityAssertDoubleSpecial(const _UD actual, /* A determinate number is non infinite and not NaN. (therefore the opposite of the two above) */ case UNITY_FLOAT_IS_DET: case UNITY_FLOAT_IS_NOT_DET: - if (isinf(actual) | isnan(actual)) + if (isinf(actual) | isnan(actual)) { is_trait = 0; - else + } else { is_trait = 1; + } break; default: @@ -923,19 +853,20 @@ void UnityAssertDoubleSpecial(const _UD actual, break; } - if (is_trait != should_be_trait) - { + if (is_trait != should_be_trait) { UnityTestResultsFailBegin(lineNumber); UnityPrint(UnityStrExpected); - if (!should_be_trait) + if (!should_be_trait) { UnityPrint(UnityStrNot); + } UnityPrint(trait_names[trait_index]); UnityPrint(UnityStrWas); #ifdef UNITY_DOUBLE_VERBOSE UnityPrintFloat(actual); #else - if (should_be_trait) + if (should_be_trait) { UnityPrint(UnityStrNot); + } UnityPrint(trait_names[trait_index]); #endif UnityAddMsgIfSpecified(msg); @@ -947,32 +878,30 @@ void UnityAssertDoubleSpecial(const _UD actual, #endif /* not UNITY_EXCLUDE_DOUBLE */ /*-----------------------------------------------*/ -void UnityAssertNumbersWithin( const _U_UINT delta, - const _U_SINT expected, - const _U_SINT actual, - const char* msg, - const UNITY_LINE_TYPE lineNumber, - const UNITY_DISPLAY_STYLE_T style) +void UnityAssertNumbersWithin(const _U_UINT delta, + const _U_SINT expected, + const _U_SINT actual, + const char *msg, + const UNITY_LINE_TYPE lineNumber, + const UNITY_DISPLAY_STYLE_T style) { UNITY_SKIP_EXECUTION; - if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT) - { - if (actual > expected) + if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT) { + if (actual > expected) { Unity.CurrentTestFailed = ((_U_UINT)(actual - expected) > delta); - else + } else { Unity.CurrentTestFailed = ((_U_UINT)(expected - actual) > delta); - } - else - { - if ((_U_UINT)actual > (_U_UINT)expected) + } + } else { + if ((_U_UINT)actual > (_U_UINT)expected) { Unity.CurrentTestFailed = ((_U_UINT)(actual - expected) > delta); - else + } else { Unity.CurrentTestFailed = ((_U_UINT)(expected - actual) > delta); + } } - if (Unity.CurrentTestFailed) - { + if (Unity.CurrentTestFailed) { UnityTestResultsFailBegin(lineNumber); UnityPrint(UnityStrDelta); UnityPrintNumberByStyle((_U_SINT)delta, style); @@ -986,9 +915,9 @@ void UnityAssertNumbersWithin( const _U_UINT delta, } /*-----------------------------------------------*/ -void UnityAssertEqualString(const char* expected, - const char* actual, - const char* msg, +void UnityAssertEqualString(const char *expected, + const char *actual, + const char *msg, const UNITY_LINE_TYPE lineNumber) { _UU32 i; @@ -996,126 +925,106 @@ void UnityAssertEqualString(const char* expected, UNITY_SKIP_EXECUTION; /* if both pointers not null compare the strings */ - if (expected && actual) - { - for (i = 0; expected[i] || actual[i]; i++) - { - if (expected[i] != actual[i]) - { + if (expected && actual) { + for (i = 0; expected[i] || actual[i]; i++) { + if (expected[i] != actual[i]) { Unity.CurrentTestFailed = 1; break; } } - } - else - { /* handle case of one pointers being null (if both null, test should pass) */ - if (expected != actual) - { + } else { + /* handle case of one pointers being null (if both null, test should pass) */ + if (expected != actual) { Unity.CurrentTestFailed = 1; } } - if (Unity.CurrentTestFailed) - { - UnityTestResultsFailBegin(lineNumber); - UnityPrintExpectedAndActualStrings(expected, actual); - UnityAddMsgIfSpecified(msg); - UNITY_FAIL_AND_BAIL; + if (Unity.CurrentTestFailed) { + UnityTestResultsFailBegin(lineNumber); + UnityPrintExpectedAndActualStrings(expected, actual); + UnityAddMsgIfSpecified(msg); + UNITY_FAIL_AND_BAIL; } } /*-----------------------------------------------*/ -void UnityAssertEqualStringLen(const char* expected, - const char* actual, - const _UU32 length, - const char* msg, - const UNITY_LINE_TYPE lineNumber) +void UnityAssertEqualStringLen(const char *expected, + const char *actual, + const _UU32 length, + const char *msg, + const UNITY_LINE_TYPE lineNumber) { _UU32 i; UNITY_SKIP_EXECUTION; /* if both pointers not null compare the strings */ - if (expected && actual) - { - for (i = 0; (expected[i] || actual[i]) && i < length; i++) - { - if (expected[i] != actual[i]) - { + if (expected && actual) { + for (i = 0; (expected[i] || actual[i]) && i < length; i++) { + if (expected[i] != actual[i]) { Unity.CurrentTestFailed = 1; break; } } - } - else - { /* handle case of one pointers being null (if both null, test should pass) */ - if (expected != actual) - { + } else { + /* handle case of one pointers being null (if both null, test should pass) */ + if (expected != actual) { Unity.CurrentTestFailed = 1; } } - if (Unity.CurrentTestFailed) - { - UnityTestResultsFailBegin(lineNumber); - UnityPrintExpectedAndActualStringsLen(expected, actual, length); - UnityAddMsgIfSpecified(msg); - UNITY_FAIL_AND_BAIL; + if (Unity.CurrentTestFailed) { + UnityTestResultsFailBegin(lineNumber); + UnityPrintExpectedAndActualStringsLen(expected, actual, length); + UnityAddMsgIfSpecified(msg); + UNITY_FAIL_AND_BAIL; } } /*-----------------------------------------------*/ -void UnityAssertEqualStringArray( const char** expected, - const char** actual, - const _UU32 num_elements, - const char* msg, - const UNITY_LINE_TYPE lineNumber) +void UnityAssertEqualStringArray(const char **expected, + const char **actual, + const _UU32 num_elements, + const char *msg, + const UNITY_LINE_TYPE lineNumber) { _UU32 i, j = 0; UNITY_SKIP_EXECUTION; /* if no elements, it's an error */ - if (num_elements == 0) - { + if (num_elements == 0) { UnityPrintPointlessAndBail(); } - if (UnityCheckArraysForNull((UNITY_INTERNAL_PTR)expected, (UNITY_INTERNAL_PTR)actual, lineNumber, msg) == 1) + if (UnityCheckArraysForNull((UNITY_INTERNAL_PTR)expected, (UNITY_INTERNAL_PTR)actual, lineNumber, msg) == 1) { return; + } - do - { + do { /* if both pointers not null compare the strings */ - if (expected[j] && actual[j]) - { - for (i = 0; expected[j][i] || actual[j][i]; i++) - { - if (expected[j][i] != actual[j][i]) - { + if (expected[j] && actual[j]) { + for (i = 0; expected[j][i] || actual[j][i]; i++) { + if (expected[j][i] != actual[j][i]) { Unity.CurrentTestFailed = 1; break; } } - } - else - { /* handle case of one pointers being null (if both null, test should pass) */ - if (expected[j] != actual[j]) - { + } else { + /* handle case of one pointers being null (if both null, test should pass) */ + if (expected[j] != actual[j]) { Unity.CurrentTestFailed = 1; } } - if (Unity.CurrentTestFailed) - { + if (Unity.CurrentTestFailed) { UnityTestResultsFailBegin(lineNumber); - if (num_elements > 1) - { + if (num_elements > 1) { UnityPrint(UnityStrElement); UnityPrintNumberUnsigned(j); } - UnityPrintExpectedAndActualStrings((const char*)(expected[j]), (const char*)(actual[j])); + UnityPrintExpectedAndActualStrings((const char *)(expected[j]), (const char *)(actual[j])); UnityAddMsgIfSpecified(msg); UNITY_FAIL_AND_BAIL; } @@ -1123,40 +1032,36 @@ void UnityAssertEqualStringArray( const char** expected, } /*-----------------------------------------------*/ -void UnityAssertEqualMemory( UNITY_INTERNAL_PTR expected, - UNITY_INTERNAL_PTR actual, - const _UU32 length, - const _UU32 num_elements, - const char* msg, - const UNITY_LINE_TYPE lineNumber) +void UnityAssertEqualMemory(UNITY_INTERNAL_PTR expected, + UNITY_INTERNAL_PTR actual, + const _UU32 length, + const _UU32 num_elements, + const char *msg, + const UNITY_LINE_TYPE lineNumber) { - UNITY_PTR_ATTRIBUTE const unsigned char* ptr_exp = (UNITY_PTR_ATTRIBUTE const unsigned char*)expected; - UNITY_PTR_ATTRIBUTE const unsigned char* ptr_act = (UNITY_PTR_ATTRIBUTE const unsigned char*)actual; + UNITY_PTR_ATTRIBUTE const unsigned char *ptr_exp = (UNITY_PTR_ATTRIBUTE const unsigned char *)expected; + UNITY_PTR_ATTRIBUTE const unsigned char *ptr_act = (UNITY_PTR_ATTRIBUTE const unsigned char *)actual; _UU32 elements = num_elements; _UU32 bytes; UNITY_SKIP_EXECUTION; - if ((elements == 0) || (length == 0)) - { + if ((elements == 0) || (length == 0)) { UnityPrintPointlessAndBail(); } - if (UnityCheckArraysForNull((UNITY_INTERNAL_PTR)expected, (UNITY_INTERNAL_PTR)actual, lineNumber, msg) == 1) + if (UnityCheckArraysForNull((UNITY_INTERNAL_PTR)expected, (UNITY_INTERNAL_PTR)actual, lineNumber, msg) == 1) { return; + } - while (elements--) - { + while (elements--) { /* /////////////////////////////////// */ bytes = length; - while (bytes--) - { - if (*ptr_exp != *ptr_act) - { + while (bytes--) { + if (*ptr_exp != *ptr_act) { UnityTestResultsFailBegin(lineNumber); UnityPrint(UnityStrMemory); - if (num_elements > 1) - { + if (num_elements > 1) { UnityPrint(UnityStrElement); UnityPrintNumberUnsigned(num_elements - elements - 1); } @@ -1181,31 +1086,27 @@ void UnityAssertEqualMemory( UNITY_INTERNAL_PTR expected, * Control Functions *-----------------------------------------------*/ -void UnityFail(const char* msg, const UNITY_LINE_TYPE line) +void UnityFail(const char *msg, const UNITY_LINE_TYPE line) { UNITY_SKIP_EXECUTION; UnityTestResultsBegin(Unity.TestFile, line); UnityPrintFail(); - if (msg != NULL) - { + if (msg != NULL) { UNITY_OUTPUT_CHAR(':'); #ifndef UNITY_EXCLUDE_DETAILS - if (Unity.CurrentDetail1) - { + if (Unity.CurrentDetail1) { UnityPrint(UnityStrDetail1Name); UnityPrint(Unity.CurrentDetail1); - if (Unity.CurrentDetail2) - { + if (Unity.CurrentDetail2) { UnityPrint(UnityStrDetail2Name); UnityPrint(Unity.CurrentDetail2); } UnityPrint(UnityStrSpacer); } #endif - if (msg[0] != ' ') - { + if (msg[0] != ' ') { UNITY_OUTPUT_CHAR(' '); } UnityPrint(msg); @@ -1214,65 +1115,61 @@ void UnityFail(const char* msg, const UNITY_LINE_TYPE line) } /*-----------------------------------------------*/ -void UnityIgnore(const char* msg, const UNITY_LINE_TYPE line) +void UnityIgnore(const char *msg, const UNITY_LINE_TYPE line) { UNITY_SKIP_EXECUTION; UnityTestResultsBegin(Unity.TestFile, line); UnityPrint(UnityStrIgnore); - if (msg != NULL) - { - UNITY_OUTPUT_CHAR(':'); - UNITY_OUTPUT_CHAR(' '); - UnityPrint(msg); + if (msg != NULL) { + UNITY_OUTPUT_CHAR(':'); + UNITY_OUTPUT_CHAR(' '); + UnityPrint(msg); } UNITY_IGNORE_AND_BAIL; } /*-----------------------------------------------*/ -void UnitySkipPrint(const char* msg, const UNITY_LINE_TYPE line) +void UnitySkipPrint(const char *msg, const UNITY_LINE_TYPE line) { UnityTestResultsBegin(Unity.TestFile, line); UnityPrint(UnityStrSkip); - if (msg != NULL) - { - UNITY_OUTPUT_CHAR(':'); - UNITY_OUTPUT_CHAR(' '); - UnityPrint(msg); + if (msg != NULL) { + UNITY_OUTPUT_CHAR(':'); + UNITY_OUTPUT_CHAR(' '); + UnityPrint(msg); } } /*-----------------------------------------------*/ #if defined(UNITY_WEAK_ATTRIBUTE) - UNITY_WEAK_ATTRIBUTE void setUp(void) { } - UNITY_WEAK_ATTRIBUTE void tearDown(void) { } +UNITY_WEAK_ATTRIBUTE void setUp(void) { } +UNITY_WEAK_ATTRIBUTE void tearDown(void) { } #elif defined(UNITY_WEAK_PRAGMA) # pragma weak setUp - void setUp(void) { } +void setUp(void) { } # pragma weak tearDown - void tearDown(void) { } +void tearDown(void) { } #endif /*-----------------------------------------------*/ -void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int FuncLineNum) +void UnityDefaultTestRun(UnityTestFunction Func, const char *FuncName, const int FuncLineNum) { Unity.CurrentTestName = FuncName; Unity.CurrentTestLineNumber = (UNITY_LINE_TYPE)FuncLineNum; Unity.NumberOfTests++; UNITY_CLR_DETAILS(); - if (TEST_PROTECT()) - { + if (TEST_PROTECT()) { setUp(); Func(); } - if (TEST_PROTECT() && !(Unity.CurrentTestIgnored)) - { + if (TEST_PROTECT() && !(Unity.CurrentTestIgnored)) { tearDown(); } UnityConcludeTest(); } /*-----------------------------------------------*/ -void UnityBegin(const char* filename) +void UnityBegin(const char *filename) { Unity.TestFile = filename; Unity.CurrentTestName = NULL; @@ -1300,15 +1197,13 @@ int UnityEnd(void) UnityPrintNumber((_U_SINT)(Unity.TestIgnores)); UnityPrint(UnityStrResultsIgnored); UNITY_PRINT_EOL(); - if (Unity.TestFailures == 0U) - { + if (Unity.TestFailures == 0U) { UnityPrintOk(); - } - else - { + } else { UnityPrintFail(); #ifdef UNITY_DIFFERENTIATE_FINAL_FAIL - UNITY_OUTPUT_CHAR('E'); UNITY_OUTPUT_CHAR('D'); + UNITY_OUTPUT_CHAR('E'); + UNITY_OUTPUT_CHAR('D'); #endif } UNITY_PRINT_EOL(); diff --git a/features/frameworks/utest/README.md b/TESTS/COMMON/utest/README.md similarity index 100% rename from features/frameworks/utest/README.md rename to TESTS/COMMON/utest/README.md diff --git a/features/frameworks/utest/TESTS/readme/main_cpp_template b/TESTS/COMMON/utest/TESTS/readme/main_cpp_template similarity index 100% rename from features/frameworks/utest/TESTS/readme/main_cpp_template rename to TESTS/COMMON/utest/TESTS/readme/main_cpp_template diff --git a/features/frameworks/utest/TESTS/unit_tests/basic_test/main.cpp b/TESTS/COMMON/utest/TESTS/unit_tests/basic_test/main.cpp similarity index 92% rename from features/frameworks/utest/TESTS/unit_tests/basic_test/main.cpp rename to TESTS/COMMON/utest/TESTS/unit_tests/basic_test/main.cpp index 0a647f6b248..b2c394bab34 100644 --- a/features/frameworks/utest/TESTS/unit_tests/basic_test/main.cpp +++ b/TESTS/COMMON/utest/TESTS/unit_tests/basic_test/main.cpp @@ -21,19 +21,22 @@ using namespace utest::v1; -void test_simple() { +void test_simple() +{ UTEST_LOG_FUNCTION(); TEST_ASSERT_EQUAL(0, 0); } -utest::v1::status_t test_repeats_setup(const Case *const source, const size_t index_of_case) { +utest::v1::status_t test_repeats_setup(const Case *const source, const size_t index_of_case) +{ UTEST_LOG_FUNCTION(); // Call the default handler for proper reporting utest::v1::status_t status = greentea_case_setup_handler(source, index_of_case); utest_printf("Setting up for '%s'\n", source->get_description()); return status; } -control_t test_repeats(const size_t call_count) { +control_t test_repeats(const size_t call_count) +{ UTEST_LOG_FUNCTION(); TEST_ASSERT_NOT_EQUAL(3, call_count); // Specify how often this test is repeated ie. n total calls @@ -41,7 +44,8 @@ control_t test_repeats(const size_t call_count) { } // Custom setup handler required for proper Greentea support -utest::v1::status_t greentea_setup(const size_t number_of_cases) { +utest::v1::status_t greentea_setup(const size_t number_of_cases) +{ UTEST_LOG_FUNCTION(); GREENTEA_SETUP(20, "default_auto"); // Call the default reporting function @@ -57,7 +61,7 @@ Case cases[] = { // Declare your test specification with a custom setup handler Specification specification(greentea_setup, cases); -extern void utest_run(const Specification& specification); +extern void utest_run(const Specification &specification); int main() { diff --git a/features/frameworks/utest/TESTS/unit_tests/basic_test_default/main.cpp b/TESTS/COMMON/utest/TESTS/unit_tests/basic_test_default/main.cpp similarity index 92% rename from features/frameworks/utest/TESTS/unit_tests/basic_test_default/main.cpp rename to TESTS/COMMON/utest/TESTS/unit_tests/basic_test_default/main.cpp index 38c808d6e6d..2194cf27c62 100644 --- a/features/frameworks/utest/TESTS/unit_tests/basic_test_default/main.cpp +++ b/TESTS/COMMON/utest/TESTS/unit_tests/basic_test_default/main.cpp @@ -24,19 +24,22 @@ using namespace utest::v1; -void test_simple() { +void test_simple() +{ UTEST_LOG_FUNCTION(); TEST_ASSERT_EQUAL(0, 0); } -utest::v1::status_t test_repeats_setup(const Case *const source, const size_t index_of_case) { +utest::v1::status_t test_repeats_setup(const Case *const source, const size_t index_of_case) +{ UTEST_LOG_FUNCTION(); // Call the default handler for proper reporting utest::v1::status_t status = greentea_case_setup_handler(source, index_of_case); utest_printf("Setting up for '%s'\n", source->get_description()); return status; } -control_t test_repeats(const size_t call_count) { +control_t test_repeats(const size_t call_count) +{ UTEST_LOG_FUNCTION(); TEST_ASSERT_NOT_EQUAL(3, call_count); // Specify how often this test is repeated ie. n total calls @@ -54,7 +57,7 @@ Case cases[] = { // the default handler will be used. Specification specification(cases); -extern void utest_run(const Specification& specification); +extern void utest_run(const Specification &specification); int main() { diff --git a/features/frameworks/utest/TESTS/unit_tests/case_async_validate/main.cpp b/TESTS/COMMON/utest/TESTS/unit_tests/case_async_validate/main.cpp similarity index 99% rename from features/frameworks/utest/TESTS/unit_tests/case_async_validate/main.cpp rename to TESTS/COMMON/utest/TESTS/unit_tests/case_async_validate/main.cpp index 44e7f737f4e..a75cdddc7ce 100644 --- a/features/frameworks/utest/TESTS/unit_tests/case_async_validate/main.cpp +++ b/TESTS/COMMON/utest/TESTS/unit_tests/case_async_validate/main.cpp @@ -215,7 +215,7 @@ void greentea_teardown(const size_t passed, const size_t failed, const failure_t } Specification specification(greentea_setup, cases, greentea_teardown, selftest_handlers); -extern void utest_run(const Specification& specification); +extern void utest_run(const Specification &specification); int main() { diff --git a/features/frameworks/utest/TESTS/unit_tests/case_control_async/main.cpp b/TESTS/COMMON/utest/TESTS/unit_tests/case_control_async/main.cpp similarity index 91% rename from features/frameworks/utest/TESTS/unit_tests/case_control_async/main.cpp rename to TESTS/COMMON/utest/TESTS/unit_tests/case_control_async/main.cpp index e315e03f82a..f82617ada3a 100644 --- a/features/frameworks/utest/TESTS/unit_tests/case_control_async/main.cpp +++ b/TESTS/COMMON/utest/TESTS/unit_tests/case_control_async/main.cpp @@ -29,21 +29,22 @@ static Timeout utest_to; class Utest_func_bind { public: - inline Utest_func_bind( void (*f)(int), int v) : _callback_fn(f), _callback_value(v) - {} + inline Utest_func_bind(void (*f)(int), int v) : _callback_fn(f), _callback_value(v) + {} - inline void callback() { + inline void callback() + { (*_callback_fn)(_callback_value); - } + } private: void (*_callback_fn)(int); int _callback_value; }; - - -void await_case_validate(int expected_call_count) + + +void await_case_validate(int expected_call_count) { UTEST_LOG_FUNCTION(); TEST_ASSERT_EQUAL(expected_call_count, call_counter++); @@ -54,8 +55,8 @@ static Utest_func_bind validate1(await_case_validate, 7); static Utest_func_bind validate2(await_case_validate, 37); static Utest_func_bind validate3(await_case_validate, 50); - - + + // Control: Timeout (Failure) ----------------------------------------------------------------------------------------- control_t timeout_failure_case(const size_t call_count) { @@ -85,7 +86,8 @@ utest::v1::status_t timeout_failure_case_teardown(const Case *const source, cons } // Control: Timeout (Success) ----------------------------------------------------------------------------------------- -void timeout_success_case_validate() { +void timeout_success_case_validate() +{ UTEST_LOG_FUNCTION(); TEST_ASSERT_EQUAL(4, call_counter++); Harness::validate_callback(); @@ -96,7 +98,7 @@ control_t timeout_success_case(const size_t call_count) UTEST_LOG_FUNCTION(); TEST_ASSERT_EQUAL(1, call_count); TEST_ASSERT_EQUAL(3, call_counter++); - utest_to.attach_us(timeout_success_case_validate, 100000); // Fire after 100 ms + utest_to.attach_us(timeout_success_case_validate, 100000); // Fire after 100 ms return CaseTimeout(200); } @@ -117,9 +119,9 @@ control_t await_case(const size_t call_count) UTEST_LOG_FUNCTION(); TEST_ASSERT_EQUAL(1, call_count); TEST_ASSERT_EQUAL(6, call_counter++); - - utest_to.attach_us(callback(&validate1, &Utest_func_bind::callback), (1372*1000)); // Fire after 1372 ms - + + utest_to.attach_us(callback(&validate1, &Utest_func_bind::callback), (1372 * 1000)); // Fire after 1372 ms + return CaseAwait; } @@ -127,14 +129,14 @@ control_t await_case(const size_t call_count) bool repeat_all_start_flag = true; utest::v1::status_t repeat_all_on_timeout_case_setup(const Case *const source, const size_t index_of_case) { - if (repeat_all_start_flag){ - UTEST_TRACE_START - repeat_all_start_flag = false; + if (repeat_all_start_flag) { + UTEST_TRACE_START + repeat_all_start_flag = false; } UTEST_LOG_FUNCTION(); static int repeat_counter(0); TEST_ASSERT_EQUAL(3, index_of_case); - TEST_ASSERT_EQUAL(repeat_counter*3 + 8, call_counter++); + TEST_ASSERT_EQUAL(repeat_counter * 3 + 8, call_counter++); repeat_counter++; return greentea_case_setup_handler(source, index_of_case); } @@ -144,9 +146,9 @@ control_t repeat_all_on_timeout_case(const size_t call_count) static int repeat_counter(1); TEST_ASSERT_EQUAL(repeat_counter++, call_count); TEST_ASSERT(call_count <= 10); - TEST_ASSERT_EQUAL((call_count-1)*3 + 9, call_counter++); + TEST_ASSERT_EQUAL((call_count - 1) * 3 + 9, call_counter++); if (call_count == 10) { - utest_to.attach_us(callback(&validate2, &Utest_func_bind::callback), (50*1000)); // Fire after 50ms + utest_to.attach_us(callback(&validate2, &Utest_func_bind::callback), (50 * 1000)); // Fire after 50ms } return CaseRepeatAllOnTimeout(100); } @@ -154,12 +156,12 @@ utest::v1::status_t repeat_all_on_timeout_case_teardown(const Case *const source { UTEST_LOG_FUNCTION(); static int repeat_counter(0); - + TEST_ASSERT_EQUAL((call_counter == 38) ? 1 : 0, passed); TEST_ASSERT_EQUAL(0, failed); TEST_ASSERT_EQUAL(REASON_NONE, failure.reason); TEST_ASSERT_EQUAL(LOCATION_NONE, failure.location); - TEST_ASSERT_EQUAL(repeat_counter*3 + ((repeat_counter == 9) ? 11 : 10), call_counter++); + TEST_ASSERT_EQUAL(repeat_counter * 3 + ((repeat_counter == 9) ? 11 : 10), call_counter++); repeat_counter++; return greentea_case_teardown_handler(source, passed, failed, failure); } @@ -179,9 +181,9 @@ control_t repeat_handler_on_timeout_case(const size_t call_count) static int repeat_counter(1); TEST_ASSERT_EQUAL(repeat_counter++, call_count); TEST_ASSERT(call_count <= 10); - TEST_ASSERT_EQUAL(call_count-1 + 40, call_counter++); + TEST_ASSERT_EQUAL(call_count - 1 + 40, call_counter++); if (call_count == 10) { - utest_to.attach_us(callback(&validate3, &Utest_func_bind::callback), (50*1000)); // Fire after 50ms + utest_to.attach_us(callback(&validate3, &Utest_func_bind::callback), (50 * 1000)); // Fire after 50ms } return CaseRepeatHandlerOnTimeout(100); } diff --git a/features/frameworks/utest/TESTS/unit_tests/case_control_repeat/main.cpp b/TESTS/COMMON/utest/TESTS/unit_tests/case_control_repeat/main.cpp similarity index 93% rename from features/frameworks/utest/TESTS/unit_tests/case_control_repeat/main.cpp rename to TESTS/COMMON/utest/TESTS/unit_tests/case_control_repeat/main.cpp index 2aec32401ff..76df4f3b272 100644 --- a/features/frameworks/utest/TESTS/unit_tests/case_control_repeat/main.cpp +++ b/TESTS/COMMON/utest/TESTS/unit_tests/case_control_repeat/main.cpp @@ -28,7 +28,7 @@ utest::v1::status_t repeat_all_case_setup(const Case *const source, const size_t { static int repeat_counter(0); TEST_ASSERT_EQUAL(0, index_of_case); - TEST_ASSERT_EQUAL(repeat_counter*3, call_counter++); + TEST_ASSERT_EQUAL(repeat_counter * 3, call_counter++); repeat_counter++; return greentea_case_setup_handler(source, index_of_case); } @@ -36,14 +36,14 @@ control_t repeat_all_case(const size_t call_count) { static int repeat_counter(1); TEST_ASSERT_EQUAL(repeat_counter++, call_count); - TEST_ASSERT_EQUAL((call_count-1)*3 + 1, call_counter++); + TEST_ASSERT_EQUAL((call_count - 1) * 3 + 1, call_counter++); return (call_count < 10) ? CaseRepeatAll : CaseNoRepeat; } utest::v1::status_t repeat_all_case_teardown(const Case *const source, const size_t passed, const size_t failed, const failure_t failure) { static int repeat_counter(0); - TEST_ASSERT_EQUAL(repeat_counter*3 + 2, call_counter++); - TEST_ASSERT_EQUAL(repeat_counter+1, passed); + TEST_ASSERT_EQUAL(repeat_counter * 3 + 2, call_counter++); + TEST_ASSERT_EQUAL(repeat_counter + 1, passed); TEST_ASSERT_EQUAL(0, failed); TEST_ASSERT_EQUAL(REASON_NONE, failure.reason); TEST_ASSERT_EQUAL(LOCATION_NONE, failure.location); @@ -62,7 +62,7 @@ control_t repeat_handler_case(const size_t call_count) { static int repeat_counter(1); TEST_ASSERT_EQUAL(repeat_counter++, call_count); - TEST_ASSERT_EQUAL((call_count-1) + 31, call_counter++); + TEST_ASSERT_EQUAL((call_count - 1) + 31, call_counter++); return (call_count < 10) ? CaseRepeatHandler : CaseNoRepeat; } utest::v1::status_t repeat_handler_case_teardown(const Case *const source, const size_t passed, const size_t failed, const failure_t failure) diff --git a/features/frameworks/utest/TESTS/unit_tests/case_selection/main.cpp b/TESTS/COMMON/utest/TESTS/unit_tests/case_selection/main.cpp similarity index 99% rename from features/frameworks/utest/TESTS/unit_tests/case_selection/main.cpp rename to TESTS/COMMON/utest/TESTS/unit_tests/case_selection/main.cpp index c3d90516979..8e4284eb82a 100644 --- a/features/frameworks/utest/TESTS/unit_tests/case_selection/main.cpp +++ b/TESTS/COMMON/utest/TESTS/unit_tests/case_selection/main.cpp @@ -73,8 +73,7 @@ utest::v1::status_t teardown_case_1(const Case *const source, const size_t passe return utest::v1::status_t(3); } -Case cases[] = -{ +Case cases[] = { Case("Case 1", handler_case_0, teardown_case_0), Case("Case 2", handler_case_1, teardown_case_1), Case("Case 3", handler_case_2, teardown_case_2) diff --git a/features/frameworks/utest/TESTS/unit_tests/case_setup_failure/main.cpp b/TESTS/COMMON/utest/TESTS/unit_tests/case_setup_failure/main.cpp similarity index 99% rename from features/frameworks/utest/TESTS/unit_tests/case_setup_failure/main.cpp rename to TESTS/COMMON/utest/TESTS/unit_tests/case_setup_failure/main.cpp index f5e62b49d2c..54dbe741b27 100644 --- a/features/frameworks/utest/TESTS/unit_tests/case_setup_failure/main.cpp +++ b/TESTS/COMMON/utest/TESTS/unit_tests/case_setup_failure/main.cpp @@ -26,7 +26,7 @@ static bool never_call = false; void never_call_case() { - never_call = true; + never_call = true; } utest::v1::status_t abort_case_setup(const Case *const source, const size_t index_of_case) diff --git a/features/frameworks/utest/TESTS/unit_tests/case_teardown_failure/main.cpp b/TESTS/COMMON/utest/TESTS/unit_tests/case_teardown_failure/main.cpp similarity index 100% rename from features/frameworks/utest/TESTS/unit_tests/case_teardown_failure/main.cpp rename to TESTS/COMMON/utest/TESTS/unit_tests/case_teardown_failure/main.cpp diff --git a/features/frameworks/utest/TESTS/unit_tests/control_type/main.cpp b/TESTS/COMMON/utest/TESTS/unit_tests/control_type/main.cpp similarity index 94% rename from features/frameworks/utest/TESTS/unit_tests/control_type/main.cpp rename to TESTS/COMMON/utest/TESTS/unit_tests/control_type/main.cpp index 04b07b217e8..2c383ec619a 100644 --- a/features/frameworks/utest/TESTS/unit_tests/control_type/main.cpp +++ b/TESTS/COMMON/utest/TESTS/unit_tests/control_type/main.cpp @@ -77,25 +77,25 @@ void test_same_group_combinations() ASSERT_CONTROL(CaseAwait + CaseAwait, REPEAT_UNDECLR, TIMEOUT_FOREVER); // same group _and_ same values - ASSERT_CONTROL(CaseTimeout( 0) + CaseTimeout( 0), REPEAT_UNDECLR, 0); + ASSERT_CONTROL(CaseTimeout(0) + CaseTimeout(0), REPEAT_UNDECLR, 0); ASSERT_CONTROL(CaseTimeout(100000) + CaseTimeout(100000), REPEAT_UNDECLR, 100000); - ASSERT_CONTROL(CaseRepeatAllOnTimeout( 0) + CaseRepeatAllOnTimeout( 0), REPEAT_ALL_ON_TIMEOUT, 0); + ASSERT_CONTROL(CaseRepeatAllOnTimeout(0) + CaseRepeatAllOnTimeout(0), REPEAT_ALL_ON_TIMEOUT, 0); ASSERT_CONTROL(CaseRepeatAllOnTimeout(100000) + CaseRepeatAllOnTimeout(100000), REPEAT_ALL_ON_TIMEOUT, 100000); - ASSERT_CONTROL(CaseRepeatHandlerOnTimeout( 0) + CaseRepeatHandlerOnTimeout( 0), REPEAT_HANDLER_ON_TIMEOUT, 0); + ASSERT_CONTROL(CaseRepeatHandlerOnTimeout(0) + CaseRepeatHandlerOnTimeout(0), REPEAT_HANDLER_ON_TIMEOUT, 0); ASSERT_CONTROL(CaseRepeatHandlerOnTimeout(100000) + CaseRepeatHandlerOnTimeout(100000), REPEAT_HANDLER_ON_TIMEOUT, 100000); // same group but _different_ values // stricter value should win - ASSERT_CONTROL(CaseTimeout(100) + CaseTimeout( 12), REPEAT_UNDECLR, 12); + ASSERT_CONTROL(CaseTimeout(100) + CaseTimeout(12), REPEAT_UNDECLR, 12); ASSERT_CONTROL(CaseTimeout(267) + CaseTimeout(36756), REPEAT_UNDECLR, 267); - ASSERT_CONTROL(CaseRepeatAllOnTimeout(12145) + CaseRepeatAllOnTimeout( 592), REPEAT_ALL_ON_TIMEOUT, 592); - ASSERT_CONTROL(CaseRepeatAllOnTimeout( 3593) + CaseRepeatAllOnTimeout(294523), REPEAT_ALL_ON_TIMEOUT, 3593); + ASSERT_CONTROL(CaseRepeatAllOnTimeout(12145) + CaseRepeatAllOnTimeout(592), REPEAT_ALL_ON_TIMEOUT, 592); + ASSERT_CONTROL(CaseRepeatAllOnTimeout(3593) + CaseRepeatAllOnTimeout(294523), REPEAT_ALL_ON_TIMEOUT, 3593); ASSERT_CONTROL(CaseRepeatHandlerOnTimeout(124001) + CaseRepeatHandlerOnTimeout(49610), REPEAT_HANDLER_ON_TIMEOUT, 49610); - ASSERT_CONTROL(CaseRepeatHandlerOnTimeout( 47) + CaseRepeatHandlerOnTimeout( 209), REPEAT_HANDLER_ON_TIMEOUT, 47); + ASSERT_CONTROL(CaseRepeatHandlerOnTimeout(47) + CaseRepeatHandlerOnTimeout(209), REPEAT_HANDLER_ON_TIMEOUT, 47); } void test_different_group_combinations() @@ -252,8 +252,7 @@ void test_different_group_combinations() ASSERT_CONTROL(CaseRepeatHandlerOnTimeout(42) + CaseRepeatAllOnTimeout(21), REPEAT_ALL_ON_TIMEOUT, 21); } -Case cases[] = -{ +Case cases[] = { Case("Testing constructors", test_constructors), Case("Testing constants", test_constants), Case("Testing combinations of same group", test_same_group_combinations), diff --git a/features/frameworks/utest/TESTS/unit_tests/minimal_async_scheduler/main.cpp b/TESTS/COMMON/utest/TESTS/unit_tests/minimal_async_scheduler/main.cpp similarity index 96% rename from features/frameworks/utest/TESTS/unit_tests/minimal_async_scheduler/main.cpp rename to TESTS/COMMON/utest/TESTS/unit_tests/minimal_async_scheduler/main.cpp index 0e36ce18c4d..308d0bfd925 100644 --- a/features/frameworks/utest/TESTS/unit_tests/minimal_async_scheduler/main.cpp +++ b/TESTS/COMMON/utest/TESTS/unit_tests/minimal_async_scheduler/main.cpp @@ -49,7 +49,7 @@ static int32_t utest_minimal_init() static void *utest_minimal_post(const utest_v1_harness_callback_t callback, timestamp_t delay_ms) { UTEST_LOG_FUNCTION(); - timestamp_t delay_us = delay_ms *1000; + timestamp_t delay_us = delay_ms * 1000; if (delay_ms) { ticker_callback = callback; @@ -60,7 +60,7 @@ static void *utest_minimal_post(const utest_v1_harness_callback_t callback, tim } // return a bogus handle - return (void*)1; + return (void *)1; } static int32_t utest_minimal_cancel(void *handle) { @@ -76,11 +76,9 @@ static int32_t utest_minimal_run() * This is just a busy loop that calls the callbacks in this context. * THIS LOOP IS BLOCKING. */ - while(1) - { + while (1) { // check if a new callback has been set - if (minimal_callback) - { + if (minimal_callback) { // copy the callback utest_v1_harness_callback_t callback = minimal_callback; // reset the shared callback @@ -91,8 +89,7 @@ static int32_t utest_minimal_run() } return 0; } -static const utest_v1_scheduler_t utest_minimal_scheduler = -{ +static const utest_v1_scheduler_t utest_minimal_scheduler = { utest_minimal_init, utest_minimal_post, utest_minimal_cancel, diff --git a/features/frameworks/utest/TESTS/unit_tests/minimal_scheduler/main.cpp b/TESTS/COMMON/utest/TESTS/unit_tests/minimal_scheduler/main.cpp similarity index 97% rename from features/frameworks/utest/TESTS/unit_tests/minimal_scheduler/main.cpp rename to TESTS/COMMON/utest/TESTS/unit_tests/minimal_scheduler/main.cpp index 2f5299ff8a9..3f28a2ab2f8 100644 --- a/features/frameworks/utest/TESTS/unit_tests/minimal_scheduler/main.cpp +++ b/TESTS/COMMON/utest/TESTS/unit_tests/minimal_scheduler/main.cpp @@ -36,7 +36,7 @@ static void *utest_minimal_post(const utest_v1_harness_callback_t callback, cons { minimal_callback = callback; // this scheduler does not support scheduling of asynchronous callbacks - return (delay_ms ? NULL : (void*)1); + return (delay_ms ? NULL : (void *)1); } static int32_t utest_minimal_cancel(void *handle) { @@ -50,8 +50,7 @@ static int32_t utest_minimal_run() * This is just a busy loop that calls the callbacks in this context. * THIS LOOP IS BLOCKING. */ - while(1) - { + while (1) { // check if a new callback has been set if (minimal_callback) { // copy the callback @@ -64,8 +63,7 @@ static int32_t utest_minimal_run() } return 0; } -static const utest_v1_scheduler_t utest_minimal_scheduler = -{ +static const utest_v1_scheduler_t utest_minimal_scheduler = { utest_minimal_init, utest_minimal_post, utest_minimal_cancel, diff --git a/features/frameworks/utest/TESTS/unit_tests/test_assertion_failure_test_setup/main.cpp b/TESTS/COMMON/utest/TESTS/unit_tests/test_assertion_failure_test_setup/main.cpp similarity index 97% rename from features/frameworks/utest/TESTS/unit_tests/test_assertion_failure_test_setup/main.cpp rename to TESTS/COMMON/utest/TESTS/unit_tests/test_assertion_failure_test_setup/main.cpp index b432a09fa27..80d24bf60fa 100644 --- a/features/frameworks/utest/TESTS/unit_tests/test_assertion_failure_test_setup/main.cpp +++ b/TESTS/COMMON/utest/TESTS/unit_tests/test_assertion_failure_test_setup/main.cpp @@ -28,8 +28,7 @@ void never_call_case() { TEST_FAIL_MESSAGE("Case handler should have never been called!"); } -Case cases[] = -{ +Case cases[] = { Case("dummy test", never_call_case) }; @@ -59,9 +58,8 @@ void test_failure_handler(const failure_t failure) // pretend to greentea that the test was successful greentea_test_teardown_handler(1, 0, REASON_NONE); - while(1) ; - } - else { + while (1) ; + } else { selftest_handlers.test_failure(failure); } } diff --git a/features/frameworks/utest/TESTS/unit_tests/test_setup_case_selection_failure/main.cpp b/TESTS/COMMON/utest/TESTS/unit_tests/test_setup_case_selection_failure/main.cpp similarity index 99% rename from features/frameworks/utest/TESTS/unit_tests/test_setup_case_selection_failure/main.cpp rename to TESTS/COMMON/utest/TESTS/unit_tests/test_setup_case_selection_failure/main.cpp index 9c928aae380..0fd8349d0b5 100644 --- a/features/frameworks/utest/TESTS/unit_tests/test_setup_case_selection_failure/main.cpp +++ b/TESTS/COMMON/utest/TESTS/unit_tests/test_setup_case_selection_failure/main.cpp @@ -26,8 +26,7 @@ void never_call_case() { TEST_FAIL_MESSAGE("Case handler should have never been called!"); } -Case cases[] = -{ +Case cases[] = { Case("dummy test", never_call_case), Case("dummy test 2", never_call_case) }; diff --git a/features/frameworks/utest/TESTS/unit_tests/test_setup_failure/main.cpp b/TESTS/COMMON/utest/TESTS/unit_tests/test_setup_failure/main.cpp similarity index 99% rename from features/frameworks/utest/TESTS/unit_tests/test_setup_failure/main.cpp rename to TESTS/COMMON/utest/TESTS/unit_tests/test_setup_failure/main.cpp index e18c25cea40..efe231a911a 100644 --- a/features/frameworks/utest/TESTS/unit_tests/test_setup_failure/main.cpp +++ b/TESTS/COMMON/utest/TESTS/unit_tests/test_setup_failure/main.cpp @@ -26,8 +26,7 @@ void never_call_case() { TEST_FAIL_MESSAGE("Case handler should have never been called!"); } -Case cases[] = -{ +Case cases[] = { Case("dummy test", never_call_case), Case("dummy test 2", never_call_case) }; diff --git a/features/frameworks/utest/TESTS/unit_tests/test_skip/main.cpp b/TESTS/COMMON/utest/TESTS/unit_tests/test_skip/main.cpp similarity index 92% rename from features/frameworks/utest/TESTS/unit_tests/test_skip/main.cpp rename to TESTS/COMMON/utest/TESTS/unit_tests/test_skip/main.cpp index 19e2fffe933..74147617523 100644 --- a/features/frameworks/utest/TESTS/unit_tests/test_skip/main.cpp +++ b/TESTS/COMMON/utest/TESTS/unit_tests/test_skip/main.cpp @@ -53,8 +53,8 @@ void conditional_test_skip_test() // Cases -------------------------------------------------------------------------------------------------------------- Case cases[] = { - Case("Unconditional test skip macro test", unconditional_test_skip_test), - Case("Conditional test skip macro test", conditional_test_skip_test, test_skip_case_teardown), + Case("Unconditional test skip macro test", unconditional_test_skip_test), + Case("Conditional test skip macro test", conditional_test_skip_test, test_skip_case_teardown), }; // Specification: Setup & Teardown ------------------------------------------------------------------------------------ diff --git a/features/frameworks/utest/utest/unity_handler.h b/TESTS/COMMON/utest/include/utest/unity_handler.h similarity index 100% rename from features/frameworks/utest/utest/unity_handler.h rename to TESTS/COMMON/utest/include/utest/unity_handler.h diff --git a/features/frameworks/utest/utest/utest.h b/TESTS/COMMON/utest/include/utest/utest.h similarity index 100% rename from features/frameworks/utest/utest/utest.h rename to TESTS/COMMON/utest/include/utest/utest.h diff --git a/TESTS/COMMON/utest/include/utest/utest_case.h b/TESTS/COMMON/utest/include/utest/utest_case.h new file mode 100644 index 00000000000..da418e26b9b --- /dev/null +++ b/TESTS/COMMON/utest/include/utest/utest_case.h @@ -0,0 +1,178 @@ +/**************************************************************************** + * Copyright (c) 2015, ARM Limited, All Rights Reserved + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + **************************************************************************** + */ + +#ifndef UTEST_CASES_H +#define UTEST_CASES_H + +#include +#include +#include +#include "utest/utest_types.h" +#include "utest/utest_default_handlers.h" + + +namespace utest { +/** \addtogroup frameworks */ +/** @{*/ +namespace v1 { +/** + * POD data structure of the Case class. + * Unlike the Case class it can be used as a POD and be put in ROM. + * + * @warning Initialization of handlers with either default_handler or + * ignore_handler helpers will prevent the object to be a POD. Prefer usage + * of NULL in favor of ignore_handler or \verbatim (1) \endverbatim for default + * handler. + * + * @see Case. + */ +struct case_t { + /** + * Textual description of the test case + */ + const char *description; + + /** + * Primitive test case handler + * This is called only if the case setup succeeded. It is followed by + * the test case teardown handler. + */ + const case_handler_t handler; + + /** + * @see case_control_handler_t + */ + const case_control_handler_t control_handler; + + /** + * @see case_call_count_handler_t + */ + const case_call_count_handler_t repeat_count_handler; + + /** + * Handler called before the execution of the case handler. It sets up + * the case environment. + */ + const case_setup_handler_t setup_handler; + + /** + * Handler called after the execution of the case handler. It cleans up + * the case environment. + */ + const case_teardown_handler_t teardown_handler; + + /** + * Handler called whenever a faillure occur; at any stage of the case + * execution (including setup and teardown). + */ + const case_failure_handler_t failure_handler; +}; + +/** Test case wrapper class. + * + * This class contains the description of the test case and all handlers + * for setting up, running the test case, tearing down and handling failures. + * + * By default you only need to provide a description and a test case handler. + * You may override the setup, teardown and failure handlers, but you do not have to. + * If you do not override these handler, the specified default handlers will be called. + * + * These constructors are overloaded to allow you a comfortable declaration of all your + * callbacks. + * The order is always: + * - description (required) + * - setup handler (optional) + * - test case handler (required) + * - teardown handler (optional) + * - failure handler (optional) + * + * @note While you can specify an empty test case (ie. use `ignore_handler` for all callbacks), + * the harness will abort the test unconditionally. + */ +class Case : private case_t { +public: + // overloads for case_handler_t + Case(const char *description, + const case_setup_handler_t setup_handler, + const case_handler_t case_handler, + const case_teardown_handler_t teardown_handler = default_handler, + const case_failure_handler_t failure_handler = default_handler); + + Case(const char *description, + const case_handler_t case_handler, + const case_failure_handler_t failure_handler = default_handler); + + Case(const char *description, + const case_handler_t case_handler, + const case_teardown_handler_t teardown_handler, + const case_failure_handler_t failure_handler = default_handler); + + // overloads for case_control_handler_t + Case(const char *description, + const case_setup_handler_t setup_handler, + const case_control_handler_t case_handler, + const case_teardown_handler_t teardown_handler = default_handler, + const case_failure_handler_t failure_handler = default_handler); + + Case(const char *description, + const case_control_handler_t case_handler, + const case_failure_handler_t failure_handler = default_handler); + + Case(const char *description, + const case_control_handler_t case_handler, + const case_teardown_handler_t teardown_handler, + const case_failure_handler_t failure_handler = default_handler); + + // overloads for case_call_count_handler_t + Case(const char *description, + const case_setup_handler_t setup_handler, + const case_call_count_handler_t case_handler, + const case_teardown_handler_t teardown_handler = default_handler, + const case_failure_handler_t failure_handler = default_handler); + + Case(const char *description, + const case_call_count_handler_t case_handler, + const case_failure_handler_t failure_handler = default_handler); + + Case(const char *description, + const case_call_count_handler_t case_handler, + const case_teardown_handler_t teardown_handler, + const case_failure_handler_t failure_handler = default_handler); + + + /// @returns the textual description of the test case + const char *get_description() const; + + /// @returns `true` if setup, test and teardown handlers are set to `ignore_handler` + bool is_empty() const; + +private: + // IMPORTANT: No data members shall be declared inside this class. + // Data members shall be declared in case_t to preserve the layout + // and the compatibility between the two types. + + friend class Harness; + friend class Specification; +}; + +} // namespace v1 +} // namespace utest + +#endif // UTEST_CASES_H + +/** @}*/ diff --git a/TESTS/COMMON/utest/include/utest/utest_default_handlers.h b/TESTS/COMMON/utest/include/utest/utest_default_handlers.h new file mode 100644 index 00000000000..459eaff2987 --- /dev/null +++ b/TESTS/COMMON/utest/include/utest/utest_default_handlers.h @@ -0,0 +1,265 @@ +/**************************************************************************** + * Copyright (c) 2015, ARM Limited, All Rights Reserved + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + **************************************************************************** + */ + +#ifndef UTEST_DEFAULT_HANDLER_H +#define UTEST_DEFAULT_HANDLER_H + +#include +#include +#include +#include "utest/utest_types.h" + + +namespace utest { +/** \addtogroup frameworks */ +/** @{*/ +namespace v1 { + +/** Default handler hint. + * + * Use this handler to indicate the you want the default handler to be called. + * This type automatically casts itself into the appropriate handler type, when possible. + * Use the constants to default a handler unambigously. + */ +static const struct { + ///@cond IGNORE + // Doxygen can't parse these implicit conversion operators properly, remove from + // doc build + operator test_setup_handler_t() const + { + return test_setup_handler_t(1); + } + operator test_teardown_handler_t() const + { + return test_teardown_handler_t(1); + } + operator test_failure_handler_t() const + { + return test_failure_handler_t(1); + } + + operator case_setup_handler_t() const + { + return case_setup_handler_t(1); + } + operator case_teardown_handler_t() const + { + return case_teardown_handler_t(1); + } + operator case_failure_handler_t() const + { + return case_failure_handler_t(1); + } + ///@endcond +} default_handler; + +/** Ignore handler hint. + * + * Use this handler to indicate the you want to ignore this handler and it will not be called. + * This type automatically casts itself into the appropriate handler type, when possible. + * Use the constants to ignore a handler unambigously. + */ +static const struct { + ///@cond IGNORE + // Doxygen can't parse these implicit conversion operators properly, remove from + // doc build + operator case_handler_t() const + { + return case_handler_t(NULL); + } + operator case_control_handler_t() const + { + return case_control_handler_t(NULL); + } + operator case_call_count_handler_t() const + { + return case_call_count_handler_t(NULL); + } + + operator test_setup_handler_t() const + { + return test_setup_handler_t(NULL); + } + operator test_teardown_handler_t() const + { + return test_teardown_handler_t(NULL); + } + operator test_failure_handler_t() const + { + return test_failure_handler_t(NULL); + } + + operator case_setup_handler_t() const + { + return case_setup_handler_t(NULL); + } + operator case_teardown_handler_t() const + { + return case_teardown_handler_t(NULL); + } + operator case_failure_handler_t() const + { + return case_failure_handler_t(NULL); + } + ///@endcond +} ignore_handler; + +/** A table of handlers. + * + * This structure stores all modifyable handlers and provides accessors to + * filter out the default handler. + * So if this structure contains handlers, and you want to use these handlers + * as a default backup, you can use the `get_handler` function to choose the right handler. + * + * Example: + * @code + * const handler_t defaults = { ... }; // your default handlers + * // will return the handler in defaults. + * test_setup_handler_t handler = defaults.get_handler(default_handler); + * // you will still need to manually check the handler before executing it + * if (handler != ignore_handler) handler(...); + * + * extern test_teardown_handler_t custom_handler(...); + * // will return `custom_handler` + * test_teardown_handler_t handler = defaults.get_handler(custom_handler); + * // you will still need to manually check the handler before executing it + * if (handler != ignore_handler) handler(...); + * @endcode + */ +struct handlers_t { + test_setup_handler_t test_setup; + test_teardown_handler_t test_teardown; + test_failure_handler_t test_failure; + + case_setup_handler_t case_setup; + case_teardown_handler_t case_teardown; + case_failure_handler_t case_failure; + + inline test_setup_handler_t get_handler(test_setup_handler_t handler) const + { + if (handler == default_handler) { + return test_setup; + } + return handler; + } + inline test_teardown_handler_t get_handler(test_teardown_handler_t handler) const + { + if (handler == default_handler) { + return test_teardown; + } + return handler; + } + inline test_failure_handler_t get_handler(test_failure_handler_t handler) const + { + if (handler == default_handler) { + return test_failure; + } + return handler; + } + + inline case_setup_handler_t get_handler(case_setup_handler_t handler) const + { + if (handler == default_handler) { + return case_setup; + } + return handler; + } + inline case_teardown_handler_t get_handler(case_teardown_handler_t handler) const + { + if (handler == default_handler) { + return case_teardown; + } + return handler; + } + inline case_failure_handler_t get_handler(case_failure_handler_t handler) const + { + if (handler == default_handler) { + return case_failure; + } + return handler; + } +}; + +/// Prints the number of tests to run and continues. +utest::v1::status_t verbose_test_setup_handler(const size_t number_of_cases); +/// Prints the number of tests that passed and failed with a reason if provided. +void verbose_test_teardown_handler(const size_t passed, const size_t failed, const failure_t failure); +/// Prints the failure for `REASON_TEST_SETUP` and `REASON_TEST_TEARDOWN` and then dies. +void verbose_test_failure_handler(const failure_t failure); + +/// Prints the index and description of the case being run and continues. +utest::v1::status_t verbose_case_setup_handler(const Case *const source, const size_t index_of_case); +/// Prints the number of tests that passed and failed with a reason if provided within this case and continues. +utest::v1::status_t verbose_case_teardown_handler(const Case *const source, const size_t passed, const size_t failed, const failure_t failure); +/// Prints the reason of the failure and continues, unless the teardown handler failed, for which it aborts. +utest::v1::status_t verbose_case_failure_handler(const Case *const source, const failure_t reason); + +/// Default greentea test case set up handler +#define UTEST_DEFAULT_GREENTEA_TIMEOUT 10 //Seconds +#define UTEST_DEFAULT_HOST_TEST_NAME "default_auto" + +utest::v1::status_t default_greentea_test_setup_handler(const size_t number_of_cases); + +/// Requests the start test case from greentea and continues. +/// Example usage: +/// utest::v1::status_t greentea_test_setup(const size_t number_of_cases) { +/// GREENTEA_SETUP(5, "default_auto"); +/// return greentea_test_setup_handler(number_of_cases); +/// } +/// +/// Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler); +utest::v1::status_t greentea_test_setup_handler(const size_t number_of_cases); + +/// Reports the test results to greentea. +void greentea_test_teardown_handler(const size_t passed, const size_t failed, const failure_t failure); +/// Reports the failure for `REASON_TEST_SETUP` and `REASON_TEST_TEARDOWN` to greentea and then dies. +void greentea_test_failure_handler(const failure_t failure); + +/// Registers the test case setup with greentea. +utest::v1::status_t greentea_case_setup_handler(const Case *const source, const size_t index_of_case); +/// Registers the test case teardown with greentea. +utest::v1::status_t greentea_case_teardown_handler(const Case *const source, const size_t passed, const size_t failed, const failure_t failure); +/// Reports the failure to greentea and then aborts. +utest::v1::status_t greentea_case_failure_abort_handler(const Case *const source, const failure_t reason); +/// Reports the failure to greentea and then continues. +utest::v1::status_t greentea_case_failure_continue_handler(const Case *const source, const failure_t reason); + +/// Notify greentea of testcase name. +void greentea_testcase_notification_handler(const char *testcase); + +/// The verbose default handlers that always continue on failure +extern const handlers_t verbose_continue_handlers; + +/// The greentea default handlers that always abort on the first encountered failure +extern const handlers_t greentea_abort_handlers; + +/// The greentea default handlers that always continue on failure +extern const handlers_t greentea_continue_handlers; + +/// The selftest default handlers that always abort on _any_ assertion failure, otherwise continue +extern const handlers_t selftest_handlers; + +/// The greentea aborting handlers are the default +extern const handlers_t &default_handlers; + +} // namespace v1 +} // namespace utest + +#endif // UTEST_DEFAULT_HANDLER_H + +/** @}*/ diff --git a/TESTS/COMMON/utest/include/utest/utest_harness.h b/TESTS/COMMON/utest/include/utest/utest_harness.h new file mode 100644 index 00000000000..909ad550da2 --- /dev/null +++ b/TESTS/COMMON/utest/include/utest/utest_harness.h @@ -0,0 +1,99 @@ +/**************************************************************************** + * Copyright (c) 2015, ARM Limited, All Rights Reserved + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + **************************************************************************** + */ + +#ifndef UTEST_HARNESS_H +#define UTEST_HARNESS_H + +#include +#include +#include + +#include "utest/utest_types.h" +#include "utest/utest_case.h" +#include "utest/utest_default_handlers.h" +#include "utest/utest_specification.h" +#include "utest/utest_scheduler.h" + + +namespace utest { +/** \addtogroup frameworks */ +/** @{*/ +namespace v1 { + +/** Test Harness. + * + * This class runs a test specification for you and calls all required handlers. + * The harness executes the test specification in an asynchronous fashion, therefore + * `run()` returns immediately. + * + * @note In case of an test abort, the harness will busy-wait and never finish. + */ +class Harness { +public: + /// Runs a test specification + /// @retval `true` if the specification can be run + /// @retval `false` if another specification is currently running + static bool run(const Specification &specification); + + /// @cond + __deprecated_message("Start case selection is done by returning the index from the test setup handler!") + static bool run(const Specification &specification, size_t start_case); + /// @endcond + + /// @returns `true` if a test specification is being executed, `false` otherwise + static bool is_busy(); + + /// Sets the scheduler to be used. + /// @return `true` if scheduler is properly specified (all functions non-null). + static bool set_scheduler(utest_v1_scheduler_t scheduler); + + /** Call this function in the asynchronous callback that you have been waiting for. + * + * You can only validate a callback once, calling this function when no callback is expected + * has no side effects. + * After callback validation, the next test case is scheduled. + * + * You may specify additional test case attributes with this callback. + * So for example, you may delay the decision to repeat an asynchronous test case until the callback + * needs to be validated. + * + * However, be aware, that only the repeat attributes can be modified and the usual arbitration rules apply. + * The modified case attributes are only valid until the case handler returns updated attributes. + * + * @param control the test case attribute to be added to the existing attributes. + */ + static void validate_callback(const control_t control = control_t()); + + /// Raising a failure causes the failure to be counted and the failure handler to be called. + /// Further action then depends on its return state. + static void raise_failure(const failure_reason_t reason); + +protected: + static void run_next_case(); + static void handle_timeout(); + static void schedule_next_case(); +private: + static void notify_testcases(); +}; + +} // namespace v1 +} // namespace utest + +#endif // UTEST_HARNESS_H + +/** @}*/ diff --git a/features/frameworks/utest/utest/utest_print.h b/TESTS/COMMON/utest/include/utest/utest_print.h similarity index 100% rename from features/frameworks/utest/utest/utest_print.h rename to TESTS/COMMON/utest/include/utest/utest_print.h diff --git a/features/frameworks/utest/utest/utest_scheduler.h b/TESTS/COMMON/utest/include/utest/utest_scheduler.h similarity index 100% rename from features/frameworks/utest/utest/utest_scheduler.h rename to TESTS/COMMON/utest/include/utest/utest_scheduler.h diff --git a/features/frameworks/utest/utest/utest_shim.h b/TESTS/COMMON/utest/include/utest/utest_shim.h similarity index 91% rename from features/frameworks/utest/utest/utest_shim.h rename to TESTS/COMMON/utest/include/utest/utest_shim.h index 34ec7d1df9a..db628c44170 100644 --- a/features/frameworks/utest/utest/utest_shim.h +++ b/TESTS/COMMON/utest/include/utest/utest_shim.h @@ -36,10 +36,10 @@ #endif #ifndef UTEST_ENTER_CRITICAL_SECTION -# define UTEST_ENTER_CRITICAL_SECTION utest_v1_enter_critical_section() +# define UTEST_ENTER_CRITICAL_SECTION utest_v1_enter_critical_section() #endif #ifndef UTEST_LEAVE_CRITICAL_SECTION -# define UTEST_LEAVE_CRITICAL_SECTION utest_v1_leave_critical_section() +# define UTEST_LEAVE_CRITICAL_SECTION utest_v1_leave_critical_section() #endif #ifdef __cplusplus diff --git a/TESTS/COMMON/utest/include/utest/utest_specification.h b/TESTS/COMMON/utest/include/utest/utest_specification.h new file mode 100644 index 00000000000..9aefcafe4f2 --- /dev/null +++ b/TESTS/COMMON/utest/include/utest/utest_specification.h @@ -0,0 +1,189 @@ +/**************************************************************************** + * Copyright (c) 2015, ARM Limited, All Rights Reserved + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + **************************************************************************** + */ + +#ifndef UTEST_SPECIFICATION_H +#define UTEST_SPECIFICATION_H + +#include +#include +#include +#include "utest/utest_types.h" +#include "utest/utest_case.h" +#include "utest/utest_default_handlers.h" + + +namespace utest { +/** \addtogroup frameworks */ +/** @{*/ +namespace v1 { + +/** Test specification containing the setup and teardown handlers and test cases. + * + * This class simply holds the test cases and allows you to specify default handlers, and + * override setup and teardown handlers. + * The order of arguments is: + * - test setup handler (optional) + * - array of test cases (required) + * - test teardown handler (optional) + * - default handlers (optional) + * + * @note You cannot set the size of the test case array dynamically, it is template deducted at compile + * time. Creating test specifications for unittests at runtime is explicitly not supported. + */ +class Specification { +public: + template< size_t N, typename CaseType > + Specification(const CaseType(&cases)[N], + const handlers_t defaults = default_handlers) : + setup_handler(default_handler), teardown_handler(default_handler), failure_handler(default_handler), + cases(static_cast(static_cast(cases))), length(N), + defaults(defaults) + { + MBED_STATIC_ASSERT( + sizeof(CaseType) == sizeof(Case), + "CaseType and Case should have the same size" + ); + } + + template< size_t N, typename CaseType > + Specification(const CaseType(&cases)[N], + const test_failure_handler_t failure_handler, + const handlers_t defaults = default_handlers) : + setup_handler(default_handler), teardown_handler(default_handler), failure_handler(failure_handler), + cases(static_cast(static_cast(cases))), length(N), + defaults(defaults) + { + MBED_STATIC_ASSERT( + sizeof(CaseType) == sizeof(Case), + "CaseType and Case should have the same size" + ); + } + + template< size_t N, typename CaseType > + Specification(const CaseType(&cases)[N], + const test_teardown_handler_t teardown_handler, + const handlers_t defaults = default_handlers) : + setup_handler(default_handler), teardown_handler(teardown_handler), failure_handler(default_handler), + cases(static_cast(static_cast(cases))), length(N), + defaults(defaults) + { + MBED_STATIC_ASSERT( + sizeof(CaseType) == sizeof(Case), + "CaseType and Case should have the same size" + ); + } + + template< size_t N, typename CaseType > + Specification(const CaseType(&cases)[N], + const test_teardown_handler_t teardown_handler, + const test_failure_handler_t failure_handler, + const handlers_t defaults = default_handlers) : + setup_handler(default_handler), teardown_handler(teardown_handler), failure_handler(failure_handler), + cases(static_cast(static_cast(cases))), length(N), + defaults(defaults) + { + MBED_STATIC_ASSERT( + sizeof(CaseType) == sizeof(Case), + "CaseType and Case should have the same size" + ); + } + + template< size_t N, typename CaseType > + Specification(const test_setup_handler_t setup_handler, + const CaseType(&cases)[N], + const handlers_t defaults = default_handlers) : + setup_handler(setup_handler), teardown_handler(default_handler), failure_handler(default_handler), + cases(static_cast(static_cast(cases))), length(N), + defaults(defaults) + {} + + template< size_t N, typename CaseType > + Specification(const test_setup_handler_t setup_handler, + const CaseType(&cases)[N], + const test_failure_handler_t failure_handler, + const handlers_t defaults = default_handlers) : + setup_handler(setup_handler), teardown_handler(default_handler), failure_handler(failure_handler), + cases(static_cast(static_cast(cases))), length(N), + defaults(defaults) + { + MBED_STATIC_ASSERT( + sizeof(CaseType) == sizeof(Case), + "CaseType and Case should have the same size" + ); + } + + template< size_t N, typename CaseType > + Specification(const test_setup_handler_t setup_handler, + const CaseType(&cases)[N], + const test_teardown_handler_t teardown_handler, + const handlers_t defaults = default_handlers) : + setup_handler(setup_handler), teardown_handler(teardown_handler), failure_handler(default_handler), + cases(static_cast(static_cast(cases))), length(N), + defaults(defaults) + { + MBED_STATIC_ASSERT( + sizeof(CaseType) == sizeof(Case), + "CaseType and Case should have the same size" + ); + } + + template< size_t N, typename CaseType > + Specification(const test_setup_handler_t setup_handler, + const CaseType(&cases)[N], + const test_teardown_handler_t teardown_handler, + const test_failure_handler_t failure_handler, + const handlers_t defaults = default_handlers) : + setup_handler(setup_handler), teardown_handler(teardown_handler), failure_handler(failure_handler), + cases(static_cast(static_cast(cases))), length(N), + defaults(defaults) + { + MBED_STATIC_ASSERT( + sizeof(CaseType) == sizeof(Case), + "CaseType and Case should have the same size" + ); + } + + Specification(const test_setup_handler_t setup_handler, + const Case *cases, + const size_t length, + const test_teardown_handler_t teardown_handler, + const test_failure_handler_t failure_handler, + const handlers_t defaults = default_handlers) : + setup_handler(setup_handler), teardown_handler(teardown_handler), failure_handler(failure_handler), + cases(cases), length(length), + defaults(defaults) + { + } + +private: + const test_setup_handler_t setup_handler; + const test_teardown_handler_t teardown_handler; + const test_failure_handler_t failure_handler; + const Case *const cases; + const size_t length; + const handlers_t defaults; + + friend class Harness; +}; + +} // namespace v1 +} // namespace utest + +#endif // UTEST_SPECIFICATION_H + +/** @}*/ diff --git a/features/frameworks/utest/utest/utest_stack_trace.h b/TESTS/COMMON/utest/include/utest/utest_stack_trace.h similarity index 97% rename from features/frameworks/utest/utest/utest_stack_trace.h rename to TESTS/COMMON/utest/include/utest/utest_stack_trace.h index e75df0f1a39..08bcd379e68 100644 --- a/features/frameworks/utest/utest/utest_stack_trace.h +++ b/TESTS/COMMON/utest/include/utest/utest_stack_trace.h @@ -38,7 +38,7 @@ extern void utest_dump_trace(); #else -#define UTEST_LOG_FUNCTION(); +#define UTEST_LOG_FUNCTION(); #define UTEST_TRACE_START #define UTEST_DUMP_TRACE diff --git a/TESTS/COMMON/utest/include/utest/utest_types.h b/TESTS/COMMON/utest/include/utest/utest_types.h new file mode 100644 index 00000000000..afe035bb9f9 --- /dev/null +++ b/TESTS/COMMON/utest/include/utest/utest_types.h @@ -0,0 +1,430 @@ +/**************************************************************************** + * Copyright (c) 2015, ARM Limited, All Rights Reserved + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + **************************************************************************** + */ + +#ifndef UTEST_TYPES_H +#define UTEST_TYPES_H + +#include +#include +#include +#include "utest/utest_shim.h" +#include "SingletonPtr.h" + +namespace utest { +/** \addtogroup frameworks */ +/** @{*/ +namespace v1 { + +/// repeat_t +enum repeat_t { + REPEAT_UNDECLR = 0, + REPEAT_NONE = 1, ///< continue with the next test case + + REPEAT_ON_TIMEOUT = 2, + REPEAT_ON_VALIDATE = 4, + REPEAT_CASE_ONLY = 8, + REPEAT_SETUP_TEARDOWN = 16, + + REPEAT_MASK = REPEAT_ON_TIMEOUT | REPEAT_ON_VALIDATE | REPEAT_CASE_ONLY | REPEAT_SETUP_TEARDOWN, + + REPEAT_ALL_ON_TIMEOUT = REPEAT_SETUP_TEARDOWN | REPEAT_ON_TIMEOUT, ///< repeat the handler with setup and teardown on timeout + REPEAT_HANDLER_ON_TIMEOUT = REPEAT_CASE_ONLY | REPEAT_ON_TIMEOUT, ///< repeat only the handler on timeout + REPEAT_ALL = REPEAT_SETUP_TEARDOWN | REPEAT_ON_VALIDATE, ///< repeat the handler with setup and teardown + REPEAT_HANDLER = REPEAT_CASE_ONLY | REPEAT_ON_VALIDATE ///< repeat only the handler +}; + +/// status_t +enum status_t { + STATUS_CONTINUE = -1, ///< continues testing + STATUS_IGNORE = -2, ///< ignores failure and continues testing + STATUS_ABORT = -3 ///< stops testing +}; + +/// failure_reason_t +enum failure_reason_t { + REASON_NONE = 0, ///< No failure occurred + + REASON_UNKNOWN = (1 << 0), ///< An unknown failure occurred + REASON_CASES = (1 << 1), ///< A failure occurred in at least one test case + REASON_EMPTY_CASE = (1 << 2), ///< The test case contains only empty handlers + REASON_TIMEOUT = (1 << 3), ///< An expected asynchronous call timed out + REASON_ASSERTION = (1 << 4), ///< An assertion failed + + REASON_TEST_SETUP = (1 << 5), ///< Test setup failed + REASON_TEST_TEARDOWN = (1 << 6), ///< Test teardown failed + REASON_CASE_SETUP = (1 << 7), ///< Case setup failed + REASON_CASE_HANDLER = (1 << 8), ///< Case handler failed + REASON_CASE_TEARDOWN = (1 << 9), ///< Case teardown failed + + REASON_CASE_INDEX = (1 << 10), ///< Case index out-of-range + REASON_SCHEDULER = (1 << 11), ///< Asynchronous callback scheduling failed + + REASON_IGNORE = 0x8000 ///< The failure may be ignored +}; + +/// location_t +enum location_t { + LOCATION_NONE = 0, ///< No location information + LOCATION_TEST_SETUP, ///< A failure occurred in the test setup + LOCATION_TEST_TEARDOWN, ///< A failure occurred in the test teardown + LOCATION_CASE_SETUP, ///< A failure occurred in the case setup + LOCATION_CASE_HANDLER, ///< A failure occurred in the case handler + LOCATION_CASE_TEARDOWN, ///< A failure occurred in the case teardown + LOCATION_UNKNOWN ///< A failure occurred in an unknown location +}; + +/// Contains the reason and location of the failure. +struct failure_t { + failure_t() : reason(REASON_NONE), location(LOCATION_NONE) {} + failure_t(failure_reason_t reason) : reason(reason), location(LOCATION_NONE) {} + failure_t(location_t location) : reason(REASON_NONE), location(location) {} + failure_t(failure_reason_t reason, location_t location) : reason(reason), location(location) {} + + /// Copy constructor + failure_t(const failure_t &obj) + { + reason = obj.reason; + location = obj.location; + } + + /// @returns a copy of the failure with the reason ignored. + failure_t ignored() const + { + return failure_t(failure_reason_t(reason | REASON_IGNORE), location); + } + + failure_reason_t reason; + location_t location; +}; + + +enum { + TIMEOUT_NONE = uint32_t(-1), ///< Do not use a timeout + TIMEOUT_UNDECLR = uint32_t(-2), ///< Timeout not explicitly specified, defaults to NONE + TIMEOUT_FOREVER = uint32_t(-3) ///< Never time out +}; + +/// Stringifies a failure reason for understandable error messages. +const char *stringify(failure_reason_t reason); +/// Stringifies a failure for understandable error messages. +const char *stringify(failure_t failure); +/// Stringifies a location. +const char *stringify(location_t location); +/// Stringifies a status. +const char *stringify(utest::v1::status_t status); + +/** POD version of the class control_t. + * It is used to instantiate const control_t objects as PODs + * and prevent them to be included in the final binary. + * @note: control_pod_t can be converted to control_t by copy construction. + */ +struct base_control_t { + repeat_t repeat; + uint32_t timeout; + + repeat_t inline get_repeat() const + { + return repeat; + } + uint32_t inline get_timeout() const + { + return timeout; + } +}; + +/** Control class for specifying test case attributes + * + * This class encapsulated control information about test cases which, when returned from + * a test case influences the behavior of the test harness. + * Instead of using this class directly it is recommended to use the aliases for clearer + * semantics: + * @code + * control_t test_case(const size_t call_count) { + * // repeat 5 times for a total of 6 calls + * return (call_count < 6) ? CaseRepeatHandler : CaseNext; + * } + * @endcode + * + * This class overloads the `+` operator to implement something similiar to saturated arbitration: + * - The lower timeout value "wins". + * - A more involved repeat "wins" (ie. `ALL` > 'HANDLER' > 'NONE'). + * - Next Case always wins. + * + * You may then add timeouts and repeats together: + * @code + * control_t test_case(const size_t call_count) { + * // repeat 5 times for a total of 6 calls, each with a 500ms asynchronous timeout + * return CaseTimeout(500) + ((call_count < 6) ? CaseRepeatAll : CaseNoRepeat); + * } + * @endcode + * + * In the future, more control information may be added transparently and backwards compatible. + */ +struct control_t : private base_control_t { + control_t() : base_control_t(make_base_control_t(REPEAT_UNDECLR, TIMEOUT_UNDECLR)) {} + + control_t(repeat_t repeat, uint32_t timeout_ms) : + base_control_t(make_base_control_t(repeat, timeout_ms)) {} + + control_t(repeat_t repeat) : + base_control_t(make_base_control_t(repeat, TIMEOUT_UNDECLR)) {} + + control_t(uint32_t timeout_ms) : + base_control_t(make_base_control_t(REPEAT_UNDECLR, timeout_ms)) {} + + control_t(const base_control_t &other) : + base_control_t(other) {} + + friend control_t operator+(const control_t &lhs, const control_t &rhs) + { + control_t result( + repeat_t(lhs.repeat | rhs.repeat), + (rhs.timeout == TIMEOUT_NONE) ? rhs.timeout : lhs.timeout); + + if (result.timeout != TIMEOUT_NONE && result.timeout > rhs.timeout) { + result.timeout = rhs.timeout; + } + + if (result.repeat & REPEAT_NONE) { + result.repeat = REPEAT_NONE; + } else { + if (result.repeat & REPEAT_SETUP_TEARDOWN) { + result.repeat = repeat_t(result.repeat & ~REPEAT_CASE_ONLY); + } + if (result.timeout == TIMEOUT_NONE && result.repeat & REPEAT_ON_TIMEOUT) { + result.repeat = repeat_t(result.repeat & ~REPEAT_ON_TIMEOUT); + } + } + + return result; + } + + repeat_t + inline get_repeat() const + { + return repeat; + } + uint32_t + inline get_timeout() const + { + return timeout; + } + +private: + static base_control_t make_base_control_t(repeat_t repeat, uint32_t timeout) + { + base_control_t result = { + repeat, + timeout + }; + return result; + } + + friend class Harness; +}; + +/// @see operator+ in control_t +inline control_t operator+(const base_control_t &lhs, const base_control_t &rhs) +{ + return control_t(lhs) + control_t(rhs); +} + +/// @see operator+ in control_t +inline control_t operator+(const base_control_t &lhs, const control_t &rhs) +{ + return control_t(lhs) + rhs; +} + +/// @see operator+ in control_t +inline control_t operator+(const control_t &lhs, const base_control_t &rhs) +{ + return lhs + control_t(rhs); +} + +/// does not repeat this test case and immediately moves on to the next one without timeout +extern const base_control_t CaseNext; + +/// does not repeat this test case, moves on to the next one +extern const base_control_t CaseNoRepeat; +/// repeats the test case handler with calling teardown and setup handlers +extern const base_control_t CaseRepeatAll; +/// repeats only the test case handler without calling teardown and setup handlers +extern const base_control_t CaseRepeatHandler; + +/// No timeout, immediately moves on to the next case, but allows repeats +extern const base_control_t CaseNoTimeout; +/// Awaits until the callback is validated and never times out. Use with caution! +extern const base_control_t CaseAwait; +/// Alias class for asynchronous timeout control in milliseconds +inline control_t CaseTimeout(uint32_t ms) +{ + return ms; +} + +/// Alias class for asynchronous timeout control in milliseconds and +/// repeats the test case handler with calling teardown and setup handlers +inline control_t CaseRepeatAllOnTimeout(uint32_t ms) +{ + return control_t(REPEAT_ALL_ON_TIMEOUT, ms); +} +/// Alias class for asynchronous timeout control in milliseconds and +/// repeats only the test case handler without calling teardown and setup handlers +inline control_t CaseRepeatHandlerOnTimeout(uint32_t ms) +{ + return control_t(REPEAT_HANDLER_ON_TIMEOUT, ms); +} + +class Case; // forward declaration + +/** Test setup handler. + * + * This handler is called before execution of any test case and + * allows you to initialize your common test environment. + * + * @param number_of_cases the total number of test cases in the test specification + * + * @returns + * You can return `STATUS_ABORT` if you initialization failed and the test teardown handler will + * then be called with the `REASON_SETUP`. + */ +typedef utest::v1::status_t (*test_setup_handler_t)(const size_t number_of_cases); + +/** Test teardown handler. + * + * This handler is called after execution of all test case or if test execution is aborted. + * You can use this handler to de-initialize your test environment and output test statistics. + * The failure argument contains the immediate reason why this handler is called. + * If the test completed normally without failures, this will contain `REASON_NONE`. + * + * After execution of this handler, the test harness will stop execution. + * + * @param passed the number of cases without failures + * @param failed the number of cases with at least one failure + * @param failure the reason why this handler was called + */ +typedef void (*test_teardown_handler_t)(const size_t passed, const size_t failed, const failure_t failure); + +/** Test failure handler. + * + * This handler is called anytime a failure occurs during the execution of a test speficication. + * The handler only allows logging of failures and cannot influence test execution. + * + * @param failure the reason why this handler was called + */ +typedef void (*test_failure_handler_t)(const failure_t reason); + +/** Test case setup handler. + * + * This handler is called before execution of each test case and + * allows you to modify your environment before each test case. + * + * @param source the test case to be setup + * @param index_of_case the current index of the test case within the specification + * + * @returns + * You can return `STATUS_ABORT` to indicate that your setup failed, which will call the case + * failure handler with `REASON_SETUP` and then the case teardown handler with `REASON_SETUP`. + * This gives the teardown handler a chance to clean up a failed setup. + */ +typedef utest::v1::status_t (*case_setup_handler_t)(const Case *const source, const size_t index_of_case); + +/** Primitive test case handler + * + * This handler is called only if the case setup succeeded and is followed by the test case teardown handler. + * + * @note This handler is executed only once. + */ +typedef void (*case_handler_t)(void); + +/** Complex test case handler + * + * This handler is called only if the case setup succeeded and then may be repeated or + * awaiting a asynchronous callback, depending on the return modifiers. + * + * @returns + * A combination of control modifiers. + */ +typedef control_t (*case_control_handler_t)(void); + +/** Test case handler (repeatable) + * + * This handler is called only if the case setup succeeded and then may be repeated or + * awaiting a asynchronous callback, depending on the return modifiers. + * + * @param call_count starting at `1`, contains the number of times this handler has been called + * + * @returns + * A combination of control modifiers. + */ +typedef control_t (*case_call_count_handler_t)(const size_t call_count); + +/** Test case teardown handler. + * + * This handler is called after execution of each test case or all repeated test cases and + * allows you to reset your environment after each test case. + * + * @param source the test case to be torn down + * @param passed the number of cases without failures (can be >1 for repeated test cases) + * @param failed the number failures (can be larger than the number of (repeated) test cases) + * @param failure the reason why this handler was called + * + * @returns + * You can return `STATUS_ABORT` to indicate that your teardown failed, which will call the case + * failure handler with `REASON_TEARDOWN`. + */ +typedef utest::v1::status_t (*case_teardown_handler_t)(const Case *const source, const size_t passed, const size_t failed, const failure_t reason); + +/** Test case failure handler. + * + * This handler is called whenever a failure occurred during the setup, execution or teardown. + * + * @param source the test case in which the failure occurred + * @param reason the reason why this handler was called + * + * @returns + * You can return `STATUS_ABORT` to indicate that this failure is non-recoverable, which will call the case + * teardown handler with reason. If a failure occurs during teardown, the teardown will not be called again. + * You may return `STATUS_IGNORE` which will cause the harness to ignore and not count the failure. + */ +typedef utest::v1::status_t (*case_failure_handler_t)(const Case *const source, const failure_t reason); + + +// deprecations +__deprecated_message("Use CaseRepeatAll instead.") +extern const base_control_t CaseRepeat; + +__deprecated_message("Use CaseRepeatHandler instead.") +extern const base_control_t CaseRepeatHandlerOnly; + +__deprecated_message("Use REASON_NONE instead.") const failure_reason_t FAILURE_NONE = REASON_NONE; +__deprecated_message("Use REASON_UNKNOWN instead.") const failure_reason_t FAILURE_UNKNOWN = REASON_UNKNOWN; +__deprecated_message("Use REASON_CASES instead.") const failure_reason_t FAILURE_CASES = REASON_CASES; +__deprecated_message("Use REASON_EMPTY_CASE instead.") const failure_reason_t FAILURE_EMPTY_CASE = REASON_EMPTY_CASE; +__deprecated_message("Use REASON_TIMEOUT instead.") const failure_reason_t FAILURE_TIMEOUT = REASON_TIMEOUT; +__deprecated_message("Use REASON_ASSERTION instead.") const failure_reason_t FAILURE_ASSERTION = REASON_ASSERTION; +__deprecated_message("Use REASON_CASE_SETUP instead.") const failure_reason_t FAILURE_SETUP = REASON_CASE_SETUP; +__deprecated_message("Use REASON_CASE_TEARDOWN instead.") const failure_reason_t FAILURE_TEARDOWN = REASON_CASE_TEARDOWN; +__deprecated_message("Use REASON_IGNORE instead.") const failure_reason_t FAILURE_IGNORE = REASON_IGNORE; + + +} // namespace v1 +} // namespace utest + +#endif // UTEST_TYPES_H + +/** @}*/ diff --git a/features/frameworks/utest/mbed_lib.json b/TESTS/COMMON/utest/mbed_lib.json similarity index 100% rename from features/frameworks/utest/mbed_lib.json rename to TESTS/COMMON/utest/mbed_lib.json diff --git a/features/frameworks/utest/mbed-utest-shim.cpp b/TESTS/COMMON/utest/source/mbed-utest-shim.cpp similarity index 100% rename from features/frameworks/utest/mbed-utest-shim.cpp rename to TESTS/COMMON/utest/source/mbed-utest-shim.cpp diff --git a/features/frameworks/utest/source/unity_handler.cpp b/TESTS/COMMON/utest/source/unity_handler.cpp similarity index 100% rename from features/frameworks/utest/source/unity_handler.cpp rename to TESTS/COMMON/utest/source/unity_handler.cpp diff --git a/features/frameworks/utest/source/utest_case.cpp b/TESTS/COMMON/utest/source/utest_case.cpp similarity index 63% rename from features/frameworks/utest/source/utest_case.cpp rename to TESTS/COMMON/utest/source/utest_case.cpp index 852869d84ae..6899ef258d5 100644 --- a/features/frameworks/utest/source/utest_case.cpp +++ b/TESTS/COMMON/utest/source/utest_case.cpp @@ -16,8 +16,8 @@ **************************************************************************** */ - #include "utest/utest_case.h" - #include "utest/utest_print.h" +#include "utest/utest_case.h" +#include "utest/utest_print.h" using namespace utest::v1; @@ -51,14 +51,14 @@ Case::Case(const char *description, const case_teardown_handler_t teardown_handler, const case_failure_handler_t failure_handler) : case_t(make_case( - description, - handler, - ignore_handler, - ignore_handler, - setup_handler, - teardown_handler, - failure_handler - )) + description, + handler, + ignore_handler, + ignore_handler, + setup_handler, + teardown_handler, + failure_handler + )) {} @@ -67,14 +67,14 @@ Case::Case(const char *description, const case_teardown_handler_t teardown_handler, const case_failure_handler_t failure_handler) : case_t(make_case( - description, - handler, - ignore_handler, - ignore_handler, - default_handler, - teardown_handler, - failure_handler - )) + description, + handler, + ignore_handler, + ignore_handler, + default_handler, + teardown_handler, + failure_handler + )) {} @@ -82,14 +82,14 @@ Case::Case(const char *description, const case_handler_t handler, const case_failure_handler_t failure_handler) : case_t(make_case( - description, - handler, - ignore_handler, - ignore_handler, - default_handler, - default_handler, - failure_handler - )) + description, + handler, + ignore_handler, + ignore_handler, + default_handler, + default_handler, + failure_handler + )) {} // control handler @@ -99,14 +99,14 @@ Case::Case(const char *description, const case_teardown_handler_t teardown_handler, const case_failure_handler_t failure_handler) : case_t(make_case( - description, - ignore_handler, - handler, - ignore_handler, - setup_handler, - teardown_handler, - failure_handler - )) + description, + ignore_handler, + handler, + ignore_handler, + setup_handler, + teardown_handler, + failure_handler + )) {} Case::Case(const char *description, @@ -114,28 +114,28 @@ Case::Case(const char *description, const case_teardown_handler_t teardown_handler, const case_failure_handler_t failure_handler) : case_t(make_case( - description, - ignore_handler, - handler, - ignore_handler, - default_handler, - teardown_handler, - failure_handler - )) + description, + ignore_handler, + handler, + ignore_handler, + default_handler, + teardown_handler, + failure_handler + )) {} Case::Case(const char *description, const case_control_handler_t handler, const case_failure_handler_t failure_handler) : case_t(make_case( - description, - ignore_handler, - handler, - ignore_handler, - default_handler, - default_handler, - failure_handler - )) + description, + ignore_handler, + handler, + ignore_handler, + default_handler, + default_handler, + failure_handler + )) {} // control flow handler @@ -145,28 +145,28 @@ Case::Case(const char *description, const case_teardown_handler_t teardown_handler, const case_failure_handler_t failure_handler) : case_t(make_case( - description, - ignore_handler, - ignore_handler, - case_repeat_count_handler, - setup_handler, - teardown_handler, - failure_handler - )) + description, + ignore_handler, + ignore_handler, + case_repeat_count_handler, + setup_handler, + teardown_handler, + failure_handler + )) {} Case::Case(const char *description, const case_call_count_handler_t case_repeat_count_handler, const case_failure_handler_t failure_handler) : case_t(make_case( - description, - ignore_handler, - ignore_handler, - case_repeat_count_handler, - default_handler, - default_handler, - failure_handler - )) + description, + ignore_handler, + ignore_handler, + case_repeat_count_handler, + default_handler, + default_handler, + failure_handler + )) {} Case::Case(const char *description, @@ -174,22 +174,24 @@ Case::Case(const char *description, const case_teardown_handler_t teardown_handler, const case_failure_handler_t failure_handler) : case_t(make_case( - description, - ignore_handler, - ignore_handler, - case_repeat_count_handler, - default_handler, - teardown_handler, - failure_handler - )) + description, + ignore_handler, + ignore_handler, + case_repeat_count_handler, + default_handler, + teardown_handler, + failure_handler + )) {} -const char* -Case::get_description() const { +const char * +Case::get_description() const +{ return description; } bool -Case::is_empty() const { +Case::is_empty() const +{ return !(handler || control_handler || repeat_count_handler || setup_handler || teardown_handler); } diff --git a/features/frameworks/utest/source/utest_default_handlers.cpp b/TESTS/COMMON/utest/source/utest_default_handlers.cpp similarity index 91% rename from features/frameworks/utest/source/utest_default_handlers.cpp rename to TESTS/COMMON/utest/source/utest_default_handlers.cpp index 22c592726f0..1f73a9b089d 100644 --- a/features/frameworks/utest/source/utest_default_handlers.cpp +++ b/TESTS/COMMON/utest/source/utest_default_handlers.cpp @@ -36,15 +36,16 @@ const handlers_t utest::v1::verbose_continue_handlers = { verbose_case_failure_handler }; -const handlers_t& utest::v1::default_handlers = greentea_abort_handlers; +const handlers_t &utest::v1::default_handlers = greentea_abort_handlers; // --- SPECIAL HANDLERS --- -static void test_failure_handler(const failure_t failure) { +static void test_failure_handler(const failure_t failure) +{ UTEST_LOG_FUNCTION(); if (failure.location == LOCATION_TEST_SETUP || failure.location == LOCATION_TEST_TEARDOWN) { verbose_test_failure_handler(failure); utest_printf("{{failure}}\n{{end}}\n"); - while(1) ; + while (1) ; } } @@ -65,13 +66,15 @@ void utest::v1::verbose_test_teardown_handler(const size_t passed, const size_t } else { utest_printf(" with reason '%s'\n", stringify(failure.reason)); } - if (failed) utest_printf(">>> TESTS FAILED!\n"); + if (failed) { + utest_printf(">>> TESTS FAILED!\n"); + } } void utest::v1::verbose_test_failure_handler(const failure_t failure) { utest_printf(">>> failure with reason '%s' during '%s'\n", stringify(failure.reason), stringify(failure.location)); - + } // --- VERBOSE CASE HANDLERS --- @@ -100,8 +103,12 @@ utest::v1::status_t utest::v1::verbose_case_failure_handler(const Case *const /* if (!(failure.reason & REASON_ASSERTION)) { verbose_test_failure_handler(failure); } - if (failure.reason & (REASON_TEST_TEARDOWN | REASON_CASE_TEARDOWN)) return STATUS_ABORT; - if (failure.reason & REASON_IGNORE) return STATUS_IGNORE; + if (failure.reason & (REASON_TEST_TEARDOWN | REASON_CASE_TEARDOWN)) { + return STATUS_ABORT; + } + if (failure.reason & REASON_IGNORE) { + return STATUS_IGNORE; + } return STATUS_CONTINUE; } diff --git a/features/frameworks/utest/source/utest_greentea_handlers.cpp b/TESTS/COMMON/utest/source/utest_greentea_handlers.cpp similarity index 96% rename from features/frameworks/utest/source/utest_greentea_handlers.cpp rename to TESTS/COMMON/utest/source/utest_greentea_handlers.cpp index 3311b778646..169195fe239 100644 --- a/features/frameworks/utest/source/utest_greentea_handlers.cpp +++ b/TESTS/COMMON/utest/source/utest_greentea_handlers.cpp @@ -58,7 +58,8 @@ const handlers_t utest::v1::selftest_handlers = { // --- SPECIAL HANDLERS --- -static void selftest_failure_handler(const failure_t failure) { +static void selftest_failure_handler(const failure_t failure) +{ UTEST_LOG_FUNCTION(); if (failure.location == LOCATION_TEST_SETUP || failure.location == LOCATION_TEST_TEARDOWN || failure.reason == REASON_ASSERTION) { verbose_test_failure_handler(failure); @@ -66,16 +67,17 @@ static void selftest_failure_handler(const failure_t failure) { if (failure.reason == REASON_ASSERTION) { UTEST_DUMP_TRACE GREENTEA_TESTSUITE_RESULT(false); - while(1) ; + while (1) ; } } -static void test_failure_handler(const failure_t failure) { +static void test_failure_handler(const failure_t failure) +{ UTEST_LOG_FUNCTION(); if (failure.location == LOCATION_TEST_SETUP || failure.location == LOCATION_TEST_TEARDOWN) { verbose_test_failure_handler(failure); GREENTEA_TESTSUITE_RESULT(false); - while(1) ; + while (1) ; } } diff --git a/features/frameworks/utest/source/utest_harness.cpp b/TESTS/COMMON/utest/source/utest_harness.cpp similarity index 72% rename from features/frameworks/utest/source/utest_harness.cpp rename to TESTS/COMMON/utest/source/utest_harness.cpp index 63911b1f449..9867b155fad 100644 --- a/features/frameworks/utest/source/utest_harness.cpp +++ b/TESTS/COMMON/utest/source/utest_harness.cpp @@ -24,45 +24,45 @@ using namespace utest::v1; -namespace -{ - const Case *test_cases = NULL; - size_t test_length = 0; +namespace { +const Case *test_cases = NULL; +size_t test_length = 0; - size_t test_index_of_case = 0; +size_t test_index_of_case = 0; - size_t test_passed = 0; - size_t test_failed = 0; +size_t test_passed = 0; +size_t test_failed = 0; - const Case *case_current = NULL; - size_t case_index = 0; - base_control_t case_control = { REPEAT_SETUP_TEARDOWN, TIMEOUT_UNDECLR }; - size_t case_repeat_count = 1; +const Case *case_current = NULL; +size_t case_index = 0; +base_control_t case_control = { REPEAT_SETUP_TEARDOWN, TIMEOUT_UNDECLR }; +size_t case_repeat_count = 1; - void *case_timeout_handle = NULL; - size_t case_validation_count = 0; - bool case_timeout_occurred = false; +void *case_timeout_handle = NULL; +size_t case_validation_count = 0; +bool case_timeout_occurred = false; - size_t case_passed = 0; - size_t case_failed = 0; - size_t case_failed_before = 0; +size_t case_passed = 0; +size_t case_failed = 0; +size_t case_failed_before = 0; - struct DefaultHandlers : public handlers_t { - DefaultHandlers() : handlers_t(default_handlers) { } - DefaultHandlers(const handlers_t& other) : handlers_t(other) { } - }; +struct DefaultHandlers : public handlers_t { + DefaultHandlers() : handlers_t(default_handlers) { } + DefaultHandlers(const handlers_t &other) : handlers_t(other) { } +}; - SingletonPtr defaults; - SingletonPtr handlers; +SingletonPtr defaults; +SingletonPtr handlers; - location_t location = LOCATION_UNKNOWN; +location_t location = LOCATION_UNKNOWN; - utest_v1_scheduler_t scheduler = {NULL, NULL, NULL, NULL}; +utest_v1_scheduler_t scheduler = {NULL, NULL, NULL, NULL}; } -static void die() { +static void die() +{ UTEST_LOG_FUNCTION(); - while(1) ; + while (1) ; } static bool is_scheduler_valid(const utest_v1_scheduler_t scheduler) @@ -84,35 +84,39 @@ bool Harness::set_scheduler(const utest_v1_scheduler_t scheduler) void Harness::notify_testcases() { - for(unsigned i = 0; i < test_length; i++) { + for (unsigned i = 0; i < test_length; i++) { utest::v1::greentea_testcase_notification_handler(test_cases[i].get_description()); } } -bool Harness::run(const Specification& specification, size_t) +bool Harness::run(const Specification &specification, size_t) { UTEST_LOG_FUNCTION(); return run(specification); } -bool Harness::run(const Specification& specification) +bool Harness::run(const Specification &specification) { UTEST_LOG_FUNCTION(); // check if a specification is currently running - if (is_busy()) + if (is_busy()) { return false; + } // if the scheduler is invalid, this is the first time we are calling - if (!is_scheduler_valid(scheduler)) + if (!is_scheduler_valid(scheduler)) { scheduler = utest_v1_get_scheduler(); + } // if the scheduler is still invalid, abort - if (!is_scheduler_valid(scheduler)) + if (!is_scheduler_valid(scheduler)) { return false; + } // if the scheduler failed to initialize, abort - if (scheduler.init() != 0) + if (scheduler.init() != 0) { return false; + } test_cases = specification.cases; test_length = specification.length; *defaults.get() = specification.defaults; @@ -134,14 +138,22 @@ bool Harness::run(const Specification& specification) if (handlers->test_setup) { setup_status = handlers->test_setup(test_length); - if (setup_status == STATUS_CONTINUE) setup_status = 0; - else if (setup_status < STATUS_CONTINUE) failure.reason = REASON_TEST_SETUP; - else if (setup_status > signed(test_length)) failure.reason = REASON_CASE_INDEX; + if (setup_status == STATUS_CONTINUE) { + setup_status = 0; + } else if (setup_status < STATUS_CONTINUE) { + failure.reason = REASON_TEST_SETUP; + } else if (setup_status > signed(test_length)) { + failure.reason = REASON_CASE_INDEX; + } } if (failure.reason != REASON_NONE) { - if (handlers->test_failure) handlers->test_failure(failure); - if (handlers->test_teardown) handlers->test_teardown(0, 0, failure); + if (handlers->test_failure) { + handlers->test_failure(failure); + } + if (handlers->test_teardown) { + handlers->test_teardown(0, 0, failure); + } test_cases = NULL; exit(1); } @@ -154,8 +166,12 @@ bool Harness::run(const Specification& specification) scheduler.post(run_next_case, 0); if (scheduler.run() != 0) { failure.reason = REASON_SCHEDULER; - if (handlers->test_failure) handlers->test_failure(failure); - if (handlers->test_teardown) handlers->test_teardown(0, 0, failure); + if (handlers->test_failure) { + handlers->test_failure(failure); + } + if (handlers->test_teardown) { + handlers->test_teardown(0, 0, failure); + } test_cases = NULL; exit(1); } @@ -167,19 +183,26 @@ void Harness::raise_failure(const failure_reason_t reason) UTEST_LOG_FUNCTION(); // ignore a failure, if the Harness has not been initialized. // this allows using unity assertion macros without setting up utest. - if (test_cases == NULL) return; + if (test_cases == NULL) { + return; + } utest::v1::status_t fail_status = STATUS_ABORT; - if (handlers->test_failure) handlers->test_failure(failure_t(reason, location)); - if (handlers->case_failure) fail_status = handlers->case_failure(case_current, failure_t(reason, location)); + if (handlers->test_failure) { + handlers->test_failure(failure_t(reason, location)); + } + if (handlers->case_failure) { + fail_status = handlers->case_failure(case_current, failure_t(reason, location)); + } { UTEST_ENTER_CRITICAL_SECTION; - if (fail_status != STATUS_IGNORE) case_failed++; + if (fail_status != STATUS_IGNORE) { + case_failed++; + } - if ((fail_status == STATUS_ABORT) && case_timeout_handle) - { + if ((fail_status == STATUS_ABORT) && case_timeout_handle) { scheduler.cancel(case_timeout_handle); case_timeout_handle = NULL; } @@ -192,9 +215,13 @@ void Harness::raise_failure(const failure_reason_t reason) location = LOCATION_CASE_TEARDOWN; utest::v1::status_t teardown_status = handlers->case_teardown(case_current, case_passed, case_failed, failure_t(reason, fail_loc)); - if (teardown_status < STATUS_CONTINUE) raise_failure(REASON_CASE_TEARDOWN); - else if (teardown_status > signed(test_length)) raise_failure(REASON_CASE_INDEX); - else if (teardown_status >= 0) case_index = teardown_status - 1; + if (teardown_status < STATUS_CONTINUE) { + raise_failure(REASON_CASE_TEARDOWN); + } else if (teardown_status > signed(test_length)) { + raise_failure(REASON_CASE_INDEX); + } else if (teardown_status >= 0) { + case_index = teardown_status - 1; + } // Restore case failure location once we have dealt with case teardown location = fail_loc; @@ -205,7 +232,9 @@ void Harness::raise_failure(const failure_reason_t reason) test_failed++; failure_t fail(reason, location); location = LOCATION_TEST_TEARDOWN; - if (handlers->test_teardown) handlers->test_teardown(test_passed, test_failed, fail); + if (handlers->test_teardown) { + handlers->test_teardown(test_passed, test_failed, fail); + } exit(test_failed); die(); } @@ -223,16 +252,23 @@ void Harness::schedule_next_case() if (handlers->case_teardown) { utest::v1::status_t status = handlers->case_teardown(case_current, case_passed, case_failed, - case_failed ? failure_t(REASON_CASES, LOCATION_UNKNOWN) : failure_t(REASON_NONE)); - if (status < STATUS_CONTINUE) raise_failure(REASON_CASE_TEARDOWN); - else if (status > signed(test_length)) raise_failure(REASON_CASE_INDEX); - else if (status >= 0) case_index = status - 1; + case_failed ? failure_t(REASON_CASES, LOCATION_UNKNOWN) : failure_t(REASON_NONE)); + if (status < STATUS_CONTINUE) { + raise_failure(REASON_CASE_TEARDOWN); + } else if (status > signed(test_length)) { + raise_failure(REASON_CASE_INDEX); + } else if (status >= 0) { + case_index = status - 1; + } } } if (!(case_control.repeat & (REPEAT_ON_TIMEOUT | REPEAT_ON_VALIDATE))) { - if (case_failed > 0) test_failed++; - else test_passed++; + if (case_failed > 0) { + test_failed++; + } else { + test_passed++; + } case_control = control_t(REPEAT_SETUP_TEARDOWN); case_index++; @@ -270,8 +306,7 @@ void Harness::validate_callback(const control_t control) UTEST_ENTER_CRITICAL_SECTION; case_validation_count++; - if (case_timeout_handle != NULL || case_control.timeout == TIMEOUT_FOREVER) - { + if (case_timeout_handle != NULL || case_control.timeout == TIMEOUT_FOREVER) { scheduler.cancel(case_timeout_handle); case_timeout_handle = NULL; control_t merged_control = case_control + control; @@ -287,11 +322,11 @@ bool Harness::is_busy() UTEST_LOG_FUNCTION(); UTEST_ENTER_CRITICAL_SECTION; bool res = false; - - if (test_cases && case_current) { + + if (test_cases && case_current) { res = (case_current < (test_cases + test_length)); } - + UTEST_LEAVE_CRITICAL_SECTION; return res; } @@ -299,8 +334,7 @@ bool Harness::is_busy() void Harness::run_next_case() { UTEST_LOG_FUNCTION(); - if(case_current < (test_cases + test_length)) - { + if (case_current < (test_cases + test_length)) { handlers->case_setup = defaults->get_handler(case_current->setup_handler); handlers->case_teardown = defaults->get_handler(case_current->teardown_handler); handlers->case_failure = defaults->get_handler(case_current->failure_handler); @@ -345,7 +379,9 @@ void Harness::run_next_case() { UTEST_ENTER_CRITICAL_SECTION; - if (case_validation_count) case_control.repeat = repeat_t(case_control.repeat & ~REPEAT_ON_TIMEOUT); + if (case_validation_count) { + case_control.repeat = repeat_t(case_control.repeat & ~REPEAT_ON_TIMEOUT); + } // if timeout valid if (case_control.timeout < TIMEOUT_UNDECLR && case_validation_count == 0) { @@ -357,14 +393,12 @@ void Harness::run_next_case() schedule_next_case(); } } - } - else { + } else { scheduler.post(schedule_next_case, 0); } UTEST_LEAVE_CRITICAL_SECTION; } - } - else if (handlers->test_teardown) { + } else if (handlers->test_teardown) { location = LOCATION_TEST_TEARDOWN; handlers->test_teardown(test_passed, test_failed, test_failed ? failure_t(REASON_CASES, LOCATION_UNKNOWN) : failure_t(REASON_NONE)); test_cases = NULL; diff --git a/features/frameworks/utest/source/utest_print.cpp b/TESTS/COMMON/utest/source/utest_print.cpp similarity index 100% rename from features/frameworks/utest/source/utest_print.cpp rename to TESTS/COMMON/utest/source/utest_print.cpp diff --git a/features/frameworks/utest/source/utest_shim.cpp b/TESTS/COMMON/utest/source/utest_shim.cpp similarity index 86% rename from features/frameworks/utest/source/utest_shim.cpp rename to TESTS/COMMON/utest/source/utest_shim.cpp index e223a753f9b..9b5e4a5dbfe 100644 --- a/features/frameworks/utest/source/utest_shim.cpp +++ b/TESTS/COMMON/utest/source/utest_shim.cpp @@ -52,13 +52,12 @@ static void *utest_us_ticker_post(const utest_v1_harness_callback_t callback, ti ticker_callback = callback; // fire the interrupt in 1000us * delay_ms utest_timeout_object->attach(ticker_handler, milliseconds(delay_ms)); - } - else { + } else { minimal_callback = callback; } // return a bogus handle - return (void*)1; + return (void *)1; } static int32_t utest_us_ticker_cancel(void *handle) { @@ -70,11 +69,9 @@ static int32_t utest_us_ticker_cancel(void *handle) static int32_t utest_us_ticker_run() { UTEST_LOG_FUNCTION(); - while(1) - { + while (1) { // check if a new callback has been set - if (minimal_callback) - { + if (minimal_callback) { // copy the callback utest_v1_harness_callback_t callback = minimal_callback; // reset the shared callback @@ -87,16 +84,15 @@ static int32_t utest_us_ticker_run() extern "C" { -static const utest_v1_scheduler_t utest_v1_scheduler = -{ - utest_us_ticker_init, - utest_us_ticker_post, - utest_us_ticker_cancel, - utest_us_ticker_run -}; -utest_v1_scheduler_t utest_v1_get_scheduler() -{ - UTEST_LOG_FUNCTION(); - return utest_v1_scheduler; -} + static const utest_v1_scheduler_t utest_v1_scheduler = { + utest_us_ticker_init, + utest_us_ticker_post, + utest_us_ticker_cancel, + utest_us_ticker_run + }; + utest_v1_scheduler_t utest_v1_get_scheduler() + { + UTEST_LOG_FUNCTION(); + return utest_v1_scheduler; + } } diff --git a/features/frameworks/utest/source/utest_stack_trace.cpp b/TESTS/COMMON/utest/source/utest_stack_trace.cpp similarity index 92% rename from features/frameworks/utest/source/utest_stack_trace.cpp rename to TESTS/COMMON/utest/source/utest_stack_trace.cpp index 634b1f2a058..6db6bcf1285 100644 --- a/features/frameworks/utest/source/utest_stack_trace.cpp +++ b/TESTS/COMMON/utest/source/utest_stack_trace.cpp @@ -15,7 +15,7 @@ * limitations under the License. */ #ifdef UTEST_STACK_TRACE - + #include "greentea-client/test_env.h" #include "utest/utest.h" #include "unity/unity.h" @@ -33,14 +33,14 @@ void utest_trace_initialise() { total_calls = 0; trace_index = 0; - for(unsigned i = 0; i < UTEST_MAX_BACKTRACE; i++) { - utest_trace[i].clear(); + for (unsigned i = 0; i < UTEST_MAX_BACKTRACE; i++) { + utest_trace[i].clear(); } } void utest_add_to_trace(char *func_name) -{ - utest_trace[trace_index] = std::string(func_name); +{ + utest_trace[trace_index] = std::string(func_name); trace_index = (trace_index + 1 == UTEST_MAX_BACKTRACE) ? 0 : trace_index + 1; total_calls ++; } @@ -53,7 +53,7 @@ void utest_dump_trace() utest_printf("Utest back trace: Total calls logged = %u.\n", total_calls); utest_printf("==================================================================\n"); while (current != trace_index) { - + utest_printf("%u > %s\n", current, utest_trace[current].c_str()); current = (current == 0) ? UTEST_MAX_BACKTRACE - 1 : current - 1; } diff --git a/features/frameworks/utest/source/utest_types.cpp b/TESTS/COMMON/utest/source/utest_types.cpp similarity index 90% rename from features/frameworks/utest/source/utest_types.cpp rename to TESTS/COMMON/utest/source/utest_types.cpp index 16a753248eb..46f081afe6f 100644 --- a/features/frameworks/utest/source/utest_types.cpp +++ b/TESTS/COMMON/utest/source/utest_types.cpp @@ -16,13 +16,12 @@ **************************************************************************** */ - #include "utest/utest_types.h" +#include "utest/utest_types.h" -const char* utest::v1::stringify(utest::v1::failure_reason_t reason) +const char *utest::v1::stringify(utest::v1::failure_reason_t reason) { const char *string; - switch(reason & ~REASON_IGNORE) - { + switch (reason & ~REASON_IGNORE) { case REASON_NONE: string = "Ignored: No Failure"; break; @@ -64,20 +63,21 @@ const char* utest::v1::stringify(utest::v1::failure_reason_t reason) string = "Ignored: Unknown Failure"; break; } - if (!(reason & REASON_IGNORE)) string += 9; + if (!(reason & REASON_IGNORE)) { + string += 9; + } return string; } -const char* utest::v1::stringify(utest::v1::failure_t failure) +const char *utest::v1::stringify(utest::v1::failure_t failure) { return stringify(failure.reason); } -const char* utest::v1::stringify(utest::v1::location_t location) +const char *utest::v1::stringify(utest::v1::location_t location) { const char *string; - switch(location) - { + switch (location) { case LOCATION_TEST_SETUP: string = "Test Setup Handler"; break; @@ -101,10 +101,9 @@ const char* utest::v1::stringify(utest::v1::location_t location) return string; } -const char* utest::v1::stringify(utest::v1::status_t status) +const char *utest::v1::stringify(utest::v1::status_t status) { - switch(status) - { + switch (status) { case STATUS_CONTINUE: return "Continue"; case STATUS_IGNORE: diff --git a/features/frameworks/utest/utest/utest_case.h b/features/frameworks/utest/utest/utest_case.h deleted file mode 100644 index 5f158ca6a92..00000000000 --- a/features/frameworks/utest/utest/utest_case.h +++ /dev/null @@ -1,180 +0,0 @@ -/**************************************************************************** - * Copyright (c) 2015, ARM Limited, All Rights Reserved - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - **************************************************************************** - */ - -#ifndef UTEST_CASES_H -#define UTEST_CASES_H - -#include -#include -#include -#include "utest/utest_types.h" -#include "utest/utest_default_handlers.h" - - -namespace utest { -/** \addtogroup frameworks */ -/** @{*/ -namespace v1 { - /** - * POD data structure of the Case class. - * Unlike the Case class it can be used as a POD and be put in ROM. - * - * @warning Initialization of handlers with either default_handler or - * ignore_handler helpers will prevent the object to be a POD. Prefer usage - * of NULL in favor of ignore_handler or \verbatim (1) \endverbatim for default - * handler. - * - * @see Case. - */ - struct case_t - { - /** - * Textual description of the test case - */ - const char *description; - - /** - * Primitive test case handler - * This is called only if the case setup succeeded. It is followed by - * the test case teardown handler. - */ - const case_handler_t handler; - - /** - * @see case_control_handler_t - */ - const case_control_handler_t control_handler; - - /** - * @see case_call_count_handler_t - */ - const case_call_count_handler_t repeat_count_handler; - - /** - * Handler called before the execution of the case handler. It sets up - * the case environment. - */ - const case_setup_handler_t setup_handler; - - /** - * Handler called after the execution of the case handler. It cleans up - * the case environment. - */ - const case_teardown_handler_t teardown_handler; - - /** - * Handler called whenever a faillure occur; at any stage of the case - * execution (including setup and teardown). - */ - const case_failure_handler_t failure_handler; - }; - - /** Test case wrapper class. - * - * This class contains the description of the test case and all handlers - * for setting up, running the test case, tearing down and handling failures. - * - * By default you only need to provide a description and a test case handler. - * You may override the setup, teardown and failure handlers, but you do not have to. - * If you do not override these handler, the specified default handlers will be called. - * - * These constructors are overloaded to allow you a comfortable declaration of all your - * callbacks. - * The order is always: - * - description (required) - * - setup handler (optional) - * - test case handler (required) - * - teardown handler (optional) - * - failure handler (optional) - * - * @note While you can specify an empty test case (ie. use `ignore_handler` for all callbacks), - * the harness will abort the test unconditionally. - */ - class Case : private case_t - { - public: - // overloads for case_handler_t - Case(const char *description, - const case_setup_handler_t setup_handler, - const case_handler_t case_handler, - const case_teardown_handler_t teardown_handler = default_handler, - const case_failure_handler_t failure_handler = default_handler); - - Case(const char *description, - const case_handler_t case_handler, - const case_failure_handler_t failure_handler = default_handler); - - Case(const char *description, - const case_handler_t case_handler, - const case_teardown_handler_t teardown_handler, - const case_failure_handler_t failure_handler = default_handler); - - // overloads for case_control_handler_t - Case(const char *description, - const case_setup_handler_t setup_handler, - const case_control_handler_t case_handler, - const case_teardown_handler_t teardown_handler = default_handler, - const case_failure_handler_t failure_handler = default_handler); - - Case(const char *description, - const case_control_handler_t case_handler, - const case_failure_handler_t failure_handler = default_handler); - - Case(const char *description, - const case_control_handler_t case_handler, - const case_teardown_handler_t teardown_handler, - const case_failure_handler_t failure_handler = default_handler); - - // overloads for case_call_count_handler_t - Case(const char *description, - const case_setup_handler_t setup_handler, - const case_call_count_handler_t case_handler, - const case_teardown_handler_t teardown_handler = default_handler, - const case_failure_handler_t failure_handler = default_handler); - - Case(const char *description, - const case_call_count_handler_t case_handler, - const case_failure_handler_t failure_handler = default_handler); - - Case(const char *description, - const case_call_count_handler_t case_handler, - const case_teardown_handler_t teardown_handler, - const case_failure_handler_t failure_handler = default_handler); - - - /// @returns the textual description of the test case - const char* get_description() const; - - /// @returns `true` if setup, test and teardown handlers are set to `ignore_handler` - bool is_empty() const; - - private: - // IMPORTANT: No data members shall be declared inside this class. - // Data members shall be declared in case_t to preserve the layout - // and the compatibility between the two types. - - friend class Harness; - friend class Specification; - }; - -} // namespace v1 -} // namespace utest - - #endif // UTEST_CASES_H - -/** @}*/ diff --git a/features/frameworks/utest/utest/utest_default_handlers.h b/features/frameworks/utest/utest/utest_default_handlers.h deleted file mode 100644 index ad89963e190..00000000000 --- a/features/frameworks/utest/utest/utest_default_handlers.h +++ /dev/null @@ -1,205 +0,0 @@ -/**************************************************************************** - * Copyright (c) 2015, ARM Limited, All Rights Reserved - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - **************************************************************************** - */ - -#ifndef UTEST_DEFAULT_HANDLER_H -#define UTEST_DEFAULT_HANDLER_H - -#include -#include -#include -#include "utest/utest_types.h" - - -namespace utest { -/** \addtogroup frameworks */ -/** @{*/ -namespace v1 { - - /** Default handler hint. - * - * Use this handler to indicate the you want the default handler to be called. - * This type automatically casts itself into the appropriate handler type, when possible. - * Use the constants to default a handler unambigously. - */ - static const struct - { - ///@cond IGNORE - // Doxygen can't parse these implicit conversion operators properly, remove from - // doc build - operator test_setup_handler_t() const { return test_setup_handler_t(1); } - operator test_teardown_handler_t() const { return test_teardown_handler_t(1); } - operator test_failure_handler_t() const { return test_failure_handler_t(1); } - - operator case_setup_handler_t() const { return case_setup_handler_t(1); } - operator case_teardown_handler_t() const { return case_teardown_handler_t(1); } - operator case_failure_handler_t() const { return case_failure_handler_t(1); } - ///@endcond - } default_handler; - - /** Ignore handler hint. - * - * Use this handler to indicate the you want to ignore this handler and it will not be called. - * This type automatically casts itself into the appropriate handler type, when possible. - * Use the constants to ignore a handler unambigously. - */ - static const struct - { - ///@cond IGNORE - // Doxygen can't parse these implicit conversion operators properly, remove from - // doc build - operator case_handler_t() const { return case_handler_t(NULL); } - operator case_control_handler_t() const { return case_control_handler_t(NULL); } - operator case_call_count_handler_t() const { return case_call_count_handler_t(NULL); } - - operator test_setup_handler_t() const { return test_setup_handler_t(NULL); } - operator test_teardown_handler_t() const { return test_teardown_handler_t(NULL); } - operator test_failure_handler_t() const { return test_failure_handler_t(NULL); } - - operator case_setup_handler_t() const { return case_setup_handler_t(NULL); } - operator case_teardown_handler_t() const { return case_teardown_handler_t(NULL); } - operator case_failure_handler_t() const { return case_failure_handler_t(NULL); } - ///@endcond - } ignore_handler; - - /** A table of handlers. - * - * This structure stores all modifyable handlers and provides accessors to - * filter out the default handler. - * So if this structure contains handlers, and you want to use these handlers - * as a default backup, you can use the `get_handler` function to choose the right handler. - * - * Example: - * @code - * const handler_t defaults = { ... }; // your default handlers - * // will return the handler in defaults. - * test_setup_handler_t handler = defaults.get_handler(default_handler); - * // you will still need to manually check the handler before executing it - * if (handler != ignore_handler) handler(...); - * - * extern test_teardown_handler_t custom_handler(...); - * // will return `custom_handler` - * test_teardown_handler_t handler = defaults.get_handler(custom_handler); - * // you will still need to manually check the handler before executing it - * if (handler != ignore_handler) handler(...); - * @endcode - */ - struct handlers_t - { - test_setup_handler_t test_setup; - test_teardown_handler_t test_teardown; - test_failure_handler_t test_failure; - - case_setup_handler_t case_setup; - case_teardown_handler_t case_teardown; - case_failure_handler_t case_failure; - - inline test_setup_handler_t get_handler(test_setup_handler_t handler) const { - if (handler == default_handler) return test_setup; - return handler; - } - inline test_teardown_handler_t get_handler(test_teardown_handler_t handler) const { - if (handler == default_handler) return test_teardown; - return handler; - } - inline test_failure_handler_t get_handler(test_failure_handler_t handler) const { - if (handler == default_handler) return test_failure; - return handler; - } - - inline case_setup_handler_t get_handler(case_setup_handler_t handler) const { - if (handler == default_handler) return case_setup; - return handler; - } - inline case_teardown_handler_t get_handler(case_teardown_handler_t handler) const { - if (handler == default_handler) return case_teardown; - return handler; - } - inline case_failure_handler_t get_handler(case_failure_handler_t handler) const { - if (handler == default_handler) return case_failure; - return handler; - } - }; - - /// Prints the number of tests to run and continues. - utest::v1::status_t verbose_test_setup_handler (const size_t number_of_cases); - /// Prints the number of tests that passed and failed with a reason if provided. - void verbose_test_teardown_handler(const size_t passed, const size_t failed, const failure_t failure); - /// Prints the failure for `REASON_TEST_SETUP` and `REASON_TEST_TEARDOWN` and then dies. - void verbose_test_failure_handler (const failure_t failure); - - /// Prints the index and description of the case being run and continues. - utest::v1::status_t verbose_case_setup_handler (const Case *const source, const size_t index_of_case); - /// Prints the number of tests that passed and failed with a reason if provided within this case and continues. - utest::v1::status_t verbose_case_teardown_handler(const Case *const source, const size_t passed, const size_t failed, const failure_t failure); - /// Prints the reason of the failure and continues, unless the teardown handler failed, for which it aborts. - utest::v1::status_t verbose_case_failure_handler (const Case *const source, const failure_t reason); - - /// Default greentea test case set up handler - #define UTEST_DEFAULT_GREENTEA_TIMEOUT 10 //Seconds - #define UTEST_DEFAULT_HOST_TEST_NAME "default_auto" - - utest::v1::status_t default_greentea_test_setup_handler (const size_t number_of_cases); - - /// Requests the start test case from greentea and continues. - /// Example usage: - /// utest::v1::status_t greentea_test_setup(const size_t number_of_cases) { - /// GREENTEA_SETUP(5, "default_auto"); - /// return greentea_test_setup_handler(number_of_cases); - /// } - /// - /// Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler); - utest::v1::status_t greentea_test_setup_handler (const size_t number_of_cases); - - /// Reports the test results to greentea. - void greentea_test_teardown_handler(const size_t passed, const size_t failed, const failure_t failure); - /// Reports the failure for `REASON_TEST_SETUP` and `REASON_TEST_TEARDOWN` to greentea and then dies. - void greentea_test_failure_handler (const failure_t failure); - - /// Registers the test case setup with greentea. - utest::v1::status_t greentea_case_setup_handler (const Case *const source, const size_t index_of_case); - /// Registers the test case teardown with greentea. - utest::v1::status_t greentea_case_teardown_handler(const Case *const source, const size_t passed, const size_t failed, const failure_t failure); - /// Reports the failure to greentea and then aborts. - utest::v1::status_t greentea_case_failure_abort_handler (const Case *const source, const failure_t reason); - /// Reports the failure to greentea and then continues. - utest::v1::status_t greentea_case_failure_continue_handler(const Case *const source, const failure_t reason); - - /// Notify greentea of testcase name. - void greentea_testcase_notification_handler(const char *testcase); - - /// The verbose default handlers that always continue on failure - extern const handlers_t verbose_continue_handlers; - - /// The greentea default handlers that always abort on the first encountered failure - extern const handlers_t greentea_abort_handlers; - - /// The greentea default handlers that always continue on failure - extern const handlers_t greentea_continue_handlers; - - /// The selftest default handlers that always abort on _any_ assertion failure, otherwise continue - extern const handlers_t selftest_handlers; - - /// The greentea aborting handlers are the default - extern const handlers_t& default_handlers; - -} // namespace v1 -} // namespace utest - -#endif // UTEST_DEFAULT_HANDLER_H - -/** @}*/ diff --git a/features/frameworks/utest/utest/utest_harness.h b/features/frameworks/utest/utest/utest_harness.h deleted file mode 100644 index 2f0bdbe6d8c..00000000000 --- a/features/frameworks/utest/utest/utest_harness.h +++ /dev/null @@ -1,100 +0,0 @@ -/**************************************************************************** - * Copyright (c) 2015, ARM Limited, All Rights Reserved - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - **************************************************************************** - */ - -#ifndef UTEST_HARNESS_H -#define UTEST_HARNESS_H - -#include -#include -#include - -#include "utest/utest_types.h" -#include "utest/utest_case.h" -#include "utest/utest_default_handlers.h" -#include "utest/utest_specification.h" -#include "utest/utest_scheduler.h" - - -namespace utest { -/** \addtogroup frameworks */ -/** @{*/ -namespace v1 { - - /** Test Harness. - * - * This class runs a test specification for you and calls all required handlers. - * The harness executes the test specification in an asynchronous fashion, therefore - * `run()` returns immediately. - * - * @note In case of an test abort, the harness will busy-wait and never finish. - */ - class Harness - { - public: - /// Runs a test specification - /// @retval `true` if the specification can be run - /// @retval `false` if another specification is currently running - static bool run(const Specification& specification); - - /// @cond - __deprecated_message("Start case selection is done by returning the index from the test setup handler!") - static bool run(const Specification& specification, size_t start_case); - /// @endcond - - /// @returns `true` if a test specification is being executed, `false` otherwise - static bool is_busy(); - - /// Sets the scheduler to be used. - /// @return `true` if scheduler is properly specified (all functions non-null). - static bool set_scheduler(utest_v1_scheduler_t scheduler); - - /** Call this function in the asynchronous callback that you have been waiting for. - * - * You can only validate a callback once, calling this function when no callback is expected - * has no side effects. - * After callback validation, the next test case is scheduled. - * - * You may specify additional test case attributes with this callback. - * So for example, you may delay the decision to repeat an asynchronous test case until the callback - * needs to be validated. - * - * However, be aware, that only the repeat attributes can be modified and the usual arbitration rules apply. - * The modified case attributes are only valid until the case handler returns updated attributes. - * - * @param control the test case attribute to be added to the existing attributes. - */ - static void validate_callback(const control_t control = control_t()); - - /// Raising a failure causes the failure to be counted and the failure handler to be called. - /// Further action then depends on its return state. - static void raise_failure(const failure_reason_t reason); - - protected: - static void run_next_case(); - static void handle_timeout(); - static void schedule_next_case(); - private: - static void notify_testcases(); - }; - -} // namespace v1 -} // namespace utest - -#endif // UTEST_HARNESS_H - -/** @}*/ diff --git a/features/frameworks/utest/utest/utest_specification.h b/features/frameworks/utest/utest/utest_specification.h deleted file mode 100644 index 70ccb1ff028..00000000000 --- a/features/frameworks/utest/utest/utest_specification.h +++ /dev/null @@ -1,190 +0,0 @@ -/**************************************************************************** - * Copyright (c) 2015, ARM Limited, All Rights Reserved - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - **************************************************************************** - */ - -#ifndef UTEST_SPECIFICATION_H -#define UTEST_SPECIFICATION_H - -#include -#include -#include -#include "utest/utest_types.h" -#include "utest/utest_case.h" -#include "utest/utest_default_handlers.h" - - -namespace utest { -/** \addtogroup frameworks */ -/** @{*/ -namespace v1 { - - /** Test specification containing the setup and teardown handlers and test cases. - * - * This class simply holds the test cases and allows you to specify default handlers, and - * override setup and teardown handlers. - * The order of arguments is: - * - test setup handler (optional) - * - array of test cases (required) - * - test teardown handler (optional) - * - default handlers (optional) - * - * @note You cannot set the size of the test case array dynamically, it is template deducted at compile - * time. Creating test specifications for unittests at runtime is explicitly not supported. - */ - class Specification - { - public: - template< size_t N, typename CaseType > - Specification(const CaseType (&cases)[N], - const handlers_t defaults = default_handlers) : - setup_handler(default_handler), teardown_handler(default_handler), failure_handler(default_handler), - cases(static_cast(static_cast(cases))), length(N), - defaults(defaults) - { - MBED_STATIC_ASSERT( - sizeof(CaseType) == sizeof(Case), - "CaseType and Case should have the same size" - ); - } - - template< size_t N, typename CaseType > - Specification(const CaseType (&cases)[N], - const test_failure_handler_t failure_handler, - const handlers_t defaults = default_handlers) : - setup_handler(default_handler), teardown_handler(default_handler), failure_handler(failure_handler), - cases(static_cast(static_cast(cases))), length(N), - defaults(defaults) - { - MBED_STATIC_ASSERT( - sizeof(CaseType) == sizeof(Case), - "CaseType and Case should have the same size" - ); - } - - template< size_t N, typename CaseType > - Specification(const CaseType (&cases)[N], - const test_teardown_handler_t teardown_handler, - const handlers_t defaults = default_handlers) : - setup_handler(default_handler), teardown_handler(teardown_handler), failure_handler(default_handler), - cases(static_cast(static_cast(cases))), length(N), - defaults(defaults) - { - MBED_STATIC_ASSERT( - sizeof(CaseType) == sizeof(Case), - "CaseType and Case should have the same size" - ); - } - - template< size_t N, typename CaseType > - Specification(const CaseType (&cases)[N], - const test_teardown_handler_t teardown_handler, - const test_failure_handler_t failure_handler, - const handlers_t defaults = default_handlers) : - setup_handler(default_handler), teardown_handler(teardown_handler), failure_handler(failure_handler), - cases(static_cast(static_cast(cases))), length(N), - defaults(defaults) - { - MBED_STATIC_ASSERT( - sizeof(CaseType) == sizeof(Case), - "CaseType and Case should have the same size" - ); - } - - template< size_t N, typename CaseType > - Specification(const test_setup_handler_t setup_handler, - const CaseType (&cases)[N], - const handlers_t defaults = default_handlers) : - setup_handler(setup_handler), teardown_handler(default_handler), failure_handler(default_handler), - cases(static_cast(static_cast(cases))), length(N), - defaults(defaults) - {} - - template< size_t N, typename CaseType > - Specification(const test_setup_handler_t setup_handler, - const CaseType (&cases)[N], - const test_failure_handler_t failure_handler, - const handlers_t defaults = default_handlers) : - setup_handler(setup_handler), teardown_handler(default_handler), failure_handler(failure_handler), - cases(static_cast(static_cast(cases))), length(N), - defaults(defaults) - { - MBED_STATIC_ASSERT( - sizeof(CaseType) == sizeof(Case), - "CaseType and Case should have the same size" - ); - } - - template< size_t N, typename CaseType > - Specification(const test_setup_handler_t setup_handler, - const CaseType (&cases)[N], - const test_teardown_handler_t teardown_handler, - const handlers_t defaults = default_handlers) : - setup_handler(setup_handler), teardown_handler(teardown_handler), failure_handler(default_handler), - cases(static_cast(static_cast(cases))), length(N), - defaults(defaults) - { - MBED_STATIC_ASSERT( - sizeof(CaseType) == sizeof(Case), - "CaseType and Case should have the same size" - ); - } - - template< size_t N, typename CaseType > - Specification(const test_setup_handler_t setup_handler, - const CaseType (&cases)[N], - const test_teardown_handler_t teardown_handler, - const test_failure_handler_t failure_handler, - const handlers_t defaults = default_handlers) : - setup_handler(setup_handler), teardown_handler(teardown_handler), failure_handler(failure_handler), - cases(static_cast(static_cast(cases))), length(N), - defaults(defaults) - { - MBED_STATIC_ASSERT( - sizeof(CaseType) == sizeof(Case), - "CaseType and Case should have the same size" - ); - } - - Specification(const test_setup_handler_t setup_handler, - const Case *cases, - const size_t length, - const test_teardown_handler_t teardown_handler, - const test_failure_handler_t failure_handler, - const handlers_t defaults = default_handlers) : - setup_handler(setup_handler), teardown_handler(teardown_handler), failure_handler(failure_handler), - cases(cases), length(length), - defaults(defaults) - { - } - - private: - const test_setup_handler_t setup_handler; - const test_teardown_handler_t teardown_handler; - const test_failure_handler_t failure_handler; - const Case *const cases; - const size_t length; - const handlers_t defaults; - - friend class Harness; - }; - -} // namespace v1 -} // namespace utest - - #endif // UTEST_SPECIFICATION_H - -/** @}*/ diff --git a/features/frameworks/utest/utest/utest_types.h b/features/frameworks/utest/utest/utest_types.h deleted file mode 100644 index 9e4a1e6f91f..00000000000 --- a/features/frameworks/utest/utest/utest_types.h +++ /dev/null @@ -1,412 +0,0 @@ -/**************************************************************************** - * Copyright (c) 2015, ARM Limited, All Rights Reserved - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - **************************************************************************** - */ - -#ifndef UTEST_TYPES_H -#define UTEST_TYPES_H - -#include -#include -#include -#include "utest/utest_shim.h" -#include "SingletonPtr.h" - -namespace utest { -/** \addtogroup frameworks */ -/** @{*/ -namespace v1 { - - /// repeat_t - enum repeat_t { - REPEAT_UNDECLR = 0, - REPEAT_NONE = 1, ///< continue with the next test case - - REPEAT_ON_TIMEOUT = 2, - REPEAT_ON_VALIDATE = 4, - REPEAT_CASE_ONLY = 8, - REPEAT_SETUP_TEARDOWN = 16, - - REPEAT_MASK = REPEAT_ON_TIMEOUT | REPEAT_ON_VALIDATE | REPEAT_CASE_ONLY | REPEAT_SETUP_TEARDOWN, - - REPEAT_ALL_ON_TIMEOUT = REPEAT_SETUP_TEARDOWN | REPEAT_ON_TIMEOUT, ///< repeat the handler with setup and teardown on timeout - REPEAT_HANDLER_ON_TIMEOUT = REPEAT_CASE_ONLY | REPEAT_ON_TIMEOUT, ///< repeat only the handler on timeout - REPEAT_ALL = REPEAT_SETUP_TEARDOWN | REPEAT_ON_VALIDATE, ///< repeat the handler with setup and teardown - REPEAT_HANDLER = REPEAT_CASE_ONLY | REPEAT_ON_VALIDATE ///< repeat only the handler - }; - - /// status_t - enum status_t { - STATUS_CONTINUE = -1, ///< continues testing - STATUS_IGNORE = -2, ///< ignores failure and continues testing - STATUS_ABORT = -3 ///< stops testing - }; - - /// failure_reason_t - enum failure_reason_t { - REASON_NONE = 0, ///< No failure occurred - - REASON_UNKNOWN = (1 << 0), ///< An unknown failure occurred - REASON_CASES = (1 << 1), ///< A failure occurred in at least one test case - REASON_EMPTY_CASE = (1 << 2), ///< The test case contains only empty handlers - REASON_TIMEOUT = (1 << 3), ///< An expected asynchronous call timed out - REASON_ASSERTION = (1 << 4), ///< An assertion failed - - REASON_TEST_SETUP = (1 << 5), ///< Test setup failed - REASON_TEST_TEARDOWN = (1 << 6), ///< Test teardown failed - REASON_CASE_SETUP = (1 << 7), ///< Case setup failed - REASON_CASE_HANDLER = (1 << 8), ///< Case handler failed - REASON_CASE_TEARDOWN = (1 << 9), ///< Case teardown failed - - REASON_CASE_INDEX = (1 << 10), ///< Case index out-of-range - REASON_SCHEDULER = (1 << 11), ///< Asynchronous callback scheduling failed - - REASON_IGNORE = 0x8000 ///< The failure may be ignored - }; - - /// location_t - enum location_t { - LOCATION_NONE = 0, ///< No location information - LOCATION_TEST_SETUP, ///< A failure occurred in the test setup - LOCATION_TEST_TEARDOWN, ///< A failure occurred in the test teardown - LOCATION_CASE_SETUP, ///< A failure occurred in the case setup - LOCATION_CASE_HANDLER, ///< A failure occurred in the case handler - LOCATION_CASE_TEARDOWN, ///< A failure occurred in the case teardown - LOCATION_UNKNOWN ///< A failure occurred in an unknown location - }; - - /// Contains the reason and location of the failure. - struct failure_t { - failure_t() : reason(REASON_NONE), location(LOCATION_NONE) {} - failure_t(failure_reason_t reason) : reason(reason), location(LOCATION_NONE) {} - failure_t(location_t location) : reason(REASON_NONE), location(location) {} - failure_t(failure_reason_t reason, location_t location) : reason(reason), location(location) {} - - /// Copy constructor - failure_t(const failure_t &obj){ - reason = obj.reason; - location = obj.location; - } - - /// @returns a copy of the failure with the reason ignored. - failure_t ignored() const { - return failure_t(failure_reason_t(reason | REASON_IGNORE), location); - } - - failure_reason_t reason; - location_t location; - }; - - - enum { - TIMEOUT_NONE = uint32_t(-1), ///< Do not use a timeout - TIMEOUT_UNDECLR = uint32_t(-2), ///< Timeout not explicitly specified, defaults to NONE - TIMEOUT_FOREVER = uint32_t(-3) ///< Never time out - }; - - /// Stringifies a failure reason for understandable error messages. - const char* stringify(failure_reason_t reason); - /// Stringifies a failure for understandable error messages. - const char* stringify(failure_t failure); - /// Stringifies a location. - const char* stringify(location_t location); - /// Stringifies a status. - const char* stringify(utest::v1::status_t status); - - /** POD version of the class control_t. - * It is used to instantiate const control_t objects as PODs - * and prevent them to be included in the final binary. - * @note: control_pod_t can be converted to control_t by copy construction. - */ - struct base_control_t { - repeat_t repeat; - uint32_t timeout; - - repeat_t inline get_repeat() const { - return repeat; - } - uint32_t inline get_timeout() const { - return timeout; - } - }; - - /** Control class for specifying test case attributes - * - * This class encapsulated control information about test cases which, when returned from - * a test case influences the behavior of the test harness. - * Instead of using this class directly it is recommended to use the aliases for clearer - * semantics: - * @code - * control_t test_case(const size_t call_count) { - * // repeat 5 times for a total of 6 calls - * return (call_count < 6) ? CaseRepeatHandler : CaseNext; - * } - * @endcode - * - * This class overloads the `+` operator to implement something similiar to saturated arbitration: - * - The lower timeout value "wins". - * - A more involved repeat "wins" (ie. `ALL` > 'HANDLER' > 'NONE'). - * - Next Case always wins. - * - * You may then add timeouts and repeats together: - * @code - * control_t test_case(const size_t call_count) { - * // repeat 5 times for a total of 6 calls, each with a 500ms asynchronous timeout - * return CaseTimeout(500) + ((call_count < 6) ? CaseRepeatAll : CaseNoRepeat); - * } - * @endcode - * - * In the future, more control information may be added transparently and backwards compatible. - */ - struct control_t : private base_control_t - { - control_t() : base_control_t(make_base_control_t(REPEAT_UNDECLR, TIMEOUT_UNDECLR)) {} - - control_t(repeat_t repeat, uint32_t timeout_ms) : - base_control_t(make_base_control_t(repeat, timeout_ms)) {} - - control_t(repeat_t repeat) : - base_control_t(make_base_control_t(repeat, TIMEOUT_UNDECLR)) {} - - control_t(uint32_t timeout_ms) : - base_control_t(make_base_control_t(REPEAT_UNDECLR, timeout_ms)) {} - - control_t(const base_control_t& other) : - base_control_t(other) {} - - friend control_t operator+(const control_t& lhs, const control_t& rhs) { - control_t result( - repeat_t(lhs.repeat | rhs.repeat), - (rhs.timeout == TIMEOUT_NONE) ? rhs.timeout : lhs.timeout); - - if (result.timeout != TIMEOUT_NONE && result.timeout > rhs.timeout) { - result.timeout = rhs.timeout; - } - - if (result.repeat & REPEAT_NONE) { - result.repeat = REPEAT_NONE; - } - else { - if (result.repeat & REPEAT_SETUP_TEARDOWN) { - result.repeat = repeat_t(result.repeat & ~REPEAT_CASE_ONLY); - } - if (result.timeout == TIMEOUT_NONE && result.repeat & REPEAT_ON_TIMEOUT) { - result.repeat = repeat_t(result.repeat & ~REPEAT_ON_TIMEOUT); - } - } - - return result; - } - - repeat_t - inline get_repeat() const { - return repeat; - } - uint32_t - inline get_timeout() const { - return timeout; - } - - private: - static base_control_t make_base_control_t(repeat_t repeat, uint32_t timeout) { - base_control_t result = { - repeat, - timeout - }; - return result; - } - - friend class Harness; - }; - - /// @see operator+ in control_t - inline control_t operator+(const base_control_t& lhs, const base_control_t& rhs) { - return control_t(lhs) + control_t(rhs); - } - - /// @see operator+ in control_t - inline control_t operator+(const base_control_t& lhs, const control_t& rhs) { - return control_t(lhs) + rhs; - } - - /// @see operator+ in control_t - inline control_t operator+(const control_t& lhs, const base_control_t& rhs) { - return lhs + control_t(rhs); - } - - /// does not repeat this test case and immediately moves on to the next one without timeout - extern const base_control_t CaseNext; - - /// does not repeat this test case, moves on to the next one - extern const base_control_t CaseNoRepeat; - /// repeats the test case handler with calling teardown and setup handlers - extern const base_control_t CaseRepeatAll; - /// repeats only the test case handler without calling teardown and setup handlers - extern const base_control_t CaseRepeatHandler; - - /// No timeout, immediately moves on to the next case, but allows repeats - extern const base_control_t CaseNoTimeout; - /// Awaits until the callback is validated and never times out. Use with caution! - extern const base_control_t CaseAwait; - /// Alias class for asynchronous timeout control in milliseconds - inline control_t CaseTimeout(uint32_t ms) { return ms; } - - /// Alias class for asynchronous timeout control in milliseconds and - /// repeats the test case handler with calling teardown and setup handlers - inline control_t CaseRepeatAllOnTimeout(uint32_t ms) { return control_t(REPEAT_ALL_ON_TIMEOUT, ms); } - /// Alias class for asynchronous timeout control in milliseconds and - /// repeats only the test case handler without calling teardown and setup handlers - inline control_t CaseRepeatHandlerOnTimeout(uint32_t ms) { return control_t(REPEAT_HANDLER_ON_TIMEOUT, ms); } - - class Case; // forward declaration - - /** Test setup handler. - * - * This handler is called before execution of any test case and - * allows you to initialize your common test environment. - * - * @param number_of_cases the total number of test cases in the test specification - * - * @returns - * You can return `STATUS_ABORT` if you initialization failed and the test teardown handler will - * then be called with the `REASON_SETUP`. - */ - typedef utest::v1::status_t (*test_setup_handler_t)(const size_t number_of_cases); - - /** Test teardown handler. - * - * This handler is called after execution of all test case or if test execution is aborted. - * You can use this handler to de-initialize your test environment and output test statistics. - * The failure argument contains the immediate reason why this handler is called. - * If the test completed normally without failures, this will contain `REASON_NONE`. - * - * After execution of this handler, the test harness will stop execution. - * - * @param passed the number of cases without failures - * @param failed the number of cases with at least one failure - * @param failure the reason why this handler was called - */ - typedef void (*test_teardown_handler_t)(const size_t passed, const size_t failed, const failure_t failure); - - /** Test failure handler. - * - * This handler is called anytime a failure occurs during the execution of a test speficication. - * The handler only allows logging of failures and cannot influence test execution. - * - * @param failure the reason why this handler was called - */ - typedef void (*test_failure_handler_t)(const failure_t reason); - - /** Test case setup handler. - * - * This handler is called before execution of each test case and - * allows you to modify your environment before each test case. - * - * @param source the test case to be setup - * @param index_of_case the current index of the test case within the specification - * - * @returns - * You can return `STATUS_ABORT` to indicate that your setup failed, which will call the case - * failure handler with `REASON_SETUP` and then the case teardown handler with `REASON_SETUP`. - * This gives the teardown handler a chance to clean up a failed setup. - */ - typedef utest::v1::status_t (*case_setup_handler_t)(const Case *const source, const size_t index_of_case); - - /** Primitive test case handler - * - * This handler is called only if the case setup succeeded and is followed by the test case teardown handler. - * - * @note This handler is executed only once. - */ - typedef void (*case_handler_t)(void); - - /** Complex test case handler - * - * This handler is called only if the case setup succeeded and then may be repeated or - * awaiting a asynchronous callback, depending on the return modifiers. - * - * @returns - * A combination of control modifiers. - */ - typedef control_t (*case_control_handler_t)(void); - - /** Test case handler (repeatable) - * - * This handler is called only if the case setup succeeded and then may be repeated or - * awaiting a asynchronous callback, depending on the return modifiers. - * - * @param call_count starting at `1`, contains the number of times this handler has been called - * - * @returns - * A combination of control modifiers. - */ - typedef control_t (*case_call_count_handler_t)(const size_t call_count); - - /** Test case teardown handler. - * - * This handler is called after execution of each test case or all repeated test cases and - * allows you to reset your environment after each test case. - * - * @param source the test case to be torn down - * @param passed the number of cases without failures (can be >1 for repeated test cases) - * @param failed the number failures (can be larger than the number of (repeated) test cases) - * @param failure the reason why this handler was called - * - * @returns - * You can return `STATUS_ABORT` to indicate that your teardown failed, which will call the case - * failure handler with `REASON_TEARDOWN`. - */ - typedef utest::v1::status_t (*case_teardown_handler_t)(const Case *const source, const size_t passed, const size_t failed, const failure_t reason); - - /** Test case failure handler. - * - * This handler is called whenever a failure occurred during the setup, execution or teardown. - * - * @param source the test case in which the failure occurred - * @param reason the reason why this handler was called - * - * @returns - * You can return `STATUS_ABORT` to indicate that this failure is non-recoverable, which will call the case - * teardown handler with reason. If a failure occurs during teardown, the teardown will not be called again. - * You may return `STATUS_IGNORE` which will cause the harness to ignore and not count the failure. - */ - typedef utest::v1::status_t (*case_failure_handler_t)(const Case *const source, const failure_t reason); - - - // deprecations - __deprecated_message("Use CaseRepeatAll instead.") - extern const base_control_t CaseRepeat; - - __deprecated_message("Use CaseRepeatHandler instead.") - extern const base_control_t CaseRepeatHandlerOnly; - - __deprecated_message("Use REASON_NONE instead.") const failure_reason_t FAILURE_NONE = REASON_NONE; - __deprecated_message("Use REASON_UNKNOWN instead.") const failure_reason_t FAILURE_UNKNOWN = REASON_UNKNOWN; - __deprecated_message("Use REASON_CASES instead.") const failure_reason_t FAILURE_CASES = REASON_CASES; - __deprecated_message("Use REASON_EMPTY_CASE instead.") const failure_reason_t FAILURE_EMPTY_CASE = REASON_EMPTY_CASE; - __deprecated_message("Use REASON_TIMEOUT instead.") const failure_reason_t FAILURE_TIMEOUT = REASON_TIMEOUT; - __deprecated_message("Use REASON_ASSERTION instead.") const failure_reason_t FAILURE_ASSERTION = REASON_ASSERTION; - __deprecated_message("Use REASON_CASE_SETUP instead.") const failure_reason_t FAILURE_SETUP = REASON_CASE_SETUP; - __deprecated_message("Use REASON_CASE_TEARDOWN instead.") const failure_reason_t FAILURE_TEARDOWN = REASON_CASE_TEARDOWN; - __deprecated_message("Use REASON_IGNORE instead.") const failure_reason_t FAILURE_IGNORE = REASON_IGNORE; - - -} // namespace v1 -} // namespace utest - -#endif // UTEST_TYPES_H - -/** @}*/