summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2020-06-08 10:04:55 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2020-07-23 09:27:47 +0200
commit6b27e3251eb6b3374751cdcec4015b4ee1026e0e (patch)
tree79bcdce7c596569ae3dd5c1b77ec343ece5b37b6
parentlibtest: Add T_make_runner() (diff)
downloadrtems-6b27e3251eb6b3374751cdcec4015b4ee1026e0e.tar.bz2
libtest: Support custom scope messages via fixture
Update #3199.
-rw-r--r--cpukit/include/rtems/test.h1
-rw-r--r--cpukit/libtest/t-test.c32
-rw-r--r--testsuites/libtests/ttest01/init.c2
-rw-r--r--testsuites/libtests/ttest01/test-fixture.c24
4 files changed, 42 insertions, 17 deletions
diff --git a/cpukit/include/rtems/test.h b/cpukit/include/rtems/test.h
index a1a976d7ff..2362e5b804 100644
--- a/cpukit/include/rtems/test.h
+++ b/cpukit/include/rtems/test.h
@@ -62,6 +62,7 @@ typedef struct T_fixture {
void (*setup)(void *);
void (*stop)(void *);
void (*teardown)(void *);
+ void (*scope)(void *, char *, size_t);
void *initial_context;
} T_fixture;
diff --git a/cpukit/libtest/t-test.c b/cpukit/libtest/t-test.c
index a0336fa461..aa04f09139 100644
--- a/cpukit/libtest/t-test.c
+++ b/cpukit/libtest/t-test.c
@@ -49,7 +49,7 @@
#define T_LINE_SIZE 128
-#define T_SCOPE_SIZE 5
+#define T_SCOPE_SIZE 64
typedef struct {
pthread_spinlock_t lock;
@@ -285,9 +285,10 @@ T_thread_name(const Thread_Control *th, char *buf)
#endif
static const char *
-T_scope(char *buf)
+T_scope(T_context *ctx, char *buf)
{
const char *r;
+ const T_case_context *tc;
#if defined(__rtems__)
ISR_Level level;
@@ -326,6 +327,20 @@ T_scope(char *buf)
r = buf;
#endif
+ tc = ctx->current_case;
+ if (tc != NULL) {
+ const T_fixture *fixture;
+
+ fixture = tc->fixture;
+ if (fixture != NULL && fixture->scope != NULL) {
+ size_t n;
+
+ n = strlen(r);
+ (*fixture->scope)(ctx->fixture_context, buf + n,
+ T_SCOPE_SIZE - n);
+ }
+ }
+
return r;
}
@@ -522,7 +537,7 @@ T_check_true(bool ok, const T_check_context *t, const char *fmt, ...)
step != T_CHECK_STEP_FROM_FLAGS(t->flags)) {
T_add_failure(ctx);
T_printf("F:%u:%i:%s:%s:%i:planned step (%u)\n", step,
- T_cpu(), T_scope(scope), T_file(t), t->line,
+ T_cpu(), T_scope(ctx, scope), T_file(t), t->line,
T_CHECK_STEP_FROM_FLAGS(t->flags));
} else if (!ok) {
T_add_failure(ctx);
@@ -530,11 +545,12 @@ T_check_true(bool ok, const T_check_context *t, const char *fmt, ...)
if (ctx->verbosity >= T_NORMAL) {
if ((t->flags & T_CHECK_QUIET) == 0) {
T_printf("F:%u:%i:%s:%s:%i:",
- step, T_cpu(), T_scope(scope),
+ step, T_cpu(), T_scope(ctx, scope),
T_file(t), t->line);
} else {
T_printf("F:*:%i:%s:%s:%i:", T_cpu(),
- T_scope(scope), T_file(t), t->line);
+ T_scope(ctx, scope), T_file(t),
+ t->line);
}
va_start(ap, fmt);
@@ -550,12 +566,12 @@ T_check_true(bool ok, const T_check_context *t, const char *fmt, ...)
} else if ((t->flags & T_CHECK_QUIET) == 0 &&
ctx->verbosity >= T_VERBOSE) {
T_printf("P:%u:%i:%s:%s:%i\n", step, T_cpu(),
- T_scope(scope), T_file(t), t->line);
+ T_scope(ctx, scope), T_file(t), t->line);
}
} else if (!ok) {
T_add_failure(ctx);
- T_printf("F:*:%i:%s:*:*:", T_cpu(), T_scope(scope));
+ T_printf("F:*:%i:%s:*:*:", T_cpu(), T_scope(ctx, scope));
va_start(ap, fmt);
T_vprintf(fmt, ap);
@@ -802,7 +818,7 @@ T_do_case_end(T_context *ctx, const T_case_context *tc)
T_printf("F:*:%i:%s:*:*:actual steps (%u), "
"planned steps (%u)\n", T_cpu(),
- T_scope(scope), steps, planned_steps);
+ T_scope(ctx, scope), steps, planned_steps);
}
}
diff --git a/testsuites/libtests/ttest01/init.c b/testsuites/libtests/ttest01/init.c
index a30211317e..1763a21616 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:342:N:1316:F:791:D:0.687999\n"
-"Y:ReportHash:SHA256:d4c293b499e6e557afcf6123cb604e8976cc5b987021f1f8c9f6193fc38a386e\n";
+"Y:ReportHash:SHA256:efd7b69ac3ec0cac31fa147008bba87a077e6d53c0cfb8a836a4de2ae90ecc27\n";
static void
run_finalize(void)
diff --git a/testsuites/libtests/ttest01/test-fixture.c b/testsuites/libtests/ttest01/test-fixture.c
index 60c3be1afb..c3515c320a 100644
--- a/testsuites/libtests/ttest01/test-fixture.c
+++ b/testsuites/libtests/ttest01/test-fixture.c
@@ -43,10 +43,18 @@ teardown(void *ctx)
T_log(T_QUIET, "teardown end");
}
+static void
+scope(void *ctx, char *buf, size_t n)
+{
+
+ strlcpy(buf, "/More", n);
+}
+
static const T_fixture fixture = {
.setup = setup,
.stop = stop,
.teardown = teardown,
+ .scope = scope,
.initial_context = &initial_value
};
@@ -62,18 +70,18 @@ T_TEST_CASE_FIXTURE(fixture, &fixture)
T_TEST_OUTPUT(fixture,
"B:fixture\n"
"L:setup begin\n"
-"P:0:0:UI1:test-fixture.c:13\n"
-"P:1:0:UI1:test-fixture.c:14\n"
-"P:2:0:UI1:test-fixture.c:18\n"
+"P:0:0:UI1/More:test-fixture.c:13\n"
+"P:1:0:UI1/More:test-fixture.c:14\n"
+"P:2:0:UI1/More:test-fixture.c:18\n"
"L:setup end\n"
-"P:3:0:UI1:test-fixture.c:55\n"
-"F:4:0:UI1:test-fixture.c:56:test fails and we stop the test case\n"
+"P:3:0:UI1/More:test-fixture.c:63\n"
+"F:4:0:UI1/More:test-fixture.c:64:test fails and we stop the test case\n"
"L:stop begin\n"
-"P:5:0:UI1:test-fixture.c:28\n"
+"P:5:0:UI1/More:test-fixture.c:28\n"
"L:stop end\n"
"L:teardown begin\n"
-"P:6:0:UI1:test-fixture.c:40\n"
-"P:7:0:UI1:test-fixture.c:42\n"
+"P:6:0:UI1/More:test-fixture.c:40\n"
+"P:7:0:UI1/More:test-fixture.c:42\n"
"L:teardown end\n"
"E:fixture:N:8:F:1:D:0.001000\n");