source: rtems/testsuites/sptests/spstkalloc02/init.c @ 46231e1

4.115
Last change on this file since 46231e1 was 46231e1, checked in by Sebastian Huber <sebastian.huber@…>, on 12/14/11 at 13:18:01

2011-12-14 Sebastian Huber <sebastian.huber@…>

PR 1924/cpukit

  • spstkalloc02/.cvsignore, spstkalloc02/Makefile.am, spstkalloc02/init.c, spstkalloc02/spstkalloc02.doc, spstkalloc02/spstkalloc02.scn: New files.
  • Makefile.am, configure.ac: Reflect changes above.
  • 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.com/license/LICENSE.
21 *
22 * $Id$
23 */
24
25#ifdef HAVE_CONFIG_H
26  #include "config.h"
27#endif
28
29#include <tmacros.h>
30
31#include <stdio.h>
32#include <inttypes.h>
33
34#include <rtems/score/heap.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  puts("\n\n*** POSIX TEST STKALLOC 02 ***");
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  puts("*** END OF POSIX TEST STKALLOC 02 ***");
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_RTEMS_INIT_TASKS_TABLE
133
134#define CONFIGURE_INIT
135
136#include <rtems/confdefs.h>
137
138static char task_stack_space
139  [CONFIGURE_TASK_STACK_FROM_ALLOCATOR(CONFIGURE_STACK_SPACE_SIZE)];
140
141static void task_stack_init(size_t stack_space_size)
142{
143  bool ok = _Heap_Initialize(
144    &task_stack_heap,
145    task_stack_space,
146    sizeof(task_stack_space),
147    PAGE_SIZE
148  );
149
150  rtems_test_assert(stack_space_size == CONFIGURE_STACK_SPACE_SIZE);
151  rtems_test_assert(ok);
152}
153
154static void *task_stack_allocate(size_t stack_size)
155{
156  return _Heap_Allocate(&task_stack_heap, stack_size);
157}
158
159static void task_stack_free(void *addr)
160{
161  _Heap_Free(&task_stack_heap, addr);
162}
Note: See TracBrowser for help on using the repository browser.