1+ /*
2+ * Copyright (C) 2022 Intel Corporation
3+ *
4+ * SPDX-License-Identifier: MIT
5+ *
6+ */
7+
8+ #include " ocloc_fcl_facade_tests.h"
9+
10+ #include " shared/offline_compiler/source/ocloc_error_code.h"
11+ #include " shared/source/debug_settings/debug_settings_manager.h"
12+ #include " shared/source/os_interface/os_inc_base.h"
13+ #include " shared/test/common/helpers/debug_manager_state_restore.h"
14+
15+ #include " mock/mock_ocloc_fcl_facade.h"
16+
17+ #include < string>
18+
19+ namespace NEO {
20+
21+ TEST_F (OclocFclFacadeTest, GivenMissingFclLibraryWhenPreparingFclThenFailureIsReported) {
22+ MockOclocFclFacade mockFclFacade{&mockArgHelper};
23+ mockFclFacade.shouldFailLoadingOfFclLib = true ;
24+
25+ ::testing::internal::CaptureStdout ();
26+ const auto fclPreparationResult{mockFclFacade.initialize (hwInfo)};
27+ const auto output{::testing::internal::GetCapturedStdout ()};
28+
29+ EXPECT_EQ (OclocErrorCode::OUT_OF_HOST_MEMORY, fclPreparationResult);
30+ EXPECT_FALSE (mockFclFacade.isInitialized ());
31+
32+ std::stringstream expectedErrorMessage;
33+ expectedErrorMessage << " Error! Loading of FCL library has failed! Filename: " << Os::frontEndDllName << " \n " ;
34+
35+ EXPECT_EQ (expectedErrorMessage.str (), output);
36+ }
37+
38+ TEST_F (OclocFclFacadeTest, GivenFailingLoadingOfFclSymbolsWhenPreparingFclThenFailureIsReported) {
39+ MockOclocFclFacade mockFclFacade{&mockArgHelper};
40+ mockFclFacade.shouldFailLoadingOfFclCreateMainFunction = true ;
41+
42+ ::testing::internal::CaptureStdout ();
43+ const auto fclPreparationResult{mockFclFacade.initialize (hwInfo)};
44+ const auto output{::testing::internal::GetCapturedStdout ()};
45+
46+ EXPECT_EQ (OclocErrorCode::OUT_OF_HOST_MEMORY, fclPreparationResult);
47+ EXPECT_FALSE (mockFclFacade.isInitialized ());
48+
49+ const std::string expectedErrorMessage{" Error! Cannot load required functions from FCL library.\n " };
50+ EXPECT_EQ (expectedErrorMessage, output);
51+ }
52+
53+ TEST_F (OclocFclFacadeTest, GivenFailingCreationOfFclMainWhenPreparingFclThenFailureIsReported) {
54+ MockOclocFclFacade mockFclFacade{&mockArgHelper};
55+ mockFclFacade.shouldFailCreationOfFclMain = true ;
56+
57+ ::testing::internal::CaptureStdout ();
58+ const auto fclPreparationResult{mockFclFacade.initialize (hwInfo)};
59+ const auto output{::testing::internal::GetCapturedStdout ()};
60+
61+ EXPECT_EQ (OclocErrorCode::OUT_OF_HOST_MEMORY, fclPreparationResult);
62+ EXPECT_FALSE (mockFclFacade.isInitialized ());
63+
64+ const std::string expectedErrorMessage{" Error! Cannot create FCL main component!\n " };
65+ EXPECT_EQ (expectedErrorMessage, output);
66+ }
67+
68+ TEST_F (OclocFclFacadeTest, GivenIncompatibleFclInterfacesWhenPreparingFclThenFailureIsReported) {
69+ DebugManagerStateRestore stateRestore;
70+ DebugManager.flags .EnableDebugBreak .set (false );
71+
72+ MockOclocFclFacade mockFclFacade{&mockArgHelper};
73+ mockFclFacade.isFclInterfaceCompatibleReturnValue = false ;
74+ mockFclFacade.getIncompatibleInterfaceReturnValue = " SomeImportantInterface" ;
75+
76+ ::testing::internal::CaptureStdout ();
77+ const auto fclPreparationResult{mockFclFacade.initialize (hwInfo)};
78+ const auto output{::testing::internal::GetCapturedStdout ()};
79+
80+ EXPECT_EQ (OclocErrorCode::OUT_OF_HOST_MEMORY, fclPreparationResult);
81+ EXPECT_FALSE (mockFclFacade.isInitialized ());
82+
83+ const std::string expectedErrorMessage{" Error! Incompatible interface in FCL: SomeImportantInterface\n " };
84+ EXPECT_EQ (expectedErrorMessage, output);
85+ }
86+
87+ TEST_F (OclocFclFacadeTest, GivenFailingCreationOfFclDeviceContextWhenPreparingFclThenFailureIsReported) {
88+ MockOclocFclFacade mockFclFacade{&mockArgHelper};
89+ mockFclFacade.shouldFailCreationOfFclDeviceContext = true ;
90+
91+ ::testing::internal::CaptureStdout ();
92+ const auto fclPreparationResult{mockFclFacade.initialize (hwInfo)};
93+ const auto output{::testing::internal::GetCapturedStdout ()};
94+
95+ EXPECT_EQ (OclocErrorCode::OUT_OF_HOST_MEMORY, fclPreparationResult);
96+ EXPECT_FALSE (mockFclFacade.isInitialized ());
97+
98+ const std::string expectedErrorMessage{" Error! Cannot create FCL device context!\n " };
99+ EXPECT_EQ (expectedErrorMessage, output);
100+ }
101+
102+ TEST_F (OclocFclFacadeTest, GivenNoneErrorsSetAndNotPopulateFclInterfaceWhenPreparingFclThenSuccessIsReported) {
103+ MockOclocFclFacade mockFclFacade{&mockArgHelper};
104+ mockFclFacade.shouldPopulateFclInterfaceReturnValue = false ;
105+
106+ ::testing::internal::CaptureStdout ();
107+ const auto fclPreparationResult{mockFclFacade.initialize (hwInfo)};
108+ const auto output{::testing::internal::GetCapturedStdout ()};
109+
110+ EXPECT_EQ (OclocErrorCode::SUCCESS, fclPreparationResult);
111+ EXPECT_TRUE (output.empty ()) << output;
112+ EXPECT_TRUE (mockFclFacade.isInitialized ());
113+ EXPECT_EQ (0 , mockFclFacade.populateFclInterfaceCalledCount );
114+ }
115+
116+ TEST_F (OclocFclFacadeTest, GivenPopulateFclInterfaceAndInvalidFclDeviceContextWhenPreparingFclThenFailureIsReported) {
117+ MockOclocFclFacade mockFclFacade{&mockArgHelper};
118+ mockFclFacade.shouldPopulateFclInterfaceReturnValue = true ;
119+ mockFclFacade.shouldReturnInvalidFclPlatformHandle = true ;
120+
121+ ::testing::internal::CaptureStdout ();
122+ const auto fclPreparationResult{mockFclFacade.initialize (hwInfo)};
123+ const auto output{::testing::internal::GetCapturedStdout ()};
124+
125+ EXPECT_EQ (OclocErrorCode::OUT_OF_HOST_MEMORY, fclPreparationResult);
126+ EXPECT_FALSE (mockFclFacade.isInitialized ());
127+
128+ const std::string expectedErrorMessage{" Error! FCL device context has not been properly created!\n " };
129+ EXPECT_EQ (expectedErrorMessage, output);
130+
131+ EXPECT_EQ (0 , mockFclFacade.populateFclInterfaceCalledCount );
132+ }
133+
134+ TEST_F (OclocFclFacadeTest, GivenPopulateFclInterfaceWhenPreparingFclThenSuccessIsReported) {
135+ MockOclocFclFacade mockFclFacade{&mockArgHelper};
136+ mockFclFacade.shouldPopulateFclInterfaceReturnValue = true ;
137+
138+ ::testing::internal::CaptureStdout ();
139+ const auto fclPreparationResult{mockFclFacade.initialize (hwInfo)};
140+ const auto output{::testing::internal::GetCapturedStdout ()};
141+
142+ EXPECT_EQ (OclocErrorCode::SUCCESS, fclPreparationResult);
143+ EXPECT_TRUE (output.empty ()) << output;
144+ EXPECT_TRUE (mockFclFacade.isInitialized ());
145+
146+ EXPECT_EQ (1 , mockFclFacade.populateFclInterfaceCalledCount );
147+ }
148+
149+ TEST_F (OclocFclFacadeTest, GivenNoneErrorsSetWhenPreparingFclThenSuccessIsReported) {
150+ MockOclocFclFacade mockFclFacade{&mockArgHelper};
151+
152+ ::testing::internal::CaptureStdout ();
153+ const auto fclPreparationResult{mockFclFacade.initialize (hwInfo)};
154+ const auto output{::testing::internal::GetCapturedStdout ()};
155+
156+ EXPECT_EQ (OclocErrorCode::SUCCESS, fclPreparationResult);
157+ EXPECT_TRUE (output.empty ()) << output;
158+ EXPECT_TRUE (mockFclFacade.isInitialized ());
159+
160+ const auto expectedPopulateCalledCount = mockFclFacade.shouldPopulateFclInterface () ? 1 : 0 ;
161+ EXPECT_EQ (expectedPopulateCalledCount, mockFclFacade.populateFclInterfaceCalledCount );
162+ }
163+
164+ TEST_F (OclocFclFacadeTest, GivenInitializedFclWhenGettingIncompatibleInterfaceThenEmptyStringIsReturned) {
165+ MockOclocFclFacade mockFclFacade{&mockArgHelper};
166+
167+ ::testing::internal::CaptureStdout ();
168+ const auto fclPreparationResult{mockFclFacade.initialize (hwInfo)};
169+ const auto output{::testing::internal::GetCapturedStdout ()};
170+
171+ ASSERT_EQ (OclocErrorCode::SUCCESS, fclPreparationResult);
172+
173+ const auto incompatibleInterface = mockFclFacade.getIncompatibleInterface ();
174+ EXPECT_TRUE (incompatibleInterface.empty ()) << incompatibleInterface;
175+ }
176+
177+ } // namespace NEO
0 commit comments