Skip to content

Commit 8aaa0a3

Browse files
committed
Typecheck tests for methods that modify state
1 parent 15657c4 commit 8aaa0a3

File tree

2 files changed

+214
-1
lines changed

2 files changed

+214
-1
lines changed

src/device.rs

Lines changed: 202 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ impl<'nvml> Device<'nvml> {
6969
Only supports Linux.
7070
*/
7171
// Checked against local
72+
// Tested (no-run)
7273
#[cfg(target_os = "linux")]
7374
#[inline]
7475
pub fn clear_cpu_affinity(&mut self) -> Result<()> {
@@ -479,6 +480,7 @@ impl<'nvml> Device<'nvml> {
479480
Only supports Linux.
480481
*/
481482
// Checked against local
483+
// Tested
482484
// TODO: Should we trim zeros here or leave it to the caller?
483485
#[cfg(target_os = "linux")]
484486
#[inline]
@@ -2005,6 +2007,7 @@ impl<'nvml> Device<'nvml> {
20052007
Only supports Linux.
20062008
*/
20072009
// Checked against local
2010+
// Tested
20082011
#[cfg(target_os = "linux")]
20092012
#[inline]
20102013
pub fn topology_common_ancestor(&self, other_device: Device) -> Result<TopologyLevel> {
@@ -2250,6 +2253,7 @@ impl<'nvml> Device<'nvml> {
22502253
* `Unknown`, on any unexpected error
22512254
*/
22522255
// Checked against local
2256+
// Tested
22532257
#[inline]
22542258
pub fn is_on_same_board_as(&self, other_device: &Device) -> Result<bool> {
22552259
unsafe {
@@ -2287,6 +2291,7 @@ impl<'nvml> Device<'nvml> {
22872291
GeForce devices.
22882292
*/
22892293
// Checked against local
2294+
// Tested (no-run)
22902295
#[inline]
22912296
pub fn reset_applications_clocks(&mut self) -> Result<()> {
22922297
unsafe {
@@ -2324,6 +2329,7 @@ impl<'nvml> Device<'nvml> {
23242329
Supports Kepler and newer fully supported devices.
23252330
*/
23262331
// Checked against local
2332+
// Tested (no-run)
23272333
#[inline]
23282334
pub fn set_auto_boosted_clocks(&mut self, enabled: bool) -> Result<()> {
23292335
unsafe {
@@ -2351,6 +2357,7 @@ impl<'nvml> Device<'nvml> {
23512357
Only supports Linux.
23522358
*/
23532359
// Checked against local
2360+
// Tested (no-run)
23542361
#[cfg(target_os = "linux")]
23552362
#[inline]
23562363
pub fn set_cpu_affinity(&mut self) -> Result<()> {
@@ -2388,10 +2395,11 @@ impl<'nvml> Device<'nvml> {
23882395
GeForce devices.
23892396
*/
23902397
// Checked against local
2398+
// Tested (no-run)
23912399
#[inline]
23922400
pub fn set_auto_boosted_clocks_default(&mut self, enabled: bool) -> Result<()> {
23932401
unsafe {
2394-
// passing 0 because NVIDIA says flags are not supported yet
2402+
// Passing 0 because NVIDIA says flags are not supported yet
23952403
nvml_try(nvmlDeviceSetDefaultAutoBoostedClocksEnabled(self.device,
23962404
state_from_bool(enabled),
23972405
0))
@@ -2440,6 +2448,7 @@ impl<'nvml> Device<'nvml> {
24402448
Supports Kepler and newer fully supported devices.
24412449
*/
24422450
// Checked against local
2451+
// Tested (no-run)
24432452
#[inline]
24442453
pub fn clear_accounting_pids(&mut self) -> Result<()> {
24452454
unsafe {
@@ -2618,6 +2627,7 @@ impl<'nvml> Device<'nvml> {
26182627
Supports Kepler and newer fully supported devices.
26192628
*/
26202629
// Checked against local
2630+
// Tested (no-run)
26212631
#[inline]
26222632
pub fn set_accounting(&mut self, enabled: bool) -> Result<()> {
26232633
unsafe {
@@ -2650,6 +2660,7 @@ impl<'nvml> Device<'nvml> {
26502660
clear all other ECC counts.
26512661
*/
26522662
// Checked against local
2663+
// Tested (no-run)
26532664
#[inline]
26542665
pub fn clear_ecc_error_counts(&mut self, counter_type: EccCounter) -> Result<()> {
26552666
unsafe {
@@ -2679,6 +2690,7 @@ impl<'nvml> Device<'nvml> {
26792690
Supports Kepler and newer fully supported devices.
26802691
*/
26812692
// Checked against local
2693+
// Tested (no-run)
26822694
#[inline]
26832695
pub fn set_api_restricted(&mut self, api_type: Api, restricted: bool) -> Result<()> {
26842696
unsafe {
@@ -2720,6 +2732,7 @@ impl<'nvml> Device<'nvml> {
27202732
GeForce devices.
27212733
*/
27222734
// Checked against local
2735+
// Tested (no-run)
27232736
#[inline]
27242737
pub fn set_applications_clocks(&mut self, mem_clock: u32, graphics_clock: u32) -> Result<()> {
27252738
unsafe {
@@ -2753,6 +2766,7 @@ impl<'nvml> Device<'nvml> {
27532766
* `Unknown`, on any unexpected error
27542767
*/
27552768
// Checked against local
2769+
// Tested (no-run)
27562770
#[inline]
27572771
pub fn set_compute_mode(&mut self, mode: ComputeMode) -> Result<()> {
27582772
unsafe {
@@ -2811,6 +2825,7 @@ impl<'nvml> Device<'nvml> {
28112825
```
28122826
*/
28132827
// Checked against local
2828+
// Tested (no-run)
28142829
#[cfg(target_os = "windows")]
28152830
#[inline]
28162831
pub fn set_driver_model(&mut self, model: DriverModel, flags: Behavior) -> Result<()> {
@@ -2839,6 +2854,7 @@ impl<'nvml> Device<'nvml> {
28392854
1.0 or higher.
28402855
*/
28412856
// Checked against local
2857+
// Tested (no-run)
28422858
#[inline]
28432859
pub fn set_ecc(&mut self, enabled: bool) -> Result<()> {
28442860
unsafe {
@@ -2870,6 +2886,7 @@ impl<'nvml> Device<'nvml> {
28702886
supported on Quadro and Tesla C-class products.
28712887
*/
28722888
// Checked against local
2889+
// Tested (no-run)
28732890
#[inline]
28742891
pub fn set_gpu_op_mode(&mut self, mode: OperationMode) -> Result<()> {
28752892
unsafe {
@@ -2899,6 +2916,7 @@ impl<'nvml> Device<'nvml> {
28992916
Only supports Linux.
29002917
*/
29012918
// Checked against local
2919+
// Tested (no-run)
29022920
#[cfg(target_os = "linux")]
29032921
#[inline]
29042922
pub fn set_persistent(&mut self, enabled: bool) -> Result<()> {
@@ -2930,6 +2948,7 @@ impl<'nvml> Device<'nvml> {
29302948
Supports Kepler and newer fully supported devices.
29312949
*/
29322950
// Checked against local
2951+
// Tested (no-run)
29332952
#[inline]
29342953
pub fn set_power_management_limit(&mut self, limit: u32) -> Result<()> {
29352954
unsafe {
@@ -3395,6 +3414,15 @@ mod test {
33953414
assert_sync::<Device>()
33963415
}
33973416

3417+
// This modifies device state, so we don't want to actually run the test
3418+
#[allow(dead_code)]
3419+
fn clear_cpu_affinity() {
3420+
let nvml = nvml();
3421+
let mut device = device(&nvml);
3422+
3423+
device.clear_cpu_affinity().unwrap();
3424+
}
3425+
33983426
#[test]
33993427
fn is_api_restricted() {
34003428
let nvml = nvml();
@@ -4011,6 +4039,17 @@ mod test {
40114039
})
40124040
}
40134041

4042+
// I do not have 2 devices
4043+
#[cfg(not(feature = "test-local"))]
4044+
#[test]
4045+
fn topology_common_ancestor() {
4046+
let nvml = nvml();
4047+
let device1 = device(&nvml);
4048+
let device2 = nvml.device_by_index(1).expect("device");
4049+
4050+
device1.topology_common_ancestor(device2).expect("TopologyLevel");
4051+
}
4052+
40144053
#[cfg(target_os = "linux")]
40154054
#[test]
40164055
fn topology_nearest_gpus() {
@@ -4063,6 +4102,57 @@ mod test {
40634102
})
40644103
}
40654104

4105+
// I do not have 2 devices
4106+
#[cfg(not(feature = "test-local"))]
4107+
#[test]
4108+
fn is_on_same_board_as() {
4109+
let nvml = nvml();
4110+
let device1 = device(&nvml);
4111+
let device2 = nvml.device_by_index(1).expect("device");
4112+
4113+
device1.is_on_same_board_as(&device2).expect("bool");
4114+
}
4115+
4116+
// This modifies device state, so we don't want to actually run the test
4117+
#[allow(dead_code)]
4118+
#[deny(unused_mut)]
4119+
fn reset_applications_clocks() {
4120+
let nvml = nvml();
4121+
let mut device = device(&nvml);
4122+
4123+
device.reset_applications_clocks().expect("reset clocks")
4124+
}
4125+
4126+
// This modifies device state, so we don't want to actually run the test
4127+
#[allow(dead_code)]
4128+
#[deny(unused_mut)]
4129+
fn set_auto_boosted_clocks() {
4130+
let nvml = nvml();
4131+
let mut device = device(&nvml);
4132+
4133+
device.set_auto_boosted_clocks(true).expect("set to true")
4134+
}
4135+
4136+
// This modifies device state, so we don't want to actually run the test
4137+
#[allow(dead_code)]
4138+
#[deny(unused_mut)]
4139+
fn set_cpu_affinity() {
4140+
let nvml = nvml();
4141+
let mut device = device(&nvml);
4142+
4143+
device.set_cpu_affinity().expect("ideal affinity set")
4144+
}
4145+
4146+
// This modifies device state, so we don't want to actually run the test
4147+
#[allow(dead_code)]
4148+
#[deny(unused_mut)]
4149+
fn set_auto_boosted_clocks_default() {
4150+
let nvml = nvml();
4151+
let mut device = device(&nvml);
4152+
4153+
device.set_auto_boosted_clocks_default(true).expect("set to true")
4154+
}
4155+
40664156
// My machine does not support this call
40674157
#[cfg(not(feature = "test-local"))]
40684158
#[test]
@@ -4073,6 +4163,16 @@ mod test {
40734163
})
40744164
}
40754165

4166+
// This modifies device state, so we don't want to actually run the test
4167+
#[allow(dead_code)]
4168+
#[deny(unused_mut)]
4169+
fn clear_accounting_pids() {
4170+
let nvml = nvml();
4171+
let mut device = device(&nvml);
4172+
4173+
device.clear_accounting_pids().expect("cleared")
4174+
}
4175+
40764176
#[test]
40774177
fn accounting_buffer_size() {
40784178
let nvml = nvml();
@@ -4112,6 +4212,107 @@ mod test {
41124212
})
41134213
}
41144214

4215+
// This modifies device state, so we don't want to actually run the test
4216+
#[allow(dead_code)]
4217+
#[deny(unused_mut)]
4218+
fn set_accounting() {
4219+
let nvml = nvml();
4220+
let mut device = device(&nvml);
4221+
4222+
device.set_accounting(true).expect("set to true")
4223+
}
4224+
4225+
// This modifies device state, so we don't want to actually run the test
4226+
#[allow(dead_code)]
4227+
#[deny(unused_mut)]
4228+
fn clear_ecc_error_counts() {
4229+
let nvml = nvml();
4230+
let mut device = device(&nvml);
4231+
4232+
device.clear_ecc_error_counts(EccCounter::Aggregate).expect("set to true")
4233+
}
4234+
4235+
// This modifies device state, so we don't want to actually run the test
4236+
#[allow(dead_code)]
4237+
#[deny(unused_mut)]
4238+
fn set_api_restricted() {
4239+
let nvml = nvml();
4240+
let mut device = device(&nvml);
4241+
4242+
device.set_api_restricted(Api::ApplicationClocks, true).expect("set to true")
4243+
}
4244+
4245+
// This modifies device state, so we don't want to actually run the test
4246+
#[allow(dead_code)]
4247+
#[deny(unused_mut)]
4248+
fn set_applications_clocks() {
4249+
let nvml = nvml();
4250+
let mut device = device(&nvml);
4251+
4252+
device.set_applications_clocks(32, 32).expect("set to true")
4253+
}
4254+
4255+
// This modifies device state, so we don't want to actually run the test
4256+
#[allow(dead_code)]
4257+
#[deny(unused_mut)]
4258+
fn set_compute_mode() {
4259+
let nvml = nvml();
4260+
let mut device = device(&nvml);
4261+
4262+
device.set_compute_mode(ComputeMode::Default).expect("set to true")
4263+
}
4264+
4265+
// This modifies device state, so we don't want to actually run the test
4266+
#[cfg(target_os = "windows")]
4267+
#[allow(dead_code)]
4268+
#[deny(unused_mut)]
4269+
fn set_driver_model() {
4270+
let nvml = nvml();
4271+
let mut device = device(&nvml);
4272+
4273+
device.set_driver_model(EccCounter::Aggregate).expect("set to true")
4274+
}
4275+
4276+
// This modifies device state, so we don't want to actually run the test
4277+
#[allow(dead_code)]
4278+
#[deny(unused_mut)]
4279+
fn set_ecc() {
4280+
let nvml = nvml();
4281+
let mut device = device(&nvml);
4282+
4283+
device.set_ecc(true).expect("set to true")
4284+
}
4285+
4286+
// This modifies device state, so we don't want to actually run the test
4287+
#[allow(dead_code)]
4288+
#[deny(unused_mut)]
4289+
fn set_gpu_op_mode() {
4290+
let nvml = nvml();
4291+
let mut device = device(&nvml);
4292+
4293+
device.set_gpu_op_mode(OperationMode::AllOn).expect("set to true")
4294+
}
4295+
4296+
// This modifies device state, so we don't want to actually run the test
4297+
#[allow(dead_code)]
4298+
#[deny(unused_mut)]
4299+
fn set_persistent() {
4300+
let nvml = nvml();
4301+
let mut device = device(&nvml);
4302+
4303+
device.set_persistent(true).expect("set to true")
4304+
}
4305+
4306+
// This modifies device state, so we don't want to actually run the test
4307+
#[allow(dead_code)]
4308+
#[deny(unused_mut)]
4309+
fn set_power_management_limit() {
4310+
let nvml = nvml();
4311+
let mut device = device(&nvml);
4312+
4313+
device.set_power_management_limit(250000).expect("set to true")
4314+
}
4315+
41154316
#[cfg(target_os = "linux")]
41164317
#[allow(unused_variables)]
41174318
#[test]

0 commit comments

Comments
 (0)