#!/bin/sh # Source the main regression test library if present [ -f "${RT_LIB}" ] && . "${RT_LIB}" # Temporary directory for tests to use. AYA_TMPDIR="${RT_PROJECT_ROOT}/_tmp" # Directory for VM images AYA_IMGDIR="${RT_PROJECT_ROOT}/_images" # Cancel Exit Code RT_CANCEL=253 # Test Architecture if [ -z "${AYA_TEST_ARCH}" ]; then AYA_TEST_ARCH="$(uname -m)" fi # Test Image if [ -z "${AYA_TEST_IMAGE}" ]; then AYA_TEST_IMAGE="fedora35" fi case "${AYA_TEST_IMAGE}" in fedora*) AYA_SSH_USER="fedora";; centos*) AYA_SSH_USER="centos";; esac # compiles the ebpf program by using rust-script to create a temporary # cargo project in $(pwd)/ebpf. caller must add rm -rf ebpf to the clean_up # functionAYA_TEST_ARCH compile_ebpf() { file=$(basename "$1") dir=$(dirname "$1") base=$(echo "${file}" | cut -f1 -d '.') rm -rf "${dir}/ebpf" rust-script --pkg-path "${dir}/ebpf" --gen-pkg-only "$1" artifact=$(sed -n 's/^name = \"\(.*\)\"/\1/p' "${dir}/ebpf/Cargo.toml" | head -n1) mkdir -p "${dir}/.cargo" cat > "${dir}/.cargo/config.toml" << EOF [build] target = "bpfel-unknown-none" [unstable] build-std = ["core"] EOF cat >> "${dir}/ebpf/Cargo.toml" << EOF [workspace] members = [] EOF # overwrite the rs file as rust-script adds a main fn cp "$1" "${dir}/ebpf/${file}" cargo build -q --manifest-path "${dir}/ebpf/Cargo.toml" mv "${dir}/ebpf/target/bpfel-unknown-none/debug/${artifact}" "${dir}/${base}.o" rm -rf "${dir}/.cargo" rm -rf "${dir}/ebpf" } # compile a C BPF file compile_c_ebpf() { file=$(basename "$1") dir=$(dirname "$1") base=$(echo "${file}" | cut -f1 -d '.') rust-script "${RT_PROJECT_ROOT}/_lib/compile-ebpf.ers" "${1}" "${dir}/${base}.o" rm -rf "${dir}/include" } # compiles the userspace program by using rust-script to create a temporary # cargo project in $(pwd)/user. caller must add rm -rf ebpf to the clean_up # function. this is required since the binary produced has to be run with # sudo to load an eBPF program compile_user() { file=$(basename "$1") dir=$(dirname "$1") base=$(echo "${file}" | cut -f1 -d '.') rm -rf "${dir}/user" rust-script --pkg-path "${dir}/user" --gen-pkg-only "$1" artifact=$(sed -n 's/^name = \"\(.*\)\"/\1/p' "${dir}/user/Cargo.toml" | head -n1) cat >> "${dir}/user/Cargo.toml" << EOF [workspace] members = [] EOF cargo build -q --release --manifest-path "${dir}/user/Cargo.toml" --target=x86_64-unknown-linux-musl mv "${dir}/user/target/x86_64-unknown-linux-musl/release/${artifact}" "${dir}/${base}" rm -rf "${dir}/user" } download_images() { mkdir -p "${AYA_IMGDIR}" case $1 in fedora35) if [ ! -f "${AYA_IMGDIR}/fedora35.${AYA_TEST_ARCH}.qcow2" ]; then IMAGE="Fedora-Cloud-Base-35-1.2.${AYA_TEST_ARCH}.qcow2" IMAGE_URL="https://download.fedoraproject.org/pub/fedora/linux/releases/35/Cloud/${AYA_TEST_ARCH}/images" echo "Downloading: ${IMAGE}, this may take a while..." curl -o "${AYA_IMGDIR}/fedora35.${AYA_TEST_ARCH}.qcow2" -sSL "${IMAGE_URL}/${IMAGE}" fi ;; centos8) if [ ! -f "${AYA_IMGDIR}/centos8.${AYA_TEST_ARCH}.qcow2" ]; then IMAGE="CentOS-8-GenericCloud-8.4.2105-20210603.0.${AYA_TEST_ARCH}.qcow2" IMAGE_URL="https://cloud.centos.org/centos/8/${AYA_TEST_ARCH}/images" echo "Downloading: ${IMAGE}, this may take a while..." curl -o "${AYA_IMGDIR}/centos8.${AYA_TEST_ARCH}.qcow2" -sSL "${IMAGE_URL}/${IMAGE}" fi ;; *) echo "$1 is not a recognized image name" return 1 ;; esac } start_vm() { download_images "${AYA_TEST_IMAGE}" # prepare config cat > "${AYA_TMPDIR}/metadata.yaml" < "${AYA_TMPDIR}/user-data.yaml" < "${AYA_TMPDIR}/ssh_config" <