55 *
66 */
77
8+ #include " shared/offline_compiler/source/decoder/translate_platform_base.h"
89#include " shared/source/helpers/array_count.h"
910#include " shared/test/common/helpers/test_files.h"
1011
1112#include " opencl/test/unit_test/offline_compiler/mock/mock_argument_helper.h"
1213#include " opencl/test/unit_test/test_files/patch_list.h"
1314
1415#include " gtest/gtest.h"
16+ #include " igad.h"
17+ #include " igfxfmid.h"
1518#include " mock/mock_decoder.h"
1619
20+ #include < array>
1721#include < fstream>
22+ #include < utility>
1823
1924SProgramBinaryHeader createProgramBinaryHeader (const uint32_t numberOfKernels, const uint32_t patchListSize) {
2025 return SProgramBinaryHeader{MAGIC_CL, 0 , 0 , 0 , numberOfKernels, 0 , patchListSize};
@@ -30,8 +35,9 @@ SKernelBinaryHeaderCommon createKernelBinaryHeaderCommon(const uint32_t kernelNa
3035}
3136
3237namespace NEO {
38+
3339TEST (DecoderTests, WhenParsingValidListOfParametersThenReturnValueIsZero) {
34- std::vector<std::string> args = {
40+ const std::vector<std::string> args = {
3541 " ocloc" ,
3642 " decoder" ,
3743 " -file" ,
@@ -45,6 +51,117 @@ TEST(DecoderTests, WhenParsingValidListOfParametersThenReturnValueIsZero) {
4551 EXPECT_EQ (0 , decoder.validateInput (args));
4652}
4753
54+ TEST (DecoderTests, GivenFlagsWhichRequireMoreArgsWithoutThemWhenParsingThenErrorIsReported) {
55+ const std::array<std::string, 4 > flagsToTest = {
56+ " -file" , " -device" , " -patch" , " -dump" };
57+
58+ for (const auto &flag : flagsToTest) {
59+ const std::vector<std::string> args = {
60+ " ocloc" ,
61+ " decoder" ,
62+ flag};
63+
64+ constexpr auto suppressMessages{false };
65+ MockDecoder decoder{suppressMessages};
66+
67+ ::testing::internal::CaptureStdout ();
68+ const auto result = decoder.validateInput (args);
69+ const auto output{::testing::internal::GetCapturedStdout ()};
70+
71+ EXPECT_EQ (-1 , result);
72+
73+ const std::string expectedErrorMessage{" Unknown argument " + flag + " \n " };
74+ EXPECT_EQ (expectedErrorMessage, output);
75+ }
76+ }
77+
78+ TEST (DecoderTests, GivenIgnoreIsaPaddingFlagWhenParsingValidListOfParametersThenReturnValueIsZeroAndInternalFlagIsSet) {
79+ const std::vector<std::string> args = {
80+ " ocloc" ,
81+ " decoder" ,
82+ " -file" ,
83+ " test_files/binary.bin" ,
84+ " -patch" ,
85+ " test_files/patch" ,
86+ " -dump" ,
87+ " test_files/created" ,
88+ " -ignore_isa_padding" };
89+
90+ MockDecoder decoder;
91+ EXPECT_EQ (0 , decoder.validateInput (args));
92+ EXPECT_TRUE (decoder.ignoreIsaPadding );
93+ }
94+
95+ TEST (DecoderTests, GivenQuietModeFlagWhenParsingValidListOfParametersThenReturnValueIsZeroAndMessagesAreSuppressed) {
96+ const std::vector<std::string> args = {
97+ " ocloc" ,
98+ " decoder" ,
99+ " -file" ,
100+ " test_files/binary.bin" ,
101+ " -patch" ,
102+ " test_files/patch" ,
103+ " -dump" ,
104+ " test_files/created" ,
105+ " -q" };
106+
107+ constexpr auto suppressMessages{false };
108+ MockDecoder decoder{suppressMessages};
109+
110+ EXPECT_EQ (0 , decoder.validateInput (args));
111+ EXPECT_TRUE (decoder.argHelper ->getPrinterRef ().isSuppressed ());
112+ }
113+
114+ TEST (DecoderTests, GivenMissingDumpFlagWhenParsingValidListOfParametersThenReturnValueIsZeroAndWarningAboutCreationOfDefaultDirectoryIsPrinted) {
115+ const std::vector<std::string> args = {
116+ " ocloc" ,
117+ " decoder" ,
118+ " -file" ,
119+ " test_files/binary.bin" ,
120+ " -device" ,
121+ " pvc" ,
122+ " -patch" ,
123+ " test_files/patch" };
124+
125+ constexpr auto suppressMessages{false };
126+ MockDecoder decoder{suppressMessages};
127+ decoder.getMockIga ()->isKnownPlatformReturnValue = true ;
128+
129+ ::testing::internal::CaptureStdout ();
130+ const auto result = decoder.validateInput (args);
131+ const auto output{::testing::internal::GetCapturedStdout ()};
132+
133+ EXPECT_EQ (0 , result);
134+
135+ const std::string expectedErrorMessage{" Warning : Path to dump folder not specificed - using ./dump as default.\n " };
136+ EXPECT_EQ (expectedErrorMessage, output);
137+ }
138+
139+ TEST (DecoderTests, GivenMissingDumpFlagAndArgHelperOutputEnabledWhenParsingValidListOfParametersThenReturnValueIsZeroAndDefaultDirectoryWarningIsNotEmitted) {
140+ const std::vector<std::string> args = {
141+ " ocloc" ,
142+ " decoder" ,
143+ " -file" ,
144+ " test_files/binary.bin" ,
145+ " -device" ,
146+ " pvc" ,
147+ " -patch" ,
148+ " test_files/patch" };
149+
150+ constexpr auto suppressMessages{false };
151+ MockDecoder decoder{suppressMessages};
152+ decoder.mockArgHelper ->hasOutput = true ;
153+ decoder.getMockIga ()->isKnownPlatformReturnValue = true ;
154+
155+ ::testing::internal::CaptureStdout ();
156+ const auto result = decoder.validateInput (args);
157+ const auto output{::testing::internal::GetCapturedStdout ()};
158+
159+ EXPECT_EQ (0 , result);
160+ EXPECT_TRUE (output.empty ()) << output;
161+
162+ decoder.mockArgHelper ->hasOutput = false ;
163+ }
164+
48165TEST (DecoderTests, GivenValidSizeStringWhenGettingSizeThenProperOutcomeIsExpectedAndExceptionIsNotThrown) {
49166 MockDecoder decoder;
50167 EXPECT_EQ (static_cast <uint8_t >(1 ), decoder.getSize (" uint8_t" ));
@@ -301,4 +418,77 @@ TEST(DecoderTests, givenPatchtokensBinaryFormatWhenTryingToGetDevBinaryThenRawDa
301418 std::string dataString (static_cast <const char *>(data), dataSize);
302419 EXPECT_STREQ (" CTNI\n\n\n\n\n\n\n " , dataString.c_str ());
303420}
421+
422+ TEST (DecoderHelperTest, GivenTextSeparatedByTabsWhenSearchingForExistingTextThenItsIndexIsReturned) {
423+ const std::vector<std::string> lines = {" Some\t Nice\t Text" };
424+ const auto position = findPos (lines, " Nice" );
425+
426+ EXPECT_EQ (0u , position);
427+ }
428+
429+ TEST (DecoderHelperTest, GivenTextSeparatedByNewLinesWhenSearchingForExistingTextThenItsIndexIsReturned) {
430+ const std::vector<std::string> lines = {" Some\n Nice\n Text" };
431+ const auto position = findPos (lines, " Nice" );
432+
433+ EXPECT_EQ (0u , position);
434+ }
435+
436+ TEST (DecoderHelperTest, GivenTextSeparatedByCarriageReturnWhenSearchingForExistingTextThenItsIndexIsReturned) {
437+ const std::vector<std::string> lines = {" Some\r Nice\r Text" };
438+ const auto position = findPos (lines, " Nice" );
439+
440+ EXPECT_EQ (0u , position);
441+ }
442+
443+ TEST (DecoderHelperTest, GivenOnlyMatchingSubstringWhenSearchingForExistingTextThenInvalidIndexIsReturned) {
444+ const std::vector<std::string> lines = {" Carpet" };
445+ const auto position = findPos (lines, " Car" );
446+
447+ EXPECT_EQ (lines.size (), position);
448+ }
449+
450+ TEST (DecoderHelperTest, GivenPathEndedBySlashWhenCallingAddSlashThenNothingIsDone) {
451+ std::string path{" ./some/path/" };
452+ addSlash (path);
453+
454+ EXPECT_EQ (" ./some/path/" , path);
455+ }
456+
457+ TEST (DecoderHelperTest, GivenPathEndedByBackSlashWhenCallingAddSlashThenNothingIsDone) {
458+ std::string path{" .\\ some\\ path\\ " };
459+ addSlash (path);
460+
461+ EXPECT_EQ (" .\\ some\\ path\\ " , path);
462+ }
463+
464+ TEST (DecoderHelperTest, GivenGfxCoreFamilyWhenTranslatingToIgaGenBaseThenExpectedIgaGenBaseIsReturned) {
465+ constexpr static std::array translations = {
466+ std::pair{IGFX_GEN8_CORE, IGA_GEN8},
467+ std::pair{IGFX_GEN9_CORE, IGA_GEN9},
468+ std::pair{IGFX_GEN11_CORE, IGA_GEN11},
469+ std::pair{IGFX_GEN11LP_CORE, IGA_GEN11},
470+ std::pair{IGFX_UNKNOWN_CORE, IGA_GEN_INVALID}};
471+
472+ for (const auto &[input, expectedOutput] : translations) {
473+ EXPECT_EQ (expectedOutput, translateToIgaGen (input));
474+ }
475+ }
476+
477+ TEST (DecoderHelperTest, GivenProductFamilyWhenTranslatingToIgaGenBaseThenExpectedIgaGenBaseIsReturned) {
478+ constexpr static std::array translations = {
479+ std::pair{IGFX_BROADWELL, IGA_GEN8},
480+ std::pair{IGFX_CHERRYVIEW, IGA_GEN8lp},
481+ std::pair{IGFX_SKYLAKE, IGA_GEN9},
482+ std::pair{IGFX_BROXTON, IGA_GEN9lp},
483+ std::pair{IGFX_KABYLAKE, IGA_GEN9p5},
484+ std::pair{IGFX_COFFEELAKE, IGA_GEN9p5},
485+ std::pair{IGFX_ICELAKE, IGA_GEN11},
486+ std::pair{IGFX_ICELAKE_LP, IGA_GEN11},
487+ std::pair{IGFX_UNKNOWN, IGA_GEN_INVALID}};
488+
489+ for (const auto &[input, expectedOutput] : translations) {
490+ EXPECT_EQ (expectedOutput, translateToIgaGen (input));
491+ }
492+ }
493+
304494} // namespace NEO
0 commit comments