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