1 | /* |
---|
2 | * Copyright (c) 2015, 2017 embedded brains GmbH. All rights reserved. |
---|
3 | * |
---|
4 | * embedded brains GmbH |
---|
5 | * Dornierstr. 4 |
---|
6 | * 82178 Puchheim |
---|
7 | * Germany |
---|
8 | * <rtems@embedded-brains.de> |
---|
9 | * |
---|
10 | * The license and distribution terms for this file may be |
---|
11 | * found in the file LICENSE in this distribution or at |
---|
12 | * http://www.rtems.org/license/LICENSE. |
---|
13 | */ |
---|
14 | |
---|
15 | #ifdef HAVE_CONFIG_H |
---|
16 | #include "config.h" |
---|
17 | #endif |
---|
18 | |
---|
19 | #include <tmacros.h> |
---|
20 | #include <intrcritical.h> |
---|
21 | |
---|
22 | #include <string.h> |
---|
23 | |
---|
24 | #include <rtems.h> |
---|
25 | #include <rtems/score/schedulerpriorityimpl.h> |
---|
26 | #include <rtems/score/threadimpl.h> |
---|
27 | |
---|
28 | const char rtems_test_name[] = "SPINTRCRITICAL 23"; |
---|
29 | |
---|
30 | typedef struct { |
---|
31 | RTEMS_INTERRUPT_LOCK_MEMBER(lock) |
---|
32 | rtems_id task_id; |
---|
33 | Scheduler_priority_Node *scheduler_node; |
---|
34 | rtems_task_priority priority_task; |
---|
35 | rtems_task_priority priority_interrupt; |
---|
36 | bool done; |
---|
37 | } test_context; |
---|
38 | |
---|
39 | static test_context ctx_instance; |
---|
40 | |
---|
41 | static void change_priority(rtems_id timer, void *arg) |
---|
42 | { |
---|
43 | /* The arg is NULL */ |
---|
44 | test_context *ctx = &ctx_instance; |
---|
45 | rtems_interrupt_lock_context lock_context; |
---|
46 | unsigned int next_priority; |
---|
47 | |
---|
48 | rtems_interrupt_lock_acquire(&ctx->lock, &lock_context); |
---|
49 | |
---|
50 | next_priority = SCHEDULER_PRIORITY_UNMAP( |
---|
51 | (unsigned int) ctx->scheduler_node->Base.Priority.value |
---|
52 | ); |
---|
53 | |
---|
54 | if ( ctx->scheduler_node->Ready_queue.current_priority != next_priority ) { |
---|
55 | rtems_task_priority priority_interrupt; |
---|
56 | rtems_task_priority priority_task; |
---|
57 | rtems_task_priority previous; |
---|
58 | rtems_status_code sc; |
---|
59 | |
---|
60 | priority_interrupt = ctx->priority_interrupt; |
---|
61 | priority_task = ctx->priority_task; |
---|
62 | |
---|
63 | rtems_interrupt_lock_release(&ctx->lock, &lock_context); |
---|
64 | |
---|
65 | sc = rtems_task_set_priority( |
---|
66 | ctx->task_id, |
---|
67 | priority_interrupt, |
---|
68 | &previous |
---|
69 | ); |
---|
70 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
71 | rtems_test_assert(previous == priority_task); |
---|
72 | |
---|
73 | ctx->done = true; |
---|
74 | } else { |
---|
75 | rtems_interrupt_lock_release(&ctx->lock, &lock_context); |
---|
76 | } |
---|
77 | } |
---|
78 | |
---|
79 | static bool test_body(void *arg) |
---|
80 | { |
---|
81 | test_context *ctx = arg; |
---|
82 | rtems_status_code sc; |
---|
83 | rtems_interrupt_lock_context lock_context; |
---|
84 | rtems_task_priority priority_last; |
---|
85 | rtems_task_priority priority_task; |
---|
86 | rtems_task_priority priority_interrupt; |
---|
87 | rtems_task_priority previous; |
---|
88 | |
---|
89 | rtems_interrupt_lock_acquire(&ctx->lock, &lock_context); |
---|
90 | |
---|
91 | priority_last = ctx->priority_task; |
---|
92 | priority_task = 1 + (priority_last + 1) % 3; |
---|
93 | priority_interrupt = 1 + (priority_task + 1) % 3; |
---|
94 | ctx->priority_task = priority_task; |
---|
95 | ctx->priority_interrupt = priority_interrupt; |
---|
96 | |
---|
97 | rtems_interrupt_lock_release(&ctx->lock, &lock_context); |
---|
98 | |
---|
99 | sc = rtems_task_set_priority( |
---|
100 | ctx->task_id, |
---|
101 | priority_task, |
---|
102 | &previous |
---|
103 | ); |
---|
104 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
105 | rtems_test_assert(previous == priority_last); |
---|
106 | |
---|
107 | if (ctx->done) { |
---|
108 | sc = rtems_task_set_priority( |
---|
109 | ctx->task_id, |
---|
110 | RTEMS_CURRENT_PRIORITY, |
---|
111 | &previous |
---|
112 | ); |
---|
113 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
114 | rtems_test_assert(previous == priority_interrupt); |
---|
115 | } |
---|
116 | |
---|
117 | return ctx->done; |
---|
118 | } |
---|
119 | |
---|
120 | static void Init(rtems_task_argument arg) |
---|
121 | { |
---|
122 | test_context *ctx = &ctx_instance; |
---|
123 | |
---|
124 | TEST_BEGIN(); |
---|
125 | |
---|
126 | rtems_interrupt_lock_initialize(&ctx->lock, "Test"); |
---|
127 | ctx->priority_task = 1; |
---|
128 | ctx->task_id = rtems_task_self(); |
---|
129 | ctx->scheduler_node = |
---|
130 | _Scheduler_priority_Thread_get_node(_Thread_Get_executing()); |
---|
131 | |
---|
132 | interrupt_critical_section_test(test_body, ctx, change_priority); |
---|
133 | rtems_test_assert(ctx->done); |
---|
134 | |
---|
135 | TEST_END(); |
---|
136 | rtems_test_exit(0); |
---|
137 | } |
---|
138 | |
---|
139 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
140 | #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER |
---|
141 | |
---|
142 | #define CONFIGURE_MICROSECONDS_PER_TICK 1000 |
---|
143 | |
---|
144 | #define CONFIGURE_MAXIMUM_TASKS 1 |
---|
145 | #define CONFIGURE_MAXIMUM_TIMERS 1 |
---|
146 | #define CONFIGURE_MAXIMUM_USER_EXTENSIONS 1 |
---|
147 | |
---|
148 | /* We use internal data structures of this scheduler in this test */ |
---|
149 | #define CONFIGURE_SCHEDULER_PRIORITY |
---|
150 | |
---|
151 | #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION |
---|
152 | |
---|
153 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
154 | |
---|
155 | #define CONFIGURE_INIT |
---|
156 | |
---|
157 | #include <rtems/confdefs.h> |
---|