mirror of
https://gitlab.steamos.cloud/holo/steamos-manager.git
synced 2025-07-12 09:22:26 -04:00
Fix test build warnings
This commit is contained in:
parent
cb04cd2cf4
commit
cf962b26c5
7 changed files with 82 additions and 59 deletions
|
@ -302,14 +302,14 @@ mod test {
|
||||||
use tokio::time::sleep;
|
use tokio::time::sleep;
|
||||||
|
|
||||||
async fn nyield(times: u32) {
|
async fn nyield(times: u32) {
|
||||||
for i in 0..times {
|
for _ in 0..times {
|
||||||
sleep(Duration::from_millis(1)).await;
|
sleep(Duration::from_millis(1)).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn hid_nodes() {
|
async fn hid_nodes() {
|
||||||
let h = testing::start();
|
let _h = testing::start();
|
||||||
|
|
||||||
let hid = HidNode::new(0);
|
let hid = HidNode::new(0);
|
||||||
let sys_base = hid.sys_base();
|
let sys_base = hid.sys_base();
|
||||||
|
@ -326,7 +326,7 @@ mod test {
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn hid_can_inhibit() {
|
async fn hid_can_inhibit() {
|
||||||
let h = testing::start();
|
let _h = testing::start();
|
||||||
|
|
||||||
let hids = [
|
let hids = [
|
||||||
HidNode::new(0),
|
HidNode::new(0),
|
||||||
|
@ -363,7 +363,7 @@ mod test {
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn hid_inhibit() {
|
async fn hid_inhibit() {
|
||||||
let h = testing::start();
|
let _h = testing::start();
|
||||||
|
|
||||||
let hid = HidNode::new(0);
|
let hid = HidNode::new(0);
|
||||||
let sys_base = hid.sys_base();
|
let sys_base = hid.sys_base();
|
||||||
|
@ -373,12 +373,12 @@ mod test {
|
||||||
|
|
||||||
assert!(hid.can_inhibit().await);
|
assert!(hid.can_inhibit().await);
|
||||||
|
|
||||||
hid.inhibit().await;
|
hid.inhibit().await.expect("inhibit");
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
read_to_string(sys_base.join("input/input0/inhibited")).expect("inhibited"),
|
read_to_string(sys_base.join("input/input0/inhibited")).expect("inhibited"),
|
||||||
"1\n"
|
"1\n"
|
||||||
);
|
);
|
||||||
hid.uninhibit().await;
|
hid.uninhibit().await.expect("uninhibit");
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
read_to_string(sys_base.join("input/input0/inhibited")).expect("inhibited"),
|
read_to_string(sys_base.join("input/input0/inhibited")).expect("inhibited"),
|
||||||
"0\n"
|
"0\n"
|
||||||
|
@ -387,7 +387,7 @@ mod test {
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn hid_inhibit_error_continue() {
|
async fn hid_inhibit_error_continue() {
|
||||||
let h = testing::start();
|
let _h = testing::start();
|
||||||
|
|
||||||
let hid = HidNode::new(0);
|
let hid = HidNode::new(0);
|
||||||
let sys_base = hid.sys_base();
|
let sys_base = hid.sys_base();
|
||||||
|
@ -399,12 +399,12 @@ mod test {
|
||||||
|
|
||||||
assert!(hid.can_inhibit().await);
|
assert!(hid.can_inhibit().await);
|
||||||
|
|
||||||
hid.inhibit().await;
|
assert!(hid.inhibit().await.is_err());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
read_to_string(sys_base.join("input/input1/inhibited")).expect("inhibited"),
|
read_to_string(sys_base.join("input/input1/inhibited")).expect("inhibited"),
|
||||||
"1\n"
|
"1\n"
|
||||||
);
|
);
|
||||||
hid.uninhibit().await;
|
assert!(hid.uninhibit().await.is_err());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
read_to_string(sys_base.join("input/input1/inhibited")).expect("inhibited"),
|
read_to_string(sys_base.join("input/input1/inhibited")).expect("inhibited"),
|
||||||
"0\n"
|
"0\n"
|
||||||
|
@ -496,7 +496,7 @@ mod test {
|
||||||
|
|
||||||
let mut inhibitor = Inhibitor::init().await.expect("init");
|
let mut inhibitor = Inhibitor::init().await.expect("init");
|
||||||
let task = tokio::spawn(async move {
|
let task = tokio::spawn(async move {
|
||||||
inhibitor.run().await;
|
inhibitor.run().await.expect("run");
|
||||||
});
|
});
|
||||||
|
|
||||||
nyield(1).await;
|
nyield(1).await;
|
||||||
|
@ -540,7 +540,7 @@ mod test {
|
||||||
|
|
||||||
let mut inhibitor = Inhibitor::init().await.expect("init");
|
let mut inhibitor = Inhibitor::init().await.expect("init");
|
||||||
let task = tokio::spawn(async move {
|
let task = tokio::spawn(async move {
|
||||||
inhibitor.run().await;
|
inhibitor.run().await.expect("run");
|
||||||
});
|
});
|
||||||
|
|
||||||
nyield(1).await;
|
nyield(1).await;
|
||||||
|
@ -548,7 +548,7 @@ mod test {
|
||||||
|
|
||||||
File::create(hid.hidraw()).expect("hidraw");
|
File::create(hid.hidraw()).expect("hidraw");
|
||||||
symlink(hid.hidraw(), path.join("proc/1/fd/3")).expect("symlink");
|
symlink(hid.hidraw(), path.join("proc/1/fd/3")).expect("symlink");
|
||||||
let f = File::open(hid.hidraw()).expect("hidraw");
|
let _f = File::open(hid.hidraw()).expect("hidraw");
|
||||||
nyield(4).await;
|
nyield(4).await;
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
read_to_string(sys_base.join("input/input0/inhibited")).expect("inhibited"),
|
read_to_string(sys_base.join("input/input0/inhibited")).expect("inhibited"),
|
||||||
|
@ -560,21 +560,20 @@ mod test {
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn inhibitor_create() {
|
async fn inhibitor_create() {
|
||||||
let h = testing::start();
|
let _h = testing::start();
|
||||||
let path = h.test.path();
|
|
||||||
|
|
||||||
let hid = HidNode::new(0);
|
let hid = HidNode::new(0);
|
||||||
let sys_base = hid.sys_base();
|
let sys_base = hid.sys_base();
|
||||||
|
|
||||||
create_dir_all(path.join("dev")).expect("dev");
|
create_dir_all(path("/dev")).expect("dev");
|
||||||
create_dir_all(sys_base.join("input/input0/mouse0")).expect("mouse0");
|
create_dir_all(sys_base.join("input/input0/mouse0")).expect("mouse0");
|
||||||
symlink("sony", sys_base.join("driver")).expect("driver");
|
symlink("sony", sys_base.join("driver")).expect("driver");
|
||||||
create_dir_all(path.join("proc/1/fd")).expect("fd");
|
create_dir_all(path("/proc/1/fd")).expect("fd");
|
||||||
write(path.join("proc/1/comm"), "steam\n").expect("comm");
|
write(path("/proc/1/comm"), "steam\n").expect("comm");
|
||||||
|
|
||||||
let mut inhibitor = Inhibitor::init().await.expect("init");
|
let mut inhibitor = Inhibitor::init().await.expect("init");
|
||||||
let task = tokio::spawn(async move {
|
let task = tokio::spawn(async move {
|
||||||
inhibitor.run().await;
|
inhibitor.run().await.expect("run");
|
||||||
});
|
});
|
||||||
|
|
||||||
nyield(3).await;
|
nyield(3).await;
|
||||||
|
@ -582,8 +581,8 @@ mod test {
|
||||||
|
|
||||||
File::create(hid.hidraw()).expect("hidraw");
|
File::create(hid.hidraw()).expect("hidraw");
|
||||||
nyield(3).await;
|
nyield(3).await;
|
||||||
symlink(hid.hidraw(), path.join("proc/1/fd/3")).expect("symlink");
|
symlink(hid.hidraw(), path("/proc/1/fd/3")).expect("symlink");
|
||||||
let f = File::open(hid.hidraw()).expect("hidraw");
|
let _f = File::open(hid.hidraw()).expect("hidraw");
|
||||||
nyield(3).await;
|
nyield(3).await;
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
read_to_string(sys_base.join("input/input0/inhibited")).expect("inhibited"),
|
read_to_string(sys_base.join("input/input0/inhibited")).expect("inhibited"),
|
||||||
|
|
|
@ -94,7 +94,7 @@ mod test {
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn board_lookup() {
|
async fn board_lookup() {
|
||||||
let h = testing::start();
|
let _h = testing::start();
|
||||||
|
|
||||||
create_dir_all(crate::path("/sys/class/dmi/id"))
|
create_dir_all(crate::path("/sys/class/dmi/id"))
|
||||||
.await
|
.await
|
||||||
|
|
|
@ -411,7 +411,7 @@ mod test {
|
||||||
use zbus::ConnectionBuilder;
|
use zbus::ConnectionBuilder;
|
||||||
|
|
||||||
struct TestHandle {
|
struct TestHandle {
|
||||||
handle: testing::TestHandle,
|
_handle: testing::TestHandle,
|
||||||
connection: Connection,
|
connection: Connection,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -450,7 +450,10 @@ mod test {
|
||||||
.await
|
.await
|
||||||
.expect("object_server at");
|
.expect("object_server at");
|
||||||
|
|
||||||
TestHandle { handle, connection }
|
TestHandle {
|
||||||
|
_handle: handle,
|
||||||
|
connection,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[zbus::proxy(
|
#[zbus::proxy(
|
||||||
|
@ -517,10 +520,10 @@ mod test {
|
||||||
assert_eq!(proxy.manual_gpu_clock().await.unwrap(), 1600);
|
assert_eq!(proxy.manual_gpu_clock().await.unwrap(), 1600);
|
||||||
|
|
||||||
proxy.set_manual_gpu_clock(200).await.expect("proxy_set");
|
proxy.set_manual_gpu_clock(200).await.expect("proxy_set");
|
||||||
power::test::expect_clocks(200);
|
power::test::expect_clocks(200).await;
|
||||||
|
|
||||||
assert!(proxy.set_manual_gpu_clock(100).await.is_err());
|
assert!(proxy.set_manual_gpu_clock(100).await.is_err());
|
||||||
power::test::expect_clocks(200);
|
power::test::expect_clocks(200).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[zbus::proxy(
|
#[zbus::proxy(
|
||||||
|
|
13
src/power.rs
13
src/power.rs
|
@ -242,7 +242,7 @@ CCLK_RANGE in Core0:
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_get_gpu_performance_level() {
|
async fn test_get_gpu_performance_level() {
|
||||||
let h = testing::start();
|
let _h = testing::start();
|
||||||
|
|
||||||
let filename = path(GPU_PERFORMANCE_LEVEL_PATH);
|
let filename = path(GPU_PERFORMANCE_LEVEL_PATH);
|
||||||
setup().await;
|
setup().await;
|
||||||
|
@ -286,7 +286,7 @@ CCLK_RANGE in Core0:
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_set_gpu_performance_level() {
|
async fn test_set_gpu_performance_level() {
|
||||||
let h = testing::start();
|
let _h = testing::start();
|
||||||
|
|
||||||
let filename = path(GPU_PERFORMANCE_LEVEL_PATH);
|
let filename = path(GPU_PERFORMANCE_LEVEL_PATH);
|
||||||
setup().await;
|
setup().await;
|
||||||
|
@ -330,7 +330,7 @@ CCLK_RANGE in Core0:
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_get_tdp_limit() {
|
async fn test_get_tdp_limit() {
|
||||||
let h = testing::start();
|
let _h = testing::start();
|
||||||
|
|
||||||
let hwmon = path(GPU_HWMON_PREFIX);
|
let hwmon = path(GPU_HWMON_PREFIX);
|
||||||
create_dir_all(hwmon.join("hwmon5").as_path())
|
create_dir_all(hwmon.join("hwmon5").as_path())
|
||||||
|
@ -347,7 +347,7 @@ CCLK_RANGE in Core0:
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_set_tdp_limit() {
|
async fn test_set_tdp_limit() {
|
||||||
let h = testing::start();
|
let _h = testing::start();
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
set_tdp_limit(2).await.unwrap_err().to_string(),
|
set_tdp_limit(2).await.unwrap_err().to_string(),
|
||||||
|
@ -407,8 +407,7 @@ CCLK_RANGE in Core0:
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_get_gpu_clocks() {
|
async fn test_get_gpu_clocks() {
|
||||||
let h = testing::start();
|
let _h = testing::start();
|
||||||
let filename = path(GPU_PERFORMANCE_LEVEL_PATH);
|
|
||||||
setup().await;
|
setup().await;
|
||||||
|
|
||||||
assert!(get_gpu_clocks().await.is_err());
|
assert!(get_gpu_clocks().await.is_err());
|
||||||
|
@ -419,7 +418,7 @@ CCLK_RANGE in Core0:
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_set_gpu_clocks() {
|
async fn test_set_gpu_clocks() {
|
||||||
let h = testing::start();
|
let _h = testing::start();
|
||||||
|
|
||||||
assert!(set_gpu_clocks(1600).await.is_err());
|
assert!(set_gpu_clocks(1600).await.is_err());
|
||||||
setup().await;
|
setup().await;
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use std::ffi::OsStr;
|
use std::ffi::OsStr;
|
||||||
|
#[cfg(not(test))]
|
||||||
use tokio::process::Command;
|
use tokio::process::Command;
|
||||||
|
|
||||||
#[cfg(not(test))]
|
#[cfg(not(test))]
|
||||||
|
|
|
@ -117,10 +117,8 @@ mod test {
|
||||||
use crate::testing;
|
use crate::testing;
|
||||||
use nix::sys::stat::Mode;
|
use nix::sys::stat::Mode;
|
||||||
use nix::unistd;
|
use nix::unistd;
|
||||||
use std::cell::Cell;
|
use tokio::fs::{create_dir_all, read_to_string, write};
|
||||||
use std::fs;
|
use tokio::sync::mpsc::{error, unbounded_channel, UnboundedSender};
|
||||||
use std::path::PathBuf;
|
|
||||||
use tokio::sync::mpsc::{unbounded_channel, UnboundedReceiver, UnboundedSender};
|
|
||||||
|
|
||||||
struct MockTrace {
|
struct MockTrace {
|
||||||
traces: UnboundedSender<(String, HashMap<String, zvariant::OwnedValue>)>,
|
traces: UnboundedSender<(String, HashMap<String, zvariant::OwnedValue>)>,
|
||||||
|
@ -133,7 +131,7 @@ mod test {
|
||||||
trace: &str,
|
trace: &str,
|
||||||
data: HashMap<&str, zvariant::Value<'_>>,
|
data: HashMap<&str, zvariant::Value<'_>>,
|
||||||
) -> zbus::fdo::Result<()> {
|
) -> zbus::fdo::Result<()> {
|
||||||
self.traces.send((
|
let _ = self.traces.send((
|
||||||
String::from(trace),
|
String::from(trace),
|
||||||
HashMap::from_iter(
|
HashMap::from_iter(
|
||||||
data.iter()
|
data.iter()
|
||||||
|
@ -146,18 +144,31 @@ mod test {
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn handle_pid() {
|
async fn handle_pid() {
|
||||||
let h = testing::start();
|
let _h = testing::start();
|
||||||
let path = h.test.path();
|
|
||||||
|
|
||||||
fs::create_dir_all(path.join("proc/1234")).expect("create_dir_all");
|
create_dir_all(path("/proc/1234"))
|
||||||
fs::write(path.join("proc/1234/comm"), "ftrace\n").expect("write comm");
|
.await
|
||||||
fs::write(path.join("proc/1234/environ"), "SteamGameId=5678").expect("write environ");
|
.expect("create_dir_all");
|
||||||
|
write(path("/proc/1234/comm"), "ftrace\n")
|
||||||
|
.await
|
||||||
|
.expect("write comm");
|
||||||
|
write(path("/proc/1234/environ"), "SteamGameId=5678")
|
||||||
|
.await
|
||||||
|
.expect("write environ");
|
||||||
|
|
||||||
fs::create_dir_all(path.join("proc/1235")).expect("create_dir_all");
|
create_dir_all(path("/proc/1235"))
|
||||||
fs::write(path.join("proc/1235/comm"), "ftrace\n").expect("write comm");
|
.await
|
||||||
|
.expect("create_dir_all");
|
||||||
|
write(path("/proc/1235/comm"), "ftrace\n")
|
||||||
|
.await
|
||||||
|
.expect("write comm");
|
||||||
|
|
||||||
fs::create_dir_all(path.join("proc/1236")).expect("create_dir_all");
|
create_dir_all(path("/proc/1236"))
|
||||||
fs::write(path.join("proc/1236/environ"), "SteamGameId=5678").expect("write environ");
|
.await
|
||||||
|
.expect("create_dir_all");
|
||||||
|
write(path("/proc/1236/environ"), "SteamGameId=5678")
|
||||||
|
.await
|
||||||
|
.expect("write environ");
|
||||||
|
|
||||||
let mut map = HashMap::new();
|
let mut map = HashMap::new();
|
||||||
assert!(Ftrace::handle_pid(&mut map, 1234).await.is_ok());
|
assert!(Ftrace::handle_pid(&mut map, 1234).await.is_ok());
|
||||||
|
@ -189,43 +200,53 @@ mod test {
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn ftrace_init() {
|
async fn ftrace_init() {
|
||||||
let h = testing::start();
|
let _h = testing::start();
|
||||||
let path = h.test.path();
|
|
||||||
|
|
||||||
let tracefs = Ftrace::base();
|
let tracefs = Ftrace::base();
|
||||||
|
|
||||||
fs::create_dir_all(tracefs.join("events/oom/mark_victim")).expect("create_dir_all");
|
create_dir_all(tracefs.join("events/oom/mark_victim"))
|
||||||
|
.await
|
||||||
|
.expect("create_dir_all");
|
||||||
unistd::mkfifo(
|
unistd::mkfifo(
|
||||||
tracefs.join("trace_pipe").as_path(),
|
tracefs.join("trace_pipe").as_path(),
|
||||||
Mode::S_IRUSR | Mode::S_IWUSR,
|
Mode::S_IRUSR | Mode::S_IWUSR,
|
||||||
)
|
)
|
||||||
.expect("trace_pipe");
|
.expect("trace_pipe");
|
||||||
let dbus = Connection::session().await.expect("dbus");
|
let dbus = Connection::session().await.expect("dbus");
|
||||||
let ftrace = Ftrace::init(dbus).await.expect("ftrace");
|
let _ftrace = Ftrace::init(dbus).await.expect("ftrace");
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
fs::read_to_string(tracefs.join("events/oom/mark_victim/enable")).unwrap(),
|
read_to_string(tracefs.join("events/oom/mark_victim/enable"))
|
||||||
|
.await
|
||||||
|
.unwrap(),
|
||||||
"1"
|
"1"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn ftrace_relay() {
|
async fn ftrace_relay() {
|
||||||
let h = testing::start();
|
let _h = testing::start();
|
||||||
let path = h.test.path();
|
|
||||||
|
|
||||||
let tracefs = Ftrace::base();
|
let tracefs = Ftrace::base();
|
||||||
|
|
||||||
fs::create_dir_all(tracefs.join("events/oom/mark_victim")).expect("create_dir_all");
|
create_dir_all(tracefs.join("events/oom/mark_victim"))
|
||||||
|
.await
|
||||||
|
.expect("create_dir_all");
|
||||||
unistd::mkfifo(
|
unistd::mkfifo(
|
||||||
tracefs.join("trace_pipe").as_path(),
|
tracefs.join("trace_pipe").as_path(),
|
||||||
Mode::S_IRUSR | Mode::S_IWUSR,
|
Mode::S_IRUSR | Mode::S_IWUSR,
|
||||||
)
|
)
|
||||||
.expect("trace_pipe");
|
.expect("trace_pipe");
|
||||||
|
|
||||||
fs::create_dir_all(path.join("proc/14351")).expect("create_dir_all");
|
create_dir_all(path("/proc/14351"))
|
||||||
fs::write(path.join("proc/14351/comm"), "ftrace\n").expect("write comm");
|
.await
|
||||||
fs::write(path.join("proc/14351/environ"), "SteamGameId=5678").expect("write environ");
|
.expect("create_dir_all");
|
||||||
|
write(path("/proc/14351/comm"), "ftrace\n")
|
||||||
|
.await
|
||||||
|
.expect("write comm");
|
||||||
|
write(path("/proc/14351/environ"), "SteamGameId=5678")
|
||||||
|
.await
|
||||||
|
.expect("write environ");
|
||||||
|
|
||||||
let (sender, mut receiver) = unbounded_channel();
|
let (sender, mut receiver) = unbounded_channel();
|
||||||
let trace = MockTrace { traces: sender };
|
let trace = MockTrace { traces: sender };
|
||||||
|
@ -241,7 +262,7 @@ mod test {
|
||||||
let mut ftrace = Ftrace::init(dbus).await.expect("ftrace");
|
let mut ftrace = Ftrace::init(dbus).await.expect("ftrace");
|
||||||
|
|
||||||
assert!(match receiver.try_recv() {
|
assert!(match receiver.try_recv() {
|
||||||
Empty => true,
|
Err(error::TryRecvError::Empty) => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
});
|
});
|
||||||
ftrace
|
ftrace
|
||||||
|
|
|
@ -253,7 +253,7 @@ mod test {
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_get_wifi_backend() {
|
async fn test_get_wifi_backend() {
|
||||||
let h = testing::start();
|
let _h = testing::start();
|
||||||
|
|
||||||
create_dir_all(path(WIFI_BACKEND_PATH).parent().unwrap())
|
create_dir_all(path(WIFI_BACKEND_PATH).parent().unwrap())
|
||||||
.await
|
.await
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue