source: rtems/testsuites/sptests/spstkalloc02/init.c @ 3324383c

4.11
Last change on this file since 3324383c was 3324383c, checked in by Joel Sherrill <joel.sherrill@…>, on May 5, 2014 at 2:47:30 PM

testsuites: Remove BSP_SMALL_MEMORY

  • Property mode set to 100644
File size: 3.5 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup sptests
5 *
6 * @brief Test that the task stack allocator works.
7 */
8
9/*
10 * Copyright (c) 2011 embedded brains GmbH.  All rights reserved.
11 *
12 *  embedded brains GmbH
13 *  Obere Lagerstr. 30
14 *  82178 Puchheim
15 *  Germany
16 *  <rtems@embedded-brains.de>
17 *
18 * The license and distribution terms for this file may be
19 * found in the file LICENSE in this distribution or at
20 * http://www.rtems.org/license/LICENSE.
21 */
22
23#ifdef HAVE_CONFIG_H
24  #include "config.h"
25#endif
26
27#include <tmacros.h>
28
29const char rtems_test_name[] = "SPSTKALLOC 2";
30
31#include <stdio.h>
32#include <inttypes.h>
33
34#include <rtems/score/heapimpl.h>
35
36#define TASK_COUNT 5
37
38#define PAGE_SIZE 1024
39
40static Heap_Control task_stack_heap;
41
42static void task_stack_init(size_t stack_space_size);
43
44static void *task_stack_allocate(size_t stack_size);
45
46static void task_stack_free(void *addr);
47
48static void print_info(void)
49{
50  Heap_Information_block info;
51
52  _Heap_Get_information(&task_stack_heap, &info);
53
54  printf(
55    "used blocks = %" PRIu32 ", "
56    "largest used block = %" PRIu32 ", "
57    "used space = %" PRIu32 "\n"
58    "free blocks = %" PRIu32 ", "
59    "largest free block = %" PRIu32 ", "
60    "free space = %" PRIu32 "\n",
61    info.Used.number,
62    info.Used.largest,
63    info.Used.total,
64    info.Free.number,
65    info.Free.largest,
66    info.Free.total
67  );
68}
69
70static rtems_task Init(rtems_task_argument argument)
71{
72  rtems_status_code sc = RTEMS_SUCCESSFUL;
73  rtems_name name = rtems_build_name('S', 'T', 'K', 'A');
74  rtems_id id = RTEMS_ID_NONE;
75  int i = 0;
76
77  TEST_BEGIN();
78
79  print_info();
80
81  for (i = 2; i < TASK_COUNT; ++i) {
82    sc = rtems_task_create(
83      name,
84      RTEMS_MINIMUM_PRIORITY,
85      RTEMS_MINIMUM_STACK_SIZE,
86      RTEMS_DEFAULT_MODES,
87      RTEMS_DEFAULT_ATTRIBUTES,
88      &id
89    );
90    directive_failed(sc, "rtems_task_create");
91  }
92
93  sc = rtems_task_create(
94    name,
95    RTEMS_MINIMUM_PRIORITY,
96    2 * RTEMS_MINIMUM_STACK_SIZE,
97    RTEMS_DEFAULT_MODES,
98    RTEMS_DEFAULT_ATTRIBUTES,
99    &id
100  );
101  fatal_directive_status(sc, RTEMS_UNSATISFIED, "rtems_task_create");
102
103  sc = rtems_task_create(
104    name,
105    RTEMS_MINIMUM_PRIORITY,
106    RTEMS_MINIMUM_STACK_SIZE,
107    RTEMS_DEFAULT_MODES,
108    RTEMS_DEFAULT_ATTRIBUTES,
109    &id
110  );
111  directive_failed(sc, "rtems_task_create");
112
113  print_info();
114
115  TEST_END();
116
117  rtems_test_exit(0);
118}
119
120#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
121#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
122
123#define CONFIGURE_MAXIMUM_TASKS TASK_COUNT
124
125#define CONFIGURE_TASK_STACK_ALLOCATOR_INIT task_stack_init
126#define CONFIGURE_TASK_STACK_ALLOCATOR task_stack_allocate
127#define CONFIGURE_TASK_STACK_DEALLOCATOR task_stack_free
128#define CONFIGURE_TASK_STACK_ALLOCATOR_AVOIDS_WORK_SPACE
129#define CONFIGURE_TASK_STACK_FROM_ALLOCATOR(stack_size) \
130  ((stack_size) + HEAP_BLOCK_HEADER_SIZE + PAGE_SIZE - 1)
131
132#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
133
134#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
135
136#define CONFIGURE_INIT
137
138#include <rtems/confdefs.h>
139
140static char task_stack_space
141  [CONFIGURE_TASK_STACK_FROM_ALLOCATOR(CONFIGURE_STACK_SPACE_SIZE)];
142
143static void task_stack_init(size_t stack_space_size)
144{
145  bool ok = _Heap_Initialize(
146    &task_stack_heap,
147    task_stack_space,
148    sizeof(task_stack_space),
149    PAGE_SIZE
150  );
151
152  rtems_test_assert(stack_space_size == CONFIGURE_STACK_SPACE_SIZE);
153  rtems_test_assert(ok);
154}
155
156static void *task_stack_allocate(size_t stack_size)
157{
158  return _Heap_Allocate(&task_stack_heap, stack_size);
159}
160
161static void task_stack_free(void *addr)
162{
163  _Heap_Free(&task_stack_heap, addr);
164}
Note: See TracBrowser for help on using the repository browser.