source: rtems/testsuites/psxtests/psxstack02/init.c @ 6baf5a5

4.115
Last change on this file since 6baf5a5 was 6baf5a5, checked in by Joel Sherrill <joel.sherrill@…>, on 10/04/10 at 15:53:45

2010-10-04 Joel Sherrill <joel.sherrill@…>

  • Makefile.am, configure.ac, psx07/init.c, psx07/psx07.scn, psxhdrs/Makefile.am, psxstack01/init.c: Add pthread_attr_getstack, pthread_attr_setstack, pthread_attr_getguardsize, and pthread_attr_setguardsize.
  • psxstack02/.cvsignore, psxstack02/Makefile.am, psxstack02/init.c, psxstack02/psxstack02.doc, psxstack02/psxstack02.scn: New files.
  • Property mode set to 100644
File size: 2.5 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2010.
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 <tmacros.h>
14#include "test_support.h"
15
16#include <errno.h>
17#include <pthread.h>
18#include <sched.h>
19
20#include <rtems/posix/pthread.h> /* for PTHREAD_MINIMUM_STACK_SIZE */
21
22void *Stack_Low;
23void *Stack_High;
24
25void *Test_Thread(void *arg)
26{
27  #if defined(__GNUC__)
28    void *sp = __builtin_frame_address(0);
29
30    #if 0
31      printf( "Stack(%p - %p) and sp=%p\n", Stack_Low, Stack_High, sp );
32    #endif
33
34    if ( sp >= Stack_Low && sp <= Stack_High )
35      puts( "Test_Thread - running on user provided stack - OK" );
36    else {
37      puts( "Test_Thread - ERROR running on other stack" );
38      rtems_test_exit(0);
39    }
40  #else
41      puts( "Test_Thread - no way to get stack pointer and verify" );
42  #endif
43  puts( "Test_Thread - delete self" );
44  return NULL;
45}
46
47void *POSIX_Init(
48  rtems_task_argument argument
49)
50{
51#if HAVE_DECL_PTHREAD_ATTR_SETSTACK
52  int                 sc;
53  pthread_t           id;
54  pthread_attr_t      attr;
55  struct timespec     delay_request;
56
57  puts( "\n\n*** POSIX STACK ATTRIBUTE TEST 02  ***" );
58
59  puts( "Init - Allocate stack from heap" );
60  Stack_Low = malloc(PTHREAD_MINIMUM_STACK_SIZE);
61  rtems_test_assert( Stack_Low );
62  Stack_High = Stack_Low + PTHREAD_MINIMUM_STACK_SIZE;
63
64  puts( "Init - Initialize thread attribute for user provided stack" );
65  sc = pthread_attr_init( &attr );
66  rtems_test_assert(  !sc );
67
68  sc = pthread_attr_setstack( &attr, Stack_Low, PTHREAD_MINIMUM_STACK_SIZE );
69  rtems_test_assert(  !sc );
70
71  /* create threads */
72  sc = pthread_create( &id, &attr, Test_Thread, NULL );
73  rtems_test_assert(  !sc );
74
75  puts( "Init - let other thread run" );
76  delay_request.tv_sec = 0;
77  delay_request.tv_nsec = 5 * 100000000;
78  sc = nanosleep( &delay_request, NULL );
79  rtems_test_assert( !sc );
80#else
81  puts( "pthread_set_stack not supported - SKIPPING TEST CASE" );
82#endif
83 
84  puts( "*** END OF POSIX STACK ATTRIBUTE TEST 02  ***" );
85
86  rtems_test_exit(0);
87}
88
89/* configuration information */
90
91#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
92#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
93
94#define CONFIGURE_MAXIMUM_POSIX_THREADS        2
95
96#define CONFIGURE_POSIX_INIT_THREAD_TABLE
97
98#define CONFIGURE_INIT
99#include <rtems/confdefs.h>
100/* end of file */
Note: See TracBrowser for help on using the repository browser.