1 /* This test is designed to see if a thread can successfully suspend itself in a single
2 thread system. This also tests a thread created that is not automatically enabled. */
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 TX_THREAD thread_1;
11
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_simple_supsend_application_define(void *first_unused_memory)
29 #endif
30 {
31
32 UINT status;
33 CHAR *pointer;
34
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, TX_NO_TIME_SLICE, 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 Simple Suspend 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 16, 16, TX_NO_TIME_SLICE, TX_DONT_START);
58 pointer = pointer + TEST_STACK_SIZE_PRINTF;
59
60 /* Check for status. */
61 if (status != TX_SUCCESS)
62 {
63
64 printf("Running Thread Simple Suspend Test.................................. ERROR #2\n");
65 test_control_return(1);
66 }
67 }
68
69
70
71 /* Define the test thread. */
72
thread_0_entry(ULONG thread_input)73 static void thread_0_entry(ULONG thread_input)
74 {
75
76 UINT status;
77
78 /* Resume the test control thread. */
79 status = tx_thread_resume(&thread_1);
80
81 /* Check status. */
82 if (status != TX_SUCCESS)
83 return;
84
85 /* Increment thread 0 counter. */
86 thread_0_counter++;
87
88 /* Suspend the running thread. */
89 tx_thread_suspend(&thread_0);
90 }
91
92
thread_1_entry(ULONG thread_input)93 static void thread_1_entry(ULONG thread_input)
94 {
95
96 /* Inform user. */
97 printf("Running Thread Simple Suspend Test.................................. ");
98
99 /* The other thread should be in a suspended state now. */
100 if ((thread_0.tx_thread_state != TX_SUSPENDED) || (thread_0_counter != 1))
101 {
102
103 /* Thread Suspend error. */
104 printf("ERROR #3\n");
105 test_control_return(1);
106 }
107 else
108 {
109
110 /* Successful Thread Suspend test. */
111 printf("SUCCESS!\n");
112 test_control_return(0);
113 }
114 }
115
116
117