1 /* Define the ThreadX SMP one thread dynamic thread exclusion test.  */
2 
3 #include   <stdio.h>
4 #include   "tx_api.h"
5 
6 
7 
8 static TX_THREAD       thread_0;
9 
10 
11 static ULONG       thread_0_counter;
12 
13 
14 static unsigned long error =  0;
15 
16 
17 /* Define thread prototypes.  */
18 
19 static void    thread_0_entry(ULONG thread_input);
20 
21 
22 /* Prototype for test control return.  */
23 
24 void  test_control_return(UINT status);
25 
26 
27 
28 
29 
30 /* Define what the initial system looks like.  */
31 
32 #ifdef CTEST
test_application_define(void * first_unused_memory)33 void test_application_define(void *first_unused_memory)
34 #else
35 void    threadx_smp_one_thread_dynamic_exclusion_test(void *first_unused_memory)
36 #endif
37 {
38 
39 UINT    status;
40 CHAR    *pointer;
41 
42 
43     /* Put first available memory address into a character pointer.  */
44     pointer =  (CHAR *) first_unused_memory;
45 
46     /* Put system definition stuff in here, e.g. thread creates and other assorted
47        create information.  */
48 
49     status =  tx_thread_create(&thread_0, "thread 0", thread_0_entry, 0,
50             pointer, TEST_STACK_SIZE_PRINTF,
51             0, 0, TX_NO_TIME_SLICE, TX_DONT_START);
52     pointer =  pointer + TEST_STACK_SIZE_PRINTF;
53     status +=   tx_thread_smp_core_exclude(&thread_0, 0x0);      /* No exclusions! */
54 
55     /* Check status.  */
56     if (status != TX_SUCCESS)
57     {
58 
59         printf("Running SMP One Thread Dynamic Exclusion Test....................... ERROR #1\n");
60         test_control_return(1);
61     }
62 
63 
64 	/* Resume thread 0.  */
65     status =  tx_thread_resume(&thread_0);
66 
67 	/* Check status.  */
68     if (status != TX_SUCCESS)
69     {
70 
71         printf("Running SMP One Thread Dynamic Exclusion Test....................... ERROR #2\n");
72         test_control_return(1);
73     }
74 }
75 
76 
77 
78 /* Define the test threads.  */
79 
thread_0_entry(ULONG thread_input)80 static void    thread_0_entry(ULONG thread_input)
81 {
82 
83 UINT    status;
84 
85 
86 
87     /* Inform user.  */
88     printf("Running SMP One Thread Dynamic Exclusion Test....................... ");
89 
90     /* Move to core 1.  */
91     status =   tx_thread_smp_core_exclude(&thread_0, 0xD);      /* Only core 1! */
92 
93     /* Determine if the test was successful or there was an error.  */
94     if ((status != TX_SUCCESS) || (tx_thread_smp_core_get() != 1))
95     {
96 
97         /* Execution error.  */
98         printf("ERROR #3\n");
99         test_control_return(1);
100     }
101 
102     /* Move to core 2.  */
103     status =   tx_thread_smp_core_exclude(&thread_0, 0xB);      /* Only core 2! */
104 
105     /* Determine if the test was successful or there was an error.  */
106     if ((status != TX_SUCCESS) || (tx_thread_smp_core_get() != 2))
107     {
108 
109         /* Execution error.  */
110         printf("ERROR #4\n");
111         test_control_return(1);
112     }
113 
114     /* Move to core 3.  */
115     status =   tx_thread_smp_core_exclude(&thread_0, 0x7);      /* Only core 3! */
116 
117     /* Determine if the test was successful or there was an error.  */
118     if ((status != TX_SUCCESS) || (tx_thread_smp_core_get() != 3))
119     {
120 
121         /* Execution error.  */
122         printf("ERROR #4\n");
123         test_control_return(1);
124     }
125 
126     /* Move back to core 0.  */
127     status =   tx_thread_smp_core_exclude(&thread_0, 0xE);      /* Only core 0! */
128 
129     /* Determine if the test was successful or there was an error.  */
130     if ((status != TX_SUCCESS) || (tx_thread_smp_core_get() != 0))
131     {
132 
133         /* Execution error.  */
134         printf("ERROR #5\n");
135         test_control_return(1);
136     }
137     else
138     {
139 
140         /* Successful test.  */
141         printf("SUCCESS!\n");
142         test_control_return(0);
143     }
144 }
145 
146