Skip to content

Commit a622867

Browse files
adding ci files
1 parent b75597d commit a622867

19 files changed

+86226
-0
lines changed

.travis.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
sudo: required
2+
language: bash
3+
dist: bionic
4+
services:
5+
- docker
6+
7+
env:
8+
global:
9+
- PROJECT_NAME='libbpf'
10+
- AUTHOR_EMAIL="$(git log -1 --pretty=\"%aE\")"
11+
- REPO_ROOT="$TRAVIS_BUILD_DIR"
12+
- CI_ROOT="$REPO_ROOT/travis-ci"
13+
- VMTEST_ROOT="$CI_ROOT/vmtest"
14+
15+
addons:
16+
apt:
17+
packages:
18+
- qemu-kvm
19+
- zstd
20+
- binutils-dev
21+
- elfutils
22+
- libcap-dev
23+
- libelf-dev
24+
- libdw-dev
25+
- python3-docutils
26+
27+
jobs:
28+
include:
29+
- stage: Builds & Tests
30+
name: Kernel LATEST + selftests
31+
language: bash
32+
env: KERNEL=LATEST
33+
script: $CI_ROOT/vmtest/run_vmtest.sh || travis_terminate 1

travis-ci/managers/debian.sh

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#!/bin/bash
2+
3+
PHASES=(${@:-SETUP RUN RUN_ASAN CLEANUP})
4+
DEBIAN_RELEASE="${DEBIAN_RELEASE:-testing}"
5+
CONT_NAME="${CONT_NAME:-libbpf-debian-$DEBIAN_RELEASE}"
6+
ENV_VARS="${ENV_VARS:-}"
7+
DOCKER_RUN="${DOCKER_RUN:-docker run}"
8+
REPO_ROOT="${REPO_ROOT:-$PWD}"
9+
ADDITIONAL_DEPS=(clang pkg-config gcc-8)
10+
CFLAGS="-g -O2 -Werror -Wall"
11+
12+
function info() {
13+
echo -e "\033[33;1m$1\033[0m"
14+
}
15+
16+
function error() {
17+
echo -e "\033[31;1m$1\033[0m"
18+
}
19+
20+
function docker_exec() {
21+
docker exec $ENV_VARS -it $CONT_NAME "$@"
22+
}
23+
24+
set -e
25+
26+
source "$(dirname $0)/travis_wait.bash"
27+
28+
for phase in "${PHASES[@]}"; do
29+
case $phase in
30+
SETUP)
31+
info "Setup phase"
32+
info "Using Debian $DEBIAN_RELEASE"
33+
34+
sudo apt-get -y -o Dpkg::Options::="--force-confnew" install docker-ce
35+
docker --version
36+
37+
docker pull debian:$DEBIAN_RELEASE
38+
info "Starting container $CONT_NAME"
39+
$DOCKER_RUN -v $REPO_ROOT:/build:rw \
40+
-w /build --privileged=true --name $CONT_NAME \
41+
-dit --net=host debian:$DEBIAN_RELEASE /bin/bash
42+
docker_exec bash -c "echo deb-src http://deb.debian.org/debian $DEBIAN_RELEASE main >>/etc/apt/sources.list"
43+
docker_exec apt-get -y update
44+
docker_exec apt-get -y build-dep libelf-dev
45+
docker_exec apt-get -y install libelf-dev
46+
docker_exec apt-get -y install "${ADDITIONAL_DEPS[@]}"
47+
;;
48+
RUN|RUN_CLANG|RUN_GCC8|RUN_ASAN|RUN_CLANG_ASAN|RUN_GCC8_ASAN)
49+
if [[ "$phase" = *"CLANG"* ]]; then
50+
ENV_VARS="-e CC=clang -e CXX=clang++"
51+
CC="clang"
52+
elif [[ "$phase" = *"GCC8"* ]]; then
53+
ENV_VARS="-e CC=gcc-8 -e CXX=g++-8"
54+
CC="gcc-8"
55+
else
56+
CFLAGS="${CFLAGS} -Wno-stringop-truncation"
57+
fi
58+
if [[ "$phase" = *"ASAN"* ]]; then
59+
CFLAGS="${CFLAGS} -fsanitize=address,undefined"
60+
fi
61+
docker_exec mkdir build install
62+
docker_exec ${CC:-cc} --version
63+
info "build"
64+
docker_exec make -j$((4*$(nproc))) CFLAGS="${CFLAGS}" -C ./src -B OBJDIR=../build
65+
info "ldd build/libbpf.so:"
66+
docker_exec ldd build/libbpf.so
67+
if ! docker_exec ldd build/libbpf.so | grep -q libelf; then
68+
error "No reference to libelf.so in libbpf.so!"
69+
exit 1
70+
fi
71+
info "install"
72+
docker_exec make -j$((4*$(nproc))) -C src OBJDIR=../build DESTDIR=../install install
73+
docker_exec rm -rf build install
74+
;;
75+
CLEANUP)
76+
info "Cleanup phase"
77+
docker stop $CONT_NAME
78+
docker rm -f $CONT_NAME
79+
;;
80+
*)
81+
echo >&2 "Unknown phase '$phase'"
82+
exit 1
83+
esac
84+
done

