RTEMS
t-test-rtems-objs.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: BSD-2-Clause */
2 
11 /*
12  * Copyright (C) 2018 embedded brains GmbH (http://www.embedded-brains.de)
13  *
14  * Redistribution and use in source and binary forms, with or without
15  * modification, are permitted provided that the following conditions
16  * are met:
17  * 1. Redistributions of source code must retain the above copyright
18  * notice, this list of conditions and the following disclaimer.
19  * 2. Redistributions in binary form must reproduce the above copyright
20  * notice, this list of conditions and the following disclaimer in the
21  * documentation and/or other materials provided with the distribution.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  */
35 
36 #undef __STRICT_ANSI__
37 
38 #include "t-test-rtems.h"
39 
40 #include <rtems/test.h>
41 
42 #include <inttypes.h>
43 
44 #include <rtems/score/threadimpl.h>
45 
47 T_objects_count(Objects_APIs api, uint16_t cls)
48 {
49  const Objects_Information *information;
50  Objects_Maximum count;
51 
52  information = _Objects_Get_information(api, cls);
53 
54  _RTEMS_Lock_allocator();
55 
56  if (information != NULL) {
57  count = _Objects_Active_count(information);
58  } else {
59  count = 0;
60  }
61 
62  _RTEMS_Unlock_allocator();
63 
64  return count;
65 }
66 
67 void
68 T_objects_check(Objects_APIs api, uint16_t cls,
69  Objects_Maximum *expected, const char *name)
70 {
71  Objects_Maximum count;
72  int32_t delta;
73 
74  count = T_objects_count(api, cls);
75  delta = (int32_t)count - (int32_t)*expected;
76 
77  if (delta != 0) {
78  *expected = count;
79  T_check(&T_special, false, "%s leak (%" PRIi32 ")", name,
80  delta);
81  }
82 }
83 
84 static Objects_Maximum T_barrier_count;
85 
86 static void
87 T_rtems_barriers_run_initialize(void)
88 {
89  T_barrier_count = T_objects_count(OBJECTS_CLASSIC_API,
90  OBJECTS_RTEMS_BARRIERS);
91 }
92 
93 static void
94 T_rtems_barriers_case_end(void)
95 {
96  T_objects_check(OBJECTS_CLASSIC_API, OBJECTS_RTEMS_BARRIERS,
97  &T_barrier_count, "RTEMS barrier");
98 }
99 
100 void
101 T_check_rtems_barriers(T_event event, const char *name)
102 {
103  (void)name;
104 
105  switch (event) {
106  case T_EVENT_RUN_INITIALIZE_EARLY:
107  T_rtems_barriers_run_initialize();
108  break;
109  case T_EVENT_CASE_END:
110  T_rtems_barriers_case_end();
111  break;
112  default:
113  break;
114  };
115 }
116 
117 static Objects_Maximum T_extension_count;
118 
119 static void
120 T_rtems_extensions_run_initialize(void)
121 {
122  T_extension_count = T_objects_count(OBJECTS_CLASSIC_API,
123  OBJECTS_RTEMS_EXTENSIONS);
124 }
125 
126 static void
127 T_rtems_extensions_case_end(void)
128 {
129  T_objects_check(OBJECTS_CLASSIC_API, OBJECTS_RTEMS_EXTENSIONS,
130  &T_extension_count, "RTEMS extension");
131 }
132 
133 void
134 T_check_rtems_extensions(T_event event, const char *name)
135 {
136  (void)name;
137 
138  switch (event) {
139  case T_EVENT_RUN_INITIALIZE_EARLY:
140  T_rtems_extensions_run_initialize();
141  break;
142  case T_EVENT_CASE_END:
143  T_rtems_extensions_case_end();
144  break;
145  default:
146  break;
147  };
148 }
149 
150 static Objects_Maximum T_mq_count;
151 
152 static void
153 T_rtems_message_queues_run_initialize(void)
154 {
155  T_mq_count = T_objects_count(OBJECTS_CLASSIC_API,
156  OBJECTS_RTEMS_MESSAGE_QUEUES);
157 }
158 
159 static void
160 T_rtems_message_queues_case_end(void)
161 {
162  T_objects_check(OBJECTS_CLASSIC_API, OBJECTS_RTEMS_MESSAGE_QUEUES,
163  &T_mq_count, "RTEMS message queue");
164 }
165 
166 void
167 T_check_rtems_message_queues(T_event event, const char *name)
168 {
169  (void)name;
170 
171  switch (event) {
172  case T_EVENT_RUN_INITIALIZE_EARLY:
173  T_rtems_message_queues_run_initialize();
174  break;
175  case T_EVENT_CASE_END:
176  T_rtems_message_queues_case_end();
177  break;
178  default:
179  break;
180  };
181 }
182 
183 static Objects_Maximum T_part_count;
184 
185 static void
186 T_rtems_partitions_run_initialize(void)
187 {
188  T_part_count = T_objects_count(OBJECTS_CLASSIC_API,
189  OBJECTS_RTEMS_PARTITIONS);
190 }
191 
192 static void
193 T_rtems_partitions_case_end(void)
194 {
195  T_objects_check(OBJECTS_CLASSIC_API, OBJECTS_RTEMS_PARTITIONS,
196  &T_part_count, "RTEMS partition");
197 }
198 
199 void
200 T_check_rtems_partitions(T_event event, const char *name)
201 {
202  (void)name;
203 
204  switch (event) {
205  case T_EVENT_RUN_INITIALIZE_EARLY:
206  T_rtems_partitions_run_initialize();
207  break;
208  case T_EVENT_CASE_END:
209  T_rtems_partitions_case_end();
210  break;
211  default:
212  break;
213  };
214 }
215 
216 static Objects_Maximum T_period_count;
217 
218 static void
219 T_rtems_periods_run_initialize(void)
220 {
221  T_period_count = T_objects_count(OBJECTS_CLASSIC_API,
222  OBJECTS_RTEMS_PERIODS);
223 }
224 
225 static void
226 T_rtems_periods_case_end(void)
227 {
228  T_objects_check(OBJECTS_CLASSIC_API, OBJECTS_RTEMS_PERIODS,
229  &T_period_count, "RTEMS period");
230 }
231 
232 void
233 T_check_rtems_periods(T_event event, const char *name)
234 {
235  (void)name;
236 
237  switch (event) {
238  case T_EVENT_RUN_INITIALIZE_EARLY:
239  T_rtems_periods_run_initialize();
240  break;
241  case T_EVENT_CASE_END:
242  T_rtems_periods_case_end();
243  break;
244  default:
245  break;
246  };
247 }
248 
249 static Objects_Maximum T_region_count;
250 
251 static void
252 T_rtems_regions_run_initialize(void)
253 {
254  T_region_count = T_objects_count(OBJECTS_CLASSIC_API,
255  OBJECTS_RTEMS_REGIONS);
256 }
257 
258 static void
259 T_rtems_regions_case_end(void)
260 {
261  T_objects_check(OBJECTS_CLASSIC_API, OBJECTS_RTEMS_REGIONS,
262  &T_region_count, "RTEMS region");
263 }
264 
265 void
266 T_check_rtems_regions(T_event event, const char *name)
267 {
268  (void)name;
269 
270  switch (event) {
271  case T_EVENT_RUN_INITIALIZE_EARLY:
272  T_rtems_regions_run_initialize();
273  break;
274  case T_EVENT_CASE_END:
275  T_rtems_regions_case_end();
276  break;
277  default:
278  break;
279  };
280 }
281 
282 static Objects_Maximum T_sema_count;
283 
284 static void
285 T_rtems_semaphores_run_initialize(void)
286 {
287  T_sema_count = T_objects_count(OBJECTS_CLASSIC_API,
288  OBJECTS_RTEMS_SEMAPHORES);
289 }
290 
291 static void
292 T_rtems_semaphores_case_end(void)
293 {
294  T_objects_check(OBJECTS_CLASSIC_API, OBJECTS_RTEMS_SEMAPHORES,
295  &T_sema_count, "RTEMS semaphore");
296 }
297 
298 void
299 T_check_rtems_semaphores(T_event event, const char *name)
300 {
301  (void)name;
302 
303  switch (event) {
304  case T_EVENT_RUN_INITIALIZE_EARLY:
305  T_rtems_semaphores_run_initialize();
306  break;
307  case T_EVENT_CASE_END:
308  T_rtems_semaphores_case_end();
309  break;
310  default:
311  break;
312  };
313 }
314 
315 static Objects_Maximum T_task_count;
316 
317 static void
318 T_rtems_tasks_run_initialize(void)
319 {
320  T_task_count = T_objects_count(OBJECTS_CLASSIC_API,
321  OBJECTS_RTEMS_TASKS);
322 }
323 
324 static void
325 T_rtems_tasks_case_end(void)
326 {
327  _RTEMS_Lock_allocator();
329  _RTEMS_Unlock_allocator();
330 
331  T_objects_check(OBJECTS_CLASSIC_API, OBJECTS_RTEMS_TASKS,
332  &T_task_count, "RTEMS task");
333 }
334 
335 void
336 T_check_rtems_tasks(T_event event, const char *name)
337 {
338  (void)name;
339 
340  switch (event) {
341  case T_EVENT_RUN_INITIALIZE_EARLY:
342  T_rtems_tasks_run_initialize();
343  break;
344  case T_EVENT_CASE_END:
345  T_rtems_tasks_case_end();
346  break;
347  default:
348  break;
349  };
350 }
351 
352 static Objects_Maximum T_timer_count;
353 
354 static void
355 T_rtems_timers_run_initialize(void)
356 {
357  T_timer_count = T_objects_count(OBJECTS_CLASSIC_API,
358  OBJECTS_RTEMS_TIMERS);
359 }
360 
361 static void
362 T_rtems_timers_case_end(void)
363 {
364  T_objects_check(OBJECTS_CLASSIC_API, OBJECTS_RTEMS_TIMERS,
365  &T_timer_count, "RTEMS timer");
366 }
367 
368 void
369 T_check_rtems_timers(T_event event, const char *name)
370 {
371  (void)name;
372 
373  switch (event) {
374  case T_EVENT_RUN_INITIALIZE_EARLY:
375  T_rtems_timers_run_initialize();
376  break;
377  case T_EVENT_CASE_END:
378  T_rtems_timers_case_end();
379  break;
380  default:
381  break;
382  };
383 }
Objects_Information * _Objects_Get_information(Objects_APIs the_api, uint16_t the_class)
Gets object information.
Definition: objectgetinfo.c:23
void _Thread_Kill_zombies(void)
Kills all zombie threads in the system.
uint16_t Objects_Maximum
Definition: object.h:86
RTEMS Support for Test Framework.
Objects_Maximum _Objects_Active_count(const Objects_Information *information)
Returns the count of active objects.
The information structure used to manage each API class of objects.
Definition: objectdata.h:176
Objects_APIs
Definition: object.h:174
Inlined Routines from the Thread Handler.