-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmod.rs
92 lines (79 loc) · 2.52 KB
/
mod.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#![allow(dead_code)] //suppress warning for these functions not being used in targets other than the tests
mod fs_tests;
mod ipc_tests;
mod networking_tests;
use crate::interface;
use crate::safeposix::{cage::*, filesystem::*};
#[cfg(test)]
mod main_tests {
use crate::tests::fs_tests::fs_tests::test_fs;
use crate::tests::ipc_tests::ipc_tests::test_ipc;
use crate::tests::networking_tests::net_tests::net_tests;
use crate::interface;
use crate::safeposix::{cage::*, dispatcher::*, filesystem::*};
use std::process::Command;
#[test]
pub fn tests() {
interface::RUSTPOSIX_TESTSUITE.store(true, interface::RustAtomicOrdering::Relaxed);
lindrustinit(0);
{
let cage = interface::cagetable_getref(1);
crate::lib_fs_utils::lind_deltree(&cage, "/");
assert_eq!(cage.mkdir_syscall("/dev", S_IRWXA), 0);
assert_eq!(
cage.mknod_syscall(
"/dev/null",
S_IFCHR as u32 | 0o777,
makedev(&DevNo { major: 1, minor: 3 })
),
0
);
assert_eq!(
cage.mknod_syscall(
"/dev/zero",
S_IFCHR as u32 | 0o777,
makedev(&DevNo { major: 1, minor: 5 })
),
0
);
assert_eq!(
cage.mknod_syscall(
"/dev/urandom",
S_IFCHR as u32 | 0o777,
makedev(&DevNo { major: 1, minor: 9 })
),
0
);
assert_eq!(
cage.mknod_syscall(
"/dev/random",
S_IFCHR as u32 | 0o777,
makedev(&DevNo { major: 1, minor: 8 })
),
0
);
assert_eq!(cage.exit_syscall(EXIT_SUCCESS), EXIT_SUCCESS);
}
lindrustfinalize();
println!("FS TESTS");
test_fs();
println!("NET TESTS");
net_tests();
println!("IPC TESTS");
test_ipc();
}
}
pub fn str2cbuf(ruststr: &str) -> *mut u8 {
let cbuflenexpected = ruststr.len();
let (ptr, len, _) = ruststr.to_string().into_raw_parts();
assert_eq!(len, cbuflenexpected);
return ptr;
}
pub fn sizecbuf<'a>(size: usize) -> Box<[u8]> {
let v = vec![0u8; size];
v.into_boxed_slice()
//buf.as_mut_ptr() as *mut u8
}
pub fn cbuf2str(buf: &[u8]) -> &str {
std::str::from_utf8(buf).unwrap()
}