Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

arsenm
Copy link
Contributor

@arsenm arsenm commented Feb 28, 2025

The actual exec error will not be immediate in the parent when
using the fork path. The error will manifest on the wait. The
ExecuteNoWait test was also expecting the immediate wait.

Remove the check in the AndWait test check for ExecutionFailed.
The execution did succeed in some sense.

Fixes #129208

Copy link
Contributor Author

arsenm commented Feb 28, 2025

@arsenm arsenm added llvm-tools All llvm tools that do not have corresponding tag test-suite labels Feb 28, 2025 — with Graphite App
@arsenm arsenm marked this pull request as ready for review February 28, 2025 14:23
@llvmbot
Copy link
Member

llvmbot commented Feb 28, 2025

@llvm/pr-subscribers-llvm-support

Author: Matt Arsenault (arsenm)

Changes

The actual exec error will not be immediate in the parent when
using the fork path. The error will manifest on the wait. The
ExecuteNoWait test was also expecting the immediate wait.

I hacked up the exit value ExecutionFailed value in ExecuteAndWait,
although arguably the previous behavior was correct. I'm not sure
what the point of the argument is, it's redundant with the return code.

Fixes #129208


Full diff: https://github.com/llvm/llvm-project/pull/129252.diff

2 Files Affected:

  • (modified) llvm/lib/Support/Program.cpp (+4)
  • (modified) llvm/unittests/Support/ProgramTest.cpp (+13-4)
diff --git a/llvm/lib/Support/Program.cpp b/llvm/lib/Support/Program.cpp
index 181f68cfbb8c3..c8208e4be3175 100644
--- a/llvm/lib/Support/Program.cpp
+++ b/llvm/lib/Support/Program.cpp
@@ -45,6 +45,10 @@ int sys::ExecuteAndWait(StringRef Program, ArrayRef<StringRef> Args,
     ProcessInfo Result = Wait(
         PI, SecondsToWait == 0 ? std::nullopt : std::optional(SecondsToWait),
         ErrMsg, ProcStat);
+
+    if (ExecutionFailed && Result.ReturnCode < 0)
+      *ExecutionFailed = true;
+
     return Result.ReturnCode;
   }
 
diff --git a/llvm/unittests/Support/ProgramTest.cpp b/llvm/unittests/Support/ProgramTest.cpp
index 47d2e269afe94..ccb154f7fab1a 100644
--- a/llvm/unittests/Support/ProgramTest.cpp
+++ b/llvm/unittests/Support/ProgramTest.cpp
@@ -433,10 +433,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());
+    }
   }
 
 }

@arsenm arsenm force-pushed the users/arsenm/support/gtest-use-expect-instead-of-assert branch from 47533d0 to bc18c29 Compare March 2, 2025 02:27
Base automatically changed from users/arsenm/support/gtest-use-expect-instead-of-assert to main March 2, 2025 02:29
@MaskRay
Copy link
Member

MaskRay commented Mar 2, 2025

I hacked up the exit value ExecutionFailed value in ExecuteAndWait, although arguably the previous behavior was correct. I'm not sure what the point of the argument is, it's redundant with the return code.

I also feel that the current behavior is better. When we have ReturnCode, it doesn't add value to set ExecutionFailed.
The PRes that adjust the tests look good to me.

@arsenm arsenm force-pushed the users/arsenm/issue129208/fix-process-error-tests-when-using-fork branch from 7b31093 to acaac0b Compare March 2, 2025 02:31
arsenm added 2 commits March 2, 2025 09:36
The actual exec error will not be immediate in the parent when
using the fork path. The error will manifest on the wait. The
ExecuteNoWait test was also expecting the immediate wait.

I hacked up the exit value ExecutionFailed value in ExecuteAndWait,
although arguably the previous behavior was correct. I'm not sure
what the point of the argument is, it's redundant with the return code.

Fixes #129208
@arsenm arsenm force-pushed the users/arsenm/issue129208/fix-process-error-tests-when-using-fork branch from acaac0b to 30daa7a Compare March 2, 2025 02:42
@aleks-tmb
Copy link
Contributor

Hi @arsenm, are you planning to merge the fix soon, or would it be better to disable the test in our local testing for now?

@arsenm arsenm merged commit e1c9c84 into main Mar 5, 2025
11 checks passed
@arsenm arsenm deleted the users/arsenm/issue129208/fix-process-error-tests-when-using-fork branch March 5, 2025 11:46
jph-13 pushed a commit to jph-13/llvm-project that referenced this pull request Mar 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
llvm:support llvm-tools All llvm tools that do not have corresponding tag test-suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support: llvm/test/tools/llvm-rc/windres-preproc.test fails on our platform with different error message.
4 participants