source: rtems/testsuites/sptests/spstkalloc02/init.c @ 57a569e

Last change on this file since 57a569e was 57a569e, checked in by Matt Joyce <matthew.joyce@…>, on 05/30/22 at 09:05:11

sptests: Disable Newlib reentrancy

Update #4560.

  • Property mode set to 100644
File size: 5.0 KB
Line 
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/**
4 * @file
5 *
6 * @ingroup sptests
7 *
8 * @brief Test that the task stack allocator works.
9 */
10
11/*
12 * Copyright (c) 2011 embedded brains GmbH.  All rights reserved.
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
16 * are met:
17 * 1. Redistributions of source code must retain the above copyright
18 *    notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 *    notice, this list of conditions and the following disclaimer in the
21 *    documentation and/or other materials provided with the distribution.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
34 */
35
36#ifdef HAVE_CONFIG_H
37#include "config.h"
38#endif
39
40#include <tmacros.h>
41
42const char rtems_test_name[] = "SPSTKALLOC 2";
43
44#include <stdio.h>
45#include <inttypes.h>
46
47#include <rtems/score/heapimpl.h>
48
49#define TASK_COUNT 5
50
51#define STACK_HEAP_PAGE_SIZE 1024
52
53static Heap_Control task_stack_heap;
54
55static void task_stack_init(size_t stack_space_size);
56
57static void *task_stack_allocate(size_t stack_size);
58
59static void task_stack_free(void *addr);
60
61static void print_info(void)
62{
63  Heap_Information_block info;
64
65  _Heap_Get_information(&task_stack_heap, &info);
66
67  printf(
68    "used blocks = %" PRIuPTR ", "
69    "largest used block = %" PRIuPTR ", "
70    "used space = %" PRIuPTR "\n"
71    "free blocks = %" PRIuPTR ", "
72    "largest free block = %" PRIuPTR ", "
73    "free space = %" PRIuPTR "\n",
74    info.Used.number,
75    info.Used.largest,
76    info.Used.total,
77    info.Free.number,
78    info.Free.largest,
79    info.Free.total
80  );
81}
82
83static rtems_task Init(rtems_task_argument argument)
84{
85  rtems_status_code sc = RTEMS_SUCCESSFUL;
86  rtems_name name = rtems_build_name('S', 'T', 'K', 'A');
87  rtems_id id = RTEMS_ID_NONE;
88  int i = 0;
89
90  TEST_BEGIN();
91
92  print_info();
93
94  for (i = 2; i < TASK_COUNT; ++i) {
95    sc = rtems_task_create(
96      name,
97      RTEMS_MINIMUM_PRIORITY,
98      RTEMS_MINIMUM_STACK_SIZE,
99      RTEMS_DEFAULT_MODES,
100      RTEMS_DEFAULT_ATTRIBUTES,
101      &id
102    );
103    directive_failed(sc, "rtems_task_create");
104  }
105
106  sc = rtems_task_create(
107    name,
108    RTEMS_MINIMUM_PRIORITY,
109    2 * RTEMS_MINIMUM_STACK_SIZE,
110    RTEMS_DEFAULT_MODES,
111    RTEMS_DEFAULT_ATTRIBUTES,
112    &id
113  );
114  fatal_directive_status(sc, RTEMS_UNSATISFIED, "rtems_task_create");
115
116  sc = rtems_task_create(
117    name,
118    RTEMS_MINIMUM_PRIORITY,
119    RTEMS_MINIMUM_STACK_SIZE,
120    RTEMS_DEFAULT_MODES,
121    RTEMS_DEFAULT_ATTRIBUTES,
122    &id
123  );
124  directive_failed(sc, "rtems_task_create");
125
126  print_info();
127
128  TEST_END();
129
130  rtems_test_exit(0);
131}
132
133#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
134
135/*
136 * Avoid a dependency on errno which might be a thread-local object.  This test
137 * assumes that no thread-local storage object is present.
138 */
139#define CONFIGURE_APPLICATION_DISABLE_FILESYSTEM
140
141/*
142 * This test requires full control over the present thread-local objects.  This
143 * is necessary for the custom stack allocator below.  In certain Newlib
144 * configurations, the Newlib reentrancy support may add thread-local objects.
145 */
146#define CONFIGURE_DISABLE_NEWLIB_REENTRANCY
147
148#define CONFIGURE_MAXIMUM_TASKS TASK_COUNT
149
150#define CONFIGURE_TASK_STACK_ALLOCATOR_INIT task_stack_init
151#define CONFIGURE_TASK_STACK_ALLOCATOR task_stack_allocate
152#define CONFIGURE_TASK_STACK_DEALLOCATOR task_stack_free
153#define CONFIGURE_TASK_STACK_ALLOCATOR_AVOIDS_WORK_SPACE
154#define CONFIGURE_TASK_STACK_FROM_ALLOCATOR(stack_size) \
155  ((stack_size) + HEAP_BLOCK_HEADER_SIZE + STACK_HEAP_PAGE_SIZE - 1)
156
157#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
158
159#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
160
161#define CONFIGURE_INIT
162
163#include <rtems/confdefs.h>
164
165static char task_stack_space
166  [CONFIGURE_TASK_STACK_FROM_ALLOCATOR(_CONFIGURE_STACK_SPACE_SIZE)];
167
168static void task_stack_init(size_t stack_space_size)
169{
170  bool ok = _Heap_Initialize(
171    &task_stack_heap,
172    task_stack_space,
173    sizeof(task_stack_space),
174    STACK_HEAP_PAGE_SIZE
175  );
176
177  rtems_test_assert(stack_space_size == _CONFIGURE_STACK_SPACE_SIZE);
178  rtems_test_assert(ok);
179}
180
181static void *task_stack_allocate(size_t stack_size)
182{
183  return _Heap_Allocate(&task_stack_heap, stack_size);
184}
185
186static void task_stack_free(void *addr)
187{
188  _Heap_Free(&task_stack_heap, addr);
189}
Note: See TracBrowser for help on using the repository browser.