source: rtems/testsuites/libtests/exit01/init.c @ 98c6d50

5
Last change on this file since 98c6d50 was 98c6d50, checked in by Chris Johns <chrisj@…>, on 10/19/17 at 05:39:16

testsuite: Use printk for all test output where possible.

  • Remove the printf support leaving the direct printk support configured with TESTS_USE_PRINTK and all other output goes via a buffered vsniprintf call to printk.
  • Control the test's single init for functions and global data with TEST_INIT and not CONFIGURE_INIT. They are now separate.

Updates #3170.

  • Property mode set to 100644
File size: 2.1 KB
Line 
1/*
2 * Copyright (c) 2013 embedded brains GmbH.  All rights reserved.
3 *
4 *  embedded brains GmbH
5 *  Obere Lagerstr. 30
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#define TESTS_USE_PRINTK
22#include "tmacros.h"
23
24#include <stdlib.h>
25
26/* Use assert() not rtems_test_assert() since it uses exit() */
27#include <assert.h>
28
29#include <rtems.h>
30
31const char rtems_test_name[] = "EXIT 1";
32
33#define EXIT_STATUS 123
34
35static int counter;
36
37static void atexit_0(void)
38{
39  assert(counter == 0);
40  ++counter;
41}
42
43static void atexit_1(void)
44{
45  assert(counter == 1);
46  ++counter;
47}
48
49static void atexit_2(void)
50{
51  assert(counter == 2);
52  ++counter;
53}
54
55static void fatal_extension(
56  rtems_fatal_source source,
57  bool always_set_to_false,
58  rtems_fatal_code error
59)
60{
61  if (
62    source == RTEMS_FATAL_SOURCE_EXIT
63      && !always_set_to_false
64      && error == EXIT_STATUS
65      && counter == 3
66  ) {
67    TEST_END();
68  }
69}
70
71static void exit_task(rtems_task_argument arg)
72{
73  int rv;
74
75  rv = atexit(atexit_2);
76  assert(rv == 0);
77
78  rv = atexit(atexit_1);
79  assert(rv == 0);
80
81  rv = atexit(atexit_0);
82  assert(rv == 0);
83
84  exit(EXIT_STATUS);
85}
86
87static void Init(rtems_task_argument arg)
88{
89  rtems_status_code sc;
90  rtems_id id;
91
92  TEST_BEGIN();
93
94  sc = rtems_task_create(
95    rtems_build_name('E', 'X', 'I', 'T'),
96    RTEMS_MINIMUM_PRIORITY,
97    RTEMS_MINIMUM_STACK_SIZE,
98    RTEMS_DEFAULT_MODES,
99    RTEMS_DEFAULT_ATTRIBUTES,
100    &id
101  );
102  assert(sc == RTEMS_SUCCESSFUL);
103
104  sc = rtems_task_start(id, exit_task, 0);
105  assert(sc == RTEMS_SUCCESSFUL);
106
107  sc = rtems_task_delete(RTEMS_SELF);
108  assert(sc == RTEMS_SUCCESSFUL);
109}
110
111#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
112#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
113
114#define CONFIGURE_INITIAL_EXTENSIONS \
115  { .fatal = fatal_extension }, \
116  RTEMS_TEST_INITIAL_EXTENSION
117
118#define CONFIGURE_MAXIMUM_TASKS 2
119
120#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
121
122#define CONFIGURE_INIT
123
124#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.