Skip to content

Commit

Permalink
Fix various static analysis identified issues (#51)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
Jemale authored Jul 11, 2024
1 parent fc7a490 commit 3b034bd
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 26 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion conformance_tests/core/test_copy/src/test_kernel_copy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
4 changes: 2 additions & 2 deletions conformance_tests/core/test_module/src/test_kernel_args.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion layer_tests/tracing/src/test_api_ltracing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 5 additions & 1 deletion perf_tests/ze_peak/src/ze_peak.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions perf_tests/ze_peer/include/ze_peer.h
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,8 @@ class ZePeer {

std::vector<uint32_t> 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_device_t> ze_peer_devices;
ze_ipc_mem_handle_t pIpcHandle = {};
Expand Down
3 changes: 2 additions & 1 deletion perf_tests/ze_peer/src/ze_peer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(max_number_of_elements));
} else {
std::cout << usage_str;
exit(-1);
Expand Down
16 changes: 8 additions & 8 deletions utils/test_harness/sysman/src/test_harness_sysman_frequency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 3b034bd

Please sign in to comment.