Skip to content

Commit 3b034bd

Browse files
authored
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 <[email protected]>
1 parent fc7a490 commit 3b034bd

File tree

9 files changed

+40
-26
lines changed

9 files changed

+40
-26
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ 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)
45+
4446
set(CMAKE_CXX_STANDARD 14)
4547

4648
set(Boost_USE_STATIC_LIBS ON)

conformance_tests/core/test_copy/src/test_kernel_copy.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ class KernelCopyTestsWithIndirectMemoryTypes
563563
EXPECT_EQ(0, memcmp(input_data[i].data, output_data[i].data + offset,
564564
(size - offset) * sizeof(uint32_t)));
565565
// break to cleanup
566-
if (::testing::Test::HasFailure) {
566+
if (::testing::Test::HasFailure()) {
567567
break;
568568
}
569569
}

conformance_tests/core/test_module/src/test_kernel_args.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ void KernelArgumentTests::set_image_pixel(ze_image_handle_t image, int x, int y,
8787
uint32_t val, bool is_immediate) {
8888

8989
auto cmd_bundle = lzt::create_command_bundle(is_immediate);
90-
lzt::ImagePNG32Bit temp_png(img_height, img_width);
90+
lzt::ImagePNG32Bit temp_png(img_width, img_height);
9191
temp_png.set_pixel(x, y, val);
9292
lzt::append_image_copy_from_mem(cmd_bundle.list, image, temp_png.raw_data(),
9393
nullptr);
@@ -102,7 +102,7 @@ uint32_t KernelArgumentTests::get_image_pixel(ze_image_handle_t image, int x,
102102
int y, bool is_immediate) {
103103

104104
auto cmd_bundle = lzt::create_command_bundle(is_immediate);
105-
lzt::ImagePNG32Bit temp_png(img_height, img_width);
105+
lzt::ImagePNG32Bit temp_png(img_width, img_height);
106106
lzt::append_image_copy_to_mem(cmd_bundle.list, temp_png.raw_data(), image,
107107
nullptr);
108108
lzt::close_command_list(cmd_bundle.list);

conformance_tests/sysman/test_sysman_device/src/test_sysman_device.cpp

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,10 @@ TEST_F(
135135

136136
EXPECT_GE(ZE_DEVICE_TYPE_GPU, properties.core.type);
137137
EXPECT_LE(properties.core.type, ZE_DEVICE_TYPE_MCA);
138-
if (properties.core.flags <= ZE_DEVICE_PROPERTY_FLAG_INTEGRATED |
139-
ZE_DEVICE_PROPERTY_FLAG_SUBDEVICE | ZE_DEVICE_PROPERTY_FLAG_ECC |
140-
ZE_DEVICE_PROPERTY_FLAG_ONDEMANDPAGING) {
138+
if (properties.core.flags <=
139+
(ZE_DEVICE_PROPERTY_FLAG_INTEGRATED |
140+
ZE_DEVICE_PROPERTY_FLAG_SUBDEVICE | ZE_DEVICE_PROPERTY_FLAG_ECC |
141+
ZE_DEVICE_PROPERTY_FLAG_ONDEMANDPAGING)) {
141142
if (properties.core.flags & ZE_DEVICE_PROPERTY_FLAG_SUBDEVICE) {
142143
EXPECT_LT(properties.core.subdeviceId, UINT32_MAX);
143144
} else {
@@ -165,12 +166,14 @@ TEST_F(
165166
auto properties_initial = lzt::get_sysman_device_properties(device);
166167
auto properties_later = lzt::get_sysman_device_properties(device);
167168
EXPECT_EQ(properties_initial.core.type, properties_later.core.type);
168-
if (properties_initial.core.flags <= ZE_DEVICE_PROPERTY_FLAG_INTEGRATED |
169-
ZE_DEVICE_PROPERTY_FLAG_SUBDEVICE | ZE_DEVICE_PROPERTY_FLAG_ECC |
170-
ZE_DEVICE_PROPERTY_FLAG_ONDEMANDPAGING &&
171-
properties_initial.core.flags <= ZE_DEVICE_PROPERTY_FLAG_INTEGRATED |
172-
ZE_DEVICE_PROPERTY_FLAG_SUBDEVICE | ZE_DEVICE_PROPERTY_FLAG_ECC |
173-
ZE_DEVICE_PROPERTY_FLAG_ONDEMANDPAGING) {
169+
if ((properties_initial.core.flags <=
170+
(ZE_DEVICE_PROPERTY_FLAG_INTEGRATED |
171+
ZE_DEVICE_PROPERTY_FLAG_SUBDEVICE | ZE_DEVICE_PROPERTY_FLAG_ECC |
172+
ZE_DEVICE_PROPERTY_FLAG_ONDEMANDPAGING)) &&
173+
(properties_initial.core.flags <=
174+
(ZE_DEVICE_PROPERTY_FLAG_INTEGRATED |
175+
ZE_DEVICE_PROPERTY_FLAG_SUBDEVICE | ZE_DEVICE_PROPERTY_FLAG_ECC |
176+
ZE_DEVICE_PROPERTY_FLAG_ONDEMANDPAGING))) {
174177
EXPECT_EQ(properties_initial.core.flags, properties_later.core.flags);
175178
if (properties_initial.core.flags & ZE_DEVICE_PROPERTY_FLAG_SUBDEVICE &&
176179
properties_later.core.flags & ZE_DEVICE_PROPERTY_FLAG_SUBDEVICE) {
@@ -607,7 +610,11 @@ TEST_F(
607610
const char *valueString = std::getenv("LZT_SYSMAN_DEVICE_TEST_ITERATIONS");
608611
uint32_t number_iterations = 2;
609612
if (valueString != nullptr) {
610-
number_iterations = atoi(valueString);
613+
auto _value = atoi(valueString);
614+
number_iterations = _value < 0 ? number_iterations : std::min(_value, 300);
615+
if (number_iterations != _value) {
616+
LOG_WARNING << "Number of iterations is capped at 300\n";
617+
}
611618
}
612619

613620
for (auto device : devices) {

layer_tests/tracing/src/test_api_ltracing.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1975,7 +1975,7 @@ TEST_F(
19751975
ze_result_t result =
19761976
zeSamplerCreate(context, device, &sampler_desc, &sampler);
19771977
if ((result == ZE_RESULT_ERROR_UNSUPPORTED_FEATURE) ||
1978-
(result = ZE_RESULT_ERROR_UNINITIALIZED)) {
1978+
(result == ZE_RESULT_ERROR_UNINITIALIZED)) {
19791979
LOG_WARNING << "test not executed because "
19801980
"sampler is not supported";
19811981
user_data.prologue_called = true;

perf_tests/ze_peak/src/ze_peak.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,11 @@ void L0Context::init_xe(uint32_t specified_driver, uint32_t specified_device,
307307
sub_devices.resize(sub_device_count);
308308
result = zeDeviceGetSubDevices(device, &sub_device_count,
309309
sub_devices.data());
310-
if (verbose)
310+
if (ZE_RESULT_SUCCESS != result) {
311+
std::cout << "zeDeviceGetSubDevices failed: "
312+
<< std::to_string(result) << "\n";
313+
sub_device_count = 0;
314+
} else if (verbose)
311315
std::cout << "Sub Device Handles retrieved\n";
312316
} else {
313317
sub_device_count = 0;

perf_tests/ze_peer/include/ze_peer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,8 @@ class ZePeer {
274274

275275
std::vector<uint32_t> queues{};
276276

277-
char *ze_host_buffer;
278-
char *ze_host_validate_buffer;
277+
char *ze_host_buffer = nullptr;
278+
char *ze_host_validate_buffer = nullptr;
279279

280280
std::vector<ze_peer_device_t> ze_peer_devices;
281281
ze_ipc_mem_handle_t pIpcHandle = {};

perf_tests/ze_peer/src/ze_peer.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,8 @@ int main(int argc, char **argv) {
442442
i++;
443443
} else if (strcmp(argv[i], "-z") == 0) {
444444
if (isdigit(argv[i + 1][0])) {
445-
size_to_run = atoi(argv[i + 1]);
445+
size_to_run = std::min(atoi(argv[i + 1]),
446+
static_cast<int>(max_number_of_elements));
446447
} else {
447448
std::cout << usage_str;
448449
exit(-1);

utils/test_harness/sysman/src/test_harness_sysman_frequency.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,14 @@ bool check_for_throttling(zes_freq_handle_t pFreqHandle) {
149149
int wait = 0;
150150
do {
151151
zes_freq_state_t state = get_freq_state(pFreqHandle);
152-
if (state.throttleReasons >= ZES_FREQ_THROTTLE_REASON_FLAG_AVE_PWR_CAP &&
153-
state.throttleReasons <= ZES_FREQ_THROTTLE_REASON_FLAG_HW_RANGE |
154-
ZES_FREQ_THROTTLE_REASON_FLAG_SW_RANGE |
155-
ZES_FREQ_THROTTLE_REASON_FLAG_PSU_ALERT |
156-
ZES_FREQ_THROTTLE_REASON_FLAG_THERMAL_LIMIT |
157-
ZES_FREQ_THROTTLE_REASON_FLAG_CURRENT_LIMIT |
158-
ZES_FREQ_THROTTLE_REASON_FLAG_BURST_PWR_CAP |
159-
ZES_FREQ_THROTTLE_REASON_FLAG_AVE_PWR_CAP)
152+
if ((state.throttleReasons >= ZES_FREQ_THROTTLE_REASON_FLAG_AVE_PWR_CAP) &&
153+
(state.throttleReasons <= (ZES_FREQ_THROTTLE_REASON_FLAG_HW_RANGE |
154+
ZES_FREQ_THROTTLE_REASON_FLAG_SW_RANGE |
155+
ZES_FREQ_THROTTLE_REASON_FLAG_PSU_ALERT |
156+
ZES_FREQ_THROTTLE_REASON_FLAG_THERMAL_LIMIT |
157+
ZES_FREQ_THROTTLE_REASON_FLAG_CURRENT_LIMIT |
158+
ZES_FREQ_THROTTLE_REASON_FLAG_BURST_PWR_CAP |
159+
ZES_FREQ_THROTTLE_REASON_FLAG_AVE_PWR_CAP)))
160160
return true;
161161
std::this_thread::sleep_for(std::chrono::microseconds(1000 * 10));
162162
wait += 10;

0 commit comments

Comments
 (0)