Skip to content

Commit

Permalink
fix: update metric tests
Browse files Browse the repository at this point in the history
Related to VLCLJ-2321

Signed-off-by: Bagria, Narendra <narendra.bagria@intel.com>
  • Loading branch information
narenbagria committed Oct 30, 2024
1 parent ef3e3c6 commit 79d3833
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 29 deletions.
40 changes: 27 additions & 13 deletions conformance_tests/tools/metrics/src/test_metric.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*
* Copyright (C) 2020-2022 Intel Corporation
* Copyright (C) 2020-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
Expand Down Expand Up @@ -432,17 +432,18 @@ 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<std::string> groupNameList;
zet_metric_group_handle_t matchedGroupHandle;
zet_metric_group_handle_t matchedGroupHandle{};
std::string groupName;

zetMetricQueryTest() {

void zetMetricQueryInitialize() {
groupNameList = lzt::get_metric_group_name_list(
device, ZET_METRIC_GROUP_SAMPLING_TYPE_FLAG_EVENT_BASED, false);
ASSERT_GT(groupNameList.size(), 0u)
<< "metric group name list cannot be empty";
groupName = groupNameList[0];

matchedGroupHandle = lzt::find_metric_group(
Expand All @@ -454,26 +455,32 @@ class zetMetricQueryTest : public zetMetricGroupTest {
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);
}
}
};

TEST_F(
zetMetricQueryTest,
GivenValidMetricQueryPoolWhenValidMetricGroupIsPassedThenExpectQueryhandle) {
zetMetricQueryInitialize();
EXPECT_NE(nullptr, metricQueryHandle);
}

TEST_F(zetMetricQueryTest,
GivenValidMetricQueryHandleWhenResettingQueryHandleThenExpectSuccess) {
zetMetricQueryInitialize();
lzt::reset_metric_query(metricQueryHandle);
}

TEST_F(
zetMetricQueryTest,
GivenOnlyMetricQueryWhenCommandListIsCreatedThenExpectCommandListToExecuteSucessfully) {

zetMetricQueryInitialize();
zet_command_list_handle_t commandList = lzt::create_command_list();
lzt::activate_metric_groups(device, 1, &matchedGroupHandle);
lzt::append_metric_query_begin(commandList, metricQueryHandle);
Expand All @@ -490,6 +497,7 @@ TEST_F(
TEST_F(
zetMetricQueryTest,
GivenOnlyMetricQueryWithMetricMemoryBarrierWhenCommandListIsCreatedThenExpectCommandListToExecuteSucessfully) {
zetMetricQueryInitialize();
zet_command_list_handle_t commandList = lzt::create_command_list();
lzt::activate_metric_groups(device, 1, &matchedGroupHandle);
lzt::append_metric_query_begin(commandList, metricQueryHandle);
Expand Down Expand Up @@ -536,7 +544,8 @@ TEST_F(
auto metricGroupInfo = lzt::get_metric_group_info(
device, ZET_METRIC_GROUP_SAMPLING_TYPE_FLAG_EVENT_BASED, false);
metricGroupInfo = lzt::optimize_metric_group_info_list(metricGroupInfo);

ASSERT_GT(metricGroupInfo.size(), 0u)
<< "metric group info list cannot be empty";
for (auto groupInfo : metricGroupInfo) {

LOG_INFO << "test metricGroup name " << groupInfo.metricGroupName;
Expand Down Expand Up @@ -631,7 +640,8 @@ void run_test(const ze_device_handle_t &device,
device, ZET_METRIC_GROUP_SAMPLING_TYPE_FLAG_EVENT_BASED, false);
metricGroupInfo =
lzt::optimize_metric_group_info_list(metricGroupInfo, reset ? 1 : 20);

ASSERT_GT(metricGroupInfo.size(), 0u)
<< "metric group info list cannot be empty";
for (auto groupInfo : metricGroupInfo) {
LOG_INFO << "test metricGroup name " << groupInfo.metricGroupName;

Expand Down Expand Up @@ -802,9 +812,12 @@ 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)
<< "metric group info list cannot be empty";
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)
<< "metric group info list cannot be empty";
metric_group_info_0 =
lzt::optimize_metric_group_info_list(metric_group_info_0);
metric_group_info_1 =
Expand Down Expand Up @@ -971,7 +984,8 @@ TEST_F(
auto metricGroupInfo = lzt::get_metric_group_info(
device, ZET_METRIC_GROUP_SAMPLING_TYPE_FLAG_EVENT_BASED, false);
metricGroupInfo = lzt::optimize_metric_group_info_list(metricGroupInfo, 1);

ASSERT_GT(metricGroupInfo.size(), 0u)
<< "metric group info list cannot be empty";
for (auto groupInfo : metricGroupInfo) {

LOG_INFO << "test metricGroup name " << groupInfo.metricGroupName;
Expand Down
51 changes: 35 additions & 16 deletions utils/test_harness/tools/src/test_harness_metric.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*
* Copyright (C) 2019 Intel Corporation
* Copyright (C) 2019-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
Expand Down Expand Up @@ -252,6 +252,8 @@ std::vector<metricGroupInfo_t> optimize_metric_group_info_list(

LOG_INFO << "size of optimizedList based on percentage "
<< optimizedList.size();
EXPECT_GT(optimizedList.size(), 0u)
<< "optimized metric group info list cannot be empty";
return optimizedList;
}

Expand Down Expand Up @@ -292,7 +294,8 @@ get_metric_group_info(ze_device_handle_t device,
metricGroupHandle, metricGroupProp.name, metricGroupProp.description,
metricGroupProp.domain, metricGroupProp.metricCount);
}

EXPECT_GT(matchedGroupsInfo.size(), 0u)
<< "metric group info list cannot be empty";
return matchedGroupsInfo;
}

Expand Down Expand Up @@ -332,7 +335,8 @@ std::vector<metricGroupInfo_t> get_metric_type_ip_group_info(
metricGroupProp.domain, metricGroupProp.metricCount);
continue;
}

EXPECT_GT(matchedGroupsInfo.size(), 0u)
<< "metric type ip group info list cannot be empty";
return matchedGroupsInfo;
}

Expand Down Expand Up @@ -360,6 +364,8 @@ get_metric_group_name_list(ze_device_handle_t device,
}
groupPropName.push_back(strItem);
}
EXPECT_GT(groupPropName.size(), 0u)
<< "metric group name list cannot be empty";
return groupPropName;
}

