Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test where zesMemoryGetState & zesFirmwareGetProperties APIs are invoked in threads #81

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include <condition_variable>
#include <thread>

#include "test_harness/test_harness.hpp"

namespace lzt = level_zero_tests;

#include <level_zero/zes_api.h>
Expand All @@ -23,12 +25,23 @@ std::mutex mem_mutex;
std::condition_variable condition_variable;
uint32_t ready = 0;

uint32_t get_property_length(char *prop) { return std::strlen(prop); }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if any other harness files contains this function , can it be reused ?

const uint32_t numThreads = 10;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be moved inside the test, since only one test is using this ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better to add this in Test code or create a environment variable to read this value for numThreads


#ifdef USE_ZESINIT
class MemoryModuleZesTest : public lzt::ZesSysmanCtsClass {};
#define MEMORY_TEST MemoryModuleZesTest

class MemoryFirmwareZesTest : public lzt::ZesSysmanCtsClass {};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess new fixture may not be required. already existing fixture can be used (MEMORY_TEST)

#define MEMORY_FIRMWARE_TEST MemoryFirmwareZesTest

#else // USE_ZESINIT
class MemoryModuleTest : public lzt::SysmanCtsClass {};
#define MEMORY_TEST MemoryModuleTest

class MemoryFirmwareTest : public lzt::SysmanCtsClass {};
#define MEMORY_FIRMWARE_TEST MemoryFirmwareTest

#endif // USE_ZESINIT

TEST_F(
Expand Down Expand Up @@ -443,4 +456,52 @@ TEST_F(
memoryThread.join();
}
}

void query_memory_state_function(ze_device_handle_t device) {
uint32_t count = 0;
std::vector<zes_mem_handle_t> mem_handles = lzt::get_mem_handles(device, count);
if (count == 0) {
FAIL() << "No handles found: "
<< _ze_result_t(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE);
}
for (auto mem_handle : mem_handles) {
ASSERT_NE(nullptr, mem_handle);
lzt::get_mem_state(mem_handle);
}
}

void query_firmware_properties_function(ze_device_handle_t device) {
uint32_t count = 0;
auto firmware_handles = lzt::get_firmware_handles(device, count);
auto deviceProperties = lzt::get_sysman_device_properties(device);
if (count == 0) {
FAIL() << "No handles found: "
<< _ze_result_t(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE);
}
for (auto firmware_handle : firmware_handles) {
ASSERT_NE(nullptr, firmware_handle);
auto properties = lzt::get_firmware_properties(firmware_handle);
EXPECT_LT(get_property_length(properties.name), ZES_STRING_PROPERTY_SIZE);
EXPECT_GT(get_property_length(properties.name), 0);
EXPECT_LT(get_property_length(properties.version), ZES_STRING_PROPERTY_SIZE);
}
}

TEST_F(
MEMORY_FIRMWARE_TEST,
GivenValidMemoryAndFirmwareHandlesWhenGettingMemoryGetStateAndFirmwareGetPropertiesFromDifferentThreadsThenExpectBothToReturnSucess) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GivenValidDeviceWhenCallingMemoryGetStateAndFirmwareGetPropertiesFromDifferentThreadsThenSuccessIsReturned

for (auto device : devices) {
std::thread memoryThreads[numThreads];
std::thread firmwareThreads[numThreads];
for (int i = 0; i < numThreads; i++) {
memoryThreads[i] = std::thread(query_memory_state_function, device);
firmwareThreads[i] = std::thread(query_firmware_properties_function, device);
}
for (int i = 0; i < numThreads; i++) {
memoryThreads[i].join();
firmwareThreads[i].join();
}
}
}

} // namespace
Loading