mirror of
https://gitlab.steamos.cloud/holo/steamos-manager.git
synced 2025-07-09 16:10:34 -04:00
manager: Add manual_gpu_clock tests
This commit is contained in:
parent
8b59bd3a39
commit
cf4d7b9ba9
2 changed files with 77 additions and 36 deletions
|
@ -277,7 +277,7 @@ impl SteamOSManager {
|
|||
.map_err(anyhow_to_zbus)
|
||||
}
|
||||
|
||||
#[zbus(property, name = "ManualGPUClock")]
|
||||
#[zbus(property(emits_changed_signal = "false"), name = "ManualGPUClock")]
|
||||
async fn manual_gpu_clock(&self) -> zbus::fdo::Result<u32> {
|
||||
get_gpu_clocks().await.map_err(anyhow_to_zbus_fdo)
|
||||
}
|
||||
|
@ -467,7 +467,7 @@ mod test {
|
|||
#[tokio::test]
|
||||
async fn gpu_performance_level() {
|
||||
let test = start("GPUPerformanceLevel").await;
|
||||
power::setup_test().await;
|
||||
power::test::setup().await;
|
||||
|
||||
let proxy = GPUPerformanceLevelProxy::new(&test.connection)
|
||||
.await
|
||||
|
@ -490,6 +490,37 @@ mod test {
|
|||
);
|
||||
}
|
||||
|
||||
#[zbus::proxy(
|
||||
interface = "com.steampowered.SteamOSManager1.Manager",
|
||||
default_service = "com.steampowered.SteamOSManager1.Test.ManualGPUClock",
|
||||
default_path = "/com/steampowered/SteamOSManager1"
|
||||
)]
|
||||
trait ManualGPUClock {
|
||||
#[zbus(property, name = "ManualGPUClock")]
|
||||
fn manual_gpu_clock(&self) -> zbus::Result<u32>;
|
||||
|
||||
#[zbus(property, name = "ManualGPUClock")]
|
||||
fn set_manual_gpu_clock(&self, clocks: u32) -> zbus::Result<()>;
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn manual_gpu_clock() {
|
||||
let test = start("ManualGPUClock").await;
|
||||
|
||||
let proxy = ManualGPUClockProxy::new(&test.connection).await.unwrap();
|
||||
|
||||
assert!(proxy.manual_gpu_clock().await.is_err());
|
||||
|
||||
power::test::write_clocks(1600).await;
|
||||
assert_eq!(proxy.manual_gpu_clock().await.unwrap(), 1600);
|
||||
|
||||
proxy.set_manual_gpu_clock(200).await.expect("proxy_set");
|
||||
power::test::expect_clocks(200);
|
||||
|
||||
assert!(proxy.set_manual_gpu_clock(100).await.is_err());
|
||||
power::test::expect_clocks(200);
|
||||
}
|
||||
|
||||
#[zbus::proxy(
|
||||
interface = "com.steampowered.SteamOSManager1.Manager",
|
||||
default_service = "com.steampowered.SteamOSManager1.Test.Version",
|
||||
|
|
78
src/power.rs
78
src/power.rs
|
@ -201,26 +201,51 @@ pub async fn set_tdp_limit(limit: u32) -> Result<()> {
|
|||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub async fn setup_test() {
|
||||
let filename = path(GPU_PERFORMANCE_LEVEL_PATH);
|
||||
fs::create_dir_all(filename.parent().unwrap())
|
||||
.await
|
||||
.expect("create_dir_all");
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
pub mod test {
|
||||
use super::*;
|
||||
use crate::testing;
|
||||
use anyhow::anyhow;
|
||||
use tokio::fs::{create_dir_all, read_to_string, remove_dir, write};
|
||||
|
||||
pub async fn setup() {
|
||||
let filename = path(GPU_PERFORMANCE_LEVEL_PATH);
|
||||
create_dir_all(filename.parent().unwrap())
|
||||
.await
|
||||
.expect("create_dir_all");
|
||||
}
|
||||
|
||||
pub async fn write_clocks(mhz: u32) {
|
||||
let filename = path(GPU_CLOCKS_PATH);
|
||||
create_dir_all(filename.parent().unwrap())
|
||||
.await
|
||||
.expect("create_dir_all");
|
||||
|
||||
let contents = format!(
|
||||
"OD_SCLK:
|
||||
0: {mhz}Mhz
|
||||
1: {mhz}Mhz
|
||||
OD_RANGE:
|
||||
SCLK: 200Mhz 1600Mhz
|
||||
CCLK: 1400Mhz 3500Mhz
|
||||
CCLK_RANGE in Core0:
|
||||
0: 1400Mhz
|
||||
1: 3500Mhz\n"
|
||||
);
|
||||
|
||||
write(filename.as_path(), contents).await.expect("write");
|
||||
}
|
||||
|
||||
pub async fn expect_clocks(mhz: u32) {
|
||||
let clocks = read_to_string(path(GPU_CLOCKS_PATH)).await.expect("read");
|
||||
assert_eq!(clocks, format!("s 0 {mhz}\ns 1 {mhz}\nc\n"));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_get_gpu_performance_level() {
|
||||
let h = testing::start();
|
||||
|
||||
let filename = path(GPU_PERFORMANCE_LEVEL_PATH);
|
||||
setup_test().await;
|
||||
setup().await;
|
||||
assert!(get_gpu_performance_level().await.is_err());
|
||||
|
||||
write(filename.as_path(), "auto\n").await.expect("write");
|
||||
|
@ -264,7 +289,7 @@ mod test {
|
|||
let h = testing::start();
|
||||
|
||||
let filename = path(GPU_PERFORMANCE_LEVEL_PATH);
|
||||
setup_test().await;
|
||||
setup().await;
|
||||
|
||||
set_gpu_performance_level(GPUPerformanceLevel::Auto)
|
||||
.await
|
||||
|
@ -314,7 +339,9 @@ mod test {
|
|||
|
||||
assert!(get_tdp_limit().await.is_err());
|
||||
|
||||
write(hwmon.join("hwmon5").join(TDP_LIMIT1), "15000000").await.expect("write");
|
||||
write(hwmon.join("hwmon5").join(TDP_LIMIT1), "15000000")
|
||||
.await
|
||||
.expect("write");
|
||||
assert_eq!(get_tdp_limit().await.unwrap(), 15);
|
||||
}
|
||||
|
||||
|
@ -381,21 +408,11 @@ mod test {
|
|||
#[tokio::test]
|
||||
async fn test_get_gpu_clocks() {
|
||||
let h = testing::start();
|
||||
|
||||
const contents: &str = "OD_SCLK:
|
||||
0: 1600Mhz
|
||||
1: 1600Mhz
|
||||
OD_RANGE:
|
||||
SCLK: 200Mhz 1600Mhz
|
||||
CCLK: 1400Mhz 3500Mhz
|
||||
CCLK_RANGE in Core0:
|
||||
0: 1400Mhz
|
||||
1: 3500Mhz\n";
|
||||
let filename = path(GPU_PERFORMANCE_LEVEL_PATH);
|
||||
setup_test().await;
|
||||
setup().await;
|
||||
|
||||
assert!(get_gpu_clocks().await.is_err());
|
||||
write(path(GPU_CLOCKS_PATH), contents).await.expect("write");
|
||||
write_clocks(1600).await;
|
||||
|
||||
assert_eq!(get_gpu_clocks().await.unwrap(), 1600);
|
||||
}
|
||||
|
@ -404,23 +421,16 @@ CCLK_RANGE in Core0:
|
|||
async fn test_set_gpu_clocks() {
|
||||
let h = testing::start();
|
||||
|
||||
let filename = path(GPU_CLOCKS_PATH);
|
||||
assert!(set_gpu_clocks(1600).await.is_err());
|
||||
setup_test().await;
|
||||
setup().await;
|
||||
|
||||
assert!(set_gpu_clocks(100).await.is_err());
|
||||
assert!(set_gpu_clocks(2000).await.is_err());
|
||||
|
||||
assert!(set_gpu_clocks(200).await.is_ok());
|
||||
assert_eq!(
|
||||
read_to_string(filename.as_path()).await.expect("string"),
|
||||
"s 0 200\ns 1 200\nc\n"
|
||||
);
|
||||
expect_clocks(200).await;
|
||||
|
||||
assert!(set_gpu_clocks(1600).await.is_ok());
|
||||
assert_eq!(
|
||||
read_to_string(filename.as_path()).await.expect("string"),
|
||||
"s 0 1600\ns 1 1600\nc\n"
|
||||
);
|
||||
expect_clocks(1600).await;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue