source: rtems/testsuites/sptests/spintrcritical19/init.c @ 6c0301d

4.115
Last change on this file since 6c0301d was 6c0301d, checked in by Sebastian Huber <sebastian.huber@…>, on 03/25/14 at 07:06:21

tests/sptests: Use <rtems/test.h>

  • Property mode set to 100644
File size: 3.1 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#include <intrcritical.h>
21#include <rtems/score/statesimpl.h>
22
23const char rtems_test_name[] = "SPINTRCRITICAL 19";
24
25#define PRIORITY_RED 1
26
27#define PRIORITY_GREEN 2
28
29#define PRIORITY_RESUMER 3
30
31typedef struct {
32  rtems_id master_task;
33  rtems_id resumer_task;
34  Thread_Control *master_task_tcb;
35  bool test_case_hit;
36} test_context;
37
38static test_context ctx_instance;
39
40static void resumer_task(rtems_task_argument arg)
41{
42  test_context *ctx = (test_context *) arg;
43
44  while (true) {
45    rtems_status_code sc = rtems_task_resume(ctx->master_task);
46    rtems_test_assert(sc == RTEMS_SUCCESSFUL);
47  }
48}
49
50static void suspend_master_task(rtems_id timer, void *arg)
51{
52  /* The arg is NULL */
53  test_context *ctx = &ctx_instance;
54  rtems_status_code sc;
55
56  if (_States_Is_transient(ctx->master_task_tcb->current_state)) {
57    ctx->test_case_hit = true;
58  }
59
60  sc = rtems_task_suspend(ctx->master_task);
61  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
62}
63
64static void Init(rtems_task_argument ignored)
65{
66  test_context *ctx = &ctx_instance;
67  rtems_task_priority priority = PRIORITY_RED;
68  int resets = 0;
69  rtems_status_code sc;
70
71  TEST_BEGIN();
72
73  ctx->master_task = rtems_task_self();
74  ctx->master_task_tcb = _Thread_Get_executing();
75
76  sc = rtems_task_create(
77    rtems_build_name('R', 'E', 'S', 'U'),
78    PRIORITY_RESUMER,
79    RTEMS_MINIMUM_STACK_SIZE,
80    RTEMS_DEFAULT_MODES,
81    RTEMS_DEFAULT_ATTRIBUTES,
82    &ctx->resumer_task
83  );
84  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
85
86  sc = rtems_task_start(
87    ctx->resumer_task,
88    resumer_task,
89    (rtems_task_argument) ctx
90  );
91  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
92
93  interrupt_critical_section_test_support_initialize(
94    suspend_master_task
95  );
96
97  while (resets < 3 && !ctx->test_case_hit) {
98    if (interrupt_critical_section_test_support_delay()) {
99      ++resets;
100    }
101
102    sc = rtems_task_set_priority(RTEMS_SELF, priority, &priority);
103    rtems_test_assert(sc == RTEMS_SUCCESSFUL);
104
105    rtems_test_assert(_States_Is_ready(ctx->master_task_tcb->current_state));
106  }
107
108  rtems_test_assert(ctx->test_case_hit);
109
110  sc = rtems_task_delete(ctx->resumer_task);
111  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
112
113  TEST_END();
114
115  rtems_test_exit(0);
116}
117
118#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
119#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
120
121#define CONFIGURE_MICROSECONDS_PER_TICK 1000
122
123#define CONFIGURE_MAXIMUM_TASKS 2
124#define CONFIGURE_MAXIMUM_TIMERS 1
125
126#define CONFIGURE_INIT_TASK_PRIORITY PRIORITY_GREEN
127#define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_DEFAULT_ATTRIBUTES
128#define CONFIGURE_INIT_TASK_INITIAL_MODES RTEMS_DEFAULT_MODES
129
130#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
131
132#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
133
134#define CONFIGURE_INIT
135
136#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.