Snap for 6013487 from 8e8f1e9c82c946997959642073317784627919a5 to rvc-release

Change-Id: I557bed205e4a3d17a7e7d33ba530ffcffea77688
diff --git a/Isolate.cpp b/Isolate.cpp
index 756f194..889b183 100644
--- a/Isolate.cpp
+++ b/Isolate.cpp
@@ -617,9 +617,13 @@
     return;
   }
 
-  // Print failure message from the assertion (e.g. expected this and got that).
-  printf("%s:(%d) Failure in test %s.%s\n%s\n", result.file_name(), result.line_number(),
-         pinfo_->test_suite_name(), pinfo_->name(), result.message());
+  if (result.type() == ::testing::TestPartResult::kSkip) {
+    printf("%s:(%d) Skipped%s\n", result.file_name(), result.line_number(), result.message());
+  } else {
+    // Print failure message from the assertion (e.g. expected this and got that).
+    printf("%s:(%d) Failure in test %s.%s\n%s\n", result.file_name(), result.line_number(),
+           pinfo_->test_suite_name(), pinfo_->name(), result.message());
+  }
   fflush(stdout);
 }
 
diff --git a/Test.cpp b/Test.cpp
index e2351e3..327facd 100644
--- a/Test.cpp
+++ b/Test.cpp
@@ -18,6 +18,7 @@
 #include <stdio.h>
 #include <unistd.h>
 
+#include <regex>
 #include <string>
 #include <tuple>
 #include <vector>
@@ -32,6 +33,8 @@
 namespace android {
 namespace gtest_extras {
 
+std::regex Test::skipped_regex_("(^|\\n)[^\\n]+:\\(\\d+\\) Skipped\\n");
+
 Test::Test(std::tuple<std::string, std::string>& test, size_t index, size_t run_index, int fd)
     : suite_name_(std::get<0>(test)),
       test_name_(std::get<1>(test)),
@@ -114,42 +117,13 @@
 
   // Need to parse the output to determine if this test was skipped.
   // Format of a skipped test:
-  //   <filename>:(<line_number>) Failure in test <testname>
-  //   Skipped
+  //   <filename>:(<line_number>) Skipped
   //   <Skip Message>
 
-  // There can be multiple skip messages, so remove all of them.
-  size_t start_index = 0;
-  while (true) {
-    size_t skipped_index = output_.find("\nSkipped\n", start_index);
-    if (skipped_index == std::string::npos) {
-      return;
-    }
-    if (skipped_index == 0) {
-      // The output starts with Skipped, so skip over it and keep looking.
-      start_index = skipped_index + 9;
-      continue;
-    }
-    // Look backwards for start of line before "Skipped" message.
-    size_t failure_line_start = output_.rfind('\n', skipped_index - 1);
-    if (failure_line_start == std::string::npos) {
-      failure_line_start = 0;
-    }
-    skipped_index += 9;
-    size_t failure_index = output_.find(" Failure in test ", failure_line_start);
-    if (failure_index == std::string::npos || failure_index > skipped_index) {
-      // Could still be another skipped message matching the pattern after
-      // this one.
-      start_index = skipped_index - 1;
-      continue;
-    }
-    start_index = 0;
+  // If there are multiple skip messages, it doesn't matter, seeing
+  // even one indicates this is a skipped test.
+  if (std::regex_search(output_, skipped_regex_)) {
     result_ = TEST_SKIPPED;
-    if (failure_line_start != 0) {
-      output_ = output_.substr(0, failure_line_start + 1) + output_.substr(skipped_index);
-    } else {
-      output_ = output_.substr(skipped_index);
-    }
   }
 }
 
diff --git a/Test.h b/Test.h
index 147b6c8..b4a1182 100644
--- a/Test.h
+++ b/Test.h
@@ -16,6 +16,7 @@
 
 #pragma once
 
+#include <regex>
 #include <string>
 #include <tuple>
 
@@ -94,6 +95,8 @@
 
   TestResult result_ = TEST_NONE;
   std::string output_;
+
+  static std::regex skipped_regex_;
 };
 
 }  // namespace gtest_extras
diff --git a/tests/SystemTests.cpp b/tests/SystemTests.cpp
index ee7b176..821c055 100644
--- a/tests/SystemTests.cpp
+++ b/tests/SystemTests.cpp
@@ -309,6 +309,7 @@
       "Note: Google Test filter = *.DISABLED_skip_no_message\n"
       "[==========] Running 1 test from 1 test suite (20 jobs).\n"
       "[ RUN      ] SystemTests.DISABLED_skip_no_message\n"
