1 /* This test is designed to test the change time-slice service call. */
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 extern unsigned long _tx_timer_time_slice;
13
14 /* Define thread prototypes. */
15
16 static void thread_0_entry(ULONG thread_input);
17 static void thread_1_entry(ULONG thread_input);
18
19
20 /* Prototype for test control return. */
21 void test_control_return(UINT status);
22
23
24 /* Define what the initial system looks like. */
25
26 #ifdef CTEST
test_application_define(void * first_unused_memory)27 void test_application_define(void *first_unused_memory)
28 #else
29 void threadx_thread_time_slice_change_application_define(void *first_unused_memory)
30 #endif
31 {
32
33 UINT status;
34 CHAR *pointer;
35
36 /* Put first available memory address into a character pointer. */
37 pointer = (CHAR *) first_unused_memory;
38
39 /* Put system definition stuff in here, e.g. thread creates and other assorted
40 create information. */
41
42 status = tx_thread_create(&thread_0, "thread 0", thread_0_entry, 1,
43 pointer, TEST_STACK_SIZE_PRINTF,
44 16, 16, 100, TX_AUTO_START);
45 pointer = pointer + TEST_STACK_SIZE_PRINTF;
46
47 /* Check for status. */
48 if (status != TX_SUCCESS)
49 {
50
51 printf("Running Thread Time-Slice Change Test............................... ERROR #1\n");
52 test_control_return(1);
53 }
54
55 status = tx_thread_create(&thread_1, "thread 1", thread_1_entry, 1,
56 pointer, TEST_STACK_SIZE_PRINTF,
57 22, 22, 200, TX_AUTO_START);
58 pointer = pointer + TEST_STACK_SIZE_PRINTF;
59
60 /* Check for status. */
61 if (status != TX_SUCCESS)
62 {
63
64 printf("Running Thread Time-Slice Change Test............................... ERROR #2\n");
65 test_control_return(1);
66 }
67 }
68
69
70
71 /* Define the test threads. */
72
thread_0_entry(ULONG thread_input)73 static void thread_0_entry(ULONG thread_input)
74 {
75
76 UINT status;
77 ULONG old_time_slice = 0;
78
79
80 /* Inform user. */
81 printf("Running Thread Time-Slice Change Test............................... ");
82
83 /* Increment thread 0 counter. */
84 thread_0_counter++;
85
86 /* Change the time-slice of other thread. */
87 status = tx_thread_time_slice_change(&thread_1, 33, &old_time_slice);
88
89 /* Check status and the time sice of specified thread. */
90 if ((status != TX_SUCCESS) || (old_time_slice != 200) || (thread_1.tx_thread_new_time_slice != 33))
91 {
92
93 /* Thread error. */
94 printf("ERROR #3\n");
95 test_control_return(1);
96 }
97
98 /* Sleep to get a fresh timer. */
99 tx_thread_sleep(1);
100
101 /* Change the time-slice of this thread. */
102 status = tx_thread_time_slice_change(&thread_0, 66, &old_time_slice);
103
104 /* Check status and the time sice of specified thread. */
105 if ((status != TX_SUCCESS) || (old_time_slice != 100) || (thread_0.tx_thread_new_time_slice != 66) ||
106 (_tx_timer_time_slice != 66))
107 {
108
109 /* Thread error. */
110 printf("ERROR #4\n");
111 test_control_return(1);
112 }
113
114 /* Change the time-slice of this thread. */
115 status = tx_thread_time_slice_change(&thread_1, 2, &old_time_slice);
116
117 /* Sleep for 8 ticks just to allow thread 1 to run and time-slice with no other thread ready. */
118 tx_thread_sleep(8);
119
120 if (status != TX_SUCCESS)
121 {
122
123 /* Thread error. */
124 printf("ERROR #5\n");
125 test_control_return(1);
126 }
127 else
128 {
129
130 /* Successful test. */
131 printf("SUCCESS!\n");
132 test_control_return(0);
133 }
134 }
135
thread_1_entry(ULONG thread_input)136 static void thread_1_entry(ULONG thread_input)
137 {
138
139 while(1)
140 {
141
142 /* Identify. */
143 tx_thread_identify();
144
145 /* Increment the thread counter. */
146 thread_1_counter++;
147 }
148 }
149
150