Mercurial > ecos
annotate packages/kernel/current/tests/thread2.cxx @ 70:c5536bad4c24 ecos-sw-2000-02-11
Merge from eCos master repository on 2000-02-11-15:46:40-GMT
| author | jlarmour |
|---|---|
| date | Fri, 11 Feb 2000 16:47:32 +0000 |
| parents | bf00f99aec69 |
| children | eb9fd8c04db3 |
| 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 | |
| 43 // (only !CYG_SCHED_UNIQUE_PRIORITIES) | |
| 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: | |
| 51 // CYG_SCHED_UNIQUE_PRIORITIES | |
| 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; | |
| 111 #if !(CYG_SCHED_UNIQUE_PRIORITIES) && defined(CYGSEM_KERNEL_SCHED_TIMESLICE) | |
| 112 thread2->set_priority(6); | |
| 113 CHECK( 6 == thread1->get_priority() ); | |
| 114 CHECK( 6 == thread2->get_priority() ); | |
| 115 | |
| 116 while ( 100 == q ) | |
| 117 ; | |
| 118 CHECK( 101 == q++ ); | |
| 119 s1.wait(); | |
| 120 CHECK( 103 == q++ ); | |
| 121 #endif | |
| 122 s0.post(); | |
| 123 s1.wait(); | |
| 124 } | |
| 125 | |
| 126 static void entry2( CYG_ADDRWORD data ) | |
| 127 { | |
| 128 CHECK( 2 == q++ ); | |
| 129 s0.post(); | |
| 130 CHECK( 7 == q++ ); | |
| 131 s2.wait(); | |
| 132 CHECK( 9 == q++ ); | |
| 133 thread1->set_priority(6); | |
| 134 CHECK( 10 == q++ ); | |
| 135 thread2->set_priority(2); | |
| 136 CHECK( 11 == q++ ); | |
| 137 thread2->set_priority(7); | |
| 138 | |
| 139 #if !(CYG_SCHED_UNIQUE_PRIORITIES) && defined(CYGSEM_KERNEL_SCHED_TIMESLICE) | |
| 140 CHECK( 6 == thread1->get_priority() ); | |
| 141 CHECK( 6 == thread2->get_priority() ); | |
| 142 | |
| 143 CHECK( 100 == q++ ); | |
| 144 while ( 101 == q ) | |
| 145 ; | |
| 146 CHECK( 102 == q++ ); | |
| 147 s1.post(); | |
| 148 #endif | |
| 149 s0.post(); | |
| 150 s2.wait(); | |
| 151 } | |
| 152 | |
| 153 | |
| 154 void thread2_main( void ) | |
| 155 { | |
| 156 CYG_TEST_INIT(); | |
| 157 | |
| 2 | 158 thread0 = new_thread( entry0, 0 ); |
| 159 thread1 = new_thread( entry1, 1 ); | |
| 160 thread2 = new_thread( entry2, 2 ); | |
| 0 | 161 |
| 162 thread0->resume(); | |
| 163 thread1->resume(); | |
| 164 thread2->resume(); | |
| 165 | |
| 166 thread0->set_priority(5); | |
| 167 thread1->set_priority(6); | |
| 168 thread2->set_priority(7); | |
| 169 | |
| 170 if( 9 >= CYG_THREAD_MIN_PRIORITY ) | |
| 171 CYG_TEST_FAIL_FINISH("Test requires priorities up to 9"); | |
| 172 | |
| 173 if( 2 <= CYG_THREAD_MAX_PRIORITY ) | |
| 174 CYG_TEST_FAIL_FINISH("Test requires priorities as low as 2"); | |
| 175 | |
| 176 Cyg_Scheduler::start(); | |
| 177 | |
| 178 CYG_TEST_FAIL_FINISH("Unresolved"); | |
| 179 } | |
| 180 | |
| 181 externC void | |
| 182 cyg_start( void ) | |
| 183 { | |
| 184 thread2_main(); | |
| 185 } | |
| 186 | |
| 187 // EOF thread2.cxx |
