source: rtems/testsuites/sptests/spclock_err01/init.c @ f6bcf163

Last change on this file since f6bcf163 was f6bcf163, checked in by Sebastian Huber <sebastian.huber@…>, on 10/25/22 at 05:59:15

sptests: Avoid fatal error to end a test

End the test with a normal exit instead of
INTERNAL_ERROR_THREAD_EXITTED.

  • Property mode set to 100644
File size: 6.7 KB
Line 
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/*
4 *  COPYRIGHT (c) 2014.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 *    notice, this list of conditions and the following disclaimer in the
14 *    documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#ifdef HAVE_CONFIG_H
30#include "config.h"
31#endif
32
33#define CONFIGURE_INIT
34#include "system.h"
35
36const char rtems_test_name[] = "SP CLOCK ERROR 2";
37
38rtems_task Init(
39  rtems_task_argument argument
40)
41{
42  rtems_time_of_day time;
43  rtems_interval    interval;
44  struct timeval    tv;
45  rtems_status_code status;
46 
47  TEST_BEGIN();
48 
49  puts( "TA1 - rtems_clock_get_tod - RTEMS_INVALID_ADDRESS" );
50  status = rtems_clock_get_tod( NULL );
51  fatal_directive_status(
52    status,
53    RTEMS_INVALID_ADDRESS,
54    "rtems_clock_get_tod NULL param"
55  );
56
57/* errors before clock is set */
58
59  status = rtems_clock_get_tod( &time );
60  if ( status == RTEMS_SUCCESSFUL ) {
61    puts(
62     "TA1 - rtems_clock_get_tod - RTEMS_NOT_DEFINED -- "
63         "DID BSP SET THE TIME OF DAY?"
64    );
65  } else {
66    fatal_directive_status(
67      status,
68      RTEMS_NOT_DEFINED,
69      "rtems_clock_get_tod before clock is set #1"
70    );
71    puts( "TA1 - rtems_clock_get_tod - RTEMS_NOT_DEFINED" );
72  }
73
74  puts( "TA1 - rtems_clock_get_seconds_since_epoch - RTEMS_INVALID_ADDRESS" );
75  status = rtems_clock_get_seconds_since_epoch( NULL );
76  fatal_directive_status(
77    status,
78    RTEMS_INVALID_ADDRESS,
79    "rtems_clock_get_seconds_since_epoch NULL param"
80  );
81
82  status = rtems_clock_get_seconds_since_epoch( &interval );
83  if ( status == RTEMS_SUCCESSFUL ) {
84    puts(
85     "TA1 - rtems_clock_get_seconds_since_epoch - RTEMS_NOT_DEFINED -- "
86         "DID BSP SET THE TIME OF DAY?"
87    );
88  } else {
89    fatal_directive_status(
90      status,
91      RTEMS_NOT_DEFINED,
92      "rtems_clock_get_seconds_before_epoch"
93    );
94    puts( "TA1 - rtems_clock_get_seconds_since_epoch - RTEMS_NOT_DEFINED" );
95  }
96
97  puts( "TA1 - rtems_clock_get_uptime - RTEMS_INVALID_ADDRESS" );
98  status = rtems_clock_get_uptime( NULL );
99  fatal_directive_status(
100    status,
101    RTEMS_INVALID_ADDRESS,
102    "rtems_clock_get_uptime NULL param"
103  );
104
105  puts( "TA1 - rtems_clock_get_uptime_timeval" );
106  rtems_clock_get_uptime_timeval( &tv );
107
108  puts( "TA1 - rtems_clock_get_uptime_seconds" );
109  rtems_clock_get_uptime_seconds();
110
111  puts( "TA1 - rtems_clock_get_uptime_nanoseconds" );
112  rtems_clock_get_uptime_nanoseconds();
113
114  puts( "TA1 - rtems_clock_get_tod_timeval - RTEMS_INVALID_ADDRESS" );
115  status = rtems_clock_get_tod_timeval( NULL );
116  fatal_directive_status(
117    status,
118    RTEMS_INVALID_ADDRESS,
119    "rtems_clock_get_tod_timeval NULL param"
120  );
121
122  status = rtems_clock_get_tod_timeval( &tv );
123  if ( status == RTEMS_SUCCESSFUL ) {
124    puts(
125     "TA1 - rtems_clock_get_tod_timeval - RTEMS_NOT_DEFINED -- "
126         "DID BSP SET THE TIME OF DAY?"
127    );
128  } else {
129    fatal_directive_status(
130      status,
131      RTEMS_NOT_DEFINED,
132      "rtems_clock_get_timeval"
133    );
134    puts( "TA1 - rtems_clock_get_tod_timeval - RTEMS_NOT_DEFINED" );
135  }
136
137  /* NULL parameter */
138  status = rtems_clock_set( NULL );
139  fatal_directive_status(
140    status,
141    RTEMS_INVALID_ADDRESS,
142    "rtems_clock_set sull pointer"
143  );
144  puts( "TA1 - rtems_clock_set - RTEMS_INVALID_ADDRESS" );
145
146  build_time( &time, 2, 5, 1987, 8, 30, 45, 0 );
147  print_time( "TA1 - rtems_clock_set - ", &time, "" );
148  status = rtems_clock_set( &time );
149  fatal_directive_status(
150    status,
151    RTEMS_INVALID_CLOCK,
152    "rtems_clock_set with invalid year"
153  );
154  puts( " - RTEMS_INVALID_CLOCK" );
155
156  build_time( &time, 15, 5, 1988, 8, 30, 45, 0 );
157  print_time( "TA1 - rtems_clock_set - ", &time, "" );
158  status = rtems_clock_set( &time );
159  fatal_directive_status(
160    status,
161    RTEMS_INVALID_CLOCK,
162    "rtems_clock_set with invalid month"
163  );
164  puts( " - RTEMS_INVALID_CLOCK" );
165
166  build_time( &time, 2, 32, 1988, 8, 30, 45, 0 );
167  print_time( "TA1 - rtems_clock_set - ", &time, "" );
168  status = rtems_clock_set( &time );
169  fatal_directive_status(
170    status,
171    RTEMS_INVALID_CLOCK,
172    "rtems_clock_set with invalid day"
173  );
174  puts( " - RTEMS_INVALID_CLOCK" );
175
176  build_time( &time, 2, 5, 1988, 25, 30, 45, 0 );
177  print_time( "TA1 - rtems_clock_set - ", &time, "" );
178  status = rtems_clock_set( &time );
179  fatal_directive_status(
180    status,
181    RTEMS_INVALID_CLOCK,
182    "rtems_clock_set with invalid hour"
183  );
184  puts( " - RTEMS_INVALID_CLOCK" );
185
186  build_time( &time, 2, 5, 1988, 8, 61, 45, 0 );
187  print_time( "TA1 - rtems_clock_set - ", &time, "" );
188  status = rtems_clock_set( &time );
189  fatal_directive_status(
190    status,
191    RTEMS_INVALID_CLOCK,
192    "rtems_clock_set with invalid minute"
193  );
194  puts( " - RTEMS_INVALID_CLOCK" );
195
196  build_time( &time, 2, 5, 1988, 8, 30, 61, 0 );
197  print_time( "TA1 - rtems_clock_set - ", &time, "" );
198  status = rtems_clock_set( &time );
199  fatal_directive_status(
200    status,
201    RTEMS_INVALID_CLOCK,
202    "rtems_clock_set with invalid second"
203  );
204  puts( " - RTEMS_INVALID_CLOCK" );
205
206  build_time(
207    &time, 2, 5, 1988, 8, 30, 45,
208    rtems_clock_get_ticks_per_second() + 1
209  );
210  print_time( "TA1 - rtems_clock_set - ", &time, "" );
211  status = rtems_clock_set( &time );
212  fatal_directive_status(
213    status,
214    RTEMS_INVALID_CLOCK,
215    "rtems_clock_set with invalid ticks per second"
216  );
217  puts( " - RTEMS_INVALID_CLOCK" );
218
219  build_time( &time, 2, 5, 1988, 8, 30, 45, 0 );
220  print_time( "TA1 - rtems_clock_set - ", &time, "" );
221  status = rtems_clock_set( &time );
222  directive_failed( status, "rtems_clock_set successful" );
223  puts( " - RTEMS_SUCCESSFUL" );
224
225  rtems_clock_get_tod( &time );
226  print_time( "TA1 - current time - ", &time, "\n" );
227
228  TEST_END();
229  rtems_test_exit( 0 );
230}
Note: See TracBrowser for help on using the repository browser.