[libc-commits] [PATCH] D105843: [libc] Add option to run specific test binaries

Caitlyn Cano via Phabricator via libc-commits libc-commits at lists.llvm.org
Mon Jul 12 14:03:39 PDT 2021


caitlyncano created this revision.
caitlyncano added reviewers: sivachandra, aeubanks, hedingarcia.
Herald added subscribers: libc-commits, ecnelises, tschuett.
Herald added a project: libc-project.
caitlyncano requested review of this revision.

This addition reads command line input to run specific single tests
within a larger call to run all the tests for a particular function.
When the user adds a second argument to the command line, the code skips
all the tests that don't match the user's specified binary. If the user
doesn't specify a test correctly and/or no tests are run, a failure
message prints.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D105843

Files:
  libc/utils/UnitTest/LibcTest.cpp
  libc/utils/UnitTest/LibcTest.h


Index: libc/utils/UnitTest/LibcTest.h
===================================================================
--- libc/utils/UnitTest/LibcTest.h
+++ libc/utils/UnitTest/LibcTest.h
@@ -70,7 +70,7 @@
   virtual void SetUp() {}
   virtual void TearDown() {}
 
-  static int runTests();
+  static int runTests(int, char *[]);
 
 protected:
   static void addTest(Test *T);
Index: libc/utils/UnitTest/LibcTest.cpp
===================================================================
--- libc/utils/UnitTest/LibcTest.cpp
+++ libc/utils/UnitTest/LibcTest.cpp
@@ -143,14 +143,23 @@
   End = T;
 }
 
-int Test::runTests() {
+int Test::runTests(int argc,char *argv[]) {
   int TestCount = 0;
   int FailCount = 0;
   for (Test *T = Start; T != nullptr; T = T->Next, ++TestCount) {
     const char *TestName = T->getName();
+    std::string str_test_name(TestName);
     constexpr auto GREEN = "\033[32m";
     constexpr auto RED = "\033[31m";
     constexpr auto RESET = "\033[0m";
+    constexpr auto YELLOW = "\033[33m";
+    if(argc>1)  {
+      std::string specific_binary(argv[1]);
+      if(specific_binary!=str_test_name)  {
+        std::cout << YELLOW << "[ SKIPPING ] " << RESET << TestName << '\n';
+        break;
+      }
+    }
     std::cout << GREEN << "[ RUN      ] " << RESET << TestName << '\n';
     RunContext Ctx;
     T->SetUp();
@@ -169,9 +178,14 @@
     }
   }
 
-  std::cout << "Ran " << TestCount << " tests. "
-            << " PASS: " << TestCount - FailCount << ' '
-            << " FAIL: " << FailCount << '\n';
+  if(TestCount>0)  {
+    std::cout << "Ran " << TestCount << " tests. "
+              << " PASS: " << TestCount - FailCount << ' '
+              << " FAIL: " << FailCount << '\n';
+  }
+  else  {
+    std::cout << "No tests run. Ensure that inputted test binary matches the test name exactly.";
+  }
 
   return FailCount > 0 ? 1 : 0;
 }
@@ -350,4 +364,4 @@
 } // namespace testing
 } // namespace __llvm_libc
 
-int main() { return __llvm_libc::testing::Test::runTests(); }
+int main(int argc, char *argv[]) { return __llvm_libc::testing::Test::runTests(argc,argv); }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D105843.358062.patch
Type: text/x-patch
Size: 2102 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20210712/c0751433/attachment-0001.bin>


More information about the libc-commits mailing list