Skip to content

Commit 6279f77

Browse files
committed
test fixes Windows
1 parent 4ff493f commit 6279f77

File tree

2 files changed

+34
-22
lines changed

2 files changed

+34
-22
lines changed

flang/runtime/execute.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@ void CheckAndStoreIntToDescriptor(
6262

6363
// If a condition occurs that would assign a nonzero value to CMDSTAT but
6464
// the CMDSTAT variable is not present, error termination is initiated.
65-
int TerminationCheck(int status, const Descriptor *cmdstat,
65+
std::int64_t TerminationCheck(std::int64_t status, const Descriptor *cmdstat,
6666
const Descriptor *cmdmsg, Terminator &terminator) {
6767
#ifdef _WIN32
6868
// On WIN32 API std::system returns exit status directly
69-
int exitStatusVal{status};
69+
std::int64_t exitStatusVal{status};
7070
#else
71-
int exitStatusVal{WEXITSTATUS(status)};
71+
std::int64_t exitStatusVal{WEXITSTATUS(status)};
7272
if (exitStatusVal == 1) {
7373
if (!cmdstat) {
7474
terminator.Crash("General Error with exit status code: 1");
@@ -163,8 +163,8 @@ void RTNAME(ExecuteCommandLine)(const Descriptor &command, bool wait,
163163

164164
if (wait) {
165165
// either wait is not specified or wait is true: synchronous mode
166-
int status{std::system(newCmd)};
167-
int exitStatusVal{TerminationCheck(status, cmdstat, cmdmsg, terminator)};
166+
std::int64_t status{std::system(newCmd)};
167+
std::int64_t exitStatusVal{TerminationCheck(status, cmdstat, cmdmsg, terminator)};
168168
// If sync, assigned processor-dependent exit status. Otherwise unchanged
169169
CheckAndStoreIntToDescriptor(exitstat, exitStatusVal, terminator);
170170
} else {
@@ -202,7 +202,7 @@ void RTNAME(ExecuteCommandLine)(const Descriptor &command, bool wait,
202202
terminator.Crash(
203203
"CreateProcess failed with error code: %lu.", GetLastError());
204204
} else {
205-
StoreIntToDescriptor(cmdstat, (uint32_t)GetLastError(), terminator);
205+
StoreIntToDescriptor(cmdstat, (std::int64_t)GetLastError(), terminator);
206206
CheckAndCopyCharsToDescriptor(cmdmsg, "CreateProcess failed.");
207207
}
208208
}
@@ -230,7 +230,7 @@ void RTNAME(ExecuteCommandLine)(const Descriptor &command, bool wait,
230230
}
231231
exit(EXIT_FAILURE);
232232
}
233-
int status{std::system(newCmd)};
233+
std::int64_t status{std::system(newCmd)};
234234
TerminationCheck(status, cmdstat, cmdmsg, terminator);
235235
exit(status);
236236
}

flang/unittests/Runtime/CommandTest.cpp

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ TEST_F(ZeroArguments, ECLGeneralErrorCommandErrorSync) {
349349
RTNAME(ExecuteCommandLine)
350350
(*command.get(), wait, exitStat.get(), cmdStat.get(), cmdMsg.get());
351351
#ifdef _WIN32
352-
CheckDescriptorEqInt(exitStat.get(), 1);
352+
CheckDescriptorEqInt<std::int64_t>(exitStat.get(), 1);
353353
CheckDescriptorEqStr(cmdMsg.get(), "Invalid command lineXXX");
354354
#else
355355
CheckDescriptorEqInt<std::int64_t>(exitStat.get(), 1);
@@ -359,7 +359,9 @@ TEST_F(ZeroArguments, ECLGeneralErrorCommandErrorSync) {
359359
}
360360

361361
TEST_F(ZeroArguments, ECLNotExecutedCommandErrorSync) {
362-
OwningPtr<Descriptor> command{CharDescriptor("cd NotExecutedCommand")};
362+
OwningPtr<Descriptor> command{CharDescriptor(
363+
"touch NotExecutedCommandFile && chmod -x NotExecutedCommandFile && "
364+
"./NotExecutedCommandFile")};
363365
bool wait{true};
364366
OwningPtr<Descriptor> exitStat{IntDescriptor(404)};
365367
OwningPtr<Descriptor> cmdStat{IntDescriptor(202)};
@@ -368,13 +370,28 @@ TEST_F(ZeroArguments, ECLNotExecutedCommandErrorSync) {
368370
RTNAME(ExecuteCommandLine)
369371
(*command.get(), wait, exitStat.get(), cmdStat.get(), cmdMsg.get());
370372
#ifdef _WIN32
371-
CheckDescriptorEqInt(exitStat.get(), 1);
373+
CheckDescriptorEqInt<std::int64_t>(exitStat.get(), 1);
372374
CheckDescriptorEqStr(cmdMsg.get(), "Invalid command lineXXX");
373375
#else
374376
CheckDescriptorEqInt<std::int64_t>(exitStat.get(), 126);
375377
CheckDescriptorEqStr(cmdMsg.get(), "Command cannot execute:");
376378
#endif
377379
CheckDescriptorEqInt<std::int64_t>(cmdStat.get(), 3);
380+
381+
// removing the file should have no error on Linux, have error on Windows
382+
OwningPtr<Descriptor> commandClean{CharDescriptor("rm -f NotExecutedCommandFile")};
383+
OwningPtr<Descriptor> cmdMsgNoErr{CharDescriptor("No Error")};
384+
RTNAME(ExecuteCommandLine)
385+
(*commandClean.get(), wait, exitStat.get(), cmdStat.get(), cmdMsgNoErr.get());
386+
#ifdef _WIN32
387+
CheckDescriptorEqInt<std::int64_t>(exitStat.get(), 1);
388+
CheckDescriptorEqStr(cmdMsgNoErr.get(), "Invalid ");
389+
CheckDescriptorEqInt<std::int64_t>(cmdStat.get(), 3);
390+
#else
391+
CheckDescriptorEqInt<std::int64_t>(exitStat.get(), 0);
392+
CheckDescriptorEqStr(cmdMsgNoErr.get(), "No Error");
393+
CheckDescriptorEqInt<std::int64_t>(cmdStat.get(), 0);
394+
#endif
378395
}
379396

380397
TEST_F(ZeroArguments, ECLNotFoundCommandErrorSync) {
@@ -388,9 +405,9 @@ TEST_F(ZeroArguments, ECLNotFoundCommandErrorSync) {
388405
RTNAME(ExecuteCommandLine)
389406
(*command.get(), wait, exitStat.get(), cmdStat.get(), cmdMsg.get());
390407
#ifdef _WIN32
391-
CheckDescriptorEqInt(exitStat.get(), 1);
408+
CheckDescriptorEqInt<std::int64_t>(exitStat.get(), 1);
392409
CheckDescriptorEqStr(cmdMsg.get(),
393-
"Invalid command lineXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
410+
"Invalid command linefy the remaining buffer XXXXXXXXXXXXXXXXXXXX");
394411
#else
395412
CheckDescriptorEqInt<std::int64_t>(exitStat.get(), 127);
396413
CheckDescriptorEqStr(cmdMsg.get(),
@@ -402,19 +419,17 @@ TEST_F(ZeroArguments, ECLNotFoundCommandErrorSync) {
402419
TEST_F(ZeroArguments, ECLInvalidCommandTerminatedSync) {
403420
OwningPtr<Descriptor> command{CharDescriptor("InvalidCommand")};
404421
bool wait{true};
405-
OwningPtr<Descriptor> exitStat{IntDescriptor(404)};
406422
OwningPtr<Descriptor> cmdMsg{CharDescriptor("No Change")};
407423

408424
#ifdef _WIN32
409425
EXPECT_DEATH(RTNAME(ExecuteCommandLine)(
410-
*command.get(), wait, exitStat.get(), nullptr, cmdMsg.get()),
426+
*command.get(), wait, nullptr, nullptr, cmdMsg.get()),
411427
"Invalid command quit with exit status code: 1");
412428
#else
413429
EXPECT_DEATH(RTNAME(ExecuteCommandLine)(
414-
*command.get(), wait, exitStat.get(), nullptr, cmdMsg.get()),
415-
"Invalid command quit with exit status code: 127");
430+
*command.get(), wait, nullptr, nullptr, cmdMsg.get()),
431+
"Command not found with exit status code: 127");
416432
#endif
417-
CheckDescriptorEqInt(exitStat.get(), 404);
418433
CheckDescriptorEqStr(cmdMsg.get(), "No Change");
419434
}
420435

@@ -428,21 +443,18 @@ TEST_F(ZeroArguments, ECLValidCommandAndExitStatNoChangeAndCMDStatusSetAsync) {
428443
RTNAME(ExecuteCommandLine)
429444
(*command.get(), wait, exitStat.get(), cmdStat.get(), cmdMsg.get());
430445

431-
CheckDescriptorEqInt(exitStat.get(), 404);
446+
CheckDescriptorEqInt<std::int64_t>(exitStat.get(), 404);
432447
CheckDescriptorEqInt<std::int64_t>(cmdStat.get(), 0);
433448
CheckDescriptorEqStr(cmdMsg.get(), "No change");
434449
}
435450

436451
TEST_F(ZeroArguments, ECLInvalidCommandParentNotTerminatedAsync) {
437452
OwningPtr<Descriptor> command{CharDescriptor("InvalidCommand")};
438453
bool wait{false};
439-
OwningPtr<Descriptor> exitStat{IntDescriptor(404)};
440454
OwningPtr<Descriptor> cmdMsg{CharDescriptor("No change")};
441455

442456
EXPECT_NO_FATAL_FAILURE(RTNAME(ExecuteCommandLine)(
443-
*command.get(), wait, exitStat.get(), nullptr, cmdMsg.get()));
444-
445-
CheckDescriptorEqInt(exitStat.get(), 404);
457+
*command.get(), wait, nullptr, nullptr, cmdMsg.get()));
446458
CheckDescriptorEqStr(cmdMsg.get(), "No change");
447459
}
448460

0 commit comments

Comments
 (0)