mirror of
https://gitlab.steamos.cloud/holo/steamos-manager.git
synced 2025-07-12 01:12:30 -04:00
manager: Add get/set_gpu_performance_level tests
This commit is contained in:
parent
9ddbc9997d
commit
3c62c57d52
2 changed files with 54 additions and 11 deletions
|
@ -403,7 +403,7 @@ impl SteamOSManager {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::testing;
|
use crate::{power, testing};
|
||||||
use tokio::fs::{create_dir_all, write};
|
use tokio::fs::{create_dir_all, write};
|
||||||
use zbus::connection::Connection;
|
use zbus::connection::Connection;
|
||||||
use zbus::ConnectionBuilder;
|
use zbus::ConnectionBuilder;
|
||||||
|
@ -413,7 +413,7 @@ mod test {
|
||||||
connection: Connection,
|
connection: Connection,
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn start() -> TestHandle {
|
async fn start(name: &str) -> TestHandle {
|
||||||
let handle = testing::start();
|
let handle = testing::start();
|
||||||
create_dir_all(crate::path("/sys/class/dmi/id"))
|
create_dir_all(crate::path("/sys/class/dmi/id"))
|
||||||
.await
|
.await
|
||||||
|
@ -436,7 +436,7 @@ mod test {
|
||||||
|
|
||||||
let connection = ConnectionBuilder::session()
|
let connection = ConnectionBuilder::session()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.name("com.steampowered.SteamOSManager1.Test")
|
.name(format!("com.steampowered.SteamOSManager1.Test.{name}"))
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.build()
|
.build()
|
||||||
.await
|
.await
|
||||||
|
@ -453,7 +453,46 @@ mod test {
|
||||||
|
|
||||||
#[zbus::proxy(
|
#[zbus::proxy(
|
||||||
interface = "com.steampowered.SteamOSManager1.Manager",
|
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"
|
default_path = "/com/steampowered/SteamOSManager1"
|
||||||
)]
|
)]
|
||||||
trait Version {
|
trait Version {
|
||||||
|
@ -463,7 +502,7 @@ mod test {
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn version() {
|
async fn version() {
|
||||||
let test = start().await;
|
let test = start("Version").await;
|
||||||
let proxy = VersionProxy::new(&test.connection).await.unwrap();
|
let proxy = VersionProxy::new(&test.connection).await.unwrap();
|
||||||
assert_eq!(proxy.version().await, Ok(SteamOSManager::API_VERSION));
|
assert_eq!(proxy.version().await, Ok(SteamOSManager::API_VERSION));
|
||||||
}
|
}
|
||||||
|
|
16
src/power.rs
16
src/power.rs
|
@ -197,6 +197,14 @@ pub async fn set_tdp_limit(limit: u32) -> Result<()> {
|
||||||
Ok(())
|
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)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
@ -209,9 +217,7 @@ mod test {
|
||||||
let h = testing::start();
|
let h = testing::start();
|
||||||
|
|
||||||
let filename = path(GPU_PERFORMANCE_LEVEL_PATH);
|
let filename = path(GPU_PERFORMANCE_LEVEL_PATH);
|
||||||
create_dir_all(filename.parent().unwrap())
|
setup_test().await;
|
||||||
.await
|
|
||||||
.expect("create_dir_all");
|
|
||||||
assert!(get_gpu_performance_level().await.is_err());
|
assert!(get_gpu_performance_level().await.is_err());
|
||||||
|
|
||||||
write(filename.as_path(), "auto\n").await.expect("write");
|
write(filename.as_path(), "auto\n").await.expect("write");
|
||||||
|
@ -255,9 +261,7 @@ mod test {
|
||||||
let h = testing::start();
|
let h = testing::start();
|
||||||
|
|
||||||
let filename = path(GPU_PERFORMANCE_LEVEL_PATH);
|
let filename = path(GPU_PERFORMANCE_LEVEL_PATH);
|
||||||
create_dir_all(filename.parent().unwrap())
|
setup_test().await;
|
||||||
.await
|
|
||||||
.expect("create_dir_all");
|
|
||||||
|
|
||||||
set_gpu_performance_level(GPUPerformanceLevel::Auto)
|
set_gpu_performance_level(GPUPerformanceLevel::Auto)
|
||||||
.await
|
.await
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue