Refactors misc test cases
[libcds.git] / test / stress / misc / mcslock_driver.cpp
index e2b6de9aa36fcdc509419ae089eab0990157fbc0..1435e971512cffe2cced76e125298b95debb1e80 100644 (file)
@@ -1,3 +1,4 @@
+#include "common.h"
 #include <atomic>
 #include <cds/gc/dhp.h>
 #include <cds/gc/hp.h>
@@ -10,41 +11,44 @@ using namespace std;
 
 namespace {
 
+static size_t s_nMCSLockThreadCount = 6;
+static size_t s_nMCSLockPassCount = 3000000;
+
 class MCSLockTest : public cds_test::stress_fixture {
 protected:
-  static int x;
+  static ullong x;
   static cds_others::mcs_mutex *my_mutex;
-  static const int kThreads = 6;
 
-  static void SetUpTestCase() {}
+  static void SetUpTestCase() {
+    cds_test::config const &cfg = get_config("Misc");
+    GetConfig(MCSLockPassCount);
+    GetConfig(MCSLockThreadCount);
+  }
 
   static void Thread() {
     cds_others::mcs_mutex::guard g(my_mutex);
     x = 1;
     my_mutex->unlock(&g);
-    for (int i = 0; i < 10000; i++) {
-      for (int j = 0; j < 300; j++) {
-        my_mutex->lock(&g);
-        x = i + j;
-        my_mutex->unlock(&g);
-      }
+    for (ullong i = 0; i < s_nMCSLockPassCount; i++) {
+      my_mutex->lock(&g);
+      x = i;
+      my_mutex->unlock(&g);
     }
     my_mutex->lock(&g);
   }
 };
 
-int MCSLockTest::x;
+ullong MCSLockTest::x;
 cds_others::mcs_mutex *MCSLockTest::my_mutex;
-const int MCSLockTest::kThreads;
 
 TEST_F(MCSLockTest, BasicLockUnlock) {
   my_mutex = new cds_others::mcs_mutex();
-  std::thread threads[kThreads];
-  for (int i = 0; i < kThreads; i++) {
+  std::thread *threads = new std::thread[s_nMCSLockThreadCount];
+  for (int i = 0; i < s_nMCSLockThreadCount; i++) {
     threads[i] = std::thread(Thread);
   }
 
-  for (int i = 0; i < kThreads; i++) {
+  for (int i = 0; i < s_nMCSLockThreadCount; i++) {
     threads[i].join();
   }
 }