Skip to content

Commit f1e839b

Browse files
Add ocloc ults
Signed-off-by: Kamil Kopryk <[email protected]>
1 parent fbf1f36 commit f1e839b

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

opencl/test/unit_test/offline_compiler/offline_compiler_tests.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,6 +1286,43 @@ TEST(OfflineCompilerTest, givenNonExistingFilenameWhenUsedToReadOptionsThenReadO
12861286
EXPECT_FALSE(result);
12871287
}
12881288

1289+
class MyOclocArgHelper : public OclocArgHelper {
1290+
public:
1291+
std::unique_ptr<char[]> loadDataFromFile(const std::string &filename, size_t &retSize) override {
1292+
auto file = std::make_unique<char[]>(fileContent.size() + 1);
1293+
strcpy_s(file.get(), fileContent.size() + 1, fileContent.c_str());
1294+
retSize = fileContent.size();
1295+
return file;
1296+
}
1297+
1298+
bool fileExists(const std::string &filename) const override {
1299+
return true;
1300+
}
1301+
1302+
std::string fileContent;
1303+
};
1304+
1305+
TEST(OfflineCompilerTest, givenEmptyFileWhenReadOptionsFromFileThenSuccessIsReturned) {
1306+
std::string options;
1307+
std::string filename("non_existing_file");
1308+
1309+
auto helper = std::make_unique<MyOclocArgHelper>();
1310+
helper->fileContent = "";
1311+
1312+
EXPECT_TRUE(OfflineCompiler::readOptionsFromFile(options, filename, helper.get()));
1313+
EXPECT_TRUE(options.empty());
1314+
}
1315+
1316+
TEST(OfflineCompilerTest, givenNoCopyRightsWhenReadOptionsFromFileThenSuccessIsReturned) {
1317+
std::string options;
1318+
std::string filename("non_existing_file");
1319+
1320+
auto helper = std::make_unique<MyOclocArgHelper>();
1321+
helper->fileContent = "-dummy_option";
1322+
EXPECT_TRUE(OfflineCompiler::readOptionsFromFile(options, filename, helper.get()));
1323+
EXPECT_STREQ(helper->fileContent.c_str(), options.c_str());
1324+
}
1325+
12891326
TEST(OfflineCompilerTest, givenEmptyDirectoryWhenGenerateFilePathIsCalledThenTrailingSlashIsNotAppended) {
12901327
std::string path = generateFilePath("", "a", "b");
12911328
EXPECT_STREQ("ab", path.c_str());
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
1+
/*
2+
* Copyright (C) 2021 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
*/
7+
18
-cl-opt-disable

shared/offline_compiler/source/ocloc_arg_helper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class OclocArgHelper {
8080
std::vector<std::string> headersToVectorOfStrings();
8181
void readFileToVectorOfStrings(const std::string &filename, std::vector<std::string> &lines);
8282
MOCKABLE_VIRTUAL std::vector<char> readBinaryFile(const std::string &filename);
83-
std::unique_ptr<char[]> loadDataFromFile(const std::string &filename, size_t &retSize);
83+
MOCKABLE_VIRTUAL std::unique_ptr<char[]> loadDataFromFile(const std::string &filename, size_t &retSize);
8484

8585
bool outputEnabled() const {
8686
return hasOutput;

0 commit comments

Comments
 (0)