source: rtems/testsuites/psxtests/psxstack02/init.c @ 698c2e50

4.115
Last change on this file since 698c2e50 was 698c2e50, checked in by Sebastian Huber <sebastian.huber@…>, on 03/25/14 at 07:06:16

tests/psxtests: Use <rtems/test.h>

  • 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.org/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
24const char rtems_test_name[] = "PSXSTACK 2";
25
26/* forward declarations to avoid warnings */
27void *POSIX_Init(void *argument);
28void *Test_Thread(void *arg);
29
30void *Stack_Low;
31void *Stack_High;
32
33void *Test_Thread(void *arg)
34{
35  #if defined(__GNUC__)
36    void *sp = __builtin_frame_address(0);
37
38    #if 0
39      printf( "Stack(%p - %p) and sp=%p\n", Stack_Low, Stack_High, sp );
40    #endif
41
42    if ( sp >= Stack_Low && sp <= Stack_High )
43      puts( "Test_Thread - running on user provided stack - OK" );
44    else {
45      puts( "Test_Thread - ERROR running on other stack" );
46      rtems_test_exit(0);
47    }
48  #else
49      puts( "Test_Thread - no way to get stack pointer and verify" );
50  #endif
51  puts( "Test_Thread - delete self" );
52  return NULL;
53}
54
55void *POSIX_Init(void *argument)
56{
57#if HAVE_DECL_PTHREAD_ATTR_SETSTACK
58  int                 sc;
59  pthread_t           id;
60  pthread_attr_t      attr;
61  struct timespec     delay_request;
62
63  TEST_BEGIN();
64
65  puts( "Init - Allocate stack from heap" );
66  Stack_Low = malloc(PTHREAD_MINIMUM_STACK_SIZE);
67  rtems_test_assert( Stack_Low );
68  Stack_High = Stack_Low + PTHREAD_MINIMUM_STACK_SIZE;
69
70  puts( "Init - Initialize thread attribute for user provided stack" );
71  sc = pthread_attr_init( &attr );
72  rtems_test_assert( !sc );
73
74  sc = pthread_attr_setstack( &attr, Stack_Low, 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#else
87  puts( "pthread_set_stack not supported - SKIPPING TEST CASE" );
88#endif
89 
90  TEST_END();
91
92  rtems_test_exit(0);
93}
94
95/* configuration information */
96
97#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
98#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
99
100#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
101
102#define CONFIGURE_MAXIMUM_POSIX_THREADS        2
103
104#define CONFIGURE_POSIX_INIT_THREAD_TABLE
105
106#define CONFIGURE_INIT
107#include <rtems/confdefs.h>
108/* end of file */
Note: See TracBrowser for help on using the repository browser.