source: rtems/testsuites/sptests/spstkalloc/init.c @ 62e6e7c

4.104.115
Last change on this file since 62e6e7c was 62e6e7c, checked in by Joel Sherrill <joel.sherrill@…>, on Jul 2, 2009 at 3:25:36 PM

2009-07-02 Joel Sherrill <joel.sherrill@…>

  • Makefile.am, configure.ac: Add new test for user configured stack allocator/deallocator. Test both pass and fail cases.
  • spstkalloc/.cvsignore, spstkalloc/Makefile.am, spstkalloc/init.c, spstkalloc/spstkalloc.doc, spstkalloc/spstkalloc.scn: New files.
  • Property mode set to 100644
File size: 2.1 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2009.
3 *  On-Line Applications Research Corporation (OAR).
4 *
5 *  The license and distribution terms for this file may be
6 *  found in the file LICENSE in this distribution or at
7 *  http://www.rtems.com/license/LICENSE.
8 *
9 *  $Id$
10 */
11
12#include <tmacros.h>
13
14#define MAXIMUM_STACKS 3
15
16typedef struct {
17  uint8_t Space[CPU_STACK_MINIMUM_SIZE];
18} StackMemory_t;
19
20int            stackToAlloc = 0;
21StackMemory_t  Stacks[3];
22void          *StackDeallocated = NULL;
23
24void *StackAllocator(uint32_t size)
25{
26  if (stackToAlloc < MAXIMUM_STACKS)
27    return &Stacks[stackToAlloc++];
28  return NULL;
29}
30
31void StackDeallocator(void *stack)
32{
33  StackDeallocated = stack;
34}
35
36rtems_task Init(
37  rtems_task_argument ignored
38)
39{
40  rtems_status_code rc; 
41  rtems_id          taskId;
42  rtems_id          taskId1;
43
44  puts( "\n\n*** TEST OF STACK ALLOCATOR PLUGIN ***" );
45
46  puts( "Init - create task TA1 to use custom stack allocator - OK" );
47  rc = rtems_task_create(
48     rtems_build_name( 'T', 'A', '1', ' ' ),
49     1,
50     RTEMS_MINIMUM_STACK_SIZE,
51     RTEMS_DEFAULT_MODES,
52     RTEMS_DEFAULT_ATTRIBUTES,
53     &taskId
54  );
55  directive_failed( rc, "rtems_task_create of TA1" );
56
57  puts( "Init - create task TA1 to have custom stack allocator fail" );
58  rc = rtems_task_create(
59     rtems_build_name( 'F', 'A', 'I', 'L' ),
60     1,
61     RTEMS_MINIMUM_STACK_SIZE,
62     RTEMS_DEFAULT_MODES,
63     RTEMS_DEFAULT_ATTRIBUTES,
64     &taskId1
65  );
66  fatal_directive_status( rc, RTEMS_UNSATISFIED, "rtems_task_create of FAIL" );
67
68  puts( "Init - delete task TA1 to use custom stack deallocator - OK" );
69  rc = rtems_task_delete( taskId );
70  directive_failed( rc, "rtems_task_delete of TA1" );
71
72  puts( "*** END OF OF STACK ALLOCATOR PLUGIN TEST ***" );
73  rtems_test_exit(0);
74}
75
76/* configuration information */
77
78#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
79#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
80
81#define CONFIGURE_TASK_STACK_ALLOCATOR    StackAllocator
82#define CONFIGURE_TASK_STACK_DEALLOCATOR  StackDeallocator
83
84#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
85#define CONFIGURE_MAXIMUM_TASKS 3
86
87#define CONFIGURE_INIT
88#include <rtems/confdefs.h>
89
90/* global variables */
Note: See TracBrowser for help on using the repository browser.