1 /* This test is designed to test multiple threads sleeping for 33 ticks.  */
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 static unsigned long   thread_1_counter =  0;
9 static TX_THREAD       thread_1;
10 static unsigned long   thread_2_counter =  0;
11 static TX_THREAD       thread_2;
12 //static unsigned long   thread_3_counter =  0;
13 static TX_THREAD       thread_3;
14 
15 
16 /* Define thread prototypes.  */
17 
18 static void    thread_0_entry(ULONG thread_input);
19 static void    thread_1_entry(ULONG thread_input);
20 static void    thread_2_entry(ULONG thread_input);
21 static void    thread_3_entry(ULONG thread_input);
22 
23 
24 /* Prototype for test control return.  */
25 void  test_control_return(UINT status);
26 
27 
28 /* Define what the initial system looks like.  */
29 
30 #ifdef CTEST
test_application_define(void * first_unused_memory)31 void test_application_define(void *first_unused_memory)
32 #else
33 void    threadx_thread_multiple_sleep_application_define(void *first_unused_memory)
34 #endif
35 {
36 
37 UINT    status;
38 CHAR    *pointer;
39 
40     /* Put first available memory address into a character pointer.  */
41     pointer =  (CHAR *) first_unused_memory;
42 
43     /* Put system definition stuff in here, e.g. thread creates and other assorted
44        create information.  */
45 
46     status =  tx_thread_create(&thread_0, "thread 0", thread_0_entry, 1,
47             pointer, TEST_STACK_SIZE_PRINTF,
48             16, 16, 3, TX_AUTO_START);
49     pointer = pointer + TEST_STACK_SIZE_PRINTF;
50 
51     /* Check for status.  */
52     if (status != TX_SUCCESS)
53     {
54 
55         printf("Running Thread Multiple Thread Sleep for 33 Test.................... ERROR #1\n");
56         test_control_return(1);
57     }
58 
59     status =  tx_thread_create(&thread_1, "thread 1", thread_1_entry, 1,
60             pointer, TEST_STACK_SIZE_PRINTF,
61             16, 16, 3, TX_AUTO_START);
62     pointer = pointer + TEST_STACK_SIZE_PRINTF;
63 
64     /* Check for status.  */
65     if (status != TX_SUCCESS)
66     {
67 
68         printf("Running Thread Multiple Thread Sleep for 33 Test.................... ERROR #2\n");
69         test_control_return(1);
70     }
71 
72     status =  tx_thread_create(&thread_2, "thread 2", thread_2_entry, 1,
73             pointer, TEST_STACK_SIZE_PRINTF,
74             16, 16, 3, TX_AUTO_START);
75     pointer = pointer + TEST_STACK_SIZE_PRINTF;
76 
77     /* Check for status.  */
78     if (status != TX_SUCCESS)
79     {
80 
81         printf("Running Thread Multiple Thread Sleep for 33 Test.................... ERROR #3\n");
82         test_control_return(1);
83     }
84 
85     status =  tx_thread_create(&thread_3, "thread 3", thread_3_entry, 1,
86             pointer, TEST_STACK_SIZE_PRINTF,
87             15, 15, 3, TX_AUTO_START);
88     pointer = pointer + TEST_STACK_SIZE_PRINTF;
89 
90     /* Check for status.  */
91     if (status != TX_SUCCESS)
92     {
93 
94         printf("Running Thread Multiple Thread Sleep for 33 Test.................... ERROR #4\n");
95         test_control_return(1);
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 
107     /* Enter into a forever loop.  */
108     while(1)
109     {
110 
111         /* Increment thread 0 counter.  */
112         thread_0_counter++;
113 
114         /* Sleep for a couple ticks.  */
115         tx_thread_sleep(33);
116     }
117 }
118 
119 
thread_1_entry(ULONG thread_input)120 static void    thread_1_entry(ULONG thread_input)
121 {
122 
123 
124     /* Enter into a forever loop.  */
125     while(1)
126     {
127 
128         /* Increment thread 1 counter.  */
129         thread_1_counter++;
130 
131         /* Sleep for a couple ticks.  */
132         tx_thread_sleep(33);
133     }
134 }
135 
136 
thread_2_entry(ULONG thread_input)137 static void    thread_2_entry(ULONG thread_input)
138 {
139 
140 
141     /* Enter into a forever loop.  */
142     while(1)
143     {
144 
145         /* Increment thread 0 counter.  */
146         thread_2_counter++;
147 
148         /* Sleep for a couple ticks.  */
149         tx_thread_sleep(33);
150     }
151 }
152 
153 
thread_3_entry(ULONG thread_input)154 static void    thread_3_entry(ULONG thread_input)
155 {
156 
157 
158     /* Inform user.  */
159     printf("Running Thread Multiple Thread Sleep for 33 Test.................... ");
160 
161     /* Clear the tick count. */
162     tx_time_set(0);
163 
164     /* Sleep for 100 ticks (+1 in case tick before threads 0,1,2 have run). */
165     tx_thread_sleep(101);
166 
167     /* Determine if the sleep was accurate.  */
168     if ((thread_0_counter == 4) && (thread_1_counter == 4) &&
169         (thread_2_counter == 4))
170     {
171 
172         /* Successful Multiple Sleep test.  */
173         printf("SUCCESS!\n");
174         test_control_return(0);
175     }
176     else
177     {
178 
179         /* Thread Multiple Sleep error.  */
180         printf("ERROR #5\n");
181         test_control_return(1);
182     }
183 }
184 
185