From 72960bc7d4c8f7eb7687827d1c1545b1eb5fdb71 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Thu, 13 Aug 2020 11:33:47 +0200 Subject: libtest: Change T_step() and T_assert_step() Normally, the expected test step must be a compile time constant. Allow variable expected test steps for the T_step() and T_assert_step(). This can be used for parameterized test loops with individual fixtures. Remove the ability to use custom failure messages due to some implementation constraints. Update #3199. --- cpukit/include/rtems/test.h | 17 +++++++++++------ cpukit/libtest/t-test.c | 11 +++++++++++ testsuites/libtests/ttest01/test-destructor.c | 2 +- testsuites/libtests/ttest01/test-plan.c | 6 +++--- testsuites/smptests/smpmulticast01/init.c | 16 ++++++++-------- 5 files changed, 34 insertions(+), 18 deletions(-) diff --git a/cpukit/include/rtems/test.h b/cpukit/include/rtems/test.h index 95e078ceff..ccab6c4a95 100644 --- a/cpukit/include/rtems/test.h +++ b/cpukit/include/rtems/test.h @@ -2168,12 +2168,17 @@ void T_check_rsc_success(const T_check_context *, uint32_t); void T_plan(unsigned int); -#define T_step(...) \ - T_flags_true(T_CHECK_STEP(T_VA_ARGS_FIRST(__VA_ARGS__)), \ - true T_VA_ARGS_MORE(__VA_ARGS__)) -#define T_step_assert(...) \ - T_flags_true(T_CHECK_STEP(T_VA_ARGS_FIRST(__VA_ARGS__)) | T_CHECK_STOP, \ - true T_VA_ARGS_MORE(__VA_ARGS__)) +void T_check_step(const T_check_context *, unsigned int); + +#define T_flags_step(a, flags) \ +{ \ + static const T_check_context T_check_instance = { \ + T_FILE_NAME, __LINE__, (flags) | T_CHECK_FMT }; \ + T_check_step(&T_check_instance, a); \ +} + +#define T_step(e) T_flags_step(e, 0) +#define T_step_assert(e) T_flags_step(e, T_CHECK_STOP) /** * @defgroup RTEMSTestFrameworkTime Time Services diff --git a/cpukit/libtest/t-test.c b/cpukit/libtest/t-test.c index 4d68a83fff..3f9046a891 100644 --- a/cpukit/libtest/t-test.c +++ b/cpukit/libtest/t-test.c @@ -550,6 +550,17 @@ void T_plan(unsigned int planned_steps) expected); } +void +T_check_step(const T_check_context *t, unsigned int expected) +{ + T_check_context tt; + + tt = *t; + tt.flags |= T_CHECK_STEP(expected); + T_check(&tt, true, "actual step is not equal to expected step (%u)", + expected); +} + void T_case_register(T_case_context *tc) { diff --git a/testsuites/libtests/ttest01/test-destructor.c b/testsuites/libtests/ttest01/test-destructor.c index 71b14c08f6..0a2f650ed2 100644 --- a/testsuites/libtests/ttest01/test-destructor.c +++ b/testsuites/libtests/ttest01/test-destructor.c @@ -4,7 +4,7 @@ static void destroy(T_destructor *dtor) { (void)dtor; - T_step(0, "destroy"); + T_step(0); } T_TEST_CASE(destructor) diff --git a/testsuites/libtests/ttest01/test-plan.c b/testsuites/libtests/ttest01/test-plan.c index 155704c478..4a550f34fa 100644 --- a/testsuites/libtests/ttest01/test-plan.c +++ b/testsuites/libtests/ttest01/test-plan.c @@ -28,10 +28,10 @@ T_TEST_CASE(double_plan) T_TEST_CASE(steps) { - T_step(0, "a"); + T_step(0); T_plan(3); - T_step(1, "b"); - T_step(2, "c"); + T_step(1); + T_step(2); } #include "t-self-test.h" diff --git a/testsuites/smptests/smpmulticast01/init.c b/testsuites/smptests/smpmulticast01/init.c index b6ee9f93cc..f5ed70952a 100644 --- a/testsuites/smptests/smpmulticast01/init.c +++ b/testsuites/smptests/smpmulticast01/init.c @@ -432,17 +432,17 @@ static Per_CPU_Job job_order_jobs[TEST_JOB_ORDER_JOBS]; static void job_order_handler_0(void *arg) { - T_step(1, "invalid job order"); + T_step(1); } static void job_order_handler_1(void *arg) { - T_step(2, "invalid job order"); + T_step(2); } static void job_order_handler_2(void *arg) { - T_step(3, "invalid job order"); + T_step(3); } static const Per_CPU_Job_context job_order_contexts[TEST_JOB_ORDER_JOBS] = { @@ -464,7 +464,7 @@ T_TEST_CASE(JobOrder) _Per_CPU_Add_job(cpu_self, &job_order_jobs[i]); } - T_step(0, "wrong job processing time"); + T_step(0); _SMP_Send_message(_Per_CPU_Get_index(cpu_self), SMP_MESSAGE_PERFORM_JOBS); _Thread_Dispatch_enable(cpu_self); } @@ -475,13 +475,13 @@ static Per_CPU_Job add_job_in_job_jobs[TEST_ADD_JOB_IN_JOB_JOBS]; static void add_job_in_job_handler_0(void *arg) { - T_step(1, "invalid job order"); + T_step(1); _Per_CPU_Add_job(_Per_CPU_Get(), &add_job_in_job_jobs[1]); } static void add_job_in_job_handler_1(void *arg) { - T_step(3, "invalid job order"); + T_step(3); } static const Per_CPU_Job_context @@ -503,9 +503,9 @@ T_TEST_CASE(AddJobInJob) } _Per_CPU_Add_job(cpu_self, &add_job_in_job_jobs[0]); - T_step(0, "wrong job processing time"); + T_step(0); _SMP_Send_message(_Per_CPU_Get_index(cpu_self), SMP_MESSAGE_PERFORM_JOBS); - T_step(2, "wrong job processing time"); + T_step(2); _SMP_Send_message(_Per_CPU_Get_index(cpu_self), SMP_MESSAGE_PERFORM_JOBS); _Thread_Dispatch_enable(cpu_self); } -- cgit v1.2.3