1 /* This test is designed to test the semaphore suspension and timeout functionality. */
2
3 #include <stdio.h>
4 #include "tx_api.h"
5
6 //static unsigned long thread_0_counter = 0;
7 static TX_THREAD thread_0;
8
9 static TX_SEMAPHORE semaphore_0;
10 static TX_SEMAPHORE semaphore_1;
11
12
13 /* Define thread prototypes. */
14
15 static void thread_0_entry(ULONG thread_input);
16
17
18 /* Prototype for test control return. */
19
20 void test_control_return(UINT status);
21
22
put_notify(TX_SEMAPHORE * semaphore_ptr)23 static void put_notify(TX_SEMAPHORE *semaphore_ptr)
24 {
25
26 /* Don't need to do anything in here... */
27 }
28
29 /* Define what the initial system looks like. */
30
31 #ifdef CTEST
test_application_define(void * first_unused_memory)32 void test_application_define(void *first_unused_memory)
33 #else
34 void threadx_semaphore_timeout_application_define(void *first_unused_memory)
35 #endif
36 {
37
38 UINT status;
39 CHAR *pointer;
40
41
42 /* Put first available memory address into a character pointer. */
43 pointer = (CHAR *) first_unused_memory;
44
45 /* Put system definition stuff in here, e.g. thread creates and other assorted
46 create information. */
47
48 status = tx_thread_create(&thread_0, "thread 0", thread_0_entry, 1,
49 pointer, TEST_STACK_SIZE_PRINTF,
50 16, 16, 100, TX_AUTO_START);
51 pointer = pointer + TEST_STACK_SIZE_PRINTF;
52
53 /* Check for status. */
54 if (status != TX_SUCCESS)
55 {
56
57 printf("Running Semaphore Suspension Timeout Test........................... ERROR #1\n");
58 test_control_return(1);
59 }
60
61 /* Create a semaphore with an initial count of 0. */
62 status = tx_semaphore_create(&semaphore_0, "semaphore 0", 0);
63
64 /* Check for status. */
65 if (status != TX_SUCCESS)
66 {
67
68 printf("Running Semaphore Suspension Timeout Test........................... ERROR #2\n");
69 test_control_return(1);
70 }
71
72 /* Setup the semaphore notify callback. */
73 status = tx_semaphore_put_notify(&semaphore_0, put_notify);
74
75 #ifndef TX_DISABLE_NOTIFY_CALLBACKS
76
77 /* Check for status. */
78 if (status != TX_SUCCESS)
79 {
80
81 printf("Running Semaphore Suspension Timeout Test........................... ERROR #3\n");
82 test_control_return(1);
83 }
84
85 #else
86
87 /* Check for status. */
88 if (status != TX_FEATURE_NOT_ENABLED)
89 {
90
91 printf("Running Semaphore Suspension Timeout Test........................... ERROR #4\n");
92 test_control_return(1);
93 }
94
95 #endif
96
97 }
98
99
100
101 /* Define the test threads. */
102
thread_0_entry(ULONG thread_input)103 static void thread_0_entry(ULONG thread_input)
104 {
105
106 UINT status;
107
108 /* Inform user. */
109 printf("Running Semaphore Suspension Timeout Test........................... ");
110
111 #ifndef TX_DISABLE_ERROR_CHECKING
112
113 /* Attempt to setup semaphore notify callback on non-semaphore. */
114 status = tx_semaphore_put_notify(TX_NULL, put_notify);
115
116 /* Check status */
117 if (status != TX_SEMAPHORE_ERROR)
118 {
119
120 /* Semaphore error. */
121 printf("ERROR #5\n");
122 test_control_return(1);
123 }
124
125 /* Attempt to setup semaphore notify callback on non-created semaphore. */
126 semaphore_1.tx_semaphore_id = 0;
127 status = tx_semaphore_put_notify(&semaphore_1, put_notify);
128
129 /* Check status */
130 if (status != TX_SEMAPHORE_ERROR)
131 {
132
133 /* Semaphore error. */
134 printf("ERROR #6\n");
135 test_control_return(1);
136 }
137 #endif
138
139 /* Sleep for 2 ticks for fresh timer. */
140 tx_thread_sleep(2);
141
142 /* Set clock to 0. */
143 tx_time_set(0);
144
145 /* Suspend on the semaphore. */
146 status = tx_semaphore_get(&semaphore_0, 33);
147
148 /* Did we get the right status at the right time? */
149 if ((status != TX_NO_INSTANCE) || (tx_time_get() != 33))
150 {
151
152 /* Semaphore error. */
153 printf("ERROR #7\n");
154 test_control_return(1);
155 }
156 else
157 {
158
159 /* Successful test. */
160 printf("SUCCESS!\n");
161 test_control_return(0);
162 }
163 }
164
165
166