1 /* This test is designed to see if a thread can be created with a time-slice.
2 No time-slice occurs, only the processing to check for time-slicing. */
3
4 #include <stdio.h>
5 #include "tx_api.h"
6
7 static unsigned long thread_0_counter = 0;
8 static TX_THREAD thread_0;
9
10 static unsigned long thread_1_counter = 0;
11 static TX_THREAD thread_1;
12
13 /* Define thread prototypes. */
14
15 static void thread_0_entry(ULONG thread_input);
16 static void thread_1_entry(ULONG thread_input);
17
18
19 /* Prototype for test control return. */
20 void test_control_return(UINT status);
21
22
23 /* Define what the initial system looks like. */
24
25 #ifdef CTEST
test_application_define(void * first_unused_memory)26 void test_application_define(void *first_unused_memory)
27 #else
28 void threadx_thread_basic_time_slice_application_define(void *first_unused_memory)
29 #endif
30 {
31
32 UINT status;
33 UCHAR *memory;
34
35
36 memory = (UCHAR *) first_unused_memory;
37
38 /* Put system definition stuff in here, e.g. thread creates and other assorted
39 create information. */
40
41 status = tx_thread_create(&thread_0, "thread 0", thread_0_entry, 1,
42 memory, TEST_STACK_SIZE_PRINTF,
43 16, 16, 1, TX_AUTO_START);
44 memory = memory + TEST_STACK_SIZE_PRINTF;
45 status += tx_thread_create(&thread_1, "thread 1", thread_1_entry, 1,
46 memory, TEST_STACK_SIZE_PRINTF,
47 16, 16, 1, TX_DONT_START);
48 status += tx_thread_smp_core_exclude(&thread_1, 0xF);
49 status += tx_thread_resume(&thread_1);
50
51 /* Check for status. */
52 if (status != TX_SUCCESS)
53 {
54
55 printf("Running Thread Basic Time-Slice Test................................ ERROR #1\n");
56 test_control_return(1);
57 }
58 }
59
60
61
62 /* Define the test threads. */
63
thread_0_entry(ULONG thread_input)64 static void thread_0_entry(ULONG thread_input)
65 {
66
67 ULONG target_time;
68
69
70 /* Inform user. */
71 printf("Running Thread Basic Time-Slice Test................................ ");
72
73 /* Calculate the target running time. */
74 target_time = tx_time_get() + 20;
75
76 /* Enter into a forever loop. */
77 while(1)
78 {
79
80 /* Increment thread 0 counter. */
81 thread_0_counter++;
82
83 /* Determine if we are done. */
84 if (tx_time_get() >= target_time)
85 {
86
87 /* Determine if thread 1 executed. */
88 if (thread_1_counter != 0)
89 {
90
91 /* Error, thread 1 has all cores excluded so it should never run. */
92 printf("ERROR #2\n");
93 test_control_return(0);
94 }
95 else
96 {
97
98 /* Successful Time-slice test. */
99 printf("SUCCESS!\n");
100 test_control_return(0);
101 }
102 }
103 }
104 }
105
106
thread_1_entry(ULONG thread_input)107 static void thread_1_entry(ULONG thread_input)
108 {
109
110 /* Loop forever. */
111 while(1)
112 {
113
114 /* Increment counter. */
115 thread_1_counter++;
116 }
117 }
118