[libc-commits] [libc] 04e066d - [libc] Display unit test runtime for hosted environments

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


Author: Guillaume Chatelet
Date: 2023-05-23T09:23:12Z
New Revision: 04e066df5eb363a24c7685837734ca6186cd478f

URL: https://github.com/llvm/llvm-project/commit/04e066df5eb363a24c7685837734ca6186cd478f
DIFF: https://github.com/llvm/llvm-project/commit/04e066df5eb363a24c7685837734ca6186cd478f.diff

LOG: [libc] Display unit test runtime for hosted environments

With more tests added to LLVM libc each week we want to keep track of unittest's runtime, especially for low end build bots.

Top offender can be tracked with a bit of scripting (spoiler alert, mem function sweep tests are in the top ones)
```
ninja check-libc | grep "ms)" | awk '{print $(NF-1),$0}' | sort -nr | cut -f2- -d' '
```

Unfortunately this doesn't work for hermetic tests since `clock` is unavailable.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D151097

Added: 
    

Modified: 
    libc/test/UnitTest/LibcTest.cpp

Removed: 
    


################################################################################
diff  --git a/libc/test/UnitTest/LibcTest.cpp b/libc/test/UnitTest/LibcTest.cpp
index edf543b33b166..9555a179707eb 100644
--- a/libc/test/UnitTest/LibcTest.cpp
+++ b/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 @@ int Test::runTests(const char *TestFilter) {
       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 @@ int Test::runTests(const char *TestFilter) {
       ++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;


        


More information about the libc-commits mailing list