[libc-commits] [PATCH] D151097: [libc] Display unit test runtime for hosted environments

Guillaume Chatelet via Phabricator via libc-commits libc-commits at lists.llvm.org
Tue May 23 02:14:39 PDT 2023


gchatelet updated this revision to Diff 524625.
gchatelet added a comment.

- remove extra empty line


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151097/new/

https://reviews.llvm.org/D151097

Files:
  libc/test/UnitTest/LibcTest.cpp


Index: libc/test/UnitTest/LibcTest.cpp
===================================================================
--- libc/test/UnitTest/LibcTest.cpp
+++ libc/test/UnitTest/LibcTest.cpp
@@ -13,6 +13,13 @@
 #include "src/__support/UInt128.h"
 #include "test/UnitTest/TestLogger.h"
 
+#if __STDC_HOSTED__
+#include <time.h>
+#else
+static long clock() { return 0; }
+#define CLOCKS_PER_SEC 1
+#endif
+
 namespace __llvm_libc {
 namespace testing {
 
@@ -149,11 +156,13 @@
       continue;
     }
     tlog << GREEN << "[ RUN      ] " << RESET << TestName << '\n';
+    [[maybe_unused]] const auto start_time = clock();
     RunContext Ctx;
     T->SetUp();
     T->setContext(&Ctx);
     T->Run();
     T->TearDown();
+    [[maybe_unused]] const auto end_time = clock();
     auto Result = Ctx.status();
     switch (Result) {
     case RunContext::Result_Fail:
@@ -161,7 +170,19 @@
       ++FailCount;
       break;
     case RunContext::Result_Pass:
-      tlog << GREEN << "[       OK ] " << RESET << TestName << '\n';
+      tlog << GREEN << "[       OK ] " << RESET << TestName;
+#if __STDC_HOSTED__
+      tlog << " (took ";
+      if (start_time > end_time) {
+        tlog << "unknown - try rerunning)\n";
+      } else {
+        const auto duration = end_time - start_time;
+        const uint64_t duration_ms = duration * 1000 / CLOCKS_PER_SEC;
+        tlog << duration_ms << " ms)\n";
+      }
+#else
+      tlog << '\n';
+#endif
       break;
     }
     ++TestCount;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D151097.524625.patch
Type: text/x-patch
Size: 1473 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20230523/ca4b0366/attachment.bin>


More information about the libc-commits mailing list