[guest][integration] Strip prompts from guest output
Reduces some flakiness for linux tests.
Also adds the system ready check to linux multiprocessor tests.
Eventually I will refactor this so it's not so easy to forget.
TEST=guest_integration_tests
Change-Id: I8b66d71c4fca16fae1d79bcf3bb052a353add5df
diff --git a/bin/guest/integration_tests/main.cc b/bin/guest/integration_tests/main.cc
index f7d03e4..98f0c8b 100644
--- a/bin/guest/integration_tests/main.cc
+++ b/bin/guest/integration_tests/main.cc
@@ -98,6 +98,14 @@
"--cmdline=loglevel=0 console=hvc0 root=/dev/vda rw");
return true;
}
+
+ static bool SetUpGuest() {
+ if (WaitForShellReady() != ZX_OK) {
+ ADD_FAILURE() << "Failed to wait for shell";
+ return false;
+ }
+ return true;
+ }
};
TEST_F(LinuxMultiprocessorGuestTest, LaunchGuest) {
diff --git a/bin/guest/integration_tests/test_serial.cc b/bin/guest/integration_tests/test_serial.cc
index 682dd5c..701e33d 100644
--- a/bin/guest/integration_tests/test_serial.cc
+++ b/bin/guest/integration_tests/test_serial.cc
@@ -8,6 +8,7 @@
#include <lib/fxl/strings/string_printf.h>
#include <lib/zx/time.h>
#include <iostream>
+#include <regex>
static constexpr bool kGuestOutput = false;
static constexpr size_t kSerialBufferSize = 1024;
@@ -101,10 +102,15 @@
zx_status_t TestSerial::WaitForMarker(const std::string& marker,
std::string* result) {
+ std::regex prompt_re("[#$] ");
std::string output = buffer_;
buffer_.erase();
zx_status_t status;
do {
+ // We strip prompts from the output as a stopgap against linux guests
+ // interleaving the prompt randomly in the output.
+ output = std::regex_replace(output, prompt_re, "");
+
auto marker_loc = output.rfind(marker);
if (marker_loc != std::string::npos && !output.empty()) {
// Do not accept a marker that isn't terminated by a newline.