From 739ccb057ce6bcc3711645b75174ee55bd3e51d3 Mon Sep 17 00:00:00 2001 From: KMC Date: Wed, 11 Mar 2026 18:09:23 -0700 Subject: [PATCH] fixed test path for dpd --- test-utils/src/dev/dendrite.rs | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/test-utils/src/dev/dendrite.rs b/test-utils/src/dev/dendrite.rs index e178c5ce72e..d9a724e6618 100644 --- a/test-utils/src/dev/dendrite.rs +++ b/test-utils/src/dev/dendrite.rs @@ -63,7 +63,14 @@ impl DendriteInstance { args.push(socket_addr.to_string()); } - let mut child = tokio::process::Command::new("dpd") + let (dpd_bin, p4_dir) = get_dpd_path(); + let mut cmd = tokio::process::Command::new(dpd_bin); + if let Some(ref p4_dir) = p4_dir { + if std::env::var("P4_DIR").is_err() { + cmd.env("P4_DIR", p4_dir); + } + } + let mut child = cmd .args(&args) .stdin(Stdio::null()) .stdout(Stdio::from(redirect_file( @@ -110,6 +117,26 @@ impl DendriteInstance { } } +fn get_dpd_path() -> (PathBuf, Option) { + // On macOS, std::env::current_exe() does not resolve symlinks. + let dpd_path = Path::new("dpd"); + let resolved_dpd = std::env::var_os("PATH") + .and_then(|paths| { + std::env::split_paths(&paths) + .map(|dir| dir.join("dpd")) + .find(|p| p.is_file()) + }) + .and_then(|p| std::fs::canonicalize(&p).ok()); + + // Rebuild the p4 directory path from dpd path + let p4_dir = resolved_dpd.as_ref().and_then(|p| { + p.parent().and_then(|p| p.parent()).map(|p| p.join("sidecar")) + }); + + let dpd_bin = resolved_dpd.as_deref().unwrap_or(dpd_path).to_owned(); + (dpd_bin, p4_dir) +} + impl Drop for DendriteInstance { fn drop(&mut self) { if self.child.is_some() || self.data_dir.is_some() { @@ -206,6 +233,8 @@ async fn find_dendrite_port_in_log( #[cfg(test)] mod tests { + use crate::dev::dendrite::get_dpd_path; + use super::find_dendrite_port_in_log; use std::io::Write; use std::process::Stdio; @@ -216,7 +245,8 @@ mod tests { #[tokio::test] async fn test_dpd_in_path() { // With no arguments, we expect to see the default help message. - tokio::process::Command::new("dpd") + let (dpd_bin, _) = get_dpd_path(); + tokio::process::Command::new(dpd_bin) .stdin(Stdio::null()) .stdout(Stdio::null()) .stderr(Stdio::null())