1 | /* |
---|
2 | * Copyright (c) 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 | #define TEST_INIT |
---|
20 | |
---|
21 | #include "tmacros.h" |
---|
22 | |
---|
23 | const char rtems_test_name[] = "SPTIMERSERVER 1"; |
---|
24 | |
---|
25 | #define TIMER_COUNT 2 |
---|
26 | |
---|
27 | typedef struct { |
---|
28 | rtems_id timer[TIMER_COUNT]; |
---|
29 | rtems_id master; |
---|
30 | } test_context; |
---|
31 | |
---|
32 | static test_context ctx_instance; |
---|
33 | |
---|
34 | static const rtems_time_of_day start = { |
---|
35 | .year = 2016, |
---|
36 | .month = 3, |
---|
37 | .day = 1, |
---|
38 | .hour = 12, |
---|
39 | .minute = 5, |
---|
40 | .second = 17 |
---|
41 | }; |
---|
42 | |
---|
43 | static void cancel(rtems_id id, void *arg) |
---|
44 | { |
---|
45 | test_context *ctx = arg; |
---|
46 | rtems_status_code sc; |
---|
47 | |
---|
48 | sc = rtems_timer_cancel(ctx->timer[1]); |
---|
49 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
50 | |
---|
51 | sc = rtems_event_transient_send(ctx->master); |
---|
52 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
53 | } |
---|
54 | |
---|
55 | static void never(rtems_id id, void *arg) |
---|
56 | { |
---|
57 | rtems_test_assert(0); |
---|
58 | } |
---|
59 | |
---|
60 | static void test(void) |
---|
61 | { |
---|
62 | test_context *ctx = &ctx_instance; |
---|
63 | rtems_status_code sc; |
---|
64 | size_t i; |
---|
65 | rtems_time_of_day later; |
---|
66 | |
---|
67 | ctx->master = rtems_task_self(); |
---|
68 | |
---|
69 | sc = rtems_timer_initiate_server( |
---|
70 | RTEMS_MINIMUM_PRIORITY, |
---|
71 | RTEMS_MINIMUM_STACK_SIZE, |
---|
72 | RTEMS_DEFAULT_ATTRIBUTES |
---|
73 | ); |
---|
74 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
75 | |
---|
76 | for (i = 0; i < TIMER_COUNT; ++i) { |
---|
77 | sc = rtems_timer_create( |
---|
78 | rtems_build_name('T', 'M', 'R', '0' + i), |
---|
79 | &ctx->timer[i] |
---|
80 | ); |
---|
81 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
82 | } |
---|
83 | |
---|
84 | sc = rtems_timer_server_fire_after(ctx->timer[0], 10, cancel, ctx); |
---|
85 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
86 | |
---|
87 | sc = rtems_timer_server_fire_after(ctx->timer[1], 10, never, NULL); |
---|
88 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
89 | |
---|
90 | sc = rtems_event_transient_receive(RTEMS_WAIT, RTEMS_NO_TIMEOUT); |
---|
91 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
92 | |
---|
93 | sc = rtems_clock_set(&start); |
---|
94 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
95 | |
---|
96 | later = start; |
---|
97 | ++later.second; |
---|
98 | |
---|
99 | sc = rtems_timer_server_fire_when(ctx->timer[0], &later, cancel, ctx); |
---|
100 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
101 | |
---|
102 | sc = rtems_timer_server_fire_when(ctx->timer[1], &later, never, NULL); |
---|
103 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
104 | |
---|
105 | sc = rtems_event_transient_receive(RTEMS_WAIT, RTEMS_NO_TIMEOUT); |
---|
106 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
107 | } |
---|
108 | |
---|
109 | static void Init(rtems_task_argument arg) |
---|
110 | { |
---|
111 | TEST_BEGIN(); |
---|
112 | |
---|
113 | test(); |
---|
114 | |
---|
115 | TEST_END(); |
---|
116 | rtems_test_exit(0); |
---|
117 | } |
---|
118 | |
---|
119 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
120 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
121 | |
---|
122 | #define CONFIGURE_MAXIMUM_TASKS 2 |
---|
123 | #define CONFIGURE_MAXIMUM_TIMERS TIMER_COUNT |
---|
124 | |
---|
125 | #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION |
---|
126 | |
---|
127 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
128 | |
---|
129 | #define CONFIGURE_INIT |
---|
130 | |
---|
131 | #include <rtems/confdefs.h> |
---|