Skip to content

Commit

Permalink
Add get_os_version RPC
Browse files Browse the repository at this point in the history
  • Loading branch information
dlon committed Apr 8, 2024
1 parent d175e15 commit 7f4ad14
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 0 deletions.
6 changes: 6 additions & 0 deletions test/test-rpc/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?
}
}
3 changes: 3 additions & 0 deletions test/test-rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
}
}

Expand Down
18 changes: 18 additions & 0 deletions test/test-rpc/src/meta.rs
Original file line number Diff line number Diff line change
@@ -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: 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 {
Expand Down
5 changes: 5 additions & 0 deletions test/test-runner/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down
36 changes: 36 additions & 0 deletions test/test-runner/src/sys.rs
Original file line number Diff line number Diff line change
@@ -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")]
Expand Down Expand Up @@ -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)
}

0 comments on commit 7f4ad14

Please sign in to comment.