[rtems commit] libtest: Make check message optional
Sebastian Huber
sebh at rtems.org
Thu Jul 23 08:57:41 UTC 2020
Module: rtems
Branch: master
Commit: d702c9f47d8b9b393316e0c6b54fca8c26f424a1
Changeset: http://git.rtems.org/rtems/commit/?id=d702c9f47d8b9b393316e0c6b54fca8c26f424a1
Author: Sebastian Huber <sebastian.huber at embedded-brains.de>
Date: Sat Jul 18 14:41:36 2020 +0200
libtest: Make check message optional
This macro magic is in line with C11 and C++11, but limits the maximum
count of arguments.
Update #3199.
---
cpukit/include/rtems/test.h | 107 ++++++++++++++++++++----------
testsuites/libtests/ttest01/init.c | 4 +-
testsuites/libtests/ttest01/test-checks.c | 23 +++++++
3 files changed, 97 insertions(+), 37 deletions(-)
diff --git a/cpukit/include/rtems/test.h b/cpukit/include/rtems/test.h
index c0227b5..d14bb9f 100644
--- a/cpukit/include/rtems/test.h
+++ b/cpukit/include/rtems/test.h
@@ -114,6 +114,7 @@ void T_case_register(T_case_context *);
#define T_CHECK_QUIET 2U
+/* If you change this value, you have to adjust T_VA_ARGS_KIND() as well */
#define T_CHECK_FMT 4U
#define T_CHECK_STEP_FLAG 8U
@@ -135,22 +136,46 @@ typedef struct {
const char *msg;
} T_check_context_msg;
+#define T_VA_ARGS_FIRST(...) T_VA_ARGS_FIRST_SELECT(__VA_ARGS__, throw_away)
+#define T_VA_ARGS_FIRST_SELECT(first, ...) first
+
+/*
+ * The T_VA_ARGS_MORE() supports up to nine arguments. It expands to nothing
+ * if only one argument is given. It expands to a comma and the second and
+ * following arguments if at least two arguments are present. The 4U shall
+ * correspond to T_CHECK_FMT.
+ */
+#define T_VA_ARGS_MORE(...) \
+ T_VA_ARGS_XEXPAND(T_VA_ARGS_KIND(__VA_ARGS__), __VA_ARGS__)
+#define T_VA_ARGS_XEXPAND(kind, ...) T_VA_ARGS_EXPAND(kind, __VA_ARGS__)
+#define T_VA_ARGS_EXPAND(kind, ...) T_VA_ARGS_EXPAND_##kind(__VA_ARGS__)
+#define T_VA_ARGS_EXPAND_0U(first)
+#define T_VA_ARGS_EXPAND_4U(first, ...) , __VA_ARGS__
+#define T_VA_ARGS_KIND(...) \
+ T_VA_ARGS_SELECT(__VA_ARGS__, \
+ 4U, 4U, 4U, 4U, 4U, 4U, 4U, 4U, 0U, throw_away)
+#define T_VA_ARGS_SELECT(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, ...) a10
+
void T_check(const T_check_context *, bool, ...);
extern const T_check_context T_special;
-#define T_flags_true(a, flags, ...) \
+#define T_flags_true(flags, ...) \
{ \
static const T_check_context T_check_instance = { \
- T_FILE_NAME, __LINE__, (flags) | T_CHECK_FMT }; \
- T_check(&T_check_instance, a, __VA_ARGS__); \
+ T_FILE_NAME, __LINE__, \
+ (flags) | T_VA_ARGS_KIND(__VA_ARGS__) }; \
+ T_check(&T_check_instance, \
+ T_VA_ARGS_FIRST(__VA_ARGS__) T_VA_ARGS_MORE(__VA_ARGS__)); \
}
-#define T_flags_eq(a, e, flags, ...) \
- T_flags_true((a) == (e), flags, __VA_ARGS__)
+#define T_flags_eq(flags, a, ...) \
+ T_flags_true(flags, \
+ (a) == (T_VA_ARGS_FIRST(__VA_ARGS__)) T_VA_ARGS_MORE(__VA_ARGS__))
-#define T_flags_ne(a, e, flags, ...) \
- T_flags_true((a) != (e), flags, __VA_ARGS__)
+#define T_flags_ne(flags, a, ...) \
+ T_flags_true(flags, \
+ (a) != (T_VA_ARGS_FIRST(__VA_ARGS__)) T_VA_ARGS_MORE(__VA_ARGS__))
void T_check_eq_ptr(const T_check_context_msg *, const void *, const void *);
@@ -658,19 +683,28 @@ T_verbosity T_set_verbosity(T_verbosity);
* @{
*/
-#define T_true(a, ...) T_flags_true(a, 0, __VA_ARGS__)
-#define T_assert_true(a, ...) T_flags_true(a, T_CHECK_STOP, __VA_ARGS__)
-#define T_quiet_true(a, ...) T_flags_true(a, T_CHECK_QUIET, __VA_ARGS__)
-#define T_step_true(s, a, ...) T_flags_true(a, T_CHECK_STEP(s), __VA_ARGS__)
-#define T_step_assert_true(s, a, ...) \
- T_flags_true(a, T_CHECK_STEP(s) | T_CHECK_STOP, __VA_ARGS__)
-
-#define T_false(a, ...) T_flags_true(!(a), 0, __VA_ARGS__)
-#define T_assert_false(a, ...) T_flags_true(!(a), T_CHECK_STOP, __VA_ARGS__)
-#define T_quiet_false(a, ...) T_flags_true(!(a), T_CHECK_QUIET, __VA_ARGS__)
-#define T_step_false(s, a, ...) T_flags_true(!(a), T_CHECK_STEP(s), __VA_ARGS__)
-#define T_step_assert_false(s, a, ...) \
- T_flags_true(!(a), T_CHECK_STEP(s) | T_CHECK_STOP, __VA_ARGS__)
+#define T_true(...) T_flags_true(0, __VA_ARGS__)
+#define T_assert_true(...) T_flags_true(T_CHECK_STOP, __VA_ARGS__)
+#define T_quiet_true(...) T_flags_true(T_CHECK_QUIET, __VA_ARGS__)
+#define T_step_true(s, ...) T_flags_true(T_CHECK_STEP(s), __VA_ARGS__)
+#define T_step_assert_true(s, ...) \
+ T_flags_true(T_CHECK_STEP(s) | T_CHECK_STOP, __VA_ARGS__)
+
+#define T_false(...) \
+ T_flags_true(0, \
+ !(T_VA_ARGS_FIRST(__VA_ARGS__)) T_VA_ARGS_MORE(__VA_ARGS__))
+#define T_assert_false(...) \
+ T_flags_true(T_CHECK_STOP, \
+ !(T_VA_ARGS_FIRST(__VA_ARGS__)) T_VA_ARGS_MORE(__VA_ARGS__))
+#define T_quiet_false(...) \
+ T_flags_true(T_CHECK_QUIET, \
+ !(T_VA_ARGS_FIRST(__VA_ARGS__)) T_VA_ARGS_MORE(__VA_ARGS__))
+#define T_step_false(s, ...) \
+ T_flags_true(T_CHECK_STEP(s), \
+ !(T_VA_ARGS_FIRST(__VA_ARGS__)) T_VA_ARGS_MORE(__VA_ARGS__))
+#define T_step_assert_false(s, ...) \
+ T_flags_true(T_CHECK_STEP(s) | T_CHECK_STOP, \
+ !(T_VA_ARGS_FIRST(__VA_ARGS__)) T_VA_ARGS_MORE(__VA_ARGS__))
/** @} */
@@ -684,19 +718,19 @@ T_verbosity T_set_verbosity(T_verbosity);
* @{
*/
-#define T_eq(a, e, ...) T_flags_eq(a, e, 0, __VA_ARGS__)
-#define T_assert_eq(a, e, ...) T_flags_eq(a, e, T_CHECK_STOP, __VA_ARGS__)
-#define T_quiet_eq(a, e, ...) T_flags_eq(a, e, T_CHECK_QUIET, __VA_ARGS__)
-#define T_step_eq(s, a, e, ...) T_flags_eq(a, e, T_CHECK_STEP(s), __VA_ARGS__)
-#define T_step_assert_eq(s, a, e, ...) \
- T_flags_eq(a, e, T_CHECK_STEP(s) | T_CHECK_STOP, __VA_ARGS__)
+#define T_eq(a, ...) T_flags_eq(0, a, __VA_ARGS__)
+#define T_assert_eq(a, ...) T_flags_eq(T_CHECK_STOP, a, __VA_ARGS__)
+#define T_quiet_eq(a, ...) T_flags_eq(T_CHECK_QUIET, a, __VA_ARGS__)
+#define T_step_eq(s, a, ...) T_flags_eq(T_CHECK_STEP(s), a, __VA_ARGS__)
+#define T_step_assert_eq(s, a, ...) \
+ T_flags_eq(T_CHECK_STEP(s) | T_CHECK_STOP, a, __VA_ARGS__)
-#define T_ne(a, e, ...) T_flags_ne(a, e, 0, __VA_ARGS__)
-#define T_assert_ne(a, e, ...) T_flags_ne(a, e, T_CHECK_STOP, __VA_ARGS__)
-#define T_quiet_ne(a, e, ...) T_flags_ne(a, e, T_CHECK_QUIET, __VA_ARGS__)
-#define T_step_ne(s, a, e, ...) T_flags_ne(a, e, T_CHECK_STEP(s), __VA_ARGS__)
-#define T_step_assert_ne(s, a, e, ...) \
- T_flags_ne(a, e, T_CHECK_STEP(s) | T_CHECK_STOP, __VA_ARGS__)
+#define T_ne(a, ...) T_flags_ne(0, a, __VA_ARGS__)
+#define T_assert_ne(a, ...) T_flags_ne(T_CHECK_STOP, a, __VA_ARGS__)
+#define T_quiet_ne(a, ...) T_flags_ne(T_CHECK_QUIET, a, __VA_ARGS__)
+#define T_step_ne(s, a, ...) T_flags_ne(T_CHECK_STEP(s), a, __VA_ARGS__)
+#define T_step_assert_ne(s, a, ...) \
+ T_flags_ne(T_CHECK_STEP(s) | T_CHECK_STOP, a, __VA_ARGS__)
/** @} */
@@ -2117,9 +2151,12 @@ void T_check_rsc_success(const T_check_context *, uint32_t);
void T_plan(unsigned int);
-#define T_step(s, ...) T_flags_true(true, T_CHECK_STEP(s), __VA_ARGS__)
-#define T_step_assert(s, ...) \
- T_flags_true(true, T_CHECK_STEP(s) | T_CHECK_STOP, __VA_ARGS__)
+#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__))
/**
* @defgroup RTEMSTestFrameworkTime Time Services
diff --git a/testsuites/libtests/ttest01/init.c b/testsuites/libtests/ttest01/init.c
index a5df393..35b7023 100644
--- a/testsuites/libtests/ttest01/init.c
+++ b/testsuites/libtests/ttest01/init.c
@@ -182,8 +182,8 @@ run_initialize(void)
T_set_putchar(censor_putchar, ctx, &ctx->putchar, &ctx->putchar_arg);
}
-static const char expected_final[] = "Z:ttest01:C:342:N:1329:F:791:D:0.687999\n"
-"Y:ReportHash:SHA256:e5c3847558c805663117be13ef27fd89579f595148b8515c42a38bd1b9dd79c2\n";
+static const char expected_final[] = "Z:ttest01:C:343:N:1335:F:795:D:0.689999\n"
+"Y:ReportHash:SHA256:f018ab0c9ddf5c5bc0ba8377492dc52205f9b63146c787fb669222e346c65d0f\n";
static void
run_finalize(void)
diff --git a/testsuites/libtests/ttest01/test-checks.c b/testsuites/libtests/ttest01/test-checks.c
index d3ce67e..fa55911 100644
--- a/testsuites/libtests/ttest01/test-checks.c
+++ b/testsuites/libtests/ttest01/test-checks.c
@@ -2880,6 +2880,18 @@ T_TEST_CASE(check_lt_sz)
T_assert_lt_sz((size_t)12, (size_t)12);
}
+T_TEST_CASE(check_false_no_fmt)
+{
+ T_false(false);
+ T_false(true);
+ T_quiet_false(false);
+ T_quiet_false(true);
+ T_step_false(2, false);
+ T_step_false(3, true);
+ T_assert_false(false);
+ T_assert_false(true);
+}
+
#include "t-self-test.h"
T_TEST_OUTPUT(step_assert_true,
@@ -5383,6 +5395,17 @@ T_TEST_OUTPUT(check_lt_sz,
"F:5:0:UI1:test-checks.c:2880:12 < 12\n"
"E:check_lt_sz:N:6:F:4:D:0.001000\n");
+T_TEST_OUTPUT(check_false_no_fmt,
+"B:check_false_no_fmt\n"
+"P:0:0:UI1:test-checks.c:2885\n"
+"F:1:0:UI1:test-checks.c:2886\n"
+"F:*:0:UI1:test-checks.c:2888\n"
+"P:2:0:UI1:test-checks.c:2889\n"
+"F:3:0:UI1:test-checks.c:2890\n"
+"P:4:0:UI1:test-checks.c:2891\n"
+"F:5:0:UI1:test-checks.c:2892\n"
+"E:check_false_no_fmt:N:6:F:4:D:0.001000\n");
+
/*
* The license is at the end of the file to be able to use the test code and
* output in examples in the documentation. This is also the reason for the
More information about the vc
mailing list