From 2441798fe4e4e4bb8d0beb2a2b56730374187e9b Mon Sep 17 00:00:00 2001 From: Bo Chen Date: Thu, 24 Sep 2020 19:52:51 -0700 Subject: [PATCH] tests: Resize the pipe size to 256K for capturing child stdout/err As discussed in #1707, the `vcpu` thread can be stalled when using `--serial tty`. To workaround that issue, this patch enforces to resize the pipe size to 256K when we capture the stdout/stderr of the cloud-hypervisor child process in the integration tests. Note that the pipe size (256K) is chosen based on the output size of our integration tests at this point, which may need to be increased in the future. Signed-off-by: Bo Chen --- tests/integration.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/tests/integration.rs b/tests/integration.rs index 4b6c8faf0..d2dc051a9 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -24,6 +24,7 @@ mod tests { use std::io::BufRead; use std::io::{Read, Write}; use std::net::TcpStream; + use std::os::unix::io::AsRawFd; use std::path::{Path, PathBuf}; use std::process::{Child, Command, Stdio}; use std::string::String; @@ -90,6 +91,8 @@ mod tests { const DIRECT_KERNEL_BOOT_CMDLINE: &str = "root=/dev/vda1 console=ttyS0 console=hvc0 quiet rw"; + const PIPE_SIZE: i32 = 256 << 10; + impl UbuntuDiskConfig { fn new(image_name: String) -> Self { UbuntuDiskConfig { @@ -978,10 +981,26 @@ mod tests { fn spawn(&mut self) -> io::Result { if self.capture_output { - self.command + let child = self + .command .stderr(Stdio::piped()) .stdout(Stdio::piped()) .spawn() + .unwrap(); + + let fd = child.stdout.as_ref().unwrap().as_raw_fd(); + let pipesize = unsafe { libc::fcntl(fd, libc::F_SETPIPE_SZ, PIPE_SIZE) }; + let fd = child.stderr.as_ref().unwrap().as_raw_fd(); + let pipesize1 = unsafe { libc::fcntl(fd, libc::F_SETPIPE_SZ, PIPE_SIZE) }; + + if pipesize >= PIPE_SIZE && pipesize1 >= PIPE_SIZE { + Ok(child) + } else { + Err(std::io::Error::new( + std::io::ErrorKind::Other, + "resizing pipe w/ 'fnctl' failed!", + )) + } } else { self.command.spawn() }