Mercurial > ecos
annotate packages/kernel/current/tests/flag1.cxx @ 2729:74dbf4c3f2e1 after-copyright-change-20090129
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
| author | jlarmour |
|---|---|
| date | Thu, 29 Jan 2009 17:47:46 +0000 |
| parents | d2c90368aeef |
| children |
| rev | line source |
|---|---|
| 0 | 1 //========================================================================== |
| 2 // | |
| 3 // flag1.cxx | |
| 4 // | |
| 5 // Flag test 1 | |
| 6 // | |
| 7 //========================================================================== | |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
8 // ####ECOSGPLCOPYRIGHTBEGIN#### |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
9 // ------------------------------------------- |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
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:
210
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:
157
diff
changeset
|
12 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
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:
210
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:
210
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:
210
diff
changeset
|
16 // version. |
|
208
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
157
diff
changeset
|
17 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
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:
210
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:
210
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:
210
diff
changeset
|
21 // for more details. |
|
208
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
157
diff
changeset
|
22 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
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:
210
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:
210
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:
157
diff
changeset
|
26 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
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:
210
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:
210
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:
210
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:
210
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:
210
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:
210
diff
changeset
|
33 // General Public License v2. |
|
208
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
157
diff
changeset
|
34 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
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:
210
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:
210
diff
changeset
|
37 // ------------------------------------------- |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
38 // ####ECOSGPLCOPYRIGHTEND#### |
| 0 | 39 //========================================================================== |
| 40 //#####DESCRIPTIONBEGIN#### | |
| 41 // | |
| 42 // Author: dsm | |
| 43 // Contributors: dsm | |
| 44 // Date: 1998-05-11 | |
| 45 // Description: Tests basic flag functionality. | |
| 46 //####DESCRIPTIONEND#### | |
| 47 | |
| 48 #include <pkgconf/kernel.h> | |
| 49 | |
| 50 #include <cyg/kernel/thread.hxx> // Cyg_Thread | |
| 51 #include <cyg/kernel/thread.inl> | |
| 52 #include <cyg/kernel/sched.hxx> // Cyg_Scheduler::start() | |
| 53 | |
| 54 #include <cyg/kernel/flag.hxx> | |
| 55 | |
| 56 #include <cyg/infra/testcase.h> | |
| 57 | |
| 58 #include <cyg/kernel/sched.inl> | |
| 59 | |
| 60 | |
| 61 #define NTHREADS 3 | |
| 62 #include "testaux.hxx" | |
| 63 | |
| 64 static Cyg_Flag f0, f1; | |
| 65 #ifdef CYGFUN_KERNEL_THREADS_TIMER | |
| 66 static Cyg_Flag f2; | |
| 67 #endif | |
| 68 | |
| 69 static volatile cyg_atomic q = 0; | |
|
157
b65ec671dd4c
Merge from eCos master repository on 2001-04-06-18:28:36-BST
jlarmour
parents:
130
diff
changeset
|
70 #define FIRST_THREAD_WAIT_TIME 5 |
|
b65ec671dd4c
Merge from eCos master repository on 2001-04-06-18:28:36-BST
jlarmour
parents:
130
diff
changeset
|
71 #define SECOND_THREAD_WAIT_TIME 10 |
|
b65ec671dd4c
Merge from eCos master repository on 2001-04-06-18:28:36-BST
jlarmour
parents:
130
diff
changeset
|
72 #define THIRD_THREAD_WAIT_TIME 20 |
| 0 | 73 |
| 74 static void entry0( CYG_ADDRWORD data ) | |
| 75 { | |
| 76 CYG_TEST_INFO("Testing setbits() and maskbits()"); | |
| 77 CYG_TEST_CHECK(0==f0.peek(), "flag not initialized properly"); | |
| 78 f0.setbits(0x1); | |
| 79 CYG_TEST_CHECK(1==f0.peek(), "setbits"); | |
| 80 f0.setbits(0x3); | |
| 81 CYG_TEST_CHECK(3==f0.peek(), "setbits"); | |
| 82 f0.maskbits(~0x5); | |
| 83 CYG_TEST_CHECK(2==f0.peek(), "maskbits"); | |
| 84 f0.setbits(); | |
| 85 CYG_TEST_CHECK(~0u==f0.peek(), "setbits no arg"); | |
| 86 f0.maskbits(); | |
| 87 CYG_TEST_CHECK(0==f0.peek(), "maskbits no arg"); | |
| 88 CYG_TEST_CHECK(0==q++, "bad synchronization"); | |
| 89 | |
| 90 CYG_TEST_INFO("Testing wait()"); | |
| 91 f1.setbits(0x4); | |
| 92 CYG_TEST_CHECK(0x4==f1.peek(), "maskbits no arg"); | |
| 93 CYG_TEST_CHECK(1==q++, "bad synchronization"); | |
| 94 f1.setbits(0x18); // wake t1 | |
| 95 f1.wait(0x11, Cyg_Flag::AND | Cyg_Flag::CLR); | |
| 96 CYG_TEST_CHECK(0==f1.peek(), "flag value wrong"); | |
| 97 CYG_TEST_CHECK(3==q++, "bad synchronization"); | |
| 98 f0.setbits(0x2); // wake t1 | |
| 99 f1.wait(0x10, Cyg_Flag::AND ); | |
| 100 f0.setbits(0x1); // wake t1 | |
| 101 | |
| 102 f1.wait(0x11, Cyg_Flag::AND | Cyg_Flag::CLR); | |
| 103 | |
| 104 #ifdef CYGFUN_KERNEL_THREADS_TIMER | |
| 105 f2.wait(0x2, Cyg_Flag::OR); | |
| 106 CYG_TEST_CHECK(20==q,"bad synchronization"); | |
| 107 f2.wait(0x10, Cyg_Flag::AND, | |
|
157
b65ec671dd4c
Merge from eCos master repository on 2001-04-06-18:28:36-BST
jlarmour
parents:
130
diff
changeset
|
108 Cyg_Clock::real_time_clock->current_value()+THIRD_THREAD_WAIT_TIME); |
| 0 | 109 CYG_TEST_CHECK(21==q++,"bad synchronization"); |
| 110 #endif | |
| 111 f0.wait(1, Cyg_Flag::OR); | |
| 112 | |
| 113 CYG_TEST_FAIL_FINISH("Not reached"); | |
| 114 } | |
| 115 | |
| 116 static void entry1( CYG_ADDRWORD data ) | |
| 117 { | |
| 118 f1.wait(0xc, Cyg_Flag::AND); | |
| 119 CYG_TEST_CHECK(2==q++, "bad synchronization"); | |
| 120 CYG_TEST_CHECK(0x1c==f1.peek(), "flag value wrong"); | |
| 121 f1.setbits(0x1); // wake t0 | |
| 122 f0.wait(0x3, Cyg_Flag::OR); | |
| 123 CYG_TEST_CHECK(4==q++, "bad synchronization"); | |
| 124 CYG_TEST_CHECK(2==f0.peek(), "flag value wrong"); | |
| 125 | |
| 126 f1.setbits(0xf0); // wake t0,t2 | |
| 127 f0.wait(0x5, Cyg_Flag::AND | Cyg_Flag::CLR); // wait for t0 & t2 | |
| 128 CYG_TEST_CHECK(0==f0.peek(), "flag value wrong"); | |
| 129 CYG_TEST_CHECK(0xf0==f1.peek(), "flag value wrong"); | |
| 130 CYG_TEST_CHECK(5==q++, "bad synchronization"); | |
| 131 f1.maskbits(); | |
| 132 CYG_TEST_CHECK(0==f1.peek(), "flag value wrong"); | |
| 133 | |
| 134 CYG_TEST_INFO("Testing poll()"); | |
| 135 f0.setbits(0x55); | |
| 136 CYG_TEST_CHECK(0x55==f0.peek(), "flag value wrong"); | |
| 137 CYG_TEST_CHECK(0x55==f0.poll(0x3, Cyg_Flag::OR),"bad poll() return"); | |
| 138 CYG_TEST_CHECK(0==f0.poll(0xf, Cyg_Flag::AND),"poll()"); | |
| 139 CYG_TEST_CHECK(0==f0.poll(0xa, Cyg_Flag::OR),"poll()"); | |
| 140 CYG_TEST_CHECK(0x55==f0.peek(), "flag value wrong"); | |
| 141 CYG_TEST_CHECK(0x55==f0.poll(0xf, Cyg_Flag::OR | Cyg_Flag::CLR),"poll"); | |
| 142 CYG_TEST_CHECK(0x0==f0.peek(), "flag value wrong"); | |
| 143 f0.setbits(0x50); | |
| 144 CYG_TEST_CHECK(0x50==f0.poll(0x10, Cyg_Flag::AND | Cyg_Flag::CLR),"poll"); | |
| 145 CYG_TEST_CHECK(0x0==f0.peek(), "flag value wrong"); | |
| 146 | |
| 147 CYG_TEST_INFO("Testing waiting()"); | |
| 148 f0.maskbits(); | |
| 149 CYG_TEST_CHECK(!f0.waiting(), "waiting()"); | |
| 150 | |
| 151 #ifdef CYGFUN_KERNEL_THREADS_TIMER | |
|
157
b65ec671dd4c
Merge from eCos master repository on 2001-04-06-18:28:36-BST
jlarmour
parents:
130
diff
changeset
|
152 thread[1]->delay( 10 ); // allow other threads to reach wait on f1 |
| 0 | 153 CYG_TEST_CHECK(f1.waiting(), "waiting() not true"); |
| 154 f1.setbits(); // wake one of t0,t2 | |
| 155 CYG_TEST_CHECK(f1.waiting(), "waiting() not true"); | |
| 156 #else | |
| 157 f1.setbits(0x11); // wake one of t0,t2 | |
| 158 #endif | |
| 159 f1.setbits(0x11); // wake other of t0,t2 | |
| 160 CYG_TEST_CHECK(!f1.waiting(), "waiting not false"); | |
| 161 | |
| 162 #ifdef CYGFUN_KERNEL_THREADS_TIMER | |
| 163 CYG_TEST_INFO("Testing wait() with timeout"); | |
| 164 q=20; | |
| 165 f2.setbits(0x2); // synchronize with t0,t2 | |
| 166 CYG_TEST_CHECK(20==q,"bad synchronization"); | |
| 167 f2.wait(0x20, Cyg_Flag::AND, | |
|
157
b65ec671dd4c
Merge from eCos master repository on 2001-04-06-18:28:36-BST
jlarmour
parents:
130
diff
changeset
|
168 Cyg_Clock::real_time_clock->current_value()+SECOND_THREAD_WAIT_TIME); |
| 0 | 169 CYG_TEST_CHECK(22==q++,"bad synchronization"); |
| 170 #endif | |
| 171 | |
| 172 CYG_TEST_PASS_FINISH("Flag 1 OK"); | |
| 173 } | |
| 174 | |
| 175 static void entry2( CYG_ADDRWORD data ) | |
| 176 { | |
| 177 f1.wait(0x60, Cyg_Flag::OR); | |
| 178 f0.setbits(0x4); | |
| 179 | |
| 180 f1.wait(0x11, Cyg_Flag::AND | Cyg_Flag::CLR); | |
| 181 #ifdef CYGFUN_KERNEL_THREADS_TIMER | |
| 182 f2.wait(0x2, Cyg_Flag::OR); | |
| 183 CYG_TEST_CHECK(20==q,"bad synchronization"); | |
| 184 CYG_TEST_CHECK(0==f2.wait(0x40, Cyg_Flag::AND, | |
|
157
b65ec671dd4c
Merge from eCos master repository on 2001-04-06-18:28:36-BST
jlarmour
parents:
130
diff
changeset
|
185 Cyg_Clock::real_time_clock->current_value()+FIRST_THREAD_WAIT_TIME), |
| 0 | 186 "timed wait() wrong"); |
| 187 CYG_TEST_CHECK(20==q++,"bad synchronization"); | |
| 188 // Now wake t0 before it times out | |
| 189 f2.setbits(0x10); | |
| 190 #endif | |
| 191 f0.wait(1, Cyg_Flag::OR); | |
| 192 | |
| 193 CYG_TEST_FAIL_FINISH("Not reached"); | |
| 194 } | |
| 195 | |
| 196 void flag1_main( void ) | |
| 197 { | |
| 198 CYG_TEST_INIT(); | |
| 199 | |
| 200 new_thread(entry0, 0); | |
| 201 new_thread(entry1, 1); | |
| 202 new_thread(entry2, 2); | |
| 203 | |
| 204 Cyg_Scheduler::start(); | |
| 205 | |
| 206 CYG_TEST_FAIL_FINISH("Not reached"); | |
| 207 } | |
| 208 | |
| 209 externC void | |
| 210 cyg_start( void ) | |
| 211 { | |
|
130
eb9fd8c04db3
Merge from eCos master repository on 2000-10-23-17:01:37-BST
jlarmour
parents:
66
diff
changeset
|
212 #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
|
213 cyg_hal_invoke_constructors(); |
|
eb9fd8c04db3
Merge from eCos master repository on 2000-10-23-17:01:37-BST
jlarmour
parents:
66
diff
changeset
|
214 #endif |
| 0 | 215 flag1_main(); |
| 216 } | |
| 217 | |
| 218 // EOF flag1.cxx |
