Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ec/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions ec/test-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,5 @@ ec-test-lib = { path = "../test-lib" }
time-alarm-service-messages.workspace = true
battery-service-messages.workspace = true

Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ec-test-cli no longer defines mock/serial/acpi features, but the repo CI uses cargo-hack with --mutually-exclusive-features mock,serial and --exclude-features acpi for this crate. Either keep these features (even as empty feature flags) or update the CI workflow; otherwise CI will error when it tries to reason about missing features.

Suggested change
[features]
mock = []
serial = []
acpi = []

Copilot uses AI. Check for mistakes.
[features]
mock = []
acpi = ["ec-test-lib/acpi"]
serial = []

[lints]
workspace = true
37 changes: 27 additions & 10 deletions ec/test-cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,44 @@ use clap::{Parser, Subcommand, ValueEnum};
#[derive(Parser)]
#[command(name = "ec-test-cli", about = "CLI tool for EC feature testing")]
pub struct Cli {
#[cfg(feature = "serial")]
#[arg(long)]
pub port: String,
/// Data source to use.
#[arg(long, value_enum)]
pub source: SourceKind,

#[cfg(feature = "serial")]
#[arg(long, value_enum, default_value = "none")]
/// Serial port path (required when --source serial).
#[arg(long, required_if_eq("source", "serial"))]
pub port: Option<String>,

/// Serial flow-control mode.
#[arg(long, value_enum, default_value_t = FlowControl::None)]
pub flow_control: FlowControl,

#[cfg(feature = "serial")]
#[arg(long, default_value = "115200")]
/// Serial baud rate.
#[arg(long, default_value_t = 115_200)]
pub baud: u32,

#[command(subcommand)]
pub command: Command,
}

#[cfg(feature = "serial")]
#[derive(Clone, PartialEq, ValueEnum)]
/// Available data sources.
#[derive(Clone, Copy, ValueEnum)]
pub enum SourceKind {
/// Deterministic in-process mock — no hardware required.
Mock,
/// Real hardware via serial transport.
Serial,
/// Real hardware via ACPI (Windows only).
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The help text says this source is "ACPI (Windows only)", but the code now routes this variant to ec_test_lib::os::OsSource, which also has a Linux implementation. Either rename this variant (e.g. Os/System) or update the doc comment/value names so the CLI accurately reflects what --source acpi does on Linux vs Windows.

Suggested change
/// Real hardware via ACPI (Windows only).
/// Real hardware via the OS-provided hardware interface
/// (ACPI on Windows; also supported on Linux).

Copilot uses AI. Check for mistakes.
Acpi,
}

#[derive(Clone, Copy, Default, ValueEnum)]
pub enum FlowControl {
Hw,
#[default]
#[value(name = "none")]
None,
#[value(name = "hw")]
Hw,
}

#[derive(Subcommand)]
Expand Down
44 changes: 19 additions & 25 deletions ec/test-cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,38 +1,32 @@
const _: () = {
let count = cfg!(feature = "mock") as u8 + cfg!(feature = "acpi") as u8 + cfg!(feature = "serial") as u8;
assert!(
count == 1,
"Exactly one of the following features must be enabled: `mock`, `acpi`, or `serial`."
);
};

mod cli;
mod commands;
mod debug;

use clap::Parser;
use cli::{Cli, Command};
use cli::{Cli, Command, SourceKind};
use ec_test_lib::Source;

