@@ -98,12 +98,21 @@ def test_device_cpu_affinity(subtests):
9898@pytest .mark .skipif (helpers .IS_WSL or helpers .IS_WINDOWS , reason = "Device attributes not supported on WSL or Windows" )
9999def test_affinity (subtests ):
100100 for device in system .Device .get_all_devices ():
101- with subtests .test (device = device ):
102- for scope in typing .AffinityScope .__members__ .values ():
101+ for scope in typing .AffinityScope .__members__ .values ():
102+ with subtests .test (
103+ device_index = device .index ,
104+ affinity_scope = scope .value ,
105+ affinity_api = "get_cpu_affinity" ,
106+ ):
103107 with unsupported_before (device , typing .DeviceArch .KEPLER ):
104108 affinity = device .get_cpu_affinity (scope )
105109 assert isinstance (affinity , list )
106110
111+ with subtests .test (
112+ device_index = device .index ,
113+ affinity_scope = scope .value ,
114+ affinity_api = "get_memory_affinity" ,
115+ ):
107116 affinity = device .get_memory_affinity (scope )
108117 assert isinstance (affinity , list )
109118
@@ -410,8 +419,11 @@ def test_field_values(subtests):
410419@pytest .mark .skipif (helpers .IS_WSL or helpers .IS_WINDOWS , reason = "Device attributes not supported on WSL or Windows" )
411420def test_get_all_devices_with_cpu_affinity (subtests ):
412421 for i in range (multiprocessing .cpu_count ()):
413- with subtests .test (i = i ):
414- for device in system .Device .get_all_devices_with_cpu_affinity (i ):
422+ devices = []
423+ with subtests .test (cpu_index = i , affinity_api = "get_all_devices_with_cpu_affinity" ):
424+ devices = list (system .Device .get_all_devices_with_cpu_affinity (i ))
425+ for device in devices :
426+ with subtests .test (cpu_index = i , device_index = device .index ):
415427 with unsupported_before (device , DeviceArch .KEPLER ):
416428 affinity = device .get_cpu_affinity ()
417429 assert isinstance (affinity , list )
@@ -566,8 +578,8 @@ def test_auto_boosted_clocks_enabled(subtests):
566578
567579def test_clock (subtests ):
568580 for device in system .Device .get_all_devices ():
569- with subtests . test ( device = device ) :
570- for clock_type in typing . ClockType :
581+ for clock_type in typing . ClockType :
582+ with subtests . test ( device_index = device . index , clock_type = clock_type . value ) :
571583 clock = device .get_clock (clock_type )
572584 assert isinstance (clock , _device .ClockInfo )
573585
@@ -628,44 +640,45 @@ def test_clock_event_reasons(subtests):
628640
629641def test_fan (subtests ):
630642 for device in system .Device .get_all_devices ():
631- with subtests . test ( device = device ):
632- # The fan APIs are only supported on discrete devices with fans,
633- # but when they are not available ` device.num_fans` returns 0.
634- if device . num_fans == 0 :
643+ # The fan APIs are only supported on discrete devices with fans,
644+ # but when they are not available `device.num_fans` returns 0.
645+ if device .num_fans == 0 :
646+ with subtests . test ( device_index = device . index ) :
635647 pytest .skip ("Device has no fans to test" )
648+ continue
636649
637- for fan_idx in range (device .num_fans ):
638- with subtests .test (fan_idx = fan_idx ):
639- fan_info = device .get_fan (fan_idx )
640- assert isinstance (fan_info , _device .FanInfo )
650+ for fan_idx in range (device .num_fans ):
651+ with subtests .test (device_index = device . index , fan_index = fan_idx ):
652+ fan_info = device .get_fan (fan_idx )
653+ assert isinstance (fan_info , _device .FanInfo )
641654
642- speed = fan_info .speed
643- assert isinstance (speed , int )
644- assert 0 <= speed <= 200
645- try :
646- fan_info .speed = 50
647- except nvml .NoPermissionError as e :
648- pytest .xfail (f"nvml.NoPermissionError: { e } " )
649- try :
650- fan_info .speed = speed
655+ speed = fan_info .speed
656+ assert isinstance (speed , int )
657+ assert 0 <= speed <= 200
658+ try :
659+ fan_info .speed = 50
660+ except nvml .NoPermissionError as e :
661+ pytest .xfail (f"nvml.NoPermissionError: { e } " )
662+ try :
663+ fan_info .speed = speed
651664
652- speed_rpm = fan_info .speed_rpm
653- assert isinstance (speed_rpm , int )
654- assert speed_rpm >= 0
665+ speed_rpm = fan_info .speed_rpm
666+ assert isinstance (speed_rpm , int )
667+ assert speed_rpm >= 0
655668
656- target_speed = fan_info .target_speed
657- assert isinstance (target_speed , int )
658- assert speed <= target_speed * 2
669+ target_speed = fan_info .target_speed
670+ assert isinstance (target_speed , int )
671+ assert speed <= target_speed * 2
659672
660- min_ , max_ = fan_info .min_max_speed
661- assert isinstance (min_ , int )
662- assert isinstance (max_ , int )
663- assert min_ <= max_
673+ min_ , max_ = fan_info .min_max_speed
674+ assert isinstance (min_ , int )
675+ assert isinstance (max_ , int )
676+ assert min_ <= max_
664677
665- control_policy = fan_info .control_policy
666- assert isinstance (control_policy , typing .FanControlPolicy )
667- finally :
668- fan_info .set_default_speed ()
678+ control_policy = fan_info .control_policy
679+ assert isinstance (control_policy , typing .FanControlPolicy )
680+ finally :
681+ fan_info .set_default_speed ()
669682
670683
671684def test_cooler (subtests ):
@@ -691,35 +704,55 @@ def test_cooler(subtests):
691704@pytest .mark .filterwarnings ("ignore::DeprecationWarning" )
692705def test_temperature (subtests ):
693706 for device in system .Device .get_all_devices ():
694- with subtests .test (device = device ):
707+ device_index = device .index
708+ temperature = None
709+ with subtests .test (device_index = device_index , temperature_api = "temperature" ):
695710 temperature = device .temperature
696711 assert isinstance (temperature , _device .Temperature )
712+ if temperature is None :
713+ continue
697714
715+ with subtests .test (device_index = device_index , temperature_api = "get_sensor" ):
698716 sensor = temperature .get_sensor ()
699717 assert isinstance (sensor , int )
700718 assert sensor >= 0
701719
702- # By docs, should be supported on KEPLER or newer, but experimentally,
703- # is also unsupported on other hardware.
704- # get_threshold emits DeprecationWarning for some thresholds on Ada+;
705- # that behaviour is tested separately in
706- # test_temperature_threshold_unrecognized_device_arch.
707- with unsupported_before (device , None ):
708- for threshold in list (typing .TemperatureThresholds ):
720+ # By docs, should be supported on KEPLER or newer, but experimentally,
721+ # is also unsupported on other hardware.
722+ # get_threshold emits DeprecationWarning for some thresholds on Ada+;
723+ # that behaviour is tested separately in
724+ # test_temperature_threshold_unrecognized_device_arch.
725+ for threshold in typing .TemperatureThresholds :
726+ with subtests .test (
727+ device_index = device_index ,
728+ temperature_api = "get_threshold" ,
729+ threshold = threshold .value ,
730+ ):
731+ with unsupported_before (device , None ):
709732 t = temperature .get_threshold (threshold )
710- assert isinstance (t , int )
711- assert t >= 0
733+ assert isinstance (t , int )
734+ assert t >= 0
712735
736+ with subtests .test (device_index = device_index , temperature_api = "margin" ):
713737 with unsupported_before (device , None ):
714738 margin = temperature .margin
715739 assert isinstance (margin , int )
716740 assert margin >= 0
717741
742+ thermals = None
743+ with subtests .test (device_index = device_index , temperature_api = "get_thermal_settings" ):
718744 with unsupported_before (device , None ):
719745 thermals = temperature .get_thermal_settings (typing .ThermalTarget .ALL )
720746 assert isinstance (thermals , _device .ThermalSettings )
747+ if thermals is None :
748+ continue
721749
722- for i , sensor in enumerate (thermals ):
750+ for i , sensor in enumerate (thermals ):
751+ with subtests .test (
752+ device_index = device_index ,
753+ temperature_api = "thermal_sensor" ,
754+ sensor_index = i ,
755+ ):
723756 assert isinstance (sensor , _device .ThermalSensor )
724757 assert isinstance (sensor .target , typing .ThermalTarget )
725758 assert isinstance (sensor .controller , typing .ThermalController )
@@ -827,8 +860,14 @@ def test_compute_running_processes(subtests):
827860
828861def test_nvlink (subtests ):
829862 for device in system .Device .get_all_devices ():
830- with subtests .test (device = device ), unsupported_before (device , None ):
831- for link in range (device .get_nvlink_count ()):
863+ device_index = device .index
864+ link_count = 0
865+ with subtests .test (device_index = device_index , nvlink_api = "get_nvlink_count" ):
866+ with unsupported_before (device , None ):
867+ link_count = device .get_nvlink_count ()
868+
869+ for link in range (link_count ):
870+ with subtests .test (device_index = device_index , nvlink_api = "get_nvlink" , link_index = link ):
832871 with unsupported_before (device , None ):
833872 nvlink_info = device .get_nvlink (link )
834873 assert isinstance (nvlink_info , _device .NvlinkInfo )
@@ -846,7 +885,13 @@ def test_nvlink(subtests):
846885 assert len (version ) == 2
847886 assert all (isinstance (i , int ) for i in version )
848887
849- for nvlink_info in device .get_nvlinks ():
888+ nvlink_infos = []
889+ with subtests .test (device_index = device_index , nvlink_api = "get_nvlinks" ):
890+ with unsupported_before (device , None ):
891+ nvlink_infos = list (device .get_nvlinks ())
892+
893+ for link , nvlink_info in enumerate (nvlink_infos ):
894+ with subtests .test (device_index = device_index , nvlink_api = "get_nvlinks" , link_index = link ):
850895 assert isinstance (nvlink_info , _device .NvlinkInfo )
851896
852897 with unsupported_before (device , None ):
0 commit comments