[rtems commit] libtest: Allow assert checks during test begin

Sebastian Huber sebh at rtems.org
Thu Nov 19 07:39:21 UTC 2020


Module:    rtems
Branch:    master
Commit:    78baeb757957fa0807c30e6c4d21ae99c9639e6a
Changeset: http://git.rtems.org/rtems/commit/?id=78baeb757957fa0807c30e6c4d21ae99c9639e6a

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Wed Nov 11 17:09:58 2020 +0100

libtest: Allow assert checks during test begin

Allow assert checks in test begin actions and setup fixture methods.

---

 cpukit/include/rtems/test.h |  2 +-
 cpukit/libtest/t-test.c     | 29 +++++++++++++++++------------
 2 files changed, 18 insertions(+), 13 deletions(-)

diff --git a/cpukit/include/rtems/test.h b/cpukit/include/rtems/test.h
index 509c7d0..573f7b9 100644
--- a/cpukit/include/rtems/test.h
+++ b/cpukit/include/rtems/test.h
@@ -2306,7 +2306,7 @@ void T_run_all(void);
 
 void T_run_by_name(const char *);
 
-void T_case_begin(const char *, const T_fixture *);
+bool T_case_begin(const char *, const T_fixture *);
 
 void T_case_end(void);
 
diff --git a/cpukit/libtest/t-test.c b/cpukit/libtest/t-test.c
index 2e27e3c..ca91d15 100644
--- a/cpukit/libtest/t-test.c
+++ b/cpukit/libtest/t-test.c
@@ -948,7 +948,7 @@ T_do_run_initialize(const T_config *config)
 	return ctx;
 }
 
-static void
+static bool
 T_do_case_begin(T_context *ctx, const T_case_context *tc)
 {
 	const T_config *config;
@@ -969,16 +969,23 @@ T_do_case_begin(T_context *ctx, const T_case_context *tc)
 	T_actions_forward(config, T_EVENT_CASE_EARLY, tc->name);
 	T_do_log(ctx, T_NORMAL, "B:%s\n", tc->name);
 	ctx->case_begin_time = (*config->now)();
-	T_actions_forward(config, T_EVENT_CASE_BEGIN, tc->name);
 
-	if (fixture != NULL) {
-		ctx->case_fixture.fixture = fixture;
-		ctx->case_fixture.context = fixture->initial_context;
+	if (setjmp(ctx->case_begin_context) == 0) {
+		T_actions_forward(config, T_EVENT_CASE_BEGIN, tc->name);
+
+		if (fixture != NULL) {
+			ctx->case_fixture.fixture = fixture;
+			ctx->case_fixture.context = fixture->initial_context;
 
-		if (fixture->setup != NULL) {
-			(*fixture->setup)(ctx->case_fixture.context);
+			if (fixture->setup != NULL) {
+				(*fixture->setup)(ctx->case_fixture.context);
+			}
 		}
+
+		return true;
 	}
+
+	return false;
 }
 
 static void
@@ -1034,9 +1041,7 @@ T_do_case_end(T_context *ctx, const T_case_context *tc)
 static void
 T_run_case(T_context *ctx, const T_case_context *tc)
 {
-	T_do_case_begin(ctx, tc);
-
-	if (setjmp(ctx->case_begin_context) == 0) {
+	if (T_do_case_begin(ctx, tc)) {
 		(*tc->body)();
 	}
 
@@ -1140,7 +1145,7 @@ T_run_by_name(const char *name)
 
 static T_case_context default_case;
 
-void
+bool
 T_case_begin(const char *name, const T_fixture *fixture)
 {
 	T_case_context *tc;
@@ -1148,7 +1153,7 @@ T_case_begin(const char *name, const T_fixture *fixture)
 	tc = &default_case;
 	tc->name = name;
 	tc->fixture = fixture;
-	T_do_case_begin(&T_instance, tc);
+	return T_do_case_begin(&T_instance, tc);
 }
 
 void



More information about the vc mailing list