travis-ci/managers/travis_wait.bash

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# This was borrowed from https://github.com/travis-ci/travis-build/tree/master/lib/travis/build/bash
2+
# to get around https://github.com/travis-ci/travis-ci/issues/9979. It should probably be removed
3+
# as soon as Travis CI has started to provide an easy way to export the functions to bash scripts.
4+
5+
travis_jigger() {
6+
local cmd_pid="${1}"
7+
shift
8+
local timeout="${1}"
9+
shift
10+
local count=0
11+
12+
echo -e "\\n"
13+
14+
while [[ "${count}" -lt "${timeout}" ]]; do
15+
count="$((count + 1))"
16+
echo -ne "Still running (${count} of ${timeout}): ${*}\\r"
17+
sleep 60
18+
done
19+
20+
echo -e "\\n${ANSI_RED}Timeout (${timeout} minutes) reached. Terminating \"${*}\"${ANSI_RESET}\\n"
21+
kill -9 "${cmd_pid}"
22+
}
23+
24+
travis_wait() {
25+
local timeout="${1}"
26+
27+
if [[ "${timeout}" =~ ^[0-9]+$ ]]; then
28+
shift
29+
else
30+
timeout=20
31+
fi
32+
33+
local cmd=("${@}")
34+
local log_file="travis_wait_${$}.log"
35+
36+
"${cmd[@]}" &>"${log_file}" &
37+
local cmd_pid="${!}"
38+
39+
travis_jigger "${!}" "${timeout}" "${cmd[@]}" &
40+
local jigger_pid="${!}"
41+
local result
42+
43+
{
44+
set +e
45+
wait "${cmd_pid}" 2>/dev/null
46+
result="${?}"
47+
ps -p"${jigger_pid}" &>/dev/null && kill "${jigger_pid}"
48+
set -e
49+
}
50+
51+
if [[ "${result}" -eq 0 ]]; then
52+
echo -e "\\n${ANSI_GREEN}The command ${cmd[*]} exited with ${result}.${ANSI_RESET}"
53+
else
54+
echo -e "\\n${ANSI_RED}The command ${cmd[*]} exited with ${result}.${ANSI_RESET}"
55+
fi
56+
57+
echo -e "\\n${ANSI_GREEN}Log:${ANSI_RESET}\\n"
58+
cat "${log_file}"
59+
60+
return "${result}"
61+
}

travis-ci/managers/ubuntu.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
set -e
3+
set -x
4+
5+
RELEASE="bionic"
6+
7+
echo "deb-src http://archive.ubuntu.com/ubuntu/ $RELEASE main restricted universe multiverse" >>/etc/apt/sources.list
8+
9+
apt-get update
10+
apt-get -y build-dep libelf-dev
11+
apt-get install -y libelf-dev pkg-config
12+
13+
source "$(dirname $0)/travis_wait.bash"
14+
15+
cd $REPO_ROOT
16+
17+
CFLAGS="-g -O2 -Werror -Wall -fsanitize=address,undefined"
18+
mkdir build install
19+
cc --version
20+
make -j$((4*$(nproc))) CFLAGS="${CFLAGS}" -C ./src -B OBJDIR=../build
21+
ldd build/libbpf.so
22+
if ! ldd build/libbpf.so | grep -q libelf; then
23+
echo "FAIL: No reference to libelf.so in libbpf.so!"
24+
exit 1
25+
fi
26+
make -j$((4*$(nproc))) -C src OBJDIR=../build DESTDIR=../install install
27+
rm -rf build install

travis-ci/vmtest/build_pahole.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
3+
set -eu
4+
5+
source $(cd $(dirname $0) && pwd)/helpers.sh
6+
7+
travis_fold start build_pahole "Building pahole"
8+
9+
CWD=$(pwd)
10+
REPO_PATH=$1
11+
PAHOLE_ORIGIN=https://git.kernel.org/pub/scm/devel/pahole/pahole.git
12+
13+
mkdir -p ${REPO_PATH}
14+
cd ${REPO_PATH}
15+
git init
16+
git remote add origin ${PAHOLE_ORIGIN}
17+
git fetch origin
18+
git checkout master
19+
20+
mkdir -p build
21+
cd build
22+
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -D__LIB=lib ..
23+
make -j$((4*$(nproc))) all
24+
sudo make install
25+
26+
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH:-}:/usr/local/lib
27+
ldd $(which pahole)
28+
pahole --version
29+
30+
travis_fold end build_pahole

