|
1 | | -#![allow(dead_code)] //suppress warning for these functions not being used in targets other than the tests |
| 1 | +#![allow(dead_code)] //suppress warning for these functions not being used in targets other than the |
| 2 | + // tests |
2 | 3 |
|
3 | 4 | #[allow(unused_parens)] |
4 | | -#[cfg(test)] |
5 | | -pub mod test_sys { |
| 5 | +#[cfg(test)] |
| 6 | +pub mod sys_tests { |
6 | 7 | use super::super::*; |
7 | 8 | use crate::interface; |
8 | | - use crate::safeposix::syscalls::sys_calls::*; |
9 | | - |
10 | | - pub fn test_sys() { |
11 | | - ut_lind_getpid(); |
12 | | - ut_lind_getppid(); |
13 | | - ut_lind_getegid(); |
14 | | - ut_lind_getuid(); |
15 | | - ut_lind_geteuid(); |
16 | | - ut_lind_getgid(); |
17 | | - ut_lind_fork(); |
18 | | - } |
| 9 | + use crate::safeposix::cage::{FileDescriptor::*, *}; |
| 10 | + use crate::safeposix::{cage::*, dispatcher::*, filesystem}; |
19 | 11 |
|
| 12 | + #[test] |
20 | 13 | pub fn ut_lind_getpid() { |
21 | | - lindrustinit(0); |
22 | | - let cage = interface::cagetable_getref(1); |
23 | | - assert_eq!(cage.getpid_syscall(),1); |
| 14 | + //acquiring a lock on TESTMUTEX prevents other tests from running concurrently, |
| 15 | + // and also performs clean env setup |
| 16 | + let _thelock = setup::lock_and_init(); |
| 17 | + let cage = interface::cagetable_getref(1); |
| 18 | + assert_eq!(cage.getpid_syscall(), 1); |
24 | 19 | lindrustfinalize(); |
25 | | - } |
| 20 | + } |
26 | 21 |
|
| 22 | + #[test] |
27 | 23 | pub fn ut_lind_getppid() { |
28 | | - lindrustinit(0); |
29 | | - let cage = interface::cagetable_getref(1); |
| 24 | + //acquiring a lock on TESTMUTEX prevents other tests from running concurrently, |
| 25 | + // and also performs clean env setup |
| 26 | + let _thelock = setup::lock_and_init(); |
| 27 | + let cage = interface::cagetable_getref(1); |
30 | 28 | cage.fork_syscall(2); |
31 | 29 | let cage2 = interface::cagetable_getref(2); |
32 | | - assert_eq!(cage2.getppid_syscall(),1); |
33 | | - lindrustfinalize(); |
34 | | - |
35 | | - } |
| 30 | + assert_eq!(cage2.getppid_syscall(), 1); |
| 31 | + lindrustfinalize(); |
| 32 | + } |
36 | 33 |
|
| 34 | + #[test] |
37 | 35 | pub fn ut_lind_getuid() { |
38 | | - lindrustinit(0); |
| 36 | + //acquiring a lock on TESTMUTEX prevents other tests from running concurrently, |
| 37 | + // and also performs clean env setup |
| 38 | + let _thelock = setup::lock_and_init(); |
| 39 | + let cage = interface::cagetable_getref(1); |
39 | 40 | // The first call to geteuid always returns -1 |
40 | | - assert_eq!(cage.getuid_syscall(),-1); |
| 41 | + assert_eq!(cage.getuid_syscall(), -1); |
41 | 42 | // Subsequent calls return the default value |
42 | | - assert_eq!(cage.getuid_syscall(),DEFAULT_UID); |
| 43 | + assert_eq!(cage.getuid_syscall(), DEFAULT_UID as i32); |
43 | 44 | lindrustfinalize() |
44 | 45 | } |
45 | 46 |
|
| 47 | + #[test] |
46 | 48 | pub fn ut_lind_geteuid() { |
47 | | - lindrustinit(0); |
| 49 | + //acquiring a lock on TESTMUTEX prevents other tests from running concurrently, |
| 50 | + // and also performs clean env setup |
| 51 | + let _thelock = setup::lock_and_init(); |
48 | 52 | let cage = interface::cagetable_getref(1); |
49 | 53 | // The first call to geteuid always returns -1 |
50 | | - assert_eq!(cage.geteuid_syscall(),-1); |
| 54 | + assert_eq!(cage.geteuid_syscall(), -1); |
51 | 55 | // Subsequent calls return the default value |
52 | | - assert_eq!(cage.geteuid_syscall(),DEFAULT_UID); |
| 56 | + assert_eq!(cage.geteuid_syscall(), DEFAULT_UID as i32); |
53 | 57 | lindrustfinalize() |
54 | 58 | } |
55 | 59 |
|
| 60 | + #[test] |
56 | 61 | pub fn ut_lind_getgid() { |
57 | | - lindrustinit(0); |
| 62 | + //acquiring a lock on TESTMUTEX prevents other tests from running concurrently, |
| 63 | + // and also performs clean env setup |
| 64 | + let _thelock = setup::lock_and_init(); |
58 | 65 | let cage = interface::cagetable_getref(1); |
59 | 66 | // The first call to geteuid always returns -1 |
60 | | - assert_eq!(cage.getgid_syscall(),-1); |
| 67 | + assert_eq!(cage.getgid_syscall(), -1); |
61 | 68 | // Subsequent calls return the default value |
62 | | - assert_eq!(cage.getgid_syscall(),DEFAULT_GID); |
| 69 | + assert_eq!(cage.getgid_syscall(), DEFAULT_GID as i32); |
63 | 70 | lindrustfinalize() |
64 | | - } |
| 71 | + } |
65 | 72 |
|
| 73 | + #[test] |
66 | 74 | pub fn ut_lind_getegid() { |
67 | | - lindrustinit(0); |
| 75 | + //acquiring a lock on TESTMUTEX prevents other tests from running concurrently, |
| 76 | + // and also performs clean env setup |
| 77 | + let _thelock = setup::lock_and_init(); |
68 | 78 | let cage = interface::cagetable_getref(1); |
69 | 79 | // The first call to geteuid always returns -1 |
70 | | - assert_eq!(cage.getegid_syscall(),-1); |
| 80 | + assert_eq!(cage.getegid_syscall(), -1); |
71 | 81 | // Subsequent calls return the default value |
72 | | - assert_eq!(cage.getegid_syscall(),DEFAULT_GID); |
| 82 | + assert_eq!(cage.getegid_syscall(), DEFAULT_GID as i32); |
73 | 83 | lindrustfinalize() |
74 | | - } |
| 84 | + } |
75 | 85 |
|
| 86 | + #[test] |
76 | 87 | pub fn ut_lind_fork() { |
77 | 88 | // Since the fork syscall is heavily tested in relation to other syscalls |
78 | 89 | // we only perform simple checks for testing the sanity of the fork syscall |
79 | | - lindrustinit(0); |
80 | | - let cage = interface::cagetable_getref(1); |
81 | | - // Spawn a new child object using the fork syscall |
82 | | - cage.fork_syscall(2); |
| 90 | + //acquiring a lock on TESTMUTEX prevents other tests from running concurrently, |
| 91 | + // and also performs clean env setup |
| 92 | + let _thelock = setup::lock_and_init(); |
| 93 | + let cage = interface::cagetable_getref(1); |
| 94 | + // Spawn a new child object using the fork syscall |
| 95 | + cage.fork_syscall(2); |
83 | 96 | // Search for the new cage object with cage_id = 2 |
84 | | - let child_cage = interface::cagetable_getref(2); |
| 97 | + let child_cage = interface::cagetable_getref(2); |
85 | 98 | // Assert the parent value is the the id of the first cage object |
86 | | - assert_eq!(child_cage.getpid_syscall(),1); |
87 | | - // Assert that the cage id of the child is the value passed in the original fork syscall |
88 | | - assert_eq!(child_cage.getuid(),2); |
89 | | - // Assert that the cwd is the same as the parent cage object |
90 | | - assert_eq!(child_cage.cwd.read(),cage.cwd.read()) |
| 99 | + assert_eq!(child_cage.getppid_syscall(), 1); |
| 100 | + // Assert that the cage id of the child is the value passed in the original fork |
| 101 | + // syscall |
| 102 | + assert_eq!(child_cage.getuid_syscall(), -1); |
| 103 | + assert_eq!(child_cage.getuid_syscall(), DEFAULT_UID as i32); |
| 104 | + lindrustfinalize(); |
91 | 105 | } |
92 | 106 |
|
| 107 | + #[test] |
93 | 108 | pub fn ut_lind_exit() { |
94 | | - // Since exit function is heavily used and tested in other syscalls and their tests |
95 | | - // We only perform preliminary checks for checking the sanity of this syscall |
96 | | - // We don't check for cases such as exiting a cage twice - since the exiting process |
97 | | - // is handled by the NaCl runtime - and it ensures that a cage does not exit twice |
98 | | - lindrustinit(0); |
| 109 | + // Since exit function is heavily used and tested in other syscalls and their |
| 110 | + // tests We only perform preliminary checks for checking the sanity of |
| 111 | + // this syscall We don't check for cases such as exiting a cage twice - |
| 112 | + // since the exiting process is handled by the NaCl runtime - and it |
| 113 | + // ensures that a cage does not exit twice acquiring a lock on TESTMUTEX |
| 114 | + // prevents other tests from running concurrently, and also performs |
| 115 | + // clean env setup |
| 116 | + let _thelock = setup::lock_and_init(); |
99 | 117 | let cage = interface::cagetable_getref(1); |
100 | 118 | // Call the exit call |
101 | | - assert_eq(cage.exit_syscall(EXIT_SUCCESS),EXIT_SUCCESS); |
102 | | - lindrustfinalize(); |
| 119 | + assert_eq!(cage.exit_syscall(EXIT_SUCCESS), EXIT_SUCCESS); |
| 120 | + lindrustfinalize(); |
103 | 121 | } |
104 | | -} |
105 | 122 |
|
| 123 | + #[test] |
| 124 | + pub fn ut_lind_exec() { |
| 125 | + //acquiring a lock on TESTMUTEX prevents other tests from running concurrently, |
| 126 | + // and also performs clean env setup |
| 127 | + let _thelock = setup::lock_and_init(); |
| 128 | + let cage1 = interface::cagetable_getref(1); |
| 129 | + // Spawn a new child |
| 130 | + cage1.fork_syscall(2); |
| 131 | + // Assert that the fork was correct |
| 132 | + let child_cage = interface::cagetable_getref(2); |
| 133 | + assert_eq!(child_cage.getuid_syscall(), -1); |
| 134 | + assert_eq!(child_cage.getuid_syscall(), DEFAULT_UID as i32); |
| 135 | + // Spawn exec and check if it returns 0 |
| 136 | + assert_eq!(cage1.exec_syscall(2), 0); |
| 137 | + lindrustfinalize(); |
| 138 | + } |
| 139 | +} |
0 commit comments