[llvm] e1c9c84 - Support: Fix program error test failures when using fork (#129252)

via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 5 03:46:41 PST 2025


Author: Matt Arsenault
Date: 2025-03-05T18:46:38+07:00
New Revision: e1c9c842cb43a9a264ba442fb6c87d95ebc6d8e2

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

LOG: Support: Fix program error test failures when using fork (#129252)

Added: 
    

Modified: 
    llvm/unittests/Support/ProgramTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/unittests/Support/ProgramTest.cpp b/llvm/unittests/Support/ProgramTest.cpp
index 47d2e269afe94..693b53b0a9781 100644
--- a/llvm/unittests/Support/ProgramTest.cpp
+++ b/llvm/unittests/Support/ProgramTest.cpp
@@ -422,10 +422,13 @@ TEST(ProgramTest, TestExecuteNegative) {
     bool ExecutionFailed;
     int RetCode = ExecuteAndWait(Executable, argv, std::nullopt, {}, 0, 0,
                                  &Error, &ExecutionFailed);
+
     EXPECT_LT(RetCode, 0) << "On error ExecuteAndWait should return 0 or "
                              "positive value indicating the result code";
-    EXPECT_TRUE(ExecutionFailed);
     EXPECT_FALSE(Error.empty());
+
+    // Note ExecutionFailed may or may not be false. When using fork, the error
+    // is produced on the wait for the child, not the execution point.
   }
 
   {
@@ -433,10 +436,19 @@ TEST(ProgramTest, TestExecuteNegative) {
     bool ExecutionFailed;
     ProcessInfo PI = ExecuteNoWait(Executable, argv, std::nullopt, {}, 0,
                                    &Error, &ExecutionFailed);
-    EXPECT_EQ(PI.Pid, ProcessInfo::InvalidPid)
-        << "On error ExecuteNoWait should return an invalid ProcessInfo";
-    EXPECT_TRUE(ExecutionFailed);
-    EXPECT_FALSE(Error.empty());
+
+    if (ExecutionFailed) {
+      EXPECT_EQ(PI.Pid, ProcessInfo::InvalidPid)
+          << "On error ExecuteNoWait should return an invalid ProcessInfo";
+      EXPECT_FALSE(Error.empty());
+    } else {
+      std::string WaitErrMsg;
+      EXPECT_NE(PI.Pid, ProcessInfo::InvalidPid);
+      ProcessInfo WaitPI = Wait(PI, std::nullopt, &WaitErrMsg);
+      EXPECT_EQ(WaitPI.Pid, PI.Pid);
+      EXPECT_LT(WaitPI.ReturnCode, 0);
+      EXPECT_FALSE(WaitErrMsg.empty());
+    }
   }
 
 }


        


More information about the llvm-commits mailing list