Merge "Fix Soong mips builds"
diff --git a/tests/gtest_main.cpp b/tests/gtest_main.cpp
index a662c73..7360f12 100644
--- a/tests/gtest_main.cpp
+++ b/tests/gtest_main.cpp
@@ -442,6 +442,36 @@
   fflush(stdout);
 }
 
+std::string XmlEscape(const std::string& xml) {
+  std::string escaped;
+  escaped.reserve(xml.size());
+
+  for (auto c : xml) {
+    switch (c) {
+    case '<':
+      escaped.append("&lt;");
+      break;
+    case '>':
+      escaped.append("&gt;");
+      break;
+    case '&':
+      escaped.append("&amp;");
+      break;
+    case '\'':
+      escaped.append("&apos;");
+      break;
+    case '"':
+      escaped.append("&quot;");
+      break;
+    default:
+      escaped.append(1, c);
+      break;
+    }
+  }
+
+  return escaped;
+}
+
 // Output xml file when --gtest_output is used, write this function as we can't reuse
 // gtest.cc:XmlUnitTestResultPrinter. The reason is XmlUnitTestResultPrinter is totally
 // defined in gtest.cc and not expose to outside. What's more, as we don't run gtest in
@@ -497,7 +527,8 @@
       } else {
         fputs(">\n", fp);
         const std::string& test_output = testcase.GetTest(j).GetTestOutput();
-        fprintf(fp, "      <failure message=\"%s\" type=\"\">\n", test_output.c_str());
+        const std::string escaped_test_output = XmlEscape(test_output);
+        fprintf(fp, "      <failure message=\"%s\" type=\"\">\n", escaped_test_output.c_str());
         fputs("      </failure>\n", fp);
         fputs("    </testcase>\n", fp);
       }
diff --git a/tests/sys_select_test.cpp b/tests/sys_select_test.cpp
index c1732ee..96e7663 100644
--- a/tests/sys_select_test.cpp
+++ b/tests/sys_select_test.cpp
@@ -89,7 +89,13 @@
   ASSERT_EQ(-1, select(-1, &r, &w, &e, NULL));
   ASSERT_EQ(EINVAL, errno);
 
-  ASSERT_EQ(2, select(max, &r, &w, &e, NULL));
+  int num_fds = select(max, &r, &w, &e, NULL);
+  ASSERT_TRUE(num_fds == 2 || num_fds == 3) << "Num fds returned " << num_fds;
+  ASSERT_TRUE(FD_ISSET(STDOUT_FILENO, &w));
+  ASSERT_TRUE(FD_ISSET(STDERR_FILENO, &w));
+  if (num_fds == 3) {
+    ASSERT_TRUE(FD_ISSET(STDIN_FILENO, &r));
+  }
 
   // Invalid timeout.
   timeval tv;
@@ -135,7 +141,13 @@
   ASSERT_EQ(-1, pselect(-1, &r, &w, &e, NULL, &ss));
   ASSERT_EQ(EINVAL, errno);
 
-  ASSERT_EQ(2, pselect(max, &r, &w, &e, NULL, &ss));
+  int num_fds = pselect(max, &r, &w, &e, NULL, &ss);
+  ASSERT_TRUE(num_fds == 2 || num_fds == 3) << "Num fds returned " << num_fds;
+  ASSERT_TRUE(FD_ISSET(STDOUT_FILENO, &w));
+  ASSERT_TRUE(FD_ISSET(STDERR_FILENO, &w));
+  if (num_fds == 3) {
+    ASSERT_TRUE(FD_ISSET(STDIN_FILENO, &r));
+  }
 
   // Invalid timeout.
   timespec tv;