RTEMS
t-test-rtems-context.c
1 /*
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (C) 2019 embedded brains GmbH
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25  * POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #undef __STRICT_ANSI__
29 
30 #include <rtems/test.h>
31 
32 #include <rtems.h>
33 #include <rtems/score/isrlevel.h>
34 #include <rtems/score/percpu.h>
36 
37 #include <inttypes.h>
38 
39 #ifdef RTEMS_SMP
40 static rtems_id T_runner_scheduler;
41 #endif
42 
43 static rtems_task_priority T_runner_priority;
44 
45 static void
46 T_initialize_runner_properties(void)
47 {
49 
50 #ifdef RTEMS_SMP
51  sc = rtems_task_get_scheduler(RTEMS_SELF, &T_runner_scheduler);
52  T_quiet_rsc_success(sc);
53 #endif
54 
56  &T_runner_priority);
57  T_quiet_rsc_success(sc);
58 }
59 
60 static void
61 T_do_check_task_context(void)
62 {
65  uint32_t v;
66 #ifdef RTEMS_SMP
67  rtems_id id;
68 #endif
69 
70  v = _Per_CPU_Get_snapshot()->thread_dispatch_disable_level;
71  T_check(&T_special, v == 0,
72  "Wrong thread dispatch disabled level (%" PRIu32 ")", v);
73 
74  v = _Per_CPU_Get_snapshot()->isr_nest_level;
75  T_check(&T_special, v == 0,
76  "Wrong ISR nest level (%" PRIu32 ")", v);
77 
78  v = _ISR_Get_level();
79  T_check(&T_special, v == 0,
80  "Wrong ISR level (%" PRIu32 ")", v);
81 
82 #ifdef RTEMS_SMP
83  id = 0;
85  T_quiet_rsc_success(sc);
86  T_check(&T_special, id == T_runner_scheduler,
87  "Wrong runner scheduler, expected ID %08" PRIx32 ", actual ID %08"
88  PRIx32, T_runner_scheduler, id);
89 #endif
90 
91  prio = 0;
93  &prio);
94  T_quiet_rsc_success(sc);
95  T_check(&T_special, prio == T_runner_priority,
96  "Wrong runner priority, expected %" PRIu32 ", actual %"
97  PRIu32, T_runner_priority, prio);
98 }
99 
100 void
101 T_check_task_context(T_event event, const char *name)
102 {
103  (void)name;
104 
105  switch (event) {
106  case T_EVENT_RUN_INITIALIZE_LATE:
107  T_initialize_runner_properties();
108  /* Fall through */
109  case T_EVENT_CASE_END:
110  T_do_check_task_context();
111  break;
112  default:
113  break;
114  };
115 }
#define RTEMS_CURRENT_PRIORITY
This constant is passed to {set-priority:/name}() when the caller wants to obtain the current priorit...
Definition: tasks.h:248
Constants and Structures Related with Thread Dispatch.
ISR Level Type.
#define _ISR_Get_level()
Return current interrupt level.
Definition: isrlevel.h:128
uint32_t rtems_task_priority
%
Definition: tasks.h:94
#define RTEMS_SELF
%
Definition: tasks.h:1046
rtems_status_code
This enumeration provides status codes for directives of the Classic API.
Definition: status.h:82
rtems_status_code rtems_task_set_priority(rtems_id id, rtems_task_priority new_priority, rtems_task_priority *old_priority)
%
This header file defines the RTEMS Classic API.
rtems_status_code rtems_task_get_scheduler(rtems_id task_id, rtems_id *scheduler_id)
%
Objects_Id rtems_id
Values of this type identify an RTEMS object.
Definition: types.h:99