Add unit tests for MultiCommand class
This change improves code coverage of MultiCommand class. Related-To: NEO-6834 Signed-off-by: Patryk Wrobel <patryk.wrobel@intel.com>
This commit is contained in:
parent
198cac9815
commit
6f911ba840
|
@ -19,6 +19,7 @@ namespace NEO {
|
|||
class MockMultiCommand : public MultiCommand {
|
||||
public:
|
||||
using MultiCommand::argHelper;
|
||||
using MultiCommand::lines;
|
||||
using MultiCommand::quiet;
|
||||
using MultiCommand::retValues;
|
||||
|
||||
|
@ -38,8 +39,20 @@ class MockMultiCommand : public MultiCommand {
|
|||
|
||||
~MockMultiCommand() override = default;
|
||||
|
||||
int singleBuild(const std::vector<std::string> &args) override {
|
||||
++singleBuildCalledCount;
|
||||
|
||||
if (callBaseSingleBuild) {
|
||||
return MultiCommand::singleBuild(args);
|
||||
}
|
||||
|
||||
return OclocErrorCode::SUCCESS;
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> filesMap{};
|
||||
std::unique_ptr<MockOclocArgHelper> uniqueHelper{};
|
||||
int singleBuildCalledCount{0};
|
||||
bool callBaseSingleBuild{true};
|
||||
};
|
||||
|
||||
} // namespace NEO
|
||||
|
|
|
@ -434,7 +434,44 @@ TEST(MultiCommandWhiteboxTest, GivenCommandLineWithMissingApostropheWhenSplittin
|
|||
EXPECT_EQ(expectedOutput, output);
|
||||
}
|
||||
|
||||
TEST(MultiCommandWhiteboxTest, GivenArgsWithQuietModeAndEmptyMulticomandFileWhenInitializingThenQuietFlagIsSetAndErrorIsReturned) {
|
||||
TEST(MultiCommandWhiteboxTest, GivenCommandLineWithMissingApostropheWhenRunningBuildsThenErrorIsReturnedAndBuildIsNotStarted) {
|
||||
MockMultiCommand mockMultiCommand{};
|
||||
mockMultiCommand.quiet = true;
|
||||
mockMultiCommand.callBaseSingleBuild = false;
|
||||
mockMultiCommand.lines.push_back("-out_dir \"Some Directory");
|
||||
|
||||
mockMultiCommand.runBuilds("ocloc");
|
||||
EXPECT_EQ(0, mockMultiCommand.singleBuildCalledCount);
|
||||
|
||||
ASSERT_EQ(1u, mockMultiCommand.retValues.size());
|
||||
EXPECT_EQ(OclocErrorCode::INVALID_FILE, mockMultiCommand.retValues[0]);
|
||||
}
|
||||
|
||||
TEST(MultiCommandWhiteboxTest, GivenTwoValidCommandLinesAndVerboseModeWhenRunningBuildsThenBuildsAreStartedReturnValuesAreStoredAndLogsArePrinted) {
|
||||
MockMultiCommand mockMultiCommand{};
|
||||
mockMultiCommand.quiet = false;
|
||||
mockMultiCommand.callBaseSingleBuild = false;
|
||||
|
||||
const std::string validLine{"-file test_files/copybuffer.cl -output SpecialOutputFilename -out_dir SomeOutputDirectory -device " + gEnvironment->devicePrefix};
|
||||
mockMultiCommand.lines.push_back(validLine);
|
||||
mockMultiCommand.lines.push_back(validLine);
|
||||
|
||||
::testing::internal::CaptureStdout();
|
||||
mockMultiCommand.runBuilds("ocloc");
|
||||
const auto output = testing::internal::GetCapturedStdout();
|
||||
|
||||
EXPECT_EQ(2, mockMultiCommand.singleBuildCalledCount);
|
||||
|
||||
ASSERT_EQ(2u, mockMultiCommand.retValues.size());
|
||||
EXPECT_EQ(OclocErrorCode::SUCCESS, mockMultiCommand.retValues[0]);
|
||||
EXPECT_EQ(OclocErrorCode::SUCCESS, mockMultiCommand.retValues[1]);
|
||||
|
||||
const auto expectedOutput{"Command number 1: \n"
|
||||
"Command number 2: \n"};
|
||||
EXPECT_EQ(expectedOutput, output);
|
||||
}
|
||||
|
||||
TEST(MultiCommandWhiteboxTest, GivenArgsWithQuietModeAndEmptyMulticommandFileWhenInitializingThenQuietFlagIsSetAndErrorIsReturned) {
|
||||
MockMultiCommand mockMultiCommand{};
|
||||
mockMultiCommand.quiet = false;
|
||||
|
||||
|
@ -457,6 +494,29 @@ TEST(MultiCommandWhiteboxTest, GivenArgsWithQuietModeAndEmptyMulticomandFileWhen
|
|||
|
||||
const auto expectedOutput = "Command file was empty.\n";
|
||||
EXPECT_EQ(expectedOutput, output);
|
||||
|
||||
EXPECT_TRUE(mockMultiCommand.quiet);
|
||||
}
|
||||
|
||||
TEST(MultiCommandWhiteboxTest, GivenInvalidArgsWhenInitializingThenErrorIsReturned) {
|
||||
MockMultiCommand mockMultiCommand{};
|
||||
mockMultiCommand.quiet = false;
|
||||
|
||||
const std::vector<std::string> args = {
|
||||
"ocloc",
|
||||
"multi",
|
||||
"commands.txt",
|
||||
"-invalid_option"};
|
||||
|
||||
::testing::internal::CaptureStdout();
|
||||
const auto result = mockMultiCommand.initialize(args);
|
||||
const auto output = testing::internal::GetCapturedStdout();
|
||||
|
||||
EXPECT_EQ(OclocErrorCode::INVALID_COMMAND_LINE, result);
|
||||
|
||||
const auto expectedError = "Invalid option (arg 3): -invalid_option\n";
|
||||
const auto errorPosition = output.find(expectedError);
|
||||
EXPECT_NE(std::string::npos, errorPosition);
|
||||
}
|
||||
|
||||
TEST(MockOfflineCompilerTests, givenProductConfigValueWhenInitHwInfoThenResetGtSystemInfo) {
|
||||
|
|
|
@ -143,7 +143,7 @@ void MultiCommand::runBuilds(const std::string &argZero) {
|
|||
}
|
||||
|
||||
if (!quiet) {
|
||||
argHelper->printf("Command numer %zu: \n", i + 1);
|
||||
argHelper->printf("Command number %zu: \n", i + 1);
|
||||
}
|
||||
|
||||
addAdditionalOptionsToSingleCommandLine(args, i);
|
||||
|
|
|
@ -38,7 +38,7 @@ class MultiCommand {
|
|||
int initialize(const std::vector<std::string> &args);
|
||||
int splitLineInSeparateArgs(std::vector<std::string> &qargs, const std::string &command, size_t numberOfBuild);
|
||||
int showResults();
|
||||
int singleBuild(const std::vector<std::string> &args);
|
||||
MOCKABLE_VIRTUAL int singleBuild(const std::vector<std::string> &args);
|
||||
void addAdditionalOptionsToSingleCommandLine(std::vector<std::string> &, size_t buildId);
|
||||
void printHelp();
|
||||
void runBuilds(const std::string &argZero);
|
||||
|
|
Loading…
Reference in New Issue