Skip to content

Commit 636604b

Browse files
committed
- Added new test document that documents conducted tests.
- Add test for job engine - Fixed a pointer on cleanup
1 parent 8950288 commit 636604b

5 files changed

Lines changed: 84 additions & 12 deletions

File tree

docs/TESTS.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Tests
2+
3+
## Manual end-to-end tests
4+
5+
| vuinputd | host | input type | app that creates device | app that reads device | working | Notes |
6+
| -------------- | ---------- |---------- | ---------- |---------- |---------- |---------- |
7+
| 0.2.0 | Ubuntu 24.04 amd64 | virtual keyboard | Sunshine (via moonlight-qt 6.1.0 on macos) | labwc via libinput | :white_check_mark: | (1) |
8+
| 0.2.0 | Ubuntu 24.04 amd64| virtual mouse | Sunshine (via moonlight-qt 6.1.0 on macos) | labwc via libinput | :white_check_mark:) | (1) |
9+
| 0.2.0 | Ubuntu 24.04 amd64 | virtual keyboard | Steam (via Remote Play from Mac) | Return to Monkey Island | :white_check_mark: | (2) |
10+
| 0.2.0 | Ubuntu 24.04 amd64 | virtual gamepad | Steam (via Remote Play from Mac) | Return to Monkey Island | :x: | (2) |
11+
12+
13+
(1) works also for programs running on the wayland desktop
14+
(2) Steam is a 32-bit application on linux

vuinputd/src/jobs/closure_job.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub struct ClosureJob {
1111
desc: String,
1212
execute_after_cancellation: bool,
1313
target: JobTarget,
14-
task_creator: Box<dyn Fn(JobTarget) -> Pin<Box<dyn Future<Output = ()>>> + Send + 'static>,
14+
task_creator: Box<dyn Fn(&ClosureJob) -> Pin<Box<dyn Future<Output = ()>>> + Send + 'static>,
1515
}
1616

1717
impl ClosureJob {
@@ -20,7 +20,7 @@ impl ClosureJob {
2020
target: JobTarget,
2121
execute_after_cancellation: bool,
2222
f: Box<
23-
dyn Fn(JobTarget) -> Pin<Box<dyn Future<Output = ()>>> // closure returns any future
23+
dyn Fn(&ClosureJob) -> Pin<Box<dyn Future<Output = ()>>> // closure returns any future
2424
+ Send // the closure itself can be sent across threads
2525
+ 'static,
2626
>,
@@ -46,8 +46,7 @@ impl Job for ClosureJob {
4646

4747
fn create_task(self: &ClosureJob) -> Pin<Box<dyn Future<Output = ()>>> {
4848
let creator = &self.task_creator;
49-
let target = self.job_target();
50-
let task = creator(target);
49+
let task = creator(self);
5150
task
5251
}
5352

@@ -66,7 +65,8 @@ pub fn example() {
6665
"Host maintenance",
6766
JobTarget::Host,
6867
false,
69-
Box::new(|target| {
68+
Box::new(|job: &ClosureJob| {
69+
let target = job.target.clone();
7070
Box::pin(async move {
7171
println!("Running host job on {:?}", target);
7272
})

vuinputd/src/jobs/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,6 @@
3333
3434
pub mod closure_job;
3535
pub mod job;
36+
37+
#[cfg(test)]
38+
mod tests;

vuinputd/src/jobs/tests.rs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
use crate::jobs::closure_job::ClosureJob;
2+
use crate::jobs::job::{Dispatcher, Job, JobTarget};
3+
4+
use super::*;
5+
use futures::executor::LocalPool;
6+
use futures::task::LocalSpawnExt;
7+
use std::cell::RefCell;
8+
use std::rc::Rc;
9+
use std::sync::{Arc, Mutex};
10+
11+
/// Simple shared integer counter
12+
fn shared_counter() -> Arc<Mutex<i32>> {
13+
Arc::new(Mutex::new(0))
14+
}
15+
16+
//
17+
// 1. Ordering test
18+
//
19+
#[test]
20+
fn test_job_ordering() {
21+
let mut dispatcher = Dispatcher::new();
22+
let c = shared_counter();
23+
24+
let c1 = c.clone();
25+
dispatcher.dispatch(Box::new(ClosureJob::new(
26+
"set to 5",
27+
JobTarget::Host,
28+
false,
29+
Box::new(move |_job| {
30+
let c1 = c1.clone();
31+
Box::pin(async move {
32+
*c1.lock().unwrap() = 5;
33+
})
34+
}),
35+
)));
36+
37+
38+
// job 2: increment to 6
39+
let c2 = c.clone();
40+
dispatcher.dispatch(Box::new(ClosureJob::new(
41+
"increment to 6",
42+
JobTarget::Host,
43+
false,
44+
Box::new(move |_job| {
45+
let c2 = c2.clone();
46+
Box::pin(async move {
47+
*c2.lock().unwrap() += 1;
48+
})
49+
}),
50+
)));
51+
52+
dispatcher.wait_until_finished();
53+
54+
assert_eq!(*c.lock().unwrap(), 6);
55+
}

vuinputd/src/main.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -742,15 +742,15 @@ fn check_permissions() -> Result<(), std::io::Error> {
742742
fn main() -> std::io::Result<()> {
743743
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("debug")).init();
744744

745-
check_permissions().unwrap();
745+
check_permissions().expect("failed to read the capabilities of the vuinputd process");;
746746

747747
let args: Vec<String> = std::env::args().collect();
748748

749-
VUINPUT_STATE.set(RwLock::new(HashMap::new())).unwrap();
750-
VUINPUT_COUNTER.set(AtomicU64::new(3)).unwrap();
751-
JOB_DISPATCHER.set(Mutex::new(Dispatcher::new())).unwrap();
752-
VUINPUTD_NAMESPACES.set(get_namespace(Pid::SelfPid)).unwrap();
753-
DEDUP_LAST_ERROR.set(Mutex::new(None)).unwrap();
749+
VUINPUT_STATE.set(RwLock::new(HashMap::new())).expect("failed to initialize global state");
750+
VUINPUT_COUNTER.set(AtomicU64::new(3)).expect("failed to initialize the counter that provides the values of the CUSE file handles"); // 3, because 1 and 2 are usually STDOUT and STDERR
751+
JOB_DISPATCHER.set(Mutex::new(Dispatcher::new())).expect("failed to initialize the job dispatcher");
752+
VUINPUTD_NAMESPACES.set(get_namespace(Pid::SelfPid)).expect("failed to retrieve the namespaces of the vuinputd process");
753+
DEDUP_LAST_ERROR.set(Mutex::new(None)).expect("failed to initialize the log deduplication state");
754754
JOB_DISPATCHER.get().unwrap().lock().unwrap().dispatch(Box::new(MonitorBackgroundLoop::new()));
755755

756756
info!("Starting vuinputd");
@@ -799,7 +799,7 @@ fn main() -> std::io::Result<()> {
799799
);
800800
let _reclaim_arg_program_name = CString::from_raw(parg_program_name);
801801
let _reclaim_arg_foreground = CString::from_raw(parg_foreground);
802-
let _reclaim_arg_foreground = CString::from_raw(parg_singlethreaded);
802+
let _reclaim_arg_singlethreaded = CString::from_raw(parg_singlethreaded);
803803
}
804804
info!("Stopping vuinputd");
805805
JOB_DISPATCHER.get().unwrap().lock().unwrap().close();

0 commit comments

Comments
 (0)