[PATCH] tests: Use rtems_test_begin and rtems_test_end.

Chris Johns chrisj at rtems.org
Tue Nov 7 21:27:24 UTC 2017


Add a tests enum and move all test banner test to the library in libmisc.

Update #3199.
---
 cpukit/libmisc/testsupport/test.h           | 39 +++++++++---
 cpukit/libmisc/testsupport/testbeginend.c   | 94 +++++++++++++++++++++++++++--
 testsuites/samples/cdtest/main.cc           |  4 +-
 testsuites/sptests/sp20/init.c              |  4 +-
 testsuites/support/include/buffer_test_io.h | 45 +-------------
 5 files changed, 126 insertions(+), 60 deletions(-)

diff --git a/cpukit/libmisc/testsupport/test.h b/cpukit/libmisc/testsupport/test.h
index d9ac6caf91..116b92d1ae 100644
--- a/cpukit/libmisc/testsupport/test.h
+++ b/cpukit/libmisc/testsupport/test.h
@@ -58,28 +58,51 @@ void rtems_test_fatal_extension(
   { NULL, NULL, NULL, NULL, NULL, NULL, NULL, rtems_test_fatal_extension }
 
 /**
- * @brief Begin of test message format string.
+ * @brief Test states.
  */
-#define TEST_BEGIN_STRING "\n\n*** BEGIN OF TEST %s ***\n", rtems_test_name
+typedef enum
+{
+  RTEMS_TEST_STATE_PASS,
+  RTEMS_TEST_STATE_FAIL,
+  RTEMS_TEST_STATE_USER_INPUT,
+  RTEMS_TEST_STATE_INDETERMINATE,
+  RTEMS_TEST_STATE_BENCHMARK
+} RTEMS_TEST_STATE;
 
-/**
- * @brief End of test message format string.
- */
-#define TEST_END_STRING "*** END OF TEST %s ***\n", rtems_test_name
+#if (TEST_STATE_EXPECTED_FAIL && TEST_STATE_USER_INPUT) || \
+    (TEST_STATE_EXPECTED_FAIL && TEST_STATE_INDETERMINATE) || \
+    (TEST_STATE_EXPECTED_FAIL && TEST_STATE_BENCHMARK) || \
+    (TEST_STATE_USER_INPUT    && TEST_STATE_INDETERMINATE) || \
+    (TEST_STATE_USER_INPUT    && TEST_STATE_BENCHMARK) || \
+    (TEST_STATE_INDETERMINATE && TEST_STATE_BENCHMARK)
+  #error Test states must be unique
+#endif
+
+#if TEST_STATE_EXPECTED_FAIL
+  #define TEST_STATE RTEMS_TEST_STATE_FAIL
+#elif TEST_STATE_USER_INPUT
+  #define TEST_STATE RTEMS_TEST_STATE_USER_INPUT
+#elif TEST_STATE_INDETERMINATE
+  #define TEST_STATE RTEMS_TEST_STATE_INDETERMINATE
+#elif TEST_STATE_BENCHMARK
+  #define TEST_STATE RTEMS_TEST_STATE_BENCHMARK
+#else
+  #define TEST_STATE RTEMS_TEST_STATE_PASS
+#endif
 
 /**
  * @brief Prints a begin of test message using printf().
  *
  * @returns As specified by printf().
  */
-int rtems_test_begin(void);
+int rtems_test_begin(const char* name, const RTEMS_TEST_STATE state);
 
 /**
  * @brief Prints an end of test message using printf().
  *
  * @returns As specified by printf().
  */
-int rtems_test_end(void);
+int rtems_test_end(const char* name);
 
 /**
  * @brief Prints via the RTEMS printer.
diff --git a/cpukit/libmisc/testsupport/testbeginend.c b/cpukit/libmisc/testsupport/testbeginend.c
index ff64851c02..04748cb796 100644
--- a/cpukit/libmisc/testsupport/testbeginend.c
+++ b/cpukit/libmisc/testsupport/testbeginend.c
@@ -7,6 +7,8 @@
  *  Germany
  *  <rtems at embedded-brains.de>
  *
+ * Copyright (c) 2017 Chris Johns <chrisj at rtems.org>. All rights reserved.
+ *
  * The license and distribution terms for this file may be
  * found in the file LICENSE in this distribution or at
  * http://www.rtems.org/license/LICENSE.
@@ -18,24 +20,106 @@
 
 #include <rtems/test.h>
 #include <rtems/bspIo.h>
+#include <rtems/version.h>
+
+#define TEST_BUILD_DEFAULT "default"
+#if RTEMS_POSIX
+  #define TEST_BUILD_DEFAULT ""
+  #define TEST_BUILD_POSIX   "posix "
+#else
+  #define TEST_BUILD_POSIX
+#endif
+#if RTEMS_SMP
+  #define TEST_BUILD_DEFAULT ""
+  #define TEST_BUILD_SMP     "smp "
+#else
+  #define TEST_BUILD_SMP
+#endif
+#if RTEMS_MULTIPROCESSING
+  #define TEST_BUILD_DEFAULT ""
+  #define TEST_BUILD_MP      "mp "
+#else
+  #define TEST_BUILD_MP
+#endif
+#if RTEMS_PARAVIRT
+  #define TEST_BUILD_DEFAULT  ""
+  #define TEST_BUILD_PARAVIRT "paravirt "
+#else
+  #define TEST_BUILD_PARAVIRT
+#endif
+#if RTEMS_NETWORKING
+  #define TEST_BUILD_DEFAULT    ""
+  #define TEST_BUILD_NETWORKING "legacy-net "
+#else
+  #define TEST_BUILD_NETWORKING
+#endif
+#if RTEMS_DEBUG
+  #define TEST_BUILD_DEFAULT ""
+  #define TEST_BUILD_DEBUG   "debug "
+#else
+  #define TEST_BUILD_DEBUG
+#endif
+#if RTEMS_PROFILING
+  #define TEST_BUILD_DEFAULT   ""
+  #define TEST_BUILD_PROFILING "profiling "
+#else
+  #define TEST_BUILD_PROFILING
+#endif
+
+#define TEST_BUILD_STRING \
+         TEST_BUILD_DEFAULT \
+         TEST_BUILD_POSIX \
+         TEST_BUILD_SMP \
+         TEST_BUILD_MP \
+         TEST_BUILD_PARAVIRT \
+         TEST_BUILD_NETWORKING \
+         TEST_BUILD_DEBUG \
+         TEST_BUILD_PROFILING
 
 rtems_printer rtems_test_printer = {
   .printer = rtems_printk_printer
 };
 
-int rtems_test_begin(void)
+static const char* const test_state_strings[] =
 {
-  return rtems_printf(
+  "EXPECTED-PASS",
+  "EXPECTED-FAIL",
+  "USER_INPUT",
+  "INDETERMINATE",
+  "BENCHMARK"
+};
+
+int rtems_test_begin(const char* name, const RTEMS_TEST_STATE state)
+{
+  int l;
+  l = rtems_printf(
+    &rtems_test_printer,
+    "\n\n*** BEGIN OF TEST %s ***\n", name
+  );
+  l += rtems_printf(
+    &rtems_test_printer,
+    "*** TEST VERSION: %s\n", rtems_version()
+  );
+  l += rtems_printf(
+    &rtems_test_printer,
+    "*** TEST STATE: %s\n", test_state_strings[state]
+  );
+  l += rtems_printf(
+    &rtems_test_printer,
+    "*** TEST BUILD: %s\n", TEST_BUILD_STRING
+  );
+  l += rtems_printf(
     &rtems_test_printer,
-    TEST_BEGIN_STRING
+    "*** TEST TOOLS: " __VERSION__ "\n"
   );
+  return l;
 }
 
-int rtems_test_end(void)
+int rtems_test_end(const char* name)
 {
   return rtems_printf(
     &rtems_test_printer,
-    TEST_END_STRING
+    "\n*** END OF TEST %s ***\n\n", name
   );
 }
 
diff --git a/testsuites/samples/cdtest/main.cc b/testsuites/samples/cdtest/main.cc
index 33e6fd2edd..7aeb884354 100644
--- a/testsuites/samples/cdtest/main.cc
+++ b/testsuites/samples/cdtest/main.cc
@@ -47,14 +47,14 @@ static int num_inst = 0;
 static void check_begin_of_test(void)
 {
   if ( num_inst == 0 ) {
-    printf(TEST_BEGIN_STRING);
+    TEST_BEGIN();
   }
 }
 
 static void check_end_of_test(void)
 {
   if ( num_inst == 0 ) {
-    printk(TEST_END_STRING);
+    TEST_END();
   }
 }
 
diff --git a/testsuites/sptests/sp20/init.c b/testsuites/sptests/sp20/init.c
index bf8afc7684..6b63b6a380 100644
--- a/testsuites/sptests/sp20/init.c
+++ b/testsuites/sptests/sp20/init.c
@@ -38,7 +38,7 @@ static long buffers[ BUFFER_COUNT ][ BUFFER_SIZE / sizeof(long) ];
 
 void end_of_test( void )
 {
-  rtems_test_printf( TEST_END_STRING );
+  TEST_END();
   rtems_printer_task_drain( &printer_task );
   rtems_test_exit( 0 );
 }
@@ -59,7 +59,7 @@ rtems_task Init(
   error = rtems_print_printer_task( &rtems_test_printer, &printer_task );
   rtems_test_assert( error == 0 );
 
-  rtems_test_printf( TEST_BEGIN_STRING );
+  TEST_BEGIN();
 
   Task_name[ 1 ] =  rtems_build_name( 'T', 'A', '1', ' ' );
   Task_name[ 2 ] =  rtems_build_name( 'T', 'A', '2', ' ' );
diff --git a/testsuites/support/include/buffer_test_io.h b/testsuites/support/include/buffer_test_io.h
index 1ff15f6ca8..8fbcd68b3e 100644
--- a/testsuites/support/include/buffer_test_io.h
+++ b/testsuites/support/include/buffer_test_io.h
@@ -11,28 +11,6 @@
 extern "C" {
 #endif
 
-/*
- * Test states. No state string is an expected pass.
- */
-#if (TEST_STATE_EXPECTED_FAIL && TEST_STATE_USER_INPUT) || \
-    (TEST_STATE_EXPECTED_FAIL && TEST_STATE_INDETERMINATE) || \
-    (TEST_STATE_EXPECTED_FAIL && TEST_STATE_BENCHMARK) || \
-    (TEST_STATE_USER_INPUT    && TEST_STATE_INDETERMINATE) || \
-    (TEST_STATE_USER_INPUT    && TEST_STATE_BENCHMARK) || \
-    (TEST_STATE_INDETERMINATE && TEST_STATE_BENCHMARK)
-  #error Test states must be unique
-#endif
-
-#if TEST_STATE_EXPECTED_FAIL
-  #define TEST_STATE_STRING "*** TEST STATE: EXPECTED-FAIL\n"
-#elif TEST_STATE_USER_INPUT
-  #define TEST_STATE_STRING "*** TEST STATE: USER_INPUT\n"
-#elif TEST_STATE_INDETERMINATE
-  #define TEST_STATE_STRING "*** TEST STATE: INDETERMINATE\n"
-#elif TEST_STATE_BENCHMARK
-  #define TEST_STATE_STRING "*** TEST STATE: BENCHMARK\n"
-#endif
-
 #undef printf
 #define printf(...) \
   do { \
@@ -61,27 +39,8 @@ extern "C" {
   do { \
   } while (0)
 
-#if defined(TEST_STATE_STRING)
-  #define TEST_BEGIN() \
-  do { \
-    rtems_printf( &rtems_test_printer, "\n"); \
-    rtems_printf( &rtems_test_printer, TEST_BEGIN_STRING ); \
-    rtems_printf( &rtems_test_printer, TEST_STATE_STRING ); \
-  } while (0)
-#else
-  #define TEST_BEGIN() \
-  do { \
-    rtems_printf( &rtems_test_printer, "\n" ); \
-    rtems_printf( &rtems_test_printer, TEST_BEGIN_STRING ); \
-  } while (0)
-#endif
-
-#define TEST_END() \
-  do { \
-     rtems_printf( &rtems_test_printer, "\n" ); \
-     rtems_printf( &rtems_test_printer, TEST_END_STRING ); \
-     rtems_printf( &rtems_test_printer, "\n" ); \
-  } while (0)
+#define TEST_BEGIN() rtems_test_begin(rtems_test_name, TEST_STATE)
+#define TEST_END()   rtems_test_end(rtems_test_name)
 
 #ifdef __cplusplus
 };
-- 
2.13.2



More information about the devel mailing list