From 0fda223d4efd232ebe635f0c008247ead6e58a42 Mon Sep 17 00:00:00 2001 From: Johannes Leupolz Date: Fri, 3 Apr 2026 23:03:58 +0000 Subject: [PATCH] Fixes for rumble test scenario --- vuinputd-tests/src/devices/device_base.rs | 26 ++++++++++++++++++---- vuinputd-tests/src/devices/xbox_gamepad.rs | 1 + vuinputd/src/cuse_device/vuinput_open.rs | 3 +-- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/vuinputd-tests/src/devices/device_base.rs b/vuinputd-tests/src/devices/device_base.rs index e239a54..bdd38a7 100644 --- a/vuinputd-tests/src/devices/device_base.rs +++ b/vuinputd-tests/src/devices/device_base.rs @@ -78,7 +78,7 @@ pub trait Device: Sized { read_event(event_device_fd) } - /// Emit and read an event with logging + /// Emit (to uinput) and read (from evdev) an event with logging fn emit_read_and_log( &mut self, ev_type: u16, @@ -86,7 +86,20 @@ pub trait Device: Sized { val: i32, ) -> io::Result { let event_device_fd = self.get_event_device()?; - let event = emit_read_and_log(self.uinput_fd(), event_device_fd, ev_type, code, val)?; + let event = emit_read_and_log(self.uinput_fd(), event_device_fd, ev_type, code, val, true)?; + self.state_mut().events.push(event.clone()); + Ok(event) + } + + /// Emit and read an event with logging + fn emit_to_evdev_read_from_uinput_and_log( + &mut self, + ev_type: u16, + code: u16, + val: i32, + ) -> io::Result { + let event_device_fd = self.get_event_device()?; + let event = emit_read_and_log(event_device_fd, self.uinput_fd(), ev_type, code, val, false)?; self.state_mut().events.push(event.clone()); Ok(event) } @@ -184,12 +197,17 @@ pub fn emit_read_and_log( ev_type: u16, code: u16, val: i32, + emit_syn: bool, ) -> io::Result { let (time_sent_sec, time_sent_nsec) = monotonic_time(); emit(emit_to, ev_type, code, val)?; - emit(emit_to, EV_SYN, SYN_REPORT, 0)?; + if emit_syn { + emit(emit_to, EV_SYN, SYN_REPORT, 0)?; + } let input_event_recv = read_event(read_from).unwrap(); - let _syn_recv = read_event(read_from).unwrap(); + if emit_syn { + let _syn_recv = read_event(read_from).unwrap(); + } let (time_recv_sec, time_recv_nsec) = monotonic_time(); let duration_usec = (time_recv_sec - time_sent_sec) * 1_000_000 + (time_recv_nsec - time_sent_nsec) / 1000; diff --git a/vuinputd-tests/src/devices/xbox_gamepad.rs b/vuinputd-tests/src/devices/xbox_gamepad.rs index b14c3a3..44be126 100644 --- a/vuinputd-tests/src/devices/xbox_gamepad.rs +++ b/vuinputd-tests/src/devices/xbox_gamepad.rs @@ -351,6 +351,7 @@ impl XboxGamepadDevice { } else { println!("event: {} {} {}",input_event.type_,input_event.code,input_event.value); + crate::devices::utils::emit(fd, input_event.type_,input_event.code,input_event.value).unwrap(); } } else { diff --git a/vuinputd/src/cuse_device/vuinput_open.rs b/vuinputd/src/cuse_device/vuinput_open.rs index 223d9ac..0d36929 100644 --- a/vuinputd/src/cuse_device/vuinput_open.rs +++ b/vuinputd/src/cuse_device/vuinput_open.rs @@ -46,8 +46,7 @@ pub unsafe extern "C" fn vuinput_open( let open_vuinput_result = OpenOptions::new() .read(true) .write(true) - .custom_flags(O_NONBLOCK) - .custom_flags(O_CLOEXEC) + .custom_flags(O_NONBLOCK | O_CLOEXEC) .open(Path::new("/dev/uinput")); match open_vuinput_result { Ok(v) => {