summaryrefslogtreecommitdiffhomepage
path: root/test/test-runner/src/sys/mod.rs
diff options
context:
space:
mode:
authorDavid Lönnhager <david.l@mullvad.net>2025-09-11 16:10:31 +0200
committerDavid Lönnhager <david.l@mullvad.net>2025-09-12 11:29:56 +0200
commiteeb8da48efab6b635d11fb92ab57a3db72d486bd (patch)
tree6ab7adabe89746ad1e800e0720565974a9204896 /test/test-runner/src/sys/mod.rs
parent295eff0a7d5b0b2ab388bab47035a68d7169f7d1 (diff)
downloadmullvadvpn-eeb8da48efab6b635d11fb92ab57a3db72d486bd.tar.xz
mullvadvpn-eeb8da48efab6b635d11fb92ab57a3db72d486bd.zip
Split sys module in test-runner into one per platform
Diffstat (limited to 'test/test-runner/src/sys/mod.rs')
-rw-r--r--test/test-runner/src/sys/mod.rs62
1 files changed, 62 insertions, 0 deletions
diff --git a/test/test-runner/src/sys/mod.rs b/test/test-runner/src/sys/mod.rs
new file mode 100644
index 0000000000..48b539739e
--- /dev/null
+++ b/test/test-runner/src/sys/mod.rs
@@ -0,0 +1,62 @@
+use std::path::Path;
+use test_rpc::mullvad_daemon::SOCKET_PATH;
+use test_rpc::mullvad_daemon::ServiceStatus;
+
+#[cfg(target_os = "windows")]
+mod windows;
+
+#[cfg(target_os = "windows")]
+pub use windows::*;
+
+#[cfg(target_os = "linux")]
+mod linux;
+
+#[cfg(target_os = "linux")]
+pub use linux::*;
+
+#[cfg(target_os = "macos")]
+mod macos;
+
+#[cfg(target_os = "macos")]
+pub use macos::*;
+
+#[cfg(unix)]
+pub fn reboot() -> Result<(), test_rpc::Error> {
+ log::debug!("Rebooting system");
+
+ std::thread::spawn(|| {
+ #[cfg(target_os = "linux")]
+ let mut cmd = std::process::Command::new("/usr/sbin/shutdown");
+ #[cfg(target_os = "macos")]
+ let mut cmd = std::process::Command::new("/sbin/shutdown");
+ cmd.args(["-r", "now"]);
+
+ std::thread::sleep(std::time::Duration::from_secs(5));
+
+ let _ = cmd.spawn().map_err(|error| {
+ log::error!("Failed to spawn shutdown command: {error}");
+ error
+ });
+ });
+
+ Ok(())
+}
+
+pub fn get_daemon_status() -> ServiceStatus {
+ let rpc_socket_exists = Path::new(SOCKET_PATH).exists();
+
+ // On Windows, we must also make sure service isn't in a pending state, since interacting with
+ // the service may fail even if there is a working named pipe.
+ #[cfg(target_os = "windows")]
+ let service_is_started =
+ get_daemon_system_service_status().unwrap_or(ServiceStatus::NotRunning);
+
+ // NOTE: May not be necessary on non-Windows
+ #[cfg(not(target_os = "windows"))]
+ let service_is_started = ServiceStatus::Running;
+
+ match (rpc_socket_exists, service_is_started) {
+ (true, ServiceStatus::Running) => ServiceStatus::Running,
+ _ => ServiceStatus::NotRunning,
+ }
+}