Expand Down Expand Up @@ -468,11 +474,15 @@ metric_query_create(zet_metric_query_pool_handle_t metricQueryPoolHandle) {
}

void destroy_metric_query(zet_metric_query_handle_t metricQueryHandle) {
EXPECT_EQ(ZE_RESULT_SUCCESS, zetMetricQueryDestroy(metricQueryHandle));
if (metricQueryHandle != nullptr) {
EXPECT_EQ(ZE_RESULT_SUCCESS, zetMetricQueryDestroy(metricQueryHandle));
}
}

void reset_metric_query(zet_metric_query_handle_t &metricQueryHandle) {
EXPECT_EQ(ZE_RESULT_SUCCESS, zetMetricQueryReset(metricQueryHandle));
if (metricQueryHandle != nullptr) {
EXPECT_EQ(ZE_RESULT_SUCCESS, zetMetricQueryReset(metricQueryHandle));
}
}

size_t metric_query_get_data_size(zet_metric_query_handle_t metricQueryHandle) {
Expand Down Expand Up @@ -580,11 +590,14 @@ void metric_streamer_read_data(
}

void activate_metric_groups(ze_device_handle_t device, uint32_t count,
zet_metric_group_handle_t *matchedGroupHandle) {
EXPECT_EQ(ZE_RESULT_SUCCESS,
zetContextActivateMetricGroups(lzt::get_default_context(), device,
count, matchedGroupHandle));
zet_metric_group_handle_t *pMatchedGroupHandle) {
if (*pMatchedGroupHandle != nullptr) {
EXPECT_EQ(ZE_RESULT_SUCCESS,
zetContextActivateMetricGroups(lzt::get_default_context(), device,
count, pMatchedGroupHandle));
}
}

void deactivate_metric_groups(ze_device_handle_t device) {
EXPECT_EQ(ZE_RESULT_SUCCESS,
zetContextActivateMetricGroups(lzt::get_default_context(), device,
Expand All @@ -593,25 +606,31 @@ 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) {
EXPECT_EQ(ZE_RESULT_SUCCESS, zetCommandListAppendMetricQueryBegin(
commandList, metricQueryHandle));
if (metricQueryHandle != nullptr) {
EXPECT_EQ(ZE_RESULT_SUCCESS, zetCommandListAppendMetricQueryBegin(
commandList, metricQueryHandle));
}
}

void append_metric_query_end(zet_command_list_handle_t commandList,
zet_metric_query_handle_t metricQueryHandle,
ze_event_handle_t eventHandle) {
append_metric_query_end(commandList, metricQueryHandle, eventHandle, 0,
nullptr);
if (metricQueryHandle != nullptr) {
append_metric_query_end(commandList, metricQueryHandle, eventHandle, 0,
nullptr);
}
}

void append_metric_query_end(zet_command_list_handle_t commandList,
zet_metric_query_handle_t metricQueryHandle,
ze_event_handle_t eventHandle,
uint32_t numWaitEvents,
ze_event_handle_t *waitEvents) {
EXPECT_EQ(ZE_RESULT_SUCCESS, zetCommandListAppendMetricQueryEnd(
commandList, metricQueryHandle, eventHandle,
numWaitEvents, waitEvents));
if (metricQueryHandle != nullptr) {
EXPECT_EQ(ZE_RESULT_SUCCESS, zetCommandListAppendMetricQueryEnd(
commandList, metricQueryHandle,
eventHandle, numWaitEvents, waitEvents));
}
}

void append_metric_memory_barrier(zet_command_list_handle_t commandList) {
Expand Down

0 comments on commit 79d3833

Please sign in to comment.