starnix_modules_wakeup_test/lib.rs
1// Copyright 2026 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4#![recursion_limit = "256"]
5
6//!
7//! This implements a VFS device named wakeup_test. It is used as a way to expose setting a wakeup
8//! timer and when it goes off, send a specified input event to to wakeup the rest of the system.
9//!
10//! It is modeled after a similar approach that is implemented as a loadable custom linux kernel
11//! module. Since Starnix does not support loadable kernel modules, this is implemented as a built-in
12//! module, that can be optionally enabled via feature configuration.
13//!
14//! An example of using it would be to write a command line tool that runs in the container and
15//! opens the /dev/wakeup_test device, and issues ioctls to set wakeup timers and specify the input
16//! event to send when the timer goes off.
17//!
18//! To set a timer to wake up the system via swiping after 2 seconds, you could run a command like this:
19//! `wakeup_test -a timers -e 2 -t cuj_tile -m swipe-right -o 7 -i 4 -u 456 -v 456`
20//!
21//! See go/fuchsia-wakeup-latency-test for more details.
22
23use starnix_core::device::DeviceMode;
24use starnix_core::device::kobject::DeviceMetadata;
25use starnix_core::task::CurrentTask;
26use starnix_sync::{Locked, Unlocked};
27use starnix_uapi::device_type::DeviceType;
28use starnix_uapi::errors::Errno;
29
30mod device;
31mod input;
32mod ioctl;
33mod tracing;
34
35pub use device::WakeupTestDevice;
36
37pub fn register_wakeup_test_device(
38 locked: &mut Locked<Unlocked>,
39 system_task: &CurrentTask,
40) -> Result<(), Errno> {
41 let kernel = system_task.kernel();
42 let registry = &kernel.device_registry;
43 let misc_class = registry.objects.misc_class();
44 let device = WakeupTestDevice::new(system_task);
45 registry.register_device(
46 locked,
47 system_task,
48 "wakeup_test0".into(),
49 DeviceMetadata::new("wakeup_test0".into(), DeviceType::new(0, 0), DeviceMode::Char),
50 misc_class,
51 device,
52 )?;
53 Ok(())
54}