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.
This commit is contained in:
Yucong Sun
2021-08-04 12:38:18 -07:00
committed by Andrii Nakryiko
parent 70ad3e8314
commit 6bf8babb33
3 changed files with 19 additions and 3 deletions

View File

@@ -48,6 +48,7 @@ for phase in "${PHASES[@]}"; do
echo -e "::endgroup::" echo -e "::endgroup::"
;; ;;
RUN|RUN_CLANG|RUN_GCC10|RUN_ASAN|RUN_CLANG_ASAN|RUN_GCC10_ASAN) RUN|RUN_CLANG|RUN_GCC10|RUN_ASAN|RUN_CLANG_ASAN|RUN_GCC10_ASAN)
CC="cc"
if [[ "$phase" = *"CLANG"* ]]; then if [[ "$phase" = *"CLANG"* ]]; then
ENV_VARS="-e CC=clang -e CXX=clang++" ENV_VARS="-e CC=clang -e CXX=clang++"
CC="clang" CC="clang"
@@ -62,7 +63,7 @@ for phase in "${PHASES[@]}"; do
CFLAGS="${CFLAGS} -fsanitize=address,undefined" CFLAGS="${CFLAGS} -fsanitize=address,undefined"
fi fi
docker_exec mkdir build install docker_exec mkdir build install
docker_exec ${CC:-cc} --version docker_exec ${CC} --version
info "build" info "build"
docker_exec make -j$((4*$(nproc))) CFLAGS="${CFLAGS}" -C ./src -B OBJDIR=../build docker_exec make -j$((4*$(nproc))) CFLAGS="${CFLAGS}" -C ./src -B OBJDIR=../build
info "ldd build/libbpf.so:" info "ldd build/libbpf.so:"
@@ -73,7 +74,8 @@ for phase in "${PHASES[@]}"; do
fi fi
info "install" info "install"
docker_exec make -j$((4*$(nproc))) -C src OBJDIR=../build DESTDIR=../install 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) CLEANUP)
info "Cleanup phase" info "Cleanup phase"

View File

@@ -0,0 +1,14 @@
#!/bin/bash
set -euox pipefail
CFLAGS=${CFLAGS:-}
cat << EOF > main.c
#include <bpf/libbpf.h>
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

View File

@@ -20,4 +20,4 @@ if ! ldd build/libbpf.so | grep -q libelf; then
exit 1 exit 1
fi fi
make -j$((4*$(nproc))) -C src OBJDIR=../build DESTDIR=../install install make -j$((4*$(nproc))) -C src OBJDIR=../build DESTDIR=../install install
rm -rf build install CFLAGS=${CFLAGS} $(dirname $0)/test_compile.sh