+      "file:(XX) Skipped\n"
       "[  SKIPPED ] SystemTests.DISABLED_skip_no_message (XX ms)\n"
       "[==========] 1 test from 1 test suite ran. (XX ms total)\n"
       "[  PASSED  ] 0 tests.\n"
@@ -322,6 +323,7 @@
       "Note: Google Test filter = *.DISABLED_skip_with_message\n"
       "[==========] Running 1 test from 1 test suite (20 jobs).\n"
       "[ RUN      ] SystemTests.DISABLED_skip_with_message\n"
+      "file:(XX) Skipped\n"
       "This is a skip message\n"
       "[  SKIPPED ] SystemTests.DISABLED_skip_with_message (XX ms)\n"
       "[==========] 1 test from 1 test suite ran. (XX ms total)\n"
@@ -337,6 +339,7 @@
       "[==========] Running 1 test from 1 test suite (20 jobs).\n"
       "[ RUN      ] SystemTests.DISABLED_skip_with_output_before\n"
       "This is the message before the skip message\n"
+      "file:(XX) Skipped\n"
       "This is the skip message\n"
       "[  SKIPPED ] SystemTests.DISABLED_skip_with_output_before (XX ms)\n"
       "[==========] 1 test from 1 test suite ran. (XX ms total)\n"
@@ -351,6 +354,7 @@
       "Note: Google Test filter = *.DISABLED_skip_with_output_after\n"
       "[==========] Running 1 test from 1 test suite (20 jobs).\n"
       "[ RUN      ] SystemTests.DISABLED_skip_with_output_after\n"
+      "file:(XX) Skipped\n"
       "This is the skip message\n"
       "This is the message after the skip message\n"
       "[  SKIPPED ] SystemTests.DISABLED_skip_with_output_after (XX ms)\n"
@@ -368,8 +372,10 @@
       "[ RUN      ] SystemTests.DISABLED_skip_with_skipped_line\n"
       "\n"
       "Skipped\n"
+      "file:(XX) Skipped\n"
       "This is the skip message 1\n"
       "Skipped\n"
+      "file:(XX) Skipped\n"
       "This is the skip message 2\n"
       "Skipped\n"
       "[  SKIPPED ] SystemTests.DISABLED_skip_with_skipped_line (XX ms)\n"
@@ -386,9 +392,12 @@
       "[==========] Running 1 test from 1 test suite (20 jobs).\n"
       "[ RUN      ] SystemTests.DISABLED_skip_multiple\n"
       "This is not a skip message 1\n"
+      "file:(XX) Skipped\n"
       "This is the skip message 1\n"
       "This is not a skip message 2\n"
+      "file:(XX) Skipped\n"
       "This is the skip message 2\n"
+      "file:(XX) Skipped\n"
       "This is the skip message 3\n"
       "This is not a skip message 4\n"
       "[  SKIPPED ] SystemTests.DISABLED_skip_multiple (XX ms)\n"
@@ -404,6 +413,7 @@
       "Note: Google Test filter = *.DISABLED_skip_no_message\n"
       "[==========] Running 1 test from 1 test suite (20 jobs).\n"
       "[ RUN      ] SystemTests.DISABLED_skip_no_message\n"
+      "file:(XX) Skipped\n"
       "[  SKIPPED ] SystemTests.DISABLED_skip_no_message\n"
       "[==========] 1 test from 1 test suite ran. (XX ms total)\n"
       "[  PASSED  ] 0 tests.\n"
@@ -418,6 +428,7 @@
       "\x1B[0;33mNote: Google Test filter = *.DISABLED_skip_no_message\x1B[m\n"
       "\x1B[0;32m[==========]\x1B[m Running 1 test from 1 test suite (20 jobs).\n"
       "\x1B[0;32m[ RUN      ]\x1B[m SystemTests.DISABLED_skip_no_message\n"
+      "file:(XX) Skipped\n"
       "\x1B[0;32m[  SKIPPED ]\x1B[m SystemTests.DISABLED_skip_no_message (XX ms)\n"
       "\x1B[0;32m[==========]\x1B[m 1 test from 1 test suite ran. (XX ms total)\n"
       "\x1B[0;32m[  PASSED  ]\x1B[m 0 tests.\n"