Skip to content
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

scmi: use PathBuf for socket path #571

Merged
merged 1 commit into from
Dec 5, 2023
Merged
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
13 changes: 7 additions & 6 deletions vhost-device-scmi/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ mod vhu_scmi;
use devices::common::{print_devices_help, DeviceDescription, DeviceProperties};

use std::{
path::PathBuf,
process::exit,
sync::{Arc, RwLock},
};
Expand All @@ -58,7 +59,7 @@ struct ScmiArgs {
// Location of vhost-user Unix domain socket.
// Required, unless one of the --help options is used.
#[clap(short, long, help = "vhost-user socket to use (required)")]
socket_path: Option<String>,
socket_path: Option<PathBuf>,
// Specification of SCMI devices to create.
#[clap(short, long, help = "Devices to expose")]
#[arg(num_args(1..))]
Expand All @@ -68,18 +69,17 @@ struct ScmiArgs {
}

pub struct VuScmiConfig {
socket_path: String,
socket_path: PathBuf,
devices: DeviceDescription,
}

impl TryFrom<ScmiArgs> for VuScmiConfig {
type Error = String;

fn try_from(cmd_args: ScmiArgs) -> Result<Self> {
if cmd_args.socket_path.is_none() {
let Some(socket_path) = cmd_args.socket_path else {
return Result::Err("Required argument socket-path was not provided".to_string());
epilys marked this conversation as resolved.
Show resolved Hide resolved
}
let socket_path = cmd_args.socket_path.unwrap().trim().to_string();
};
let mut devices: DeviceDescription = vec![];
let device_iterator = cmd_args.device.iter();
for d in device_iterator {
Expand Down Expand Up @@ -159,6 +159,7 @@ fn main() {
#[cfg(test)]
mod tests {
use super::*;
use std::path::Path;

#[test]
fn test_command_line() {
Expand All @@ -173,7 +174,7 @@ mod tests {
let params: Vec<&str> = params_string.split_whitespace().collect();
let args: ScmiArgs = process_args(Parser::parse_from(params)).unwrap();
let config = VuScmiConfig::try_from(args).unwrap();
assert_eq!(config.socket_path, path);
assert_eq!(&config.socket_path, Path::new(&path));
let devices = vec![
("dummy".to_owned(), DeviceProperties::new(vec![])),
(
Expand Down
2 changes: 1 addition & 1 deletion vhost-device-scmi/src/vhu_scmi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ mod tests {

fn make_backend() -> VuScmiBackend {
let config = VuScmiConfig {
socket_path: "/foo/scmi.sock".to_owned(),
socket_path: "/foo/scmi.sock".into(),
devices: vec![],
};
VuScmiBackend::new(&config).unwrap()
Expand Down