Perfprofd: Refactor test code

Return an AssertionResult from CompareLogMessages, so that the
failure is attributed directly to a check in the test, not in
helper code.

Bug: 73175642
Test: perfprofd_test
Change-Id: Id3a4e7551bc9aacad9eb39c4d3e28656456d5472
diff --git a/perfprofd/tests/perfprofd_test.cc b/perfprofd/tests/perfprofd_test.cc
index 8712f0c..8314880 100644
--- a/perfprofd/tests/perfprofd_test.cc
+++ b/perfprofd/tests/perfprofd_test.cc
@@ -202,9 +202,8 @@
   // match, e.g. if we see the expected excerpt anywhere in the
   // result, it's a match (for exact match, set exact to true)
   //
-  void CompareLogMessages(const std::string& expected,
-                          const char* testpoint,
-                          bool exactMatch = false) {
+  ::testing::AssertionResult CompareLogMessages(const std::string& expected,
+                                                bool exactMatch = false) {
      std::string sqexp = squeezeWhite(expected, "expected");
 
      // Strip out JIT errors.
@@ -216,17 +215,18 @@
      std::string sqact = squeezeWhite(test_logger.JoinTestLog(" ", strip_jit), "actual");
 
      if (exactMatch) {
-       EXPECT_STREQ(sqexp.c_str(), sqact.c_str());
-     } else {
-       std::size_t foundpos = sqact.find(sqexp);
-       bool wasFound = true;
-       if (foundpos == std::string::npos) {
-         std::cerr << testpoint << ": expected result not found\n";
-         std::cerr << " Actual: \"" << sqact << "\"\n";
-         std::cerr << " Expected: \"" << sqexp << "\"\n";
-         wasFound = false;
+       if (sqexp == sqact) {
+         return ::testing::AssertionSuccess() << sqexp << " is equal to " << sqact;
        }
-       EXPECT_TRUE(wasFound);
+       return ::testing::AssertionFailure() << "Expected:" << std::endl << sqexp << std::endl
+                                            << "Received:" << std::endl << sqact;
+     } else {
+       if (sqact.find(sqexp) == std::string::npos) {
+         return ::testing::AssertionFailure()
+             << "Expected to find:" << std::endl << sqexp << std::endl
+             << "in:" << std::endl << sqact;
+       }
+       return ::testing::AssertionSuccess() << sqexp << " was found in " << sqact;
      }
   }
 
@@ -482,7 +482,7 @@
                                           );
 
   // check to make sure entire log matches
-  CompareLogMessages(expected, "MissingGMS");
+  EXPECT_TRUE(CompareLogMessages(expected));
 }
 
 
@@ -518,7 +518,7 @@
       I: profile collection skipped (missing config directory)
                                           );
   // check to make sure log excerpt matches
-  CompareLogMessages(expected, "MissingOptInSemaphoreFile");
+  EXPECT_TRUE(CompareLogMessages(expected));
 }
 
 TEST_F(PerfProfdTest, MissingPerfExecutable)
@@ -555,7 +555,7 @@
       I: profile collection skipped (missing 'perf' executable)
                                           );
   // check to make sure log excerpt matches
-  CompareLogMessages(expected, "MissingPerfExecutable");
+  EXPECT_TRUE(CompareLogMessages(expected));
 }
 
 TEST_F(PerfProfdTest, BadPerfRun)
@@ -597,7 +597,7 @@
                                           );
 
   // check to make sure log excerpt matches
-  CompareLogMessages(expected, "BadPerfRun");
+  EXPECT_TRUE(CompareLogMessages(expected));
 }
 
 TEST_F(PerfProfdTest, ConfigFileParsing)
@@ -631,7 +631,7 @@
                                           );
 
   // check to make sure log excerpt matches
-  CompareLogMessages(expected, "ConfigFileParsing");
+  EXPECT_TRUE(CompareLogMessages(expected));
 }
 
 TEST_F(PerfProfdTest, ProfileCollectionAnnotations)
@@ -1110,7 +1110,7 @@
       I: finishing Android Wide Profiling daemon
                                           );
   // check to make sure log excerpt matches
-  CompareLogMessages(expandVars(expected), "BasicRunWithLivePerf", true);
+  EXPECT_TRUE(CompareLogMessages(expandVars(expected), true));
 }
 
 TEST_F(PerfProfdTest, MultipleRunWithLivePerf)
@@ -1183,7 +1183,7 @@
       I: finishing Android Wide Profiling daemon
                                           );
   // check to make sure log excerpt matches
-  CompareLogMessages(expandVars(expected), "BasicRunWithLivePerf", true);
+  EXPECT_TRUE(CompareLogMessages(expandVars(expected), true));
 }
 
 TEST_F(PerfProfdTest, CallChainRunWithLivePerf)
@@ -1240,7 +1240,7 @@
       I: finishing Android Wide Profiling daemon
                                           );
   // check to make sure log excerpt matches
-  CompareLogMessages(expandVars(expected), "CallChainRunWithLivePerf", true);
+  EXPECT_TRUE(CompareLogMessages(expandVars(expected), true));
 
   // Check that we have at least one SampleEvent with a callchain.
   SampleEventIterator samples(encodedProfile);