source: rtems/testsuites/psxtests/psxstack01/init.c @ 6b4e448

4.115
Last change on this file since 6b4e448 was 218286bc, checked in by Sebastian Huber <sebastian.huber@…>, on 07/23/13 at 15:17:05

score: Create stack implementation header

Move implementation specific parts of stack.h and stack.inl into new
header file stackimpl.h. The stack.h contains now only the application
visible API.

  • Property mode set to 100644
File size: 2.6 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#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__
15#include <pmacros.h>
16#include <errno.h>
17#include <pthread.h>
18#include <sched.h>
19
20#include <rtems/posix/pthreadimpl.h>
21#include <rtems/score/stackimpl.h>
22
23/* forward declarations to avoid warnings */
24void *POSIX_Init(void *argument);
25void *Test_Thread(void *argument);
26
27void *Stack_Low;
28void *Stack_High;
29
30void *Test_Thread(void *arg)
31{
32  #if defined(__GNUC__)
33    void *sp = __builtin_frame_address(0);
34
35    #if 0
36      printf( "Stack(%p - %p) and sp=%p\n", Stack_Low, Stack_High, sp );
37    #endif
38
39    if ( sp >= Stack_Low && sp <= Stack_High )
40      puts( "Test_Thread - running on user provided stack - OK" );
41    else {
42      puts( "Test_Thread - ERROR running on other stack" );
43      rtems_test_exit(0);
44    }
45  #else
46      puts( "Test_Thread - no way to get stack pointer and verify" );
47  #endif
48  puts( "Test_Thread - delete self" );
49  return NULL;
50}
51
52void *POSIX_Init(
53  void *argument
54)
55{
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 01 ***" );
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_setstackaddr( &attr, Stack_Low );
73  rtems_test_assert( !sc );
74
75  sc = pthread_attr_setstacksize( &attr, PTHREAD_MINIMUM_STACK_SIZE );
76  rtems_test_assert( !sc );
77
78  /* create threads */
79  sc = pthread_create( &id, &attr, Test_Thread, NULL );
80  rtems_test_assert( !sc );
81
82  puts( "Init - let other thread run" );
83  delay_request.tv_sec = 0;
84  delay_request.tv_nsec = 5 * 100000000;
85  sc = nanosleep( &delay_request, NULL );
86  rtems_test_assert( !sc );
87
88  puts( "*** END OF POSIX STACK ATTRIBUTE TEST 01 ***" );
89  rtems_test_exit(0);
90
91  return NULL; /* just so the compiler thinks we returned something */
92}
93
94/* configuration information */
95
96#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
97#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
98
99#define CONFIGURE_MAXIMUM_POSIX_THREADS        2
100
101#define CONFIGURE_POSIX_INIT_THREAD_TABLE
102
103#define CONFIGURE_INIT
104#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.