Skip to content

Commit

Permalink
Add static analysis fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Jemale Lockett <jemale.lockett@intel.com>
  • Loading branch information
Jemale committed Jul 12, 2024
1 parent 3b034bd commit 7038a10
Show file tree
Hide file tree
Showing 15 changed files with 344 additions and 184 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ if(NOT TARGET GTest::GTest AND NOT TARGET GMock::GMock AND NOT BUILD_ZE_PERF_TES
endif()
enable_testing()

set(GTEST_HAS_EXCEPTIONS 0)
add_compile_definitions(GTEST_HAS_EXCEPTIONS=0)

set(CMAKE_CXX_STANDARD 14)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ class CaptureOutput {
file_name = std::tmpnam(nullptr);
file_descriptor = creat(file_name.c_str(), _S_IREAD | _S_IWRITE);
#endif
if (file_descriptor < 0) {
LOG_ERROR << "Error creating file" << std::endl;
return;
}
fflush(nullptr);
dup2(file_descriptor, stream);
close(file_descriptor);
Expand All @@ -67,7 +71,9 @@ class CaptureOutput {
close(orig_file_descriptor);
orig_file_descriptor = -1;
}
remove(file_name.c_str());
if (remove(file_name.c_str())) {
LOG_WARNING << "Error removing file: " << file_name << std::endl;
}
}

std::stringstream GetOutput() {
Expand Down
4 changes: 2 additions & 2 deletions conformance_tests/core/test_device/src/test_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -931,8 +931,8 @@ void RunGivenExecutedKernelWhenGettingGlobalTimestampsTest(bool is_immediate) {
auto device_time_0 = std::get<1>(timestamps);
auto device_time_1 = std::get<1>(timestamps_1);
auto device_properties = lzt::get_device_properties(device);
uint64_t timestamp_max_val =
~(-1 << device_properties.kernelTimestampValidBits);
uint64_t timestamp_max_val = ~(static_cast<uint64_t>(-1)
<< device_properties.kernelTimestampValidBits);
uint64_t timestamp_freq = device_properties.timerResolution;

auto device_diff_ns =
Expand Down
8 changes: 6 additions & 2 deletions conformance_tests/core/test_module/src/test_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ std::vector<ze_module_handle_t> create_module_vector_and_log(
ZE_MODULE_FORMAT_NATIVE, nullptr,
&build_log->at(count)));
count++;
std::remove(filename_native.c_str());
if (std::remove(filename_native.c_str())) {
LOG_WARNING << "FAILED to remove file " << filename_native;
}
}
} else {
for (auto flag : build_flag) {
Expand Down Expand Up @@ -511,7 +513,9 @@ TEST_F(
std::ifstream stream(filename_native, std::ios::in | std::ios::binary);
stream.seekg(0, stream.end);
EXPECT_EQ(static_cast<size_t>(stream.tellg()), size);
std::remove(filename_native.c_str());
if (std::remove(filename_native.c_str())) {
LOG_WARNING << "FAILED to remove file " << filename_native;
}
lzt::destroy_module(module);
stream.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ TEST_F(
(ZE_DEVICE_PROPERTY_FLAG_INTEGRATED |
ZE_DEVICE_PROPERTY_FLAG_SUBDEVICE | ZE_DEVICE_PROPERTY_FLAG_ECC |
ZE_DEVICE_PROPERTY_FLAG_ONDEMANDPAGING)) &&
(properties_initial.core.flags <=
(properties_later.core.flags <=
(ZE_DEVICE_PROPERTY_FLAG_INTEGRATED |
ZE_DEVICE_PROPERTY_FLAG_SUBDEVICE | ZE_DEVICE_PROPERTY_FLAG_ECC |
ZE_DEVICE_PROPERTY_FLAG_ONDEMANDPAGING))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ void get_ze_root_uuids(std::vector<ze_device_handle_t> ze_devices,
int main(int argc, char **argv) {

char *device_hierarchy = getenv("ZE_FLAT_DEVICE_HIERARCHY");
LOG_INFO << "Device Hierarchy : " << device_hierarchy;
EXPECT_NE(device_hierarchy, nullptr);
LOG_INFO << "Device Hierarchy : " << device_hierarchy ? device_hierarchy
: "NULL";

auto driver = lzt::zeDevice::get_instance()->get_driver();
std::vector<ze_device_handle_t> ze_devices = lzt::get_ze_devices(driver);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ void get_sysman_devices(const std::string set_device_hierarchy,
putenv(sys_env);
char *get_device_hierarchy = getenv("ZE_FLAT_DEVICE_HIERARCHY");
EXPECT_NE(get_device_hierarchy, nullptr);
LOG_INFO << "Child Process : Device Hierarchy = " << get_device_hierarchy;
LOG_INFO << "Child Process : Device Hierarchy = " << get_device_hierarchy
? get_device_hierarchy
: "NULL";
devices = GET_DEVICE_FN();
}

Expand Down
146 changes: 103 additions & 43 deletions perf_tests/cl_image_copy/src/cl_image_copy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,16 @@ void measure_bandwidth_Host2Device2Host(ClImageCopy &Imagecopy,
std::stringstream Image_dimensions;
Image_dimensions << Imagecopy.width << "X" << Imagecopy.height << "X"
<< Imagecopy.depth;
test_ptree->put(
"Name", "Host2Device2Host: Bandwidth copying from Host->Device->Host ");
test_ptree->put("Image size", Image_dimensions.str());
try {
test_ptree->put(
"Name",
"Host2Device2Host: Bandwidth copying from Host->Device->Host ");
test_ptree->put("Image size", Image_dimensions.str());
} catch (const std::exception &e) {
std::cerr
<< "Error outputting bandwidth host to device to host measurement: "
<< e.what() << std::endl;
}
} else {
std::cout << "Host2Device2Host: Measuring Bandwidth for copying the "
"image buffer size "
Expand All @@ -348,9 +355,15 @@ void measure_bandwidth_Host2Device2Host(ClImageCopy &Imagecopy,
Imagecopy.measureHost2Device2Host();

if (Imagecopy.is_json_output_enabled()) {
test_ptree->put("GBPS", Imagecopy.gbps);
if (Imagecopy.data_validation)
test_ptree->put("Result", (Imagecopy.validRet ? "PASSED" : "FAILED"));
try {
test_ptree->put("GBPS", Imagecopy.gbps);
if (Imagecopy.data_validation)
test_ptree->put("Result", (Imagecopy.validRet ? "PASSED" : "FAILED"));
} catch (const std::exception &e) {
std::cerr
<< "Error outputting bandwidth host to device to host measurement: "
<< e.what() << std::endl;
}
} else {
if (Imagecopy.data_validation) {
std::cout << " Results: Data validation "
Expand All @@ -365,8 +378,14 @@ void measure_bandwidth_Host2Device(ClImageCopy &Imagecopy, ptree *test_ptree) {
std::stringstream Image_dimensions;
Image_dimensions << Imagecopy.width << "X" << Imagecopy.height << "X"
<< Imagecopy.depth;
test_ptree->put("Name", "Host2Device: Bandwidth copying from Host->Device");
test_ptree->put("Image size", Image_dimensions.str());
try {
test_ptree->put("Name",
"Host2Device: Bandwidth copying from Host->Device");
test_ptree->put("Image size", Image_dimensions.str());
} catch (const std::exception &e) {
std::cerr << "Error outputting bandwidth measurement:" << e.what()
<< std::endl;
}
} else {
std::cout
<< "Host2Device: Measuring Bandwidth/Latency for copying the image "
Expand All @@ -378,9 +397,14 @@ void measure_bandwidth_Host2Device(ClImageCopy &Imagecopy, ptree *test_ptree) {
Imagecopy.measureParallelHost2Device();

if (Imagecopy.is_json_output_enabled()) {
test_ptree->put("GBPS", Imagecopy.gbps);
if (Imagecopy.data_validation) {
test_ptree->put("Result", (Imagecopy.validRet ? "PASSED" : "FAILED"));
try {
test_ptree->put("GBPS", Imagecopy.gbps);
if (Imagecopy.data_validation) {
test_ptree->put("Result", (Imagecopy.validRet ? "PASSED" : "FAILED"));
}
} catch (const std::exception &e) {
std::cerr << "Error outputting bandwidth measurement:" << e.what()
<< std::endl;
}
} else {
if (Imagecopy.data_validation) {
Expand All @@ -396,8 +420,14 @@ void measure_bandwidth_Device2Host(ClImageCopy &Imagecopy, ptree *test_ptree) {
std::stringstream Image_dimensions;
Image_dimensions << Imagecopy.width << "X" << Imagecopy.height << "X"
<< Imagecopy.depth;
test_ptree->put("Name", "Device2Host: Bandwidth copying from Device->Host");
test_ptree->put("Image size", Image_dimensions.str());
try {
test_ptree->put("Name",
"Device2Host: Bandwidth copying from Device->Host");
test_ptree->put("Image size", Image_dimensions.str());
} catch (const std::exception &e) {
std::cerr << "Error outputting bandwidth measurement:" << e.what()
<< std::endl;
}
} else {
std::cout
<< "Device2Host: Measurign Bandwidth/Latency for copying the image "
Expand All @@ -409,9 +439,14 @@ void measure_bandwidth_Device2Host(ClImageCopy &Imagecopy, ptree *test_ptree) {
Imagecopy.measureParallelDevice2Host();

if (Imagecopy.is_json_output_enabled()) {
test_ptree->put("GBPS", Imagecopy.gbps);
if (Imagecopy.data_validation)
test_ptree->put("Result", (Imagecopy.validRet ? "PASSED" : "FAILED"));
try {
test_ptree->put("GBPS", Imagecopy.gbps);
if (Imagecopy.data_validation)
test_ptree->put("Result", (Imagecopy.validRet ? "PASSED" : "FAILED"));
} catch (const std::exception &e) {
std::cerr << "Error outputting bandwidth measurement:" << e.what()
<< std::endl;
}
} else {
if (Imagecopy.data_validation) {
std::cout << " Results: Data validation "
Expand All @@ -435,9 +470,14 @@ void measure_bandwidth(ClImageCopy &Imagecopy) {
Imagecopy.param_array.push_back(std::make_pair("", ptree_Host2Device2Host));
Imagecopy.param_array.push_back(std::make_pair("", ptree_Host2Device));
Imagecopy.param_array.push_back(std::make_pair("", ptree_Device2Host));
ptree_main.put_child("Performance Benchmark.bandwidth",
Imagecopy.param_array);
pt::write_json(Imagecopy.JsonFileName.c_str(), ptree_main);
try {
ptree_main.put_child("Performance Benchmark.bandwidth",
Imagecopy.param_array);
pt::write_json(Imagecopy.JsonFileName.c_str(), ptree_main);
} catch (const std::exception &e) {
std::cerr << "Error outputting bandwidth measurement:" << e.what()
<< std::endl;
}
}
}

Expand All @@ -447,14 +487,19 @@ void measure_latency_Host2Device(ClImageCopyLatency &imageCopyLatency,
std::stringstream Image_dimensions;
Image_dimensions << imageCopyLatency.width << "X" << imageCopyLatency.height
<< "X" << imageCopyLatency.depth;
test_ptree->put("Name",
"Host2Device: Measuring Latency for copying the image ");
test_ptree->put("Image size", Image_dimensions.str());
test_ptree->put("Image type", level_zero_tests::to_string(
(cl_uint)imageCopyLatency.clImagetype));
test_ptree->put("Image Channel order",
level_zero_tests::to_string(
(cl_uint)imageCopyLatency.clImageChannelOrder));
try {
test_ptree->put("Name",
"Host2Device: Measuring Latency for copying the image ");
test_ptree->put("Image size", Image_dimensions.str());
test_ptree->put("Image type", level_zero_tests::to_string(
(cl_uint)imageCopyLatency.clImagetype));
test_ptree->put("Image Channel order",
level_zero_tests::to_string(
(cl_uint)imageCopyLatency.clImageChannelOrder));
} catch (const std::exception &e) {
std::cerr << "Error outputting latency host to device measurement:"
<< e.what() << std::endl;
}
} else {
std::cout
<< "Host2Device: Measuring Bandwidth/Latency for copying the image "
Expand All @@ -471,10 +516,15 @@ void measure_latency_Host2Device(ClImageCopyLatency &imageCopyLatency,
imageCopyLatency.measureParallelHost2Device();

if (imageCopyLatency.is_json_output_enabled()) {
test_ptree->put("Latency", imageCopyLatency.latency);
if (imageCopyLatency.data_validation)
test_ptree->put("Result",
(imageCopyLatency.validRet ? "PASSED" : "FAILED"));
try {
test_ptree->put("Latency", imageCopyLatency.latency);
if (imageCopyLatency.data_validation)
test_ptree->put("Result",
(imageCopyLatency.validRet ? "PASSED" : "FAILED"));
} catch (const std::exception &e) {
std::cerr << "Error outputting parallel host to device measurement:"
<< e.what() << std::endl;
}
}
}

Expand All @@ -484,14 +534,19 @@ void measure_latency_Device2Host(ClImageCopyLatency &imageCopyLatency,
std::stringstream Image_dimensions;
Image_dimensions << imageCopyLatency.width << "X" << imageCopyLatency.height
<< "X" << imageCopyLatency.depth;
test_ptree->put("Name",
"Device2Host: Measuring Latency for copying the image");
test_ptree->put("Image size", Image_dimensions.str());
test_ptree->put("Image type", level_zero_tests::to_string(
(cl_uint)imageCopyLatency.clImagetype));
test_ptree->put("Image Channel order",
level_zero_tests::to_string(
(cl_uint)imageCopyLatency.clImageChannelOrder));
try {
test_ptree->put("Name",
"Device2Host: Measuring Latency for copying the image");
test_ptree->put("Image size", Image_dimensions.str());
test_ptree->put("Image type", level_zero_tests::to_string(
(cl_uint)imageCopyLatency.clImagetype));
test_ptree->put("Image Channel order",
level_zero_tests::to_string(
(cl_uint)imageCopyLatency.clImageChannelOrder));
} catch (const std::exception &e) {
std::cerr << "Error outputting latency device to host measurement:"
<< e.what() << std::endl;
}
} else {
std::cout
<< "Device2Host: Measuring Bandwidth/Latency for copying the image "
Expand All @@ -508,10 +563,15 @@ void measure_latency_Device2Host(ClImageCopyLatency &imageCopyLatency,
imageCopyLatency.measureParallelDevice2Host();

if (imageCopyLatency.is_json_output_enabled()) {
test_ptree->put("Latency", imageCopyLatency.latency);
if (imageCopyLatency.data_validation)
test_ptree->put("Result",
(imageCopyLatency.validRet ? "PASSED" : "FAILED"));
try {
test_ptree->put("Latency", imageCopyLatency.latency);
if (imageCopyLatency.data_validation)
test_ptree->put("Result",
(imageCopyLatency.validRet ? "PASSED" : "FAILED"));
} catch (const std::exception &e) {
std::cerr << "Error outputting parallel device to host measurement:"
<< e.what() << std::endl;
}
}
}

Expand Down
Loading

0 comments on commit 7038a10

Please sign in to comment.