From 5f7a847822718a6e60452a9ef6b0dc7a7758e6e2 Mon Sep 17 00:00:00 2001 From: Bo Chen Date: Fri, 3 Nov 2023 10:30:21 -0700 Subject: [PATCH] test_infra: Print error and output if host commands failed It helps with understanding integration test errors when host commands failed to run or complete. Signed-off-by: Bo Chen --- test_infra/src/lib.rs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/test_infra/src/lib.rs b/test_infra/src/lib.rs index b6237bf29..18953e9f5 100644 --- a/test_infra/src/lib.rs +++ b/test_infra/src/lib.rs @@ -719,17 +719,26 @@ pub fn ssh_command_ip( } pub fn exec_host_command_status(command: &str) -> ExitStatus { - std::process::Command::new("bash") - .args(["-c", command]) - .status() - .unwrap_or_else(|_| panic!("Expected '{command}' to run")) + exec_host_command_output(command).status } pub fn exec_host_command_output(command: &str) -> Output { - std::process::Command::new("bash") + let output = std::process::Command::new("bash") .args(["-c", command]) .output() - .unwrap_or_else(|_| panic!("Expected '{command}' to run")) + .unwrap_or_else(|e| panic!("Expected '{command}' to run. Error: {:?}", e)); + + if !output.status.success() { + let stdout = String::from_utf8_lossy(&output.stdout); + let stderr = String::from_utf8_lossy(&output.stderr); + eprintln!( + "\n\n==== Start 'exec_host_command' failed ==== \ + \n\n---stdout---\n{stdout}\n---stderr---{stderr} \ + \n\n==== End 'exec_host_command' failed ====", + ); + } + + output } pub const PIPE_SIZE: i32 = 32 << 20;