[rtems commit] libtest: Add T_busy()

Sebastian Huber sebh at rtems.org
Thu Jul 23 08:57:41 UTC 2020


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

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Fri Jul 17 14:40:36 2020 +0200

libtest: Add T_busy()

Update #3199.

---

 cpukit/Makefile.am                                 |  1 +
 cpukit/include/rtems/test-info.h                   | 12 +----
 cpukit/include/rtems/test.h                        |  4 +-
 cpukit/libtest/t-test-busy.c                       | 58 ++++++++++++++++++++++
 cpukit/libtest/testbusy.c                          | 20 ++------
 .../sptests/spintrcritical_support/intrcritical.c  |  3 +-
 6 files changed, 68 insertions(+), 30 deletions(-)

diff --git a/cpukit/Makefile.am b/cpukit/Makefile.am
index abf18d1..7f89f6a 100644
--- a/cpukit/Makefile.am
+++ b/cpukit/Makefile.am
@@ -1857,6 +1857,7 @@ librtemstest_a_SOURCES += libtest/testextension.c
 librtemstest_a_SOURCES += libtest/testparallel.c
 librtemstest_a_SOURCES += libtest/testwrappers.c
 librtemstest_a_SOURCES += libtest/t-test.c
+librtemstest_a_SOURCES += libtest/t-test-busy.c
 librtemstest_a_SOURCES += libtest/t-test-checks.c
 librtemstest_a_SOURCES += libtest/t-test-checks-eno.c
 librtemstest_a_SOURCES += libtest/t-test-checks-psx.c
diff --git a/cpukit/include/rtems/test-info.h b/cpukit/include/rtems/test-info.h
index 873b848..5f73e92 100644
--- a/cpukit/include/rtems/test-info.h
+++ b/cpukit/include/rtems/test-info.h
@@ -305,17 +305,7 @@ void rtems_test_parallel(
 void rtems_test_busy_cpu_usage(time_t seconds, long nanoseconds);
 
 /**
- * @brief Performs a busy loop with the specified iteration count.
- *
- * This function is optimized to not perform memory accesses and should have a
- * small jitter.
- *
- * @param[in] count The iteration count.
- */
-void rtems_test_busy(uint_fast32_t count);
-
-/**
- * @brief Returns a count value for rtems_test_busy() which yields roughly a
+ * @brief Returns a count value for T_busy() which yields roughly a
  * duration of one clock tick.
  */
 uint_fast32_t rtems_test_get_one_tick_busy_count(void);
diff --git a/cpukit/include/rtems/test.h b/cpukit/include/rtems/test.h
index ecdc03f..4c14e8d 100644
--- a/cpukit/include/rtems/test.h
+++ b/cpukit/include/rtems/test.h
@@ -1,7 +1,7 @@
 /*
  * SPDX-License-Identifier: BSD-2-Clause
  *
- * Copyright (C) 2018, 2019 embedded brains GmbH
+ * Copyright (C) 2017, 2020 embedded brains GmbH
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -2261,6 +2261,8 @@ void T_case_body_##name(void)
 
 #define T_TEST_CASE(name) T_TEST_CASE_FIXTURE(name, NULL)
 
+void T_busy(uint_fast32_t);
+
 void T_report_hash_sha256(T_event, const char *);
 
 void T_check_heap(T_event, const char *);
diff --git a/cpukit/libtest/t-test-busy.c b/cpukit/libtest/t-test-busy.c
new file mode 100644
index 0000000..3bf149b
--- /dev/null
+++ b/cpukit/libtest/t-test-busy.c
@@ -0,0 +1,58 @@
+/* SPDX-License-Identifier: BSD-2-Clause */
+
+/**
+ * @file
+ *
+ * @ingroup RTEMSTestFrameworkImpl
+ *
+ * @brief Implementation of T_busy().
+ */
+
+/*
+ * Copyright (C) 2014, 2020 embedded brains GmbH (http://www.embedded-brains.de)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/test.h>
+
+/*
+ * It is important that we actually use the same T_busy() function at the
+ * various places.  So, the compiler must not inline this function.  Take care
+ * of link time optimization.
+ */
+__attribute__((__noinline__)) void
+T_busy(uint_fast32_t count)
+{
+	uint_fast32_t i;
+
+	i = 0;
+
+	do {
+		__asm__ volatile ("");
+		++i;
+	} while (i < count);
+}
diff --git a/cpukit/libtest/testbusy.c b/cpukit/libtest/testbusy.c
index e5218b0..bf11b11 100644
--- a/cpukit/libtest/testbusy.c
+++ b/cpukit/libtest/testbusy.c
@@ -19,6 +19,7 @@
 
 #include <rtems/test-info.h>
 #include <rtems.h>
+#include <rtems/test.h>
 #include <rtems/score/threadimpl.h>
 
 static uint_fast32_t estimate_busy_loop_maximum( void )
@@ -45,21 +46,6 @@ static uint_fast32_t wait_for_tick_change( void )
   return now;
 }
 
-/*
- * It is important that we use actually use the same rtems_test_busy() function
- * at the various places, since otherwise the obtained maximum value might be
- * wrong.  So, the compiler must not inline this function.
- */
-RTEMS_NO_INLINE void rtems_test_busy( uint_fast32_t count )
-{
-  uint_fast32_t i = 0;
-
-  do {
-    __asm__ volatile ("");
-    ++i;
-  } while ( i < count );
-}
-
 uint_fast32_t rtems_test_get_one_tick_busy_count( void )
 {
   uint_fast32_t last;
@@ -78,7 +64,7 @@ uint_fast32_t rtems_test_get_one_tick_busy_count( void )
 
   while ( true ) {
     last = wait_for_tick_change();
-    rtems_test_busy( b );
+    T_busy( b );
     now = rtems_clock_get_ticks_since_boot();
 
     if ( now != last ) {
@@ -94,7 +80,7 @@ uint_fast32_t rtems_test_get_one_tick_busy_count( void )
     m = ( a + b ) / 2;
 
     last = wait_for_tick_change();
-    rtems_test_busy( m );
+    T_busy( m );
     now = rtems_clock_get_ticks_since_boot();
 
     if ( now != last ) {
diff --git a/testsuites/sptests/spintrcritical_support/intrcritical.c b/testsuites/sptests/spintrcritical_support/intrcritical.c
index 51ab42f..9bce230 100644
--- a/testsuites/sptests/spintrcritical_support/intrcritical.c
+++ b/testsuites/sptests/spintrcritical_support/intrcritical.c
@@ -13,6 +13,7 @@
 
 #include <tmacros.h>
 #include <intrcritical.h>
+#include <rtems/test.h>
 
 #define INTERRUPT_CRITICAL_NAME rtems_build_name( 'I', 'C', 'R', 'I' )
 
@@ -49,7 +50,7 @@ static bool interrupt_critical_busy_wait( void )
     interrupt_critical.maximum_current = max - 1;
   }
 
-  rtems_test_busy( max );
+  T_busy( max );
 
   return reset;
 }



More information about the vc mailing list