1 /* This test is designed to test for preemption-threshold use during thread creation during initialization.  */
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 unsigned long   thread_1_counter =  0;
10 static TX_THREAD       thread_1;
11 
12 static unsigned long   thread_2_counter =  0;
13 static TX_THREAD       thread_2;
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 
22 
23 /* Prototype for test control return.  */
24 void  test_control_return(UINT status);
25 
26 
27 /* Define what the initial system looks like.  */
28 
29 #ifdef CTEST
test_application_define(void * first_unused_memory)30 void test_application_define(void *first_unused_memory)
31 #else
32 void    threadx_thread_create_preemption_threshold_application_define(void *first_unused_memory)
33 #endif
34 {
35 
36 UINT    status;
37 CHAR    *pointer;
38 
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_2, "thread 2", thread_2_entry, 2,
47             pointer, TEST_STACK_SIZE_PRINTF,
48             17, 0, 100, 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 Create Preemption-Threshold from Init 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, 0, 100, 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 Create Preemption-Threshold from Init Test........... ERROR #2\n");
69         test_control_return(1);
70     }
71 
72     status =  tx_thread_create(&thread_0, "thread 0", thread_0_entry, 1,
73             pointer, TEST_STACK_SIZE_PRINTF,
74             15, 0, 100, TX_DONT_START);
75     status +=  tx_thread_resume(&thread_0);
76     pointer = pointer + TEST_STACK_SIZE_PRINTF;
77 
78     /* Check for status.  */
79     if (status != TX_SUCCESS)
80     {
81 
82         printf("Running Thread Create Preemption-Threshold from Init Test........... ERROR #3\n");
83         test_control_return(1);
84     }
85 }
86 
87 
88 
89 /* Define the test threads.  */
90 
thread_0_entry(ULONG thread_input)91 static void    thread_0_entry(ULONG thread_input)
92 {
93 
94     /* Inform user.  */
95     printf("Running Thread Create Preemption-Threshold from Init Test........... ");
96 
97     /* If either of the other threads have run, an error is present.  */
98     if ((thread_1_counter) || (thread_2_counter))
99     {
100 
101         /* Test error!  */
102         printf("ERROR #4\n");
103         test_control_return(1);
104     }
105 
106     /* Sleep for two ticks (one is insufficient to guarantee the other
107        tasks will run, if this executes too close to the tick interrupt.  */
108     tx_thread_sleep(2);
109 
110 
111     /* Now, both threads should have run.  */
112     if ((thread_1_counter != 1) || (thread_2_counter != 1))
113     {
114 
115         /* Test error!  */
116         printf("ERROR #5\n");
117         test_control_return(2);
118     }
119 
120     /* Successful test.  */
121     printf("SUCCESS!\n");
122     test_control_return(0);
123 }
124 
125 
thread_1_entry(ULONG thread_input)126 static void    thread_1_entry(ULONG thread_input)
127 {
128 
129     /* Increment this thread's counter.  */
130     thread_1_counter++;
131 }
132 
133 
thread_2_entry(ULONG thread_input)134 static void    thread_2_entry(ULONG thread_input)
135 {
136 
137     /* Increment the thread counter.  */
138     thread_2_counter++;
139 }
140 
141