@ -3,7 +3,7 @@ use std::{os::unix::process::CommandExt, path::PathBuf, process::Command};
use anyhow ::Context as _ ;
use anyhow ::Context as _ ;
use clap ::Parser ;
use clap ::Parser ;
use crate ::build_ebpf ::{ build_ebpf , Architecture , BuildEbpfOptions as BuildOptions } ;
use crate ::build_ebpf ::{ build_ebpf , Architecture , BuildEbpfOptions } ;
#[ derive(Debug, Parser) ]
#[ derive(Debug, Parser) ]
pub struct Options {
pub struct Options {
@ -18,14 +18,20 @@ pub struct Options {
pub runner : String ,
pub runner : String ,
/// libbpf directory
/// libbpf directory
#[ clap(long, action) ]
#[ clap(long, action) ]
pub libbpf_dir : String ,
pub libbpf_dir : PathBuf ,
/// Arguments to pass to your application
/// Arguments to pass to your application
#[ clap(name = " args " , last = true) ]
#[ clap(name = " args " , last = true) ]
pub run_args : Vec < String > ,
pub run_args : Vec < String > ,
}
}
/// Build the project
/// Configures building the integration test binary.
fn build ( opts : & Options ) -> Result < ( ) , anyhow ::Error > {
pub struct BuildOptions {
pub release : bool ,
}
/// Build the project. Returns the path to the binary that was built.
pub fn build ( opts : BuildOptions ) -> Result < std ::path ::PathBuf , anyhow ::Error > {
let BuildOptions { release } = opts ;
let mut args = vec! [ "build" ] ;
let mut args = vec! [ "build" ] ;
if opts . release {
if opts . release {
args . push ( "--release" )
args . push ( "--release" )
@ -37,28 +43,35 @@ fn build(opts: &Options) -> Result<(), anyhow::Error> {
. status ( )
. status ( )
. expect ( "failed to build userspace" ) ;
. expect ( "failed to build userspace" ) ;
assert! ( status . success ( ) ) ;
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
/// Build and run the project
pub fn run ( opts : Options ) -> Result < ( ) , anyhow ::Error > {
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 our ebpf program followed by our application
build_ebpf ( BuildOptions {
build_ebpf ( Build Ebpf Options {
target : opts . bpf_target ,
target : bpf_target,
libbpf_dir : PathBuf ::from ( & opts . libbpf_dir ) ,
libbpf_dir ,
} )
} )
. context ( "Error while building eBPF program" ) ? ;
. context ( "Error while building eBPF program" ) ? ;
build ( & opts ) . context ( "Error while building userspace application" ) ? ;
let bin_path =
// profile we are building (release or debug)
build ( BuildOptions { release } ) . context ( "Error while building userspace application" ) ? ;
let profile = if opts . release { "release" } else { "debug" } ;
let bin_path = format! ( "target/{profile}/integration-test" ) ;
// arguments to pass to the 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
// configure args
let mut args : Vec < _ > = opts. runner. trim ( ) . split_terminator ( ' ' ) . collect ( ) ;
let mut args : Vec < _ > = runner. trim ( ) . split_terminator ( ' ' ) . collect ( ) ;
args . push ( bin_path . as_str( ) ) ;
args . push ( bin_path . to_str( ) . expect ( "Invalid binary path" ) ) ;
args . append ( & mut run_args ) ;
args . append ( & mut run_args ) ;
// spawn the command
// spawn the command