kokoro: build and run all crosvm unit tests in docker

TEST=run kokoro presubmit
BUG=b:73822503

Change-Id: Ica341fd8a064f4deb64fecbd4277ed6cc285ef2d
Reviewed-on: https://chromium-review.googlesource.com/1236888
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
This commit is contained in:
Zach Reizner 2018-09-20 14:39:59 -07:00 committed by chrome-bot
parent a1422e6bca
commit f55812ac20
5 changed files with 223 additions and 6 deletions

96
kokoro/Dockerfile Normal file
View file

@ -0,0 +1,96 @@
FROM debian:stretch
LABEL description="Test crosvm using a command like the following: \
docker run --privileged -v /dev/log:/dev/log -v <path to crosvm>:/src:ro <crosvm base image>"
RUN apt-get update && apt-get install -y \
autoconf \
automake \
curl \
gcc \
git \
libcap-dev \
libdrm-dev \
libegl1-mesa-dev \
libgl1-mesa-dev \
libgles1-mesa-dev \
libgles2-mesa-dev \
libtool \
libwayland-dev \
make \
nasm \
ninja-build \
pkg-config \
protobuf-compiler \
python3
ENV RUSTUP_HOME=/usr/local/rustup \
CARGO_HOME=/usr/local/cargo \
PATH=/usr/local/cargo/bin:$PATH \
RUST_VERSION=1.29.0
# Debian usually has an old rust version in the repository. Instead of using that, we use rustup to
# pull in a toolchain versions of our choosing.
RUN curl -LO "https://static.rust-lang.org/rustup/archive/1.13.0/x86_64-unknown-linux-gnu/rustup-init" \
&& echo "f69dafcca62fe70d7882113e21bb96a2cbdf4fc4636d25337d6de9191bdec8da *rustup-init" | sha256sum -c - \
&& chmod +x rustup-init \
&& ./rustup-init -y --no-modify-path --default-toolchain $RUST_VERSION \
&& rm rustup-init \
&& chmod -R a+w $RUSTUP_HOME $CARGO_HOME \
&& rustup --version \
&& cargo --version \
&& rustc --version
# Warms up the cargo registry cache for future cargo runs. Cargo will still update the cache using a
# git pull, but it only needs to download files that were changed since this image was built.
RUN cargo install thisiznotarealpackage -q || true
# Used /scratch for building dependencies which are too new or don't exist on Debian stretch.
WORKDIR /scratch
# minijail does not exist in upstream linux distros.
RUN git clone https://android.googlesource.com/platform/external/minijail \
&& cd minijail \
&& make -j24 \
&& cp libminijail.so /usr/lib/x86_64-linux-gnu/
# The gbm used by upstream linux distros is not compatible with crosvm, which must use Chrome OS's
# minigbm.
RUN dpkg --force-depends -r libgbm1
RUN git clone https://chromium.googlesource.com/chromiumos/platform/minigbm \
&& cd minigbm \
&& sed 's/-Wall/-Wno-maybe-uninitialized/g' -i Makefile \
&& make install -j24
# New libepoxy requires newer meson than is in Debian stretch.
RUN git clone https://github.com/mesonbuild/meson \
&& cd meson \
&& git checkout 0a5ff338012a00f32c3aa9d8773835accc3e4e5b \
&& ln -s $PWD/meson.py /usr/bin/meson
# New libepoxy has EGL_KHR_DEBUG entry points needed by crosvm.
RUN git clone https://github.com/anholt/libepoxy.git \
&& cd libepoxy \
&& git checkout 707f50e680ab4f1861b1e54ca6e2907aaca56c12 \
&& mkdir build \
&& cd build \
&& meson \
&& ninja install
# virglrenderer is under heavy development on master and we want the very latest.
RUN git clone https://gitlab.freedesktop.org/virgl/virglrenderer.git \
&& cd virglrenderer \
&& ./autogen.sh \
&& make install -j24
# Reduces image size and prevents accidentally using /scratch files
RUN rm -r /scratch /usr/bin/meson
# The manual installation of shared objects requires an ld.so.cache refresh.
RUN ldconfig
# The /build directory is used so that the bind mounted /src volume does not get scribbled on.
ENV CARGO_TARGET_DIR=/build
RUN mkdir -p $CARGO_TARGET_DIR
WORKDIR /src
CMD cargo test --no-fail-fast --all-features --all --exclude aarch64 $TEST_FLAGS -- \
--test-threads=1 $TEST_RUNNER_FLAGS

72
kokoro/README.md Normal file
View file

