Browse Source

added an ad hoc prerequisite check because it didn't work on some netbsd box.
not sure if this check really helps. will see.


git-svn-id: svn://bind10.isc.org/svn/bind10/branches/trac241@2504 e5f2f494-b856-4b98-b285-d166d9295462

JINMEI Tatuya 15 years ago
parent
commit
6f8ef11b0e
1 changed files with 23 additions and 0 deletions
  1. 23 0
      src/lib/bench/tests/benchmark_unittest.cc

+ 23 - 0
src/lib/bench/tests/benchmark_unittest.cc

@@ -75,6 +75,29 @@ TEST(BenchMarkTest, run) {
     const int duration_margin = 10000; // 10ms
     const int duration_margin = 10000; // 10ms
     const int ONE_MILLION = 1000000;
     const int ONE_MILLION = 1000000;
 
 
+    // Prerequisite check: since the tests in this case may depend on subtle
+    // timing, it may result in false positives.  There are reportedly systems
+    // where usleep() doesn't work as this test expects.  So we check the
+    // conditions before the tests, and if it fails skip the tests at the
+    // risk of overlooking possible bugs.
+    struct timeval check_begin, check_end;
+    gettimeofday(&check_begin, NULL);
+    usleep(sleep_time);
+    gettimeofday(&check_end, NULL);
+    check_end.tv_sec -= check_begin.tv_sec;
+    if (check_end.tv_usec >= check_begin.tv_usec) {
+        check_end.tv_usec = check_end.tv_usec - check_begin.tv_usec;
+    } else {
+        check_end.tv_usec = ONE_MILLION + check_begin.tv_usec -
+            check_end.tv_usec;
+        --check_end.tv_sec;
+    }
+    if (check_end.tv_sec != 0 ||
+        sleep_time - duration_margin > check_end.tv_usec ||
+        sleep_time + duration_margin < check_end.tv_usec) {
+        cerr << "Prerequisite check failed.  skipping test" << endl;
+    }
+
     TestBenchMark test_bench(sub_iterations, sleep_time);
     TestBenchMark test_bench(sub_iterations, sleep_time);
     BenchMark<TestBenchMark> bench(1, test_bench, false);
     BenchMark<TestBenchMark> bench(1, test_bench, false);
     // Check pre-test conditions.
     // Check pre-test conditions.