7
7
8
8
#include " offline_compiler_tests.h"
9
9
10
+ #include " shared/offline_compiler/source/ocloc_api.h"
10
11
#include " shared/source/compiler_interface/intermediate_representations.h"
11
12
#include " shared/source/compiler_interface/oclc_extensions.h"
12
13
#include " shared/source/debug_settings/debug_settings_manager.h"
@@ -121,6 +122,7 @@ TEST_F(MultiCommandTests, GivenOutputFileWhenBuildingMultiCommandThenSuccessIsRe
121
122
};
122
123
123
124
std::vector<std::string> singleArgs = {
125
+ " -gen_file" ,
124
126
" -file" ,
125
127
" test_files/copybuffer.cl" ,
126
128
" -device" ,
@@ -154,6 +156,7 @@ TEST_F(MultiCommandTests, GivenSpecifiedOutputDirWhenBuildingMultiCommandThenSuc
154
156
};
155
157
156
158
std::vector<std::string> singleArgs = {
159
+ " -gen_file" ,
157
160
" -file" ,
158
161
" test_files/copybuffer.cl" ,
159
162
" -device" ,
@@ -197,6 +200,7 @@ TEST_F(MultiCommandTests, GivenSpecifiedOutputDirWithProductConfigValueWhenBuild
197
200
};
198
201
199
202
std::vector<std::string> singleArgs = {
203
+ " -gen_file" ,
200
204
" -file" ,
201
205
" test_files/copybuffer.cl" ,
202
206
" -device" ,
@@ -280,6 +284,7 @@ TEST_F(MultiCommandTests, GivenOutputFileListFlagWhenBuildingMultiCommandThenSuc
280
284
};
281
285
282
286
std::vector<std::string> singleArgs = {
287
+ " -gen_file" ,
283
288
" -file" ,
284
289
" test_files/copybuffer.cl" ,
285
290
" -device" ,
@@ -679,7 +684,8 @@ TEST_F(OfflineCompilerTests, GivenArgsWhenBuildingThenBuildSucceeds) {
679
684
" -file" ,
680
685
" test_files/copybuffer.cl" ,
681
686
" -device" ,
682
- gEnvironment ->devicePrefix .c_str ()};
687
+ gEnvironment ->devicePrefix .c_str (),
688
+ " -gen_file" };
683
689
684
690
pOfflineCompiler = OfflineCompiler::create (argv.size (), argv, true , retVal, oclocArgHelperWithoutInput.get ());
685
691
@@ -713,25 +719,30 @@ TEST_F(OfflineCompilerTests, GivenArgsWhenBuildingWithDeviceConfigValueThenBuild
713
719
" -file" ,
714
720
" test_files/copybuffer.cl" ,
715
721
" -device" ,
716
- configString};
722
+ configString,
723
+ " -gen_file" };
717
724
718
- pOfflineCompiler = OfflineCompiler::create (argv.size (), argv, true , retVal, oclocArgHelperWithoutInput.get ());
725
+ MockOfflineCompiler offlineCompiler{};
726
+
727
+ offlineCompiler.argHelper = oclocArgHelperWithoutInput.get ();
728
+ retVal = offlineCompiler.initialize (argv.size (), argv);
719
729
720
- EXPECT_NE (nullptr , pOfflineCompiler);
721
730
EXPECT_EQ (CL_SUCCESS, retVal);
722
731
723
732
testing::internal::CaptureStdout ();
724
- retVal = pOfflineCompiler-> build ();
733
+ retVal = offlineCompiler. build ();
725
734
std::string output = testing::internal::GetCapturedStdout ();
726
735
EXPECT_EQ (CL_SUCCESS, retVal);
736
+
737
+ Environment testedEnv{configString, offlineCompiler.familyNameWithType };
738
+ VariableBackup<Environment *> backup (&gEnvironment , &testedEnv);
739
+
727
740
EXPECT_TRUE (compilerOutputExists (" copybuffer" , " bc" ) || compilerOutputExists (" copybuffer" , " spv" ));
728
741
EXPECT_TRUE (compilerOutputExists (" copybuffer" , " gen" ));
729
742
EXPECT_TRUE (compilerOutputExists (" copybuffer" , " bin" ));
730
743
731
- std::string buildLog = pOfflineCompiler-> getBuildLog ();
744
+ std::string buildLog = offlineCompiler. getBuildLog ();
732
745
EXPECT_STREQ (buildLog.c_str (), " " );
733
-
734
- delete pOfflineCompiler;
735
746
}
736
747
737
748
TEST_F (OfflineCompilerTests, GivenLlvmTextWhenBuildingThenBuildSucceeds) {
@@ -741,7 +752,8 @@ TEST_F(OfflineCompilerTests, GivenLlvmTextWhenBuildingThenBuildSucceeds) {
741
752
" test_files/copybuffer.cl" ,
742
753
" -device" ,
743
754
gEnvironment ->devicePrefix .c_str (),
744
- " -llvm_text" };
755
+ " -llvm_text" ,
756
+ " -gen_file" };
745
757
746
758
pOfflineCompiler = OfflineCompiler::create (argv.size (), argv, true , retVal, oclocArgHelperWithoutInput.get ());
747
759
@@ -757,6 +769,97 @@ TEST_F(OfflineCompilerTests, GivenLlvmTextWhenBuildingThenBuildSucceeds) {
757
769
delete pOfflineCompiler;
758
770
}
759
771
772
+ TEST_F (OfflineCompilerTests, WhenGenFileFlagIsNotProvidedThenGenFileIsNotCreated) {
773
+ uint32_t numOutputs = 0u ;
774
+ uint64_t *lenOutputs = nullptr ;
775
+ uint8_t **dataOutputs = nullptr ;
776
+ char **nameOutputs = nullptr ;
777
+
778
+ bool isSpvFile = false ;
779
+ bool isGenFile = false ;
780
+ bool isBinFile = false ;
781
+
782
+ const char *argv[] = {
783
+ " ocloc" ,
784
+ " -q" ,
785
+ " -file" ,
786
+ " test_files/copybuffer.cl" ,
787
+ " -device" ,
788
+ gEnvironment ->devicePrefix .c_str ()};
789
+
790
+ unsigned int argc = sizeof (argv) / sizeof (const char *);
791
+ int retVal = oclocInvoke (argc, argv,
792
+ 0 , nullptr , nullptr , nullptr ,
793
+ 0 , nullptr , nullptr , nullptr ,
794
+ &numOutputs, &dataOutputs, &lenOutputs, &nameOutputs);
795
+
796
+ EXPECT_EQ (retVal, CL_SUCCESS);
797
+ EXPECT_EQ (numOutputs, 3u );
798
+
799
+ for (unsigned int i = 0 ; i < numOutputs; i++) {
800
+ std::string nameOutput (nameOutputs[i]);
801
+ if (nameOutput.find (" .spv" ) != std::string::npos) {
802
+ isSpvFile = true ;
803
+ }
804
+ if (nameOutput.find (" .gen" ) != std::string::npos) {
805
+ isGenFile = true ;
806
+ }
807
+ if (nameOutput.find (" .bin" ) != std::string::npos) {
808
+ isBinFile = true ;
809
+ }
810
+ }
811
+
812
+ EXPECT_TRUE (isSpvFile);
813
+ EXPECT_FALSE (isGenFile);
814
+ EXPECT_TRUE (isBinFile);
815
+ }
816
+
817
+ TEST_F (OfflineCompilerTests, WhenGenFileFlagIsProvidedThenGenFileIsCreated) {
818
+ uint32_t numOutputs = 0u ;
819
+ uint64_t *lenOutputs = nullptr ;
820
+ uint8_t **dataOutputs = nullptr ;
821
+ char **nameOutputs = nullptr ;
822
+
823
+ bool isSpvFile = false ;
824
+ bool isGenFile = false ;
825
+ bool isBinFile = false ;
826
+
827
+ const char *argv[] = {
828
+ " ocloc" ,
829
+ " -q" ,
830
+ " -gen_file" ,
831
+ " -file" ,
832
+ " test_files/copybuffer.cl" ,
833
+ " -device" ,
834
+ gEnvironment ->devicePrefix .c_str ()};
835
+
836
+ unsigned int argc = sizeof (argv) / sizeof (const char *);
837
+ int retVal = oclocInvoke (argc, argv,
838
+ 0 , nullptr , nullptr , nullptr ,
839
+ 0 , nullptr , nullptr , nullptr ,
840
+ &numOutputs, &dataOutputs, &lenOutputs, &nameOutputs);
841
+
842
+ EXPECT_EQ (retVal, CL_SUCCESS);
843
+ EXPECT_EQ (numOutputs, 4u );
844
+
845
+ for (unsigned int i = 0 ; i < numOutputs; i++) {
846
+ std::string nameOutput (nameOutputs[i]);
847
+ if (nameOutput.find (" .spv" ) != std::string::npos) {
848
+ isSpvFile = true ;
849
+ }
850
+ if (nameOutput.find (" .gen" ) != std::string::npos) {
851
+ isGenFile = true ;
852
+ }
853
+ if (nameOutput.find (" .bin" ) != std::string::npos) {
854
+ isBinFile = true ;
855
+ }
856
+ }
857
+
858
+ EXPECT_TRUE (isSpvFile);
859
+ EXPECT_TRUE (isGenFile);
860
+ EXPECT_TRUE (isBinFile);
861
+ }
862
+
760
863
TEST_F (OfflineCompilerTests, WhenFclNotNeededThenDontLoadIt) {
761
864
std::vector<std::string> argv = {
762
865
" ocloc" ,
@@ -824,7 +927,8 @@ TEST_F(OfflineCompilerTests, GivenCppFileWhenBuildingThenBuildSucceeds) {
824
927
" test_files/copybuffer.cl" ,
825
928
" -device" ,
826
929
gEnvironment ->devicePrefix .c_str (),
827
- " -cpp_file" };
930
+ " -cpp_file" ,
931
+ " -gen_file" };
828
932
829
933
pOfflineCompiler = OfflineCompiler::create (argv.size (), argv, true , retVal, oclocArgHelperWithoutInput.get ());
830
934
@@ -847,6 +951,7 @@ TEST_F(OfflineCompilerTests, GivenOutputDirWhenBuildingThenBuildSucceeds) {
847
951
" test_files/copybuffer.cl" ,
848
952
" -device" ,
849
953
gEnvironment ->devicePrefix .c_str (),
954
+ " -gen_file" ,
850
955
" -out_dir" ,
851
956
" offline_compiler_test" };
852
957
@@ -1189,7 +1294,8 @@ TEST(OfflineCompilerTest, givenSpvOnlyOptionPassedWhenCmdLineParsedThenGenerateO
1189
1294
" myOutputFileName" ,
1190
1295
" -spv_only" ,
1191
1296
" -device" ,
1192
- gEnvironment ->devicePrefix .c_str ()};
1297
+ gEnvironment ->devicePrefix .c_str (),
1298
+ " -gen_file" };
1193
1299
1194
1300
auto mockOfflineCompiler = std::unique_ptr<MockOfflineCompiler>(new MockOfflineCompiler ());
1195
1301
ASSERT_NE (nullptr , mockOfflineCompiler);
@@ -1398,7 +1504,8 @@ TEST(OfflineCompilerTest, givenOutputFileOptionWhenSourceIsCompiledThenOutputFil
1398
1504
" -output" ,
1399
1505
" myOutputFileName" ,
1400
1506
" -device" ,
1401
- gEnvironment ->devicePrefix .c_str ()};
1507
+ gEnvironment ->devicePrefix .c_str (),
1508
+ " -gen_file" };
1402
1509
1403
1510
auto mockOfflineCompiler = std::unique_ptr<MockOfflineCompiler>(new MockOfflineCompiler ());
1404
1511
ASSERT_NE (nullptr , mockOfflineCompiler);
@@ -1431,7 +1538,8 @@ TEST(OfflineCompilerTest, givenDebugDataAvailableWhenSourceIsBuiltThenDebugDataF
1431
1538
" -output" ,
1432
1539
" myOutputFileName" ,
1433
1540
" -device" ,
1434
- gEnvironment ->devicePrefix .c_str ()};
1541
+ gEnvironment ->devicePrefix .c_str (),
1542
+ " -gen_file" };
1435
1543
1436
1544
char debugData[10 ];
1437
1545
MockCompilerDebugVars igcDebugVars (gEnvironment ->igcDebugVars );
@@ -2032,7 +2140,8 @@ TEST(OclocCompile, givenSpirvInputThenDontGenerateSpirvFile) {
2032
2140
" offline_compiler_test" ,
2033
2141
" -device" ,
2034
2142
gEnvironment ->devicePrefix .c_str (),
2035
- " -spirv_input" };
2143
+ " -spirv_input" ,
2144
+ " -gen_file" };
2036
2145
2037
2146
int retVal = ocloc.initialize (argv.size (), argv);
2038
2147
ASSERT_EQ (0 , retVal);
0 commit comments