[llvm] c32f8f3 - [unittests] fix intermittent SupportTests failures

Yuanfang Chen via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 5 18:19:36 PDT 2022


Author: Yuanfang Chen
Date: 2022-04-05T18:19:20-07:00
New Revision: c32f8f34614d89dbe4978b71b6e2a6da17b1b0d4

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

LOG: [unittests] fix intermittent SupportTests failures

by invoking `SupportTests --gtest_shuffle=1`.

`HideUnrelatedOptions`/`HideUnrelatedOptionsMulti` failed due to other
tests calling `cl::ResetCommandLineParser()` which causes default
options to be removed.

`ExitOnError` would hang due to the threading environment. Renaming it
as `*Deathtest` is the recommended practice by GTest docs.

Added: 
    

Modified: 
    llvm/unittests/Support/CommandLineTest.cpp
    llvm/unittests/Support/ErrorTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/unittests/Support/CommandLineTest.cpp b/llvm/unittests/Support/CommandLineTest.cpp
index e68761eca3525..dd02d92012652 100644
--- a/llvm/unittests/Support/CommandLineTest.cpp
+++ b/llvm/unittests/Support/CommandLineTest.cpp
@@ -391,7 +391,8 @@ TEST(CommandLineTest, HideUnrelatedOptions) {
 
   StringMap<cl::Option *> &Map =
       cl::getRegisteredOptions(*cl::TopLevelSubCommand);
-  ASSERT_EQ(cl::NotHidden, Map["help"]->getOptionHiddenFlag())
+  ASSERT_TRUE(Map.count("help") == (size_t)0 ||
+              cl::NotHidden == Map["help"]->getOptionHiddenFlag())
       << "Hid default option that should be visable.";
 }
 
@@ -416,7 +417,8 @@ TEST(CommandLineTest, HideUnrelatedOptionsMulti) {
 
   StringMap<cl::Option *> &Map =
       cl::getRegisteredOptions(*cl::TopLevelSubCommand);
-  ASSERT_EQ(cl::NotHidden, Map["help"]->getOptionHiddenFlag())
+  ASSERT_TRUE(Map.count("help") == (size_t)0 ||
+              cl::NotHidden == Map["help"]->getOptionHiddenFlag())
       << "Hid default option that should be visable.";
 }
 

diff  --git a/llvm/unittests/Support/ErrorTest.cpp b/llvm/unittests/Support/ErrorTest.cpp
index d4daceda2b14a..547566cd09e36 100644
--- a/llvm/unittests/Support/ErrorTest.cpp
+++ b/llvm/unittests/Support/ErrorTest.cpp
@@ -474,7 +474,7 @@ TEST(Error, createStringError) {
 }
 
 // Test that the ExitOnError utility works as expected.
-TEST(Error, ExitOnError) {
+TEST(ErrorDeathTest, ExitOnError) {
   ExitOnError ExitOnErr;
   ExitOnErr.setBanner("Error in tool:");
   ExitOnErr.setExitCodeMapper([](const Error &E) {


        


More information about the llvm-commits mailing list