summaryrefslogtreecommitdiffstats
path: root/sandbox
diff options
context:
space:
mode:
authorjln@chromium.org <jln@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-05 19:01:51 +0000
committerjln@chromium.org <jln@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-05 19:01:51 +0000
commit054584c3921dc77f7a6fdcab2ebf2b0a4621cae8 (patch)
tree6d3564a9368c7b7da3e4e31d124246938e0f17d5 /sandbox
parentdd3df002acf7bc813598eebb51d55e49d9667346 (diff)
downloadchromium_src-054584c3921dc77f7a6fdcab2ebf2b0a4621cae8.zip
chromium_src-054584c3921dc77f7a6fdcab2ebf2b0a4621cae8.tar.gz
chromium_src-054584c3921dc77f7a6fdcab2ebf2b0a4621cae8.tar.bz2
Linux sandbox: add warning if running tests multithreaded.
BUG=169416 NOTRY=true Review URL: https://chromiumcodereview.appspot.com/12207004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@180747 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sandbox')
-rw-r--r--sandbox/linux/tests/main.cc1
-rw-r--r--sandbox/linux/tests/unit_tests.cc26
2 files changed, 22 insertions, 5 deletions
diff --git a/sandbox/linux/tests/main.cc b/sandbox/linux/tests/main.cc
index 4412645..8142545 100644
--- a/sandbox/linux/tests/main.cc
+++ b/sandbox/linux/tests/main.cc
@@ -4,7 +4,6 @@
#include "testing/gtest/include/gtest/gtest.h"
-
int main(int argc, char *argv[]) {
testing::InitGoogleTest(&argc, argv);
// Always go through re-execution for death tests.
diff --git a/sandbox/linux/tests/unit_tests.cc b/sandbox/linux/tests/unit_tests.cc
index 27707f9..3d049ab 100644
--- a/sandbox/linux/tests/unit_tests.cc
+++ b/sandbox/linux/tests/unit_tests.cc
@@ -24,8 +24,19 @@ int GetSubProcessTimeoutTimeInSeconds() {
return 10;
}
+// Returns the number of threads of the current process or -1.
+int CountThreads() {
+ struct stat task_stat;
+ int task_d = stat("/proc/self/task", &task_stat);
+ // task_stat.st_nlink should be the number of tasks + 2 (accounting for
+ // "." and "..".
+ if (task_d != 0 || task_stat.st_nlink < 3)
+ return -1;
+ return task_stat.st_nlink - 2;
}
+} // namespace
+
namespace sandbox {
static const int kExpectedValue = 42;
@@ -66,12 +77,19 @@ static void SetProcessTimeout(int time_in_seconds) {
// alarm.
}
+// Runs a test in a sub-process. This is necessary for most of the code
+// in the BPF sandbox, as it potentially makes global state changes and as
+// it also tends to raise fatal errors, if the code has been used in an
+// insecure manner.
void UnitTests::RunTestInProcess(UnitTests::Test test, void *arg,
DeathCheck death, const void *death_aux) {
- // Runs a test in a sub-process. This is necessary for most of the code
- // in the BPF sandbox, as it potentially makes global state changes and as
- // it also tends to raise fatal errors, if the code has been used in an
- // insecure manner.
+ if (CountThreads() != 1) {
+ // We need to use fork(), so we can't be multi-threaded.
+ // TODO(jln): change this to a fatal error once we can launch
+ // Android tests with --exe.
+ fprintf(stderr, "WARNING: running sandbox tests with multiple threads"
+ " is not supported and will make the tests flaky.\n");
+ }
int fds[2];
ASSERT_EQ(0, pipe(fds));
// Check that our pipe is not on one of the standard file descriptor.