diff options
| author | David Lönnhager <david.l@mullvad.net> | 2024-04-09 09:50:38 +0200 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2024-04-09 09:50:38 +0200 |
| commit | 77d24c0ac3ec1f75c57b1b208d7e01654c018e81 (patch) | |
| tree | 9a2771f538a350d687afd9b4100a535b210b3bba /test | |
| parent | 6868d3c3336a8289c56fdd978ad61ef8a19a7155 (diff) | |
| parent | 5eb50dd7d68fb0a5231424edf5f68afae5f4df83 (diff) | |
| download | mullvadvpn-77d24c0ac3ec1f75c57b1b208d7e01654c018e81.tar.xz mullvadvpn-77d24c0ac3ec1f75c57b1b208d7e01654c018e81.zip | |
Merge branch 'test-add-os-version-info'
Diffstat (limited to 'test')
| -rw-r--r-- | test/test-manager/src/run_tests.rs | 13 | ||||
| -rw-r--r-- | test/test-rpc/src/client.rs | 6 | ||||
| -rw-r--r-- | test/test-rpc/src/lib.rs | 3 | ||||
| -rw-r--r-- | test/test-rpc/src/meta.rs | 28 | ||||
| -rw-r--r-- | test/test-runner/src/main.rs | 5 | ||||
| -rw-r--r-- | test/test-runner/src/sys.rs | 36 |
6 files changed, 91 insertions, 0 deletions
diff --git a/test/test-manager/src/run_tests.rs b/test/test-manager/src/run_tests.rs index 6b3da37138..b2b1e9534b 100644 --- a/test/test-manager/src/run_tests.rs +++ b/test/test-manager/src/run_tests.rs @@ -49,6 +49,8 @@ pub async fn run( let mullvad_client = mullvad_daemon::new_rpc_client(connection_handle, mullvad_daemon_transport); + print_os_version(&client).await; + let mut tests: Vec<_> = inventory::iter::<tests::TestMetadata>() .filter(|test| test.should_run_on_os(TEST_CONFIG.os)) .collect(); @@ -220,3 +222,14 @@ where result, } } + +async fn print_os_version(client: &ServiceClient) { + match client.get_os_version().await { + Ok(version) => { + log::debug!("Guest OS version: {version}"); + } + Err(error) => { + log::debug!("Failed to obtain guest OS version: {error}"); + } + } +} diff --git a/test/test-rpc/src/client.rs b/test/test-rpc/src/client.rs index 0c4010a521..79c6a038ca 100644 --- a/test/test-rpc/src/client.rs +++ b/test/test-rpc/src/client.rs @@ -378,4 +378,10 @@ impl ServiceClient { .close_child_stdin(tarpc::context::current(), pid) .await? } + + pub async fn get_os_version(&self) -> Result<meta::OsVersion, Error> { + self.client + .get_os_version(tarpc::context::current()) + .await? + } } diff --git a/test/test-rpc/src/lib.rs b/test/test-rpc/src/lib.rs index e0088a67b5..fc9ea67c84 100644 --- a/test/test-rpc/src/lib.rs +++ b/test/test-rpc/src/lib.rs @@ -244,6 +244,9 @@ mod service { /// Kill a process spawned through [Service::spawn]. async fn kill_child(pid: u32) -> Result<(), Error>; + + /// Returns operating system details + async fn get_os_version() -> Result<meta::OsVersion, Error>; } } diff --git a/test/test-rpc/src/meta.rs b/test/test-rpc/src/meta.rs index 09200f8690..40dda3bb9c 100644 --- a/test/test-rpc/src/meta.rs +++ b/test/test-rpc/src/meta.rs @@ -1,6 +1,34 @@ use serde::{Deserialize, Serialize}; use std::str::FromStr; +#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)] +#[serde(rename_all = "snake_case")] +pub enum OsVersion { + Linux, + Macos(MacosVersion), + Windows(WindowsVersion), +} + +impl std::fmt::Display for OsVersion { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + OsVersion::Linux => f.write_str("Linux"), + OsVersion::Macos(version) => write!(f, "macOS {}", version.major), + OsVersion::Windows(version) => write!(f, "Windows {}", version.major), + } + } +} + +#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)] +pub struct MacosVersion { + pub major: u32, +} + +#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)] +pub struct WindowsVersion { + pub major: u32, +} + #[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone, Copy)] #[serde(rename_all = "snake_case")] pub enum Os { diff --git a/test/test-runner/src/main.rs b/test/test-runner/src/main.rs index 8399e118d3..29f0f936d3 100644 --- a/test/test-runner/src/main.rs +++ b/test/test-runner/src/main.rs @@ -12,6 +12,7 @@ use util::OnDrop; use tarpc::{context, server::Channel}; use test_rpc::{ + meta::OsVersion, mullvad_daemon::{ServiceStatus, SOCKET_PATH}, net::SockHandleId, package::Package, @@ -533,6 +534,10 @@ impl Service for TestServer { Ok(()) } + + async fn get_os_version(self, _: context::Context) -> Result<OsVersion, test_rpc::Error> { + sys::get_os_version() + } } fn get_pipe_status() -> ServiceStatus { diff --git a/test/test-runner/src/sys.rs b/test/test-runner/src/sys.rs index db154e8819..7576c64e89 100644 --- a/test/test-runner/src/sys.rs +++ b/test/test-runner/src/sys.rs @@ -1,6 +1,7 @@ use std::collections::HashMap; #[cfg(target_os = "windows")] use std::io; +use test_rpc::meta::OsVersion; use test_rpc::mullvad_daemon::Verbosity; #[cfg(target_os = "windows")] @@ -583,3 +584,38 @@ async fn wait_for_service_state(awaited_state: ServiceState) -> Result<(), test_ } Ok(()) } + +#[cfg(target_os = "macos")] +pub fn get_os_version() -> Result<OsVersion, test_rpc::Error> { + use test_rpc::meta::MacosVersion; + + let version = talpid_platform_metadata::MacosVersion::new() + .inspect_err(|error| { + log::error!("Failed to obtain OS version: {error}"); + }) + .map_err(|_| test_rpc::Error::Syscall)?; + + Ok(OsVersion::Macos(MacosVersion { + major: version.major_version(), + })) +} + +#[cfg(target_os = "windows")] +pub fn get_os_version() -> Result<OsVersion, test_rpc::Error> { + use test_rpc::meta::WindowsVersion; + + let version = talpid_platform_metadata::WindowsVersion::new() + .inspect_err(|error| { + log::error!("Failed to obtain OS version: {error}"); + }) + .map_err(|_| test_rpc::Error::Syscall)?; + + Ok(OsVersion::Windows(WindowsVersion { + major: version.release_version().0, + })) +} + +#[cfg(target_os = "linux")] +pub fn get_os_version() -> Result<OsVersion, test_rpc::Error> { + Ok(OsVersion::Linux) +} |
