| 13 | { |
| 14 | |
| 15 | bool RunTestCase(vtkMPIController* controller, const std::string& command, |
| 16 | std::optional<int> commandProcessId, const std::vector<std::string>& expectedResults) |
| 17 | { |
| 18 | if (expectedResults.size() != (size_t)controller->GetNumberOfProcesses()) |
| 19 | { |
| 20 | vtkLogF(ERROR, |
| 21 | "ExpectedResults vector should have %i elements, but its number of elements is %i", |
| 22 | controller->GetNumberOfProcesses(), (int)expectedResults.size()); |
| 23 | return false; |
| 24 | } |
| 25 | |
| 26 | int localProcessId = controller->GetLocalProcessId(); |
| 27 | |
| 28 | vtkNew<vtkPExecutableRunner> executableRunner; |
| 29 | executableRunner->SetExecutionProcessId(commandProcessId.value_or(-1)); |
| 30 | executableRunner->SetCommand(command.c_str()); |
| 31 | executableRunner->Execute(); |
| 32 | |
| 33 | int returnValue = executableRunner->GetReturnValue(); |
| 34 | if (returnValue > 0) |
| 35 | { |
| 36 | vtkLogF(ERROR, "Error when executing command: %s.", executableRunner->GetStdErr()); |
| 37 | return false; |
| 38 | } |
| 39 | |
| 40 | std::string commandResult = executableRunner->GetStdOut(); |
| 41 | const std::string& expectedResult = expectedResults[static_cast<size_t>(localProcessId)]; |
| 42 | // Verify that the command result is the expected one |
| 43 | if (commandResult != expectedResult) |
| 44 | { |
| 45 | vtkLogF(ERROR, "Expected %s command result but got %s.", |
| 46 | expectedResult.empty() ? "[empty]" : expectedResult.c_str(), commandResult.c_str()); |
| 47 | return false; |
| 48 | } |
| 49 | |
| 50 | return true; |
| 51 | } |
| 52 | |
| 53 | } |
| 54 |
no test coverage detected