From 3b034bd90ce04d4b1de31ac2c41955b025c8d414 Mon Sep 17 00:00:00 2001 From: Jemale Lockett Date: Thu, 11 Jul 2024 18:02:12 -0400 Subject: [PATCH] Fix various static analysis identified issues (#51) * Set GTEST_HAS_EXCEPTIONS to 0 * Add initialization of buffers in ze_peer * Correct argument order * Reset ze_peak subdevice count on failure to get * Fix test_sysman_device typos * Fix test_harness_sysman_frequency expression * Sanitize ze_peer input data --------- Signed-off-by: Jemale Lockett --- CMakeLists.txt | 2 ++ .../core/test_copy/src/test_kernel_copy.cpp | 2 +- .../core/test_module/src/test_kernel_args.cpp | 4 +-- .../src/test_sysman_device.cpp | 27 ++++++++++++------- layer_tests/tracing/src/test_api_ltracing.cpp | 2 +- perf_tests/ze_peak/src/ze_peak.cpp | 6 ++++- perf_tests/ze_peer/include/ze_peer.h | 4 +-- perf_tests/ze_peer/src/ze_peer.cpp | 3 ++- .../src/test_harness_sysman_frequency.cpp | 16 +++++------ 9 files changed, 40 insertions(+), 26 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a5596680..a3183d28 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,6 +41,8 @@ if(NOT TARGET GTest::GTest AND NOT TARGET GMock::GMock AND NOT BUILD_ZE_PERF_TES endif() enable_testing() +set(GTEST_HAS_EXCEPTIONS 0) + set(CMAKE_CXX_STANDARD 14) set(Boost_USE_STATIC_LIBS ON) diff --git a/conformance_tests/core/test_copy/src/test_kernel_copy.cpp b/conformance_tests/core/test_copy/src/test_kernel_copy.cpp index 553307c2..828c1e2f 100644 --- a/conformance_tests/core/test_copy/src/test_kernel_copy.cpp +++ b/conformance_tests/core/test_copy/src/test_kernel_copy.cpp @@ -563,7 +563,7 @@ class KernelCopyTestsWithIndirectMemoryTypes EXPECT_EQ(0, memcmp(input_data[i].data, output_data[i].data + offset, (size - offset) * sizeof(uint32_t))); // break to cleanup - if (::testing::Test::HasFailure) { + if (::testing::Test::HasFailure()) { break; } } diff --git a/conformance_tests/core/test_module/src/test_kernel_args.cpp b/conformance_tests/core/test_module/src/test_kernel_args.cpp index ffc58f83..30e2100a 100644 --- a/conformance_tests/core/test_module/src/test_kernel_args.cpp +++ b/conformance_tests/core/test_module/src/test_kernel_args.cpp @@ -87,7 +87,7 @@ void KernelArgumentTests::set_image_pixel(ze_image_handle_t image, int x, int y, uint32_t val, bool is_immediate) { auto cmd_bundle = lzt::create_command_bundle(is_immediate); - lzt::ImagePNG32Bit temp_png(img_height, img_width); + lzt::ImagePNG32Bit temp_png(img_width, img_height); temp_png.set_pixel(x, y, val); lzt::append_image_copy_from_mem(cmd_bundle.list, image, temp_png.raw_data(), nullptr); @@ -102,7 +102,7 @@ uint32_t KernelArgumentTests::get_image_pixel(ze_image_handle_t image, int x, int y, bool is_immediate) { auto cmd_bundle = lzt::create_command_bundle(is_immediate); - lzt::ImagePNG32Bit temp_png(img_height, img_width); + lzt::ImagePNG32Bit temp_png(img_width, img_height); lzt::append_image_copy_to_mem(cmd_bundle.list, temp_png.raw_data(), image, nullptr); lzt::close_command_list(cmd_bundle.list); diff --git a/conformance_tests/sysman/test_sysman_device/src/test_sysman_device.cpp b/conformance_tests/sysman/test_sysman_device/src/test_sysman_device.cpp index ba5286c5..f4f98bd4 100644 --- a/conformance_tests/sysman/test_sysman_device/src/test_sysman_device.cpp +++ b/conformance_tests/sysman/test_sysman_device/src/test_sysman_device.cpp @@ -135,9 +135,10 @@ TEST_F( EXPECT_GE(ZE_DEVICE_TYPE_GPU, properties.core.type); EXPECT_LE(properties.core.type, ZE_DEVICE_TYPE_MCA); - if (properties.core.flags <= ZE_DEVICE_PROPERTY_FLAG_INTEGRATED | - ZE_DEVICE_PROPERTY_FLAG_SUBDEVICE | ZE_DEVICE_PROPERTY_FLAG_ECC | - ZE_DEVICE_PROPERTY_FLAG_ONDEMANDPAGING) { + if (properties.core.flags <= + (ZE_DEVICE_PROPERTY_FLAG_INTEGRATED | + ZE_DEVICE_PROPERTY_FLAG_SUBDEVICE | ZE_DEVICE_PROPERTY_FLAG_ECC | + ZE_DEVICE_PROPERTY_FLAG_ONDEMANDPAGING)) { if (properties.core.flags & ZE_DEVICE_PROPERTY_FLAG_SUBDEVICE) { EXPECT_LT(properties.core.subdeviceId, UINT32_MAX); } else { @@ -165,12 +166,14 @@ TEST_F( auto properties_initial = lzt::get_sysman_device_properties(device); auto properties_later = lzt::get_sysman_device_properties(device); EXPECT_EQ(properties_initial.core.type, properties_later.core.type); - if (properties_initial.core.flags <= ZE_DEVICE_PROPERTY_FLAG_INTEGRATED | - ZE_DEVICE_PROPERTY_FLAG_SUBDEVICE | ZE_DEVICE_PROPERTY_FLAG_ECC | - ZE_DEVICE_PROPERTY_FLAG_ONDEMANDPAGING && - properties_initial.core.flags <= ZE_DEVICE_PROPERTY_FLAG_INTEGRATED | - ZE_DEVICE_PROPERTY_FLAG_SUBDEVICE | ZE_DEVICE_PROPERTY_FLAG_ECC | - ZE_DEVICE_PROPERTY_FLAG_ONDEMANDPAGING) { + if ((properties_initial.core.flags <= + (ZE_DEVICE_PROPERTY_FLAG_INTEGRATED | + ZE_DEVICE_PROPERTY_FLAG_SUBDEVICE | ZE_DEVICE_PROPERTY_FLAG_ECC | + ZE_DEVICE_PROPERTY_FLAG_ONDEMANDPAGING)) && + (properties_initial.core.flags <= + (ZE_DEVICE_PROPERTY_FLAG_INTEGRATED | + ZE_DEVICE_PROPERTY_FLAG_SUBDEVICE | ZE_DEVICE_PROPERTY_FLAG_ECC | + ZE_DEVICE_PROPERTY_FLAG_ONDEMANDPAGING))) { EXPECT_EQ(properties_initial.core.flags, properties_later.core.flags); if (properties_initial.core.flags & ZE_DEVICE_PROPERTY_FLAG_SUBDEVICE && properties_later.core.flags & ZE_DEVICE_PROPERTY_FLAG_SUBDEVICE) { @@ -607,7 +610,11 @@ TEST_F( const char *valueString = std::getenv("LZT_SYSMAN_DEVICE_TEST_ITERATIONS"); uint32_t number_iterations = 2; if (valueString != nullptr) { - number_iterations = atoi(valueString); + auto _value = atoi(valueString); + number_iterations = _value < 0 ? number_iterations : std::min(_value, 300); + if (number_iterations != _value) { + LOG_WARNING << "Number of iterations is capped at 300\n"; + } } for (auto device : devices) { diff --git a/layer_tests/tracing/src/test_api_ltracing.cpp b/layer_tests/tracing/src/test_api_ltracing.cpp index ab71444b..d5f03581 100644 --- a/layer_tests/tracing/src/test_api_ltracing.cpp +++ b/layer_tests/tracing/src/test_api_ltracing.cpp @@ -1975,7 +1975,7 @@ TEST_F( ze_result_t result = zeSamplerCreate(context, device, &sampler_desc, &sampler); if ((result == ZE_RESULT_ERROR_UNSUPPORTED_FEATURE) || - (result = ZE_RESULT_ERROR_UNINITIALIZED)) { + (result == ZE_RESULT_ERROR_UNINITIALIZED)) { LOG_WARNING << "test not executed because " "sampler is not supported"; user_data.prologue_called = true; diff --git a/perf_tests/ze_peak/src/ze_peak.cpp b/perf_tests/ze_peak/src/ze_peak.cpp index b7e8569c..9645ccad 100644 --- a/perf_tests/ze_peak/src/ze_peak.cpp +++ b/perf_tests/ze_peak/src/ze_peak.cpp @@ -307,7 +307,11 @@ void L0Context::init_xe(uint32_t specified_driver, uint32_t specified_device, sub_devices.resize(sub_device_count); result = zeDeviceGetSubDevices(device, &sub_device_count, sub_devices.data()); - if (verbose) + if (ZE_RESULT_SUCCESS != result) { + std::cout << "zeDeviceGetSubDevices failed: " + << std::to_string(result) << "\n"; + sub_device_count = 0; + } else if (verbose) std::cout << "Sub Device Handles retrieved\n"; } else { sub_device_count = 0; diff --git a/perf_tests/ze_peer/include/ze_peer.h b/perf_tests/ze_peer/include/ze_peer.h index 269abe67..07d0b41e 100644 --- a/perf_tests/ze_peer/include/ze_peer.h +++ b/perf_tests/ze_peer/include/ze_peer.h @@ -274,8 +274,8 @@ class ZePeer { std::vector queues{}; - char *ze_host_buffer; - char *ze_host_validate_buffer; + char *ze_host_buffer = nullptr; + char *ze_host_validate_buffer = nullptr; std::vector ze_peer_devices; ze_ipc_mem_handle_t pIpcHandle = {}; diff --git a/perf_tests/ze_peer/src/ze_peer.cpp b/perf_tests/ze_peer/src/ze_peer.cpp index b0f224ed..75520493 100644 --- a/perf_tests/ze_peer/src/ze_peer.cpp +++ b/perf_tests/ze_peer/src/ze_peer.cpp @@ -442,7 +442,8 @@ int main(int argc, char **argv) { i++; } else if (strcmp(argv[i], "-z") == 0) { if (isdigit(argv[i + 1][0])) { - size_to_run = atoi(argv[i + 1]); + size_to_run = std::min(atoi(argv[i + 1]), + static_cast(max_number_of_elements)); } else { std::cout << usage_str; exit(-1); diff --git a/utils/test_harness/sysman/src/test_harness_sysman_frequency.cpp b/utils/test_harness/sysman/src/test_harness_sysman_frequency.cpp index c90189ed..64b70166 100644 --- a/utils/test_harness/sysman/src/test_harness_sysman_frequency.cpp +++ b/utils/test_harness/sysman/src/test_harness_sysman_frequency.cpp @@ -149,14 +149,14 @@ bool check_for_throttling(zes_freq_handle_t pFreqHandle) { int wait = 0; do { zes_freq_state_t state = get_freq_state(pFreqHandle); - if (state.throttleReasons >= ZES_FREQ_THROTTLE_REASON_FLAG_AVE_PWR_CAP && - state.throttleReasons <= ZES_FREQ_THROTTLE_REASON_FLAG_HW_RANGE | - ZES_FREQ_THROTTLE_REASON_FLAG_SW_RANGE | - ZES_FREQ_THROTTLE_REASON_FLAG_PSU_ALERT | - ZES_FREQ_THROTTLE_REASON_FLAG_THERMAL_LIMIT | - ZES_FREQ_THROTTLE_REASON_FLAG_CURRENT_LIMIT | - ZES_FREQ_THROTTLE_REASON_FLAG_BURST_PWR_CAP | - ZES_FREQ_THROTTLE_REASON_FLAG_AVE_PWR_CAP) + if ((state.throttleReasons >= ZES_FREQ_THROTTLE_REASON_FLAG_AVE_PWR_CAP) && + (state.throttleReasons <= (ZES_FREQ_THROTTLE_REASON_FLAG_HW_RANGE | + ZES_FREQ_THROTTLE_REASON_FLAG_SW_RANGE | + ZES_FREQ_THROTTLE_REASON_FLAG_PSU_ALERT | + ZES_FREQ_THROTTLE_REASON_FLAG_THERMAL_LIMIT | + ZES_FREQ_THROTTLE_REASON_FLAG_CURRENT_LIMIT | + ZES_FREQ_THROTTLE_REASON_FLAG_BURST_PWR_CAP | + ZES_FREQ_THROTTLE_REASON_FLAG_AVE_PWR_CAP))) return true; std::this_thread::sleep_for(std::chrono::microseconds(1000 * 10)); wait += 10;