Mercurial > ecos
annotate packages/kernel/current/tests/thread2.cxx @ 3292:7f8e529b4d82 default tip
Fix FREESCALE_EDMA_NBYTES_MLOFFYES_MLOFF() so it works with negative offsets.
| author | vae |
|---|---|
| date | Wed, 29 Apr 2015 23:31:48 +0000 |
| parents | 74dbf4c3f2e1 |
| children |
| rev | line source |
|---|---|
| 0 | 1 //========================================================================== |
| 2 // | |
| 3 // thread2.cxx | |
| 4 // | |
| 5 // Thread test 2 | |
| 6 // | |
| 7 //========================================================================== | |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1507
diff
changeset
|
8 // ####ECOSGPLCOPYRIGHTBEGIN#### |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1507
diff
changeset
|
9 // ------------------------------------------- |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1507
diff
changeset
|
10 // This file is part of eCos, the Embedded Configurable Operating System. |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1507
diff
changeset
|
11 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc. |
|
208
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
177
diff
changeset
|
12 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1507
diff
changeset
|
13 // eCos is free software; you can redistribute it and/or modify it under |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1507
diff
changeset
|
14 // the terms of the GNU General Public License as published by the Free |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1507
diff
changeset
|
15 // Software Foundation; either version 2 or (at your option) any later |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1507
diff
changeset
|
16 // version. |
|
208
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
177
diff
changeset
|
17 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1507
diff
changeset
|
18 // eCos is distributed in the hope that it will be useful, but WITHOUT |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1507
diff
changeset
|
19 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1507
diff
changeset
|
20 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1507
diff
changeset
|
21 // for more details. |
|
208
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
177
diff
changeset
|
22 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1507
diff
changeset
|
23 // You should have received a copy of the GNU General Public License |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1507
diff
changeset
|
24 // along with eCos; if not, write to the Free Software Foundation, Inc., |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1507
diff
changeset
|
25 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
208
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
177
diff
changeset
|
26 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1507
diff
changeset
|
27 // As a special exception, if other files instantiate templates or use |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1507
diff
changeset
|
28 // macros or inline functions from this file, or you compile this file |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1507
diff
changeset
|
29 // and link it with other works to produce a work based on this file, |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1507
diff
changeset
|
30 // this file does not by itself cause the resulting work to be covered by |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1507
diff
changeset
|
31 // the GNU General Public License. However the source code for this file |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1507
diff
changeset
|
32 // must still be made available in accordance with section (3) of the GNU |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1507
diff
changeset
|
33 // General Public License v2. |
|
208
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
177
diff
changeset
|
34 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1507
diff
changeset
|
35 // This exception does not invalidate any other reasons why a work based |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1507
diff
changeset
|
36 // on this file might be covered by the GNU General Public License. |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1507
diff
changeset
|
37 // ------------------------------------------- |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1507
diff
changeset
|
38 // ####ECOSGPLCOPYRIGHTEND#### |
| 0 | 39 //========================================================================== |
| 40 //#####DESCRIPTIONBEGIN#### | |
| 41 // | |
| 42 // Author(s): dsm | |
| 43 // Contributors: dsm | |
| 44 // Date: 1998-02-19 | |
| 45 // Description: | |
| 46 // tests scheduler & threads & priorities | |
| 47 // + create multiple threads with various priorities | |
| 48 // + check highest priority running thread is always running | |
| 49 // + check next highest runs when highest suspended | |
| 50 // + check several threads of equal priority share time | |
|
132
0ae0bc38e387
Merge from eCos master repository on 2000-10-31-00:30:36-GMT
jlarmour
parents:
130
diff
changeset
|
51 // (only !CYGINT_KERNEL_SCHEDULER_UNIQUE_PRIORITIES) |
| 0 | 52 // + check other threads are starved |
| 53 // + check setting priority dynamically causes a thread to | |
| 54 // become/stay current/non-current | |
| 55 // Omissions: | |
| 56 // check yield | |
| 57 // check can set threads with min and max priority | |
| 58 // Options: | |
|
132
0ae0bc38e387
Merge from eCos master repository on 2000-10-31-00:30:36-GMT
jlarmour
parents:
130
diff
changeset
|
59 // CYGINT_KERNEL_SCHEDULER_UNIQUE_PRIORITIES |
| 0 | 60 // CYGIMP_THREAD_PRIORITY |
| 61 // CYGNUM_KERNEL_SCHED_PRIORITIES | |
| 62 // CYGSEM_KERNEL_SCHED_BITMAP | |
| 63 // CYGSEM_KERNEL_SCHED_MLQUEUE | |
| 64 //####DESCRIPTIONEND#### | |
|
177
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
132
diff
changeset
|
65 //========================================================================== |
| 0 | 66 |
| 67 #include <pkgconf/kernel.h> | |
| 68 | |
| 69 #include <cyg/kernel/thread.hxx> | |
| 70 #include <cyg/kernel/thread.inl> | |
| 71 #include <cyg/kernel/sched.hxx> | |
| 72 #include <cyg/kernel/mutex.hxx> | |
| 73 #include <cyg/kernel/sema.hxx> | |
| 74 | |
| 75 #include <cyg/infra/testcase.h> | |
| 76 | |
| 77 #include <cyg/kernel/sched.inl> | |
| 78 | |
|
177
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
132
diff
changeset
|
79 // ------------------------------------------------------------------------ |
|
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
132
diff
changeset
|
80 |
|
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
132
diff
changeset
|
81 #if defined(CYGIMP_THREAD_PRIORITY) && \ |
|
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
132
diff
changeset
|
82 !defined(CYGPKG_KERNEL_SMP_SUPPORT) |
|
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
132
diff
changeset
|
83 |
|
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
132
diff
changeset
|
84 // ------------------------------------------------------------------------ |
| 0 | 85 |
| 86 static Cyg_Counting_Semaphore s0, s1, s2; | |
| 87 | |
| 88 static volatile cyg_ucount8 q = 0; | |
| 89 | |
| 90 static Cyg_Thread *thread0, *thread1, *thread2; | |
| 91 | |
| 2 | 92 #define NTHREADS 3 |
| 93 #include "testaux.hxx" | |
| 0 | 94 |
|
177
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
132
diff
changeset
|
95 // ------------------------------------------------------------------------ |
|
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
132
diff
changeset
|
96 |
| 0 | 97 static void entry0( CYG_ADDRWORD data ) |
| 98 { | |
| 99 CHECK( 0 == q++ ); | |
| 100 s0.wait(); | |
| 101 CHECK( 3 == q++ ); | |
| 102 s1.post(); | |
| 103 CHECK( 4 == q++ ); | |
| 104 s0.wait(); | |
| 105 s0.wait(); | |
| 106 CYG_TEST_PASS_FINISH("Thread 2 OK"); | |
| 107 } | |
| 108 | |
|
177
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
132
diff
changeset
|
109 // ------------------------------------------------------------------------ |
|
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
132
diff
changeset
|
110 |
| 0 | 111 static void entry1( CYG_ADDRWORD data ) |
| 112 { | |
| 113 CHECK( 1 == q++ ); | |
| 114 s1.wait(); | |
| 115 CHECK( 5 == q++ ); | |
| 116 thread0->set_priority(9); | |
| 117 s0.post(); | |
| 118 CHECK( 6 == q++ ); | |
| 119 thread2->set_priority(3); | |
| 120 CHECK( 8 == q++ ); | |
| 121 s2.post(); | |
| 122 CHECK( 12 == q++ ); | |
| 123 CHECK( 9 == thread0->get_priority() ); | |
| 124 CHECK( 6 == thread1->get_priority() ); | |
| 125 CHECK( 7 == thread2->get_priority() ); | |
| 126 q = 100; | |
|
132
0ae0bc38e387
Merge from eCos master repository on 2000-10-31-00:30:36-GMT
jlarmour
parents:
130
diff
changeset
|
127 #if !(CYGINT_KERNEL_SCHEDULER_UNIQUE_PRIORITIES) \ |
|
0ae0bc38e387
Merge from eCos master repository on 2000-10-31-00:30:36-GMT
jlarmour
parents:
130
diff
changeset
|
128 && defined(CYGSEM_KERNEL_SCHED_TIMESLICE) |
| 0 | 129 thread2->set_priority(6); |
| 130 CHECK( 6 == thread1->get_priority() ); | |
| 131 CHECK( 6 == thread2->get_priority() ); | |
| 132 | |
| 133 while ( 100 == q ) | |
| 134 ; | |
| 135 CHECK( 101 == q++ ); | |
| 136 s1.wait(); | |
| 137 CHECK( 103 == q++ ); | |
| 138 #endif | |
| 139 s0.post(); | |
| 140 s1.wait(); | |
| 141 } | |
| 142 | |
|
177
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
132
diff
changeset
|
143 // ------------------------------------------------------------------------ |
|
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
132
diff
changeset
|
144 |
| 0 | 145 static void entry2( CYG_ADDRWORD data ) |
| 146 { | |
| 147 CHECK( 2 == q++ ); | |
| 148 s0.post(); | |
| 149 CHECK( 7 == q++ ); | |
| 150 s2.wait(); | |
| 151 CHECK( 9 == q++ ); | |
| 152 thread1->set_priority(6); | |
| 153 CHECK( 10 == q++ ); | |
| 154 thread2->set_priority(2); | |
| 155 CHECK( 11 == q++ ); | |
| 156 thread2->set_priority(7); | |
| 157 | |
|
132
0ae0bc38e387
Merge from eCos master repository on 2000-10-31-00:30:36-GMT
jlarmour
parents:
130
diff
changeset
|
158 #if !(CYGINT_KERNEL_SCHEDULER_UNIQUE_PRIORITIES) \ |
|
0ae0bc38e387
Merge from eCos master repository on 2000-10-31-00:30:36-GMT
jlarmour
parents:
130
diff
changeset
|
159 && defined(CYGSEM_KERNEL_SCHED_TIMESLICE) |
| 0 | 160 CHECK( 6 == thread1->get_priority() ); |
| 161 CHECK( 6 == thread2->get_priority() ); | |
| 162 | |
| 163 CHECK( 100 == q++ ); | |
| 164 while ( 101 == q ) | |
| 165 ; | |
| 166 CHECK( 102 == q++ ); | |
| 167 s1.post(); | |
| 168 #endif | |
| 169 s0.post(); | |
| 170 s2.wait(); | |
| 171 } | |
| 172 | |
| 173 | |
|
177
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
132
diff
changeset
|
174 // ------------------------------------------------------------------------ |
|
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
132
diff
changeset
|
175 |
| 0 | 176 void thread2_main( void ) |
| 177 { | |
| 178 CYG_TEST_INIT(); | |
| 179 | |
| 2 | 180 thread0 = new_thread( entry0, 0 ); |
| 181 thread1 = new_thread( entry1, 1 ); | |
| 182 thread2 = new_thread( entry2, 2 ); | |
| 0 | 183 |
| 184 thread0->resume(); | |
| 185 thread1->resume(); | |
| 186 thread2->resume(); | |
| 187 | |
| 188 thread0->set_priority(5); | |
| 189 thread1->set_priority(6); | |
| 190 thread2->set_priority(7); | |
| 191 | |
| 192 if( 9 >= CYG_THREAD_MIN_PRIORITY ) | |
| 193 CYG_TEST_FAIL_FINISH("Test requires priorities up to 9"); | |
| 194 | |
| 195 if( 2 <= CYG_THREAD_MAX_PRIORITY ) | |
| 196 CYG_TEST_FAIL_FINISH("Test requires priorities as low as 2"); | |
| 197 | |
| 198 Cyg_Scheduler::start(); | |
| 199 | |
| 200 CYG_TEST_FAIL_FINISH("Unresolved"); | |
| 201 } | |
| 202 | |
|
177
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
132
diff
changeset
|
203 // ------------------------------------------------------------------------ |
|
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
132
diff
changeset
|
204 |
| 0 | 205 externC void |
| 206 cyg_start( void ) | |
| 207 { | |
|
130
eb9fd8c04db3
Merge from eCos master repository on 2000-10-23-17:01:37-BST
jlarmour
parents:
66
diff
changeset
|
208 #ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG |
|
eb9fd8c04db3
Merge from eCos master repository on 2000-10-23-17:01:37-BST
jlarmour
parents:
66
diff
changeset
|
209 cyg_hal_invoke_constructors(); |
|
eb9fd8c04db3
Merge from eCos master repository on 2000-10-23-17:01:37-BST
jlarmour
parents:
66
diff
changeset
|
210 #endif |
| 0 | 211 thread2_main(); |
| 212 } | |
|
177
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
132
diff
changeset
|
213 // ------------------------------------------------------------------------ |
| 0 | 214 |
|
177
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
132
diff
changeset
|
215 |
|
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
132
diff
changeset
|
216 #else // CYGPKG_KERNEL_SMP_SUPPORT etc |
|
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
132
diff
changeset
|
217 |
|
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
132
diff
changeset
|
218 // ------------------------------------------------------------------------ |
|
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
132
diff
changeset
|
219 |
|
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
132
diff
changeset
|
220 externC void |
|
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
132
diff
changeset
|
221 cyg_start( void ) |
|
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
132
diff
changeset
|
222 { |
|
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
132
diff
changeset
|
223 CYG_TEST_INIT(); |
| 1507 | 224 CYG_TEST_INFO("Thread2 test requires:\n" |
|
177
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
132
diff
changeset
|
225 "defined(CYGIMP_THREAD_PRIORITY) &&\n" |
|
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
132
diff
changeset
|
226 "!defined(CYGPKG_KERNEL_SMP_SUPPORT)\n"); |
| 1507 | 227 CYG_TEST_NA("Thread2 test requirements"); |
|
177
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
132
diff
changeset
|
228 } |
|
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
132
diff
changeset
|
229 |
|
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
132
diff
changeset
|
230 // ------------------------------------------------------------------------ |
|
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
132
diff
changeset
|
231 |
|
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
132
diff
changeset
|
232 #endif // CYGPKG_KERNEL_SMP_SUPPORT etc |
|
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
132
diff
changeset
|
233 |
|
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
132
diff
changeset
|
234 // ------------------------------------------------------------------------ |
| 0 | 235 // EOF thread2.cxx |
