Support a new test plan for each nested fixture.

Update #3199.
---
 cpukit/include/rtems/test.h                |  3 +
 cpukit/libtest/t-test.c                    | 83 ++++++++++++++--------
 testsuites/libtests/ttest01/init.c         |  2 +-
 testsuites/libtests/ttest01/test-fixture.c | 34 ++++-----
 testsuites/libtests/ttest02/init.c         |  7 +-
 5 files changed, 80 insertions(+), 49 deletions(-)

diff --git a/cpukit/include/rtems/test.h b/cpukit/include/rtems/test.h
index 212d4a5ae2..95e078ceff 100644
--- a/cpukit/include/rtems/test.h
+++ b/cpukit/include/rtems/test.h
@@ -71,6 +71,9 @@ typedef struct T_fixture_node {
        struct T_fixture_node *previous;
        const T_fixture *fixture;
        void *context;
+       unsigned int next_planned_steps;
+       unsigned int next_steps;
+       unsigned int failures;
 } T_fixture_node;
 
 #define T_ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
diff --git a/cpukit/libtest/t-test.c b/cpukit/libtest/t-test.c
index 21e9afe190..306f9439c4 100644
--- a/cpukit/libtest/t-test.c
+++ b/cpukit/libtest/t-test.c
@@ -68,6 +68,7 @@ typedef struct {
        atomic_uint steps;
        atomic_uint failures;
        jmp_buf case_begin_context;
+       unsigned int fixture_steps;
        unsigned int overall_cases;
        unsigned int overall_steps;
        unsigned int overall_failures;
@@ -633,6 +634,32 @@ T_check_putc(int c, void *arg)
        }
 }
 
+static void
+T_check_print_steps(T_context *ctx, T_putchar_string_context *sctx,
+    unsigned int step)
+{
+       T_fixture_node *node;
+
+       node = &ctx->case_fixture;
+
+       while (true) {
+               node = node->previous;
+
+               if (node != NULL) {
+                       _IO_Printf(T_check_putc, sctx, "%u.",
+                           node->next_steps);
+               } else {
+                       break;
+               }
+       }
+
+       if (step != UINT_MAX) {
+               _IO_Printf(T_check_putc, sctx, "%u", step);
+       } else {
+               T_check_putc('*', sctx);
+       }
+}
+
 void
 T_check(const T_check_context *t, bool ok, ...)
 {
@@ -686,13 +713,7 @@ T_check(const T_check_context *t, bool ok, ...)
                sctx.n = sizeof(line) - 1;
                sctx.s = &line[1];
                T_check_putc(':', &sctx);
-
-               if (step != UINT_MAX) {
-                       _IO_Printf(T_check_putc, &sctx, "%u", step);
-               } else {
-                       T_check_putc('*', &sctx);
-               }
-
+               T_check_print_steps(ctx, &sctx, step);
                _IO_Printf(T_check_putc, &sctx, ":%i:", T_cpu());
                chunk = T_scope(ctx, sctx.s, sctx.n);
                sctx.s += chunk;
@@ -887,8 +908,6 @@ T_do_run_initialize(const T_config *config)
        ctx->putchar = config->putchar;
        ctx->putchar_arg = config->putchar_arg;
        ctx->verbosity = config->verbosity;
-       atomic_store_explicit(&ctx->steps, 0, memory_order_relaxed);
-       atomic_store_explicit(&ctx->failures, 0, memory_order_relaxed);
        ctx->overall_cases = 0;
        ctx->overall_steps = 0;
        ctx->overall_failures = 0;
@@ -919,6 +938,7 @@ T_do_case_begin(T_context *ctx, const T_case_context *tc)
            memory_order_relaxed);
        atomic_store_explicit(&ctx->steps, 0, memory_order_relaxed);
        atomic_store_explicit(&ctx->failures, 0, memory_order_relaxed);
+       ctx->fixture_steps = 0;
 
        T_actions_forward(config, T_EVENT_CASE_EARLY, tc->name);
        T_do_log(ctx, T_NORMAL, "B:%s\n", tc->name);
