@@ -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 ):
@@ -690,32 +703,52 @@ def test_cooler(subtests):
690703
691704def test_temperature (subtests ):
692705 for device in system .Device .get_all_devices ():
693- with subtests .test (device = device ):
706+ device_index = device .index
707+ temperature = None
708+ with subtests .test (device_index = device_index , temperature_api = "temperature" ):
694709 temperature = device .temperature
695710 assert isinstance (temperature , _device .Temperature )
711+ if temperature is None :
712+ continue
696713
714+ with subtests .test (device_index = device_index , temperature_api = "get_sensor" ):
697715 sensor = temperature .get_sensor ()
698716 assert isinstance (sensor , int )
699717 assert sensor >= 0
700718
701- # By docs, should be supported on KEPLER or newer, but experimentally,
702- # is also unsupported on other hardware.
703- with unsupported_before (device , None ):
704- for threshold in list (typing .TemperatureThresholds ):
719+ # By docs, should be supported on KEPLER or newer, but experimentally,
720+ # is also unsupported on other hardware.
721+ for threshold in typing .TemperatureThresholds :
722+ with subtests .test (
723+ device_index = device_index ,
724+ temperature_api = "get_threshold" ,
725+ threshold = threshold .value ,
726+ ):
727+ with unsupported_before (device , None ):
705728 t = temperature .get_threshold (threshold )
706- assert isinstance (t , int )
707- assert t >= 0
729+ assert isinstance (t , int )
730+ assert t >= 0
708731
732+ with subtests .test (device_index = device_index , temperature_api = "margin" ):
709733 with unsupported_before (device , None ):
710734 margin = temperature .margin
711735 assert isinstance (margin , int )
712736 assert margin >= 0
713737
738+ thermals = None
739+ with subtests .test (device_index = device_index , temperature_api = "get_thermal_settings" ):
714740 with unsupported_before (device , None ):
715741 thermals = temperature .get_thermal_settings (typing .ThermalTarget .ALL )
716742 assert isinstance (thermals , _device .ThermalSettings )
743+ if thermals is None :
744+ continue
717745
718- for i , sensor in enumerate (thermals ):
746+ for i , sensor in enumerate (thermals ):
747+ with subtests .test (
748+ device_index = device_index ,
749+ temperature_api = "thermal_sensor" ,
750+ sensor_index = i ,
751+ ):
719752 assert isinstance (sensor , _device .ThermalSensor )
720753 assert isinstance (sensor .target , typing .ThermalTarget )
721754 assert isinstance (sensor .controller , typing .ThermalController )
@@ -804,8 +837,14 @@ def test_compute_running_processes(subtests):
804837
805838def test_nvlink (subtests ):
806839 for device in system .Device .get_all_devices ():
807- with subtests .test (device = device ), unsupported_before (device , None ):
808- for link in range (device .get_nvlink_count ()):
840+ device_index = device .index
841+ link_count = 0
842+ with subtests .test (device_index = device_index , nvlink_api = "get_nvlink_count" ):
843+ with unsupported_before (device , None ):
844+ link_count = device .get_nvlink_count ()
845+
846+ for link in range (link_count ):
847+ with subtests .test (device_index = device_index , nvlink_api = "get_nvlink" , link_index = link ):
809848 with unsupported_before (device , None ):
810849 nvlink_info = device .get_nvlink (link )
811850 assert isinstance (nvlink_info , _device .NvlinkInfo )
@@ -823,7 +862,13 @@ def test_nvlink(subtests):
823862 assert len (version ) == 2
824863 assert all (isinstance (i , int ) for i in version )
825864
826- for nvlink_info in device .get_nvlinks ():
865+ nvlink_infos = []
866+ with subtests .test (device_index = device_index , nvlink_api = "get_nvlinks" ):
867+ with unsupported_before (device , None ):
868+ nvlink_infos = list (device .get_nvlinks ())
869+
870+ for link , nvlink_info in enumerate (nvlink_infos ):
871+ with subtests .test (device_index = device_index , nvlink_api = "get_nvlinks" , link_index = link ):
827872 assert isinstance (nvlink_info , _device .NvlinkInfo )
828873
829874 with unsupported_before (device , None ):
0 commit comments