-
Notifications
You must be signed in to change notification settings - Fork 1
/
ch3_taskinfo.rs
46 lines (41 loc) · 1.52 KB
/
ch3_taskinfo.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#![no_std]
#![no_main]
extern crate user_lib;
use user_lib::{
get_time, println, sleep, task_info, TaskInfo, TaskStatus, SYSCALL_EXIT, SYSCALL_GETTIMEOFDAY,
SYSCALL_TASK_INFO, SYSCALL_WRITE, SYSCALL_YIELD,
};
#[no_mangle]
pub fn main() -> usize {
let t1 = get_time() as usize;
let info = TaskInfo::new();
get_time();
sleep(500);
let t2 = get_time() as usize;
// 注意本次 task info 调用也计入
assert_eq!(0, task_info(&info));
let t3 = get_time() as usize;
assert!(3 <= info.syscall_times[SYSCALL_GETTIMEOFDAY]);
assert_eq!(1, info.syscall_times[SYSCALL_TASK_INFO]);
assert_eq!(0, info.syscall_times[SYSCALL_WRITE]);
assert!(0 < info.syscall_times[SYSCALL_YIELD]);
assert_eq!(0, info.syscall_times[SYSCALL_EXIT]);
assert!(t2 - t1 <= info.time + 1);
assert!(info.time < t3 - t1 + 100);
assert!(info.status == TaskStatus::Running);
// 想想为什么 write 调用是两次
println!("string from task info test\n");
let t4 = get_time() as usize;
assert_eq!(0, task_info(&info));
let t5 = get_time() as usize;
assert!(5 <= info.syscall_times[SYSCALL_GETTIMEOFDAY]);
assert_eq!(2, info.syscall_times[SYSCALL_TASK_INFO]);
assert_eq!(2, info.syscall_times[SYSCALL_WRITE]);
assert!(0 < info.syscall_times[SYSCALL_YIELD]);
assert_eq!(0, info.syscall_times[SYSCALL_EXIT]);
assert!(t4 - t1 <= info.time + 1);
assert!(info.time < t5 - t1 + 100);
assert!(info.status == TaskStatus::Running);
println!("Test task info OK!");
0
}