From b91ca019225c001ac63d046241c9d75667004729 Mon Sep 17 00:00:00 2001 From: Yucong Sun Date: Wed, 4 Aug 2021 12:38:18 -0700 Subject: [PATCH] Add a test step to produce a minimal binary using libbpf. This patch adds a test step to link a minimal program to libbpf library produced, making sure that the library works. --- travis-ci/managers/debian.sh | 6 ++++-- travis-ci/managers/test_compile.sh | 22 ++++++++++++++++++++++ travis-ci/managers/ubuntu.sh | 2 +- 3 files changed, 27 insertions(+), 3 deletions(-) create mode 100755 travis-ci/managers/test_compile.sh diff --git a/travis-ci/managers/debian.sh b/travis-ci/managers/debian.sh index 55f990b..759bb78 100755 --- a/travis-ci/managers/debian.sh +++ b/travis-ci/managers/debian.sh @@ -48,6 +48,7 @@ for phase in "${PHASES[@]}"; do echo -e "::endgroup::" ;; RUN|RUN_CLANG|RUN_GCC10|RUN_ASAN|RUN_CLANG_ASAN|RUN_GCC10_ASAN) + CC="cc" if [[ "$phase" = *"CLANG"* ]]; then ENV_VARS="-e CC=clang -e CXX=clang++" CC="clang" @@ -62,7 +63,7 @@ for phase in "${PHASES[@]}"; do CFLAGS="${CFLAGS} -fsanitize=address,undefined" fi docker_exec mkdir build install - docker_exec ${CC:-cc} --version + docker_exec ${CC} --version info "build" docker_exec make -j$((4*$(nproc))) CFLAGS="${CFLAGS}" -C ./src -B OBJDIR=../build info "ldd build/libbpf.so:" @@ -73,7 +74,8 @@ for phase in "${PHASES[@]}"; do fi info "install" docker_exec make -j$((4*$(nproc))) -C src OBJDIR=../build DESTDIR=../install install - docker_exec rm -rf build install + info "link binary" + docker_exec bash -c "CFLAGS=\"${CFLAGS}\" ./travis-ci/managers/test_compile.sh" ;; CLEANUP) info "Cleanup phase" diff --git a/travis-ci/managers/test_compile.sh b/travis-ci/managers/test_compile.sh new file mode 100755 index 0000000..20a8f27 --- /dev/null +++ b/travis-ci/managers/test_compile.sh @@ -0,0 +1,22 @@ +#!/bin/bash +set -euox pipefail + +CFLAGS=${CFLAGS:-} + +cat << EOF > main.c +#include +int main() { + return bpf_object__open(0) < 0; +} +EOF + +# static linking +${CC:-cc} ${CFLAGS} -o main -I./install/usr/include main.c ./build/libbpf.a -lelf -lz + +# shared linking +${CC:-cc} ${CFLAGS} -o main_shared -I./install/usr/include main.c -L./install/usr/lib64 -L./install/usr/lib -lbpf +ldd main_shared +if ! ldd main_shared | grep -q libbpf; then + echo "FAIL: No reference to libbpf.so in main!" + exit 1 +fi diff --git a/travis-ci/managers/ubuntu.sh b/travis-ci/managers/ubuntu.sh index 6c38ca1..8af229e 100755 --- a/travis-ci/managers/ubuntu.sh +++ b/travis-ci/managers/ubuntu.sh @@ -20,4 +20,4 @@ if ! ldd build/libbpf.so | grep -q libelf; then exit 1 fi make -j$((4*$(nproc))) -C src OBJDIR=../build DESTDIR=../install install -rm -rf build install +CFLAGS=${CFLAGS} $(dirname $0)/test_compile.sh