Added unit test target, unit tests run and pass with bionic runner

As b/22772126 says, mm runtests should do the "right thing".
For clarity, this has been renamed so you use mm runtargettests.
The "right thing" is here interpreted to mean build & run the
unit tests using the bionic test runner on the target. All
tests should pass.

BUG: 22772126, 22874311
Change-Id: Id68bbf18bc7a8b3b36e80408af0399fdb53bad61
diff --git a/Android.mk b/Android.mk
index 34d7f33..f6b33d7 100644
--- a/Android.mk
+++ b/Android.mk
@@ -107,8 +107,7 @@
     chromeos/streams/stream_unittest.cc \
     chromeos/streams/stream_utils_unittest.cc \
     chromeos/strings/string_utils_unittest.cc \
-    chromeos/url_utils_unittest.cc \
-    testrunner_android.cc
+    chromeos/url_utils_unittest.cc
 
 libchromeos_CFLAGS := -Wall -D__BRILLO__ \
     -Wno-char-subscripts -Wno-missing-field-initializers \
@@ -258,7 +257,7 @@
 LOCAL_SRC_FILES := $(libchromeos_test_sources)
 LOCAL_C_INCLUDES := $(libchromeos_includes)
 LOCAL_STATIC_LIBRARIES := libgtest libchrome_test_helpers \
-    libchromeos-test-helpers libgmock
+    libchromeos-test-helpers libgmock libBionicGtestMain
 LOCAL_SHARED_LIBRARIES := $(libchromeos_shared_libraries) libchromeos libcurl \
     libchromeos-http libchromeos-stream libcrypto
 LOCAL_CFLAGS := $(libchromeos_CFLAGS)
@@ -266,4 +265,13 @@
 LOCAL_CLANG := true
 include $(BUILD_NATIVE_TEST)
 
+# Run unit tests on target
+# ========================================================
+# We su shell because process tests try setting "illegal"
+# uid/gids and expecting failures, but root can legally
+# set those to any value.
+runtargettests: libchromeos_test
+	adb sync
+	adb shell su shell /data/nativetest/libchromeos_test/libchromeos_test
+
 endif # HOST_OS == linux
diff --git a/chromeos/flag_helper_unittest.cc b/chromeos/flag_helper_unittest.cc
index bb2257e..3178aaa 100644
--- a/chromeos/flag_helper_unittest.cc
+++ b/chromeos/flag_helper_unittest.cc
@@ -18,6 +18,9 @@
  public:
   FlagHelperTest() {}
   ~FlagHelperTest() override { chromeos::FlagHelper::ResetForTesting(); }
+  static void SetUpTestCase() {
+      base::CommandLine::Init(0, nullptr);
+  }
 };
 
 // Test that the DEFINE_xxxx macros can create the respective variables
diff --git a/chromeos/process_unittest.cc b/chromeos/process_unittest.cc
index 81a8f34..c74e1ed 100644
--- a/chromeos/process_unittest.cc
+++ b/chromeos/process_unittest.cc
@@ -85,6 +85,12 @@
     ClearLog();
   }
 
+  static void SetUpTestCase() {
+    base::CommandLine::Init(0, nullptr);
+    ::chromeos::InitLog(chromeos::kLogToStderr);
+    ::chromeos::LogToString(true);
+  }
+
  protected:
   void CheckStderrCaptured();
   FilePath GetFdPath(int fd);
@@ -260,6 +266,7 @@
   EXPECT_EQ(-1, process_.Run());
 }
 
+#if !defined(__BRILLO__) // Bionic intercepts the segfault in brillo
 TEST_F(ProcessTest, SegFaultHandling) {
   process_.AddArg(kBinSh);
   process_.AddArg("-c");
@@ -267,6 +274,16 @@
   EXPECT_EQ(-1, process_.Run());
   EXPECT_TRUE(FindLog("did not exit normally: 11"));
 }
+#endif
+
+TEST_F(ProcessTest, KillHandling) {
+  process_.AddArg(kBinSh);
+  process_.AddArg("-c");
+  process_.AddArg("kill -KILL $$");
+  EXPECT_EQ(-1, process_.Run());
+  EXPECT_TRUE(FindLog("did not exit normally: 9"));
+}
+
 
 TEST_F(ProcessTest, KillNoPid) {
   process_.Kill(SIGTERM, 0);