Mercurial > ecos
annotate packages/kernel/current/tests/sync3.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 // sync3.cxx | |
| 4 // | |
| 5 // Sync test 3 -- tests priorities and priority inheritance | |
| 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-18 | |
| 45 // Description: | |
| 46 // Creates mutexes and threads to set up starvation condition. | |
| 47 // Checks simple priority inheritance cures this. | |
| 48 // | |
| 49 // The starvation condition is caused by the highest priority | |
| 50 // thread, t0 waiting on a mutex which is never released because | |
| 51 // it is held by t2. t2 never releases it because t1 will be | |
| 52 // running at a priority level higher than t2 (but lower than t0). | |
| 53 // | |
| 54 // With priority inheritance enabled, t2 will inherit its priority | |
| 55 // from t0 when t0 tries to grab the mutex. | |
| 56 // | |
| 57 // Options: | |
| 58 // CYGIMP_THREAD_PRIORITY | |
|
115
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
66
diff
changeset
|
59 // CYGSEM_KERNEL_SYNCH_MUTEX_PRIORITY_INVERSION_PROTOCOL_INHERIT |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
66
diff
changeset
|
60 // CYGSEM_KERNEL_SYNCH_MUTEX_PRIORITY_INVERSION_PROTOCOL_SIMPLE |
| 0 | 61 //####DESCRIPTIONEND#### |
| 62 | |
| 63 #include <pkgconf/kernel.h> | |
| 64 | |
| 65 #include <cyg/kernel/thread.hxx> | |
| 66 #include <cyg/kernel/thread.inl> | |
| 67 #include <cyg/kernel/sched.hxx> | |
| 68 #include <cyg/kernel/mutex.hxx> | |
| 69 #include <cyg/kernel/sema.hxx> | |
| 70 | |
| 71 #include <cyg/infra/testcase.h> | |
| 72 | |
| 73 #include <cyg/kernel/sched.inl> | |
| 74 | |
|
177
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
130
diff
changeset
|
75 #if defined(CYGIMP_THREAD_PRIORITY) && \ |
|
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
130
diff
changeset
|
76 !defined(CYGPKG_KERNEL_SMP_SUPPORT) |
| 0 | 77 |
|
115
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
66
diff
changeset
|
78 // ------------------------------------------------------------------------ |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
66
diff
changeset
|
79 // Manufacture a simpler feature test macro for priority inheritance than |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
66
diff
changeset
|
80 // the configuration gives us. We have priority inheritance if it is configured |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
66
diff
changeset
|
81 // as the only protocol, or if it is the default protocol for dynamic protocol |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
66
diff
changeset
|
82 // choice. |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
66
diff
changeset
|
83 // FIXME: If we have dynamic protocol choice, we can also set priority inheritance |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
66
diff
changeset
|
84 // as the protocol to be used on the mutexes we are interested in. At present we |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
66
diff
changeset
|
85 // do not do this. |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
66
diff
changeset
|
86 |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
66
diff
changeset
|
87 #ifdef CYGSEM_KERNEL_SYNCH_MUTEX_PRIORITY_INVERSION_PROTOCOL_INHERIT |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
66
diff
changeset
|
88 # ifdef CYGSEM_KERNEL_SYNCH_MUTEX_PRIORITY_INVERSION_PROTOCOL_DYNAMIC |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
66
diff
changeset
|
89 # ifdef CYGSEM_KERNEL_SYNCH_MUTEX_PRIORITY_INVERSION_PROTOCOL_DEFAULT_INHERIT |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
66
diff
changeset
|
90 # define PRIORITY_INHERITANCE |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
66
diff
changeset
|
91 # else |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
66
diff
changeset
|
92 # undef PRIORITY_INHERITANCE |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
66
diff
changeset
|
93 # endif |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
66
diff
changeset
|
94 # else |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
66
diff
changeset
|
95 # define PRIORITY_INHERITANCE |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
66
diff
changeset
|
96 # endif |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
66
diff
changeset
|
97 #else |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
66
diff
changeset
|
98 # undef PRIORITY_INHERITANCE |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
66
diff
changeset
|
99 #endif |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
66
diff
changeset
|
100 |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
66
diff
changeset
|
101 // ------------------------------------------------------------------------ |
|
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
66
diff
changeset
|
102 |
| 0 | 103 #define NTHREADS 3 |
| 104 | |
| 105 #include "testaux.hxx" | |
| 106 | |
| 107 static Cyg_Mutex m0; | |
| 108 static Cyg_Binary_Semaphore s0, s1, s2; | |
| 109 | |
| 110 static cyg_ucount8 m0d = 9; | |
| 111 | |
| 112 static void check_priorities_normal() | |
| 113 { | |
| 114 CHECK( 5 == thread[0]->get_priority()); | |
| 115 CHECK( 6 == thread[1]->get_priority()); | |
| 116 CHECK( 7 == thread[2]->get_priority()); | |
| 117 } | |
| 118 | |
| 119 static void check_priorities_inherited() | |
| 120 { | |
| 121 CHECK( 5 == thread[0]->get_priority()); | |
| 122 CHECK( 6 == thread[1]->get_priority()); | |
|
115
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
66
diff
changeset
|
123 #ifdef PRIORITY_INHERITANCE |
| 0 | 124 CHECK( 5 == thread[2]->get_current_priority()); |
| 125 #endif | |
| 126 CHECK( 7 == thread[2]->get_priority()); | |
| 127 | |
| 128 } | |
| 129 | |
| 130 static void entry0( CYG_ADDRWORD data ) | |
| 131 { | |
| 2 | 132 s0.wait(); // wait until t2 has gained m0.lock |
| 0 | 133 check_priorities_normal(); |
| 134 m0.lock(); { | |
| 135 check_priorities_normal(); | |
| 2 | 136 CHECK( 2 == m0d ); |
| 137 m0d = 0; | |
| 0 | 138 } m0.unlock(); |
| 139 check_priorities_normal(); | |
|
115
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
66
diff
changeset
|
140 #ifdef PRIORITY_INHERITANCE |
| 0 | 141 CYG_TEST_PASS_FINISH("Sync 3 OK -- priority inheritance worked"); |
| 142 #else | |
| 143 CYG_TEST_FAIL_FINISH("Sync 3: thread not starved"); | |
| 144 #endif | |
| 145 // NOT REACHED | |
| 146 } | |
| 147 | |
| 148 static void entry1( CYG_ADDRWORD data ) | |
| 149 { | |
| 150 s1.wait(); | |
| 151 // The delay below will allow testing of the priority inheritance | |
| 152 // mechanism when scheduler does not guarantee to schedule threads | |
| 153 // in strict priority order. | |
| 154 for ( volatile cyg_ucount32 i=0; i < 100000; i++ ) | |
| 2 | 155 ; // math is hard |
| 0 | 156 |
|
115
6ed91473a1cd
Merge from eCos master repository on 2000-08-21-22:40:54-BST
jlarmour
parents:
66
diff
changeset
|
157 #ifdef PRIORITY_INHERITANCE |
| 0 | 158 // thread0 should have stopped by this point |
| 159 CYG_TEST_FAIL_FINISH("Sync 3: priority inheritance mechanism failed"); | |
| 160 #else | |
| 161 // With strict priority scheduling and no priority inheritance | |
| 162 // this is expected to happen. | |
| 163 CYG_TEST_PASS_FINISH("Sync 3 OK"); | |
| 164 #endif | |
| 165 CYG_TEST_FAIL_FINISH("Not reached"); | |
| 166 } | |
| 167 | |
| 168 void entry2( CYG_ADDRWORD data ) | |
| 169 { | |
| 170 m0.lock(); { | |
| 2 | 171 CHECK( 9 == m0d ); |
| 0 | 172 check_priorities_normal(); |
| 2 | 173 s0.post(); // Now I have lock on m0, wake t0 then t1 |
| 0 | 174 check_priorities_inherited(); |
| 2 | 175 s1.post(); |
| 0 | 176 check_priorities_inherited(); |
| 2 | 177 m0d = 2; |
| 0 | 178 } m0.unlock(); |
| 179 check_priorities_normal(); | |
| 180 m0.lock(); { | |
| 181 check_priorities_normal(); | |
| 2 | 182 CHECK( 0 == m0d ); |
| 183 m0d = 21; | |
| 184 s2.wait(); // never posted | |
| 0 | 185 } m0.unlock(); |
| 186 } | |
| 187 | |
| 188 | |
| 189 | |
| 190 void sync3_main(void) | |
| 191 { | |
| 192 CYG_TEST_INIT(); | |
| 193 | |
| 194 new_thread( entry0, 0); | |
| 195 new_thread( entry1, 1); | |
| 196 new_thread( entry2, 2); | |
| 197 | |
| 198 thread[0]->set_priority(5); | |
| 199 thread[1]->set_priority(6); | |
| 200 thread[2]->set_priority(7); | |
| 201 | |
| 202 Cyg_Scheduler::start(); | |
| 203 | |
| 204 CYG_TEST_FAIL_FINISH("Not reached"); | |
| 205 } | |
| 206 | |
| 207 externC void | |
| 208 cyg_start( void ) | |
| 209 { | |
|
130
eb9fd8c04db3
Merge from eCos master repository on 2000-10-23-17:01:37-BST
jlarmour
parents:
115
diff
changeset
|
210 #ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG |
|
eb9fd8c04db3
Merge from eCos master repository on 2000-10-23-17:01:37-BST
jlarmour
parents:
115
diff
changeset
|
211 cyg_hal_invoke_constructors(); |
|
eb9fd8c04db3
Merge from eCos master repository on 2000-10-23-17:01:37-BST
jlarmour
parents:
115
diff
changeset
|
212 #endif |
| 0 | 213 sync3_main(); |
| 214 } | |
|
177
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
130
diff
changeset
|
215 |
|
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
130
diff
changeset
|
216 #else // defined(CYGIMP_THREAD_PRIORITY) etc |
|
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
130
diff
changeset
|
217 |
|
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
130
diff
changeset
|
218 externC void |
|
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
130
diff
changeset
|
219 cyg_start( void ) |
|
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
130
diff
changeset
|
220 { |
|
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
130
diff
changeset
|
221 CYG_TEST_INIT(); |
| 1507 | 222 CYG_TEST_INFO("Sync3 test requires:\n" |
|
177
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
130
diff
changeset
|
223 "defined(CYGIMP_THREAD_PRIORITY) &&\n" |
|
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
130
diff
changeset
|
224 "!defined(CYGPKG_KERNEL_SMP_SUPPORT)\n"); |
| 1507 | 225 CYG_TEST_NA("Sync3 test requirements"); |
|
177
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
130
diff
changeset
|
226 |
|
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
130
diff
changeset
|
227 } |
|
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
130
diff
changeset
|
228 |
|
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
130
diff
changeset
|
229 #endif // defined(CYGIMP_THREAD_PRIORITY) etc |
|
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
130
diff
changeset
|
230 |
| 0 | 231 // EOF sync3.cxx |
