Mercurial > ecos
comparison packages/kernel/current/tests/thread1.cxx @ 0:3111d98ba7b3 ecos-v1_1-release
Initial commit of eCos version 1.1
| author | jlarmour |
|---|---|
| date | Tue, 11 May 1999 11:16:07 +0000 |
| parents | |
| children | 443894e2e912 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:3111d98ba7b3 |
|---|---|
| 1 //========================================================================== | |
| 2 // | |
| 3 // thread1.cxx | |
| 4 // | |
| 5 // Thread test 1 | |
| 6 // | |
| 7 //========================================================================== | |
| 8 //####COPYRIGHTBEGIN#### | |
| 9 // | |
| 10 // ------------------------------------------- | |
| 11 // The contents of this file are subject to the Cygnus eCos Public License | |
| 12 // Version 1.0 (the "License"); you may not use this file except in | |
| 13 // compliance with the License. You may obtain a copy of the License at | |
| 14 // http://sourceware.cygnus.com/ecos | |
| 15 // | |
| 16 // Software distributed under the License is distributed on an "AS IS" | |
| 17 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the | |
| 18 // License for the specific language governing rights and limitations under | |
| 19 // the License. | |
| 20 // | |
| 21 // The Original Code is eCos - Embedded Cygnus Operating System, released | |
| 22 // September 30, 1998. | |
| 23 // | |
| 24 // The Initial Developer of the Original Code is Cygnus. Portions created | |
| 25 // by Cygnus are Copyright (C) 1998 Cygnus Solutions. All Rights Reserved. | |
| 26 // ------------------------------------------- | |
| 27 // | |
| 28 //####COPYRIGHTEND#### | |
| 29 //========================================================================== | |
| 30 //#####DESCRIPTIONBEGIN#### | |
| 31 // | |
| 32 // Author(s): dsm | |
| 33 // Contributors: dsm | |
| 34 // Date: 1998-02-11 | |
| 35 // Description: Tests some basic thread functions. | |
| 36 // Omissions: Cyg_ThreadTimer | |
| 37 // Cyg_Thread | |
| 38 // exit -- not necessarily called | |
| 39 // yield | |
| 40 // set_priority | |
| 41 // get_priority | |
| 42 // get/set_sleep_reason | |
| 43 // get/set_wake_reason | |
| 44 // set/clear_timer | |
| 45 // Cyg_ThreadQueue | |
| 46 // | |
| 47 //####DESCRIPTIONEND#### | |
| 48 | |
| 49 #include <pkgconf/kernel.h> | |
| 50 | |
| 51 #include <cyg/kernel/sched.hxx> | |
| 52 #include <cyg/kernel/thread.hxx> | |
| 53 | |
| 54 #include <cyg/infra/testcase.h> | |
| 55 | |
| 56 #include <cyg/kernel/sched.inl> | |
| 57 #include <cyg/kernel/thread.inl> | |
| 58 | |
| 59 #include "testaux.hxx" | |
| 60 | |
| 61 #define STACKSIZE 2000 | |
| 62 | |
| 63 static char stack[2][STACKSIZE]; | |
| 64 | |
| 65 static char thread[2][sizeof(Cyg_Thread)]; | |
| 66 | |
| 67 inline void *operator new(size_t size, void *ptr) { return ptr; }; | |
| 68 | |
| 69 static Cyg_Thread *pt0,*pt1; | |
| 70 static cyg_uint16 uid0,uid1; | |
| 71 | |
| 72 | |
| 73 static void entry0( CYG_ADDRWORD data ) | |
| 74 { | |
| 75 CHECK( 222 == data ); | |
| 76 | |
| 77 uid0 = pt0->get_unique_id(); | |
| 78 | |
| 79 pt1->suspend(); | |
| 80 pt1->resume(); | |
| 81 | |
| 82 do { | |
| 83 pt0->delay(1); | |
| 84 } while( Cyg_Thread::RUNNING == pt1->get_state() ); | |
| 85 | |
| 86 CHECK( Cyg_Thread::SLEEPING == pt1->get_state() ); | |
| 87 | |
| 88 pt1->wake(); | |
| 89 | |
| 90 CHECK( uid0 != uid1 ); | |
| 91 | |
| 92 CYG_TEST_PASS_FINISH("Thread 1 OK"); | |
| 93 } | |
| 94 | |
| 95 static void entry1( CYG_ADDRWORD data ) | |
| 96 { | |
| 97 CHECK( 333 == data ); | |
| 98 | |
| 99 uid1 = pt1->get_unique_id(); | |
| 100 | |
| 101 Cyg_Thread *self = Cyg_Thread::self(); | |
| 102 | |
| 103 CHECK( self == pt1 ); | |
| 104 | |
| 105 pt1->sleep(); | |
| 106 pt1->suspend(); | |
| 107 | |
| 108 Cyg_Thread::exit(); // no guarantee this will be called | |
| 109 } | |
| 110 | |
| 111 void thread1_main( void ) | |
| 112 { | |
| 113 CYG_TEST_INIT(); | |
| 114 | |
| 115 pt0 = new((void *)&thread[0]) | |
| 116 Cyg_Thread(entry0, 222, STACKSIZE, (CYG_ADDRESS)stack[0] ); | |
| 117 pt1 = new((void *)&thread[1]) | |
| 118 Cyg_Thread(entry1, 333, STACKSIZE, (CYG_ADDRESS)stack[1] ); | |
| 119 | |
| 120 CYG_ASSERTCLASS( pt0, "error" ); | |
| 121 CYG_ASSERTCLASS( pt1, "error" ); | |
| 122 | |
| 123 pt0->resume(); | |
| 124 pt1->resume(); | |
| 125 | |
| 126 Cyg_Scheduler::start(); | |
| 127 | |
| 128 CYG_TEST_FAIL_FINISH("Not reached"); | |
| 129 } | |
| 130 | |
| 131 externC void | |
| 132 cyg_start( void ) | |
| 133 { | |
| 134 thread1_main(); | |
| 135 } | |
| 136 | |
| 137 // EOF thread1.cxx |
