Skip to content

Commit 3524f6a

Browse files
authored
Add static analysis fixes (#52)
Signed-off-by: Jemale Lockett <[email protected]>
1 parent 3b034bd commit 3524f6a

File tree

15 files changed

+344
-184
lines changed

15 files changed

+344
-184
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ if(NOT TARGET GTest::GTest AND NOT TARGET GMock::GMock AND NOT BUILD_ZE_PERF_TES
4141
endif()
4242
enable_testing()
4343

44-
set(GTEST_HAS_EXCEPTIONS 0)
44+
add_compile_definitions(GTEST_HAS_EXCEPTIONS=0)
4545

4646
set(CMAKE_CXX_STANDARD 14)
4747

conformance_tests/core/test_cmdlist/src/test_cmdlist_and_functions.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ class CaptureOutput {
5555
file_name = std::tmpnam(nullptr);
5656
file_descriptor = creat(file_name.c_str(), _S_IREAD | _S_IWRITE);
5757
#endif
58+
if (file_descriptor < 0) {
59+
LOG_ERROR << "Error creating file" << std::endl;
60+
return;
61+
}
5862
fflush(nullptr);
5963
dup2(file_descriptor, stream);
6064
close(file_descriptor);
@@ -67,7 +71,9 @@ class CaptureOutput {
6771
close(orig_file_descriptor);
6872
orig_file_descriptor = -1;
6973
}
70-
remove(file_name.c_str());
74+
if (remove(file_name.c_str())) {
75+
LOG_WARNING << "Error removing file: " << file_name << std::endl;
76+
}
7177
}
7278

7379
std::stringstream GetOutput() {

conformance_tests/core/test_device/src/test_device.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -931,8 +931,8 @@ void RunGivenExecutedKernelWhenGettingGlobalTimestampsTest(bool is_immediate) {
931931
auto device_time_0 = std::get<1>(timestamps);
932932
auto device_time_1 = std::get<1>(timestamps_1);
933933
auto device_properties = lzt::get_device_properties(device);
934-
uint64_t timestamp_max_val =
935-
~(-1 << device_properties.kernelTimestampValidBits);
934+
uint64_t timestamp_max_val = ~(static_cast<uint64_t>(-1)
935+
<< device_properties.kernelTimestampValidBits);
936936
uint64_t timestamp_freq = device_properties.timerResolution;
937937

938938
auto device_diff_ns =

conformance_tests/core/test_module/src/test_module.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ std::vector<ze_module_handle_t> create_module_vector_and_log(
6464
ZE_MODULE_FORMAT_NATIVE, nullptr,
6565
&build_log->at(count)));
6666
count++;
67-
std::remove(filename_native.c_str());
67+
if (std::remove(filename_native.c_str())) {
68+
LOG_WARNING << "FAILED to remove file " << filename_native;
69+
}
6870
}
6971
} else {
7072
for (auto flag : build_flag) {
@@ -511,7 +513,9 @@ TEST_F(
511513
std::ifstream stream(filename_native, std::ios::in | std::ios::binary);
512514
stream.seekg(0, stream.end);
513515
EXPECT_EQ(static_cast<size_t>(stream.tellg()), size);
514-
std::remove(filename_native.c_str());
516+
if (std::remove(filename_native.c_str())) {
517+
LOG_WARNING << "FAILED to remove file " << filename_native;
518+
}
515519
lzt::destroy_module(module);
516520
stream.close();
517521
}

conformance_tests/sysman/test_sysman_device/src/test_sysman_device.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ TEST_F(
170170
(ZE_DEVICE_PROPERTY_FLAG_INTEGRATED |
171171
ZE_DEVICE_PROPERTY_FLAG_SUBDEVICE | ZE_DEVICE_PROPERTY_FLAG_ECC |
172172
ZE_DEVICE_PROPERTY_FLAG_ONDEMANDPAGING)) &&
173-
(properties_initial.core.flags <=
173+
(properties_later.core.flags <=
174174
(ZE_DEVICE_PROPERTY_FLAG_INTEGRATED |
175175
ZE_DEVICE_PROPERTY_FLAG_SUBDEVICE | ZE_DEVICE_PROPERTY_FLAG_ECC |
176176
ZE_DEVICE_PROPERTY_FLAG_ONDEMANDPAGING))) {

conformance_tests/sysman/test_sysman_device/src/test_sysman_device_helper.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ void get_ze_root_uuids(std::vector<ze_device_handle_t> ze_devices,
5454
int main(int argc, char **argv) {
5555

5656
char *device_hierarchy = getenv("ZE_FLAT_DEVICE_HIERARCHY");
57-
LOG_INFO << "Device Hierarchy : " << device_hierarchy;
5857
EXPECT_NE(device_hierarchy, nullptr);
58+
LOG_INFO << "Device Hierarchy : " << device_hierarchy ? device_hierarchy
59+
: "NULL";
5960

6061
auto driver = lzt::zeDevice::get_instance()->get_driver();
6162
std::vector<ze_device_handle_t> ze_devices = lzt::get_ze_devices(driver);

conformance_tests/sysman/test_sysman_device/src/test_sysman_device_hierarchy_helper.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ void get_sysman_devices(const std::string set_device_hierarchy,
2727
putenv(sys_env);
2828
char *get_device_hierarchy = getenv("ZE_FLAT_DEVICE_HIERARCHY");
2929
EXPECT_NE(get_device_hierarchy, nullptr);
30-
LOG_INFO << "Child Process : Device Hierarchy = " << get_device_hierarchy;
30+
LOG_INFO << "Child Process : Device Hierarchy = " << get_device_hierarchy
31+
? get_device_hierarchy
32+
: "NULL";
3133
devices = GET_DEVICE_FN();
3234
}
3335

perf_tests/cl_image_copy/src/cl_image_copy.cpp

Lines changed: 103 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -335,9 +335,16 @@ void measure_bandwidth_Host2Device2Host(ClImageCopy &Imagecopy,
335335
std::stringstream Image_dimensions;
336336
Image_dimensions << Imagecopy.width << "X" << Imagecopy.height << "X"
337337
<< Imagecopy.depth;
338-
test_ptree->put(
339-
"Name", "Host2Device2Host: Bandwidth copying from Host->Device->Host ");
340-
test_ptree->put("Image size", Image_dimensions.str());
338+
try {
339+
test_ptree->put(
340+
"Name",
341+
"Host2Device2Host: Bandwidth copying from Host->Device->Host ");
342+
test_ptree->put("Image size", Image_dimensions.str());
343+
} catch (const std::exception &e) {
344+
std::cerr
345+
<< "Error outputting bandwidth host to device to host measurement: "
346+
<< e.what() << std::endl;
347+
}
341348
} else {
342349
std::cout << "Host2Device2Host: Measuring Bandwidth for copying the "
343350
"image buffer size "
@@ -348,9 +355,15 @@ void measure_bandwidth_Host2Device2Host(ClImageCopy &Imagecopy,
348355
Imagecopy.measureHost2Device2Host();
349356

350357
if (Imagecopy.is_json_output_enabled()) {
351-
test_ptree->put("GBPS", Imagecopy.gbps);
352-
if (Imagecopy.data_validation)
353-
test_ptree->put("Result", (Imagecopy.validRet ? "PASSED" : "FAILED"));
358+
try {
359+
test_ptree->put("GBPS", Imagecopy.gbps);
360+
if (Imagecopy.data_validation)
361+
test_ptree->put("Result", (Imagecopy.validRet ? "PASSED" : "FAILED"));
362+
} catch (const std::exception &e) {
363+
std::cerr
364+
<< "Error outputting bandwidth host to device to host measurement: "
365+
<< e.what() << std::endl;
366+
}
354367
} else {
355368
if (Imagecopy.data_validation) {
356369
std::cout << " Results: Data validation "
@@ -365,8 +378,14 @@ void measure_bandwidth_Host2Device(ClImageCopy &Imagecopy, ptree *test_ptree) {
365378
std::stringstream Image_dimensions;
366379
Image_dimensions << Imagecopy.width << "X" << Imagecopy.height << "X"
367380
<< Imagecopy.depth;
368-
test_ptree->put("Name", "Host2Device: Bandwidth copying from Host->Device");
369-
test_ptree->put("Image size", Image_dimensions.str());
381+
try {
382+
test_ptree->put("Name",
383+
"Host2Device: Bandwidth copying from Host->Device");
384+
test_ptree->put("Image size", Image_dimensions.str());
385+
} catch (const std::exception &e) {
386+
std::cerr << "Error outputting bandwidth measurement:" << e.what()
387+
<< std::endl;
388+
}
370389
} else {
371390
std::cout
372391
<< "Host2Device: Measuring Bandwidth/Latency for copying the image "
@@ -378,9 +397,14 @@ void measure_bandwidth_Host2Device(ClImageCopy &Imagecopy, ptree *test_ptree) {
378397
Imagecopy.measureParallelHost2Device();
379398

380399
if (Imagecopy.is_json_output_enabled()) {
381-
test_ptree->put("GBPS", Imagecopy.gbps);
382-
if (Imagecopy.data_validation) {
383-
test_ptree->put("Result", (Imagecopy.validRet ? "PASSED" : "FAILED"));
400+
try {
401+
test_ptree->put("GBPS", Imagecopy.gbps);
402+
if (Imagecopy.data_validation) {
403+
test_ptree->put("Result", (Imagecopy.validRet ? "PASSED" : "FAILED"));
404+
}
405+
} catch (const std::exception &e) {
406+
std::cerr << "Error outputting bandwidth measurement:" << e.what()
407+
<< std::endl;
384408
}
385409
} else {
386410
if (Imagecopy.data_validation) {
@@ -396,8 +420,14 @@ void measure_bandwidth_Device2Host(ClImageCopy &Imagecopy, ptree *test_ptree) {
396420
std::stringstream Image_dimensions;
397421
Image_dimensions << Imagecopy.width << "X" << Imagecopy.height << "X"
398422
<< Imagecopy.depth;
399-
test_ptree->put("Name", "Device2Host: Bandwidth copying from Device->Host");
400-
test_ptree->put("Image size", Image_dimensions.str());
423+
try {
424+
test_ptree->put("Name",
425+
"Device2Host: Bandwidth copying from Device->Host");
426+
test_ptree->put("Image size", Image_dimensions.str());
427+
} catch (const std::exception &e) {
428+
std::cerr << "Error outputting bandwidth measurement:" << e.what()
429+
<< std::endl;
430+
}
401431
} else {
402432
std::cout
403433
<< "Device2Host: Measurign Bandwidth/Latency for copying the image "
@@ -409,9 +439,14 @@ void measure_bandwidth_Device2Host(ClImageCopy &Imagecopy, ptree *test_ptree) {
409439
Imagecopy.measureParallelDevice2Host();
410440

411441
if (Imagecopy.is_json_output_enabled()) {
412-
test_ptree->put("GBPS", Imagecopy.gbps);
413-
if (Imagecopy.data_validation)
414-
test_ptree->put("Result", (Imagecopy.validRet ? "PASSED" : "FAILED"));
442+
try {
443+
test_ptree->put("GBPS", Imagecopy.gbps);
444+
if (Imagecopy.data_validation)
445+
test_ptree->put("Result", (Imagecopy.validRet ? "PASSED" : "FAILED"));
446+
} catch (const std::exception &e) {
447+
std::cerr << "Error outputting bandwidth measurement:" << e.what()
448+
<< std::endl;
449+
}
415450
} else {
416451
if (Imagecopy.data_validation) {
417452
std::cout << " Results: Data validation "
@@ -435,9 +470,14 @@ void measure_bandwidth(ClImageCopy &Imagecopy) {
435470
Imagecopy.param_array.push_back(std::make_pair("", ptree_Host2Device2Host));
436471
Imagecopy.param_array.push_back(std::make_pair("", ptree_Host2Device));
437472
Imagecopy.param_array.push_back(std::make_pair("", ptree_Device2Host));
438-
ptree_main.put_child("Performance Benchmark.bandwidth",
439-
Imagecopy.param_array);
440-
pt::write_json(Imagecopy.JsonFileName.c_str(), ptree_main);
473+
try {
474+
ptree_main.put_child("Performance Benchmark.bandwidth",
475+
Imagecopy.param_array);
476+
pt::write_json(Imagecopy.JsonFileName.c_str(), ptree_main);
477+
} catch (const std::exception &e) {
478+
std::cerr << "Error outputting bandwidth measurement:" << e.what()
479+
<< std::endl;
480+
}
441481
}
442482
}
443483

@@ -447,14 +487,19 @@ void measure_latency_Host2Device(ClImageCopyLatency &imageCopyLatency,
447487
std::stringstream Image_dimensions;
448488
Image_dimensions << imageCopyLatency.width << "X" << imageCopyLatency.height
449489
<< "X" << imageCopyLatency.depth;
450-
test_ptree->put("Name",
451-
"Host2Device: Measuring Latency for copying the image ");
452-
test_ptree->put("Image size", Image_dimensions.str());
453-
test_ptree->put("Image type", level_zero_tests::to_string(
454-
(cl_uint)imageCopyLatency.clImagetype));
455-
test_ptree->put("Image Channel order",
456-
level_zero_tests::to_string(
457-
(cl_uint)imageCopyLatency.clImageChannelOrder));
490+
try {
491+
test_ptree->put("Name",
492+
"Host2Device: Measuring Latency for copying the image ");
493+
test_ptree->put("Image size", Image_dimensions.str());
494+
test_ptree->put("Image type", level_zero_tests::to_string(
495+
(cl_uint)imageCopyLatency.clImagetype));
496+
test_ptree->put("Image Channel order",
497+
level_zero_tests::to_string(
498+
(cl_uint)imageCopyLatency.clImageChannelOrder));
499+
} catch (const std::exception &e) {
500+
std::cerr << "Error outputting latency host to device measurement:"
501+
<< e.what() << std::endl;
502+
}
458503
} else {
459504
std::cout
460505
<< "Host2Device: Measuring Bandwidth/Latency for copying the image "
@@ -471,10 +516,15 @@ void measure_latency_Host2Device(ClImageCopyLatency &imageCopyLatency,
471516
imageCopyLatency.measureParallelHost2Device();
472517

473518
if (imageCopyLatency.is_json_output_enabled()) {
474-
test_ptree->put("Latency", imageCopyLatency.latency);
475-
if (imageCopyLatency.data_validation)
476-
test_ptree->put("Result",
477-
(imageCopyLatency.validRet ? "PASSED" : "FAILED"));
519+
try {
520+
test_ptree->put("Latency", imageCopyLatency.latency);
521+
if (imageCopyLatency.data_validation)
522+
test_ptree->put("Result",
523+
(imageCopyLatency.validRet ? "PASSED" : "FAILED"));
524+
} catch (const std::exception &e) {
525+
std::cerr << "Error outputting parallel host to device measurement:"
526+
<< e.what() << std::endl;
527+
}
478528
}
479529
}
480530

@@ -484,14 +534,19 @@ void measure_latency_Device2Host(ClImageCopyLatency &imageCopyLatency,
484534
std::stringstream Image_dimensions;
485535
Image_dimensions << imageCopyLatency.width << "X" << imageCopyLatency.height
486536
<< "X" << imageCopyLatency.depth;
487-
test_ptree->put("Name",
488-
"Device2Host: Measuring Latency for copying the image");
489-
test_ptree->put("Image size", Image_dimensions.str());
490-
test_ptree->put("Image type", level_zero_tests::to_string(
491-
(cl_uint)imageCopyLatency.clImagetype));
492-
test_ptree->put("Image Channel order",
493-
level_zero_tests::to_string(
494-
(cl_uint)imageCopyLatency.clImageChannelOrder));
537+
try {
538+
test_ptree->put("Name",
539+
"Device2Host: Measuring Latency for copying the image");
540+
test_ptree->put("Image size", Image_dimensions.str());
541+
test_ptree->put("Image type", level_zero_tests::to_string(
542+
(cl_uint)imageCopyLatency.clImagetype));
543+
test_ptree->put("Image Channel order",
544+
level_zero_tests::to_string(
545+
(cl_uint)imageCopyLatency.clImageChannelOrder));
546+
} catch (const std::exception &e) {
547+
std::cerr << "Error outputting latency device to host measurement:"
548+
<< e.what() << std::endl;
549+
}
495550
} else {
496551
std::cout
497552
<< "Device2Host: Measuring Bandwidth/Latency for copying the image "
@@ -508,10 +563,15 @@ void measure_latency_Device2Host(ClImageCopyLatency &imageCopyLatency,
508563
imageCopyLatency.measureParallelDevice2Host();
509564

510565
if (imageCopyLatency.is_json_output_enabled()) {
511-
test_ptree->put("Latency", imageCopyLatency.latency);
512-
if (imageCopyLatency.data_validation)
513-
test_ptree->put("Result",
514-
(imageCopyLatency.validRet ? "PASSED" : "FAILED"));
566+
try {
567+
test_ptree->put("Latency", imageCopyLatency.latency);
568+
if (imageCopyLatency.data_validation)
569+
test_ptree->put("Result",
570+
(imageCopyLatency.validRet ? "PASSED" : "FAILED"));
571+
} catch (const std::exception &e) {
572+
std::cerr << "Error outputting parallel device to host measurement:"
573+
<< e.what() << std::endl;
574+
}
515575
}
516576
}
517577

0 commit comments

Comments
 (0)