diff --git a/xtask/src/run.rs b/xtask/src/integration_test.rs similarity index 64% rename from xtask/src/run.rs rename to xtask/src/integration_test.rs index c433c3f7..b4f5dd15 100644 --- a/xtask/src/run.rs +++ b/xtask/src/integration_test.rs @@ -3,7 +3,7 @@ use std::{os::unix::process::CommandExt, path::PathBuf, process::Command}; use anyhow::Context as _; use clap::Parser; -use crate::build_ebpf::{build_ebpf, Architecture, BuildEbpfOptions as BuildOptions}; +use crate::build_ebpf::{build_ebpf, Architecture, BuildEbpfOptions}; #[derive(Debug, Parser)] pub struct Options { @@ -18,14 +18,20 @@ pub struct Options { pub runner: String, /// libbpf directory #[clap(long, action)] - pub libbpf_dir: String, + pub libbpf_dir: PathBuf, /// Arguments to pass to your application #[clap(name = "args", last = true)] pub run_args: Vec, } -/// Build the project -fn build(opts: &Options) -> Result<(), anyhow::Error> { +/// Configures building the integration test binary. +pub struct BuildOptions { + pub release: bool, +} + +/// Build the project. Returns the path to the binary that was built. +pub fn build(opts: BuildOptions) -> Result { + let BuildOptions { release } = opts; let mut args = vec!["build"]; if opts.release { args.push("--release") @@ -37,28 +43,35 @@ fn build(opts: &Options) -> Result<(), anyhow::Error> { .status() .expect("failed to build userspace"); assert!(status.success()); - Ok(()) + let profile = if release { "release" } else { "debug" }; + let bin_path = format!("target/{profile}/integration-test"); + Ok(PathBuf::from(bin_path)) } /// Build and run the project pub fn run(opts: Options) -> Result<(), anyhow::Error> { + let Options { + bpf_target, + release, + runner, + libbpf_dir, + run_args, + } = opts; // build our ebpf program followed by our application - build_ebpf(BuildOptions { - target: opts.bpf_target, - libbpf_dir: PathBuf::from(&opts.libbpf_dir), + build_ebpf(BuildEbpfOptions { + target: bpf_target, + libbpf_dir, }) .context("Error while building eBPF program")?; - build(&opts).context("Error while building userspace application")?; - // profile we are building (release or debug) - let profile = if opts.release { "release" } else { "debug" }; - let bin_path = format!("target/{profile}/integration-test"); + let bin_path = + build(BuildOptions { release }).context("Error while building userspace application")?; // arguments to pass to the application - let mut run_args: Vec<_> = opts.run_args.iter().map(String::as_str).collect(); + let mut run_args: Vec<_> = run_args.iter().map(String::as_str).collect(); // configure args - let mut args: Vec<_> = opts.runner.trim().split_terminator(' ').collect(); - args.push(bin_path.as_str()); + let mut args: Vec<_> = runner.trim().split_terminator(' ').collect(); + args.push(bin_path.to_str().expect("Invalid binary path")); args.append(&mut run_args); // spawn the command diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 81f3e658..e50e8675 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -2,7 +2,8 @@ mod build_ebpf; mod build_test; mod codegen; mod docs; -mod run; +mod integration_test; + pub(crate) mod utils; use std::process::exit; @@ -20,7 +21,7 @@ enum Command { Docs, BuildIntegrationTest(build_test::Options), BuildIntegrationTestEbpf(build_ebpf::BuildEbpfOptions), - IntegrationTest(run::Options), + IntegrationTest(integration_test::Options), } fn main() { @@ -32,7 +33,7 @@ fn main() { Docs => docs::docs(), BuildIntegrationTest(opts) => build_test::build_test(opts), BuildIntegrationTestEbpf(opts) => build_ebpf::build_ebpf(opts), - IntegrationTest(opts) => run::run(opts), + IntegrationTest(opts) => integration_test::run(opts), }; if let Err(e) = ret {