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