source: rtems/testsuites/psxtests/psxspin02/test.c @ 6c2de60

4.115
Last change on this file since 6c2de60 was 6c2de60, checked in by Joel Sherrill <joel.sherrill@…>, on 05/11/12 at 19:12:11

psxtests - Eliminate missing prototype warnings

  • Property mode set to 100644
File size: 2.4 KB
Line 
1/**
2 *  @file
3 *
4 *  This test exercises the POSIX Spinlock manager.
5 */
6
7/*
8 *  COPYRIGHT (c) 1989-2012.
9 *  On-Line Applications Research Corporation (OAR).
10 *
11 *  The license and distribution terms for this file may be
12 *  found in the file LICENSE in this distribution or at
13 *  http://www.rtems.com/license/LICENSE.
14 */
15
16#ifdef HAVE_CONFIG_H
17#include "config.h"
18#endif
19
20#include "tmacros.h"
21#include <stdio.h>
22#include <errno.h>
23#include <stdlib.h>
24
25#include <pthread.h>
26
27#include <rtems.h>  /* for task creation */
28
29/* forward declarations to avoid warnings */
30int test_main(void);
31rtems_task SpinlockThread(rtems_task_argument arg);
32
33pthread_spinlock_t Spinlock;
34
35rtems_task SpinlockThread(rtems_task_argument arg)
36{
37  int  status;
38
39  puts( "pthread_spin_trylock( &Spinlock ) -- EBUSY" );
40  status = pthread_spin_trylock( &Spinlock );
41  rtems_test_assert( status == EBUSY );
42
43  puts( "pthread_spin_unlock( &Spinlock ) -- EPERM" );
44  status = pthread_spin_unlock( &Spinlock );
45  rtems_test_assert( status == EPERM );
46
47  rtems_task_delete( RTEMS_SELF );
48}
49
50/*
51 *  main entry point to the test
52 */
53
54#if defined(__rtems__)
55int test_main(void)
56#else
57int main(
58  int    argc,
59  char **argv
60)
61#endif
62{
63  int                   status;
64  rtems_status_code     rstatus;
65  rtems_id              taskid;
66
67  puts( "\n\n*** POSIX SPINLOCK TEST 02 ***" );
68
69  /* This successfully creates one */
70  puts( "pthread_spin_init( &Spinlock, PTHREAD_PROCESS_PRIVATE ) -- OK" );
71  status = pthread_spin_init( &Spinlock, PTHREAD_PROCESS_PRIVATE );
72  rtems_test_assert( status == 0 );
73
74  /* Lock it */
75  puts( "pthread_spin_lock( &Spinlock ) -- OK" );
76  status = pthread_spin_lock( &Spinlock );
77  rtems_test_assert( status == 0 );
78
79  /*  Create a helper task */
80  rstatus = rtems_task_create(
81     rtems_build_name( 'S', 'P', 'I', 'N' ),
82     1,
83     RTEMS_MINIMUM_STACK_SIZE,
84     RTEMS_DEFAULT_MODES,
85     RTEMS_DEFAULT_ATTRIBUTES,
86     &taskid
87  );
88  rtems_test_assert( rstatus == RTEMS_SUCCESSFUL );
89
90  rstatus = rtems_task_start( taskid, SpinlockThread, 0 );
91  rtems_test_assert( rstatus == RTEMS_SUCCESSFUL );
92
93  sleep(1);
94
95  puts( "pthread_spin_unlock( &Spinlock ) -- OK" );
96  status = pthread_spin_unlock( &Spinlock );
97  rtems_test_assert( status == 0 );
98
99  puts( "pthread_spin_destroy( &Spinlock ) -- OK" );
100  status = pthread_spin_destroy( &Spinlock );
101  rtems_test_assert( status == 0 );
102
103  /*************** END OF TEST *****************/
104  puts( "*** END OF POSIX SPINLOCK TEST 02 ***" );
105  exit(0);
106}
Note: See TracBrowser for help on using the repository browser.