power: Fix get_tdp_limit not handling trailing newline

This commit is contained in:
Vicki Pfau 2024-04-05 14:59:03 -07:00
parent 0142f1199f
commit 92817223d5

View file

@ -170,7 +170,7 @@ async fn find_hwmon() -> Result<PathBuf> {
pub async fn get_tdp_limit() -> Result<u32> { pub async fn get_tdp_limit() -> Result<u32> {
let base = find_hwmon().await?; let base = find_hwmon().await?;
let power1cap = fs::read_to_string(base.join(TDP_LIMIT1)).await?; let power1cap = fs::read_to_string(base.join(TDP_LIMIT1)).await?;
let power1cap: u32 = power1cap.parse()?; let power1cap: u32 = power1cap.trim_end().parse()?;
Ok(power1cap / 1000000) Ok(power1cap / 1000000)
} }
@ -339,7 +339,7 @@ CCLK_RANGE in Core0:
assert!(get_tdp_limit().await.is_err()); assert!(get_tdp_limit().await.is_err());
write(hwmon.join("hwmon5").join(TDP_LIMIT1), "15000000") write(hwmon.join("hwmon5").join(TDP_LIMIT1), "15000000\n")
.await .await
.expect("write"); .expect("write");
assert_eq!(get_tdp_limit().await.unwrap(), 15); assert_eq!(get_tdp_limit().await.unwrap(), 15);