-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into pb_doc_stat_syscall
- Loading branch information
Showing
3 changed files
with
143 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,105 +1,139 @@ | ||
#![allow(dead_code)] //suppress warning for these functions not being used in targets other than the tests | ||
#![allow(dead_code)] //suppress warning for these functions not being used in targets other than the | ||
// tests | ||
|
||
#[allow(unused_parens)] | ||
#[cfg(test)] | ||
pub mod test_sys { | ||
#[cfg(test)] | ||
pub mod sys_tests { | ||
use super::super::*; | ||
use crate::interface; | ||
use crate::safeposix::syscalls::sys_calls::*; | ||
|
||
pub fn test_sys() { | ||
ut_lind_getpid(); | ||
ut_lind_getppid(); | ||
ut_lind_getegid(); | ||
ut_lind_getuid(); | ||
ut_lind_geteuid(); | ||
ut_lind_getgid(); | ||
ut_lind_fork(); | ||
} | ||
use crate::safeposix::cage::{FileDescriptor::*, *}; | ||
use crate::safeposix::{cage::*, dispatcher::*, filesystem}; | ||
|
||
#[test] | ||
pub fn ut_lind_getpid() { | ||
lindrustinit(0); | ||
let cage = interface::cagetable_getref(1); | ||
assert_eq!(cage.getpid_syscall(),1); | ||
//acquiring a lock on TESTMUTEX prevents other tests from running concurrently, | ||
// and also performs clean env setup | ||
let _thelock = setup::lock_and_init(); | ||
let cage = interface::cagetable_getref(1); | ||
assert_eq!(cage.getpid_syscall(), 1); | ||
lindrustfinalize(); | ||
} | ||
} | ||
|
||
#[test] | ||
pub fn ut_lind_getppid() { | ||
lindrustinit(0); | ||
let cage = interface::cagetable_getref(1); | ||
//acquiring a lock on TESTMUTEX prevents other tests from running concurrently, | ||
// and also performs clean env setup | ||
let _thelock = setup::lock_and_init(); | ||
let cage = interface::cagetable_getref(1); | ||
cage.fork_syscall(2); | ||
let cage2 = interface::cagetable_getref(2); | ||
assert_eq!(cage2.getppid_syscall(),1); | ||
lindrustfinalize(); | ||
|
||
} | ||
assert_eq!(cage2.getppid_syscall(), 1); | ||
lindrustfinalize(); | ||
} | ||
|
||
#[test] | ||
pub fn ut_lind_getuid() { | ||
lindrustinit(0); | ||
//acquiring a lock on TESTMUTEX prevents other tests from running concurrently, | ||
// and also performs clean env setup | ||
let _thelock = setup::lock_and_init(); | ||
let cage = interface::cagetable_getref(1); | ||
// The first call to geteuid always returns -1 | ||
assert_eq!(cage.getuid_syscall(),-1); | ||
assert_eq!(cage.getuid_syscall(), -1); | ||
// Subsequent calls return the default value | ||
assert_eq!(cage.getuid_syscall(),DEFAULT_UID); | ||
assert_eq!(cage.getuid_syscall(), DEFAULT_UID as i32); | ||
lindrustfinalize() | ||
} | ||
|
||
#[test] | ||
pub fn ut_lind_geteuid() { | ||
lindrustinit(0); | ||
//acquiring a lock on TESTMUTEX prevents other tests from running concurrently, | ||
// and also performs clean env setup | ||
let _thelock = setup::lock_and_init(); | ||
let cage = interface::cagetable_getref(1); | ||
// The first call to geteuid always returns -1 | ||
assert_eq!(cage.geteuid_syscall(),-1); | ||
assert_eq!(cage.geteuid_syscall(), -1); | ||
// Subsequent calls return the default value | ||
assert_eq!(cage.geteuid_syscall(),DEFAULT_UID); | ||
assert_eq!(cage.geteuid_syscall(), DEFAULT_UID as i32); | ||
lindrustfinalize() | ||
} | ||
|
||
#[test] | ||
pub fn ut_lind_getgid() { | ||
lindrustinit(0); | ||
//acquiring a lock on TESTMUTEX prevents other tests from running concurrently, | ||
// and also performs clean env setup | ||
let _thelock = setup::lock_and_init(); | ||
let cage = interface::cagetable_getref(1); | ||
// The first call to geteuid always returns -1 | ||
assert_eq!(cage.getgid_syscall(),-1); | ||
assert_eq!(cage.getgid_syscall(), -1); | ||
// Subsequent calls return the default value | ||
assert_eq!(cage.getgid_syscall(),DEFAULT_GID); | ||
assert_eq!(cage.getgid_syscall(), DEFAULT_GID as i32); | ||
lindrustfinalize() | ||
} | ||
} | ||
|
||
#[test] | ||
pub fn ut_lind_getegid() { | ||
lindrustinit(0); | ||
//acquiring a lock on TESTMUTEX prevents other tests from running concurrently, | ||
// and also performs clean env setup | ||
let _thelock = setup::lock_and_init(); | ||
let cage = interface::cagetable_getref(1); | ||
// The first call to geteuid always returns -1 | ||
assert_eq!(cage.getegid_syscall(),-1); | ||
assert_eq!(cage.getegid_syscall(), -1); | ||
// Subsequent calls return the default value | ||
assert_eq!(cage.getegid_syscall(),DEFAULT_GID); | ||
assert_eq!(cage.getegid_syscall(), DEFAULT_GID as i32); | ||
lindrustfinalize() | ||
} | ||
} | ||
|
||
#[test] | ||
pub fn ut_lind_fork() { | ||
// Since the fork syscall is heavily tested in relation to other syscalls | ||
// we only perform simple checks for testing the sanity of the fork syscall | ||
lindrustinit(0); | ||
let cage = interface::cagetable_getref(1); | ||
// Spawn a new child object using the fork syscall | ||
cage.fork_syscall(2); | ||
//acquiring a lock on TESTMUTEX prevents other tests from running concurrently, | ||
// and also performs clean env setup | ||
let _thelock = setup::lock_and_init(); | ||
let cage = interface::cagetable_getref(1); | ||
// Spawn a new child object using the fork syscall | ||
cage.fork_syscall(2); | ||
// Search for the new cage object with cage_id = 2 | ||
let child_cage = interface::cagetable_getref(2); | ||
let child_cage = interface::cagetable_getref(2); | ||
// Assert the parent value is the the id of the first cage object | ||
assert_eq!(child_cage.getpid_syscall(),1); | ||
// Assert that the cage id of the child is the value passed in the original fork syscall | ||
assert_eq!(child_cage.getuid(),2); | ||
// Assert that the cwd is the same as the parent cage object | ||
assert_eq!(child_cage.cwd.read(),cage.cwd.read()) | ||
assert_eq!(child_cage.getppid_syscall(), 1); | ||
// Assert that the cage id of the child is the value passed in the original fork | ||
// syscall | ||
assert_eq!(child_cage.getuid_syscall(), -1); | ||
assert_eq!(child_cage.getuid_syscall(), DEFAULT_UID as i32); | ||
lindrustfinalize(); | ||
} | ||
|
||
#[test] | ||
pub fn ut_lind_exit() { | ||
// Since exit function is heavily used and tested in other syscalls and their tests | ||
// We only perform preliminary checks for checking the sanity of this syscall | ||
// We don't check for cases such as exiting a cage twice - since the exiting process | ||
// is handled by the NaCl runtime - and it ensures that a cage does not exit twice | ||
lindrustinit(0); | ||
// Since exit function is heavily used and tested in other syscalls and their | ||
// tests We only perform preliminary checks for checking the sanity of | ||
// this syscall We don't check for cases such as exiting a cage twice - | ||
// since the exiting process is handled by the NaCl runtime - and it | ||
// ensures that a cage does not exit twice acquiring a lock on TESTMUTEX | ||
// prevents other tests from running concurrently, and also performs | ||
// clean env setup | ||
let _thelock = setup::lock_and_init(); | ||
let cage = interface::cagetable_getref(1); | ||
// Call the exit call | ||
assert_eq(cage.exit_syscall(EXIT_SUCCESS),EXIT_SUCCESS); | ||
lindrustfinalize(); | ||
assert_eq!(cage.exit_syscall(EXIT_SUCCESS), EXIT_SUCCESS); | ||
lindrustfinalize(); | ||
} | ||
} | ||
|
||
#[test] | ||
pub fn ut_lind_exec() { | ||
//acquiring a lock on TESTMUTEX prevents other tests from running concurrently, | ||
// and also performs clean env setup | ||
let _thelock = setup::lock_and_init(); | ||
let cage1 = interface::cagetable_getref(1); | ||
// Spawn a new child | ||
cage1.fork_syscall(2); | ||
// Assert that the fork was correct | ||
let child_cage = interface::cagetable_getref(2); | ||
assert_eq!(child_cage.getuid_syscall(), -1); | ||
assert_eq!(child_cage.getuid_syscall(), DEFAULT_UID as i32); | ||
// Spawn exec and check if it returns 0 | ||
assert_eq!(cage1.exec_syscall(2), 0); | ||
lindrustfinalize(); | ||
} | ||
} |