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