fn dispatch<S: Source>(source: S, command: Command) -> Result<(), Box<dyn std::error::Error>> {
match command {
Command::Thermal(cmd) => commands::thermal::run(source, cmd).map_err(Into::into),
Command::Battery(cmd) => commands::battery::run(source, cmd).map_err(Into::into),
Command::Rtc(cmd) => commands::rtc::run(source, cmd).map_err(Into::into),
}
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
let cli = Cli::parse();

#[cfg(feature = "mock")]
let source = ec_test_lib::mock::Mock::default();
match cli.source {
SourceKind::Mock => dispatch(ec_test_lib::mock::Mock::default(), cli.command),

#[cfg(feature = "acpi")]
let source = ec_test_lib::acpi::Acpi::default();
SourceKind::Serial => {
let port = cli.port.expect("--port is required for --source serial");
let hw_flow = matches!(cli.flow_control, cli::FlowControl::Hw);
let source = ec_test_lib::serial::Serial::new(&port, cli.baud, hw_flow)?;
dispatch(source, cli.command)
}

#[cfg(feature = "serial")]
let source = {
let flow_control = cli.flow_control == cli::FlowControl::Hw;
ec_test_lib::serial::Serial::new(&cli.port, cli.baud, flow_control)?
};

match cli.command {
Command::Thermal(cmd) => commands::thermal::run(source, cmd)?,
Command::Battery(cmd) => commands::battery::run(source, cmd)?,
Command::Rtc(cmd) => commands::rtc::run(source, cmd)?,
SourceKind::Acpi => dispatch(ec_test_lib::os::OsSource::default(), cli.command),
}

Ok(())
}
20 changes: 11 additions & 9 deletions ec/test-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,14 @@ battery-service-messages.workspace = true

embedded-mcu-hal = { workspace = true }

# ACPI feature specific
num_enum = { version = "0.7.5", default-features = false, optional = true }
# Serial transport specific
serialport = { version = "4.8.1" }
embedded-services = { git = "https://github.com/OpenDevicePartnership/embedded-services", branch = "v0.2.0" }
thermal-service-messages = { git = "https://github.com/OpenDevicePartnership/embedded-services", branch = "v0.2.0" }

[target.'cfg(target_os = "windows")'.dependencies]
num_enum = { version = "0.7.5", default-features = false }
scopeguard = { version = "1.2" }
windows = { version = "0.58", features = [
"Win32_Devices_DeviceAndDriverInstallation",
"Win32_Devices_Properties",
Expand All @@ -24,16 +30,12 @@ windows = { version = "0.58", features = [
"Win32_Foundation",
"Win32_System_SystemServices",
"Win32_Security",
], optional = true }
scopeguard = { version = "1.2", optional = true }
] }

# Serial feature specific
serialport = { version = "4.8.1" }
embedded-services = { git = "https://github.com/OpenDevicePartnership/embedded-services", branch = "v0.2.0" }
thermal-service-messages = { git = "https://github.com/OpenDevicePartnership/embedded-services", branch = "v0.2.0" }
[target.'cfg(target_os = "linux")'.dependencies]
libc = { version = "0.2" }

[features]
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This crate no longer defines the acpi feature, but the repository CI/workflows (e.g. cargo hack --exclude-features acpi / cargo xwin ... --features acpi) still assume it exists. Either restore an acpi feature flag (even as a no-op/alias) or update the CI configuration accordingly, otherwise CI will fail.

Suggested change
[features]
[features]
acpi = []

Copilot uses AI. Check for mistakes.
acpi = ["dep:num_enum", "dep:windows", "dep:scopeguard"]

[lints]
workspace = true
17 changes: 1 addition & 16 deletions ec/test-lib/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,13 @@
// Multiple source features may be enabled simultaneously; the binary selects one at runtime.

#[cfg(all(
feature = "acpi",
not(all(target_arch = "aarch64", target_os = "windows", target_env = "msvc"))
))]
compile_error!(
"The `acpi` feature requires targeting `aarch64-pc-windows-msvc`.\n\
If on WSL, try: cargo build-win --release --features acpi"
);

use battery_service_messages::{BixFixedStrings, BstReturn};
use time_alarm_service_messages::{
AcpiTimerId, AcpiTimestamp, AlarmExpiredWakePolicy, AlarmTimerSeconds, TimeAlarmDeviceCapabilities, TimerStatus,
};

pub(crate) mod common;

#[cfg(all(
feature = "acpi",
target_arch = "aarch64",
target_os = "windows",
target_env = "msvc"
))]
pub mod acpi;
pub mod os;

pub mod mock;
pub mod serial;
Expand Down
Loading