Skip to content

Commit 74c4d9b

Browse files
committed
Added CTS to check if memoryState & firmwareProperties can be retrieved in parallel
Related to VLCLJ-2289 Signed-off-by: Harini Kumaran <[email protected]>
1 parent ab306e0 commit 74c4d9b

File tree

1 file changed

+106
-0
lines changed

1 file changed

+106
-0
lines changed

conformance_tests/sysman/test_sysman_memory/src/test_sysman_memory.cpp

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#include <condition_variable>
1414
#include <thread>
1515

16+
#include "test_harness/test_harness.hpp"
17+
1618
namespace lzt = level_zero_tests;
1719

1820
#include <level_zero/zes_api.h>
@@ -23,12 +25,29 @@ std::mutex mem_mutex;
2325
std::condition_variable condition_variable;
2426
uint32_t ready = 0;
2527

28+
uint32_t get_prop_length(char *prop) { return std::strlen(prop); }
29+
const uint32_t numThreads = 10;
30+
2631
#ifdef USE_ZESINIT
2732
class MemoryModuleZesTest : public lzt::ZesSysmanCtsClass {};
2833
#define MEMORY_TEST MemoryModuleZesTest
34+
35+
class MemoryFirmwareZesTest : public lzt::ZesSysmanCtsClass {};
36+
#define MEMORY_FIRMWARE_TEST MemoryFirmwareZesTest
37+
38+
//class MemoryFirmwareZesTest : public MemoryModuleZesTest {};
39+
//#define MEMORY_FIRMWARE_TEST MemoryFirmwareZesTest
40+
2941
#else // USE_ZESINIT
3042
class MemoryModuleTest : public lzt::SysmanCtsClass {};
3143
#define MEMORY_TEST MemoryModuleTest
44+
45+
class MemoryFirmwareTest : public lzt::SysmanCtsClass {};
46+
#define MEMORY_FIRMWARE_TEST MemoryFirmwareTest
47+
48+
//class MemoryFirmwareTest : public MemoryModuleTest {};
49+
//#define MEMORY_FIRMWARE_TEST MemoryFirmwareTest
50+
3251
#endif // USE_ZESINIT
3352

3453
TEST_F(
@@ -443,4 +462,91 @@ TEST_F(
443462
memoryThread.join();
444463
}
445464
}
465+
466+
void getMemoryStateTemp(ze_device_handle_t device) {
467+
std::cout<<"\nInside function getMemoryStateTemp";
468+
uint32_t count = 0;
469+
std::vector<zes_mem_handle_t> mem_handles =
470+
lzt::get_mem_handles(device, count);
471+
if (count == 0) {
472+
FAIL() << "No handles found: "
473+
<< _ze_result_t(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE);
474+
}
475+
for (auto mem_handle : mem_handles) {
476+
ASSERT_NE(nullptr, mem_handle);
477+
lzt::get_mem_state(mem_handle);
478+
}
479+
std::cout<<"\nExiting function getMemoryStateTemp";
480+
}
481+
482+
void getFirmwareProperties(zes_firmware_handle_t firmware_handle, zes_device_properties_t deviceProperties) {
483+
std::cout<<"\nCalling function getFirmwareProperties";
484+
ASSERT_NE(nullptr, firmware_handle);
485+
auto properties = lzt::get_firmware_properties(firmware_handle);
486+
//Are the below lines till line.495 required?
487+
//but we cant ensure correct firmware props are returned without them
488+
489+
///*
490+
if (properties.onSubdevice) {
491+
EXPECT_LT(properties.subdeviceId, deviceProperties.numSubdevices);
492+
}
493+
EXPECT_LT(get_prop_length(properties.name), ZES_STRING_PROPERTY_SIZE);
494+
EXPECT_GT(get_prop_length(properties.name), 0);
495+
EXPECT_LT(get_prop_length(properties.version), ZES_STRING_PROPERTY_SIZE);
496+
//*/
497+
498+
std::cout<<"\nOut of function getFirmwareProperties";
499+
}
500+
501+
TEST_F(
502+
MEMORY_FIRMWARE_TEST,
503+
GivenValidMemoryAndFirmwareHandlesWhenGettingMemoryGetStateAndFirmwareGetPropertiesFromDifferentThreadsThenExpectBothToReturnSucess) {
504+
505+
for (auto device : devices) {
506+
uint32_t count = 0;
507+
std::cout<<"\nInside loop devices; Initialised count=0";
508+
auto firmware_handles = lzt::get_firmware_handles(device, count);
509+
auto deviceProperties = lzt::get_sysman_device_properties(device);
510+
if (count == 0) {
511+
FAIL() << "No handles found: "
512+
<< _ze_result_t(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE);
513+
}
514+
std::cout<<"\nInside loop devices after checking firmware handles count!=0";
515+
for (auto firmware_handle : firmware_handles) {
516+
517+
std::cout<<"\nInside loop firmware handles before starting threads\n\n";
518+
519+
///*
520+
for (int i = 0; i < numThreads; i++) {
521+
std::thread memoryThreadss(getMemoryStateTemp, device);
522+
std::thread firmwareThreadss(getFirmwareProperties, firmware_handle, deviceProperties);
523+
524+
memoryThreadss.join();
525+
firmwareThreadss.join();
526+
}
527+
//*/
528+
std::cout<<"\n\nEnd of loop with thread initializations & joins in the same loop\n";
529+
530+
///*
531+
std::thread memoryThreads[numThreads];
532+
std::thread firmwareThreads[numThreads];
533+
534+
for (int i = 0; i < numThreads; i++) {
535+
memoryThreads[i] = std::thread(getMemoryStateTemp, device);
536+
firmwareThreads[i] = std::thread(getFirmwareProperties, firmware_handle, deviceProperties);
537+
}
538+
for (int i = 0; i < numThreads; i++) {
539+
memoryThreads[i].join();
540+
firmwareThreads[i].join();
541+
}
542+
//*/
543+
544+
std::cout<<"\n\nCompletion of loops with 'Thread Array' initializations & joins in the different loops\n";
545+
546+
}
547+
548+
}
549+
550+
}
551+
446552
} // namespace

0 commit comments

Comments
 (0)