@ -0,0 +1,72 @@
# Kokoro CI for crosvm
For presubmit testing, each change posted for Gerrit on the master branch of crosvm will be tried by
Kokoro. The configuration is found in [`presubmit.cfg`](presubmit.cfg) and the build script is at
[`build.sh`](build.sh). A Docker image called `crosvm-base` is used as the testing environment which
is built with a [`Dockerfile`](Dockerfile).
[TOC]
## How to use Docker to test crosvm
Assuming a Docker daemon is already running, build the `crosvm-base` image:
```shell
cd crosvm/kokoro
docker build -t crosvm-base - < Dockerfile
```
Here is how to use the image to test a crosvm repository located at `$CROSVM_SRC`:
```shell
docker run --privileged -v /dev/log:/dev/log -v "${CROSVM_SRC}":/src:ro crosvm-base
```
> **WARNING**:
> The `--privileged` is so that the container will have `/dev/kvm` access.
## How to update `crosvm-base`
The `crosvm-base` `Dockerfile` downloads, builds, and install specific library versions needed to
test crosvm. It also defines a run time environment and default command line for performing a test.
If an update or new library is needed or any other adjustment is required, a new image can be
generated as follows:
```shell
cd crosvm/kokoro
docker build -t crosvm-base - < Dockerfile
docker save crosvm-base | xz -T 0 -z >crosvm-base.tar.xz
```
If you have x20 access, move `crosvm-base.tar.xz` to `/teams/chromeos-vm/docker/` and ensure the
owner is `chromeos-vm-ci-read-write`. This owner is used to allow Kokoro to read the base image in
during the test run. The updated image will be used for future Kokoro runs until it is replaced.
> **WARNING**:
> If the image tarball uploaded to x20 is defective in any way, Kokoro will fail to verify every
> crosvm change as if the change itself were defective. Please verify the image is good before
> uploading to x20.
## How to simulate Kokoro before uploading
If you want to test a change before uploading it in a similar environment to Kokoro, use the
[`kokoro_simulator.sh`](kokoro_simulator.sh) script. It will invoke the `build.sh` script after
exporting environment variables and a volume that are expected to be present. The crosvm source code
is symlinked in, and is tested exactly as in the working directory. Any changes to `build.sh` will
also be tested, but any changes to `presubmit.cfg` will have no effect. If there are any changes to
`Dockerfile`, they will have no effect unless the `crosvm-base` image is removed (or never existed)
from the local Docker daemon. To test `Dockerfile` changes use the following formula to purge
`crosvm-base`.
```shell
# So that kokoro_simulator.sh doesn't skip `docker save`.
rm /tmp/kokoro_simulator/crosvm-base.tar.xz
# Stopped containers prevent the removal of images below.
docker container prune
# So that kokoro_simulator.sh doesn't skip `docker build`.
docker rmi crosvm-base
```

View file

@ -6,14 +6,26 @@
set -ex
main() {
if [ -z "${KOKORO_ARTIFACTS_DIR}" ]; then
echo "This script must be run in kokoro"
exit 1
fi
if [ -z "${KOKORO_ARTIFACTS_DIR}" ]; then
echo "This script must be run in kokoro"
exit 1
fi
local src_root="${KOKORO_ARTIFACTS_DIR}"/git/crosvm
local src_root="${KOKORO_ARTIFACTS_DIR}"/git/crosvm
local base_image_tarball="${KOKORO_GFILE_DIR}"/crosvm-base.tar.xz
local base_image="crosvm-base"
return 0
if [[ "$(docker images -q ${base_image} 2> /dev/null)" == "" ]]; then
docker load -i "${base_image_tarball}"
fi
docker run \
--privileged \
-e TEST_RUNNER_FLAGS='--format terse' \
-v /dev/log:/dev/log \
-v "${src_root}":/src:ro \
${base_image}
return 0
}
main "$@"

35
kokoro/kokoro_simulator.sh Executable file
View file

@ -0,0 +1,35 @@
#!/bin/bash
# Copyright 2018 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
set -ex
main() {
cd "$(dirname "$0")"
local kokoro_simulator_root=/tmp/kokoro_simulator
local src_root="${kokoro_simulator_root}"/git/crosvm
local base_image_tarball="${kokoro_simulator_root}"/crosvm-base.tar.xz
local base_image="crosvm-base"
mkdir -p "${kokoro_simulator_root}"
if [[ ! -e "${base_image_tarball}" ]]; then
if [[ "$(docker images -q ${base_image} 2> /dev/null)" == "" ]]; then
docker build -t ${base_image} - < Dockerfile
fi
docker save ${base_image} | xz -T 0 -z >"${base_image_tarball}"
fi
if [[ ! -e "${src_root}" ]]; then
mkdir -p "${kokoro_simulator_root}"/git
ln -s "$(realpath ../)" "${src_root}"
fi
export KOKORO_ARTIFACTS_DIR="${kokoro_simulator_root}"
export KOKORO_GFILE_DIR="${kokoro_simulator_root}"
./build.sh
}
main "$@"

View file

@ -1,3 +1,5 @@
# Format: //devtools/kokoro/config/proto/build.proto
build_file: "crosvm/kokoro/build.sh"
gfile_resources: "/x20/teams/chromeos-vm/docker/crosvm-base.tar.xz"