1 | /* SPDX-License-Identifier: BSD-2-Clause */ |
---|
2 | |
---|
3 | /** |
---|
4 | * @file |
---|
5 | * |
---|
6 | * @ingroup RTEMSTestCaseRtemsClockValClock |
---|
7 | */ |
---|
8 | |
---|
9 | /* |
---|
10 | * Copyright (C) 2021, 2022 embedded brains GmbH (http://www.embedded-brains.de) |
---|
11 | * |
---|
12 | * Redistribution and use in source and binary forms, with or without |
---|
13 | * modification, are permitted provided that the following conditions |
---|
14 | * are met: |
---|
15 | * 1. Redistributions of source code must retain the above copyright |
---|
16 | * notice, this list of conditions and the following disclaimer. |
---|
17 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
18 | * notice, this list of conditions and the following disclaimer in the |
---|
19 | * documentation and/or other materials provided with the distribution. |
---|
20 | * |
---|
21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
---|
25 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
31 | * POSSIBILITY OF SUCH DAMAGE. |
---|
32 | */ |
---|
33 | |
---|
34 | /* |
---|
35 | * This file is part of the RTEMS quality process and was automatically |
---|
36 | * generated. If you find something that needs to be fixed or |
---|
37 | * worded better please post a report or patch to an RTEMS mailing list |
---|
38 | * or raise a bug report: |
---|
39 | * |
---|
40 | * https://www.rtems.org/bugs.html |
---|
41 | * |
---|
42 | * For information on updating and regenerating please refer to the How-To |
---|
43 | * section in the Software Requirements Engineering chapter of the |
---|
44 | * RTEMS Software Engineering manual. The manual is provided as a part of |
---|
45 | * a release. For development sources please refer to the online |
---|
46 | * documentation at: |
---|
47 | * |
---|
48 | * https://docs.rtems.org |
---|
49 | */ |
---|
50 | |
---|
51 | #ifdef HAVE_CONFIG_H |
---|
52 | #include "config.h" |
---|
53 | #endif |
---|
54 | |
---|
55 | #include <rtems.h> |
---|
56 | |
---|
57 | #include "ts-config.h" |
---|
58 | #include "tx-support.h" |
---|
59 | |
---|
60 | #include <rtems/test.h> |
---|
61 | |
---|
62 | /** |
---|
63 | * @defgroup RTEMSTestCaseRtemsClockValClock spec:/rtems/clock/val/clock |
---|
64 | * |
---|
65 | * @ingroup RTEMSTestSuiteTestsuitesValidationNoClock0 |
---|
66 | * |
---|
67 | * @brief Tests some @ref RTEMSAPIClassicClock directives. |
---|
68 | * |
---|
69 | * This test case performs the following actions: |
---|
70 | * |
---|
71 | * - Use the rtems_clock_get_ticks_since_boot() directive before and after |
---|
72 | * exactly one clock tick. |
---|
73 | * |
---|
74 | * - Check that clock tick gets incremented. |
---|
75 | * |
---|
76 | * - Use the rtems_clock_get_ticks_since_boot() directive before and after |
---|
77 | * exactly one clock tick. |
---|
78 | * |
---|
79 | * - Check that clock tick gets incremented. |
---|
80 | * |
---|
81 | * - Use the rtems_clock_get_ticks_per_second() directive. |
---|
82 | * |
---|
83 | * - Check that rtems_clock_get_ticks_per_second() actually returns 1us / |
---|
84 | * CONFIGURE_MICROSECONDS_PER_TICK. |
---|
85 | * |
---|
86 | * - Use the rtems_clock_get_ticks_per_second() directive. |
---|
87 | * |
---|
88 | * - Check that rtems_clock_get_ticks_per_second() actually returns 1us / |
---|
89 | * CONFIGURE_MICROSECONDS_PER_TICK. |
---|
90 | * |
---|
91 | * @{ |
---|
92 | */ |
---|
93 | |
---|
94 | /** |
---|
95 | * @brief Use the rtems_clock_get_ticks_since_boot() directive before and after |
---|
96 | * exactly one clock tick. |
---|
97 | */ |
---|
98 | static void RtemsClockValClock_Action_0( void ) |
---|
99 | { |
---|
100 | rtems_interval result_0; |
---|
101 | rtems_interval result_1; |
---|
102 | |
---|
103 | result_0 = rtems_clock_get_ticks_since_boot(); |
---|
104 | ClockTick(); |
---|
105 | result_1 = rtems_clock_get_ticks_since_boot(); |
---|
106 | |
---|
107 | /* |
---|
108 | * Check that clock tick gets incremented. |
---|
109 | */ |
---|
110 | T_step_eq_u32( 0, result_1 - result_0, 1 ); |
---|
111 | } |
---|
112 | |
---|
113 | /** |
---|
114 | * @brief Use the rtems_clock_get_ticks_since_boot() directive before and after |
---|
115 | * exactly one clock tick. |
---|
116 | */ |
---|
117 | static void RtemsClockValClock_Action_1( void ) |
---|
118 | { |
---|
119 | rtems_interval result_0; |
---|
120 | rtems_interval result_1; |
---|
121 | |
---|
122 | #undef rtems_clock_get_ticks_since_boot |
---|
123 | |
---|
124 | result_0 = rtems_clock_get_ticks_since_boot(); |
---|
125 | ClockTick(); |
---|
126 | result_1 = rtems_clock_get_ticks_since_boot(); |
---|
127 | |
---|
128 | /* |
---|
129 | * Check that clock tick gets incremented. |
---|
130 | */ |
---|
131 | T_step_eq_u32( 1, result_1 - result_0, 1 ); |
---|
132 | } |
---|
133 | |
---|
134 | /** |
---|
135 | * @brief Use the rtems_clock_get_ticks_per_second() directive. |
---|
136 | */ |
---|
137 | static void RtemsClockValClock_Action_2( void ) |
---|
138 | { |
---|
139 | rtems_interval result; |
---|
140 | |
---|
141 | result = rtems_clock_get_ticks_per_second(); |
---|
142 | |
---|
143 | /* |
---|
144 | * Check that rtems_clock_get_ticks_per_second() actually returns 1us / |
---|
145 | * CONFIGURE_MICROSECONDS_PER_TICK. |
---|
146 | */ |
---|
147 | T_step_eq_u32( 2, result, 1000000UL / TEST_MICROSECONDS_PER_TICK ); |
---|
148 | } |
---|
149 | |
---|
150 | /** |
---|
151 | * @brief Use the rtems_clock_get_ticks_per_second() directive. |
---|
152 | */ |
---|
153 | static void RtemsClockValClock_Action_3( void ) |
---|
154 | { |
---|
155 | rtems_interval result; |
---|
156 | |
---|
157 | #undef rtems_clock_get_ticks_per_second |
---|
158 | |
---|
159 | result = rtems_clock_get_ticks_per_second(); |
---|
160 | |
---|
161 | /* |
---|
162 | * Check that rtems_clock_get_ticks_per_second() actually returns 1us / |
---|
163 | * CONFIGURE_MICROSECONDS_PER_TICK. |
---|
164 | */ |
---|
165 | T_step_eq_u32( 3, result, 1000000UL / TEST_MICROSECONDS_PER_TICK ); |
---|
166 | } |
---|
167 | |
---|
168 | /** |
---|
169 | * @fn void T_case_body_RtemsClockValClock( void ) |
---|
170 | */ |
---|
171 | T_TEST_CASE( RtemsClockValClock ) |
---|
172 | { |
---|
173 | T_plan( 4 ); |
---|
174 | |
---|
175 | RtemsClockValClock_Action_0(); |
---|
176 | RtemsClockValClock_Action_1(); |
---|
177 | RtemsClockValClock_Action_2(); |
---|
178 | RtemsClockValClock_Action_3(); |
---|
179 | } |
---|
180 | |
---|
181 | /** @} */ |
---|