source: rtems/testsuites/sptests/sptimerserver01/init.c @ 99de42c

5
Last change on this file since 99de42c was c4b8b147, checked in by Sebastian Huber <sebastian.huber@…>, on 11/03/17 at 07:35:38

tests: Use simple console driver

Update #3170.
Update #3199.

  • Property mode set to 100644
File size: 2.8 KB
Line 
1/*
2 * Copyright (c) 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
21const char rtems_test_name[] = "SPTIMERSERVER 1";
22
23#define TIMER_COUNT 2
24
25typedef struct {
26  rtems_id timer[TIMER_COUNT];
27  rtems_id master;
28} test_context;
29
30static test_context ctx_instance;
31
32static const rtems_time_of_day start = {
33  .year = 2016,
34  .month = 3,
35  .day = 1,
36  .hour = 12,
37  .minute = 5,
38  .second = 17
39};
40
41static void cancel(rtems_id id, void *arg)
42{
43  test_context *ctx = arg;
44  rtems_status_code sc;
45
46  sc = rtems_timer_cancel(ctx->timer[1]);
47  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
48
49  sc = rtems_event_transient_send(ctx->master);
50  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
51}
52
53static void never(rtems_id id, void *arg)
54{
55  rtems_test_assert(0);
56}
57
58static void test(void)
59{
60  test_context *ctx = &ctx_instance;
61  rtems_status_code sc;
62  size_t i;
63  rtems_time_of_day later;
64
65  ctx->master = rtems_task_self();
66
67  sc = rtems_timer_initiate_server(
68    RTEMS_MINIMUM_PRIORITY,
69    RTEMS_MINIMUM_STACK_SIZE,
70    RTEMS_DEFAULT_ATTRIBUTES
71  );
72  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
73
74  for (i = 0; i < TIMER_COUNT; ++i) {
75    sc = rtems_timer_create(
76      rtems_build_name('T', 'M', 'R', '0' + i),
77      &ctx->timer[i]
78    );
79    rtems_test_assert(sc == RTEMS_SUCCESSFUL);
80  }
81
82  sc = rtems_timer_server_fire_after(ctx->timer[0], 10, cancel, ctx);
83  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
84
85  sc = rtems_timer_server_fire_after(ctx->timer[1], 10, never, NULL);
86  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
87
88  sc = rtems_event_transient_receive(RTEMS_WAIT, RTEMS_NO_TIMEOUT);
89  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
90
91  sc = rtems_clock_set(&start);
92  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
93
94  later = start;
95  ++later.second;
96
97  sc = rtems_timer_server_fire_when(ctx->timer[0], &later, cancel, ctx);
98  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
99
100  sc = rtems_timer_server_fire_when(ctx->timer[1], &later, never, NULL);
101  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
102
103  sc = rtems_event_transient_receive(RTEMS_WAIT, RTEMS_NO_TIMEOUT);
104  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
105}
106
107static void Init(rtems_task_argument arg)
108{
109  TEST_BEGIN();
110
111  test();
112
113  TEST_END();
114  rtems_test_exit(0);
115}
116
117#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
118#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
119
120#define CONFIGURE_MAXIMUM_TASKS 2
121#define CONFIGURE_MAXIMUM_TIMERS TIMER_COUNT
122
123#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
124
125#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
126
127#define CONFIGURE_INIT
128
129#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.