[flang-commits] [flang] 4498137 - [flang] Rewrite test for CPU_TIME

Diana Picus via flang-commits flang-commits at lists.llvm.org
Fri Jun 18 02:21:04 PDT 2021


Author: Diana Picus
Date: 2021-06-18T09:12:24Z
New Revision: 4498137bd7857c07921b4cd6313baac62ead24e2

URL: https://github.com/llvm/llvm-project/commit/4498137bd7857c07921b4cd6313baac62ead24e2
DIFF: https://github.com/llvm/llvm-project/commit/4498137bd7857c07921b4cd6313baac62ead24e2.diff

LOG: [flang] Rewrite test for CPU_TIME

Don't rely on volatile writes to keep the CPU busy - it seems MSVC
optimizes them out, so we don't get different values for 'start' and
'end' on Windows. Rewrite the test to loop until we get a different
value for 'end'.

Fix suggested by Michael Kruse in
https://reviews.llvm.org/rG57e85622bbdb2eb18cc03df2ea457019c58f6912#inline-6002

Committing to fix the Windows buildbot, post-commit comments welcome!

Added: 
    

Modified: 
    flang/unittests/RuntimeGTest/Time.cpp

Removed: 
    


################################################################################
diff  --git a/flang/unittests/RuntimeGTest/Time.cpp b/flang/unittests/RuntimeGTest/Time.cpp
index 1a15b306a3e43..8ff43272cc258 100644
--- a/flang/unittests/RuntimeGTest/Time.cpp
+++ b/flang/unittests/RuntimeGTest/Time.cpp
@@ -11,25 +11,18 @@
 
 using namespace Fortran::runtime;
 
-volatile int x = 0;
-
-void LookBusy() {
-  // We're trying to track actual processor time, so sleeping is not an option.
-  // Doing some writes to a volatile variable should do the trick.
-  for (int i = 0; i < (1 << 8); ++i) {
-    x = i;
-  }
-}
-
 TEST(TimeIntrinsics, CpuTime) {
   // We can't really test that we get the "right" result for CPU_TIME, but we
   // can have a smoke test to see that we get something reasonable on the
   // platforms where we expect to support it.
   double start = RTNAME(CpuTime)();
-  LookBusy();
-  double end = RTNAME(CpuTime)();
-
   ASSERT_GE(start, 0.0);
-  ASSERT_GT(end, 0.0);
-  ASSERT_GT(end, start);
+
+  // Loop until we get a 
diff erent value from CpuTime. If we don't get one
+  // before we time out, then we should probably look into an implementation
+  // for CpuTime with a better timer resolution.
+  for (double end = start; end == start; end = RTNAME(CpuTime)()) {
+    ASSERT_GT(end, 0.0);
+    ASSERT_GE(end, start);
+  }
 }


        


More information about the flang-commits mailing list