mirror of https://github.com/ARMmbed/mbed-os.git
Code review rework:
Updated include files within tests to use subdirectory/header.h Updated global variables within tests to be static Fixed indentation issue. Renamed Timeout class variables to be more meaningful Moved definition of utest_trace into stack_trace.cpp Removed unecessary call to .clear() method in utest_add_to_trace() Changed UTEST_LOG_FUNCTION macro to UTEST_LOG_FUNCTION();
parent
4cd34b1235
commit
710421d3e8
|
@ -17,14 +17,14 @@
|
|||
* unit test.
|
||||
*
|
||||
*/
|
||||
#include "mbed-drivers/mbed.h"
|
||||
#include "mbed.h"
|
||||
#include "greentea-client/test_env.h"
|
||||
#include "utest/utest.h"
|
||||
#include "unity/unity.h"
|
||||
#include "utest.h"
|
||||
#include "unity.h"
|
||||
|
||||
using namespace utest::v1;
|
||||
|
||||
Timeout to;
|
||||
static Timeout utest_to;
|
||||
|
||||
void test_simple() {
|
||||
TEST_ASSERT_EQUAL(0, 0);
|
||||
|
@ -53,7 +53,7 @@ void test_callback_validate() {
|
|||
control_t test_asynchronous() {
|
||||
TEST_ASSERT_TRUE_MESSAGE(true, "(true == false) o_O");
|
||||
// Set up a callback in the future. This may also be an interrupt!
|
||||
to.attach_us(test_callback_validate, (100*1000)); // Fire after 100 ms
|
||||
utest_to.attach_us(test_callback_validate, (100*1000)); // Fire after 100 ms
|
||||
|
||||
// Set a 200ms timeout starting from now
|
||||
return CaseTimeout(200);
|
||||
|
@ -65,7 +65,7 @@ control_t test_asynchronous_timeout(const size_t call_count) {
|
|||
// but automatically repeat only this handler on timeout.
|
||||
if (call_count >= 5) {
|
||||
// but after the 5th call, the callback finally gets validated
|
||||
to.attach_us(test_callback_validate, (100*1000)); // Fire after 100 ms
|
||||
utest_to.attach_us(test_callback_validate, (100*1000)); // Fire after 100 ms
|
||||
}
|
||||
return CaseRepeatHandlerOnTimeout(200);
|
||||
}
|
|
@ -1,22 +1,26 @@
|
|||
#include "test_env.h"
|
||||
#include "mbed.h"
|
||||
#include "utest.h"
|
||||
#include "unity.h"
|
||||
#include "mbed-drivers/mbed.h"
|
||||
#include "greentea-client/test_env.h"
|
||||
#include "utest/utest.h"
|
||||
#include "unity/unity.h"
|
||||
#include "stack_trace.h"
|
||||
|
||||
using namespace utest::v1;
|
||||
|
||||
void test_simple() {
|
||||
UTEST_LOG_FUNCTION();
|
||||
TEST_ASSERT_EQUAL(0, 0);
|
||||
printf("Simple test called\n");
|
||||
}
|
||||
|
||||
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
|
||||
status_t status = greentea_case_setup_handler(source, index_of_case);
|
||||
printf("Setting up for '%s'\n", source->get_description());
|
||||
return status;
|
||||
}
|
||||
control_t test_repeats(const size_t call_count) {
|
||||
UTEST_LOG_FUNCTION();
|
||||
printf("Called for the %u. time\n", call_count);
|
||||
TEST_ASSERT_NOT_EQUAL(3, call_count);
|
||||
// Specify how often this test is repeated ie. n total calls
|
||||
|
@ -25,6 +29,7 @@ control_t test_repeats(const size_t call_count) {
|
|||
|
||||
// Custom setup handler required for proper Greentea support
|
||||
status_t greentea_setup(const size_t number_of_cases) {
|
||||
UTEST_LOG_FUNCTION();
|
||||
GREENTEA_SETUP(20, "default_auto");
|
||||
// Call the default reporting function
|
||||
return greentea_test_setup_handler(number_of_cases);
|
||||
|
@ -43,8 +48,7 @@ extern void utest_run(const Specification& specification);
|
|||
|
||||
int main()
|
||||
{
|
||||
// You MUST set the custom scheduler before running the specification.
|
||||
Harness::set_scheduler(utest_v1_get_scheduler());
|
||||
UTEST_LOG_FUNCTION();
|
||||
// Run the specification only AFTER setting the custom scheduler.
|
||||
Harness::run(specification);
|
||||
}
|
||||
|
|
|
@ -14,19 +14,18 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "test_env.h"
|
||||
#include "mbed.h"
|
||||
#include "utest.h"
|
||||
#include "unity.h"
|
||||
#include "mbed-drivers/mbed.h"
|
||||
#include "greentea-client/test_env.h"
|
||||
#include "utest/utest.h"
|
||||
#include "unity/unity.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
using namespace utest::v1;
|
||||
|
||||
int call_counter(0);
|
||||
static int call_counter(0);
|
||||
|
||||
Timeout to1;
|
||||
Timeout to;
|
||||
static Timeout utest_to;
|
||||
|
||||
// Validate: Simple Validation ----------------------------------------------------------------------------------------
|
||||
void simple_validation()
|
||||
|
@ -40,7 +39,7 @@ control_t simple_validation_case()
|
|||
{
|
||||
printf("Simple validation, posting callback\n");
|
||||
TEST_ASSERT_EQUAL(0, call_counter++);
|
||||
to.attach_us(simple_validation, 100); // Fire after 100 us
|
||||
utest_to.attach_us(simple_validation, 100); // Fire after 100 us
|
||||
|
||||
return CaseAwait;
|
||||
}
|
||||
|
@ -69,7 +68,7 @@ control_t multiple_validation_case()
|
|||
{
|
||||
TEST_ASSERT_EQUAL(2, call_counter++);
|
||||
printf("Multiple validation callback posted.\n");
|
||||
to1.attach_us(multiple_validation, 100000); // Fire after 100 ms
|
||||
utest_to.attach_us(multiple_validation, 100000); // Fire after 100 ms
|
||||
return CaseAwait;
|
||||
}
|
||||
|
||||
|
@ -146,7 +145,7 @@ control_t attributed_validation_cancel_repeat_case()
|
|||
TEST_ASSERT_EQUAL(18, call_counter++);
|
||||
printf("Validation cancel repeat callback posted.\n");
|
||||
|
||||
to1.attach_us(attributed_validation_cancel_repeat, 100000); // Fire after 100 ms
|
||||
utest_to.attach_us(attributed_validation_cancel_repeat, 100000); // Fire after 100 ms
|
||||
// the RepeatAll will be cancelled during callback validation
|
||||
return CaseRepeatAll + CaseAwait;
|
||||
}
|
||||
|
@ -178,8 +177,8 @@ control_t attributed_validation_enable_repeat_case(const size_t call_count)
|
|||
{
|
||||
if (call_count == 1) {
|
||||
TEST_ASSERT_EQUAL(21, call_counter++);
|
||||
printf("Validation enable repeat callback posted.\n");
|
||||
to1.attach_us(attributed_validation_enable_repeat, 100000); // Fire after 100 ms
|
||||
printf("Validation enable repeat callback posted.\n");
|
||||
utest_to.attach_us(attributed_validation_enable_repeat, 100000); // Fire after 100 ms
|
||||
// the RepeatAll will be cancelled during callback validation
|
||||
return CaseAwait;
|
||||
}
|
||||
|
|
|
@ -14,20 +14,17 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "mbed.h"
|
||||
#include "test_env.h"
|
||||
#include "utest.h"
|
||||
#include "unity.h"
|
||||
#include "stack_trace.h"
|
||||
#include "mbed-drivers/mbed.h"
|
||||
#include "greentea-client/test_env.h"
|
||||
#include "utest/utest.h"
|
||||
#include "unity/unity.h"
|
||||
#include "utest/stack_trace.h"
|
||||
|
||||
using namespace utest::v1;
|
||||
|
||||
#ifdef UTEST_STACK_TRACE
|
||||
std::string utest_trace[UTEST_MAX_BACKTRACE];
|
||||
#endif // UTEST_STACK_TRACE
|
||||
|
||||
int call_counter(0);
|
||||
Timeout to;
|
||||
static int call_counter(0);
|
||||
static Timeout utest_to;
|
||||
|
||||
class Utest_func_bind {
|
||||
|
||||
|
@ -48,29 +45,29 @@ private:
|
|||
|
||||
void await_case_validate(int expected_call_count)
|
||||
{
|
||||
UTEST_LOG_FUNCTION
|
||||
UTEST_LOG_FUNCTION();
|
||||
printf("await_case_validate called with expected call count of %d\n", expected_call_count);
|
||||
TEST_ASSERT_EQUAL(expected_call_count, call_counter++);
|
||||
Harness::validate_callback();
|
||||
}
|
||||
|
||||
Utest_func_bind validate1(await_case_validate, 7);
|
||||
Utest_func_bind validate2(await_case_validate, 37);
|
||||
Utest_func_bind validate3(await_case_validate, 50);
|
||||
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)
|
||||
{
|
||||
UTEST_LOG_FUNCTION
|
||||
UTEST_LOG_FUNCTION();
|
||||
TEST_ASSERT_EQUAL(1, call_count);
|
||||
TEST_ASSERT_EQUAL(0, call_counter++);
|
||||
return CaseTimeout(100);
|
||||
}
|
||||
status_t timeout_failure_case_failure_handler(const Case *const source, const failure_t failure)
|
||||
{
|
||||
UTEST_LOG_FUNCTION
|
||||
UTEST_LOG_FUNCTION();
|
||||
TEST_ASSERT_EQUAL(1, call_counter++);
|
||||
TEST_ASSERT_EQUAL(REASON_TIMEOUT, failure.reason);
|
||||
TEST_ASSERT_EQUAL(LOCATION_CASE_HANDLER, failure.location);
|
||||
|
@ -79,7 +76,7 @@ status_t timeout_failure_case_failure_handler(const Case *const source, const fa
|
|||
}
|
||||
status_t timeout_failure_case_teardown(const Case *const source, const size_t passed, const size_t failed, const failure_t failure)
|
||||
{
|
||||
UTEST_LOG_FUNCTION
|
||||
UTEST_LOG_FUNCTION();
|
||||
TEST_ASSERT_EQUAL(2, call_counter++);
|
||||
TEST_ASSERT_EQUAL(0, passed);
|
||||
TEST_ASSERT_EQUAL(1, failed);
|
||||
|
@ -90,23 +87,23 @@ status_t timeout_failure_case_teardown(const Case *const source, const size_t pa
|
|||
|
||||
// Control: Timeout (Success) -----------------------------------------------------------------------------------------
|
||||
void timeout_success_case_validate() {
|
||||
UTEST_LOG_FUNCTION
|
||||
UTEST_LOG_FUNCTION();
|
||||
TEST_ASSERT_EQUAL(4, call_counter++);
|
||||
Harness::validate_callback();
|
||||
}
|
||||
|
||||
control_t timeout_success_case(const size_t call_count)
|
||||
{
|
||||
UTEST_LOG_FUNCTION
|
||||
UTEST_LOG_FUNCTION();
|
||||
TEST_ASSERT_EQUAL(1, call_count);
|
||||
TEST_ASSERT_EQUAL(3, call_counter++);
|
||||
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);
|
||||
}
|
||||
status_t timeout_success_case_failure_handler(const Case *const source, const size_t passed, const size_t failed, const failure_t failure)
|
||||
{
|
||||
UTEST_LOG_FUNCTION
|
||||
UTEST_LOG_FUNCTION();
|
||||
TEST_ASSERT_EQUAL(5, call_counter++);
|
||||
TEST_ASSERT_EQUAL(1, passed);
|
||||
TEST_ASSERT_EQUAL(0, failed);
|
||||
|
@ -118,11 +115,11 @@ status_t timeout_success_case_failure_handler(const Case *const source, const si
|
|||
// Control: Await -----------------------------------------------------------------------------------------------------
|
||||
control_t await_case(const size_t call_count)
|
||||
{
|
||||
UTEST_LOG_FUNCTION
|
||||
UTEST_LOG_FUNCTION();
|
||||
TEST_ASSERT_EQUAL(1, call_count);
|
||||
TEST_ASSERT_EQUAL(6, call_counter++);
|
||||
|
||||
to.attach_us(&validate1, &Utest_func_bind::callback, (1372*1000)); // Fire after 1372 ms
|
||||
utest_to.attach_us(&validate1, &Utest_func_bind::callback, (1372*1000)); // Fire after 1372 ms
|
||||
|
||||
return CaseAwait;
|
||||
}
|
||||
|
@ -135,7 +132,7 @@ status_t repeat_all_on_timeout_case_setup(const Case *const source, const size_t
|
|||
UTEST_TRACE_START
|
||||
repeat_all_start_flag = false;
|
||||
}
|
||||
UTEST_LOG_FUNCTION
|
||||
UTEST_LOG_FUNCTION();
|
||||
static int repeat_counter(0);
|
||||
TEST_ASSERT_EQUAL(3, index_of_case);
|
||||
TEST_ASSERT_EQUAL(repeat_counter*3 + 8, call_counter++);
|
||||
|
@ -144,7 +141,7 @@ status_t repeat_all_on_timeout_case_setup(const Case *const source, const size_t
|
|||
}
|
||||
control_t repeat_all_on_timeout_case(const size_t call_count)
|
||||
{
|
||||
UTEST_LOG_FUNCTION
|
||||
UTEST_LOG_FUNCTION();
|
||||
printf("Running case handler for %u. time\n", call_count);
|
||||
static int repeat_counter(1);
|
||||
TEST_ASSERT_EQUAL(repeat_counter++, call_count);
|
||||
|
@ -152,13 +149,13 @@ control_t repeat_all_on_timeout_case(const size_t call_count)
|
|||
TEST_ASSERT_EQUAL((call_count-1)*3 + 9, call_counter++);
|
||||
if (call_count == 10) {
|
||||
printf("Scheduling await_case_validate with value 37");
|
||||
to.attach_us(&validate2, &Utest_func_bind::callback, (50*1000)); // Fire after 50ms
|
||||
utest_to.attach_us(&validate2, &Utest_func_bind::callback, (50*1000)); // Fire after 50ms
|
||||
}
|
||||
return CaseRepeatAllOnTimeout(100);
|
||||
}
|
||||
status_t repeat_all_on_timeout_case_teardown(const Case *const source, const size_t passed, const size_t failed, const failure_t failure)
|
||||
{
|
||||
UTEST_LOG_FUNCTION
|
||||
UTEST_LOG_FUNCTION();
|
||||
static int repeat_counter(0);
|
||||
printf("Call counter = %d, passed =%u, failed = %u\n", call_counter, passed, failed);
|
||||
|
||||
|
@ -174,7 +171,7 @@ status_t repeat_all_on_timeout_case_teardown(const Case *const source, const siz
|
|||
// Control: RepeatAllOnTimeout ----------------------------------------------------------------------------------------
|
||||
status_t repeat_handler_on_timeout_case_setup(const Case *const source, const size_t index_of_case)
|
||||
{
|
||||
UTEST_LOG_FUNCTION
|
||||
UTEST_LOG_FUNCTION();
|
||||
TEST_ASSERT_EQUAL(4, index_of_case);
|
||||
TEST_ASSERT_EQUAL(39, call_counter++);
|
||||
return greentea_case_setup_handler(source, index_of_case);
|
||||
|
@ -182,7 +179,7 @@ status_t repeat_handler_on_timeout_case_setup(const Case *const source, const si
|
|||
|
||||
control_t repeat_handler_on_timeout_case(const size_t call_count)
|
||||
{
|
||||
UTEST_LOG_FUNCTION
|
||||
UTEST_LOG_FUNCTION();
|
||||
printf("Running case handler for %u. time\n", call_count);
|
||||
static int repeat_counter(1);
|
||||
TEST_ASSERT_EQUAL(repeat_counter++, call_count);
|
||||
|
@ -190,13 +187,13 @@ control_t repeat_handler_on_timeout_case(const size_t call_count)
|
|||
TEST_ASSERT_EQUAL(call_count-1 + 40, call_counter++);
|
||||
if (call_count == 10) {
|
||||
printf("Scheduling await_case_validate with value 50");
|
||||
to.attach_us(&validate3, &Utest_func_bind::callback, (50*1000)); // Fire after 50ms
|
||||
utest_to.attach_us(&validate3, &Utest_func_bind::callback, (50*1000)); // Fire after 50ms
|
||||
}
|
||||
return CaseRepeatHandlerOnTimeout(100);
|
||||
}
|
||||
status_t repeat_handler_on_timeout_case_teardown(const Case *const source, const size_t passed, const size_t failed, const failure_t failure)
|
||||
{
|
||||
UTEST_LOG_FUNCTION
|
||||
UTEST_LOG_FUNCTION();
|
||||
TEST_ASSERT_EQUAL(1, passed);
|
||||
TEST_ASSERT_EQUAL(0, failed);
|
||||
TEST_ASSERT_EQUAL(REASON_NONE, failure.reason);
|
||||
|
@ -208,7 +205,7 @@ status_t repeat_handler_on_timeout_case_teardown(const Case *const source, const
|
|||
// Control: NoTimeout -------------------------------------------------------------------------------------------------
|
||||
control_t no_timeout_case(const size_t call_count)
|
||||
{
|
||||
UTEST_LOG_FUNCTION
|
||||
UTEST_LOG_FUNCTION();
|
||||
TEST_ASSERT_EQUAL(1, call_count);
|
||||
TEST_ASSERT_EQUAL(52, call_counter++);
|
||||
return CaseNoTimeout;
|
||||
|
@ -217,7 +214,7 @@ control_t no_timeout_case(const size_t call_count)
|
|||
// Control: NoTimeout -------------------------------------------------------------------------------------------------
|
||||
control_t next_case(const size_t call_count)
|
||||
{
|
||||
UTEST_LOG_FUNCTION
|
||||
UTEST_LOG_FUNCTION();
|
||||
TEST_ASSERT_EQUAL(1, call_count);
|
||||
TEST_ASSERT_EQUAL(53, call_counter++);
|
||||
return CaseNoTimeout;
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
|
||||
using namespace utest::v1;
|
||||
|
||||
int call_counter(0);
|
||||
static int call_counter(0);
|
||||
|
||||
// Control: RepeatAll -------------------------------------------------------------------------------------------------
|
||||
status_t repeat_all_case_setup(const Case *const source, const size_t index_of_case)
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
using namespace utest::v1;
|
||||
|
||||
int call_counter(0);
|
||||
static int call_counter(0);
|
||||
|
||||
void handler_case_2()
|
||||
{
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
|
||||
using namespace utest::v1;
|
||||
|
||||
int call_counter(0);
|
||||
static int call_counter(0);
|
||||
|
||||
void never_call_case()
|
||||
{
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
|
||||
using namespace utest::v1;
|
||||
|
||||
int call_counter(0);
|
||||
static int call_counter(0);
|
||||
|
||||
// Continue Teardown Handler ------------------------------------------------------------------------------------------
|
||||
void continue_case()
|
||||
|
|
|
@ -22,40 +22,36 @@
|
|||
#include "greentea-client/test_env.h"
|
||||
#include "utest/utest.h"
|
||||
#include "unity/unity.h"
|
||||
#include "stack_trace.h"
|
||||
#include "utest/stack_trace.h"
|
||||
|
||||
#include "ticker_api.h"
|
||||
#include "us_ticker_api.h"
|
||||
|
||||
using namespace utest::v1;
|
||||
|
||||
#ifdef UTEST_STACK_TRACE
|
||||
std::string utest_trace[UTEST_MAX_BACKTRACE];
|
||||
#endif // UTEST_STACK_TRACE
|
||||
|
||||
// only one callback is active at any given time
|
||||
volatile utest_v1_harness_callback_t minimal_callback;
|
||||
volatile utest_v1_harness_callback_t ticker_callback;
|
||||
Timeout utest_minimal_object;
|
||||
static Timeout utest_minimal_object;
|
||||
|
||||
// Scheduler ----------------------------------------------------------------------------------------------------------
|
||||
static void ticker_handler()
|
||||
{
|
||||
UTEST_LOG_FUNCTION
|
||||
UTEST_LOG_FUNCTION();
|
||||
// printf("\t\t>>> Ticker callback fired for %p.\n", ticker_callback);
|
||||
minimal_callback = ticker_callback;
|
||||
}
|
||||
|
||||
static int32_t utest_minimal_init()
|
||||
{
|
||||
UTEST_LOG_FUNCTION
|
||||
UTEST_LOG_FUNCTION();
|
||||
minimal_callback = NULL;
|
||||
ticker_callback = NULL;
|
||||
return 0;
|
||||
}
|
||||
static void *utest_minimal_post(const utest_v1_harness_callback_t callback, timestamp_t delay_ms)
|
||||
{
|
||||
UTEST_LOG_FUNCTION
|
||||
UTEST_LOG_FUNCTION();
|
||||
// printf("\t\t>>> Schedule %p with %ums delay => %p.\n", callback, (unsigned int)delay_ms, (void*)1);
|
||||
timestamp_t delay_us = delay_ms *1000;
|
||||
|
||||
|
@ -72,7 +68,7 @@ static void *utest_minimal_post(const utest_v1_harness_callback_t callback, tim
|
|||
}
|
||||
static int32_t utest_minimal_cancel(void *handle)
|
||||
{
|
||||
UTEST_LOG_FUNCTION
|
||||
UTEST_LOG_FUNCTION();
|
||||
printf("\t\t>>> Cancel %p => %u\n", handle, (unsigned int)0);
|
||||
(void) handle;
|
||||
utest_minimal_object.detach();
|
||||
|
@ -80,7 +76,7 @@ static int32_t utest_minimal_cancel(void *handle)
|
|||
}
|
||||
static int32_t utest_minimal_run()
|
||||
{
|
||||
UTEST_LOG_FUNCTION
|
||||
UTEST_LOG_FUNCTION();
|
||||
/* This is the amazing minimal scheduler.
|
||||
* This is just a busy loop that calls the callbacks in this context.
|
||||
* THIS LOOP IS BLOCKING.
|
||||
|
@ -115,7 +111,7 @@ int call_counter(0);
|
|||
// Basic Test Case ----------------------------------------------------------------------------------------------------
|
||||
control_t test_case()
|
||||
{
|
||||
UTEST_LOG_FUNCTION
|
||||
UTEST_LOG_FUNCTION();
|
||||
static int counter(0);
|
||||
TEST_ASSERT_EQUAL(counter++, call_counter++);
|
||||
printf("Running Test #%d\n", counter);
|
||||
|
@ -125,7 +121,7 @@ control_t test_case()
|
|||
// Async Test Case Failure --------------------------------------------------------------------------------------------
|
||||
control_t test_case_async()
|
||||
{
|
||||
UTEST_LOG_FUNCTION
|
||||
UTEST_LOG_FUNCTION();
|
||||
static int counter(3);
|
||||
TEST_ASSERT_EQUAL(counter++, call_counter++);
|
||||
printf("Running Test #%d\n", counter);
|
||||
|
@ -133,7 +129,7 @@ control_t test_case_async()
|
|||
}
|
||||
status_t test_case_async_failure(const Case *const source, const failure_t reason)
|
||||
{
|
||||
UTEST_LOG_FUNCTION
|
||||
UTEST_LOG_FUNCTION();
|
||||
// ignore the timeout, since this is a test
|
||||
return greentea_case_failure_continue_handler(source, reason.ignored());
|
||||
}
|
||||
|
@ -154,7 +150,7 @@ status_t greentea_setup(const size_t number_of_cases)
|
|||
}
|
||||
void greentea_teardown(const size_t passed, const size_t failed, const failure_t failure)
|
||||
{
|
||||
UTEST_LOG_FUNCTION
|
||||
UTEST_LOG_FUNCTION();
|
||||
TEST_ASSERT_EQUAL(4, call_counter++);
|
||||
TEST_ASSERT_EQUAL(4, passed);
|
||||
TEST_ASSERT_EQUAL(0, failed);
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
using namespace utest::v1;
|
||||
|
||||
bool failure_is_in_setup = false;
|
||||
static bool failure_is_in_setup = false;
|
||||
|
||||
void never_call_case()
|
||||
{
|
||||
|
|
|
@ -37,7 +37,7 @@ const handlers_t utest::v1::verbose_continue_handlers = {
|
|||
|
||||
// --- SPECIAL HANDLERS ---
|
||||
static void test_failure_handler(const failure_t failure) {
|
||||
UTEST_LOG_FUNCTION
|
||||
UTEST_LOG_FUNCTION();
|
||||
if (failure.location == LOCATION_TEST_SETUP || failure.location == LOCATION_TEST_TEARDOWN) {
|
||||
verbose_test_failure_handler(failure);
|
||||
printf("{{failure}}\n{{end}}\n");
|
||||
|
@ -48,14 +48,14 @@ static void test_failure_handler(const failure_t failure) {
|
|||
// --- VERBOSE TEST HANDLERS ---
|
||||
utest::v1::status_t utest::v1::verbose_test_setup_handler(const size_t number_of_cases)
|
||||
{
|
||||
UTEST_LOG_FUNCTION
|
||||
UTEST_LOG_FUNCTION();
|
||||
printf(">>> Running %u test cases...\n", number_of_cases);
|
||||
return STATUS_CONTINUE;
|
||||
}
|
||||
|
||||
void utest::v1::verbose_test_teardown_handler(const size_t passed, const size_t failed, const failure_t failure)
|
||||
{
|
||||
UTEST_LOG_FUNCTION
|
||||
UTEST_LOG_FUNCTION();
|
||||
printf("\n>>> Test cases: %u passed, %u failed", passed, failed);
|
||||
if (failure.reason == REASON_NONE) {
|
||||
printf("\n");
|
||||
|
@ -74,14 +74,14 @@ void utest::v1::verbose_test_failure_handler(const failure_t failure)
|
|||
// --- VERBOSE CASE HANDLERS ---
|
||||
utest::v1::status_t utest::v1::verbose_case_setup_handler(const Case *const source, const size_t index_of_case)
|
||||
{
|
||||
UTEST_LOG_FUNCTION
|
||||
UTEST_LOG_FUNCTION();
|
||||
printf("\n>>> Running case #%u: '%s'...\n", index_of_case + 1, source->get_description());
|
||||
return STATUS_CONTINUE;
|
||||
}
|
||||
|
||||
utest::v1::status_t utest::v1::verbose_case_teardown_handler(const Case *const source, const size_t passed, const size_t failed, const failure_t failure)
|
||||
{
|
||||
UTEST_LOG_FUNCTION
|
||||
UTEST_LOG_FUNCTION();
|
||||
printf(">>> '%s': %u passed, %u failed", source->get_description(), passed, failed);
|
||||
if (failure.reason == REASON_NONE) {
|
||||
printf("\n");
|
||||
|
@ -93,7 +93,7 @@ utest::v1::status_t utest::v1::verbose_case_teardown_handler(const Case *const s
|
|||
|
||||
utest::v1::status_t utest::v1::verbose_case_failure_handler(const Case *const /*source*/, const failure_t failure)
|
||||
{
|
||||
UTEST_LOG_FUNCTION
|
||||
UTEST_LOG_FUNCTION();
|
||||
if (!(failure.reason & REASON_ASSERTION)) {
|
||||
verbose_test_failure_handler(failure);
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ const handlers_t utest::v1::selftest_handlers = {
|
|||
|
||||
// --- SPECIAL HANDLERS ---
|
||||
static utest::v1::status_t unknown_test_setup_handler(const size_t) {
|
||||
UTEST_LOG_FUNCTION
|
||||
UTEST_LOG_FUNCTION();
|
||||
printf(">>> I do not know how to tell greentea that the test started, since\n");
|
||||
printf(">>> you forgot to override the `test_setup_handler` in your specification.\n");
|
||||
|
||||
|
@ -66,7 +66,7 @@ static utest::v1::status_t unknown_test_setup_handler(const size_t) {
|
|||
}
|
||||
|
||||
static void selftest_failure_handler(const failure_t failure) {
|
||||
UTEST_LOG_FUNCTION
|
||||
UTEST_LOG_FUNCTION();
|
||||
if (failure.location == LOCATION_TEST_SETUP || failure.location == LOCATION_TEST_TEARDOWN || failure.reason == REASON_ASSERTION) {
|
||||
verbose_test_failure_handler(failure);
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ static void selftest_failure_handler(const failure_t failure) {
|
|||
}
|
||||
|
||||
static void test_failure_handler(const failure_t failure) {
|
||||
UTEST_LOG_FUNCTION
|
||||
UTEST_LOG_FUNCTION();
|
||||
if (failure.location == LOCATION_TEST_SETUP || failure.location == LOCATION_TEST_TEARDOWN) {
|
||||
verbose_test_failure_handler(failure);
|
||||
GREENTEA_TESTSUITE_RESULT(false);
|
||||
|
@ -89,14 +89,14 @@ static void test_failure_handler(const failure_t failure) {
|
|||
// --- GREENTEA HANDLERS ---
|
||||
utest::v1::status_t utest::v1::greentea_test_setup_handler(const size_t number_of_cases)
|
||||
{
|
||||
UTEST_LOG_FUNCTION
|
||||
UTEST_LOG_FUNCTION();
|
||||
greentea_send_kv(TEST_ENV_TESTCASE_COUNT, number_of_cases);
|
||||
return verbose_test_setup_handler(number_of_cases);
|
||||
}
|
||||
|
||||
void utest::v1::greentea_test_teardown_handler(const size_t passed, const size_t failed, const failure_t failure)
|
||||
{
|
||||
UTEST_LOG_FUNCTION
|
||||
UTEST_LOG_FUNCTION();
|
||||
verbose_test_teardown_handler(passed, failed, failure);
|
||||
greentea_send_kv(TEST_ENV_TESTCASE_SUMMARY, passed, failed);
|
||||
int result = !(failed || (failure.reason && !(failure.reason & REASON_IGNORE)));
|
||||
|
@ -105,14 +105,14 @@ void utest::v1::greentea_test_teardown_handler(const size_t passed, const size_t
|
|||
|
||||
void utest::v1::greentea_test_failure_handler(const failure_t failure)
|
||||
{
|
||||
UTEST_LOG_FUNCTION
|
||||
UTEST_LOG_FUNCTION();
|
||||
verbose_test_failure_handler(failure);
|
||||
}
|
||||
|
||||
// --- GREENTEA CASE HANDLERS ---
|
||||
utest::v1::status_t utest::v1::greentea_case_setup_handler(const Case *const source, const size_t index_of_case)
|
||||
{
|
||||
UTEST_LOG_FUNCTION
|
||||
UTEST_LOG_FUNCTION();
|
||||
utest::v1::status_t status = verbose_case_setup_handler(source, index_of_case);
|
||||
greentea_send_kv(TEST_ENV_TESTCASE_START, source->get_description());
|
||||
return status;
|
||||
|
@ -120,20 +120,20 @@ utest::v1::status_t utest::v1::greentea_case_setup_handler(const Case *const sou
|
|||
|
||||
utest::v1::status_t utest::v1::greentea_case_teardown_handler(const Case *const source, const size_t passed, const size_t failed, const failure_t failure)
|
||||
{
|
||||
UTEST_LOG_FUNCTION
|
||||
UTEST_LOG_FUNCTION();
|
||||
greentea_send_kv(TEST_ENV_TESTCASE_FINISH, source->get_description(), passed, failed);
|
||||
return verbose_case_teardown_handler(source, passed, failed, failure);
|
||||
}
|
||||
|
||||
utest::v1::status_t utest::v1::greentea_case_failure_abort_handler(const Case *const source, const failure_t failure)
|
||||
{
|
||||
UTEST_LOG_FUNCTION
|
||||
UTEST_LOG_FUNCTION();
|
||||
utest::v1::status_t status = verbose_case_failure_handler(source, failure);
|
||||
return (status == STATUS_IGNORE) ? STATUS_IGNORE : STATUS_ABORT;
|
||||
}
|
||||
|
||||
utest::v1::status_t utest::v1::greentea_case_failure_continue_handler(const Case *const source, const failure_t failure)
|
||||
{
|
||||
UTEST_LOG_FUNCTION
|
||||
UTEST_LOG_FUNCTION();
|
||||
return verbose_case_failure_handler(source, failure);
|
||||
}
|
||||
|
|
|
@ -55,19 +55,19 @@ namespace
|
|||
}
|
||||
|
||||
static void die() {
|
||||
UTEST_LOG_FUNCTION
|
||||
UTEST_LOG_FUNCTION();
|
||||
while(1) ;
|
||||
}
|
||||
|
||||
static bool is_scheduler_valid(const utest_v1_scheduler_t scheduler)
|
||||
{
|
||||
UTEST_LOG_FUNCTION
|
||||
UTEST_LOG_FUNCTION();
|
||||
return (scheduler.init && scheduler.post && scheduler.cancel && scheduler.run);
|
||||
}
|
||||
|
||||
bool Harness::set_scheduler(const utest_v1_scheduler_t scheduler)
|
||||
{
|
||||
UTEST_LOG_FUNCTION
|
||||
UTEST_LOG_FUNCTION();
|
||||
if (is_scheduler_valid(scheduler)) {
|
||||
::scheduler = scheduler;
|
||||
return true;
|
||||
|
@ -77,27 +77,33 @@ bool Harness::set_scheduler(const utest_v1_scheduler_t scheduler)
|
|||
|
||||
bool Harness::run(const Specification& specification, size_t)
|
||||
{
|
||||
UTEST_LOG_FUNCTION
|
||||
UTEST_LOG_FUNCTION();
|
||||
return run(specification);
|
||||
}
|
||||
|
||||
bool Harness::run(const Specification& specification)
|
||||
{
|
||||
UTEST_LOG_FUNCTION
|
||||
UTEST_LOG_FUNCTION();
|
||||
printf("here in harness::run 1\n");
|
||||
// check if a specification is currently running
|
||||
if (is_busy())
|
||||
return false;
|
||||
printf("here in harness::run 2\n");
|
||||
|
||||
// if the scheduler is invalid, this is the first time we are calling
|
||||
if (!is_scheduler_valid(scheduler))
|
||||
scheduler = utest_v1_get_scheduler();
|
||||
// if the scheduler is still invalid, abort
|
||||
printf("here in harness::run 3\n");
|
||||
|
||||
// if the scheduler is still invalid, abort
|
||||
if (!is_scheduler_valid(scheduler))
|
||||
return false;
|
||||
printf("here in harness::run 4\n");
|
||||
|
||||
// if the scheduler failed to initialize, abort
|
||||
if (scheduler.init() != 0)
|
||||
return false;
|
||||
|
||||
printf("here in harness::run 5\n");
|
||||
test_cases = specification.cases;
|
||||
test_length = specification.length;
|
||||
defaults = specification.defaults;
|
||||
|
@ -149,7 +155,7 @@ bool Harness::run(const Specification& specification)
|
|||
|
||||
void Harness::raise_failure(const failure_reason_t reason)
|
||||
{
|
||||
UTEST_LOG_FUNCTION
|
||||
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;
|
||||
|
@ -195,7 +201,7 @@ void Harness::raise_failure(const failure_reason_t reason)
|
|||
|
||||
void Harness::schedule_next_case()
|
||||
{
|
||||
UTEST_LOG_FUNCTION
|
||||
UTEST_LOG_FUNCTION();
|
||||
if (!case_timeout_occurred && case_failed_before == case_failed) {
|
||||
case_passed++;
|
||||
}
|
||||
|
@ -231,7 +237,7 @@ void Harness::schedule_next_case()
|
|||
|
||||
void Harness::handle_timeout()
|
||||
{
|
||||
UTEST_LOG_FUNCTION
|
||||
UTEST_LOG_FUNCTION();
|
||||
{
|
||||
UTEST_ENTER_CRITICAL_SECTION;
|
||||
|
||||
|
@ -249,7 +255,7 @@ void Harness::handle_timeout()
|
|||
|
||||
void Harness::validate_callback(const control_t control)
|
||||
{
|
||||
UTEST_LOG_FUNCTION
|
||||
UTEST_LOG_FUNCTION();
|
||||
UTEST_ENTER_CRITICAL_SECTION;
|
||||
case_validation_count++;
|
||||
|
||||
|
@ -269,7 +275,7 @@ void Harness::validate_callback(const control_t control)
|
|||
|
||||
bool Harness::is_busy()
|
||||
{
|
||||
UTEST_LOG_FUNCTION
|
||||
UTEST_LOG_FUNCTION();
|
||||
UTEST_ENTER_CRITICAL_SECTION;
|
||||
if (!test_cases) return false;
|
||||
if (!case_current) return false;
|
||||
|
@ -281,7 +287,7 @@ bool Harness::is_busy()
|
|||
|
||||
void Harness::run_next_case()
|
||||
{
|
||||
UTEST_LOG_FUNCTION
|
||||
UTEST_LOG_FUNCTION();
|
||||
if(case_current < (test_cases + test_length))
|
||||
{
|
||||
handlers.case_setup = defaults.get_handler(case_current->setup_handler);
|
||||
|
|
|
@ -69,20 +69,20 @@ Timeout utest_timeout_object;
|
|||
|
||||
static void ticker_handler()
|
||||
{
|
||||
UTEST_LOG_FUNCTION
|
||||
UTEST_LOG_FUNCTION();
|
||||
//printf("\t\t>>> Ticker callback fired for %p.\n", ticker_callback);
|
||||
minimal_callback = ticker_callback;
|
||||
}
|
||||
|
||||
static int32_t utest_us_ticker_init()
|
||||
{
|
||||
UTEST_LOG_FUNCTION
|
||||
UTEST_LOG_FUNCTION();
|
||||
// Ticker scheduler does not require any initialisation so return immediately
|
||||
return 0;
|
||||
}
|
||||
static void *utest_us_ticker_post(const utest_v1_harness_callback_t callback, timestamp_t delay_ms)
|
||||
{
|
||||
UTEST_LOG_FUNCTION
|
||||
UTEST_LOG_FUNCTION();
|
||||
timestamp_t delay_us = delay_ms *1000;
|
||||
|
||||
//printf("\t\t>>> Schedule %p with %ums delay => %p.\n", callback, (unsigned int)delay_ms, (void*)1);
|
||||
|
@ -103,7 +103,7 @@ static void *utest_us_ticker_post(const utest_v1_harness_callback_t callback, ti
|
|||
}
|
||||
static int32_t utest_us_ticker_cancel(void *handle)
|
||||
{
|
||||
UTEST_LOG_FUNCTION
|
||||
UTEST_LOG_FUNCTION();
|
||||
//printf("\t\t>>> Cancel %p => %u\n", handle, (unsigned int)0);
|
||||
(void) handle;
|
||||
utest_timeout_object.detach();
|
||||
|
@ -111,7 +111,7 @@ static int32_t utest_us_ticker_cancel(void *handle)
|
|||
}
|
||||
static int32_t utest_us_ticker_run()
|
||||
{
|
||||
UTEST_LOG_FUNCTION
|
||||
UTEST_LOG_FUNCTION();
|
||||
while(1)
|
||||
{
|
||||
// check if a new callback has been set
|
||||
|
@ -138,7 +138,7 @@ static const utest_v1_scheduler_t utest_v1_scheduler =
|
|||
};
|
||||
utest_v1_scheduler_t utest_v1_get_scheduler()
|
||||
{
|
||||
UTEST_LOG_FUNCTION
|
||||
UTEST_LOG_FUNCTION();
|
||||
return utest_v1_scheduler;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,6 +26,8 @@
|
|||
|
||||
using namespace utest::v1;
|
||||
|
||||
std::string utest_trace[UTEST_MAX_BACKTRACE];
|
||||
|
||||
static unsigned trace_index = 0;
|
||||
static unsigned total_calls = 0;
|
||||
|
||||
|
@ -39,11 +41,7 @@ void utest_trace_initialise()
|
|||
}
|
||||
|
||||
void utest_add_to_trace(char *func_name)
|
||||
{
|
||||
|
||||
// Check if we have already used this entry. If so free the previously allocated
|
||||
// string.
|
||||
utest_trace[trace_index].clear();
|
||||
{
|
||||
utest_trace[trace_index] = std::string(func_name);
|
||||
trace_index = (trace_index + 1 == UTEST_MAX_BACKTRACE) ? 0 : trace_index + 1;
|
||||
total_calls ++;
|
||||
|
|
|
@ -23,13 +23,13 @@
|
|||
extern "C"
|
||||
void utest_unity_assert_failure()
|
||||
{
|
||||
UTEST_LOG_FUNCTION
|
||||
UTEST_LOG_FUNCTION();
|
||||
utest::v1::Harness::raise_failure(utest::v1::REASON_ASSERTION);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
void utest_unity_ignore_failure()
|
||||
{
|
||||
UTEST_LOG_FUNCTION
|
||||
UTEST_LOG_FUNCTION();
|
||||
utest::v1::Harness::raise_failure(utest::v1::failure_reason_t(utest::v1::REASON_ASSERTION | utest::v1::REASON_IGNORE));
|
||||
}
|
||||
|
|
|
@ -29,13 +29,13 @@ extern void utest_trace_initialise();
|
|||
extern void utest_add_to_trace(char *func_name);
|
||||
extern void utest_dump_trace();
|
||||
|
||||
#define UTEST_LOG_FUNCTION utest_add_to_trace((char *)__func__);
|
||||
#define UTEST_LOG_FUNCTION(); utest_add_to_trace((char *)__func__);
|
||||
#define UTEST_TRACE_START utest_trace_initialise();
|
||||
#define UTEST_DUMP_TRACE utest_dump_trace();
|
||||
|
||||
#else
|
||||
|
||||
#define UTEST_LOG_FUNCTION
|
||||
#define UTEST_LOG_FUNCTION();
|
||||
#define UTEST_TRACE_START
|
||||
#define UTEST_DUMP_TRACE
|
||||
|
||||
|
|
Loading…
Reference in New Issue