travis-ci/vmtest/build_selftests.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
source $(cd $(dirname $0) && pwd)/helpers.sh
6+
7+
travis_fold start prepare_selftests "Building selftests"
8+
9+
LLVM_VER=12
10+
LIBBPF_PATH="${REPO_ROOT}"
11+
12+
PREPARE_SELFTESTS_SCRIPT=${VMTEST_ROOT}/prepare_selftests-${KERNEL}.sh
13+
if [ -f "${PREPARE_SELFTESTS_SCRIPT}" ]; then
14+
(cd "${REPO_ROOT}/tools/testing/selftests/bpf" && ${PREPARE_SELFTESTS_SCRIPT})
15+
fi
16+
17+
if [[ "${KERNEL}" = 'LATEST' ]]; then
18+
VMLINUX_H=
19+
else
20+
VMLINUX_H=${VMTEST_ROOT}/vmlinux.h
21+
fi
22+
23+
make \
24+
CLANG=clang-${LLVM_VER} \
25+
LLC=llc-${LLVM_VER} \
26+
LLVM_STRIP=llvm-strip-${LLVM_VER} \
27+
VMLINUX_BTF="${VMLINUX_BTF}" \
28+
VMLINUX_H=${VMLINUX_H} \
29+
-C "${REPO_ROOT}/tools/testing/selftests/bpf" \
30+
-j $((2*$(nproc)))
31+
mkdir ${LIBBPF_PATH}/selftests
32+
cp -R "${REPO_ROOT}/tools/testing/selftests/bpf" \
33+
${LIBBPF_PATH}/selftests
34+
cd ${LIBBPF_PATH}
35+
rm selftests/bpf/.gitignore
36+
git add selftests
37+
38+
git add "${VMTEST_ROOT}/configs/blacklist"
39+
40+
travis_fold end prepare_selftests
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/bash
2+
3+
set -eu
4+
5+
source $(cd $(dirname $0) && pwd)/helpers.sh
6+
7+
CWD=$(pwd)
8+
LIBBPF_PATH=$(pwd)
9+
REPO_PATH=$1
10+
11+
BPF_NEXT_ORIGIN=https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git
12+
LINUX_SHA=$(cat ${LIBBPF_PATH}/CHECKPOINT-COMMIT)
13+
SNAPSHOT_URL=https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git/snapshot/bpf-next-${LINUX_SHA}.tar.gz
14+
15+
echo REPO_PATH = ${REPO_PATH}
16+
echo LINUX_SHA = ${LINUX_SHA}
17+
18+
if [ ! -d "${REPO_PATH}" ]; then
19+
echo
20+
travis_fold start pull_kernel_srcs "Fetching kernel sources"
21+
22+
mkdir -p $(dirname "${REPO_PATH}")
23+
cd $(dirname "${REPO_PATH}")
24+
# attempt to fetch desired bpf-next repo snapshot
25+
if wget ${SNAPSHOT_URL} ; then
26+
tar xf bpf-next-${LINUX_SHA}.tar.gz
27+
mv bpf-next-${LINUX_SHA} $(basename ${REPO_PATH})
28+
else
29+
# but fallback to git fetch approach if that fails
30+
mkdir -p ${REPO_PATH}
31+
cd ${REPO_PATH}
32+
git init
33+
git remote add bpf-next ${BPF_NEXT_ORIGIN}
34+
# try shallow clone first
35+
git fetch --depth 32 bpf-next
36+
# check if desired SHA exists
37+
if ! git cat-file -e ${LINUX_SHA}^{commit} ; then
38+
# if not, fetch all of bpf-next; slow and painful
39+
git fetch bpf-next
40+
fi
41+
git reset --hard ${LINUX_SHA}
42+
fi
43+
44+
travis_fold end pull_kernel_srcs
45+
fi

travis-ci/vmtest/configs/INDEX

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
INDEX https://libbpf-vmtest.s3-us-west-1.amazonaws.com/x86_64/INDEX
2+
libbpf-vmtest-rootfs-2020.09.27.tar.zst https://libbpf-vmtest.s3-us-west-1.amazonaws.com/x86_64/libbpf-vmtest-rootfs-2020.09.27.tar.zst
3+
vmlinux-4.9.0.zst https://libbpf-vmtest.s3-us-west-1.amazonaws.com/x86_64/vmlinux-4.9.0.zst
4+
vmlinux-5.5.0-rc6.zst https://libbpf-vmtest.s3-us-west-1.amazonaws.com/x86_64/vmlinux-5.5.0-rc6.zst
5+
vmlinux-5.5.0.zst https://libbpf-vmtest.s3-us-west-1.amazonaws.com/x86_64/vmlinux-5.5.0.zst
6+
vmlinuz-5.5.0-rc6 https://libbpf-vmtest.s3-us-west-1.amazonaws.com/x86_64/vmlinuz-5.5.0-rc6
7+
vmlinuz-5.5.0 https://libbpf-vmtest.s3-us-west-1.amazonaws.com/x86_64/vmlinuz-5.5.0
8+
vmlinuz-4.9.0 https://libbpf-vmtest.s3-us-west-1.amazonaws.com/x86_64/vmlinuz-4.9.0

0 commit comments

Comments
 (0)