|  |  | @ -1,20 +1,13 @@ | 
			
		
	
		
		
			
				
					
					|  |  |  | #!/bin/bash |  |  |  | #!/usr/bin/env bash | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | set -ex |  |  |  | set -eux | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | TEMPLATE_DIR=$1 |  |  |  | TEMPLATE_DIR=$1 | 
			
		
	
		
		
			
				
					
					|  |  |  | if [ -z "${TEMPLATE_DIR}" ]; then echo "template dir required"; exit 1; fi |  |  |  | if [ -z "${TEMPLATE_DIR}" ]; then echo "template dir required"; exit 1; fi | 
			
		
	
		
		
			
				
					
					|  |  |  | PROG_TYPE=$2 |  |  |  | PROG_TYPE=$2 | 
			
		
	
		
		
			
				
					
					|  |  |  | if [ -z "${PROG_TYPE}" ]; then echo "program type required"; exit 1; fi |  |  |  | if [ -z "${PROG_TYPE}" ]; then echo "program type required"; exit 1; fi | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | CRATE_NAME=aya-test-crate | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | TMP_DIR=$(mktemp -d) |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | clean_up() { |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     # shellcheck disable=SC2317 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     rm -rf "${TMP_DIR}" |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | } |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | trap clean_up EXIT |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | pushd "${TMP_DIR}" |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | case "${PROG_TYPE}" in |  |  |  | case "${PROG_TYPE}" in | 
			
		
	
		
		
			
				
					
					|  |  |  |     "cgroup_sockopt") |  |  |  |     "cgroup_sockopt") | 
			
		
	
		
		
			
				
					
					|  |  |  | 	    ADDITIONAL_ARGS=(-d sockopt_target=getsockopt) |  |  |  | 	    ADDITIONAL_ARGS=(-d sockopt_target=getsockopt) | 
			
		
	
	
		
		
			
				
					|  |  | @ -26,7 +19,7 @@ case "${PROG_TYPE}" in | 
			
		
	
		
		
			
				
					
					|  |  |  |         ADDITIONAL_ARGS=(-d fn_name=try_to_wake_up) |  |  |  |         ADDITIONAL_ARGS=(-d fn_name=try_to_wake_up) | 
			
		
	
		
		
			
				
					
					|  |  |  |         ;; |  |  |  |         ;; | 
			
		
	
		
		
			
				
					
					|  |  |  |     "kprobe"|"kretprobe") |  |  |  |     "kprobe"|"kretprobe") | 
			
		
	
		
		
			
				
					
					|  |  |  |         ADDITIONAL_ARGS=(-d kprobe=test) |  |  |  |         ADDITIONAL_ARGS=(-d kprobe=do_unlinkat) | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |         ;; |  |  |  |         ;; | 
			
		
	
		
		
			
				
					
					|  |  |  |     "lsm") |  |  |  |     "lsm") | 
			
		
	
		
		
			
				
					
					|  |  |  |         ADDITIONAL_ARGS=(-d lsm_hook=file_open) |  |  |  |         ADDITIONAL_ARGS=(-d lsm_hook=file_open) | 
			
		
	
	
		
		
			
				
					|  |  | @ -44,21 +37,52 @@ case "${PROG_TYPE}" in | 
			
		
	
		
		
			
				
					
					|  |  |  | 	    ADDITIONAL_ARGS=(-d tracepoint_category=net -d tracepoint_name=net_dev_queue) |  |  |  | 	    ADDITIONAL_ARGS=(-d tracepoint_category=net -d tracepoint_name=net_dev_queue) | 
			
		
	
		
		
			
				
					
					|  |  |  |         ;; |  |  |  |         ;; | 
			
		
	
		
		
			
				
					
					|  |  |  |     "uprobe"|"uretprobe") |  |  |  |     "uprobe"|"uretprobe") | 
			
		
	
		
		
			
				
					
					|  |  |  |         ADDITIONAL_ARGS=(-d uprobe_target=testlib -d uprobe_fn_name=testfn) |  |  |  |         ADDITIONAL_ARGS=(-d uprobe_target=/proc/self/exe -d uprobe_fn_name=main) | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |         ;; |  |  |  |         ;; | 
			
		
	
		
		
			
				
					
					|  |  |  |     *) |  |  |  |     *) | 
			
		
	
		
		
			
				
					
					|  |  |  |         ADDITIONAL_ARGS=() |  |  |  |         ADDITIONAL_ARGS=() | 
			
		
	
		
		
			
				
					
					|  |  |  | esac |  |  |  | esac | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | cargo generate --path "${TEMPLATE_DIR}" -n test -d program_type="${PROG_TYPE}" "${ADDITIONAL_ARGS[@]}" |  |  |  | TMP_DIR=$(mktemp -d) | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | pushd test |  |  |  | clean_up() { | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     # shellcheck disable=SC2317 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     rm -rf "${TMP_DIR}" | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | trap clean_up EXIT | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | pushd "${TMP_DIR}" | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | cargo generate --path "${TEMPLATE_DIR}" -n "${CRATE_NAME}" -d program_type="${PROG_TYPE}" "${ADDITIONAL_ARGS[@]}" | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | pushd "${CRATE_NAME}" | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | cargo +nightly fmt --all -- --check |  |  |  | cargo +nightly fmt --all -- --check | 
			
		
	
		
		
			
				
					
					|  |  |  | cargo build --package test |  |  |  | cargo build --package "${CRATE_NAME}" | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | cargo build --package test --release |  |  |  | cargo build --package "${CRATE_NAME}" --release | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | # We cannot run clippy over the whole workspace at once due to feature unification. Since both test |  |  |  | # We cannot run clippy over the whole workspace at once due to feature unification. Since both | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | # and test-ebpf depend on test-common and test activates test-common's aya dependency, we end up |  |  |  | # ${CRATE_NAME} and ${CRATE_NAME}-ebpf depend on ${CRATE_NAME}-common and ${CRATE_NAME} activates | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | # trying to compile the panic handler twice: once from the bpf program, and again from std via aya. |  |  |  | # ${CRATE_NAME}-common's aya dependency, we end up trying to compile the panic handler twice: once | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | cargo clippy --exclude test-ebpf --all-targets --workspace -- --deny warnings |  |  |  | # from the bpf program, and again from std via aya. | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | cargo clippy --package test-ebpf --all-targets -- --deny warnings |  |  |  | cargo clippy --exclude "${CRATE_NAME}-ebpf" --all-targets --workspace -- --deny warnings | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | popd |  |  |  | cargo clippy --package "${CRATE_NAME}-ebpf" --all-targets -- --deny warnings | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | exit 0 |  |  |  | 
 | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | expect << EOF | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |   set timeout 30        ;# Increase timeout if necessary | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |   spawn cargo xtask run | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |   expect { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     -re "Waiting for Ctrl-C.*" { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |       send -- \003      ;# Send Ctrl-C | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     timeout { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |       puts "Error: Timed out waiting for 'Waiting for Ctrl-C...'" | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |       exit 1 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     eof { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |       puts "Error: Process exited prematurely" | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |       exit 1 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |   } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |   expect { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     -re "Exiting.*" { } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     eof { } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |   } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | EOF | 
			
		
	
	
		
		
			
				
					|  |  | 
 |