|
0
|
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 |
|
2
|
25 // by Cygnus are Copyright (C) 1998,1999 Cygnus Solutions. All Rights Reserved. |
|
0
|
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 |
|
2
|
56 #ifdef CYGFUN_KERNEL_THREADS_TIMER |
|
|
57 |
|
0
|
58 #include <cyg/kernel/sched.inl> |
|
|
59 #include <cyg/kernel/thread.inl> |
|
|
60 |
|
|
61 #include "testaux.hxx" |
|
|
62 |
|
2
|
63 #ifdef CYGNUM_HAL_STACK_SIZE_TYPICAL |
|
|
64 #define STACKSIZE CYGNUM_HAL_STACK_SIZE_TYPICAL |
|
|
65 #else |
|
0
|
66 #define STACKSIZE 2000 |
|
2
|
67 #endif |
|
0
|
68 |
|
|
69 static char stack[2][STACKSIZE]; |
|
|
70 |
|
|
71 static char thread[2][sizeof(Cyg_Thread)]; |
|
|
72 |
|
|
73 static Cyg_Thread *pt0,*pt1; |
|
|
74 static cyg_uint16 uid0,uid1; |
|
|
75 |
|
|
76 |
|
|
77 static void entry0( CYG_ADDRWORD data ) |
|
|
78 { |
|
|
79 CHECK( 222 == data ); |
|
|
80 |
|
|
81 uid0 = pt0->get_unique_id(); |
|
|
82 |
|
|
83 pt1->suspend(); |
|
|
84 pt1->resume(); |
|
|
85 |
|
|
86 do { |
|
2
|
87 pt0->delay(1); |
|
0
|
88 } while( Cyg_Thread::RUNNING == pt1->get_state() ); |
|
|
89 |
|
|
90 CHECK( Cyg_Thread::SLEEPING == pt1->get_state() ); |
|
|
91 |
|
|
92 pt1->wake(); |
|
|
93 |
|
|
94 CHECK( uid0 != uid1 ); |
|
|
95 |
|
|
96 CYG_TEST_PASS_FINISH("Thread 1 OK"); |
|
|
97 } |
|
|
98 |
|
|
99 static void entry1( CYG_ADDRWORD data ) |
|
|
100 { |
|
|
101 CHECK( 333 == data ); |
|
|
102 |
|
|
103 uid1 = pt1->get_unique_id(); |
|
|
104 |
|
|
105 Cyg_Thread *self = Cyg_Thread::self(); |
|
|
106 |
|
|
107 CHECK( self == pt1 ); |
|
|
108 |
|
|
109 pt1->sleep(); |
|
|
110 pt1->suspend(); |
|
|
111 |
|
2
|
112 Cyg_Thread::exit(); // no guarantee this will be called |
|
0
|
113 } |
|
|
114 |
|
|
115 void thread1_main( void ) |
|
|
116 { |
|
|
117 CYG_TEST_INIT(); |
|
|
118 |
|
|
119 pt0 = new((void *)&thread[0]) |
|
2
|
120 Cyg_Thread(CYG_SCHED_DEFAULT_INFO, |
|
|
121 entry0, 222, |
|
|
122 "thread 0", |
|
|
123 (CYG_ADDRESS)stack[0], STACKSIZE ); |
|
0
|
124 pt1 = new((void *)&thread[1]) |
|
2
|
125 Cyg_Thread(CYG_SCHED_DEFAULT_INFO, |
|
|
126 entry1, 333, |
|
|
127 "thread 1", |
|
|
128 (CYG_ADDRESS)stack[1], STACKSIZE ); |
|
0
|
129 |
|
|
130 CYG_ASSERTCLASS( pt0, "error" ); |
|
|
131 CYG_ASSERTCLASS( pt1, "error" ); |
|
|
132 |
|
|
133 pt0->resume(); |
|
|
134 pt1->resume(); |
|
|
135 |
|
|
136 Cyg_Scheduler::start(); |
|
|
137 |
|
|
138 CYG_TEST_FAIL_FINISH("Not reached"); |
|
|
139 } |
|
|
140 |
|
|
141 externC void |
|
|
142 cyg_start( void ) |
|
|
143 { |
|
|
144 thread1_main(); |
|
|
145 } |
|
|
146 |
|
2
|
147 #else // ifdef CYGFUN_KERNEL_THREADS_TIMER |
|
|
148 |
|
|
149 externC void |
|
|
150 cyg_start( void ) |
|
|
151 { |
|
|
152 CYG_TEST_INIT(); |
|
|
153 CYG_TEST_NA("Kernel threads timer disabled"); |
|
|
154 } |
|
|
155 |
|
|
156 #endif // ifdef CYGFUN_KERNEL_THREADS_TIMER |
|
|
157 |
|
0
|
158 // EOF thread1.cxx |