@@ -37,6 +37,8 @@ mod metrics;
37
37
mod panic;
38
38
mod scheduler;
39
39
mod task;
40
+ #[ cfg( test) ]
41
+ mod tests;
40
42
mod time;
41
43
mod tracing;
42
44
mod traps;
@@ -50,10 +52,10 @@ use crate::time::clock::Ticks;
50
52
use crate :: time:: Instant ;
51
53
use crate :: vm:: bootstrap_alloc:: BootstrapAllocator ;
52
54
use arrayvec:: ArrayVec ;
55
+ use cfg_if:: cfg_if;
53
56
use core:: cell:: Cell ;
54
57
use core:: range:: Range ;
55
58
use core:: slice;
56
- use core:: time:: Duration ;
57
59
use cpu_local:: cpu_local;
58
60
use loader_api:: { BootInfo , LoaderConfig , MemoryRegionKind } ;
59
61
use rand:: SeedableRng ;
@@ -144,52 +146,58 @@ fn _start(cpuid: usize, boot_info: &'static BootInfo, boot_ticks: u64) -> ! {
144
146
tracing:: per_cpu_init_late ( Instant :: from_ticks ( Ticks ( boot_ticks) ) ) ;
145
147
146
148
// initialize the executor
147
- let sched = scheduler:: init ( boot_info. cpu_mask . count_ones ( ) as usize ) ;
149
+ let _sched = scheduler:: init ( boot_info. cpu_mask . count_ones ( ) as usize ) ;
148
150
149
151
tracing:: info!(
150
152
"Booted in ~{:?} ({:?} in k23)" ,
151
153
Instant :: now( ) . duration_since( Instant :: ZERO ) ,
152
154
Instant :: from_ticks( Ticks ( boot_ticks) ) . elapsed( )
153
155
) ;
154
156
155
- if cpuid == 0 {
156
- sched. spawn ( async move {
157
- tracing:: debug!( "before timeout" ) ;
158
- let start = Instant :: now ( ) ;
159
- let res =
160
- time:: timeout ( Duration :: from_secs ( 1 ) , time:: sleep ( Duration :: from_secs ( 5 ) ) ) . await ;
161
- tracing:: debug!( "after timeout {res:?}" ) ;
162
- assert ! ( res. is_err( ) ) ;
163
- assert_eq ! ( start. elapsed( ) . as_secs( ) , 1 ) ;
164
-
165
- tracing:: debug!( "before timeout" ) ;
166
- let start = Instant :: now ( ) ;
167
- let res =
168
- time:: timeout ( Duration :: from_secs ( 5 ) , time:: sleep ( Duration :: from_secs ( 1 ) ) ) . await ;
169
- tracing:: debug!( "after timeout {res:?}" ) ;
170
- assert ! ( res. is_ok( ) ) ;
171
- assert_eq ! ( start. elapsed( ) . as_secs( ) , 1 ) ;
172
-
173
- tracing:: debug!( "sleeping for 1 sec..." ) ;
174
- let start = Instant :: now ( ) ;
175
- time:: sleep ( Duration :: from_secs ( 1 ) ) . await ;
176
- assert_eq ! ( start. elapsed( ) . as_secs( ) , 1 ) ;
177
- tracing:: debug!( "slept 1 sec! {:?}" , start. elapsed( ) ) ;
178
-
179
- // FIXME this is a quite terrible hack to get the scheduler to close in tests (otherwise
180
- // tests would run forever) we should find a proper way to shut down the scheduler when idle.
181
- #[ cfg( test) ]
182
- scheduler:: scheduler ( ) . shutdown ( ) ;
183
- } ) ;
184
-
185
- // scheduler::scheduler().spawn(async move {
186
- // tracing::debug!("Point A");
187
- // scheduler::yield_now().await;
188
- // tracing::debug!("Point B");
189
- // });
157
+ cfg_if ! {
158
+ if #[ cfg( test) ] {
159
+ let mut output = riscv:: hio:: HostStream :: new_stderr( ) ;
160
+ tests:: run_tests( & mut output, boot_info) ;
161
+ } else {
162
+ scheduler:: Worker :: new( _sched, cpuid, & mut rng) . run( ) ;
163
+ }
190
164
}
191
165
192
- scheduler:: Worker :: new ( sched, cpuid, & mut rng) . run ( ) ;
166
+ // if cpuid == 0 {
167
+ // sched.spawn(async move {
168
+ // tracing::debug!("before timeout");
169
+ // let start = Instant::now();
170
+ // let res =
171
+ // time::timeout(Duration::from_secs(1), time::sleep(Duration::from_secs(5))).await;
172
+ // tracing::debug!("after timeout {res:?}");
173
+ // assert!(res.is_err());
174
+ // assert_eq!(start.elapsed().as_secs(), 1);
175
+ //
176
+ // tracing::debug!("before timeout");
177
+ // let start = Instant::now();
178
+ // let res =
179
+ // time::timeout(Duration::from_secs(5), time::sleep(Duration::from_secs(1))).await;
180
+ // tracing::debug!("after timeout {res:?}");
181
+ // assert!(res.is_ok());
182
+ // assert_eq!(start.elapsed().as_secs(), 1);
183
+ //
184
+ // tracing::debug!("sleeping for 1 sec...");
185
+ // let start = Instant::now();
186
+ // time::sleep(Duration::from_secs(1)).await;
187
+ // assert_eq!(start.elapsed().as_secs(), 1);
188
+ // tracing::debug!("slept 1 sec! {:?}", start.elapsed());
189
+ //
190
+ //
191
+ // #[cfg(test)]
192
+ // scheduler::scheduler().shutdown();
193
+ // });
194
+ //
195
+ // // scheduler::scheduler().spawn(async move {
196
+ // // tracing::debug!("Point A");
197
+ // // scheduler::yield_now().await;
198
+ // // tracing::debug!("Point B");
199
+ // // });
200
+ // }
193
201
194
202
// wasm::test();
195
203
0 commit comments