diff options
Diffstat (limited to '')
-rwxr-xr-x | ci/managers/debian.sh | 95 | ||||
-rwxr-xr-x | ci/managers/test_compile.sh | 15 | ||||
-rw-r--r-- | ci/managers/travis_wait.bash | 61 | ||||
-rwxr-xr-x | ci/managers/ubuntu.sh | 24 |
4 files changed, 195 insertions, 0 deletions
diff --git a/ci/managers/debian.sh b/ci/managers/debian.sh new file mode 100755 index 0000000..3d3f860 --- /dev/null +++ b/ci/managers/debian.sh @@ -0,0 +1,95 @@ +#!/bin/bash + +PHASES=(${@:-SETUP RUN RUN_ASAN CLEANUP}) +DEBIAN_RELEASE="${DEBIAN_RELEASE:-testing}" +CONT_NAME="${CONT_NAME:-libbpf-debian-$DEBIAN_RELEASE}" +ENV_VARS="${ENV_VARS:-}" +DOCKER_RUN="${DOCKER_RUN:-docker run}" +REPO_ROOT="${REPO_ROOT:-$PWD}" +ADDITIONAL_DEPS=(pkgconf) +EXTRA_CFLAGS="" +EXTRA_LDFLAGS="" + +function info() { + echo -e "\033[33;1m$1\033[0m" +} + +function error() { + echo -e "\033[31;1m$1\033[0m" +} + +function docker_exec() { + docker exec $ENV_VARS $CONT_NAME "$@" +} + +set -eu + +source "$(dirname $0)/travis_wait.bash" + +for phase in "${PHASES[@]}"; do + case $phase in + SETUP) + info "Setup phase" + info "Using Debian $DEBIAN_RELEASE" + + docker --version + + docker pull debian:$DEBIAN_RELEASE + info "Starting container $CONT_NAME" + $DOCKER_RUN -v $REPO_ROOT:/build:rw \ + -w /build --privileged=true --name $CONT_NAME \ + -dit --net=host debian:$DEBIAN_RELEASE /bin/bash + echo -e "::group::Build Env Setup" + docker_exec bash -c "echo deb-src http://deb.debian.org/debian $DEBIAN_RELEASE main >>/etc/apt/sources.list" + docker_exec apt-get -y update + docker_exec apt-get -y install aptitude + docker_exec aptitude -y install make libz-dev libelf-dev + docker_exec aptitude -y install "${ADDITIONAL_DEPS[@]}" + echo -e "::endgroup::" + ;; + RUN|RUN_CLANG|RUN_CLANG14|RUN_CLANG15|RUN_CLANG16|RUN_GCC10|RUN_GCC11|RUN_GCC12|RUN_ASAN|RUN_CLANG_ASAN|RUN_GCC10_ASAN) + CC="cc" + if [[ "$phase" =~ "RUN_CLANG(\d+)(_ASAN)?" ]]; then + ENV_VARS="-e CC=clang-${BASH_REMATCH[1]} -e CXX=clang++-${BASH_REMATCH[1]}" + CC="clang-${BASH_REMATCH[1]}" + elif [[ "$phase" = *"CLANG"* ]]; then + ENV_VARS="-e CC=clang -e CXX=clang++" + CC="clang" + elif [[ "$phase" =~ "RUN_GCC(\d+)(_ASAN)?" ]]; then + ENV_VARS="-e CC=gcc-${BASH_REMATCH[1]} -e CXX=g++-${BASH_REMATCH[1]}" + CC="gcc-${BASH_REMATCH[1]}" + fi + if [[ "$phase" = *"ASAN"* ]]; then + EXTRA_CFLAGS="${EXTRA_CFLAGS} -fsanitize=address,undefined" + EXTRA_LDFLAGS="${EXTRA_LDFLAGS} -fsanitize=address,undefined" + fi + if [[ "$CC" != "cc" ]]; then + docker_exec aptitude -y install "$CC" + else + docker_exec aptitude -y install gcc + fi + docker_exec mkdir build install + docker_exec ${CC} --version + info "build" + docker_exec make -j$((4*$(nproc))) EXTRA_CFLAGS="${EXTRA_CFLAGS}" EXTRA_LDFLAGS="${EXTRA_LDFLAGS}" -C ./src -B OBJDIR=../build + info "ldd build/libbpf.so:" + docker_exec ldd build/libbpf.so + if ! docker_exec ldd build/libbpf.so | grep -q libelf; then + error "No reference to libelf.so in libbpf.so!" + exit 1 + fi + info "install" + docker_exec make -j$((4*$(nproc))) -C src OBJDIR=../build DESTDIR=../install install + info "link binary" + docker_exec bash -c "EXTRA_CFLAGS=\"${EXTRA_CFLAGS}\" EXTRA_LDFLAGS=\"${EXTRA_LDFLAGS}\" ./ci/managers/test_compile.sh" + ;; + CLEANUP) + info "Cleanup phase" + docker stop $CONT_NAME + docker rm -f $CONT_NAME + ;; + *) + echo >&2 "Unknown phase '$phase'" + exit 1 + esac +done diff --git a/ci/managers/test_compile.sh b/ci/managers/test_compile.sh new file mode 100755 index 0000000..094ba3e --- /dev/null +++ b/ci/managers/test_compile.sh @@ -0,0 +1,15 @@ +#!/bin/bash +set -euox pipefail + +EXTRA_CFLAGS=${EXTRA_CFLAGS:-} +EXTRA_LDFLAGS=${EXTRA_LDFLAGS:-} + +cat << EOF > main.c +#include <bpf/libbpf.h> +int main() { + return bpf_object__open(0) < 0; +} +EOF + +# static linking +${CC:-cc} ${EXTRA_CFLAGS} ${EXTRA_LDFLAGS} -o main -I./include/uapi -I./install/usr/include main.c ./build/libbpf.a -lelf -lz diff --git a/ci/managers/travis_wait.bash b/ci/managers/travis_wait.bash new file mode 100644 index 0000000..acf6ad1 --- /dev/null +++ b/ci/managers/travis_wait.bash @@ -0,0 +1,61 @@ +# This was borrowed from https://github.com/travis-ci/travis-build/tree/master/lib/travis/build/bash +# to get around https://github.com/travis-ci/travis-ci/issues/9979. It should probably be removed +# as soon as Travis CI has started to provide an easy way to export the functions to bash scripts. + +travis_jigger() { + local cmd_pid="${1}" + shift + local timeout="${1}" + shift + local count=0 + + echo -e "\\n" + + while [[ "${count}" -lt "${timeout}" ]]; do + count="$((count + 1))" + echo -ne "Still running (${count} of ${timeout}): ${*}\\r" + sleep 60 + done + + echo -e "\\n${ANSI_RED}Timeout (${timeout} minutes) reached. Terminating \"${*}\"${ANSI_RESET}\\n" + kill -9 "${cmd_pid}" +} + +travis_wait() { + local timeout="${1}" + + if [[ "${timeout}" =~ ^[0-9]+$ ]]; then + shift + else + timeout=20 + fi + + local cmd=("${@}") + local log_file="travis_wait_${$}.log" + + "${cmd[@]}" &>"${log_file}" & + local cmd_pid="${!}" + + travis_jigger "${!}" "${timeout}" "${cmd[@]}" & + local jigger_pid="${!}" + local result + + { + set +e + wait "${cmd_pid}" 2>/dev/null + result="${?}" + ps -p"${jigger_pid}" &>/dev/null && kill "${jigger_pid}" + set -e + } + + if [[ "${result}" -eq 0 ]]; then + echo -e "\\n${ANSI_GREEN}The command ${cmd[*]} exited with ${result}.${ANSI_RESET}" + else + echo -e "\\n${ANSI_RED}The command ${cmd[*]} exited with ${result}.${ANSI_RESET}" + fi + + echo -e "\\n${ANSI_GREEN}Log:${ANSI_RESET}\\n" + cat "${log_file}" + + return "${result}" +} diff --git a/ci/managers/ubuntu.sh b/ci/managers/ubuntu.sh new file mode 100755 index 0000000..7fe1b3f --- /dev/null +++ b/ci/managers/ubuntu.sh @@ -0,0 +1,24 @@ +#!/bin/bash +set -eux + +RELEASE="focal" + +apt-get update +apt-get install -y pkg-config + +source "$(dirname $0)/travis_wait.bash" + +cd $REPO_ROOT + +EXTRA_CFLAGS="-Werror -Wall -fsanitize=address,undefined" +EXTRA_LDFLAGS="-Werror -Wall -fsanitize=address,undefined" +mkdir build install +cc --version +make -j$((4*$(nproc))) EXTRA_CFLAGS="${EXTRA_CFLAGS}" EXTRA_LDFLAGS="${EXTRA_LDFLAGS}" -C ./src -B OBJDIR=../build +ldd build/libbpf.so +if ! ldd build/libbpf.so | grep -q libelf; then + echo "FAIL: No reference to libelf.so in libbpf.so!" + exit 1 +fi +make -j$((4*$(nproc))) -C src OBJDIR=../build DESTDIR=../install install +EXTRA_CFLAGS=${EXTRA_CFLAGS} EXTRA_LDFLAGS=${EXTRA_LDFLAGS} $(dirname $0)/test_compile.sh |