[PATCH] rtems: Add rtems_clock_get_ticks_since_boot() function
Sebastian Huber
sebastian.huber at embedded-brains.de
Thu Sep 22 11:23:12 UTC 2022
This function was declared, however, a definition was missing. Add a
validation test for it.
---
cpukit/rtems/src/clockgettickssinceboot.c | 53 ++++++++++++++++
spec/build/cpukit/librtemscpu.yml | 1 +
testsuites/validation/tc-clock.c | 75 ++++++++++++++++++-----
3 files changed, 115 insertions(+), 14 deletions(-)
create mode 100644 cpukit/rtems/src/clockgettickssinceboot.c
diff --git a/cpukit/rtems/src/clockgettickssinceboot.c b/cpukit/rtems/src/clockgettickssinceboot.c
new file mode 100644
index 0000000000..273eeaec0d
--- /dev/null
+++ b/cpukit/rtems/src/clockgettickssinceboot.c
@@ -0,0 +1,53 @@
+/* SPDX-License-Identifier: BSD-2-Clause */
+
+/**
+ * @file
+ *
+ * @ingroup RTEMSImplClassicClock
+ *
+ * @brief This source file contains the implementation of
+ * rtems_clock_get_ticks_since_boot().
+ */
+
+/*
+ * Copyright (C) 2022 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/rtems/clock.h>
+
+static rtems_interval _RTEMS_Clock_get_ticks_since_boot( void )
+{
+ return rtems_clock_get_ticks_since_boot();
+}
+
+#undef rtems_clock_get_ticks_since_boot
+
+rtems_interval rtems_clock_get_ticks_since_boot( void )
+{
+ return _RTEMS_Clock_get_ticks_since_boot();
+}
diff --git a/spec/build/cpukit/librtemscpu.yml b/spec/build/cpukit/librtemscpu.yml
index a62e1b00aa..f034f3fadf 100644
--- a/spec/build/cpukit/librtemscpu.yml
+++ b/spec/build/cpukit/librtemscpu.yml
@@ -1184,6 +1184,7 @@ source:
- cpukit/rtems/src/barrierrelease.c
- cpukit/rtems/src/barrierwait.c
- cpukit/rtems/src/clockgetsecondssinceepoch.c
+- cpukit/rtems/src/clockgettickssinceboot.c
- cpukit/rtems/src/clockgettickspersecond.c
- cpukit/rtems/src/clockgettod.c
- cpukit/rtems/src/clockgettodtimeval.c
diff --git a/testsuites/validation/tc-clock.c b/testsuites/validation/tc-clock.c
index b0592c2b26..5ff8b24ca4 100644
--- a/testsuites/validation/tc-clock.c
+++ b/testsuites/validation/tc-clock.c
@@ -7,7 +7,7 @@
*/
/*
- * Copyright (C) 2021 embedded brains GmbH (http://www.embedded-brains.de)
+ * Copyright (C) 2021, 2022 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
@@ -68,11 +68,22 @@
*
* This test case performs the following actions:
*
- * - Use the rtems_clock_get_ticks_since_boot() function.
+ * - Use the rtems_clock_get_ticks_since_boot() directive before and after
+ * exactly one clock tick.
*
* - Check that clock tick gets incremented.
*
- * - Use the rtems_clock_get_ticks_per_second() function.
+ * - Use the rtems_clock_get_ticks_since_boot() directive before and after
+ * exactly one clock tick.
+ *
+ * - Check that clock tick gets incremented.
+ *
+ * - Use the rtems_clock_get_ticks_per_second() directive.
+ *
+ * - Check that rtems_clock_get_ticks_per_second() actually returns 1us /
+ * CONFIGURE_MICROSECONDS_PER_TICK.
+ *
+ * - Use the rtems_clock_get_ticks_per_second() directive.
*
* - Check that rtems_clock_get_ticks_per_second() actually returns 1us /
* CONFIGURE_MICROSECONDS_PER_TICK.
@@ -81,43 +92,77 @@
*/
/**
- * @brief Use the rtems_clock_get_ticks_since_boot() function.
+ * @brief Use the rtems_clock_get_ticks_since_boot() directive before and after
+ * exactly one clock tick.
*/
static void RtemsClockValClock_Action_0( void )
{
rtems_interval result_0;
rtems_interval result_1;
- int32_t difference; /* Note: rtems_interval = uint32_t (unsigned!) */
result_0 = rtems_clock_get_ticks_since_boot();
ClockTick();
result_1 = rtems_clock_get_ticks_since_boot();
+
/*
- * Because of the ones-complement, the overflow
- * is handled correctly. result_0 = 0xFFFFFFFF will become -1
- * and result_1 = 0x0 will become 0.
+ * Check that clock tick gets incremented.
*/
- difference = (int32_t) result_1 - (int32_t) result_0;
+ T_step_eq_u32( 0, result_1 - result_0, 1 );
+}
+
+/**
+ * @brief Use the rtems_clock_get_ticks_since_boot() directive before and after
+ * exactly one clock tick.
+ */
+static void RtemsClockValClock_Action_1( void )
+{
+ rtems_interval result_0;
+ rtems_interval result_1;
+
+ #undef rtems_clock_get_ticks_since_boot
+
+ result_0 = rtems_clock_get_ticks_since_boot();
+ ClockTick();
+ result_1 = rtems_clock_get_ticks_since_boot();
/*
* Check that clock tick gets incremented.
*/
- T_step_eq_i32( 0, difference, 1 );
+ T_step_eq_u32( 1, result_1 - result_0, 1 );
}
/**
- * @brief Use the rtems_clock_get_ticks_per_second() function.
+ * @brief Use the rtems_clock_get_ticks_per_second() directive.
*/
-static void RtemsClockValClock_Action_1( void )
+static void RtemsClockValClock_Action_2( void )
{
rtems_interval result;
+
+ result = rtems_clock_get_ticks_per_second();
+
+ /*
+ * Check that rtems_clock_get_ticks_per_second() actually returns 1us /
+ * CONFIGURE_MICROSECONDS_PER_TICK.
+ */
+ T_step_eq_u32( 2, result, 1000000UL / TEST_MICROSECONDS_PER_TICK );
+}
+
+/**
+ * @brief Use the rtems_clock_get_ticks_per_second() directive.
+ */
+static void RtemsClockValClock_Action_3( void )
+{
+ rtems_interval result;
+
+ #undef rtems_clock_get_ticks_per_second
+
result = rtems_clock_get_ticks_per_second();
/*
* Check that rtems_clock_get_ticks_per_second() actually returns 1us /
* CONFIGURE_MICROSECONDS_PER_TICK.
*/
- T_step_eq_u32( 1, result, 1000000UL / TEST_MICROSECONDS_PER_TICK );
+ T_step_eq_u32( 3, result, 1000000UL / TEST_MICROSECONDS_PER_TICK );
}
/**
@@ -125,10 +170,12 @@ static void RtemsClockValClock_Action_1( void )
*/
T_TEST_CASE( RtemsClockValClock )
{
- T_plan( 2 );
+ T_plan( 4 );
RtemsClockValClock_Action_0();
RtemsClockValClock_Action_1();
+ RtemsClockValClock_Action_2();
+ RtemsClockValClock_Action_3();
}
/** @} */
--
2.35.3
More information about the devel
mailing list