()
| 2134 | |
| 2135 | #[test] |
| 2136 | fn test_serial_file() { |
| 2137 | let disk_config = UbuntuDiskConfig::new(JAMMY_IMAGE_NAME.to_string()); |
| 2138 | let guest = Guest::new(Box::new(disk_config)); |
| 2139 | |
| 2140 | let serial_path = guest.tmp_dir.as_path().join("serial-output"); |
| 2141 | #[cfg(target_arch = "x86_64")] |
| 2142 | let console_str: &str = "console=ttyS0"; |
| 2143 | #[cfg(target_arch = "aarch64")] |
| 2144 | let console_str: &str = "console=ttyAMA0"; |
| 2145 | |
| 2146 | let mut child = GuestCommand::new(&guest) |
| 2147 | .default_cpus() |
| 2148 | .default_memory() |
| 2149 | .args(["--kernel", direct_kernel_boot_path().to_str().unwrap()]) |
| 2150 | .args([ |
| 2151 | "--cmdline", |
| 2152 | DIRECT_KERNEL_BOOT_CMDLINE |
| 2153 | .replace("console=hvc0", console_str) |
| 2154 | .as_str(), |
| 2155 | ]) |
| 2156 | .default_disks() |
| 2157 | .default_net() |
| 2158 | .args([ |
| 2159 | "--serial", |
| 2160 | format!("file={}", serial_path.to_str().unwrap()).as_str(), |
| 2161 | ]) |
| 2162 | .capture_output() |
| 2163 | .spawn() |
| 2164 | .unwrap(); |
| 2165 | |
| 2166 | let r = std::panic::catch_unwind(|| { |
| 2167 | guest.wait_vm_boot().unwrap(); |
| 2168 | |
| 2169 | // Test that there is a ttyS0 |
| 2170 | assert_eq!( |
| 2171 | guest |
| 2172 | .ssh_command(GREP_SERIAL_IRQ_CMD) |
| 2173 | .unwrap() |
| 2174 | .trim() |
| 2175 | .parse::<u32>() |
| 2176 | .unwrap_or_default(), |
| 2177 | 1 |
| 2178 | ); |
| 2179 | |
| 2180 | guest.ssh_command("sudo shutdown -h now").unwrap(); |
| 2181 | }); |
| 2182 | |
| 2183 | let _ = child.wait_timeout(std::time::Duration::from_secs(20)); |
| 2184 | kill_child(&mut child); |
| 2185 | let output = child.wait_with_output().unwrap(); |
| 2186 | handle_child_output(r, &output); |
| 2187 | |
| 2188 | let r = std::panic::catch_unwind(|| { |
| 2189 | // Check that the cloud-hypervisor binary actually terminated |
| 2190 | assert!(output.status.success()); |
| 2191 | |
| 2192 | // Do this check after shutdown of the VM as an easy way to ensure |
| 2193 | // all writes are flushed to disk |
nothing calls this directly
no test coverage detected