source: rtems/testsuites/smptests/smppsxsignal01/init.c @ ac28f15

5
Last change on this file since ac28f15 was af43554, checked in by Sebastian Huber <sebastian.huber@…>, on 10/26/17 at 11:59:11

tests: Remove TEST_INIT

The TEST_EXTERN is a used only by the system.h style tests and they use
CONFIGURE_INIT appropriately.

Update #3170.
Update #3199.

  • Property mode set to 100644
File size: 3.9 KB
Line 
1/*
2 * Copyright (c) 2013 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
21#include <pthread.h>
22#include <signal.h>
23
24const char rtems_test_name[] = "SMPPSXSIGNAL 1";
25
26#define TEST_SIGNAL SIGUSR1
27
28typedef enum {
29  SIG_READY,
30  SIG_SENT,
31  SIG_PROCESSED
32} test_state;
33
34typedef struct {
35  test_state state;
36  pthread_t consumer;
37  pthread_t producer;
38  uint32_t consumer_processor;
39  uint32_t producer_processor;
40} test_context;
41
42static void change_state(test_context *ctx, test_state new_state)
43{
44  ctx->state = new_state;
45  _CPU_SMP_Processor_event_broadcast();
46}
47
48static void wait_for_state(const test_context *ctx, test_state desired_state)
49{
50  while ( ctx->state != desired_state ) {
51    _CPU_SMP_Processor_event_receive();
52  }
53}
54
55static test_context ctx_instance = {
56  .state = SIG_READY
57};
58
59static void signal_handler(int signum)
60{
61  test_context *ctx = &ctx_instance;
62
63  switch (ctx->state) {
64    case SIG_SENT:
65      change_state(ctx, SIG_PROCESSED);
66      break;
67    default:
68      rtems_test_assert(0);
69  }
70}
71
72static void signal_send(test_context *ctx, test_state new_state)
73{
74  int eno;
75
76  eno = pthread_kill(ctx->consumer, TEST_SIGNAL);
77  rtems_test_assert(eno == 0);
78
79  change_state(ctx, new_state);
80}
81
82static void check_consumer_processor(const test_context *ctx)
83{
84  rtems_test_assert(
85    ctx->consumer_processor == rtems_get_current_processor()
86  );
87}
88
89static void check_producer_processor(const test_context *ctx)
90{
91  rtems_test_assert(
92    ctx->producer_processor == rtems_get_current_processor()
93  );
94}
95
96static void *producer(void *arg)
97{
98  test_context *ctx = arg;
99
100  ctx->producer_processor = rtems_get_current_processor();
101
102  rtems_test_assert(ctx->consumer_processor != ctx->producer_processor);
103
104  wait_for_state(ctx, SIG_READY);
105  signal_send(ctx, SIG_SENT);
106
107  check_producer_processor(ctx);
108
109  return ctx;
110}
111
112static void test(void)
113{
114  test_context *ctx = &ctx_instance;
115  struct sigaction new_action;
116  sigset_t test_signal_set;
117  int rv;
118  pthread_attr_t attr;
119  int eno;
120  void *producer_status;
121
122  ctx->consumer = pthread_self();
123  ctx->consumer_processor = rtems_get_current_processor();
124
125  memset(&new_action, 0, sizeof(new_action));
126  new_action.sa_handler = signal_handler;
127
128  rv = sigaction(TEST_SIGNAL, &new_action, NULL);
129  rtems_test_assert(rv == 0);
130
131  rv = sigemptyset(&test_signal_set);
132  rtems_test_assert(rv == 0);
133
134  rv = sigaddset(&test_signal_set, TEST_SIGNAL);
135  rtems_test_assert(rv == 0);
136
137  eno = pthread_sigmask(SIG_UNBLOCK, &test_signal_set, NULL);
138  rtems_test_assert(eno == 0);
139
140  eno = pthread_attr_init(&attr);
141  rtems_test_assert(eno == 0);
142
143  eno = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
144  rtems_test_assert(eno == 0);
145
146  eno = pthread_create(&ctx->producer, &attr, producer, ctx);
147  rtems_test_assert(eno == 0);
148
149  eno = pthread_attr_destroy(&attr);
150  rtems_test_assert(eno == 0);
151
152  check_consumer_processor(ctx);
153
154  wait_for_state(ctx, SIG_PROCESSED);
155
156  check_consumer_processor(ctx);
157
158  producer_status = NULL;
159  pthread_join(ctx->producer, &producer_status);
160  rtems_test_assert(eno == 0);
161  rtems_test_assert(producer_status == ctx);
162}
163
164static void *POSIX_Init(void *arg)
165{
166  TEST_BEGIN();
167
168  if (rtems_get_processor_count() >= 2) {
169    test();
170  }
171
172  TEST_END();
173  rtems_test_exit(0);
174}
175
176#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
177#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
178
179#define CONFIGURE_MAXIMUM_PROCESSORS 2
180
181#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
182
183#define CONFIGURE_MAXIMUM_POSIX_THREADS 2
184
185#define CONFIGURE_POSIX_INIT_THREAD_TABLE
186
187#define CONFIGURE_INIT
188
189#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.