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 1 commit
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
106 changes: 106 additions & 0 deletions conformance_tests/sysman/test_sysman_memory/src/test_sysman_memory.cpp
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,29 @@ std::mutex mem_mutex;
std::condition_variable condition_variable;
uint32_t ready = 0;

uint32_t get_prop_length(char *prop) { return std::strlen(prop); }
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

//class MemoryFirmwareZesTest : public MemoryModuleZesTest {};
//#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

//class MemoryFirmwareTest : public MemoryModuleTest {};
//#define MEMORY_FIRMWARE_TEST MemoryFirmwareTest

#endif // USE_ZESINIT

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

void getMemoryStateTemp(ze_device_handle_t device) {
harinik124 marked this conversation as resolved.
Show resolved Hide resolved
std::cout<<"\nInside function getMemoryStateTemp";
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);
}
std::cout<<"\nExiting function getMemoryStateTemp";
}

void getFirmwareProperties(zes_firmware_handle_t firmware_handle, zes_device_properties_t deviceProperties) {
std::cout<<"\nCalling function getFirmwareProperties";
ASSERT_NE(nullptr, firmware_handle);
auto properties = lzt::get_firmware_properties(firmware_handle);
//Are the below lines till line.495 required?
harinik124 marked this conversation as resolved.
Show resolved Hide resolved
//but we cant ensure correct firmware props are returned without them

///*
if (properties.onSubdevice) {
EXPECT_LT(properties.subdeviceId, deviceProperties.numSubdevices);
}
EXPECT_LT(get_prop_length(properties.name), ZES_STRING_PROPERTY_SIZE);
EXPECT_GT(get_prop_length(properties.name), 0);
EXPECT_LT(get_prop_length(properties.version), ZES_STRING_PROPERTY_SIZE);
//*/

std::cout<<"\nOut of function getFirmwareProperties";
}

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) {
uint32_t count = 0;
std::cout<<"\nInside loop devices; Initialised 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);
}
std::cout<<"\nInside loop devices after checking firmware handles count!=0";
for (auto firmware_handle : firmware_handles) {

std::cout<<"\nInside loop firmware handles before starting threads\n\n";

///*
for (int i = 0; i < numThreads; i++) {
std::thread memoryThreadss(getMemoryStateTemp, device);
std::thread firmwareThreadss(getFirmwareProperties, firmware_handle, deviceProperties);

memoryThreadss.join();
firmwareThreadss.join();
}
//*/
std::cout<<"\n\nEnd of loop with thread initializations & joins in the same loop\n";

///*
std::thread memoryThreads[numThreads];
std::thread firmwareThreads[numThreads];

for (int i = 0; i < numThreads; i++) {
memoryThreads[i] = std::thread(getMemoryStateTemp, device);
Copy link
Contributor

Choose a reason for hiding this comment

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

@AshwinKumarKulkarni is the test expected to have barrier mechanism in both the functions getMemoryState & getFirmwareProperties ? similar to test GivenValidMemoryAndRasHandlesWhenGettingMemoryGetStateAndRasGetStateFromDifferentThreadsThenExpectBothToReturnSucess

firmwareThreads[i] = std::thread(getFirmwareProperties, firmware_handle, deviceProperties);
}
for (int i = 0; i < numThreads; i++) {
memoryThreads[i].join();
firmwareThreads[i].join();
}
//*/

std::cout<<"\n\nCompletion of loops with 'Thread Array' initializations & joins in the different loops\n";

}

}

}

} // namespace
Loading