source: rtems/testsuites/psxtests/psxstack02/init.c @ ae75429

4.115
Last change on this file since ae75429 was ae75429, checked in by Sebastian Huber <sebastian.huber@…>, on Aug 6, 2013 at 2:10:26 PM

PR766: Delete RTEMS_VIOLATE_KERNEL_VISIBILITY

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