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::Kernel;
26use std::sync::Arc;
27
28use starnix_uapi::device_id::DeviceId;
29use starnix_uapi::errors::Errno;
30
31mod device;
32mod input;
33mod ioctl;
34mod tracing;
35
36pub use device::WakeupTestDevice;
37
38pub fn register_wakeup_test_device(kernel: &Arc<Kernel>) -> Result<(), Errno> {
39 let registry = &kernel.device_registry;
40 let misc_class = registry.objects.misc_class();
41 let device = WakeupTestDevice::new(kernel);
42 registry.register_device(
43 kernel,
44 "wakeup_test0".into(),
45 DeviceMetadata::new("wakeup_test0".into(), DeviceId::new(0, 0), DeviceMode::Char),
46 misc_class,
47 device,
48 )?;
49 Ok(())
50}