mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/kdave/btrfs-progs.git
synced 2024-11-15 00:04:23 +08:00
btrfs-progs: ci: setup GitLab-CI
Make use of GitLab-CI nested virutal environment to start QEMU instance inside containers and perform btrfs-progs build, execute unit test cases and save the logs. This allows to run the progs testsuite on a recent kernel, newer than what CI instances usually provide. As this is is emulated, the runtime is longer. Issue: #171 Signed-off-by: Lakshmipathi.G <lakshmipathi.ganapathi@collabora.com> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
a7e2f17a84
commit
6d59786363
157
.gitlab-ci.yml
Normal file
157
.gitlab-ci.yml
Normal file
@ -0,0 +1,157 @@
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public
|
||||
# License v2 as published by the Free Software Foundation.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public
|
||||
# License along with this program; if not, write to the
|
||||
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
# Boston, MA 021110-1307, USA.
|
||||
#
|
||||
|
||||
image: docker:18.09.7
|
||||
|
||||
services:
|
||||
- docker:18.09.7-dind
|
||||
|
||||
# To enable or disable Kernel Build set BUILD_KERNEL: "1" or BUILD_KERNEL: "0"
|
||||
# If you disable Kernel Build, make sure PREBUILT_KERNEL_ID points to previously built the kernel job id.
|
||||
# To enable or disable image build update BUILD_IMAGE value to "1" or "0".
|
||||
# If you disable Image Build, make sure PREBUILT_IMAGE_ID points to previously built rootfs job id.
|
||||
|
||||
variables:
|
||||
DOCKER_DRIVER: overlay2
|
||||
IMAGE_TAG: registry.gitlab.com/$CI_PROJECT_NAMESPACE/btrfs-progs:gitlab-ci
|
||||
BUILD_KERNEL: "1"
|
||||
PREBUILT_KERNEL_ID: "320566224"
|
||||
BUILD_IMAGE: "1"
|
||||
PREBUILT_IMAGE_ID: "288506168"
|
||||
|
||||
stages:
|
||||
- build
|
||||
- btrfs-progs build
|
||||
- test
|
||||
|
||||
before_script:
|
||||
- docker login --username $CI_REGISTRY_USER --password $CI_REGISTRY_PASSWORD $CI_REGISTRY
|
||||
|
||||
docker build:
|
||||
stage: build
|
||||
script:
|
||||
- cd ci/gitlab
|
||||
- docker pull $IMAGE_TAG > /dev/null && echo "Downloaded image" || ( docker build -t $IMAGE_TAG . && docker push $IMAGE_TAG )
|
||||
|
||||
|
||||
kernel build:
|
||||
before_script:
|
||||
- apk add curl unzip
|
||||
stage: build
|
||||
script:
|
||||
- if [ "$BUILD_KERNEL" == "1" ]; then
|
||||
docker run --cap-add SYS_PTRACE --cap-add sys_admin --privileged --device=/dev/kvm -v $PWD:/repo $IMAGE_TAG /repo/ci/gitlab/kernel_build.sh;
|
||||
else
|
||||
curl -o bzImage.zip --location --header "JOB-TOKEN:$CI_JOB_TOKEN" "https://gitlab.com/api/v4/projects/$CI_PROJECT_ID/jobs/$PREBUILT_KERNEL_ID/artifacts" && unzip bzImage.zip;
|
||||
fi;
|
||||
artifacts:
|
||||
when: always
|
||||
paths:
|
||||
- bzImage
|
||||
|
||||
|
||||
image build:
|
||||
before_script:
|
||||
- apk add curl unzip
|
||||
stage: build
|
||||
script:
|
||||
- if [ "$BUILD_IMAGE" == "1" ]; then
|
||||
docker run --cap-add SYS_PTRACE --cap-add sys_admin --privileged --device=/dev/kvm -v $PWD:/repo $IMAGE_TAG /repo/ci/gitlab/setup_image.sh;
|
||||
else
|
||||
curl -o qemu-image.img.zip --location --header "JOB-TOKEN:$CI_JOB_TOKEN" "https://gitlab.com/api/v4/projects/$CI_PROJECT_ID/jobs/$PREBUILT_IMAGE_ID/artifacts" && unzip qemu-image.img.zip;
|
||||
fi;
|
||||
artifacts:
|
||||
when: always
|
||||
paths:
|
||||
- qemu-image.img
|
||||
|
||||
btrfs-progs build:
|
||||
stage: btrfs-progs build
|
||||
script:
|
||||
- docker run --cap-add SYS_PTRACE --cap-add sys_admin --privileged --device=/dev/kvm -v $PWD:/repo $IMAGE_TAG /repo/ci/gitlab/run_tests.sh
|
||||
artifacts:
|
||||
expire_in: 1 week
|
||||
when: always
|
||||
paths:
|
||||
- qemu-image.img
|
||||
|
||||
cli tests:
|
||||
stage: test
|
||||
script:
|
||||
- echo "./cli-tests.sh" > $PWD/cmd
|
||||
- docker run --cap-add SYS_PTRACE --cap-add sys_admin --privileged --device=/dev/kvm -v $PWD:/repo $IMAGE_TAG /repo/ci/gitlab/run_tests.sh
|
||||
- test -e "result" || exit 1 # If result doesn't exists, job failed.
|
||||
artifacts:
|
||||
when: always
|
||||
paths:
|
||||
- "*tests-results.txt"
|
||||
|
||||
convert tests:
|
||||
only:
|
||||
- devel
|
||||
stage: test
|
||||
script:
|
||||
- echo "./convert-tests.sh" > $PWD/cmd
|
||||
- docker run --cap-add SYS_PTRACE --cap-add sys_admin --privileged --device=/dev/kvm -v $PWD:/repo $IMAGE_TAG /repo/ci/gitlab/run_tests.sh
|
||||
- test -e "result" || exit 1
|
||||
artifacts:
|
||||
when: always
|
||||
paths:
|
||||
- "*tests-results.txt"
|
||||
|
||||
fsck tests:
|
||||
stage: test
|
||||
script:
|
||||
- echo "./fsck-tests.sh" > $PWD/cmd
|
||||
- docker run --cap-add SYS_PTRACE --cap-add sys_admin --privileged --device=/dev/kvm -v $PWD:/repo $IMAGE_TAG /repo/ci/gitlab/run_tests.sh
|
||||
- test -e "result" || exit 1
|
||||
artifacts:
|
||||
when: always
|
||||
paths:
|
||||
- "*tests-results.txt"
|
||||
- error.log
|
||||
|
||||
fuzz tests:
|
||||
stage: test
|
||||
script:
|
||||
- echo "./fuzz-tests.sh" > $PWD/cmd
|
||||
- docker run --cap-add SYS_PTRACE --cap-add sys_admin --privileged --device=/dev/kvm -v $PWD:/repo $IMAGE_TAG /repo/ci/gitlab/run_tests.sh
|
||||
- test -e "result" || exit 1
|
||||
artifacts:
|
||||
when: always
|
||||
paths:
|
||||
- "*tests-results.txt"
|
||||
|
||||
misc tests:
|
||||
stage: test
|
||||
script:
|
||||
- echo "./misc-tests.sh" > $PWD/cmd
|
||||
- docker run --cap-add SYS_PTRACE --cap-add sys_admin --privileged --device=/dev/kvm -v $PWD:/repo $IMAGE_TAG /repo/ci/gitlab/run_tests.sh
|
||||
- test -e "result" || exit 1
|
||||
artifacts:
|
||||
when: always
|
||||
paths:
|
||||
- "*tests-results.txt"
|
||||
|
||||
mkfs tests:
|
||||
stage: test
|
||||
script:
|
||||
- echo "./mkfs-tests.sh" > $PWD/cmd
|
||||
- docker run --cap-add SYS_PTRACE --cap-add sys_admin --privileged --device=/dev/kvm -v $PWD:/repo $IMAGE_TAG /repo/ci/gitlab/run_tests.sh
|
||||
- test -e "result" || exit 1
|
||||
artifacts:
|
||||
when: always
|
||||
paths:
|
||||
- "*tests-results.txt"
|
3
ci/gitlab/Dockerfile
Normal file
3
ci/gitlab/Dockerfile
Normal file
@ -0,0 +1,3 @@
|
||||
FROM debian:stretch-slim
|
||||
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends ovmf qemu-system qemu-efi
|
13
ci/gitlab/btrfs-progs-tests.service
Normal file
13
ci/gitlab/btrfs-progs-tests.service
Normal file
@ -0,0 +1,13 @@
|
||||
[Unit]
|
||||
Description=Execute build_or_run_btrfs-progs.sh on console
|
||||
|
||||
[Service]
|
||||
ExecStart=/usr/bin/build_or_run_btrfs-progs.sh
|
||||
StandardInput=tty
|
||||
StandardOutput=tty
|
||||
TTYPath=/dev/ttyS0
|
||||
Type=idle
|
||||
|
||||
[Install]
|
||||
WantedBy=getty.target
|
||||
After=multi-user.target
|
37
ci/gitlab/build_or_run_btrfs-progs.sh
Executable file
37
ci/gitlab/build_or_run_btrfs-progs.sh
Executable file
@ -0,0 +1,37 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Build or Run btrfs-progs tests.
|
||||
|
||||
set -x
|
||||
|
||||
BTRFS_BIN="btrfs"
|
||||
MNT_DIR="/mnt/"
|
||||
BUILD_DIR="/btrfs/"
|
||||
test_cmd=$(cat ${MNT_DIR}/cmd)
|
||||
|
||||
rm -f ${MNT_DIR}/result
|
||||
${BTRFS_BIN} --version
|
||||
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
echo "=========================== Builb btrfs-progs ================"
|
||||
echo " Image doesn't have ${BTRFS_BIN} - start build process"
|
||||
cd ${MNT_DIR} && ./autogen.sh && ./configure --disable-documentation --disable-backtrace && make -j`nproc` && make install && make testsuite
|
||||
echo "================= Prepare Testsuite =========================="
|
||||
mkdir -p ${BUILD_DIR}
|
||||
cp tests/btrfs-progs-tests.tar.gz ${BUILD_DIR}
|
||||
poweroff
|
||||
else
|
||||
echo "================= Run Tests ================================="
|
||||
cd ${BUILD_DIR} && tar -xvf btrfs-progs-tests.tar.gz && ${test_cmd}
|
||||
|
||||
# check test result status
|
||||
if [ $? -ne 0 ]; then
|
||||
cd ${BUILD_DIR} && cp *tests-results.txt ${MNT_DIR}
|
||||
poweroff
|
||||
else
|
||||
cd ${BUILD_DIR} && cp *tests-results.txt ${MNT_DIR}
|
||||
touch ${MNT_DIR}/result
|
||||
poweroff
|
||||
fi
|
||||
fi
|
31
ci/gitlab/kernel_build.sh
Executable file
31
ci/gitlab/kernel_build.sh
Executable file
@ -0,0 +1,31 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# Setup BTRFS kernel options and build kernel
|
||||
|
||||
set -x
|
||||
|
||||
apt-get update
|
||||
apt-get -y install build-essential libncurses-dev bison flex libssl-dev libelf-dev unzip wget bc
|
||||
|
||||
# Build kernel
|
||||
wget https://github.com/kdave/btrfs-devel/archive/misc-next.zip
|
||||
unzip -qq misc-next.zip
|
||||
cd btrfs-devel-misc-next/ && make x86_64_defconfig && make kvmconfig
|
||||
|
||||
# BTRFS specific entires
|
||||
cat <<EOF >> .config
|
||||
CONFIG_BTRFS_FS=y
|
||||
CONFIG_BTRFS_FS_POSIX_ACL=y
|
||||
CONFIG_BTRFS_FS_CHECK_INTEGRITY=n
|
||||
CONFIG_BTRFS_FS_RUN_SANITY_TESTS=n
|
||||
CONFIG_BTRFS_DEBUG=y
|
||||
CONFIG_BTRFS_ASSERT=y
|
||||
CONFIG_BTRFS_FS_REF_VERIFY=y
|
||||
CONFIG_RAID6_PQ_BENCHMARK=y
|
||||
CONFIG_LIBCRC32C=y
|
||||
EOF
|
||||
|
||||
make -j8
|
||||
|
||||
# Store file to shared dir
|
||||
cp -v arch/x86/boot/bzImage /repo
|
12
ci/gitlab/run_tests.sh
Executable file
12
ci/gitlab/run_tests.sh
Executable file
@ -0,0 +1,12 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# Install and start qemu instance with custom kernel while exporting
|
||||
# btrfs-progs src over 9p
|
||||
#
|
||||
set -x
|
||||
|
||||
qemu-system-x86_64 -m 512 -nographic -kernel /repo/bzImage \
|
||||
-drive file=/repo/qemu-image.img,index=0,media=disk,format=raw \
|
||||
-fsdev local,id=btrfs-progs,path=/repo,security_model=mapped \
|
||||
-device virtio-9p-pci,fsdev=btrfs-progs,mount_tag=btrfs-progs \
|
||||
-append "console=tty1 root=/dev/sda rw"
|
42
ci/gitlab/setup_image.sh
Executable file
42
ci/gitlab/setup_image.sh
Executable file
@ -0,0 +1,42 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# Setup debian image via debootstrap and include systemd service file.
|
||||
set -x
|
||||
|
||||
apt-get update
|
||||
apt-get -y install debootstrap wget unzip
|
||||
|
||||
# Setup rootfs
|
||||
IMG="/qemu-image.img"
|
||||
DIR="/target"
|
||||
truncate -s2G $IMG
|
||||
mkfs.ext4 $IMG
|
||||
mkdir -p $DIR
|
||||
for i in {0..7};do
|
||||
mknod -m 0660 "/dev/loop$i" b 7 "$i"
|
||||
done
|
||||
|
||||
# mount the image file
|
||||
mount -o loop $IMG $DIR
|
||||
|
||||
# Install required pacakges
|
||||
debootstrap --arch=amd64 --include=git,autoconf,automake,gcc,make,pkg-config,e2fslibs-dev,libblkid-dev,zlib1g-dev,liblzo2-dev,asciidoc,xmlto,libzstd-dev,python3.5,python3.5-dev,python3-dev,python3-setuptools,python-setuptools,xz-utils,acl,attr stretch $DIR http://ftp.de.debian.org/debian/
|
||||
|
||||
## Setup 9p mount
|
||||
echo "btrfs-progs /mnt 9p trans=virtio 0 0" > $DIR/etc/fstab
|
||||
|
||||
# Setup autologin
|
||||
sed -i 's/9600/9600 --autologin root/g' $DIR/lib/systemd/system/serial-getty@.service
|
||||
|
||||
# Setup systemd service
|
||||
cp -v /repo/ci/gitlab/build_or_run_btrfs-progs.sh $DIR/usr/bin/
|
||||
cp -v /repo/ci/gitlab/btrfs-progs-tests.service $DIR/etc/systemd/system/
|
||||
|
||||
## Enable service
|
||||
ln -s $DIR/etc/systemd/system/btrfs-progs-tests.service $DIR/etc/systemd/system/getty.target.wants/btrfs-progs-tests.service
|
||||
|
||||
cd /
|
||||
umount $DIR
|
||||
rmdir $DIR
|
||||
|
||||
cp -v $IMG /repo
|
Loading…
Reference in New Issue
Block a user