From d05d68f031128277dcb574641666655d932aa5ed Mon Sep 17 00:00:00 2001 From: Narendra Bagria Date: Fri, 8 Nov 2024 14:59:37 +0530 Subject: [PATCH] fix: update metric query tests (#101) Resolves: VLCLJ-2321 Signed-off-by: Bagria, Narendra --- .../tools/metrics/src/test_metric.cpp | 31 ++++++++++++------- .../tools/include/test_harness_metric.hpp | 7 +++-- .../tools/src/test_harness_metric.cpp | 16 +++++++--- 3 files changed, 36 insertions(+), 18 deletions(-) diff --git a/conformance_tests/tools/metrics/src/test_metric.cpp b/conformance_tests/tools/metrics/src/test_metric.cpp index fe924dd6..5e9887d2 100644 --- a/conformance_tests/tools/metrics/src/test_metric.cpp +++ b/conformance_tests/tools/metrics/src/test_metric.cpp @@ -1,6 +1,6 @@ /* * - * Copyright (C) 2020-2022 Intel Corporation + * Copyright (C) 2020-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -432,30 +432,35 @@ TEST_F( class zetMetricQueryTest : public zetMetricGroupTest { protected: - zet_metric_query_pool_handle_t metricQueryPoolHandle; - zet_metric_query_handle_t metricQueryHandle; + zet_metric_query_pool_handle_t metricQueryPoolHandle{}; + zet_metric_query_handle_t metricQueryHandle{}; std::vector groupNameList; - zet_metric_group_handle_t matchedGroupHandle; + zet_metric_group_handle_t matchedGroupHandle{}; std::string groupName; - zetMetricQueryTest() { - + void SetUp() override { groupNameList = lzt::get_metric_group_name_list( device, ZET_METRIC_GROUP_SAMPLING_TYPE_FLAG_EVENT_BASED, false); + ASSERT_GT(groupNameList.size(), 0u) << "No query metric groups found"; groupName = groupNameList[0]; matchedGroupHandle = lzt::find_metric_group( device, groupName, ZET_METRIC_GROUP_SAMPLING_TYPE_FLAG_EVENT_BASED); - EXPECT_NE(nullptr, matchedGroupHandle); + ASSERT_NE(nullptr, matchedGroupHandle); metricQueryPoolHandle = lzt::create_metric_query_pool( 1000, ZET_METRIC_QUERY_POOL_TYPE_PERFORMANCE, matchedGroupHandle); - EXPECT_NE(nullptr, metricQueryPoolHandle); + ASSERT_NE(nullptr, metricQueryPoolHandle); metricQueryHandle = lzt::metric_query_create(metricQueryPoolHandle); } + void TearDown() override { - lzt::destroy_metric_query(metricQueryHandle); - lzt::destroy_metric_query_pool(metricQueryPoolHandle); + if (metricQueryHandle != nullptr) { + lzt::destroy_metric_query(metricQueryHandle); + } + if (metricQueryPoolHandle != nullptr) { + lzt::destroy_metric_query_pool(metricQueryPoolHandle); + } } }; @@ -473,7 +478,6 @@ TEST_F(zetMetricQueryTest, TEST_F( zetMetricQueryTest, GivenOnlyMetricQueryWhenCommandListIsCreatedThenExpectCommandListToExecuteSucessfully) { - zet_command_list_handle_t commandList = lzt::create_command_list(); lzt::activate_metric_groups(device, 1, &matchedGroupHandle); lzt::append_metric_query_begin(commandList, metricQueryHandle); @@ -535,6 +539,7 @@ TEST_F( auto metricGroupInfo = lzt::get_metric_group_info( device, ZET_METRIC_GROUP_SAMPLING_TYPE_FLAG_EVENT_BASED, false); + ASSERT_GT(metricGroupInfo.size(), 0u) << "No query metric groups found"; metricGroupInfo = lzt::optimize_metric_group_info_list(metricGroupInfo); for (auto groupInfo : metricGroupInfo) { @@ -629,6 +634,7 @@ void run_test(const ze_device_handle_t &device, } auto metricGroupInfo = lzt::get_metric_group_info( device, ZET_METRIC_GROUP_SAMPLING_TYPE_FLAG_EVENT_BASED, false); + ASSERT_GT(metricGroupInfo.size(), 0u) << "No query metric groups found"; metricGroupInfo = lzt::optimize_metric_group_info_list(metricGroupInfo, reset ? 1 : 20); @@ -802,8 +808,10 @@ void run_multi_device_query_load_test( auto metric_group_info_0 = lzt::get_metric_group_info( device_0, ZET_METRIC_GROUP_SAMPLING_TYPE_FLAG_EVENT_BASED, true); + ASSERT_GT(metric_group_info_0.size(), 0u) << "No query metric groups found"; auto metric_group_info_1 = lzt::get_metric_group_info( device_1, ZET_METRIC_GROUP_SAMPLING_TYPE_FLAG_EVENT_BASED, true); + ASSERT_GT(metric_group_info_1.size(), 0u) << "No query metric groups found"; metric_group_info_0 = lzt::optimize_metric_group_info_list(metric_group_info_0); @@ -970,6 +978,7 @@ TEST_F( auto metricGroupInfo = lzt::get_metric_group_info( device, ZET_METRIC_GROUP_SAMPLING_TYPE_FLAG_EVENT_BASED, false); + ASSERT_GT(metricGroupInfo.size(), 0u) << "No query metric groups found"; metricGroupInfo = lzt::optimize_metric_group_info_list(metricGroupInfo, 1); for (auto groupInfo : metricGroupInfo) { diff --git a/utils/test_harness/tools/include/test_harness_metric.hpp b/utils/test_harness/tools/include/test_harness_metric.hpp index 25ce77e5..45d2d41c 100644 --- a/utils/test_harness/tools/include/test_harness_metric.hpp +++ b/utils/test_harness/tools/include/test_harness_metric.hpp @@ -1,6 +1,6 @@ /* * - * Copyright (C) 2019 Intel Corporation + * Copyright (C) 2019-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -103,8 +103,9 @@ size_t metric_streamer_read_data_size( void metric_streamer_read_data( zet_metric_streamer_handle_t metricStreamerHandle, std::vector *metricData); -void activate_metric_groups(ze_device_handle_t device, uint32_t count, - zet_metric_group_handle_t *matchedGroupHandle); +void activate_metric_groups( + ze_device_handle_t device, uint32_t count, + zet_metric_group_handle_t *ptr_matched_group_handle); void deactivate_metric_groups(ze_device_handle_t device); void append_metric_query_begin(zet_command_list_handle_t commandList, zet_metric_query_handle_t metricQueryHandle); diff --git a/utils/test_harness/tools/src/test_harness_metric.cpp b/utils/test_harness/tools/src/test_harness_metric.cpp index ad5ff3f4..33789613 100644 --- a/utils/test_harness/tools/src/test_harness_metric.cpp +++ b/utils/test_harness/tools/src/test_harness_metric.cpp @@ -1,6 +1,6 @@ /* * - * Copyright (C) 2019 Intel Corporation + * Copyright (C) 2019-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -468,10 +468,12 @@ metric_query_create(zet_metric_query_pool_handle_t metricQueryPoolHandle) { } void destroy_metric_query(zet_metric_query_handle_t metricQueryHandle) { + ASSERT_NE(nullptr, metricQueryHandle); EXPECT_EQ(ZE_RESULT_SUCCESS, zetMetricQueryDestroy(metricQueryHandle)); } void reset_metric_query(zet_metric_query_handle_t &metricQueryHandle) { + ASSERT_NE(nullptr, metricQueryHandle); EXPECT_EQ(ZE_RESULT_SUCCESS, zetMetricQueryReset(metricQueryHandle)); } @@ -579,12 +581,15 @@ void metric_streamer_read_data( rawDataSize = metricSize; } -void activate_metric_groups(ze_device_handle_t device, uint32_t count, - zet_metric_group_handle_t *matchedGroupHandle) { +void activate_metric_groups( + ze_device_handle_t device, uint32_t count, + zet_metric_group_handle_t *ptr_matched_group_handle) { + ASSERT_NE(nullptr, *ptr_matched_group_handle); EXPECT_EQ(ZE_RESULT_SUCCESS, zetContextActivateMetricGroups(lzt::get_default_context(), device, - count, matchedGroupHandle)); + count, ptr_matched_group_handle)); } + void deactivate_metric_groups(ze_device_handle_t device) { EXPECT_EQ(ZE_RESULT_SUCCESS, zetContextActivateMetricGroups(lzt::get_default_context(), device, @@ -593,6 +598,7 @@ void deactivate_metric_groups(ze_device_handle_t device) { void append_metric_query_begin(zet_command_list_handle_t commandList, zet_metric_query_handle_t metricQueryHandle) { + ASSERT_NE(nullptr, metricQueryHandle); EXPECT_EQ(ZE_RESULT_SUCCESS, zetCommandListAppendMetricQueryBegin( commandList, metricQueryHandle)); } @@ -600,6 +606,7 @@ void append_metric_query_begin(zet_command_list_handle_t commandList, void append_metric_query_end(zet_command_list_handle_t commandList, zet_metric_query_handle_t metricQueryHandle, ze_event_handle_t eventHandle) { + ASSERT_NE(nullptr, metricQueryHandle); append_metric_query_end(commandList, metricQueryHandle, eventHandle, 0, nullptr); } @@ -609,6 +616,7 @@ void append_metric_query_end(zet_command_list_handle_t commandList, ze_event_handle_t eventHandle, uint32_t numWaitEvents, ze_event_handle_t *waitEvents) { + ASSERT_NE(nullptr, metricQueryHandle); EXPECT_EQ(ZE_RESULT_SUCCESS, zetCommandListAppendMetricQueryEnd( commandList, metricQueryHandle, eventHandle, numWaitEvents, waitEvents));