Skip to content

Commit

Permalink
Update vhost-device-console
Browse files Browse the repository at this point in the history
Add tests in vhu_console.rs file, update the control message handling,
apply cargo clippy & fmt recommendations.

Signed-off-by: Timos Ampelikiotis <t.ampelikiotis@virtualopensystems.com>
  • Loading branch information
TimosAmpel committed Mar 11, 2024
1 parent 006b2e0 commit ac9c5bc
Show file tree
Hide file tree
Showing 4 changed files with 515 additions and 107 deletions.
37 changes: 16 additions & 21 deletions staging/vhost-device-console/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ pub(crate) type Result<T> = std::result::Result<T, Error>;
pub(crate) enum Error {
#[error("Invalid socket count: {0}")]
SocketCountInvalid(usize),
#[error("Could not create console controller: {0}")]
CouldNotCreateConsoleController(crate::console::Error),
#[error("Could not create console backend: {0}")]
CouldNotCreateBackend(crate::vhu_console::Error),
#[error("Could not create daemon: {0}")]
Expand Down Expand Up @@ -131,8 +129,7 @@ pub(crate) fn start_backend_server(
backend: BackendType,
) -> Result<()> {
loop {
let controller =
ConsoleController::new(backend).map_err(Error::CouldNotCreateConsoleController)?;
let controller = ConsoleController::new(backend);
let arc_controller = Arc::new(RwLock::new(controller));
let vu_console_backend = Arc::new(RwLock::new(
VhostUserConsoleBackend::new(arc_controller).map_err(Error::CouldNotCreateBackend)?,
Expand Down Expand Up @@ -234,8 +231,8 @@ mod tests {
fn test_console_valid_configuration_nested() {
let args = ConsoleArgs {
socket_path: String::from("/tmp/vhost.sock").into(),
backend: BackendType::Nested.into(),
tcp_port: String::from("12345").into(),
backend: BackendType::Nested,
tcp_port: String::from("12345"),
socket_count: 1,
};

Expand All @@ -246,8 +243,8 @@ mod tests {
fn test_console_invalid_configuration_nested_1() {
let args = ConsoleArgs {
socket_path: String::from("/tmp/vhost.sock").into(),
backend: BackendType::Nested.into(),
tcp_port: String::from("12345").into(),
backend: BackendType::Nested,
tcp_port: String::from("12345"),
socket_count: 0,
};

Expand All @@ -261,8 +258,8 @@ mod tests {
fn test_console_invalid_configuration_nested_2() {
let args = ConsoleArgs {
socket_path: String::from("/tmp/vhost.sock").into(),
backend: BackendType::Nested.into(),
tcp_port: String::from("12345").into(),
backend: BackendType::Nested,
tcp_port: String::from("12345"),
socket_count: 2,
};

Expand All @@ -276,8 +273,8 @@ mod tests {
fn test_console_valid_configuration_network_1() {
let args = ConsoleArgs {
socket_path: String::from("/tmp/vhost.sock").into(),
backend: BackendType::Network.into(),
tcp_port: String::from("12345").into(),
backend: BackendType::Network,
tcp_port: String::from("12345"),
socket_count: 1,
};

Expand All @@ -288,8 +285,8 @@ mod tests {
fn test_console_valid_configuration_network_2() {
let args = ConsoleArgs {
socket_path: String::from("/tmp/vhost.sock").into(),
backend: BackendType::Network.into(),
tcp_port: String::from("12345").into(),
backend: BackendType::Network,
tcp_port: String::from("12345"),
socket_count: 2,
};

Expand All @@ -307,9 +304,7 @@ mod tests {
.into_iter()
.zip(tcp_addrs.iter())
{
let controller = ConsoleController::new(backend)
.map_err(Error::CouldNotCreateConsoleController)
.expect("Failed create console");
let controller = ConsoleController::new(backend);
let arc_controller = Arc::new(RwLock::new(controller));
let vu_console_backend = Arc::new(RwLock::new(
VhostUserConsoleBackend::new(arc_controller)
Expand Down Expand Up @@ -346,8 +341,8 @@ mod tests {
fn test_start_net_backend_success() {
let args = ConsoleArgs {
socket_path: String::from("/tmp/vhost.sock").into(),
backend: BackendType::Network.into(),
tcp_port: String::from("12345").into(),
backend: BackendType::Network,
tcp_port: String::from("12345"),
socket_count: 1,
};

Expand All @@ -358,8 +353,8 @@ mod tests {
fn test_start_nested_backend_success() {
let args = ConsoleArgs {
socket_path: String::from("/tmp/vhost.sock").into(),
backend: BackendType::Nested.into(),
tcp_port: String::from("12345").into(),
backend: BackendType::Nested,
tcp_port: String::from("12345"),
socket_count: 1,
};

Expand Down
8 changes: 3 additions & 5 deletions staging/vhost-device-console/src/console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ use clap::ValueEnum;
use log::trace;
use thiserror::Error as ThisError;

type Result<T> = std::result::Result<T, Error>;

#[derive(Copy, Clone, Debug, PartialEq, ThisError)]
pub(crate) enum Error {}

Expand All @@ -30,8 +28,8 @@ pub(crate) struct ConsoleController {
}

impl ConsoleController {
pub(crate) fn new(backend: BackendType) -> Result<ConsoleController> {
Ok(ConsoleController {
pub(crate) fn new(backend: BackendType) -> ConsoleController {
ConsoleController {
config: VirtioConsoleConfig {
cols: 20.into(),
rows: 20.into(),
Expand All @@ -40,7 +38,7 @@ impl ConsoleController {
},
backend,
exit: false,
})
}
}

pub(crate) fn config(&self) -> &VirtioConsoleConfig {
Expand Down
4 changes: 0 additions & 4 deletions staging/vhost-device-console/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,10 @@
//
// SPDX-License-Identifier: Apache-2.0 or BSD-3-Clause

#[cfg(target_env = "gnu")]
mod backend;
#[cfg(target_env = "gnu")]
mod console;
#[cfg(target_env = "gnu")]
mod vhu_console;

#[cfg(target_env = "gnu")]
fn main() {
backend::console_init()
}

0 comments on commit ac9c5bc

Please sign in to comment.