source: rtems/testsuites/sptests/spprivenv01/init.c @ c0d7e23

4.115
Last change on this file since c0d7e23 was c0d7e23, checked in by Joel Sherrill <joel.sherrill@…>, on 05/05/11 at 16:45:57

2011-05-05 Joel Sherrill <joel.sherrill@…>

  • sp09/screen12.c, sp09/sp09.scn, sp21/Makefile.am, sp35/priinv.c, sp39/init.c, sp50/init.c, sp57/init.c, sp72/init.c, sp73/init.c, spintrcritical01/init.c, spprivenv01/init.c, spsimplesched01/init.c, spsimplesched02/init.c: Remove warnings.
  • Property mode set to 100644
File size: 3.9 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2011.
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#ifdef HAVE_CONFIG_H
13#include "config.h"
14#endif
15
16#include <tmacros.h>
17#include "test_support.h"
18#include <rtems/libio_.h>
19#include <rtems/libcsupport.h>
20
21rtems_task task_routine( rtems_task_argument not_used )
22{
23  rtems_status_code sc;
24
25  puts( "task_routine - setting up a private environment" );
26
27  sc = rtems_libio_set_private_env();
28  directive_failed( sc, "set private env" );
29  sleep( 1 );
30
31  rtems_task_delete( RTEMS_SELF );
32}
33
34rtems_task Init(
35  rtems_task_argument argument
36)
37{
38  rtems_status_code       sc;
39  bool                    status;
40  void                   *alloc_ptr;
41  rtems_id                current_task_id;
42  rtems_id                task_id;
43  rtems_name              another_task_name;
44  Heap_Information_block  Info;
45 
46  puts( "\n\n*** TEST USER ENVIRONMENT ROUTINE - 01 ***" );
47
48  puts( "Init - allocating most of heap -- OK" );
49  alloc_ptr = malloc( malloc_free_space() - 4 );
50  rtems_test_assert( alloc_ptr != NULL );
51
52  puts( "Init - attempt to reset env - expect RTEMS_NO_MEMORY" );
53  sc = rtems_libio_set_private_env();
54  rtems_test_assert( sc == RTEMS_NO_MEMORY );
55
56  puts( "Init - freeing the allocated memory" );
57  free( alloc_ptr );
58
59  puts( "Init - allocating most of workspace memory" );
60  status = rtems_workspace_get_information( &Info );
61  rtems_test_assert( status == true );
62  status = rtems_workspace_allocate( Info.Free.largest - 4, &alloc_ptr );
63  rtems_test_assert( status == true );
64 
65  puts( "Init - attempt to reset env - expect RTEMS_NO_MEMORY" );
66  sc = rtems_libio_set_private_env();
67  rtems_test_assert( sc == RTEMS_NO_MEMORY );
68
69  puts( "Init - freeing the workspace memory" );
70  status = rtems_workspace_free( alloc_ptr );
71  rtems_test_assert( status == true );
72
73  puts( "Init - creating a task name and a task -- OK" );
74
75  another_task_name =
76    rtems_build_name( 'T','S','K','D' );
77
78  sc = rtems_task_create( another_task_name,
79                          1,
80                          RTEMS_MINIMUM_STACK_SIZE * 2,
81                          RTEMS_INTERRUPT_LEVEL(31),
82                          RTEMS_DEFAULT_ATTRIBUTES,
83                          &task_id
84                          );
85
86  puts( "Init - starting the task_routine, to set its private environment" );
87  status = rtems_task_start( task_id, task_routine, 0);
88  rtems_test_assert(status == 0);
89
90  puts( "Init - attempt to share the env with another task -- Expect error" );
91  sc = rtems_libio_share_private_env( task_id );
92  rtems_test_assert( sc == RTEMS_INVALID_ADDRESS );
93
94  sleep( 1 );
95
96  puts( "Init - attempt to share the env with another task -- OK" );
97  sc = rtems_libio_share_private_env( task_id );
98  rtems_test_assert( sc == RTEMS_SUCCESSFUL );
99  rtems_test_assert( rtems_current_user_env->task_id == task_id );
100
101  puts( "Init - Get current task id" );
102  current_task_id = rtems_task_self();
103
104  puts( "Init - Attempt to reset current task's environment" );
105  sc = rtems_libio_set_private_env();
106  rtems_test_assert( sc == RTEMS_SUCCESSFUL );
107  rtems_test_assert( rtems_current_user_env->task_id == current_task_id );
108 
109  puts( "Init - attempt to share the env with another task -- OK" );
110  sc = rtems_libio_share_private_env( task_id );
111  rtems_test_assert( sc == RTEMS_SUCCESSFUL );
112  rtems_test_assert( rtems_current_user_env->task_id == task_id );
113
114  puts( "Init - attempt to share with self -- OK" );
115  sc = rtems_libio_share_private_env( task_id );
116  rtems_test_assert( sc == RTEMS_SUCCESSFUL );
117
118  puts( "*** END OF TEST USER ENVIRONMENT ROUTINE - 01 ***" );
119
120  rtems_test_exit(0);
121}
122
123/* configuration information */
124
125#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
126#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
127
128#define CONFIGURE_MAXIMUM_TASKS             3
129#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
130
131#define CONFIGURE_INIT
132
133#include <rtems/confdefs.h>
134/* end of file */
Note: See TracBrowser for help on using the repository browser.