Skip to content

Commit 561f4bc

Browse files
committed
fix: pyzes minor bug fixes.
Two structures were not defined correctly. Related-To: NEO-18748 Signed-off-by: Aviral Nigam <aviral.nigam@intel.com>
1 parent b92de6f commit 561f4bc

5 files changed

Lines changed: 64 additions & 46 deletions

File tree

bindings/sysman/python/source/examples/pyzes_black_box_test.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,10 @@ def test_global_operation(driver_handle, device_handle, device_index):
436436
ProcessArray = pz.zes_process_state_t * process_count.value
437437
processes = ProcessArray()
438438

439+
for i in range(process_count.value):
440+
processes[i].stype = pz.ZES_STRUCTURE_TYPE_PROCESS_STATE
441+
processes[i].pNext = None
442+
439443
rc = pz.zesDeviceProcessesGetState(
440444
device_handle, byref(process_count), processes
441445
)
@@ -447,11 +451,10 @@ def test_global_operation(driver_handle, device_handle, device_index):
447451
for i in range(process_count.value):
448452
process = processes[i]
449453
print_verbose(f" Process {i}:")
450-
print_verbose(f" PID: {process.pid}")
454+
print_verbose(f" PID: {process.processId}")
451455
print_verbose(f" Memory Size: {process.memSize} bytes")
452-
print_verbose(f" Shared Memory Size: {process.sharedMemSize} bytes")
453-
print_verbose(f" Engine Type Flags: 0x{process.engineType:08X}")
454-
print_verbose(f" Subdevice ID: {process.subdeviceId}")
456+
print_verbose(f" Shared Memory Size: {process.sharedSize} bytes")
457+
print_verbose(f" Engine Type Flags: 0x{process.engines:08X}")
455458

456459
return True
457460

@@ -475,18 +478,21 @@ def test_device_processes(device_handle, device_index):
475478
ProcessArray = pz.zes_process_state_t * process_count.value
476479
processes = ProcessArray()
477480

481+
for i in range(process_count.value):
482+
processes[i].stype = pz.ZES_STRUCTURE_TYPE_PROCESS_STATE
483+
processes[i].pNext = None
484+
478485
rc = pz.zesDeviceProcessesGetState(device_handle, byref(process_count), processes)
479486
if not check_rc(f"zesDeviceProcessesGetState(device {device_index}, handles)", rc):
480487
return False
481488

482489
for i in range(process_count.value):
483490
process = processes[i]
484491
print_verbose(f" Process {i}:")
485-
print_verbose(f" PID: {process.pid}")
492+
print_verbose(f" PID: {process.processId}")
486493
print_verbose(f" Memory Size: {process.memSize} bytes")
487-
print_verbose(f" Shared Memory Size: {process.sharedMemSize} bytes")
488-
print_verbose(f" Engine Type Flags: 0x{process.engineType:08X}")
489-
print_verbose(f" Subdevice ID: {process.subdeviceId}")
494+
print_verbose(f" Shared Memory Size: {process.sharedSize} bytes")
495+
print_verbose(f" Engine Type Flags: 0x{process.engines:08X}")
490496

491497
return True
492498

@@ -849,13 +855,13 @@ def test_temperature_sensors(device_handle, device_index):
849855
print_verbose(" Temperature Config:")
850856
print_verbose(f" Critical Enabled: {bool(temp_config.enableCritical)}")
851857
print_verbose(
852-
f" Threshold 1: {temp_config.threshold1:.1f} °C"
853-
if temp_config.threshold1 >= 0
858+
f" Threshold 1: {temp_config.threshold1.threshold:.1f} °C"
859+
if temp_config.threshold1.threshold >= 0
854860
else " Threshold 1: Not set"
855861
)
856862
print_verbose(
857-
f" Threshold 2: {temp_config.threshold2:.1f} °C"
858-
if temp_config.threshold2 >= 0
863+
f" Threshold 2: {temp_config.threshold2.threshold:.1f} °C"
864+
if temp_config.threshold2.threshold >= 0
859865
else " Threshold 2: Not set"
860866
)
861867
else:

bindings/sysman/python/source/pyzes.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ class zes_engine_handle_t(c_void_p):
334334

