You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by mp...@apache.org on 2016/08/24 18:48:16 UTC
[2/2] kudu git commit: tests: add --stress_cpu_threads argument
tests: add --stress_cpu_threads argument
This is equivalent to running 'stress -c <N>' except it's built into our
test binaries. This is quite handy for reproducing race conditions,
especially on dist-test where it isn't easy to just pop open another
terminal and run 'stress' at the same time.
Change-Id: I9214098a9f83fad78889b2ff9621b19109f92425
Reviewed-on: http://gerrit.cloudera.org:8080/4106
Tested-by: Kudu Jenkins
Reviewed-by: Adar Dembo <ad...@cloudera.com>
Reviewed-by: Mike Percy <mp...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/kudu/repo
Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/df3d070e
Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/df3d070e
Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/df3d070e
Branch: refs/heads/master
Commit: df3d070e569d33875dc5d64180acbf913a2e2288
Parents: 5350702
Author: Todd Lipcon <to...@apache.org>
Authored: Tue Aug 23 18:46:25 2016 -0700
Committer: Mike Percy <mp...@apache.org>
Committed: Wed Aug 24 18:47:18 2016 +0000
----------------------------------------------------------------------
src/kudu/util/test_main.cc | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/kudu/blob/df3d070e/src/kudu/util/test_main.cc
----------------------------------------------------------------------
diff --git a/src/kudu/util/test_main.cc b/src/kudu/util/test_main.cc
index dd9af5f..f1b3763 100644
--- a/src/kudu/util/test_main.cc
+++ b/src/kudu/util/test_main.cc
@@ -20,7 +20,9 @@
#include <gtest/gtest.h>
#include <signal.h>
#include <sys/time.h>
+#include <thread>
+#include "kudu/gutil/atomicops.h"
#include "kudu/util/pstack_watcher.h"
#include "kudu/util/flags.h"
#include "kudu/util/status.h"
@@ -28,6 +30,10 @@
DEFINE_int32(test_timeout_after, 0,
"Maximum total seconds allowed for all unit tests in the suite. Default: disabled");
+DEFINE_int32(stress_cpu_threads, 0,
+ "Number of threads to start that burn CPU in an attempt to "
+ "stimulate race conditions");
+
// Start timer that kills the process if --test_timeout_after is exceeded before
// the tests complete.
static void CreateAndStartTimer();
@@ -35,6 +41,17 @@ static void CreateAndStartTimer();
// Gracefully kill the process.
static void KillTestOnTimeout(int signum);
+static void StartStressThreads() {
+ for (int i = 0; i < FLAGS_stress_cpu_threads; i++) {
+ std::thread([]{
+ while (true) {
+ // Do something which won't be optimized out.
+ base::subtle::MemoryBarrier();
+ }
+ }).detach();
+ }
+}
+
int main(int argc, char **argv) {
google::InstallFailureSignalHandler();
// InitGoogleTest() must precede ParseCommandLineFlags(), as the former
@@ -45,6 +62,8 @@ int main(int argc, char **argv) {
// Create the test-timeout timer.
CreateAndStartTimer();
+ StartStressThreads();
+
int ret = RUN_ALL_TESTS();
return ret;