Fix Chrome OS unit tests am: 9131f6c360
am: 81be8b2dde

Change-Id: I5a0427d1a4c8377d47a068d5feb98bb217a5eab0
diff --git a/Makefile b/Makefile
index 24e7836..2982aac 100644
--- a/Makefile
+++ b/Makefile
@@ -31,18 +31,22 @@
 CPPFLAGS += -DUSE_EXIT_ON_DIE
 endif
 
+# Setting this flag will run more unit tests that need a certain well-known
+# environment to run successfully.
+ifeq ($(USE_RUN_USER_NAMESPACE_TESTS),yes)
+CPPFLAGS += -DRUN_USER_NAMESPACE_TESTS
+endif
+
 CFLAGS += -Wextra -Wno-missing-field-initializers
 CXXFLAGS += -Wextra -Wno-missing-field-initializers
 
 USE_SYSTEM_GTEST ?= no
 ifeq ($(USE_SYSTEM_GTEST),no)
 GTEST_CXXFLAGS := -std=gnu++11
-GTEST_MAIN := gtest_main.a
 GTEST_LIBS := gtest.a
 else
-GTEST_CXXFLAGS := $(gtest-config --cxxflags)
-GTEST_MAIN := -lgtest -lgtest_main
-GTEST_LIBS := $(gtest-config --libs)
+GTEST_CXXFLAGS := $(shell gtest-config --cxxflags)
+GTEST_LIBS := $(shell gtest-config --libs)
 endif
 
 CORE_OBJECT_FILES := libminijail.o syscall_filter.o signal_handler.o \
diff --git a/libminijail_unittest.cc b/libminijail_unittest.cc
index 93e3790..d07ee4a 100644
--- a/libminijail_unittest.cc
+++ b/libminijail_unittest.cc
@@ -359,9 +359,13 @@
 }
 
 TEST(Test,
-#if defined(__ANDROID__)
+#if !defined(RUN_USER_NAMESPACE_TESTS)
 // TODO(lhchavez): Android unit tests don't currently support entering user
-// namespaces as unprivileged users.
+// namespaces as unprivileged users due to having an older kernel.
+// Chrome OS unit tests don't support it either due to being in a chroot
+// environment (see man 2 clone for more information about failure modes with
+// the CLONE_NEWUSER flag).
+// Only run this test when explicitly asked to do so.
 DISABLED_test_tmpfs_userns
 #else
 test_tmpfs_userns