|
27 | 27 | #include "gtest/gtest.h" |
28 | 28 | #include "hw_cmds.h" |
29 | 29 | #include "mock/mock_argument_helper.h" |
| 30 | +#include "mock/mock_multi_command.h" |
30 | 31 | #include "mock/mock_offline_compiler.h" |
31 | 32 |
|
32 | 33 | #include <algorithm> |
@@ -315,6 +316,148 @@ TEST_F(MultiCommandTests, GivenOutputFileListFlagWhenBuildingMultiCommandThenSuc |
315 | 316 | delete pMultiCommand; |
316 | 317 | } |
317 | 318 |
|
| 319 | +TEST(MultiCommandWhiteboxTest, GivenVerboseModeWhenShowingResultsThenLogsArePrintedForEachBuild) { |
| 320 | + MockMultiCommand mockMultiCommand{}; |
| 321 | + mockMultiCommand.retValues = {OclocErrorCode::SUCCESS, OclocErrorCode::INVALID_FILE}; |
| 322 | + mockMultiCommand.quiet = false; |
| 323 | + |
| 324 | + ::testing::internal::CaptureStdout(); |
| 325 | + const auto result = mockMultiCommand.showResults(); |
| 326 | + const auto output = testing::internal::GetCapturedStdout(); |
| 327 | + |
| 328 | + const auto maskedResult = result | OclocErrorCode::INVALID_FILE; |
| 329 | + EXPECT_NE(OclocErrorCode::SUCCESS, result); |
| 330 | + EXPECT_EQ(OclocErrorCode::INVALID_FILE, maskedResult); |
| 331 | + |
| 332 | + const auto expectedOutput{"Build command 0: successful\n" |
| 333 | + "Build command 1: failed. Error code: -5151\n"}; |
| 334 | + EXPECT_EQ(expectedOutput, output); |
| 335 | +} |
| 336 | + |
| 337 | +TEST(MultiCommandWhiteboxTest, GivenVerboseModeAndDefinedOutputFilenameAndDirectoryWhenAddingAdditionalOptionsToSingleCommandLineThenNothingIsDone) { |
| 338 | + MockMultiCommand mockMultiCommand{}; |
| 339 | + mockMultiCommand.quiet = false; |
| 340 | + |
| 341 | + std::vector<std::string> singleArgs = { |
| 342 | + "-file", |
| 343 | + "test_files/copybuffer.cl", |
| 344 | + "-output", |
| 345 | + "SpecialOutputFilename", |
| 346 | + "-out_dir", |
| 347 | + "SomeOutputDirectory", |
| 348 | + "-device", |
| 349 | + gEnvironment->devicePrefix.c_str()}; |
| 350 | + |
| 351 | + const auto singleArgsCopy{singleArgs}; |
| 352 | + const size_t buildId{0}; |
| 353 | + |
| 354 | + ::testing::internal::CaptureStdout(); |
| 355 | + mockMultiCommand.addAdditionalOptionsToSingleCommandLine(singleArgs, buildId); |
| 356 | + const auto output = testing::internal::GetCapturedStdout(); |
| 357 | + |
| 358 | + EXPECT_EQ(singleArgsCopy, singleArgs); |
| 359 | +} |
| 360 | + |
| 361 | +TEST(MultiCommandWhiteboxTest, GivenHelpArgumentsWhenInitializingThenHelpIsPrinted) { |
| 362 | + MockMultiCommand mockMultiCommand{}; |
| 363 | + mockMultiCommand.quiet = false; |
| 364 | + |
| 365 | + std::vector<std::string> singleArgs = { |
| 366 | + "--help"}; |
| 367 | + |
| 368 | + const auto args{singleArgs}; |
| 369 | + |
| 370 | + ::testing::internal::CaptureStdout(); |
| 371 | + const auto result = mockMultiCommand.initialize(args); |
| 372 | + const auto output = testing::internal::GetCapturedStdout(); |
| 373 | + |
| 374 | + const auto expectedOutput = R"===(Compiles multiple files using a config file. |
| 375 | +
|
| 376 | +Usage: ocloc multi <file_name> |
| 377 | + <file_name> Input file containing a list of arguments for subsequent |
| 378 | + ocloc invocations. |
| 379 | + Expected format of each line inside such file is: |
| 380 | + '-file <filename> -device <device_type> [compile_options]'. |
| 381 | + See 'ocloc compile --help' for available compile_options. |
| 382 | + Results of subsequent compilations will be dumped into |
| 383 | + a directory with name indentical file_name's base name. |
| 384 | +
|
| 385 | + -output_file_list Name of optional file containing |
| 386 | + paths to outputs .bin files |
| 387 | +
|
| 388 | +)==="; |
| 389 | + |
| 390 | + EXPECT_EQ(expectedOutput, output); |
| 391 | + EXPECT_EQ(-1, result); |
| 392 | +} |
| 393 | + |
| 394 | +TEST(MultiCommandWhiteboxTest, GivenCommandLineWithApostrophesWhenSplittingLineInSeparateArgsThenTextBetweenApostrophesIsReadAsSingleArg) { |
| 395 | + MockMultiCommand mockMultiCommand{}; |
| 396 | + mockMultiCommand.quiet = false; |
| 397 | + |
| 398 | + const std::string commandLine{" -out_dir \"Some Directory\" -output \'Some Filename\'"}; |
| 399 | + std::vector<std::string> outputArgs{}; |
| 400 | + const std::size_t numberOfBuild{0}; |
| 401 | + |
| 402 | + ::testing::internal::CaptureStdout(); |
| 403 | + const auto result = mockMultiCommand.splitLineInSeparateArgs(outputArgs, commandLine, numberOfBuild); |
| 404 | + const auto output = testing::internal::GetCapturedStdout(); |
| 405 | + |
| 406 | + EXPECT_EQ(OclocErrorCode::SUCCESS, result); |
| 407 | + EXPECT_TRUE(output.empty()) << output; |
| 408 | + |
| 409 | + ASSERT_EQ(4u, outputArgs.size()); |
| 410 | + |
| 411 | + EXPECT_EQ("-out_dir", outputArgs[0]); |
| 412 | + EXPECT_EQ("Some Directory", outputArgs[1]); |
| 413 | + |
| 414 | + EXPECT_EQ("-output", outputArgs[2]); |
| 415 | + EXPECT_EQ("Some Filename", outputArgs[3]); |
| 416 | +} |
| 417 | + |
| 418 | +TEST(MultiCommandWhiteboxTest, GivenCommandLineWithMissingApostropheWhenSplittingLineInSeparateArgsThenErrorIsReturned) { |
| 419 | + MockMultiCommand mockMultiCommand{}; |
| 420 | + mockMultiCommand.quiet = false; |
| 421 | + |
| 422 | + const std::string commandLine{"-out_dir \"Some Directory"}; |
| 423 | + std::vector<std::string> outputArgs{}; |
| 424 | + const std::size_t numberOfBuild{0}; |
| 425 | + |
| 426 | + ::testing::internal::CaptureStdout(); |
| 427 | + const auto result = mockMultiCommand.splitLineInSeparateArgs(outputArgs, commandLine, numberOfBuild); |
| 428 | + const auto output = testing::internal::GetCapturedStdout(); |
| 429 | + |
| 430 | + EXPECT_EQ(OclocErrorCode::INVALID_FILE, result); |
| 431 | + |
| 432 | + const auto expectedOutput = "One of the quotes is open in build number 1\n"; |
| 433 | + EXPECT_EQ(expectedOutput, output); |
| 434 | +} |
| 435 | + |
| 436 | +TEST(MultiCommandWhiteboxTest, GivenArgsWithQuietModeAndEmptyMulticomandFileWhenInitializingThenQuietFlagIsSetAndErrorIsReturned) { |
| 437 | + MockMultiCommand mockMultiCommand{}; |
| 438 | + mockMultiCommand.quiet = false; |
| 439 | + |
| 440 | + mockMultiCommand.uniqueHelper->callBaseFileExists = false; |
| 441 | + mockMultiCommand.uniqueHelper->callBaseReadFileToVectorOfStrings = false; |
| 442 | + mockMultiCommand.uniqueHelper->shouldReturnEmptyVectorOfStrings = true; |
| 443 | + mockMultiCommand.filesMap["commands.txt"] = ""; |
| 444 | + |
| 445 | + const std::vector<std::string> args = { |
| 446 | + "ocloc", |
| 447 | + "multi", |
| 448 | + "commands.txt", |
| 449 | + "-q"}; |
| 450 | + |
| 451 | + ::testing::internal::CaptureStdout(); |
| 452 | + const auto result = mockMultiCommand.initialize(args); |
| 453 | + const auto output = testing::internal::GetCapturedStdout(); |
| 454 | + |
| 455 | + EXPECT_EQ(OclocErrorCode::INVALID_FILE, result); |
| 456 | + |
| 457 | + const auto expectedOutput = "Command file was empty.\n"; |
| 458 | + EXPECT_EQ(expectedOutput, output); |
| 459 | +} |
| 460 | + |
318 | 461 | TEST(MockOfflineCompilerTests, givenProductConfigValueWhenInitHwInfoThenResetGtSystemInfo) { |
319 | 462 | MockOfflineCompiler mockOfflineCompiler; |
320 | 463 | auto allEnabledDeviceConfigs = mockOfflineCompiler.argHelper->getAllSupportedDeviceConfigs(); |
|
0 commit comments