1+ ##
2+ # Copyright (C) 2026 Intel Corporation
3+ #
4+ # SPDX-License-Identifier: MIT
5+ #
6+ ##
7+
8+ import os
9+ import sys
10+ from ctypes import byref , c_uint32
11+
12+ import pytest
13+
14+
15+ CTS_TESTS_DIR = os .path .dirname (os .path .abspath (__file__ ))
16+ SOURCE_DIR = os .path .abspath (os .path .join (CTS_TESTS_DIR , ".." ))
17+
18+ if SOURCE_DIR not in sys .path :
19+ sys .path .insert (0 , SOURCE_DIR )
20+
21+
22+ @pytest .fixture (scope = "session" )
23+ def pyzes_module ():
24+ try :
25+ import pyzes as pz
26+ except (ImportError , OSError ) as exc :
27+ pytest .skip (f"pyzes is not available for CTS validation: { exc } " )
28+
29+ return pz
30+
31+
32+ @pytest .fixture (scope = "session" )
33+ def sysman_devices (pyzes_module ):
34+ pz = pyzes_module
35+
36+ rc = pz .zesInit (0 )
37+ if rc != pz .ZE_RESULT_SUCCESS :
38+ pytest .skip (f"zesInit failed with ze_result_t={ rc } " )
39+
40+ driver_count = c_uint32 (0 )
41+ rc = pz .zesDriverGet (byref (driver_count ), None )
42+ if rc != pz .ZE_RESULT_SUCCESS :
43+ pytest .skip (f"zesDriverGet(count) failed with ze_result_t={ rc } " )
44+
45+ if driver_count .value == 0 :
46+ pytest .skip ("No Sysman drivers available" )
47+
48+ DriverArray = pz .zes_driver_handle_t * driver_count .value
49+ drivers = DriverArray ()
50+ rc = pz .zesDriverGet (byref (driver_count ), drivers )
51+ if rc != pz .ZE_RESULT_SUCCESS :
52+ pytest .skip (f"zesDriverGet(handles) failed with ze_result_t={ rc } " )
53+
54+ devices = []
55+ for driver in drivers :
56+ device_count = c_uint32 (0 )
57+ rc = pz .zesDeviceGet (driver , byref (device_count ), None )
58+ if rc != pz .ZE_RESULT_SUCCESS :
59+ continue
60+
61+ if device_count .value == 0 :
62+ continue
63+
64+ DeviceArray = pz .zes_device_handle_t * device_count .value
65+ driver_devices = DeviceArray ()
66+ rc = pz .zesDeviceGet (driver , byref (device_count ), driver_devices )
67+ if rc != pz .ZE_RESULT_SUCCESS :
68+ continue
69+
70+ devices .extend (driver_devices )
71+
72+ if not devices :
73+ pytest .skip ("No Sysman devices available" )
74+
75+ return devices
0 commit comments