Skip to content

Commit

Permalink
feat: use boxed slice for fan curve, more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ilya-zlobintsev committed Jan 20, 2024
1 parent 7d88bef commit 0d270af
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/gpu_handle/fan_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ pub struct FanInfo {
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct FanCurve {
/// Fan curve points in the (temperature, speed) format
pub points: Vec<(i32, u8)>,
/// This is a boxed slice as the number of curve points cannot be modified, only their values can be.
pub points: Box<[(i32, u8)]>,
/// Allowed value ranges.
/// Empty when changes to the fan curve are not supported.
pub allowed_ranges: Option<FanCurveRanges>,
Expand Down
2 changes: 1 addition & 1 deletion tests/rx7800xt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ test_with_handle! {
},
get_fan_curve => {
GpuHandle::get_fan_curve,
Ok(FanCurve { points: vec![(0, 0); 5], allowed_ranges: Some(FanCurveRanges {temperature_range: 25..=100, speed_range: 20..=100 })})
Ok(FanCurve { points: vec![(0, 0); 5].into_boxed_slice(), allowed_ranges: Some(FanCurveRanges {temperature_range: 25..=100, speed_range: 20..=100 })})
}
}
25 changes: 24 additions & 1 deletion tests/rx7900xt.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(clippy::redundant_closure_call)]
mod sysfs;

use amdgpu_sysfs::gpu_handle::{
Expand Down Expand Up @@ -25,6 +26,28 @@ test_with_handle! {
},
get_fan_curve => {
GpuHandle::get_fan_curve,
Ok(FanCurve { points: vec![(0, 0); 5], allowed_ranges: Some(FanCurveRanges {temperature_range: 25..=100, speed_range: 15..=100 })})
Ok(FanCurve { points: vec![(0, 0); 5].into_boxed_slice(), allowed_ranges: Some(FanCurveRanges {temperature_range: 25..=100, speed_range: 15..=100 })})
},
set_invalid_fan_curve => {
|gpu_handle: &GpuHandle| {
let mut curve = gpu_handle.get_fan_curve().unwrap();
curve.points[0].0 = 5;
curve.points[0].1 = 0;
gpu_handle.set_fan_curve(&curve).unwrap_err().to_string()
},
"not allowed: Temperature value 5 is outside of the allowed range 25..=100",
},

set_valid_fan_curve => {
|gpu_handle: &GpuHandle| {
let mut curve = gpu_handle.get_fan_curve().unwrap();
curve.points[0] = (25, 15);
curve.points[1] = (40, 30);
curve.points[2] = (60, 65);
curve.points[3] = (70, 80);
curve.points[4] = (85, 100);
gpu_handle.set_fan_curve(&curve)
},
Ok(())
}
}

0 comments on commit 0d270af

Please sign in to comment.