mirror of https://github.com/ARMmbed/mbed-os.git
Unify `Case` and `AsyncCase` using return type.
By letting the test case return a `control_t` type, it can decide itself if it repeats, and what timeouts are required. This removes the `AsyncCase` and allows a uniform declaration of test cases.
parent
b72f18009b
commit
dc4cb4585c
|
@ -28,11 +28,11 @@ Case::Case(const char *description,
|
||||||
const case_failure_handler_t failure_handler) :
|
const case_failure_handler_t failure_handler) :
|
||||||
description(description),
|
description(description),
|
||||||
handler(handler),
|
handler(handler),
|
||||||
control_flow_handler(ignore_handler),
|
control_handler(ignore_handler),
|
||||||
|
repeat_count_handler(ignore_handler),
|
||||||
setup_handler(setup_handler),
|
setup_handler(setup_handler),
|
||||||
teardown_handler(teardown_handler),
|
teardown_handler(teardown_handler),
|
||||||
failure_handler(failure_handler),
|
failure_handler(failure_handler)
|
||||||
timeout_ms(0)
|
|
||||||
{}
|
{}
|
||||||
|
|
||||||
Case::Case(const char *description,
|
Case::Case(const char *description,
|
||||||
|
@ -41,11 +41,11 @@ Case::Case(const char *description,
|
||||||
const case_failure_handler_t failure_handler) :
|
const case_failure_handler_t failure_handler) :
|
||||||
description(description),
|
description(description),
|
||||||
handler(handler),
|
handler(handler),
|
||||||
control_flow_handler(ignore_handler),
|
control_handler(ignore_handler),
|
||||||
|
repeat_count_handler(ignore_handler),
|
||||||
setup_handler(default_handler),
|
setup_handler(default_handler),
|
||||||
teardown_handler(teardown_handler),
|
teardown_handler(teardown_handler),
|
||||||
failure_handler(failure_handler),
|
failure_handler(failure_handler)
|
||||||
timeout_ms(0)
|
|
||||||
{}
|
{}
|
||||||
|
|
||||||
Case::Case(const char *description,
|
Case::Case(const char *description,
|
||||||
|
@ -53,67 +53,91 @@ Case::Case(const char *description,
|
||||||
const case_failure_handler_t failure_handler) :
|
const case_failure_handler_t failure_handler) :
|
||||||
description(description),
|
description(description),
|
||||||
handler(handler),
|
handler(handler),
|
||||||
control_flow_handler(ignore_handler),
|
control_handler(ignore_handler),
|
||||||
|
repeat_count_handler(ignore_handler),
|
||||||
setup_handler(default_handler),
|
setup_handler(default_handler),
|
||||||
teardown_handler(default_handler),
|
teardown_handler(default_handler),
|
||||||
failure_handler(failure_handler),
|
failure_handler(failure_handler)
|
||||||
timeout_ms(0)
|
{}
|
||||||
|
|
||||||
|
// control handler
|
||||||
|
Case::Case(const char *description,
|
||||||
|
const case_setup_handler_t setup_handler,
|
||||||
|
const case_control_handler_t handler,
|
||||||
|
const case_teardown_handler_t teardown_handler,
|
||||||
|
const case_failure_handler_t failure_handler) :
|
||||||
|
description(description),
|
||||||
|
handler(ignore_handler),
|
||||||
|
control_handler(handler),
|
||||||
|
repeat_count_handler(ignore_handler),
|
||||||
|
setup_handler(setup_handler),
|
||||||
|
teardown_handler(teardown_handler),
|
||||||
|
failure_handler(failure_handler)
|
||||||
|
{}
|
||||||
|
|
||||||
|
Case::Case(const char *description,
|
||||||
|
const case_control_handler_t handler,
|
||||||
|
const case_teardown_handler_t teardown_handler,
|
||||||
|
const case_failure_handler_t failure_handler) :
|
||||||
|
description(description),
|
||||||
|
handler(ignore_handler),
|
||||||
|
control_handler(handler),
|
||||||
|
repeat_count_handler(ignore_handler),
|
||||||
|
setup_handler(default_handler),
|
||||||
|
teardown_handler(teardown_handler),
|
||||||
|
failure_handler(failure_handler)
|
||||||
|
{}
|
||||||
|
|
||||||
|
Case::Case(const char *description,
|
||||||
|
const case_control_handler_t handler,
|
||||||
|
const case_failure_handler_t failure_handler) :
|
||||||
|
description(description),
|
||||||
|
handler(ignore_handler),
|
||||||
|
control_handler(handler),
|
||||||
|
repeat_count_handler(ignore_handler),
|
||||||
|
setup_handler(default_handler),
|
||||||
|
teardown_handler(default_handler),
|
||||||
|
failure_handler(failure_handler)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
// control flow handler
|
// control flow handler
|
||||||
Case::Case(const char *description,
|
Case::Case(const char *description,
|
||||||
const case_setup_handler_t setup_handler,
|
const case_setup_handler_t setup_handler,
|
||||||
const case_control_flow_handler_t control_flow_handler,
|
const case_repeat_count_handler_t case_repeat_count_handler,
|
||||||
const case_teardown_handler_t teardown_handler,
|
const case_teardown_handler_t teardown_handler,
|
||||||
const case_failure_handler_t failure_handler) :
|
const case_failure_handler_t failure_handler) :
|
||||||
description(description),
|
description(description),
|
||||||
handler(ignore_handler),
|
handler(ignore_handler),
|
||||||
control_flow_handler(control_flow_handler),
|
control_handler(ignore_handler),
|
||||||
|
repeat_count_handler(case_repeat_count_handler),
|
||||||
setup_handler(setup_handler),
|
setup_handler(setup_handler),
|
||||||
teardown_handler(teardown_handler),
|
teardown_handler(teardown_handler),
|
||||||
failure_handler(failure_handler),
|
failure_handler(failure_handler)
|
||||||
timeout_ms(0)
|
|
||||||
{}
|
{}
|
||||||
|
|
||||||
Case::Case(const char *description,
|
Case::Case(const char *description,
|
||||||
const case_control_flow_handler_t control_flow_handler,
|
const case_repeat_count_handler_t case_repeat_count_handler,
|
||||||
const case_failure_handler_t failure_handler) :
|
const case_failure_handler_t failure_handler) :
|
||||||
description(description),
|
description(description),
|
||||||
handler(ignore_handler),
|
handler(ignore_handler),
|
||||||
control_flow_handler(control_flow_handler),
|
control_handler(ignore_handler),
|
||||||
|
repeat_count_handler(case_repeat_count_handler),
|
||||||
setup_handler(default_handler),
|
setup_handler(default_handler),
|
||||||
teardown_handler(default_handler),
|
teardown_handler(default_handler),
|
||||||
failure_handler(failure_handler),
|
failure_handler(failure_handler)
|
||||||
timeout_ms(0)
|
|
||||||
{}
|
{}
|
||||||
|
|
||||||
Case::Case(const char *description,
|
Case::Case(const char *description,
|
||||||
const case_control_flow_handler_t control_flow_handler,
|
const case_repeat_count_handler_t case_repeat_count_handler,
|
||||||
const case_teardown_handler_t teardown_handler,
|
const case_teardown_handler_t teardown_handler,
|
||||||
const case_failure_handler_t failure_handler) :
|
const case_failure_handler_t failure_handler) :
|
||||||
description(description),
|
description(description),
|
||||||
handler(ignore_handler),
|
handler(ignore_handler),
|
||||||
control_flow_handler(control_flow_handler),
|
control_handler(ignore_handler),
|
||||||
|
repeat_count_handler(case_repeat_count_handler),
|
||||||
setup_handler(default_handler),
|
setup_handler(default_handler),
|
||||||
teardown_handler(teardown_handler),
|
teardown_handler(teardown_handler),
|
||||||
failure_handler(failure_handler),
|
failure_handler(failure_handler)
|
||||||
timeout_ms(0)
|
|
||||||
{}
|
|
||||||
|
|
||||||
Case::Case(const char *description,
|
|
||||||
const case_setup_handler_t setup_handler,
|
|
||||||
const case_handler_t handler,
|
|
||||||
const case_control_flow_handler_t control_flow_handler,
|
|
||||||
const case_teardown_handler_t teardown_handler,
|
|
||||||
const case_failure_handler_t failure_handler,
|
|
||||||
const int32_t timeout_ms) :
|
|
||||||
description(description),
|
|
||||||
handler(handler),
|
|
||||||
control_flow_handler(control_flow_handler),
|
|
||||||
setup_handler(setup_handler),
|
|
||||||
teardown_handler(teardown_handler),
|
|
||||||
failure_handler(failure_handler),
|
|
||||||
timeout_ms(timeout_ms)
|
|
||||||
{}
|
{}
|
||||||
|
|
||||||
const char*
|
const char*
|
||||||
|
@ -123,116 +147,5 @@ Case::get_description() const {
|
||||||
|
|
||||||
bool
|
bool
|
||||||
Case::is_empty() const {
|
Case::is_empty() const {
|
||||||
return !(handler || control_flow_handler || setup_handler || teardown_handler);
|
return !(handler || repeat_count_handler || setup_handler || teardown_handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
AsyncCase::AsyncCase(const char *description,
|
|
||||||
const case_handler_t case_handler,
|
|
||||||
const uint32_t timeout_ms) :
|
|
||||||
Case(description, default_handler, case_handler, ignore_handler, default_handler, default_handler, timeout_ms) {}
|
|
||||||
|
|
||||||
AsyncCase::AsyncCase(const char *description,
|
|
||||||
const case_setup_handler_t setup_handler,
|
|
||||||
const case_handler_t case_handler,
|
|
||||||
const uint32_t timeout_ms) :
|
|
||||||
Case(description, setup_handler, case_handler, ignore_handler, default_handler, default_handler, timeout_ms) {}
|
|
||||||
|
|
||||||
|
|
||||||
AsyncCase::AsyncCase(const char *description,
|
|
||||||
const case_handler_t case_handler,
|
|
||||||
const case_teardown_handler_t teardown_handler,
|
|
||||||
const uint32_t timeout_ms) :
|
|
||||||
Case(description, default_handler, case_handler, ignore_handler, teardown_handler, default_handler, timeout_ms) {}
|
|
||||||
|
|
||||||
AsyncCase::AsyncCase(const char *description,
|
|
||||||
const case_setup_handler_t setup_handler,
|
|
||||||
const case_handler_t case_handler,
|
|
||||||
const case_teardown_handler_t teardown_handler,
|
|
||||||
const uint32_t timeout_ms) :
|
|
||||||
Case(description, setup_handler, case_handler, ignore_handler, teardown_handler, default_handler, timeout_ms) {}
|
|
||||||
|
|
||||||
|
|
||||||
AsyncCase::AsyncCase(const char *description,
|
|
||||||
const case_handler_t case_handler,
|
|
||||||
const case_failure_handler_t failure_handler,
|
|
||||||
const uint32_t timeout_ms) :
|
|
||||||
Case(description, default_handler, case_handler, ignore_handler, default_handler, failure_handler, timeout_ms) {}
|
|
||||||
|
|
||||||
AsyncCase::AsyncCase(const char *description,
|
|
||||||
const case_setup_handler_t setup_handler,
|
|
||||||
const case_handler_t case_handler,
|
|
||||||
const case_failure_handler_t failure_handler,
|
|
||||||
const uint32_t timeout_ms) :
|
|
||||||
Case(description, setup_handler, case_handler, ignore_handler, default_handler, failure_handler, timeout_ms) {}
|
|
||||||
|
|
||||||
AsyncCase::AsyncCase(const char *description,
|
|
||||||
const case_handler_t case_handler,
|
|
||||||
const case_teardown_handler_t teardown_handler,
|
|
||||||
const case_failure_handler_t failure_handler,
|
|
||||||
const uint32_t timeout_ms) :
|
|
||||||
Case(description, default_handler, case_handler, ignore_handler, teardown_handler, failure_handler, timeout_ms) {}
|
|
||||||
|
|
||||||
AsyncCase::AsyncCase(const char *description,
|
|
||||||
const case_setup_handler_t setup_handler,
|
|
||||||
const case_handler_t case_handler,
|
|
||||||
const case_teardown_handler_t teardown_handler,
|
|
||||||
const case_failure_handler_t failure_handler,
|
|
||||||
const uint32_t timeout_ms) :
|
|
||||||
Case(description, setup_handler, case_handler, ignore_handler, teardown_handler, failure_handler, timeout_ms) {}
|
|
||||||
|
|
||||||
|
|
||||||
AsyncCase::AsyncCase(const char *description,
|
|
||||||
const case_control_flow_handler_t case_handler,
|
|
||||||
const uint32_t timeout_ms) :
|
|
||||||
Case(description, default_handler, ignore_handler, case_handler, default_handler, default_handler, timeout_ms) {}
|
|
||||||
|
|
||||||
AsyncCase::AsyncCase(const char *description,
|
|
||||||
const case_setup_handler_t setup_handler,
|
|
||||||
const case_control_flow_handler_t case_handler,
|
|
||||||
const uint32_t timeout_ms) :
|
|
||||||
Case(description, setup_handler, ignore_handler, case_handler, default_handler, default_handler, timeout_ms) {}
|
|
||||||
|
|
||||||
|
|
||||||
AsyncCase::AsyncCase(const char *description,
|
|
||||||
const case_control_flow_handler_t case_handler,
|
|
||||||
const case_teardown_handler_t teardown_handler,
|
|
||||||
const uint32_t timeout_ms) :
|
|
||||||
Case(description, default_handler, ignore_handler, case_handler, teardown_handler, default_handler, timeout_ms) {}
|
|
||||||
|
|
||||||
AsyncCase::AsyncCase(const char *description,
|
|
||||||
const case_setup_handler_t setup_handler,
|
|
||||||
const case_control_flow_handler_t case_handler,
|
|
||||||
const case_teardown_handler_t teardown_handler,
|
|
||||||
const uint32_t timeout_ms) :
|
|
||||||
Case(description, setup_handler, ignore_handler, case_handler, teardown_handler, default_handler, timeout_ms) {}
|
|
||||||
|
|
||||||
|
|
||||||
AsyncCase::AsyncCase(const char *description,
|
|
||||||
const case_control_flow_handler_t case_handler,
|
|
||||||
const case_failure_handler_t failure_handler,
|
|
||||||
const uint32_t timeout_ms) :
|
|
||||||
Case(description, default_handler, ignore_handler, case_handler, default_handler, failure_handler, timeout_ms) {}
|
|
||||||
|
|
||||||
AsyncCase::AsyncCase(const char *description,
|
|
||||||
const case_setup_handler_t setup_handler,
|
|
||||||
const case_control_flow_handler_t case_handler,
|
|
||||||
const case_failure_handler_t failure_handler,
|
|
||||||
const uint32_t timeout_ms) :
|
|
||||||
Case(description, setup_handler, ignore_handler, case_handler, default_handler, failure_handler, timeout_ms) {}
|
|
||||||
|
|
||||||
|
|
||||||
AsyncCase::AsyncCase(const char *description,
|
|
||||||
const case_control_flow_handler_t case_handler,
|
|
||||||
const case_teardown_handler_t teardown_handler,
|
|
||||||
const case_failure_handler_t failure_handler,
|
|
||||||
const uint32_t timeout_ms) :
|
|
||||||
Case(description, default_handler, ignore_handler, case_handler, teardown_handler, failure_handler, timeout_ms) {}
|
|
||||||
|
|
||||||
AsyncCase::AsyncCase(const char *description,
|
|
||||||
const case_setup_handler_t setup_handler,
|
|
||||||
const case_control_flow_handler_t case_handler,
|
|
||||||
const case_teardown_handler_t teardown_handler,
|
|
||||||
const case_failure_handler_t failure_handler,
|
|
||||||
const uint32_t timeout_ms) :
|
|
||||||
Case(description, setup_handler, ignore_handler, case_handler, teardown_handler, failure_handler, timeout_ms) {}
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ namespace
|
||||||
size_t test_failed = 0;
|
size_t test_failed = 0;
|
||||||
|
|
||||||
const Case *case_current = NULL;
|
const Case *case_current = NULL;
|
||||||
control_flow_t case_control_flow = CONTROL_FLOW_NEXT;
|
control_t case_control = control_t();
|
||||||
size_t case_repeat_count = 0;
|
size_t case_repeat_count = 0;
|
||||||
|
|
||||||
minar::callback_handle_t case_timeout_handle = NULL;
|
minar::callback_handle_t case_timeout_handle = NULL;
|
||||||
|
@ -107,16 +107,19 @@ void Harness::schedule_next_case()
|
||||||
{
|
{
|
||||||
if (case_failed_before == case_failed) case_passed++;
|
if (case_failed_before == case_failed) case_passed++;
|
||||||
|
|
||||||
if(case_control_flow == CONTROL_FLOW_NEXT) {
|
if(case_control.repeat != REPEAT_CASE_ONLY) {
|
||||||
if (handlers.case_teardown &&
|
if (handlers.case_teardown &&
|
||||||
(handlers.case_teardown(case_current, case_passed, case_failed,
|
(handlers.case_teardown(case_current, case_passed, case_failed,
|
||||||
case_failed ? FAILURE_CASES : FAILURE_NONE) != STATUS_CONTINUE)) {
|
case_failed ? FAILURE_CASES : FAILURE_NONE) != STATUS_CONTINUE)) {
|
||||||
raise_failure(FAILURE_TEARDOWN);
|
raise_failure(FAILURE_TEARDOWN);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(case_control.repeat == REPEAT_NO_REPEAT) {
|
||||||
if (case_failed > 0) test_failed++;
|
if (case_failed > 0) test_failed++;
|
||||||
else test_passed++;
|
else test_passed++;
|
||||||
|
|
||||||
|
case_control = control_t();
|
||||||
case_current++;
|
case_current++;
|
||||||
case_passed = 0;
|
case_passed = 0;
|
||||||
case_failed = 0;
|
case_failed = 0;
|
||||||
|
@ -175,9 +178,9 @@ void Harness::run_next_case()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!case_failed && !case_passed) {
|
if ((!case_failed && !case_passed) || case_control.repeat == REPEAT_ALL) {
|
||||||
size_t index = test_index_of_case++;
|
if (case_control.repeat == REPEAT_NO_REPEAT) test_index_of_case++;
|
||||||
if (handlers.case_setup && (handlers.case_setup(case_current, index) != STATUS_CONTINUE)) {
|
if (handlers.case_setup && (handlers.case_setup(case_current, test_index_of_case) != STATUS_CONTINUE)) {
|
||||||
raise_failure(FAILURE_SETUP);
|
raise_failure(FAILURE_SETUP);
|
||||||
schedule_next_case();
|
schedule_next_case();
|
||||||
return;
|
return;
|
||||||
|
@ -187,16 +190,17 @@ void Harness::run_next_case()
|
||||||
case_failed_before = case_failed;
|
case_failed_before = case_failed;
|
||||||
|
|
||||||
if (case_current->handler) {
|
if (case_current->handler) {
|
||||||
case_control_flow = CONTROL_FLOW_NEXT;
|
|
||||||
case_current->handler();
|
case_current->handler();
|
||||||
} else if (case_current->control_flow_handler) {
|
} else if (case_current->control_handler) {
|
||||||
case_control_flow = case_current->control_flow_handler(case_repeat_count);
|
case_control = case_current->control_handler();
|
||||||
case_repeat_count++;
|
} else if (case_current->repeat_count_handler) {
|
||||||
|
case_control = case_current->repeat_count_handler(case_repeat_count);
|
||||||
}
|
}
|
||||||
|
case_repeat_count++;
|
||||||
|
|
||||||
if (case_current->timeout_ms > 0) {
|
if (case_control.timeout > 0) {
|
||||||
case_timeout_handle = minar::Scheduler::postCallback(handle_timeout)
|
case_timeout_handle = minar::Scheduler::postCallback(handle_timeout)
|
||||||
.delay(minar::milliseconds(case_current->timeout_ms))
|
.delay(minar::milliseconds(case_control.timeout))
|
||||||
.getHandle();
|
.getHandle();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
Loading…
Reference in New Issue