source: rtems/testsuites/tmtests/tmfine01/init.c @ 54835ae

Last change on this file since 54835ae was 54835ae, checked in by Sebastian Huber <sebastian.huber@…>, on Feb 1, 2017 at 1:10:18 PM

Rename CONFIGURE_SMP_MAXIMUM_PROCESSORS

Rename CONFIGURE_SMP_MAXIMUM_PROCESSORS to CONFIGURE_MAXIMUM_PROCESSORS
since the SMP part is superfluous.

Update #2894.

  • Property mode set to 100644
File size: 10.8 KB
Line 
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
21#include <sys/lock.h>
22#include <stdio.h>
23#include <inttypes.h>
24
25#include <rtems/test.h>
26
27const char rtems_test_name[] = "TMFINE 1";
28
29#define CPU_COUNT 32
30
31#define MSG_COUNT 3
32
33typedef struct {
34  uint32_t value;
35} test_msg;
36
37typedef struct {
38  rtems_test_parallel_context base;
39  rtems_id master;
40  rtems_id sema[CPU_COUNT];
41  rtems_id mq[CPU_COUNT];
42  uint32_t self_event_ops[CPU_COUNT][CPU_COUNT];
43  uint32_t all_to_one_event_ops[CPU_COUNT][CPU_COUNT];
44  uint32_t one_mutex_ops[CPU_COUNT][CPU_COUNT];
45  uint32_t many_mutex_ops[CPU_COUNT][CPU_COUNT];
46  uint32_t self_msg_ops[CPU_COUNT][CPU_COUNT];
47  uint32_t many_to_one_msg_ops[CPU_COUNT][CPU_COUNT];
48  uint32_t many_sys_lock_mutex_ops[CPU_COUNT][CPU_COUNT];
49} test_context;
50
51static test_context test_instance;
52
53static rtems_interval test_duration(void)
54{
55  return rtems_clock_get_ticks_per_second();
56}
57
58static rtems_interval test_init(
59  rtems_test_parallel_context *base,
60  void *arg,
61  size_t active_workers
62)
63{
64  return test_duration();
65}
66
67static void test_fini(
68  const char *name,
69  uint32_t *counters,
70  size_t active_workers
71)
72{
73  size_t i;
74
75  printf("  <%s activeWorker=\"%zu\">\n", name, active_workers);
76
77  for (i = 0; i < active_workers; ++i) {
78    printf(
79      "    <Counter worker=\"%zu\">%" PRIu32 "</Counter>\n",
80      i,
81      counters[i]
82    );
83  }
84
85  printf("  </%s>\n", name);
86}
87
88static void test_self_event_body(
89  rtems_test_parallel_context *base,
90  void *arg,
91  size_t active_workers,
92  size_t worker_index
93)
94{
95  test_context *ctx = (test_context *) base;
96  rtems_id id = rtems_task_self();
97  uint32_t counter = 0;
98
99  while (!rtems_test_parallel_stop_job(&ctx->base)) {
100    rtems_status_code sc;
101    rtems_event_set out;
102
103    ++counter;
104
105    sc = rtems_event_send(id, RTEMS_EVENT_0);
106    rtems_test_assert(sc == RTEMS_SUCCESSFUL);
107
108    sc = rtems_event_receive(
109      RTEMS_EVENT_0,
110      RTEMS_WAIT | RTEMS_EVENT_ANY,
111      RTEMS_NO_TIMEOUT,
112      &out
113    );
114    rtems_test_assert(sc == RTEMS_SUCCESSFUL);
115  }
116
117  ctx->self_event_ops[active_workers - 1][worker_index] = counter;
118}
119
120static void test_self_event_fini(
121  rtems_test_parallel_context *base,
122  void *arg,
123  size_t active_workers
124)
125{
126  test_context *ctx = (test_context *) base;
127
128  test_fini(
129    "SelfEvent",
130    &ctx->self_event_ops[active_workers - 1][0],
131    active_workers
132  );
133}
134
135static void test_all_to_one_event_body(
136  rtems_test_parallel_context *base,
137  void *arg,
138  size_t active_workers,
139  size_t worker_index
140)
141{
142  test_context *ctx = (test_context *) base;
143  rtems_id id = rtems_task_self();
144  bool is_master = rtems_test_parallel_is_master_worker(worker_index);
145  uint32_t counter = 0;
146
147  while (!rtems_test_parallel_stop_job(&ctx->base)) {
148    rtems_status_code sc;
149
150    ++counter;
151
152    sc = rtems_event_send(id, RTEMS_EVENT_0);
153    rtems_test_assert(sc == RTEMS_SUCCESSFUL);
154
155    if (is_master) {
156      rtems_event_set out;
157
158      sc = rtems_event_receive(
159        RTEMS_ALL_EVENTS,
160        RTEMS_WAIT | RTEMS_EVENT_ANY,
161        RTEMS_NO_TIMEOUT,
162        &out
163      );
164      rtems_test_assert(sc == RTEMS_SUCCESSFUL);
165    }
166  }
167
168  ctx->all_to_one_event_ops[active_workers - 1][worker_index] = counter;
169}
170
171static void test_all_to_one_event_fini(
172  rtems_test_parallel_context *base,
173  void *arg,
174  size_t active_workers
175)
176{
177  test_context *ctx = (test_context *) base;
178
179  test_fini(
180    "AllToOneEvent",
181    &ctx->all_to_one_event_ops[active_workers - 1][0],
182    active_workers
183  );
184}
185
186static void test_one_mutex_body(
187  rtems_test_parallel_context *base,
188  void *arg,
189  size_t active_workers,
190  size_t worker_index
191)
192{
193  test_context *ctx = (test_context *) base;
194  rtems_id id = ctx->sema[0];
195  uint32_t counter = 0;
196
197  while (!rtems_test_parallel_stop_job(&ctx->base)) {
198    rtems_status_code sc;
199
200    ++counter;
201
202    sc = rtems_semaphore_obtain(id, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
203    rtems_test_assert(sc == RTEMS_SUCCESSFUL);
204
205    sc = rtems_semaphore_release(id);
206    rtems_test_assert(sc == RTEMS_SUCCESSFUL);
207  }
208
209  ctx->one_mutex_ops[active_workers - 1][worker_index] = counter;
210}
211
212static void test_one_mutex_fini(
213  rtems_test_parallel_context *base,
214  void *arg,
215  size_t active_workers
216)
217{
218  test_context *ctx = (test_context *) base;
219
220  test_fini(
221    "OneMutex",
222    &ctx->one_mutex_ops[active_workers - 1][0],
223    active_workers
224  );
225}
226
227static void test_many_mutex_body(
228  rtems_test_parallel_context *base,
229  void *arg,
230  size_t active_workers,
231  size_t worker_index
232)
233{
234  test_context *ctx = (test_context *) base;
235  rtems_id id = ctx->sema[worker_index];
236  uint32_t counter = 0;
237
238  while (!rtems_test_parallel_stop_job(&ctx->base)) {
239    rtems_status_code sc;
240
241    ++counter;
242
243    sc = rtems_semaphore_obtain(id, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
244    rtems_test_assert(sc == RTEMS_SUCCESSFUL);
245
246    sc = rtems_semaphore_release(id);
247    rtems_test_assert(sc == RTEMS_SUCCESSFUL);
248  }
249
250  ctx->many_mutex_ops[active_workers - 1][worker_index] = counter;
251}
252
253static void test_many_mutex_fini(
254  rtems_test_parallel_context *base,
255  void *arg,
256  size_t active_workers
257)
258{
259  test_context *ctx = (test_context *) base;
260
261  test_fini(
262    "ManyMutex",
263    &ctx->many_mutex_ops[active_workers - 1][0],
264    active_workers
265  );
266}
267
268static void test_self_msg_body(
269  rtems_test_parallel_context *base,
270  void *arg,
271  size_t active_workers,
272  size_t worker_index
273)
274{
275  test_context *ctx = (test_context *) base;
276  rtems_id id = ctx->mq[worker_index];
277  uint32_t counter = 0;
278
279  while (!rtems_test_parallel_stop_job(&ctx->base)) {
280    rtems_status_code sc;
281    test_msg msg = { .value = 0 };
282    size_t n;
283
284    ++counter;
285
286    sc = rtems_message_queue_send(id, &msg, sizeof(msg));
287    rtems_test_assert(sc == RTEMS_SUCCESSFUL || sc == RTEMS_TOO_MANY);
288
289    n = sizeof(msg);
290    sc = rtems_message_queue_receive(
291      id,
292      &msg,
293      &n,
294      RTEMS_WAIT,
295      RTEMS_NO_TIMEOUT
296    );
297    rtems_test_assert(sc == RTEMS_SUCCESSFUL);
298    rtems_test_assert(n == sizeof(msg));
299  }
300
301  ctx->self_msg_ops[active_workers - 1][worker_index] = counter;
302}
303
304static void test_self_msg_fini(
305  rtems_test_parallel_context *base,
306  void *arg,
307  size_t active_workers
308)
309{
310  test_context *ctx = (test_context *) base;
311
312  test_fini(
313    "SelfMsg",
314    &ctx->self_msg_ops[active_workers - 1][0],
315    active_workers
316  );
317}
318
319static void test_many_to_one_msg_body(
320  rtems_test_parallel_context *base,
321  void *arg,
322  size_t active_workers,
323  size_t worker_index
324)
325{
326  test_context *ctx = (test_context *) base;
327  rtems_id id = ctx->mq[0];
328  bool is_master = rtems_test_parallel_is_master_worker(worker_index);
329  uint32_t counter = 0;
330
331  while (!rtems_test_parallel_stop_job(&ctx->base)) {
332    rtems_status_code sc;
333    test_msg msg = { .value = 0 };
334    size_t n;
335
336    ++counter;
337
338    sc = rtems_message_queue_send(id, &msg, sizeof(msg));
339    rtems_test_assert(sc == RTEMS_SUCCESSFUL || sc == RTEMS_TOO_MANY);
340
341    if (is_master) {
342      n = sizeof(msg);
343      sc = rtems_message_queue_receive(
344        id,
345        &msg,
346        &n,
347        RTEMS_WAIT,
348        RTEMS_NO_TIMEOUT
349      );
350      rtems_test_assert(sc == RTEMS_SUCCESSFUL);
351      rtems_test_assert(n == sizeof(msg));
352    }
353  }
354
355  ctx->many_to_one_msg_ops[active_workers - 1][worker_index] = counter;
356}
357
358static void test_many_to_one_msg_fini(
359  rtems_test_parallel_context *base,
360  void *arg,
361  size_t active_workers
362)
363{
364  test_context *ctx = (test_context *) base;
365
366  test_fini(
367    "ManyToOneMsg",
368    &ctx->many_to_one_msg_ops[active_workers - 1][0],
369    active_workers
370  );
371}
372
373static void test_many_sys_lock_mutex_body(
374  rtems_test_parallel_context *base,
375  void *arg,
376  size_t active_workers,
377  size_t worker_index
378)
379{
380  test_context *ctx = (test_context *) base;
381  struct _Mutex_Control mtx;
382  uint32_t counter = 0;
383
384  _Mutex_Initialize(&mtx);
385
386  while (!rtems_test_parallel_stop_job(&ctx->base)) {
387    ++counter;
388
389    _Mutex_Acquire(&mtx);
390    _Mutex_Release(&mtx);
391  }
392
393  ctx->many_sys_lock_mutex_ops[active_workers - 1][worker_index] = counter;
394}
395
396static void test_many_sys_lock_mutex_fini(
397  rtems_test_parallel_context *base,
398  void *arg,
399  size_t active_workers
400)
401{
402  test_context *ctx = (test_context *) base;
403
404  test_fini(
405    "ManySysLockMutex",
406    &ctx->many_sys_lock_mutex_ops[active_workers - 1][0],
407    active_workers
408  );
409}
410
411static const rtems_test_parallel_job test_jobs[] = {
412  {
413    .init = test_init,
414    .body = test_self_event_body,
415    .fini = test_self_event_fini,
416    .cascade = true
417  }, {
418    .init = test_init,
419    .body = test_all_to_one_event_body,
420    .fini = test_all_to_one_event_fini,
421    .cascade = true
422  }, {
423    .init = test_init,
424    .body = test_one_mutex_body,
425    .fini = test_one_mutex_fini,
426    .cascade = true
427  }, {
428    .init = test_init,
429    .body = test_many_mutex_body,
430    .fini = test_many_mutex_fini,
431    .cascade = true
432  }, {
433    .init = test_init,
434    .body = test_self_msg_body,
435    .fini = test_self_msg_fini,
436    .cascade = true
437  }, {
438    .init = test_init,
439    .body = test_many_to_one_msg_body,
440    .fini = test_many_to_one_msg_fini,
441    .cascade = true
442  }, {
443    .init = test_init,
444    .body = test_many_sys_lock_mutex_body,
445    .fini = test_many_sys_lock_mutex_fini,
446    .cascade = true
447  }
448};
449
450static void Init(rtems_task_argument arg)
451{
452  test_context *ctx = &test_instance;
453  const char *test = "TestTimeFine01";
454  size_t i;
455
456  TEST_BEGIN();
457
458  ctx->master = rtems_task_self();
459
460  for (i = 0; i < CPU_COUNT; ++i) {
461    rtems_status_code sc;
462
463    sc = rtems_semaphore_create(
464      rtems_build_name('T', 'E', 'S', 'T'),
465      1,
466      RTEMS_BINARY_SEMAPHORE | RTEMS_INHERIT_PRIORITY | RTEMS_PRIORITY,
467      0,
468      &ctx->sema[i]
469    );
470    rtems_test_assert(sc == RTEMS_SUCCESSFUL);
471
472    sc = rtems_message_queue_create(
473      rtems_build_name('T', 'E', 'S', 'T'),
474      MSG_COUNT,
475      sizeof(test_msg),
476      RTEMS_DEFAULT_ATTRIBUTES,
477      &ctx->mq[i]
478    );
479    rtems_test_assert(sc == RTEMS_SUCCESSFUL);
480  }
481
482  printf("<%s>\n", test);
483
484  rtems_test_parallel(
485    &ctx->base,
486    NULL,
487    &test_jobs[0],
488    RTEMS_ARRAY_SIZE(test_jobs)
489  );
490
491  printf("</%s>\n", test);
492
493  TEST_END();
494  rtems_test_exit(0);
495}
496
497#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
498#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
499
500#define CONFIGURE_MAXIMUM_TASKS CPU_COUNT
501
502#define CONFIGURE_MAXIMUM_TIMERS 1
503
504#define CONFIGURE_MAXIMUM_SEMAPHORES CPU_COUNT
505
506#define CONFIGURE_MAXIMUM_MESSAGE_QUEUES CPU_COUNT
507
508#define CONFIGURE_MESSAGE_BUFFER_MEMORY \
509  CONFIGURE_MESSAGE_BUFFERS_FOR_QUEUE(MSG_COUNT, sizeof(test_msg))
510
511#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
512
513#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
514
515#define CONFIGURE_MAXIMUM_PROCESSORS CPU_COUNT
516
517#define CONFIGURE_INIT
518
519#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.