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.org/license/LICENSE. |
---|
14 | */ |
---|
15 | |
---|
16 | #ifdef HAVE_CONFIG_H |
---|
17 | #include "config.h" |
---|
18 | #endif |
---|
19 | |
---|
20 | #define TESTS_USE_PRINTK |
---|
21 | #include "tmacros.h" |
---|
22 | #include <stdio.h> |
---|
23 | #include <errno.h> |
---|
24 | #include <stdlib.h> |
---|
25 | |
---|
26 | #include <pthread.h> |
---|
27 | |
---|
28 | #include <rtems.h> /* for task creation */ |
---|
29 | |
---|
30 | const char rtems_test_name[] = "PSXSPIN 1"; |
---|
31 | |
---|
32 | /* forward declarations to avoid warnings */ |
---|
33 | int test_main(void); |
---|
34 | |
---|
35 | /* |
---|
36 | * main entry point to the test |
---|
37 | */ |
---|
38 | |
---|
39 | #if defined(__rtems__) |
---|
40 | int test_main(void) |
---|
41 | #else |
---|
42 | int main( |
---|
43 | int argc, |
---|
44 | char **argv |
---|
45 | ) |
---|
46 | #endif |
---|
47 | { |
---|
48 | pthread_spinlock_t spinlock; |
---|
49 | pthread_spinlock_t spinlock2; |
---|
50 | int status; |
---|
51 | |
---|
52 | TEST_BEGIN(); |
---|
53 | |
---|
54 | puts( "pthread_spin_init( &spinlock, PTHREAD_PROCESS_PRIVATE ) -- OK" ); |
---|
55 | status = pthread_spin_init( &spinlock, PTHREAD_PROCESS_PRIVATE ); |
---|
56 | rtems_test_assert( status == 0 ); |
---|
57 | |
---|
58 | puts( "pthread_spin_destroy( &spinlock ) -- OK" ); |
---|
59 | status = pthread_spin_destroy( &spinlock ); |
---|
60 | rtems_test_assert( status == 0 ); |
---|
61 | |
---|
62 | puts( "pthread_spin_init( &spinlock, PTHREAD_PROCESS_SHARED ) -- OK" ); |
---|
63 | status = pthread_spin_init( &spinlock, PTHREAD_PROCESS_PRIVATE ); |
---|
64 | rtems_test_assert( status == 0 ); |
---|
65 | |
---|
66 | puts( "pthread_spin_destroy( &spinlock ) -- OK" ); |
---|
67 | status = pthread_spin_destroy( &spinlock ); |
---|
68 | rtems_test_assert( status == 0 ); |
---|
69 | |
---|
70 | puts( "pthread_spin_init( &spinlock, 0x1234 ) -- OK" ); |
---|
71 | status = pthread_spin_init( &spinlock, 0x1234 ); |
---|
72 | rtems_test_assert( status == 0 ); |
---|
73 | |
---|
74 | puts( "pthread_spin_init( &spinlock2, 0 ) -- OK" ); |
---|
75 | status = pthread_spin_init( &spinlock2, 0 ); |
---|
76 | rtems_test_assert( status == 0 ); |
---|
77 | |
---|
78 | rtems_test_assert( _ISR_Get_level() == 0 ); |
---|
79 | |
---|
80 | puts( "pthread_spin_lock( &spinlock ) -- OK" ); |
---|
81 | status = pthread_spin_lock( &spinlock ); |
---|
82 | rtems_test_assert( status == 0 ); |
---|
83 | |
---|
84 | rtems_test_assert( _ISR_Get_level() != 0 ); |
---|
85 | |
---|
86 | puts( "pthread_spin_lock( &spinlock2 ) -- OK" ); |
---|
87 | status = pthread_spin_lock( &spinlock2 ); |
---|
88 | rtems_test_assert( status == 0 ); |
---|
89 | |
---|
90 | rtems_test_assert( _ISR_Get_level() != 0 ); |
---|
91 | |
---|
92 | puts( "pthread_spin_unlock( &spinlock2 ) -- OK" ); |
---|
93 | status = pthread_spin_unlock( &spinlock2 ); |
---|
94 | rtems_test_assert( status == 0 ); |
---|
95 | |
---|
96 | rtems_test_assert( _ISR_Get_level() != 0 ); |
---|
97 | |
---|
98 | puts( "pthread_spin_unlock( &spinlock ) -- OK" ); |
---|
99 | status = pthread_spin_unlock( &spinlock ); |
---|
100 | rtems_test_assert( status == 0 ); |
---|
101 | |
---|
102 | rtems_test_assert( _ISR_Get_level() == 0 ); |
---|
103 | |
---|
104 | puts( "pthread_spin_trylock( &spinlock ) -- OK" ); |
---|
105 | status = pthread_spin_trylock( &spinlock ); |
---|
106 | rtems_test_assert( status == 0 ); |
---|
107 | |
---|
108 | rtems_test_assert( _ISR_Get_level() != 0 ); |
---|
109 | |
---|
110 | puts( "pthread_spin_trylock( &spinlock2 ) -- OK" ); |
---|
111 | status = pthread_spin_trylock( &spinlock2 ); |
---|
112 | rtems_test_assert( status == 0 ); |
---|
113 | |
---|
114 | rtems_test_assert( _ISR_Get_level() != 0 ); |
---|
115 | |
---|
116 | puts( "pthread_spin_unlock( &spinlock2 ) -- OK" ); |
---|
117 | status = pthread_spin_unlock( &spinlock2 ); |
---|
118 | rtems_test_assert( status == 0 ); |
---|
119 | |
---|
120 | rtems_test_assert( _ISR_Get_level() != 0 ); |
---|
121 | |
---|
122 | puts( "pthread_spin_unlock( &spinlock ) -- OK" ); |
---|
123 | status = pthread_spin_unlock( &spinlock ); |
---|
124 | rtems_test_assert( status == 0 ); |
---|
125 | |
---|
126 | rtems_test_assert( _ISR_Get_level() == 0 ); |
---|
127 | |
---|
128 | puts( "pthread_spin_destroy( &spinlock2 ) -- OK" ); |
---|
129 | status = pthread_spin_destroy( &spinlock2 ); |
---|
130 | rtems_test_assert( status == 0 ); |
---|
131 | |
---|
132 | puts( "pthread_spin_destroy( &spinlock ) -- OK" ); |
---|
133 | status = pthread_spin_destroy( &spinlock ); |
---|
134 | rtems_test_assert( status == 0 ); |
---|
135 | |
---|
136 | TEST_END(); |
---|
137 | exit(0); |
---|
138 | } |
---|