summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAri Hausman-Cohen <arihc@google.com>2015-08-11 17:25:27 -0700
committerAri Hausman-Cohen <arihc@google.com>2015-08-13 13:34:14 -0700
commitcc76bff0d0a26687b9117f748bb8473761cfdfe6 (patch)
treeb0aaf4c7b1337f4443899cfdb3f9827a7f977549
parent5d7fc29f9f5a9c9858f3df2395eed31abe72c5a7 (diff)
downloadlibchromeos-cc76bff0d0a26687b9117f748bb8473761cfdfe6.tar.gz
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
-rw-r--r--Android.mk14
-rw-r--r--chromeos/flag_helper_unittest.cc3
-rw-r--r--chromeos/process_unittest.cc17
3 files changed, 31 insertions, 3 deletions
diff --git a/Android.mk b/Android.mk
index 34d7f33..f6b33d7 100644
--- a/Android.mk
+++ b/Android.mk
@@ -107,8 +107,7 @@ libchromeos_test_sources := \
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_MODULE := libchromeos_test
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_CPPFLAGS := $(libchromeos_CFLAGS) -Wno-sign-compare
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 @@ class FlagHelperTest : public ::testing::Test {
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 @@ class ProcessTest : public ::testing::Test {
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 @@ TEST_F(ProcessTest, NoParams) {
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 @@ TEST_F(ProcessTest, SegFaultHandling) {
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);