diff --git a/test/test-rpc/src/lib.rs b/test/test-rpc/src/lib.rs index e0088a67b50b..fc9ea67c8449 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; } } diff --git a/test/test-rpc/src/meta.rs b/test/test-rpc/src/meta.rs index 09200f869014..d721eb33f397 100644 --- a/test/test-rpc/src/meta.rs +++ b/test/test-rpc/src/meta.rs @@ -1,6 +1,24 @@ 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), +} + +#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)] +pub struct MacosVersion { + pub major: usize, +} + +#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)] +pub struct WindowsVersion { + pub major: usize, +} + #[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 8399e118d368..29f0f936d363 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 { + 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 db154e8819d2..be38fd97a9e2 100644 --- a/test/test-runner/src/sys.rs +++ b/test/test-runner/src/sys.rs @@ -2,6 +2,7 @@ use std::collections::HashMap; #[cfg(target_os = "windows")] use std::io; use test_rpc::mullvad_daemon::Verbosity; +use test_rpc::meta::OsVersion; #[cfg(target_os = "windows")] use std::ffi::OsString; @@ -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 { + 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 { + 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 { + Ok(OsVersion::Linux) +}