1 | /* |
---|
2 | * Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de) |
---|
3 | * |
---|
4 | * COPYRIGHT (c) 1989-2012. |
---|
5 | * On-Line Applications Research Corporation (OAR). |
---|
6 | * |
---|
7 | * The license and distribution terms for this file may be |
---|
8 | * found in the file LICENSE in this distribution or at |
---|
9 | * http://www.rtems.org/license/LICENSE. |
---|
10 | */ |
---|
11 | |
---|
12 | #ifdef HAVE_CONFIG_H |
---|
13 | #include "config.h" |
---|
14 | #endif |
---|
15 | |
---|
16 | #include <string.h> |
---|
17 | #include <time.h> |
---|
18 | |
---|
19 | #include <rtems/test.h> |
---|
20 | #include <rtems/test-info.h> |
---|
21 | |
---|
22 | const char rtems_test_name[] = "PSXINTRCRITICAL 1"; |
---|
23 | |
---|
24 | typedef struct { |
---|
25 | timer_t timer; |
---|
26 | struct itimerspec spec; |
---|
27 | volatile bool early; |
---|
28 | volatile bool late; |
---|
29 | long early_count; |
---|
30 | long late_count; |
---|
31 | long potential_hits; |
---|
32 | } test_context; |
---|
33 | |
---|
34 | #define POSIX_TIMER_RELATIVE 0 |
---|
35 | |
---|
36 | static void prepare(void *arg) |
---|
37 | { |
---|
38 | test_context *ctx; |
---|
39 | |
---|
40 | ctx = arg; |
---|
41 | ctx->early = false; |
---|
42 | ctx->late = false; |
---|
43 | } |
---|
44 | |
---|
45 | static void action(void *arg) |
---|
46 | { |
---|
47 | test_context *ctx; |
---|
48 | int rv; |
---|
49 | |
---|
50 | ctx = arg; |
---|
51 | ctx->early = true; |
---|
52 | rv = timer_settime(ctx->timer, POSIX_TIMER_RELATIVE, &ctx->spec, NULL); |
---|
53 | ctx->late = true; |
---|
54 | T_quiet_psx_success(rv); |
---|
55 | |
---|
56 | T_interrupt_test_busy_wait_for_interrupt(); |
---|
57 | } |
---|
58 | |
---|
59 | static T_interrupt_test_state interrupt(void *arg) |
---|
60 | { |
---|
61 | test_context *ctx; |
---|
62 | int rv; |
---|
63 | |
---|
64 | if (T_interrupt_test_get_state() != T_INTERRUPT_TEST_ACTION) { |
---|
65 | return T_INTERRUPT_TEST_EARLY; |
---|
66 | } |
---|
67 | |
---|
68 | ctx = arg; |
---|
69 | rv = timer_settime(ctx->timer, POSIX_TIMER_RELATIVE, &ctx->spec, NULL); |
---|
70 | T_quiet_psx_success(rv); |
---|
71 | |
---|
72 | if (ctx->late) { |
---|
73 | ++ctx->late_count; |
---|
74 | return T_INTERRUPT_TEST_LATE; |
---|
75 | } else if (ctx->early) { |
---|
76 | ++ctx->early_count; |
---|
77 | return T_INTERRUPT_TEST_EARLY; |
---|
78 | } else { |
---|
79 | ++ctx->potential_hits; |
---|
80 | |
---|
81 | if (ctx->potential_hits > 13) { |
---|
82 | return T_INTERRUPT_TEST_DONE; |
---|
83 | } else { |
---|
84 | return T_INTERRUPT_TEST_CONTINUE; |
---|
85 | } |
---|
86 | } |
---|
87 | } |
---|
88 | |
---|
89 | static const T_interrupt_test_config config = { |
---|
90 | .prepare = prepare, |
---|
91 | .action = action, |
---|
92 | .interrupt = interrupt, |
---|
93 | .max_iteration_count = 10000 |
---|
94 | }; |
---|
95 | |
---|
96 | T_TEST_CASE(PSXSetTimerInterrupt) |
---|
97 | { |
---|
98 | test_context ctx; |
---|
99 | int sc; |
---|
100 | T_interrupt_test_state state; |
---|
101 | |
---|
102 | memset(&ctx, 0, sizeof(ctx)); |
---|
103 | |
---|
104 | /* create POSIX Timer */ |
---|
105 | sc = timer_create (CLOCK_REALTIME, NULL, &ctx.timer); |
---|
106 | T_psx_success(sc); |
---|
107 | |
---|
108 | /* we don't care if it ever fires */ |
---|
109 | ctx.spec.it_interval.tv_sec = 10; |
---|
110 | ctx.spec.it_value.tv_sec = 10; |
---|
111 | |
---|
112 | state = T_interrupt_test(&config, &ctx); |
---|
113 | T_eq_int(state, T_INTERRUPT_TEST_DONE); |
---|
114 | |
---|
115 | T_log(T_NORMAL, "early count = %ld", ctx.early_count); |
---|
116 | T_log(T_NORMAL, "late count = %ld", ctx.late_count); |
---|
117 | T_log(T_NORMAL, "potential hits = %ld", ctx.potential_hits); |
---|
118 | T_gt_int(ctx.potential_hits, 0); |
---|
119 | |
---|
120 | sc = timer_delete(ctx.timer); |
---|
121 | T_psx_success(sc); |
---|
122 | } |
---|
123 | |
---|
124 | static rtems_task Init(rtems_task_argument arg) |
---|
125 | { |
---|
126 | rtems_test_run(arg, TEST_STATE); |
---|
127 | } |
---|
128 | |
---|
129 | /* configuration information */ |
---|
130 | |
---|
131 | #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER |
---|
132 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
133 | |
---|
134 | #define CONFIGURE_MAXIMUM_TASKS 1 |
---|
135 | #define CONFIGURE_MAXIMUM_POSIX_TIMERS 1 |
---|
136 | #define CONFIGURE_MICROSECONDS_PER_TICK 1000 |
---|
137 | #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION |
---|
138 | |
---|
139 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
140 | |
---|
141 | #define CONFIGURE_INIT |
---|
142 | #include <rtems/confdefs.h> |
---|
143 | |
---|
144 | /* global variables */ |
---|