1 | /* |
---|
2 | * Copyright (c) 2015, 2016 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 | |
---|
47 | rtems_interrupt_lock_acquire(&ctx->lock, &lock_context); |
---|
48 | if ( |
---|
49 | ctx->scheduler_node->Ready_queue.current_priority |
---|
50 | != ctx->scheduler_node->Base.Priority.value |
---|
51 | ) { |
---|
52 | rtems_task_priority priority_interrupt; |
---|
53 | rtems_task_priority priority_task; |
---|
54 | rtems_task_priority previous; |
---|
55 | rtems_status_code sc; |
---|
56 | |
---|
57 | priority_interrupt = ctx->priority_interrupt; |
---|
58 | priority_task = ctx->priority_task; |
---|
59 | |
---|
60 | rtems_interrupt_lock_release(&ctx->lock, &lock_context); |
---|
61 | |
---|
62 | sc = rtems_task_set_priority( |
---|
63 | ctx->task_id, |
---|
64 | priority_interrupt, |
---|
65 | &previous |
---|
66 | ); |
---|
67 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
68 | rtems_test_assert(previous == priority_task); |
---|
69 | |
---|
70 | ctx->done = true; |
---|
71 | } else { |
---|
72 | rtems_interrupt_lock_release(&ctx->lock, &lock_context); |
---|
73 | } |
---|
74 | } |
---|
75 | |
---|
76 | static bool test_body(void *arg) |
---|
77 | { |
---|
78 | test_context *ctx = arg; |
---|
79 | rtems_status_code sc; |
---|
80 | rtems_interrupt_lock_context lock_context; |
---|
81 | rtems_task_priority priority_last; |
---|
82 | rtems_task_priority priority_task; |
---|
83 | rtems_task_priority priority_interrupt; |
---|
84 | rtems_task_priority previous; |
---|
85 | |
---|
86 | rtems_interrupt_lock_acquire(&ctx->lock, &lock_context); |
---|
87 | priority_last = ctx->priority_task; |
---|
88 | priority_task = 1 + (priority_last + 1) % 3; |
---|
89 | priority_interrupt = 1 + (priority_task + 1) % 3; |
---|
90 | ctx->priority_task = priority_task; |
---|
91 | ctx->priority_interrupt = priority_interrupt; |
---|
92 | rtems_interrupt_lock_release(&ctx->lock, &lock_context); |
---|
93 | |
---|
94 | sc = rtems_task_set_priority( |
---|
95 | ctx->task_id, |
---|
96 | priority_task, |
---|
97 | &previous |
---|
98 | ); |
---|
99 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
100 | rtems_test_assert(previous == priority_last); |
---|
101 | |
---|
102 | if (ctx->done) { |
---|
103 | sc = rtems_task_set_priority( |
---|
104 | ctx->task_id, |
---|
105 | RTEMS_CURRENT_PRIORITY, |
---|
106 | &previous |
---|
107 | ); |
---|
108 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
109 | rtems_test_assert(previous == priority_interrupt); |
---|
110 | } |
---|
111 | |
---|
112 | return ctx->done; |
---|
113 | } |
---|
114 | |
---|
115 | static void Init(rtems_task_argument arg) |
---|
116 | { |
---|
117 | test_context *ctx = &ctx_instance; |
---|
118 | |
---|
119 | TEST_BEGIN(); |
---|
120 | |
---|
121 | rtems_interrupt_lock_initialize(&ctx->lock, "Test"); |
---|
122 | ctx->priority_task = 1; |
---|
123 | ctx->task_id = rtems_task_self(); |
---|
124 | ctx->scheduler_node = |
---|
125 | _Scheduler_priority_Thread_get_node(_Thread_Get_executing()); |
---|
126 | |
---|
127 | interrupt_critical_section_test(test_body, ctx, change_priority); |
---|
128 | rtems_test_assert(ctx->done); |
---|
129 | |
---|
130 | TEST_END(); |
---|
131 | rtems_test_exit(0); |
---|
132 | } |
---|
133 | |
---|
134 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
135 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
136 | |
---|
137 | #define CONFIGURE_MICROSECONDS_PER_TICK 1000 |
---|
138 | |
---|
139 | #define CONFIGURE_MAXIMUM_TASKS 1 |
---|
140 | #define CONFIGURE_MAXIMUM_TIMERS 1 |
---|
141 | #define CONFIGURE_MAXIMUM_USER_EXTENSIONS 1 |
---|
142 | |
---|
143 | /* We use internal data structures of this scheduler in this test */ |
---|
144 | #define CONFIGURE_SCHEDULER_PRIORITY |
---|
145 | |
---|
146 | #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION |
---|
147 | |
---|
148 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
149 | |
---|
150 | #define CONFIGURE_INIT |
---|
151 | |
---|
152 | #include <rtems/confdefs.h> |
---|