[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
Mon May 22 07:00:56 PDT 2023


gchatelet created this revision.
gchatelet added a reviewer: sivachandra.
Herald added subscribers: libc-commits, ecnelises, tschuett.
Herald added projects: libc-project, All.
gchatelet requested review of this revision.

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 )

  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.


Repository:
  rG LLVM Github Monorepo

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 {
 
@@ -162,19 +169,30 @@
       continue;
     }
     tlog << GREEN << "[ RUN      ] " << RESET << TestName << '\n';
+    const auto start_time = clock();
     RunContext Ctx;
     T->SetUp();
     T->setContext(&Ctx);
     T->Run();
     T->TearDown();
     auto Result = Ctx.status();
+    const auto duration = clock() - start_time;
+    const auto elapsed_ms =
+        static_cast<uint64_t>(duration * 1000 / CLOCKS_PER_SEC);
     switch (Result) {
     case RunContext::Result_Fail:
       tlog << RED << "[  FAILED  ] " << RESET << TestName << '\n';
       ++FailCount;
       break;
     case RunContext::Result_Pass:
+#if __STDC_HOSTED__
+      const auto seconds = static_cast<uint64_t>(elapsed_ms / 1000);
+      const auto frac = static_cast<uint64_t>(elapsed_ms % 1000);
+      tlog << GREEN << "[       OK ] " << RESET << TestName << " (took "
+           << elapsed_ms << " ms)\n";
+#else
       tlog << GREEN << "[       OK ] " << RESET << TestName << '\n';
+#endif
       break;
     }
     ++TestCount;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D151097.524287.patch
Type: text/x-patch
Size: 1459 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20230522/b2d6fe18/attachment-0001.bin>


More information about the libc-commits mailing list