1 | /* |
---|
2 | * Copyright (c) 2014 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 <rtems/profiling.h> |
---|
22 | #include <rtems/bspIo.h> |
---|
23 | #include <rtems.h> |
---|
24 | |
---|
25 | #include <stdio.h> |
---|
26 | #include <string.h> |
---|
27 | |
---|
28 | #include "tmacros.h" |
---|
29 | |
---|
30 | const char rtems_test_name[] = "SPPROFILING 1"; |
---|
31 | |
---|
32 | typedef struct { |
---|
33 | rtems_interrupt_lock a; |
---|
34 | rtems_interrupt_lock b; |
---|
35 | rtems_interrupt_lock c; |
---|
36 | rtems_interrupt_lock d; |
---|
37 | enum { |
---|
38 | WAIT_FOR_A, |
---|
39 | EXPECT_B, |
---|
40 | EXPECT_D, |
---|
41 | DONE |
---|
42 | } state; |
---|
43 | } visitor_context; |
---|
44 | |
---|
45 | static bool is_equal(const rtems_profiling_smp_lock *psl, const char *name) |
---|
46 | { |
---|
47 | return strcmp(psl->name, name) == 0; |
---|
48 | } |
---|
49 | |
---|
50 | static void visitor(void *arg, const rtems_profiling_data *data) |
---|
51 | { |
---|
52 | visitor_context *ctx = arg; |
---|
53 | |
---|
54 | if (data->header.type == RTEMS_PROFILING_SMP_LOCK) { |
---|
55 | const rtems_profiling_smp_lock *psl = &data->smp_lock; |
---|
56 | |
---|
57 | switch (ctx->state) { |
---|
58 | case WAIT_FOR_A: |
---|
59 | rtems_test_assert(!is_equal(psl, "b")); |
---|
60 | rtems_test_assert(!is_equal(psl, "c")); |
---|
61 | rtems_test_assert(!is_equal(psl, "d")); |
---|
62 | |
---|
63 | if (is_equal(psl, "a")) { |
---|
64 | ctx->state = EXPECT_B; |
---|
65 | } |
---|
66 | break; |
---|
67 | case EXPECT_B: |
---|
68 | rtems_test_assert(is_equal(psl, "b")); |
---|
69 | rtems_interrupt_lock_destroy(&ctx->c); |
---|
70 | ctx->state = EXPECT_D; |
---|
71 | break; |
---|
72 | case EXPECT_D: |
---|
73 | rtems_test_assert(is_equal(psl, "d")); |
---|
74 | ctx->state = DONE; |
---|
75 | break; |
---|
76 | case DONE: |
---|
77 | rtems_test_assert(!is_equal(psl, "a")); |
---|
78 | rtems_test_assert(!is_equal(psl, "b")); |
---|
79 | rtems_test_assert(!is_equal(psl, "c")); |
---|
80 | rtems_test_assert(!is_equal(psl, "d")); |
---|
81 | break; |
---|
82 | } |
---|
83 | } |
---|
84 | } |
---|
85 | |
---|
86 | static void lock_init(rtems_interrupt_lock *lock, const char *name) |
---|
87 | { |
---|
88 | rtems_interrupt_lock_context lock_context; |
---|
89 | |
---|
90 | rtems_interrupt_lock_initialize(lock, name); |
---|
91 | rtems_interrupt_lock_acquire(lock, &lock_context); |
---|
92 | rtems_interrupt_lock_release(lock, &lock_context); |
---|
93 | } |
---|
94 | |
---|
95 | static void test_iterate(void) |
---|
96 | { |
---|
97 | visitor_context ctx_instance; |
---|
98 | visitor_context *ctx = &ctx_instance; |
---|
99 | |
---|
100 | ctx->state = WAIT_FOR_A; |
---|
101 | lock_init(&ctx->a, "a"); |
---|
102 | lock_init(&ctx->b, "b"); |
---|
103 | lock_init(&ctx->c, "c"); |
---|
104 | lock_init(&ctx->d, "d"); |
---|
105 | |
---|
106 | rtems_profiling_iterate(visitor, ctx); |
---|
107 | |
---|
108 | rtems_interrupt_lock_destroy(&ctx->a); |
---|
109 | rtems_interrupt_lock_destroy(&ctx->b); |
---|
110 | |
---|
111 | if (ctx->state != DONE) { |
---|
112 | rtems_interrupt_lock_destroy(&ctx->c); |
---|
113 | } |
---|
114 | |
---|
115 | rtems_interrupt_lock_destroy(&ctx->d); |
---|
116 | } |
---|
117 | |
---|
118 | static void test_report_xml(void) |
---|
119 | { |
---|
120 | rtems_status_code sc; |
---|
121 | int rv; |
---|
122 | |
---|
123 | sc = rtems_task_wake_after(3); |
---|
124 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
125 | |
---|
126 | rv = rtems_profiling_report_xml("X", &rtems_test_printer, 1, " "); |
---|
127 | printf("characters produced by rtems_profiling_report_xml(): %i\n", rv); |
---|
128 | } |
---|
129 | |
---|
130 | static void Init(rtems_task_argument arg) |
---|
131 | { |
---|
132 | TEST_BEGIN(); |
---|
133 | |
---|
134 | test_iterate(); |
---|
135 | test_report_xml(); |
---|
136 | |
---|
137 | TEST_END(); |
---|
138 | |
---|
139 | rtems_test_exit(0); |
---|
140 | } |
---|
141 | |
---|
142 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
143 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
144 | |
---|
145 | #define CONFIGURE_MAXIMUM_TASKS 1 |
---|
146 | |
---|
147 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
148 | |
---|
149 | #define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_FLOATING_POINT |
---|
150 | |
---|
151 | #define CONFIGURE_INIT |
---|
152 | |
---|
153 | #include <rtems/confdefs.h> |
---|