summaryrefslogtreecommitdiffstats
path: root/testsuites/sptests/spconfig01/init.c
blob: 2d1b5d4145c3ab407e7a822417a9e05f5214677f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
 * Copyright (c) 2018 embedded brains GmbH.  All rights reserved.
 *
 *  embedded brains GmbH
 *  Dornierstr. 4
 *  82178 Puchheim
 *  Germany
 *  <rtems@embedded-brains.de>
 *
 * The license and distribution terms for this file may be
 * found in the file LICENSE in this distribution or at
 * http://www.rtems.com/license/LICENSE.
 */

#define _GNU_SOURCE

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <sys/stat.h>
#include <errno.h>
#include <pthread.h>

#include <bsp.h>

#include <tmacros.h>

const char rtems_test_name[] = "SPCONFIG 1";

static int counter;

static void checkpoint(int expected_counter)
{
  int current_counter;

  current_counter = counter;
  rtems_test_assert(current_counter == expected_counter);
  counter = current_counter + 1;
}

static rtems_status_code bsp_prerequisite_drivers_init(
  rtems_device_major_number major,
  rtems_device_minor_number minor,
  void *arg
)
{
  TEST_BEGIN();
  checkpoint(0);
  return RTEMS_SUCCESSFUL;
}

static rtems_status_code app_prerequisite_drivers_init(
  rtems_device_major_number major,
  rtems_device_minor_number minor,
  void *arg
)
{
  struct stat st;
  int rv;

  checkpoint(1);

  errno = 0;
  rv = stat("/dev/null", &st);
  rtems_test_assert(rv == -1);
  rtems_test_assert(errno == ENOENT);

  return RTEMS_SUCCESSFUL;
}

static rtems_status_code app_extra_drivers_init(
  rtems_device_major_number major,
  rtems_device_minor_number minor,
  void *arg
)
{
  struct stat st;
  int rv;

  checkpoint(2);

  rv = stat("/dev/null", &st);
  rtems_test_assert(rv == 0);

  return RTEMS_SUCCESSFUL;
}

static void test_stack_config(void)
{
  pthread_attr_t attr;
  size_t stack_size;
  int eno;

  rtems_test_assert(
    rtems_configuration_get_interrupt_stack_size() == CPU_STACK_MINIMUM_SIZE
  );

  eno = pthread_getattr_np(pthread_self(), &attr);
  rtems_test_assert(eno == 0);

  eno = pthread_attr_getstacksize(&attr, &stack_size);
  rtems_test_assert(eno == 0);
  rtems_test_assert(stack_size >= 2 * CPU_STACK_MINIMUM_SIZE);
  rtems_test_assert(
    stack_size <= 2 * CPU_STACK_MINIMUM_SIZE + CPU_STACK_ALIGNMENT -
      CPU_HEAP_ALIGNMENT
  );

  eno = pthread_attr_destroy(&attr);
  rtems_test_assert(eno == 0);
}

static void Init(rtems_task_argument arg)
{
  checkpoint(3);
  test_stack_config();
  TEST_END();
  rtems_test_exit(0);
}

#ifdef BSP_INTERRUPT_STACK_SIZE
#warning "BSP_INTERRUPT_STACK_SIZE will be #undef for this test"
#undef BSP_INTERRUPT_STACK_SIZE
#endif

#ifdef CONFIGURE_BSP_PREREQUISITE_DRIVERS
#warning "CONFIGURE_BSP_PREREQUISITE_DRIVERS will be #undef for this test"
#undef CONFIGURE_BSP_PREREQUISITE_DRIVERS
#endif

#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER

#define CONFIGURE_BSP_PREREQUISITE_DRIVERS \
  { bsp_prerequisite_drivers_init, NULL, NULL, NULL, NULL, NULL }

#define CONFIGURE_APPLICATION_PREREQUISITE_DRIVERS \
  { app_prerequisite_drivers_init, NULL, NULL, NULL, NULL, NULL }

#define CONFIGURE_APPLICATION_NEEDS_STUB_DRIVER

#define CONFIGURE_APPLICATION_EXTRA_DRIVERS \
  { app_extra_drivers_init, NULL, NULL, NULL, NULL, NULL }

#define CONFIGURE_MAXIMUM_TASKS 1

#define CONFIGURE_MINIMUM_TASK_STACK_SIZE (2 * CPU_STACK_MINIMUM_SIZE)

#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION

#define CONFIGURE_RTEMS_INIT_TASKS_TABLE

#define CONFIGURE_INIT

#include <rtems/confdefs.h>