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