Skip to content

Commit

Permalink
Added CTS to check if memoryState & firmwareProperties can be retriev…
Browse files Browse the repository at this point in the history
…ed in parallel

Related to VLCLJ-2289

Signed-off-by: Harini Kumaran <[email protected]>
  • Loading branch information
harinik124 committed Oct 4, 2024
1 parent ab306e0 commit 74c4d9b
Showing 1 changed file with 106 additions and 0 deletions.
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;

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

class MemoryFirmwareZesTest : public lzt::ZesSysmanCtsClass {};
#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) {
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?
//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) {

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);
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

0 comments on commit 74c4d9b

Please sign in to comment.