|
0
|
1 //========================================================================== |
|
|
2 // |
|
|
3 // thread2.cxx |
|
|
4 // |
|
|
5 // Thread test 2 |
|
|
6 // |
|
|
7 //========================================================================== |
|
|
8 //####COPYRIGHTBEGIN#### |
|
|
9 // |
|
|
10 // ------------------------------------------- |
|
|
11 // The contents of this file are subject to the Cygnus eCos Public License |
|
|
12 // Version 1.0 (the "License"); you may not use this file except in |
|
|
13 // compliance with the License. You may obtain a copy of the License at |
|
|
14 // http://sourceware.cygnus.com/ecos |
|
|
15 // |
|
|
16 // Software distributed under the License is distributed on an "AS IS" |
|
|
17 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the |
|
|
18 // License for the specific language governing rights and limitations under |
|
|
19 // the License. |
|
|
20 // |
|
|
21 // The Original Code is eCos - Embedded Cygnus Operating System, released |
|
|
22 // September 30, 1998. |
|
|
23 // |
|
|
24 // The Initial Developer of the Original Code is Cygnus. Portions created |
|
2
|
25 // by Cygnus are Copyright (C) 1998,1999 Cygnus Solutions. All Rights Reserved. |
|
0
|
26 // ------------------------------------------- |
|
|
27 // |
|
|
28 //####COPYRIGHTEND#### |
|
|
29 //========================================================================== |
|
|
30 //#####DESCRIPTIONBEGIN#### |
|
|
31 // |
|
|
32 // Author(s): dsm |
|
|
33 // Contributors: dsm |
|
|
34 // Date: 1998-02-19 |
|
|
35 // Description: |
|
|
36 // tests scheduler & threads & priorities |
|
|
37 // + create multiple threads with various priorities |
|
|
38 // + check highest priority running thread is always running |
|
|
39 // + check next highest runs when highest suspended |
|
|
40 // + check several threads of equal priority share time |
|
|
41 // (only !CYG_SCHED_UNIQUE_PRIORITIES) |
|
|
42 // + check other threads are starved |
|
|
43 // + check setting priority dynamically causes a thread to |
|
|
44 // become/stay current/non-current |
|
|
45 // Omissions: |
|
|
46 // check yield |
|
|
47 // check can set threads with min and max priority |
|
|
48 // Options: |
|
|
49 // CYG_SCHED_UNIQUE_PRIORITIES |
|
|
50 // CYGIMP_THREAD_PRIORITY |
|
|
51 // CYGNUM_KERNEL_SCHED_PRIORITIES |
|
|
52 // CYGSEM_KERNEL_SCHED_BITMAP |
|
|
53 // CYGSEM_KERNEL_SCHED_MLQUEUE |
|
|
54 //####DESCRIPTIONEND#### |
|
|
55 |
|
|
56 #include <pkgconf/kernel.h> |
|
|
57 |
|
|
58 #include <cyg/kernel/thread.hxx> |
|
|
59 #include <cyg/kernel/thread.inl> |
|
|
60 #include <cyg/kernel/sched.hxx> |
|
|
61 #include <cyg/kernel/mutex.hxx> |
|
|
62 #include <cyg/kernel/sema.hxx> |
|
|
63 |
|
|
64 #include <cyg/infra/testcase.h> |
|
|
65 |
|
|
66 #include <cyg/kernel/sched.inl> |
|
|
67 |
|
|
68 #ifndef CYGIMP_THREAD_PRIORITY |
|
|
69 #error "Test requires thread priorities" |
|
|
70 #endif |
|
|
71 |
|
|
72 static Cyg_Counting_Semaphore s0, s1, s2; |
|
|
73 |
|
|
74 static volatile cyg_ucount8 q = 0; |
|
|
75 |
|
|
76 static Cyg_Thread *thread0, *thread1, *thread2; |
|
|
77 |
|
2
|
78 #define NTHREADS 3 |
|
|
79 #include "testaux.hxx" |
|
0
|
80 |
|
|
81 static void entry0( CYG_ADDRWORD data ) |
|
|
82 { |
|
|
83 CHECK( 0 == q++ ); |
|
|
84 s0.wait(); |
|
|
85 CHECK( 3 == q++ ); |
|
|
86 s1.post(); |
|
|
87 CHECK( 4 == q++ ); |
|
|
88 s0.wait(); |
|
|
89 s0.wait(); |
|
|
90 CYG_TEST_PASS_FINISH("Thread 2 OK"); |
|
|
91 } |
|
|
92 |
|
|
93 static void entry1( CYG_ADDRWORD data ) |
|
|
94 { |
|
|
95 CHECK( 1 == q++ ); |
|
|
96 s1.wait(); |
|
|
97 CHECK( 5 == q++ ); |
|
|
98 thread0->set_priority(9); |
|
|
99 s0.post(); |
|
|
100 CHECK( 6 == q++ ); |
|
|
101 thread2->set_priority(3); |
|
|
102 CHECK( 8 == q++ ); |
|
|
103 s2.post(); |
|
|
104 CHECK( 12 == q++ ); |
|
|
105 CHECK( 9 == thread0->get_priority() ); |
|
|
106 CHECK( 6 == thread1->get_priority() ); |
|
|
107 CHECK( 7 == thread2->get_priority() ); |
|
|
108 q = 100; |
|
|
109 #if !(CYG_SCHED_UNIQUE_PRIORITIES) && defined(CYGSEM_KERNEL_SCHED_TIMESLICE) |
|
|
110 thread2->set_priority(6); |
|
|
111 CHECK( 6 == thread1->get_priority() ); |
|
|
112 CHECK( 6 == thread2->get_priority() ); |
|
|
113 |
|
|
114 while ( 100 == q ) |
|
|
115 ; |
|
|
116 CHECK( 101 == q++ ); |
|
|
117 s1.wait(); |
|
|
118 CHECK( 103 == q++ ); |
|
|
119 #endif |
|
|
120 s0.post(); |
|
|
121 s1.wait(); |
|
|
122 } |
|
|
123 |
|
|
124 static void entry2( CYG_ADDRWORD data ) |
|
|
125 { |
|
|
126 CHECK( 2 == q++ ); |
|
|
127 s0.post(); |
|
|
128 CHECK( 7 == q++ ); |
|
|
129 s2.wait(); |
|
|
130 CHECK( 9 == q++ ); |
|
|
131 thread1->set_priority(6); |
|
|
132 CHECK( 10 == q++ ); |
|
|
133 thread2->set_priority(2); |
|
|
134 CHECK( 11 == q++ ); |
|
|
135 thread2->set_priority(7); |
|
|
136 |
|
|
137 #if !(CYG_SCHED_UNIQUE_PRIORITIES) && defined(CYGSEM_KERNEL_SCHED_TIMESLICE) |
|
|
138 CHECK( 6 == thread1->get_priority() ); |
|
|
139 CHECK( 6 == thread2->get_priority() ); |
|
|
140 |
|
|
141 CHECK( 100 == q++ ); |
|
|
142 while ( 101 == q ) |
|
|
143 ; |
|
|
144 CHECK( 102 == q++ ); |
|
|
145 s1.post(); |
|
|
146 #endif |
|
|
147 s0.post(); |
|
|
148 s2.wait(); |
|
|
149 } |
|
|
150 |
|
|
151 |
|
|
152 void thread2_main( void ) |
|
|
153 { |
|
|
154 CYG_TEST_INIT(); |
|
|
155 |
|
2
|
156 thread0 = new_thread( entry0, 0 ); |
|
|
157 thread1 = new_thread( entry1, 1 ); |
|
|
158 thread2 = new_thread( entry2, 2 ); |
|
0
|
159 |
|
|
160 thread0->resume(); |
|
|
161 thread1->resume(); |
|
|
162 thread2->resume(); |
|
|
163 |
|
|
164 thread0->set_priority(5); |
|
|
165 thread1->set_priority(6); |
|
|
166 thread2->set_priority(7); |
|
|
167 |
|
|
168 if( 9 >= CYG_THREAD_MIN_PRIORITY ) |
|
|
169 CYG_TEST_FAIL_FINISH("Test requires priorities up to 9"); |
|
|
170 |
|
|
171 if( 2 <= CYG_THREAD_MAX_PRIORITY ) |
|
|
172 CYG_TEST_FAIL_FINISH("Test requires priorities as low as 2"); |
|
|
173 |
|
|
174 Cyg_Scheduler::start(); |
|
|
175 |
|
|
176 CYG_TEST_FAIL_FINISH("Unresolved"); |
|
|
177 } |
|
|
178 |
|
|
179 externC void |
|
|
180 cyg_start( void ) |
|
|
181 { |
|
|
182 thread2_main(); |
|
|
183 } |
|
|
184 |
|
|
185 // EOF thread2.cxx |