1313#include < condition_variable>
1414#include < thread>
1515
16+ #include " test_harness/test_harness.hpp"
17+
1618namespace lzt = level_zero_tests;
1719
1820#include < level_zero/zes_api.h>
@@ -23,12 +25,29 @@ std::mutex mem_mutex;
2325std::condition_variable condition_variable;
2426uint32_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
2732class 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
3042class 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
3453TEST_F (
@@ -443,4 +462,91 @@ TEST_F(
443462 memoryThread.join ();
444463 }
445464}
465+
466+ void getMemoryStateTemp (ze_device_handle_t device) {
467+ std::cout<<" \n Inside 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<<" \n Exiting function getMemoryStateTemp" ;
480+ }
481+
482+ void getFirmwareProperties (zes_firmware_handle_t firmware_handle, zes_device_properties_t deviceProperties) {
483+ std::cout<<" \n Calling 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<<" \n Out 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<<" \n Inside 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<<" \n Inside loop devices after checking firmware handles count!=0" ;
515+ for (auto firmware_handle : firmware_handles) {
516+
517+ std::cout<<" \n Inside 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\n End 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\n Completion of loops with 'Thread Array' initializations & joins in the different loops\n " ;
545+
546+ }
547+
548+ }
549+
550+ }
551+
446552} // namespace
0 commit comments