manager: Add get/set_gpu_performance_level tests

This commit is contained in:
Vicki Pfau 2024-04-02 19:02:19 -07:00
parent 9ddbc9997d
commit 3c62c57d52
2 changed files with 54 additions and 11 deletions

View file

@ -403,7 +403,7 @@ impl SteamOSManager {
#[cfg(test)]
mod test {
use super::*;
use crate::testing;
use crate::{power, testing};
use tokio::fs::{create_dir_all, write};
use zbus::connection::Connection;
use zbus::ConnectionBuilder;
@ -413,7 +413,7 @@ mod test {
connection: Connection,
}
async fn start() -> TestHandle {
async fn start(name: &str) -> TestHandle {
let handle = testing::start();
create_dir_all(crate::path("/sys/class/dmi/id"))
.await
@ -436,7 +436,7 @@ mod test {
let connection = ConnectionBuilder::session()
.unwrap()
.name("com.steampowered.SteamOSManager1.Test")
.name(format!("com.steampowered.SteamOSManager1.Test.{name}"))
.unwrap()
.build()
.await
@ -453,7 +453,46 @@ mod test {
#[zbus::proxy(
interface = "com.steampowered.SteamOSManager1.Manager",
default_service = "com.steampowered.SteamOSManager1.Test",
default_service = "com.steampowered.SteamOSManager1.Test.GPUPerformanceLevel",
default_path = "/com/steampowered/SteamOSManager1"
)]
trait GPUPerformanceLevel {
#[zbus(property)]
fn gpu_performance_level(&self) -> zbus::Result<u32>;
#[zbus(property)]
fn set_gpu_performance_level(&self, level: u32) -> zbus::Result<()>;
}
#[tokio::test]
async fn gpu_performance_level() {
let test = start("GPUPerformanceLevel").await;
power::setup_test().await;
let proxy = GPUPerformanceLevelProxy::new(&test.connection)
.await
.unwrap();
set_gpu_performance_level(GPUPerformanceLevel::Auto)
.await
.expect("set");
assert_eq!(
proxy.gpu_performance_level().await.unwrap(),
GPUPerformanceLevel::Auto as u32
);
proxy
.set_gpu_performance_level(GPUPerformanceLevel::Low as u32)
.await
.expect("proxy_set");
assert_eq!(
get_gpu_performance_level().await.unwrap(),
GPUPerformanceLevel::Low
);
}
#[zbus::proxy(
interface = "com.steampowered.SteamOSManager1.Manager",
default_service = "com.steampowered.SteamOSManager1.Test.Version",
default_path = "/com/steampowered/SteamOSManager1"
)]
trait Version {
@ -463,7 +502,7 @@ mod test {
#[tokio::test]
async fn version() {
let test = start().await;
let test = start("Version").await;
let proxy = VersionProxy::new(&test.connection).await.unwrap();
assert_eq!(proxy.version().await, Ok(SteamOSManager::API_VERSION));
}

View file

@ -197,6 +197,14 @@ pub async fn set_tdp_limit(limit: u32) -> Result<()> {
Ok(())
}
#[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 {
use super::*;
@ -209,9 +217,7 @@ mod test {
let h = testing::start();
let filename = path(GPU_PERFORMANCE_LEVEL_PATH);
create_dir_all(filename.parent().unwrap())
.await
.expect("create_dir_all");
setup_test().await;
assert!(get_gpu_performance_level().await.is_err());
write(filename.as_path(), "auto\n").await.expect("write");
@ -255,9 +261,7 @@ mod test {
let h = testing::start();
let filename = path(GPU_PERFORMANCE_LEVEL_PATH);
create_dir_all(filename.parent().unwrap())
.await
.expect("create_dir_all");
setup_test().await;
set_gpu_performance_level(GPUPerformanceLevel::Auto)
.await