335335
# Structure type enum values
336336
ZES_STRUCTURE_TYPE_DEVICE_PROPERTIES = 0x1
337+
ZES_STRUCTURE_TYPE_PROCESS_STATE = 0x16
337338
ZES_STRUCTURE_TYPE_DEVICE_EXT_PROPERTIES = 0x2D # from zes_structure_type_t
338339
ZES_STRUCTURE_TYPE_SUBDEVICE_EXP_PROPERTIES = 0x2E # Experimental subdevice properties
339340
ZES_STRUCTURE_TYPE_MEM_PROPERTIES = 0xB
@@ -396,14 +397,14 @@ class zes_device_properties_t(_PrintableStructure):
396397
## Sysman zes_process_state_t ##
397398
class zes_process_state_t(_PrintableStructure):
398399
_fields_ = [
399-
("pid", c_uint32),
400-
("command", c_char * ZES_STRING_PROPERTY_SIZE),
401-
("memSize", c_uint64), # in bytes
402-
("sharedMemSize", c_uint64), # in bytes
403-
("engineType", zes_engine_type_flags_t),
404-
("subdeviceId", c_uint32),
400+
("stype", c_int32),
401+
("pNext", c_void_p),
402+
("processId", c_uint32),
403+
("memSize", c_uint64),
404+
("sharedSize", c_uint64),
405+
("engines", zes_engine_type_flags_t),
405406
]
406-
_fmt_ = {"memSize": "%d bytes", "sharedMemSize": "%d bytes"}
407+
_fmt_ = {"memSize": "%d bytes", "sharedSize": "%d bytes"}
407408

408409

409410
## Sysman zes_uuid_t ##
@@ -524,15 +525,23 @@ class zes_temp_properties_t(_PrintableStructure):
524525
_fmt_ = {"maxTemperature": "%.1f °C"}
525526

526527

528+
class zes_temp_threshold_t(_PrintableStructure):
529+
_fields_ = [
530+
("enableLowToHigh", ze_bool_t),
531+
("enableHighToLow", ze_bool_t),
532+
("threshold", c_double),
533+
]
534+
_fmt_ = {"threshold": "%.1f °C"}
535+
536+
527537
class zes_temp_config_t(_PrintableStructure):
528538
_fields_ = [
529539
("stype", c_int32), # ZES_STRUCTURE_TYPE_TEMP_CONFIG
530540
("pNext", c_void_p),
531541
("enableCritical", ze_bool_t), # enable critical temperature event
532-
("threshold1", c_double), # threshold 1 in degrees Celsius
533-
("threshold2", c_double), # threshold 2 in degrees Celsius
542+
("threshold1", zes_temp_threshold_t),
543+
("threshold2", zes_temp_threshold_t),
534544
]
535-
_fmt_ = {"threshold1": "%.1f °C", "threshold2": "%.1f °C"}
536545

537546

538547
## Engine structures ##

bindings/sysman/python/test/unit_tests/test_global_operations.py

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -130,28 +130,28 @@ def test_GivenValidDeviceHandleWhenCallingZesDeviceProcessesGetStateWithArrayThe
130130
self, mock_get_func
131131
):
132132
mock_process_count = 2
133-
mock_pid_1 = 1234
134-
mock_pid_2 = 5678
133+
mock_process_id_1 = 1234
134+
mock_process_id_2 = 5678
135135
mock_mem_size_1 = 1073741824 # 1GB
136136
mock_mem_size_2 = 2147483648 # 2GB
137-
mock_shared_mem_size_1 = 536870912 # 512MB
138-
mock_shared_mem_size_2 = 1073741824 # 1GB
139-
mock_subdevice_id_1 = 0
140-
mock_subdevice_id_2 = 1
137+
mock_shared_size_1 = 536870912 # 512MB
138+
mock_shared_size_2 = 1073741824 # 1GB
139+
mock_engines_1 = 0x3
140+
mock_engines_2 = 0x5
141141

142142
def mock_get_processes_state_with_data(device_handle, count_ptr, processes_ptr):
143143
if processes_ptr:
144144
# Fill in process data for first process
145-
processes_ptr[0].pid = mock_pid_1
145+
processes_ptr[0].processId = mock_process_id_1
146146
processes_ptr[0].memSize = mock_mem_size_1
147-
processes_ptr[0].sharedMemSize = mock_shared_mem_size_1
148-
processes_ptr[0].subdeviceId = mock_subdevice_id_1
147+
processes_ptr[0].sharedSize = mock_shared_size_1
148+
processes_ptr[0].engines = mock_engines_1
149149

150150
# Fill in process data for second process
151-
processes_ptr[1].pid = mock_pid_2
151+
processes_ptr[1].processId = mock_process_id_2
152152
processes_ptr[1].memSize = mock_mem_size_2
153-
processes_ptr[1].sharedMemSize = mock_shared_mem_size_2
154-
processes_ptr[1].subdeviceId = mock_subdevice_id_2
153+
processes_ptr[1].sharedSize = mock_shared_size_2
154+
processes_ptr[1].engines = mock_engines_2
155155
else:
156156
count_ptr._obj.value = mock_process_count
157157
return self.pyzes.ZE_RESULT_SUCCESS
@@ -164,6 +164,9 @@ def mock_get_processes_state_with_data(device_handle, count_ptr, processes_ptr):
164164

165165
# Create array for process states
166166
process_array = (self.pyzes.zes_process_state_t * mock_process_count)()
167+
for i in range(mock_process_count):
168+
process_array[i].stype = self.pyzes.ZES_STRUCTURE_TYPE_PROCESS_STATE
169+
process_array[i].pNext = None
167170

168171
result = self.pyzes.zesDeviceProcessesGetState(
169172
device_handle, byref(count), process_array
@@ -172,16 +175,16 @@ def mock_get_processes_state_with_data(device_handle, count_ptr, processes_ptr):
172175
self.assertEqual(result, self.pyzes.ZE_RESULT_SUCCESS)
173176

174177
# Validate first process data
175-
self.assertEqual(process_array[0].pid, mock_pid_1)
178+
self.assertEqual(process_array[0].processId, mock_process_id_1)
176179
self.assertEqual(process_array[0].memSize, mock_mem_size_1)
177-
self.assertEqual(process_array[0].sharedMemSize, mock_shared_mem_size_1)
178-
self.assertEqual(process_array[0].subdeviceId, mock_subdevice_id_1)
180+
self.assertEqual(process_array[0].sharedSize, mock_shared_size_1)
181+
self.assertEqual(process_array[0].engines, mock_engines_1)
179182

180183
# Validate second process data
181-
self.assertEqual(process_array[1].pid, mock_pid_2)
184+
self.assertEqual(process_array[1].processId, mock_process_id_2)
182185
self.assertEqual(process_array[1].memSize, mock_mem_size_2)
183-
self.assertEqual(process_array[1].sharedMemSize, mock_shared_mem_size_2)
184-
self.assertEqual(process_array[1].subdeviceId, mock_subdevice_id_2)
186+
self.assertEqual(process_array[1].sharedSize, mock_shared_size_2)
187+
self.assertEqual(process_array[1].engines, mock_engines_2)
185188

186189
mock_get_func.assert_called_with("zesDeviceProcessesGetState")
187190
mock_func.assert_called_once()

bindings/sysman/python/test/unit_tests/test_temperature.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ def test_GivenValidTemperatureHandleWhenCallingZesTemperatureGetConfigThenCallSu
105105

106106
def mock_get_config(temp_handle, config_ptr):
107107
config_ptr._obj.enableCritical = mock_enable_critical
108-
config_ptr._obj.threshold1 = mock_threshold1
109-
config_ptr._obj.threshold2 = mock_threshold2
108+
config_ptr._obj.threshold1.threshold = mock_threshold1
109+
config_ptr._obj.threshold2.threshold = mock_threshold2
110110
return self.pyzes.ZE_RESULT_SUCCESS
111111

112112
mock_func = MagicMock(side_effect=mock_get_config)
@@ -118,8 +118,8 @@ def mock_get_config(temp_handle, config_ptr):
118118

119119
self.assertEqual(result, self.pyzes.ZE_RESULT_SUCCESS)
120120
self.assertEqual(temp_config.enableCritical, mock_enable_critical)
121-
self.assertEqual(temp_config.threshold1, mock_threshold1)
122-
self.assertEqual(temp_config.threshold2, mock_threshold2)
121+
self.assertEqual(temp_config.threshold1.threshold, mock_threshold1)
122+
self.assertEqual(temp_config.threshold2.threshold, mock_threshold2)
123123
mock_get_func.assert_called_with("zesTemperatureGetConfig")
124124
mock_func.assert_called_once()
125125

bindings/sysman/python/test/unit_tests/test_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ def test_GivenPrintableStructureWhenConvertedToStringThenProvidesFormattedOutput
3232
# Test _PrintableStructure string formatting functionality
3333
temp_state = self.pyzes.zes_temp_config_t()
3434
temp_state.enableCritical = True
35-
temp_state.threshold1 = 75.0
36-
temp_state.threshold2 = 80.0
35+
temp_state.threshold1.threshold = 75.0
36+
temp_state.threshold2.threshold = 80.0
3737

3838
# Test string representation functionality
3939
str_repr = str(temp_state)

0 commit comments

Comments
 (0)