source: rtems/testsuites/psxtests/psxstack01/init.c @ 147e4ac

4.104.115
Last change on this file since 147e4ac was c05f2010, checked in by Joel Sherrill <joel.sherrill@…>, on 08/07/09 at 00:42:47

2009-08-06 Joel Sherrill <joel.sherrill@…>

  • Makefile.am, configure.ac: Add test case for user providing their own stack to a POSIX thread.
  • psxstack01/.cvsignore, psxstack01/Makefile.am, psxstack01/init.c, psxstack01/psxstack01.doc, psxstack01/psxstack01.scn: New files.
  • Property mode set to 100644
File size: 2.3 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                 i;
50  int                 sc;
51  pthread_t           id;
52  pthread_attr_t      attr;
53
54  puts( "\n\n*** POSIX STACK ATTRIBUTE TEST 01 ***" );
55
56  puts( "Init - Allocate stack from heap" );
57  Stack_Low = malloc(PTHREAD_MINIMUM_STACK_SIZE);
58  assert( Stack_Low );
59  Stack_High = Stack_Low + PTHREAD_MINIMUM_STACK_SIZE;
60
61  puts( "Init - Initialize thread attribute for user provided stack" );
62  sc = pthread_attr_init( &attr );
63  assert( !sc );
64
65  sc = pthread_attr_setstackaddr( &attr, Stack_Low );
66  assert( !sc );
67
68  sc = pthread_attr_setstacksize( &attr, PTHREAD_MINIMUM_STACK_SIZE );
69  assert( !sc );
70
71  /* create threads */
72  sc = pthread_create( &id, &attr, Test_Thread, NULL );
73  assert( !sc );
74
75  puts( "Init - let other thread run" );
76  usleep( 500000 );
77
78  puts( "*** END OF POSIX STACK ATTRIBUTE TEST 01 ***" );
79  rtems_test_exit(0);
80
81  return NULL; /* just so the compiler thinks we returned something */
82}
83
84/* configuration information */
85
86#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
87#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
88
89#define CONFIGURE_MAXIMUM_POSIX_THREADS        2
90
91#define CONFIGURE_POSIX_INIT_THREAD_TABLE
92
93#define CONFIGURE_INIT
94#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.