@@ -950,33 +970,18 @@ static void
 T_do_case_end(T_context *ctx, const T_case_context *tc)
 {
        const T_config *config;
-       T_fixture_node *node;
        unsigned int planned_steps;
        unsigned int steps;
        unsigned int failures;
        T_time delta;
        T_time_string ts;
 
-       config = ctx->config;
-       node = ctx->fixtures;
-       ctx->fixtures = NULL;
-
-       while (node != NULL) {
-               const T_fixture *fixture;
-               T_fixture_node *dead;
-
-               fixture = node->fixture;
-
-               if (fixture != NULL && fixture->teardown != NULL) {
-                       (*fixture->teardown)(node->context);
-               }
-
-               dead = node;
-               node = node->next;
-               memset(dead, 0, sizeof(*dead));
+       while (ctx->fixtures != NULL) {
+               T_pop_fixture();
        }
 
        T_call_destructors(ctx);
+       config = ctx->config;
        T_actions_backward(config, T_EVENT_CASE_END, tc->name);
 
        planned_steps = atomic_fetch_add_explicit(&ctx->planned_steps,
@@ -989,6 +994,7 @@ T_do_case_end(T_context *ctx, const T_case_context *tc)
 
        failures = atomic_load_explicit(&ctx->failures, memory_order_relaxed);
        delta = (*config->now)() - ctx->case_begin_time;
+       steps += ctx->fixture_steps;
        T_do_log(ctx, T_QUIET, "E:%s:N:%u:F:%u:D:%s\n",
            tc->name, steps, failures, T_time_to_string_us(delta, ts));
 
@@ -1179,6 +1185,12 @@ T_push_fixture(T_fixture_node *node, const T_fixture 
*fixture)
        node->fixture = fixture;
        context = fixture->initial_context;
        node->context = context;
+       node->next_planned_steps = atomic_exchange_explicit(
+           &ctx->planned_steps, UINT_MAX, memory_order_relaxed);
+       node->next_steps = atomic_exchange_explicit(&ctx->steps, 0,
+           memory_order_relaxed);
+       node->failures = atomic_fetch_add_explicit(&ctx->failures, 0,
+           memory_order_relaxed);
        ctx->fixtures = node;
 
        if (fixture != NULL && fixture->setup != NULL) {
@@ -1199,7 +1211,6 @@ T_pop_fixture(void)
        ctx = &T_instance;
        node = ctx->fixtures;
        next = node->next;
-       next->previous = NULL;
        ctx->fixtures = next;
        fixture = node->fixture;
 
@@ -1207,6 +1218,22 @@ T_pop_fixture(void)
                (*fixture->teardown)(node->context);
        }
 
+       if (next != NULL) {
+               unsigned int planned_steps;
+               unsigned int steps;
+               unsigned int failures;
+
+               next->previous = NULL;
+               planned_steps = atomic_exchange_explicit(&ctx->planned_steps,
+                   node->next_planned_steps, memory_order_relaxed);
+               steps = atomic_exchange_explicit(&ctx->steps, node->next_steps,
+                   memory_order_relaxed);
+               failures = atomic_fetch_add_explicit(&ctx->failures, 0,
+                   memory_order_relaxed);
+               ctx->fixture_steps += steps;
+               T_check_steps(planned_steps, steps, node->failures - failures);
+       }
+
        memset(node, 0, sizeof(*node));
 }
 
diff --git a/testsuites/libtests/ttest01/init.c 
b/testsuites/libtests/ttest01/init.c
index 35b7023385..8636cdadd4 100644
--- a/testsuites/libtests/ttest01/init.c
+++ b/testsuites/libtests/ttest01/init.c
@@ -183,7 +183,7 @@ run_initialize(void)
 }
 
 static const char expected_final[] = 
"Z:ttest01:C:343:N:1335:F:795:D:0.689999\n"
-"Y:ReportHash:SHA256:f018ab0c9ddf5c5bc0ba8377492dc52205f9b63146c787fb669222e346c65d0f\n";
+"Y:ReportHash:SHA256:525591019364543d5694dd09fef3bf2f0b7db69694f959e4298f22f4f9803fef\n";
 
 static void
 run_finalize(void)
diff --git a/testsuites/libtests/ttest01/test-fixture.c 
b/testsuites/libtests/ttest01/test-fixture.c
index 0e97c1c71c..e1f59876ca 100644
--- a/testsuites/libtests/ttest01/test-fixture.c
+++ b/testsuites/libtests/ttest01/test-fixture.c
@@ -144,35 +144,35 @@ T_TEST_OUTPUT(fixture,
 "L:setup end\n"
 "P:3:0:UI1/More:test-fixture.c:125\n"
 "L:setup 2 begin\n"
-"P:4:0:UI1/More/AndMore:test-fixture.c:71\n"
-"P:5:0:UI1/More/AndMore:test-fixture.c:72\n"
-"P:6:0:UI1/More/AndMore:test-fixture.c:76\n"
+"P:4.0:0:UI1/More/AndMore:test-fixture.c:71\n"
+"P:4.1:0:UI1/More/AndMore:test-fixture.c:72\n"
+"P:4.2:0:UI1/More/AndMore:test-fixture.c:76\n"
 "L:setup 2 end\n"
-"P:7:0:UI1/More/AndMore:test-fixture.c:127\n"
+"P:4.3:0:UI1/More/AndMore:test-fixture.c:127\n"
 "L:teardown 2 begin\n"
-"P:8:0:UI1/More:test-fixture.c:98\n"
-"P:9:0:UI1/More:test-fixture.c:100\n"
+"P:4.4:0:UI1/More/AndMore:test-fixture.c:98\n"
+"P:4.5:0:UI1/More/AndMore:test-fixture.c:100\n"
 "L:teardown 2 end\n"
 "L:setup 2 begin\n"
-"P:10:0:UI1/More/AndMore:test-fixture.c:71\n"
-"P:11:0:UI1/More/AndMore:test-fixture.c:72\n"
-"P:12:0:UI1/More/AndMore:test-fixture.c:76\n"
+"P:4.0:0:UI1/More/AndMore:test-fixture.c:71\n"
+"P:4.1:0:UI1/More/AndMore:test-fixture.c:72\n"
+"P:4.2:0:UI1/More/AndMore:test-fixture.c:76\n"
 "L:setup 2 end\n"
-"P:13:0:UI1/More/AndMore:test-fixture.c:131\n"
-"F:14:0:UI1/More/AndMore:test-fixture.c:132:test fails and we stop the test 
case\n"
+"P:4.3:0:UI1/More/AndMore:test-fixture.c:131\n"
+"F:4.4:0:UI1/More/AndMore:test-fixture.c:132:test fails and we stop the test 
case\n"
 "L:stop 2 begin\n"
-"P:15:0:UI1/More/AndMore:test-fixture.c:86\n"
+"P:4.5:0:UI1/More/AndMore:test-fixture.c:86\n"
 "L:stop 2 end\n"
 "L:stop begin\n"
-"P:16:0:UI1/More/AndMore:test-fixture.c:28\n"
+"P:4.6:0:UI1/More/AndMore:test-fixture.c:28\n"
 "L:stop end\n"
 "L:teardown 2 begin\n"
-"P:17:0:UI1/More/AndMore:test-fixture.c:98\n"
-"P:18:0:UI1/More/AndMore:test-fixture.c:100\n"
+"P:4.7:0:UI1/More/AndMore:test-fixture.c:98\n"
+"P:4.8:0:UI1/More/AndMore:test-fixture.c:100\n"
 "L:teardown 2 end\n"
 "L:teardown begin\n"
-"P:19:0:UI1/More:test-fixture.c:40\n"
-"P:20:0:UI1/More:test-fixture.c:42\n"
+"P:4:0:UI1/More:test-fixture.c:40\n"
+"P:5:0:UI1/More:test-fixture.c:42\n"
 "L:teardown end\n"
 "E:fixture:N:21:F:1:D:0.001000\n");
 
diff --git a/testsuites/libtests/ttest02/init.c 
b/testsuites/libtests/ttest02/init.c
index 846a778536..7f972aec7e 100644
--- a/testsuites/libtests/ttest02/init.c
+++ b/testsuites/libtests/ttest02/init.c
@@ -134,6 +134,7 @@ static void
 fatal(void *arg)
 {
        (void)arg;
+       T_plan(1);
        T_step(0);
        T_stop();
 }
@@ -149,7 +150,6 @@ T_TEST_CASE(TestInterruptFatal)
 {
        Atomic_Uint action_state;
 
-       T_plan(1);
        T_interrupt_test(&fatal_config, &action_state);
        T_unreachable();
 }
@@ -161,6 +161,7 @@ suspend(void *arg)
        rtems_id *id;
 
        id = arg;
+       T_plan(2);
        sc = rtems_task_suspend(*id);
        T_step_rsc_success(1, sc);
 }
@@ -202,10 +203,10 @@ T_TEST_CASE(TestInterruptBlocked)
        T_interrupt_test_state state;
        rtems_id id;
 
-       T_plan(3);
+       T_plan(1);
        id = rtems_task_self();
        state = T_interrupt_test(&blocked_config, &id);
-       T_step_eq_int(2, state, T_INTERRUPT_TEST_DONE);
+       T_step_eq_int(0, state, T_INTERRUPT_TEST_DONE);
 }
 
 T_TEST_CASE(TestThreadSwitch)
-- 
2.26.2

_______________________________________________
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

Reply via email to