source: rtems/testsuites/psxtests/psxstack01/init.c @ 1e17848

4.104.115
Last change on this file since 1e17848 was b6912c40, checked in by Ralf Corsepius <ralf.corsepius@…>, on 10/25/09 at 06:25:04

Remove unused vars.
Add missing prototypes.

  • Property mode set to 100644
File size: 2.2 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#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__
13#include <pmacros.h>
14#include <errno.h>
15#include <pthread.h>
16#include <sched.h>
17
18#include <rtems/posix/pthread.h> /* for PTHREAD_MINIMUM_STACK_SIZE */
19
20void *Stack_Low;
21void *Stack_High;
22
23void *Test_Thread(void *arg)
24{
25  #if defined(__GNUC__)
26    void *sp = __builtin_frame_address(0);
27
28    #if 0
29      printf( "Stack(%p - %p) and sp=%p\n", Stack_Low, Stack_High, sp );
30    #endif
31
32    if ( sp >= Stack_Low && sp <= Stack_High )
33      puts( "Test_Thread - running on user provided stack - OK" );
34    else {
35      puts( "Test_Thread - ERROR running on other stack" );
36      rtems_test_exit(0);
37    }
38  #else
39      puts( "Test_Thread - no way to get stack pointer and verify" );
40  #endif
41  puts( "Test_Thread - delete self" );
42  return NULL;
43}
44
45void *POSIX_Init(
46  void *argument
47)
48{
49  int                 sc;
50  pthread_t           id;
51  pthread_attr_t      attr;
52
53  puts( "\n\n*** POSIX STACK ATTRIBUTE TEST 01 ***" );
54
55  puts( "Init - Allocate stack from heap" );
56  Stack_Low = malloc(PTHREAD_MINIMUM_STACK_SIZE);
57  assert( Stack_Low );
58  Stack_High = Stack_Low + PTHREAD_MINIMUM_STACK_SIZE;
59
60  puts( "Init - Initialize thread attribute for user provided stack" );
61  sc = pthread_attr_init( &attr );
62  assert( !sc );
63
64  sc = pthread_attr_setstackaddr( &attr, Stack_Low );
65  assert( !sc );
66
67  sc = pthread_attr_setstacksize( &attr, PTHREAD_MINIMUM_STACK_SIZE );
68  assert( !sc );
69
70  /* create threads */
71  sc = pthread_create( &id, &attr, Test_Thread, NULL );
72  assert( !sc );
73
74  puts( "Init - let other thread run" );
75  usleep( 500000 );
76
77  puts( "*** END OF POSIX STACK ATTRIBUTE TEST 01 ***" );
78  rtems_test_exit(0);
79
80  return NULL; /* just so the compiler thinks we returned something */
81}
82
83/* configuration information */
84
85#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
86#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
87
88#define CONFIGURE_MAXIMUM_POSIX_THREADS        2
89
90#define CONFIGURE_POSIX_INIT_THREAD_TABLE
91
92#define CONFIGURE_INIT
93#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.