1
0
Fork 0
mirror of https://github.com/containers/youki synced 2024-05-10 01:26:14 +02:00

move ipc-channel to dev dependencies

This commit is contained in:
yihuaf 2021-09-30 01:06:11 +02:00
parent 6850ee62f7
commit 6d4bda689d
3 changed files with 46 additions and 40 deletions

View File

@ -50,7 +50,6 @@ tabwriter = "1"
fastrand = "1.4.1"
crossbeam-channel = "0.5"
seccomp = { version = "0.1.0", path = "./seccomp" }
ipc-channel = "0.15.0"
[dev-dependencies]
# TODO: Fetch from crate.io instead of git when next release oci-spec-rs
@ -59,6 +58,7 @@ ipc-channel = "0.15.0"
oci-spec = { git = "https://github.com/containers/oci-spec-rs", rev = "5018f8e5b0355a82c08962cefa5ab07a05b930c6", features = ["proptests"] }
quickcheck = "1"
serial_test = "0.5.1"
ipc-channel = "0.15.0"
[profile.release]
lto = true

View File

@ -382,7 +382,7 @@ pub fn initialize_seccomp(seccomp: &LinuxSeccomp) -> Result<Option<io::RawFd>> {
#[cfg(test)]
mod tests {
use super::*;
use crate::utils;
use crate::utils::test_utils;
use anyhow::Result;
use oci_spec::runtime::Arch;
use oci_spec::runtime::{LinuxSeccompBuilder, LinuxSyscallBuilder};
@ -415,7 +415,7 @@ mod tests {
.syscalls(vec![syscall])
.build()?;
utils::test_in_child_process(|| {
test_utils::test_in_child_process(|| {
let _ = prctl::set_no_new_privileges(true);
initialize_seccomp(&seccomp_profile)?;
let ret = nix::unistd::getcwd();
@ -447,7 +447,7 @@ mod tests {
// We know linux and seccomp exist, so let's just unwrap.
let seccomp_profile = spec.linux().as_ref().unwrap().seccomp().as_ref().unwrap();
utils::test_in_child_process(|| {
test_utils::test_in_child_process(|| {
let _ = prctl::set_no_new_privileges(true);
initialize_seccomp(seccomp_profile)?;
@ -469,7 +469,7 @@ mod tests {
.architectures(vec![Arch::ScmpArchNative])
.syscalls(vec![syscall])
.build()?;
utils::test_in_child_process(|| {
test_utils::test_in_child_process(|| {
let _ = prctl::set_no_new_privileges(true);
let fd = initialize_seccomp(&seccomp_profile)?;
if fd.is_none() {

View File

@ -2,12 +2,9 @@
use anyhow::Context;
use anyhow::{bail, Result};
use ipc_channel::ipc;
use nix::sys::stat::Mode;
use nix::sys::statfs;
use nix::sys::wait;
use nix::unistd;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::ffi::CString;
use std::fs::{self, DirBuilder, File};
@ -218,42 +215,51 @@ pub fn create_temp_dir(test_name: &str) -> Result<TempDir> {
Ok(dir)
}
#[derive(Debug, Serialize, Deserialize)]
struct TestResult {
success: bool,
message: String,
}
#[cfg(test)]
pub(crate) mod test_utils {
use anyhow::Context;
use anyhow::{bail, Result};
use ipc_channel::ipc;
use nix::sys::wait;
use serde::{Deserialize, Serialize};
pub fn test_in_child_process<F: FnOnce() -> Result<()>>(cb: F) -> Result<()> {
let (sender, receiver) = ipc::channel::<TestResult>()?;
match unsafe { nix::unistd::fork()? } {
nix::unistd::ForkResult::Parent { child } => {
let res = receiver.recv().unwrap();
wait::waitpid(child, None)?;
#[derive(Debug, Serialize, Deserialize)]
struct TestResult {
success: bool,
message: String,
}
if !res.success {
bail!("child process failed: {}", res.message);
pub fn test_in_child_process<F: FnOnce() -> Result<()>>(cb: F) -> Result<()> {
let (sender, receiver) = ipc::channel::<TestResult>()?;
match unsafe { nix::unistd::fork()? } {
nix::unistd::ForkResult::Parent { child } => {
let res = receiver.recv().unwrap();
wait::waitpid(child, None)?;
if !res.success {
bail!("child process failed: {}", res.message);
}
}
}
nix::unistd::ForkResult::Child => {
let test_result = match cb() {
Ok(_) => TestResult {
success: true,
message: String::new(),
},
Err(err) => TestResult {
success: false,
message: err.to_string(),
},
};
sender
.send(test_result)
.context("failed to send from the child process")?;
std::process::exit(0);
}
};
nix::unistd::ForkResult::Child => {
let test_result = match cb() {
Ok(_) => TestResult {
success: true,
message: String::new(),
},
Err(err) => TestResult {
success: false,
message: err.to_string(),
},
};
sender
.send(test_result)
.context("failed to send from the child process")?;
std::process::exit(0);
}
};
Ok(())
Ok(())
}
}
#[cfg(test)]