summary refs log tree commit diff
path: root/io_jail
diff options
context:
space:
mode:
authorZach Reizner <zachr@google.com>2017-10-31 21:57:37 -0700
committerchrome-bot <chrome-bot@chromium.org>2017-11-01 14:06:30 -0700
commitad98452a14a9b5f61a0845a40590422691f9a8d5 (patch)
tree37af4655600fce6013194c7876105ef3bf0408e6 /io_jail
parent082aecec87e818a971d7a2c3c548e8aaf4745bd6 (diff)
downloadcrosvm-ad98452a14a9b5f61a0845a40590422691f9a8d5.tar
crosvm-ad98452a14a9b5f61a0845a40590422691f9a8d5.tar.gz
crosvm-ad98452a14a9b5f61a0845a40590422691f9a8d5.tar.bz2
crosvm-ad98452a14a9b5f61a0845a40590422691f9a8d5.tar.lz
crosvm-ad98452a14a9b5f61a0845a40590422691f9a8d5.tar.xz
crosvm-ad98452a14a9b5f61a0845a40590422691f9a8d5.tar.zst
crosvm-ad98452a14a9b5f61a0845a40590422691f9a8d5.zip
io_jail: correct io_jail tests that used Minijail::enter()
This also updates the `build_test.py` to use the command line option to
run certain certain test modules serially.

TEST=./build_test
BUG=None

Change-Id: I8a498514cb6b89fab01f02d0ef8faf39629f717c
Reviewed-on: https://chromium-review.googlesource.com/748824
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Diffstat (limited to 'io_jail')
-rw-r--r--io_jail/src/lib.rs23
1 files changed, 15 insertions, 8 deletions
diff --git a/io_jail/src/lib.rs b/io_jail/src/lib.rs
index e70cdb7..2ac27c3 100644
--- a/io_jail/src/lib.rs
+++ b/io_jail/src/lib.rs
@@ -362,8 +362,14 @@ impl Minijail {
     /// This Function may abort in the child on error because a partially
     /// entered jail isn't recoverable.
     pub unsafe fn fork(&self, inheritable_fds: Option<&[RawFd]>) -> Result<pid_t> {
-        if !is_single_threaded().map_err(Error::CheckingMultiThreaded)? {
-            return Err(Error::ForkingWhileMultiThreaded);
+        // This test will fail during `cargo test` because the test harness always spawns a test
+        // thread. We will make an exception for that case because the tests for this module should
+        // always be run in a serial fashion using `--test-threads=1`.
+        #[cfg(not(test))]
+        {
+            if !is_single_threaded().map_err(Error::CheckingMultiThreaded)? {
+                return Err(Error::ForkingWhileMultiThreaded);
+            }
         }
 
         if let Some(keep_fds) = inheritable_fds {
@@ -453,7 +459,7 @@ mod tests {
         j.parse_seccomp_filters(Path::new("src/test_filter.policy")).unwrap();
         j.use_seccomp_filter();
         unsafe {
-            j.enter(None).unwrap();
+            j.fork(None).unwrap();
         }
     }
 
@@ -468,9 +474,10 @@ mod tests {
             let second = libc::open(FILE_PATH.as_ptr() as *const i8, libc::O_RDONLY);
             assert!(second >= 0);
             let fds: Vec<RawFd> = vec![0, 1, 2, first];
-            j.enter(Some(&fds)).unwrap();
-            assert!(libc::close(second) < 0); // Should fail as second should be closed already.
-            assert_eq!(libc::close(first), 0); // Should succeed as first should be untouched.
+            if j.fork(Some(&fds)).unwrap() == 0 {
+                assert!(libc::close(second) < 0); // Should fail as second should be closed already.
+                assert_eq!(libc::close(first), 0); // Should succeed as first should be untouched.
+            }
         }
     }
 
@@ -480,7 +487,7 @@ mod tests {
         let mut j = Minijail::new().unwrap();
         j.enter_chroot(Path::new(".")).unwrap();
         unsafe {
-            j.enter(None).unwrap();
+            j.fork(None).unwrap();
         }
     }
 
@@ -490,7 +497,7 @@ mod tests {
         let mut j = Minijail::new().unwrap();
         j.namespace_vfs();
         unsafe {
-            j.enter(None).unwrap();
+            j.fork(None).unwrap();
         }
     }
 }