-
Notifications
You must be signed in to change notification settings - Fork 2
Add linux support #40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -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). | ||||||||
|
||||||||
| /// Real hardware via ACPI (Windows only). | |
| /// Real hardware via the OS-provided hardware interface | |
| /// (ACPI on Windows; also supported on Linux). |
| 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(()) | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -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", | ||||||||
|
|
@@ -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] | ||||||||
|
||||||||
| [features] | |
| [features] | |
| acpi = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ec-test-clino longer definesmock/serial/acpifeatures, but the repo CI usescargo-hackwith--mutually-exclusive-features mock,serialand--exclude-features acpifor 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.