1 | /* |
---|
2 | * COPYRIGHT (c) 2016. |
---|
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 <pthread.h> |
---|
16 | #include <time.h> |
---|
17 | #include <errno.h> |
---|
18 | |
---|
19 | const char rtems_test_name[] = "PSXCOND 2"; |
---|
20 | |
---|
21 | /* forward declarations to avoid warnings */ |
---|
22 | void *POSIX_Init(void *argument); |
---|
23 | |
---|
24 | static void test_exercise_clock_attribute_errors(void) |
---|
25 | { |
---|
26 | int sc; |
---|
27 | pthread_condattr_t attr; |
---|
28 | clockid_t clock; |
---|
29 | |
---|
30 | /* NULL attribute pointer errors */ |
---|
31 | puts( "pthread_condattr_getclock (NULL attribute) - EINVAL" ); |
---|
32 | sc = pthread_condattr_getclock( NULL, &clock ); |
---|
33 | fatal_posix_service_status( sc, EINVAL, "condattr getclock" ); |
---|
34 | |
---|
35 | puts( "pthread_condattr_getclock (NULL clock) - EINVAL" ); |
---|
36 | sc = pthread_condattr_getclock( &attr, NULL ); |
---|
37 | fatal_posix_service_status( sc, EINVAL, "condattr getclock" ); |
---|
38 | |
---|
39 | puts( "pthread_condattr_setclock (NULL attribute) - EINVAL" ); |
---|
40 | sc = pthread_condattr_setclock( NULL, CLOCK_REALTIME ); |
---|
41 | fatal_posix_service_status( sc, EINVAL, "condattr setclock" ); |
---|
42 | |
---|
43 | /* invalid clock errors */ |
---|
44 | puts( "pthread_condattr_init - OK" ); |
---|
45 | sc = pthread_condattr_init( &attr ); |
---|
46 | fatal_posix_service_status( sc, 0, "condattr init" ); |
---|
47 | |
---|
48 | puts( "pthread_condattr_setclock (bad clock)- EINVAL" ); |
---|
49 | sc = pthread_condattr_setclock( &attr, -1 ); |
---|
50 | fatal_posix_service_status( sc, EINVAL, "condattr setclock" ); |
---|
51 | |
---|
52 | puts( "pthread_condattr_setclock (CLOCK_PROCESS_CPUTIME_ID)- EINVAL" ); |
---|
53 | sc = pthread_condattr_setclock( &attr, CLOCK_PROCESS_CPUTIME_ID ); |
---|
54 | fatal_posix_service_status( sc, EINVAL, "condattr setclock" ); |
---|
55 | |
---|
56 | puts( "pthread_condattr_setclock (CLOCK_THREAD_CPUTIME_ID)- EINVAL" ); |
---|
57 | sc = pthread_condattr_setclock( &attr, CLOCK_THREAD_CPUTIME_ID ); |
---|
58 | fatal_posix_service_status( sc, EINVAL, "condattr setclock" ); |
---|
59 | } |
---|
60 | |
---|
61 | static void test_exercise_clock_attribute(void) |
---|
62 | { |
---|
63 | int sc; |
---|
64 | pthread_condattr_t attr; |
---|
65 | |
---|
66 | puts( "pthread_condattr_init - OK" ); |
---|
67 | sc = pthread_condattr_init( &attr ); |
---|
68 | fatal_posix_service_status( sc, 0, "condattr init" ); |
---|
69 | |
---|
70 | puts( "pthread_condattr_setclock (CLOCK_REALTIME)- OK" ); |
---|
71 | sc = pthread_condattr_setclock( &attr, CLOCK_REALTIME ); |
---|
72 | fatal_posix_service_status( sc, 0, "condattr setclock" ); |
---|
73 | |
---|
74 | puts( "pthread_condattr_setclock (CLOCK_MONOTONIC)- OK" ); |
---|
75 | sc = pthread_condattr_setclock( &attr, CLOCK_MONOTONIC ); |
---|
76 | fatal_posix_service_status( sc, 0, "condattr setclock" ); |
---|
77 | } |
---|
78 | |
---|
79 | void *POSIX_Init( |
---|
80 | void *argument |
---|
81 | ) |
---|
82 | { |
---|
83 | TEST_BEGIN(); |
---|
84 | |
---|
85 | test_exercise_clock_attribute_errors(); |
---|
86 | |
---|
87 | test_exercise_clock_attribute(); |
---|
88 | |
---|
89 | TEST_END(); |
---|
90 | rtems_test_exit( 0 ); |
---|
91 | |
---|
92 | return NULL; /* just so the compiler thinks we returned something */ |
---|
93 | } |
---|
94 | |
---|
95 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
96 | #define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER |
---|
97 | |
---|
98 | #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION |
---|
99 | |
---|
100 | #define CONFIGURE_MAXIMUM_POSIX_THREADS 1 |
---|
101 | |
---|
102 | #define CONFIGURE_POSIX_INIT_THREAD_TABLE |
---|
103 | |
---|
104 | #define CONFIGURE_INIT |
---|
105 | #include <rtems/confdefs.h> |
---|