Re-apply missed reviewer updates from 0e16afc15. Changes in response to reviewer comments in 0e16afc15 were inadvertently dropped. Re-apply the changes. Bug: MAC-213, MAC-214 Change-Id: I21e4b46a5713fc486a384a08c018f737e3f53c88
diff --git a/Cargo.toml b/Cargo.toml index 422772a..443e4f1 100644 --- a/Cargo.toml +++ b/Cargo.toml
@@ -12,10 +12,10 @@ edition = "2018" [dependencies] -structopt = { path = "rust_crates/vendor/structopt" } -libc = { path = "rust_crates/vendor/libc" } clap = { path = "rust_crates/vendor/clap" } +libc = { path = "rust_crates/vendor/libc" } matches = { path = "rust_crates/vendor/matches" } +structopt = { path = "rust_crates/vendor/structopt" } [patch.crates-io] winapi = { path = "rust_crates/tiny_mirrors/winapi" }
diff --git a/src/bin/virtio_input_test_util/events.rs b/src/bin/virtio_input_test_util/events.rs index ee86c63..238afe0 100644 --- a/src/bin/virtio_input_test_util/events.rs +++ b/src/bin/virtio_input_test_util/events.rs
@@ -1,5 +1,6 @@ -/// Functionality for parsing events on Linux's `/dev/input/eventX` character -/// devices. +//! Functionality for parsing events on Linux's `/dev/input/eventX` character +//! devices. + use std::fs::OpenOptions; use std::io::{Error, Read}; @@ -24,13 +25,6 @@ FfStatus = 0x17, } -impl Default for EventType { - fn default() -> EventType { - // By default, return the value with a zero representation. - EventType::Syn - } -} - /// Linux's `struct time_val`. /// /// See Linux `include/uapi/linux/time.h` for details. @@ -51,7 +45,7 @@ #[derive(Debug, Clone, Copy, Default)] pub struct InputEvent { pub time: TimeVal, - pub type_: EventType, + pub type_: u16, pub code: u16, pub value: i32, } @@ -139,7 +133,7 @@ let mut reader = EventReader::new_from_reader(Box::new(std::io::Cursor::new(raw_event))); let event = reader.read().expect("Could not parse event"); - assert_eq!({ event.type_ }, EventType::Key); + assert_eq!({ event.type_ }, EventType::Key as u16); assert_eq!({ event.code }, KeyboardCode::A as u16); assert_eq!({ event.value }, KeyboardValue::KeyDown as i32); }
diff --git a/src/bin/virtio_input_test_util/main.rs b/src/bin/virtio_input_test_util/main.rs index 739908c..c27c88e 100644 --- a/src/bin/virtio_input_test_util/main.rs +++ b/src/bin/virtio_input_test_util/main.rs
@@ -12,7 +12,7 @@ I: Iterator<Item = InputEvent>, { for e in events { - if { e.type_ } == EventType::Key + if { e.type_ } == (EventType::Key as u16) && e.code == (code as u16) && e.value == (KeyboardValue::KeyDown as i32) { @@ -23,28 +23,18 @@ } fn run_keyboard_test(input_devices: &[&Path]) -> Result<(), String> { - // Open the set of character devices. - let files = input_devices - .iter() - .map(|x| { - EventReader::new_from_path(Path::new(x)) - .map_err(|e| format!("Failed to open file '{}': {}", x.display(), e)) - }) - .collect::<Result<Vec<EventReader>, String>>()?; - - // Create a EventReader object for each input file, all sending to the channel `tx`. + // Create a EventReader object for each input file, each with its own thread, all sending to the channel `tx`. let (tx, rx) = mpsc::sync_channel(0); - let _threads = files - .into_iter() - .map(|mut r| { - let tx = tx.clone(); - std::thread::spawn(move || { - while let Ok(event) = r.read() { - tx.send(event).ok(); - } - }) - }) - .collect::<Vec<_>>(); + for path in input_devices.iter() { + let mut reader = EventReader::new_from_path(path) + .map_err(|e| format!("Failed to open file '{}': {}", path.display(), e))?; + let tx = tx.clone(); + std::thread::spawn(move || { + while let Ok(event) = reader.read() { + tx.send(event).ok(); + } + }); + } // Wait for key strokes. println!("Type 'abc<shift>' to pass test."); @@ -76,15 +66,14 @@ .get_matches(); // Run the user-specified command - match matches.subcommand() { - ("keyboard", Some(keyboard_matches)) => { - let files = keyboard_matches - .values_of("files") - .unwrap() - .map(Path::new) - .collect::<Vec<&Path>>(); - run_keyboard_test(&files) - } - _ => Err("Must provide a subcommand indicating which test to run.".to_string()), + if let ("keyboard", Some(keyboard_matches)) = matches.subcommand() { + let files = keyboard_matches + .values_of("files") + .unwrap() + .map(Path::new) + .collect::<Vec<&Path>>(); + run_keyboard_test(&files) + } else { + Err("Must provide a subcommand indicating which test to run.".to_string()) } }