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 08/06/13 at 14:10:26

PR766: Delete RTEMS_VIOLATE_KERNEL_VISIBILITY

  • Property mode set to 100644
File size: 2.5 KB
RevLine 
[c05f2010]1/*
[6c2de60]2 *  COPYRIGHT (c) 1989-2012.
[c05f2010]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
[cafefbf]10#ifdef HAVE_CONFIG_H
11#include "config.h"
12#endif
13
[c05f2010]14#include <pmacros.h>
15#include <errno.h>
16#include <pthread.h>
17#include <sched.h>
18
[218286bc]19#include <rtems/posix/pthreadimpl.h>
20#include <rtems/score/stackimpl.h>
[c05f2010]21
[6c2de60]22/* forward declarations to avoid warnings */
23void *POSIX_Init(void *argument);
24void *Test_Thread(void *argument);
25
[c05f2010]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;
[ea7d86b]58  struct timespec     delay_request;
[c05f2010]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);
[6baf5a5]64  rtems_test_assert( Stack_Low );
[c05f2010]65  Stack_High = Stack_Low + PTHREAD_MINIMUM_STACK_SIZE;
66
[b1274bd9]67  puts( "Init - Initialize thread attribute for user provided stack" );
[c05f2010]68  sc = pthread_attr_init( &attr );
[33c46f1]69  rtems_test_assert( !sc );
[c05f2010]70
71  sc = pthread_attr_setstackaddr( &attr, Stack_Low );
[33c46f1]72  rtems_test_assert( !sc );
[c05f2010]73
74  sc = pthread_attr_setstacksize( &attr, PTHREAD_MINIMUM_STACK_SIZE );
[33c46f1]75  rtems_test_assert( !sc );
[c05f2010]76
77  /* create threads */
78  sc = pthread_create( &id, &attr, Test_Thread, NULL );
[33c46f1]79  rtems_test_assert( !sc );
[c05f2010]80
81  puts( "Init - let other thread run" );
[ea7d86b]82  delay_request.tv_sec = 0;
83  delay_request.tv_nsec = 5 * 100000000;
84  sc = nanosleep( &delay_request, NULL );
[33c46f1]85  rtems_test_assert( !sc );
[c05f2010]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.