Mercurial > nand-ecoscentric
annotate packages/kernel/current/tests/kmbox1.c @ 3403:8c8767bb9a62 default tip
devs/nand/micron_mt29: Remove defunct references (in comments) to mt29f2g08_oob_ecc.
| author | Ross Younger <wry@ecoscentric.com> |
|---|---|
| date | Sun, 18 Jan 2015 17:59:01 +1300 |
| parents | 80f232caf539 |
| children |
| rev | line source |
|---|---|
| 0 | 1 /*========================================================================== |
| 2 // | |
| 3 // kmbox1.cxx | |
| 4 // | |
| 5 // Kernel Mbox test 1 | |
| 6 // | |
| 7 //========================================================================== | |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2310
diff
changeset
|
8 // ####ECOSGPLCOPYRIGHTBEGIN#### |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2310
diff
changeset
|
9 // ------------------------------------------- |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2310
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:
2310
diff
changeset
|
11 // Copyright (C) 1998, 1999, 2000, 2001, 2002, 2006 Free Software Foundation, Inc. |
|
208
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
12 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2310
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:
2310
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:
2310
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:
2310
diff
changeset
|
16 // version. |
|
208
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
17 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2310
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:
2310
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:
2310
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:
2310
diff
changeset
|
21 // for more details. |
|
208
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
22 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2310
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:
2310
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:
2310
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:
66
diff
changeset
|
26 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2310
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:
2310
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:
2310
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:
2310
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:
2310
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:
2310
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:
2310
diff
changeset
|
33 // General Public License v2. |
|
208
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
34 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2310
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:
2310
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:
2310
diff
changeset
|
37 // ------------------------------------------- |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2310
diff
changeset
|
38 // ####ECOSGPLCOPYRIGHTEND#### |
| 0 | 39 //========================================================================== |
| 40 //#####DESCRIPTIONBEGIN#### | |
| 41 // | |
| 42 // Author: dsm | |
| 43 // Contributors: dsm | |
| 44 // Date: 1998-06-02 | |
| 45 // Description: Tests basic mbox functionality. | |
| 46 //####DESCRIPTIONEND#### | |
| 47 */ | |
| 48 | |
| 2 | 49 #include <cyg/hal/hal_arch.h> // CYGNUM_HAL_STACK_SIZE_TYPICAL |
| 50 | |
| 0 | 51 #include <cyg/kernel/kapi.h> |
| 52 | |
| 53 #include <cyg/infra/testcase.h> | |
| 54 | |
| 55 #ifdef CYGFUN_KERNEL_API_C | |
| 56 | |
| 57 #include "testaux.h" | |
| 58 | |
| 59 #define NTHREADS 2 | |
| 2 | 60 #define STACKSIZE CYGNUM_HAL_STACK_SIZE_TYPICAL |
| 0 | 61 |
| 62 static cyg_handle_t thread[NTHREADS]; | |
| 63 | |
| 64 static cyg_thread thread_obj[NTHREADS]; | |
| 65 static char stack[NTHREADS][STACKSIZE]; | |
| 66 | |
| 67 static cyg_handle_t m0, m1, m2; | |
| 68 static cyg_mbox mbox0, mbox1, mbox2; | |
| 69 | |
| 70 static cyg_atomic q = 0; | |
| 71 | |
| 72 #ifndef CYGMTH_MBOX_PUT_CAN_WAIT | |
| 73 #define cyg_mbox_PUT cyg_mbox_tryput | |
| 74 #endif | |
| 75 | |
| 76 static void entry0( cyg_addrword_t data ) | |
| 77 { | |
| 78 cyg_count8 u,i,j; | |
| 79 | |
| 80 CYG_TEST_INFO("Testing put() and tryput() without wakeup"); | |
| 81 CYG_TEST_CHECK(!cyg_mbox_waiting_to_get(m0), "mbox not initialized properly"); | |
| 82 CYG_TEST_CHECK(0==cyg_mbox_peek(m0), "mbox not initialized properly"); | |
| 83 CYG_TEST_CHECK(NULL==cyg_mbox_peek_item(m0), "mbox not initialized properly"); | |
| 84 cyg_mbox_PUT(m0, (void *)55); | |
| 85 CYG_TEST_CHECK(1==cyg_mbox_peek(m0), "peek() wrong"); | |
| 86 CYG_TEST_CHECK(55==(cyg_count8)cyg_mbox_peek_item(m0), "peek_item() wrong"); | |
| 87 for(u=1; cyg_mbox_tryput(m0, (void*)u); u++) { | |
| 88 CYG_TEST_CHECK(55==(cyg_count8)cyg_mbox_peek_item(m0), "peek_item() wrong"); | |
| 89 CYG_TEST_CHECK(u+1==cyg_mbox_peek(m0), "peek() wrong"); | |
| 90 } | |
| 91 CYG_TEST_CHECK(u == CYGNUM_KERNEL_SYNCH_MBOX_QUEUE_SIZE, "mbox not configured size"); | |
| 92 | |
| 93 // m0 now contains ( 55 1 2 .. u-1 ) | |
| 94 CYG_TEST_CHECK(u==cyg_mbox_peek(m0), "peek() wrong"); | |
| 95 CYG_TEST_CHECK(55==(cyg_count8)cyg_mbox_peek_item(m0), "peek_item() wrong"); | |
| 96 | |
| 97 CYG_TEST_INFO("Testing get(), tryget()"); | |
| 98 | |
| 99 i = (cyg_count8)cyg_mbox_tryget(m0); | |
| 100 CYG_TEST_CHECK( 55 == i, "Got wrong message" ); | |
| 101 for(j=1; j<u;j++) { | |
| 102 CYG_TEST_CHECK( j == (cyg_count8)cyg_mbox_peek_item(m0), "peek_item()" ); | |
| 103 CYG_TEST_CHECK( cyg_mbox_peek(m0) == u - j, "peek() wrong" ); | |
| 104 i = (cyg_count8)cyg_mbox_get(m0); | |
| 105 CYG_TEST_CHECK( j == i, "Got wrong message" ); | |
| 106 } | |
| 107 | |
| 108 CYG_TEST_CHECK( NULL == cyg_mbox_peek_item(m0), "peek_item()" ); | |
| 109 CYG_TEST_CHECK( 0 == cyg_mbox_peek(m0), "peek()"); | |
| 110 | |
| 111 // m0 now empty | |
| 112 | |
| 113 CYG_TEST_CHECK(!cyg_mbox_waiting_to_put(m0), "waiting_to_put()"); | |
| 114 CYG_TEST_CHECK(!cyg_mbox_waiting_to_get(m0), "waiting_to_get()"); | |
| 115 | |
| 116 CYG_TEST_INFO("Testing get(), blocking"); | |
| 117 | |
| 118 CYG_TEST_CHECK(0==q++, "bad synchronization"); | |
| 119 cyg_mbox_PUT(m1, (void*)99); // wakes t1 | |
| 120 i = (cyg_count8)cyg_mbox_get(m0); // sent by t1 | |
| 121 CYG_TEST_CHECK(3==i, "Recieved wrong message"); | |
| 122 CYG_TEST_CHECK(2==q++, "bad synchronization"); | |
| 123 | |
| 124 #ifdef CYGFUN_KERNEL_THREADS_TIMER | |
| 2 | 125 CYG_TEST_CHECK(NULL==cyg_mbox_timed_get(m0, cyg_current_time()+10), |
| 0 | 126 "unexpectedly found message"); |
| 127 CYG_TEST_CHECK(3==q++, "bad synchronization"); | |
| 128 // Allow t1 to run as this get times out | |
| 129 // t1 must not be waiting... | |
| 130 CYG_TEST_CHECK(cyg_mbox_waiting_to_get(m0), "waiting_to_get()"); | |
| 131 | |
| 132 cyg_mbox_PUT(m0, (void*)7); // wake t1 from timed get | |
| 133 #ifdef CYGMTH_MBOX_PUT_CAN_WAIT | |
| 134 q=10; | |
| 135 while(cyg_mbox_tryput(m0, (void*)6)) // fill m0's queue | |
| 136 ; | |
| 137 // m0 now contains ( 6 ... 6 ) | |
| 138 CYG_TEST_CHECK(10==q++, "bad synchronization"); | |
| 139 cyg_mbox_put(m1, (void*)4); // wake t1 | |
| 2 | 140 CYG_TEST_CHECK(!cyg_mbox_timed_put(m0, (void*)8, cyg_current_time()+10), |
| 0 | 141 "timed put() unexpectedly worked"); |
| 142 CYG_TEST_CHECK(12==q++, "bad synchronization"); | |
| 143 // m0 still contains ( 6 ... 6 ) | |
| 144 cyg_mbox_put(m0, (void*)9); | |
| 145 CYG_TEST_CHECK(13==q++, "bad synchronization"); | |
| 146 #endif | |
| 147 #endif | |
| 148 i=(cyg_count8)cyg_mbox_get(m2); | |
| 149 CYG_TEST_FAIL_FINISH("Not reached"); | |
| 150 } | |
| 151 | |
| 152 static void entry1( cyg_addrword_t data ) | |
| 153 { | |
|
3209
80f232caf539
* tests/except1.cxx (cause_exception): Fix compiler warning about
sergeig
parents:
2729
diff
changeset
|
154 #ifdef CYGMTH_MBOX_PUT_CAN_WAIT |
| 0 | 155 cyg_count8 i; |
| 156 i = (cyg_count8)cyg_mbox_get(m1); | |
|
3209
80f232caf539
* tests/except1.cxx (cause_exception): Fix compiler warning about
sergeig
parents:
2729
diff
changeset
|
157 #endif |
| 0 | 158 CYG_TEST_CHECK(1==q++, "bad synchronization"); |
| 159 cyg_mbox_PUT(m0, (void *)3); // wake t0 | |
| 160 | |
| 2 | 161 #if defined(CYGFUN_KERNEL_THREADS_TIMER) |
| 0 | 162 CYG_TEST_INFO("Testing timed functions"); |
| 2 | 163 CYG_TEST_CHECK(7==(cyg_count8)cyg_mbox_timed_get(m0,cyg_current_time()+20), |
| 0 | 164 "timed get()"); |
| 165 CYG_TEST_CHECK(4==q++, "bad synchronization"); | |
| 166 #ifdef CYGMTH_MBOX_PUT_CAN_WAIT | |
| 167 CYG_TEST_CHECK(4==(cyg_count8)cyg_mbox_get(m1)); | |
| 168 | |
| 169 CYG_TEST_CHECK(11==q++, "bad synchronization"); | |
| 2 | 170 thread[0]->delay(20); // allow t0 to reach put on m1 |
| 0 | 171 CYG_TEST_CHECK(14==q++, "bad synchronization"); |
| 172 CYG_TEST_CHECK(cyg_mbox_waiting_to_put(m0), "waiting_to_put()"); | |
| 173 do { | |
| 174 // after first get m0 contains ( 6 .. 6 9 ) | |
| 175 i=(cyg_count8)cyg_mbox_tryget(m0); | |
| 176 } while(6==i); | |
| 177 CYG_TEST_CHECK(9==i,"put gone awry"); | |
| 178 #endif | |
| 179 #endif | |
| 180 CYG_TEST_PASS_FINISH("Kernel C API Mbox 1 OK"); | |
| 181 } | |
| 182 | |
| 183 void kmbox1_main( void ) | |
| 184 { | |
| 185 CYG_TEST_INIT(); | |
| 186 | |
| 187 cyg_thread_create(4, entry0 , (cyg_addrword_t)0, "kmbox1-0", | |
| 2 | 188 (void *)stack[0], STACKSIZE, &thread[0], &thread_obj[0]); |
| 0 | 189 cyg_thread_resume(thread[0]); |
| 190 | |
|
2310
4be03fe7814d
* cdl/synch.cdl: Added CYGIMP_MBOX_USE_MBOXT_PLAIN option. This is
nickg
parents:
210
diff
changeset
|
191 cyg_thread_create(5, entry1 , (cyg_addrword_t)1, "kmbox1-1", |
| 2 | 192 (void *)stack[1], STACKSIZE, &thread[1], &thread_obj[1]); |
| 0 | 193 cyg_thread_resume(thread[1]); |
| 194 | |
| 195 cyg_mbox_create( &m0, &mbox0 ); | |
| 196 cyg_mbox_create( &m1, &mbox1 ); | |
| 197 cyg_mbox_create( &m2, &mbox2 ); | |
| 198 | |
| 199 cyg_scheduler_start(); | |
| 200 | |
| 201 CYG_TEST_FAIL_FINISH("Not reached"); | |
| 202 } | |
| 203 | |
| 204 externC void | |
| 205 cyg_start( void ) | |
| 206 { | |
| 207 kmbox1_main(); | |
| 208 } | |
| 209 #else /* def CYGFUN_KERNEL_API_C */ | |
| 210 externC void | |
| 211 cyg_start( void ) | |
| 212 { | |
| 213 CYG_TEST_INIT(); | |
| 2 | 214 CYG_TEST_NA("Kernel C API layer disabled"); |
| 0 | 215 } |
| 216 #endif /* def CYGFUN_KERNEL_API_C */ | |
| 217 | |
| 218 /* EOF kmbox1.c */ |
