Skip to content

Commit e1c9c84

Browse files
authored
Support: Fix program error test failures when using fork (#129252)
1 parent 53c1579 commit e1c9c84

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

llvm/unittests/Support/ProgramTest.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -422,21 +422,33 @@ TEST(ProgramTest, TestExecuteNegative) {
422422
bool ExecutionFailed;
423423
int RetCode = ExecuteAndWait(Executable, argv, std::nullopt, {}, 0, 0,
424424
&Error, &ExecutionFailed);
425+
425426
EXPECT_LT(RetCode, 0) << "On error ExecuteAndWait should return 0 or "
426427
"positive value indicating the result code";
427-
EXPECT_TRUE(ExecutionFailed);
428428
EXPECT_FALSE(Error.empty());
429+
430+
// Note ExecutionFailed may or may not be false. When using fork, the error
431+
// is produced on the wait for the child, not the execution point.
429432
}
430433

431434
{
432435
std::string Error;
433436
bool ExecutionFailed;
434437
ProcessInfo PI = ExecuteNoWait(Executable, argv, std::nullopt, {}, 0,
435438
&Error, &ExecutionFailed);
436-
EXPECT_EQ(PI.Pid, ProcessInfo::InvalidPid)
437-
<< "On error ExecuteNoWait should return an invalid ProcessInfo";
438-
EXPECT_TRUE(ExecutionFailed);
439-
EXPECT_FALSE(Error.empty());
439+
440+
if (ExecutionFailed) {
441+
EXPECT_EQ(PI.Pid, ProcessInfo::InvalidPid)
442+
<< "On error ExecuteNoWait should return an invalid ProcessInfo";
443+
EXPECT_FALSE(Error.empty());
444+
} else {
445+
std::string WaitErrMsg;
446+
EXPECT_NE(PI.Pid, ProcessInfo::InvalidPid);
447+
ProcessInfo WaitPI = Wait(PI, std::nullopt, &WaitErrMsg);
448+
EXPECT_EQ(WaitPI.Pid, PI.Pid);
449+
EXPECT_LT(WaitPI.ReturnCode, 0);
450+
EXPECT_FALSE(WaitErrMsg.empty());
451+
}
440452
}
441453

442454
}

0 commit comments

Comments
 (0)