simpleperf: fix *handle_SIGHUP tests.

Fix record_cmd.handle_SIGHUP and omit stat_cmd.handle_SIGHUP
in cts tests.

Bug: 111648912
Bug: 79495636
Test: run CtsSimpleperfTestCases.

Change-Id: I3a540207082000a1d0cdf39ab53798411a8b4d24
Merged-In: I3a540207082000a1d0cdf39ab53798411a8b4d24
(cherry picked from commit 9bd7e57e5f68db6906b1d5fed9a9a76f6973f6ff)
diff --git a/simpleperf/cmd_record_test.cpp b/simpleperf/cmd_record_test.cpp
index 31f1727..64bc7fb 100644
--- a/simpleperf/cmd_record_test.cpp
+++ b/simpleperf/cmd_record_test.cpp
@@ -430,12 +430,21 @@
 
 TEST(record_cmd, handle_SIGHUP) {
   TemporaryFile tmpfile;
-  std::thread thread([]() {
-    sleep(1);
+  int pipefd[2];
+  ASSERT_EQ(0, pipe(pipefd));
+  int read_fd = pipefd[0];
+  int write_fd = pipefd[1];
+  char data[8] = {};
+  std::thread thread([&]() {
+    android::base::ReadFully(read_fd, data, 7);
     kill(getpid(), SIGHUP);
   });
-  thread.detach();
-  ASSERT_TRUE(RecordCmd()->Run({"-o", tmpfile.path, "sleep", "1000000"}));
+  ASSERT_TRUE(RecordCmd()->Run({"-o", tmpfile.path, "--start_profiling_fd",
+                                std::to_string(write_fd), "sleep", "1000000"}));
+  thread.join();
+  close(write_fd);
+  close(read_fd);
+  ASSERT_STREQ(data, "STARTED");
 }
 
 TEST(record_cmd, stop_when_no_more_targets) {
diff --git a/simpleperf/cmd_stat_test.cpp b/simpleperf/cmd_stat_test.cpp
index b6896e1..61b65a1 100644
--- a/simpleperf/cmd_stat_test.cpp
+++ b/simpleperf/cmd_stat_test.cpp
@@ -162,6 +162,11 @@
 }
 
 TEST(stat_cmd, handle_SIGHUP) {
+  if (!GetDefaultAppPackageName().empty()) {
+    // See http://b/79495636.
+    GTEST_LOG_(INFO) << "Omit this test in app's context.";
+    return;
+  }
   std::thread thread([]() {
     sleep(1);
     kill(getpid(), SIGHUP);