1# Copyright 2018 The Chromium OS Authors. All rights reserved. 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5FROM debian:bullseye 6LABEL description="Test crosvm using a command like the following: \ 7docker run --privileged -v /dev/log:/dev/log -v <path to crosvm>:/platform/crosvm:ro <crosvm base image>" 8 9# should be set to the ID/GROUP_ID of the user running the docker image 10ARG USER_ID 11ARG GROUP_ID 12 13RUN apt-get update && \ 14 apt-get install -y --no-install-recommends ca-certificates gnupg wget && \ 15 echo 'deb-src https://deb.debian.org/debian bullseye main' >> /etc/apt/sources.list && \ 16 cat /etc/apt/sources.list && \ 17 apt-get update && \ 18 apt-get build-dep -y mesa && \ 19 apt-get install -y --no-install-recommends ca-certificates \ 20 python3-setuptools \ 21 llvm-dev \ 22 libxcb-shm0-dev \ 23 libelf-dev \ 24 cmake \ 25 chrony \ 26 bc \ 27 flex \ 28 bison \ 29 debootstrap \ 30 cpio \ 31 xz-utils \ 32 libegl1-mesa-dev \ 33 autoconf \ 34 automake \ 35 curl \ 36 g++ \ 37 gcc \ 38 gdb \ 39 git \ 40 kmod \ 41 libcap-dev \ 42 libdbus-1-dev \ 43 libegl1-mesa-dev \ 44 libepoxy-dev \ 45 libfdt-dev \ 46 libgl1-mesa-dev \ 47 libgles2-mesa-dev \ 48 libpciaccess-dev \ 49 libssl-dev \ 50 libtool \ 51 libusb-1.0-0-dev \ 52 libwayland-dev \ 53 make \ 54 nasm \ 55 ninja-build \ 56 pkg-config \ 57 protobuf-compiler \ 58 python \ 59 libtinfo5 \ 60 python3-protobuf \ 61 clang \ 62 iptables \ 63 libunwind-dev \ 64 libprotobuf-dev \ 65 protobuf-compiler \ 66 libprotoc-dev \ 67 libdw-dev \ 68 libprotobuf-dev \ 69 libdocopt-dev \ 70 && \ 71 apt-get -y build-dep intel-gpu-tools 72 73ENV RUSTUP_HOME=/usr/local/rustup \ 74 CARGO_HOME=/usr/local/cargo \ 75 PATH=/usr/local/cargo/bin:$PATH \ 76 RUST_VERSION=1.45.2 \ 77 RUSTFLAGS='--cfg hermetic' 78 79# Debian usually has an old rust version in the repository. Instead of using that, we use rustup to 80# pull in a toolchain versions of our choosing. 81RUN curl -LO "https://static.rust-lang.org/rustup/archive/1.22.1/x86_64-unknown-linux-gnu/rustup-init" \ 82 && echo "49c96f3f74be82f4752b8bffcf81961dea5e6e94ce1ccba94435f12e871c3bdb *rustup-init" | sha256sum -c - \ 83 && chmod +x rustup-init \ 84 && ./rustup-init -y --no-modify-path --default-toolchain $RUST_VERSION \ 85 && rm rustup-init \ 86 && chmod -R a+w $RUSTUP_HOME $CARGO_HOME \ 87 && rustup --version \ 88 && cargo --version \ 89 && rustc --version 90 91# Set the default toolchain to 'stable' to match the one that bin/smoke_test 92# uses. This allows kokoro runs to avoid re-downloading the toolchain as long 93# as the version matches RUST_VERSION. 94RUN rustup default stable 95 96# Warms up the cargo registry cache for future cargo runs. Cargo will still update the cache using a 97# git pull, but it only needs to download files that were changed since this image was built. 98RUN cargo install thisiznotarealpackage -q || true 99 100# Used /scratch for building dependencies which are too new or don't exist on Debian stretch. 101WORKDIR /scratch 102 103# Suppress warnings about detached HEAD, which will happen a lot and is meaningless in this context. 104RUN git config --global advice.detachedHead false 105 106# New libepoxy and libdrm-dev requires newer meson than is in Debian stretch. 107ARG MESON_COMMIT=master 108RUN git clone https://github.com/mesonbuild/meson /meson \ 109 && cd /meson \ 110 && git checkout $MESON_COMMIT \ 111 && rm -f /usr/bin/meson \ 112 && ln -s $PWD/meson.py /usr/bin/meson 113 114# The libdrm-dev in distro can be too old to build minigbm, 115# so we build it from upstream. 116ARG DRM_COMMIT=master 117RUN git clone https://gitlab.freedesktop.org/mesa/drm.git/ \ 118 && cd drm \ 119 && git checkout $DRM_COMMIT \ 120 && meson build -Dlibdir=lib \ 121 && ninja -C build/ install 122 123# The gbm used by upstream linux distros is not compatible with crosvm, which must use Chrome OS's 124# minigbm. 125RUN git clone https://chromium.googlesource.com/chromiumos/platform/minigbm \ 126 && cd minigbm \ 127 && sed 's/-Wall/-Wno-maybe-uninitialized/g' -i Makefile \ 128 && make CPPFLAGS="-DDRV_I915" DRV_I915=1 install -j$(nproc) 129 130RUN git clone https://gitlab.freedesktop.org/virgl/virglrenderer.git \ 131 && cd virglrenderer \ 132 && mkdir -p build \ 133 && meson build/ -Dprefix=/usr/local -Dlibdir=lib \ 134 && ninja -C build/ install 135 136# Install libtpm2 so that tpm2-sys/build.rs does not try to build it in place in 137# the read-only source directory. 138ARG TPM2_COMMIT=073dc25aa4dda42475a7a5a140399fc5db61b20f 139RUN git clone https://chromium.googlesource.com/chromiumos/third_party/tpm2 \ 140 && cd tpm2 \ 141 && git checkout $TPM2_COMMIT \ 142 && make -j$(nproc) \ 143 && cp build/libtpm2.a /lib 144 145# PUll down platform2 repositroy and install librendernodehost. 146# Note that we clone the repository outside of /scratch not to be removed 147# because crosvm depends on libvda. 148ENV PLATFORM2_ROOT=/platform2 149ARG PLATFORM2_COMMIT=2dce812fc9091e41a33094929610199468ee322b 150RUN git clone https://chromium.googlesource.com/chromiumos/platform2 $PLATFORM2_ROOT \ 151 && cd $PLATFORM2_ROOT \ 152 && git checkout $PLATFORM2_COMMIT 153 154# Set up sysroot from which system_api proto files are built. 155ENV SYSROOT=/sysroot 156RUN mkdir -p $SYSROOT/usr/include/chromeos/dbus/trunks \ 157 && cp $PLATFORM2_ROOT/trunks/interface.proto \ 158 $SYSROOT/usr/include/chromeos/dbus/trunks 159# Copy it under rustc's sysroot as well for cargo clippy. 160RUN export RUST_SYSROOT=$(rustc --print sysroot); echo $RUST_SYSROOT 161RUN mkdir -p $RUST_SYSROOT/usr/include/chromeos/dbus/trunks \ 162 && cp $PLATFORM2_ROOT/trunks/interface.proto \ 163 $RUST_SYSROOT/usr/include/chromeos/dbus/trunks 164 165# Reduces image size and prevents accidentally using /scratch files 166RUN rm -r /scratch 167WORKDIR / 168 169# The manual installation of shared objects requires an ld.so.cache refresh. 170RUN ldconfig 171 172# Pull down repositories that crosvm depends on to cros checkout-like locations. 173ENV CROS_ROOT=/ 174ENV THIRD_PARTY_ROOT=$CROS_ROOT/third_party 175RUN mkdir -p $THIRD_PARTY_ROOT 176ENV PLATFORM_ROOT=$CROS_ROOT/platform 177RUN mkdir -p $PLATFORM_ROOT 178ENV AOSP_EXTERNAL_ROOT=$CROS_ROOT/aosp/external 179RUN mkdir -p $AOSP_EXTERNAL_ROOT 180 181# minijail does not exist in upstream linux distros. 182ARG MINIJAIL_COMMIT=5f9e3001c61626d2863dad91248ba8496c3ef511 183RUN git clone https://android.googlesource.com/platform/external/minijail $AOSP_EXTERNAL_ROOT/minijail \ 184 && cd $AOSP_EXTERNAL_ROOT/minijail \ 185 && git checkout $MINIJAIL_COMMIT \ 186 && make -j$(nproc) \ 187 && cp libminijail.so /usr/lib/x86_64-linux-gnu/ 188 189# Pull the cras library for audio access. 190ARG ADHD_COMMIT=5068bdd18b51de8f2d5bcff754cdecda80de8f44 191RUN git clone https://chromium.googlesource.com/chromiumos/third_party/adhd $THIRD_PARTY_ROOT/adhd \ 192 && cd $THIRD_PARTY_ROOT/adhd \ 193 && git checkout $ADHD_COMMIT 194 195ARG VPERFETTO_COMMIT=3ce4813ae114e5f2e6e0b3f29517a88246c00363 196RUN git clone https://github.com/741g/vperfetto.git && \ 197 cd vperfetto && \ 198 git checkout $VPERFETTO_COMMIT && \ 199 cmake -G Ninja -B_build -DOPTION_BUILD_TESTS=FALSE && \ 200 ninja -C _build install 201 202ARG CROSVM_COMMIT=3f9373f474a295df0f8a38592472ae59adc98e29 203RUN mkdir -p /platform/ \ 204 && cd /platform \ 205 && git clone --single-branch -b perfetto https://gitlab.freedesktop.org/tomeu/crosvm.git \ 206 && cd crosvm \ 207 && cargo install --locked --debug --features 'default-no-sandbox wl-dmabuf gpu x virtio-gpu-next' --path . --root /usr/local 208 209RUN export uid=$USER_ID gid=$GROUP_ID && \ 210 mkdir -p /home/chronos && \ 211 echo "chronos:x:${uid}:${gid}:Developer,,,:/home/chronos:/bin/bash" >> /etc/passwd && \ 212 echo "chronos:x:${uid}:" >> /etc/group && \ 213 chown ${uid}:${gid} -R /home/chronos 214 215 216#crony didn't install cleanly when using --include, so we add it by using an extra apt install 217 218ENV EXTRA_PACKAGES="sudo,strace,libxcb-dri2-0,libxcb-dri3-0,libx11-xcb1,libxcb-xfixes0,libxcb-present0,libxcb-sync1,libxshmfence1,libx11-6,sysvinit-core,libwayland-client0,libwayland-server0,time,inetutils-ping,dnsutils,libpng16-16,libprocps8,valgrind,libsensors5,python3,wget,gnupg,ca-certificates,llvm-dev,chrony" 219 220RUN ulimit -n 1024 && \ 221 debootstrap --variant=minbase --components main,contrib,non-free --include=$EXTRA_PACKAGES bullseye /rootfs http://deb.debian.org/debian && \ 222 chroot /rootfs /bin/bash -c "apt install -yy gdb" && \ 223 chroot /rootfs /bin/bash -c "dpkg-query -Wf '\${Installed-Size}\t\${Package}\n' | sort -n " && \ 224 chroot /rootfs /bin/bash -c "useradd -u 1001 -r -d / -s /sbin/nologin -c 'crossvm image user' perfetto" 225 226COPY perf-testing/Docker/init.sh /rootfs/. 227 228RUN cd /rootfs && \ 229 find -H | cpio -H newc -o | xz --check=crc32 -T4 - > /rootfs.cpio.gz 230 231COPY perf-testing/Docker/x86_64.config /tmp/. 232RUN mkdir -p kernel && \ 233 wget -O- https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.10.16.tar.xz | tar -xJ --strip-components=1 -C kernel && \ 234 cd kernel && \ 235 ./scripts/kconfig/merge_config.sh arch/x86/configs/x86_64_defconfig /tmp/x86_64.config && \ 236 make -j12 vmlinux && \ 237 cp vmlinux /. && \ 238 cd .. && \ 239 rm -rf kernel 240 241# Need an unreleased version of Waffle for surfaceless support in apitrace 242# Replace this build with the Debian package once that's possible 243ENV WAFFLE_VERSION="b6d94483694b6889a8567b6bd748f7baad527df4" 244RUN git clone https://gitlab.freedesktop.org/mesa/waffle.git --single-branch --no-checkout /waffle && \ 245 cd /waffle && \ 246 git checkout "$WAFFLE_VERSION" && \ 247 cmake -B_build -DCMAKE_INSTALL_LIBDIR=lib -DCMAKE_BUILD_TYPE=Debug -Dwaffle_has_surfaceless_egl=1 . && \ 248 make -j12 -C _build install && \ 249 mkdir -p build/lib build/bin && \ 250 cp _build/lib/libwaffle-1.so build/lib/libwaffle-1.so.0 && \ 251 cp _build/bin/wflinfo build/bin/wflinfo 252 253ENV APITRACE_VERSION="perfetto" 254RUN git clone https://gitlab.freedesktop.org/tomeu/apitrace.git --single-branch -b perfetto --no-checkout /apitrace && \ 255 cd /apitrace && \ 256 git checkout "$APITRACE_VERSION" && \ 257 cmake -G Ninja -B_build -H. -DCMAKE_BUILD_TYPE=Debug -DENABLE_GUI=False -DENABLE_WAFFLE=on -DWaffle_DIR=/usr/local/lib/cmake/Waffle/ && \ 258 ninja -C _build && \ 259 mkdir build && \ 260 cp _build/apitrace build && \ 261 cp _build/eglretrace build 262 263ENV GN_ARGS="is_debug=false use_custom_libcxx=false" 264ENV CFG=linux_trusty-gcc7-x86_64-release 265RUN git clone https://android.googlesource.com/platform/external/perfetto && \ 266 cd perfetto && \ 267 git checkout v12.1 && \ 268 python3 tools/install-build-deps && \ 269 python3 tools/install-build-deps --ui && \ 270 tools/gn gen out/dist --args="${GN_ARGS}" --check && \ 271 tools/ninja -C out/dist traced traced_probes perfetto trace_to_text ui trace_processor_shell && \ 272 mkdir -p /usr/local/lib/python3.7/site-packages && \ 273 protoc --python_out=/usr/local/lib/python3.7/site-packages protos/perfetto/trace/perfetto_trace.proto && \ 274 tools/gen_amalgamated --gn_args 'target_os="linux" is_debug=false' 275 276RUN mkdir -p /traces-db && chown chronos:chronos /traces-db && mkdir -p /wd && chown -R chronos:chronos /wd 277 278ENV IGT_GPU_TOOLS_VERSION="igt-gpu-tools-1.25" 279RUN git clone --single-branch -b master https://gitlab.freedesktop.org/drm/igt-gpu-tools.git && \ 280 cd igt-gpu-tools && \ 281 git checkout "$IGT_GPU_TOOLS_VERSION" && \ 282 meson build -Doverlay=disabled -Dchamelium=disabled -Dvalgrind=disabled -Dman=disabled -Ddocs=disabled -Dtests=disabled -Drunner=disabled && \ 283 ninja -C build install 284 285ENV GFX_PPS_VERSION="v0.3.0" 286RUN git clone --single-branch -b master https://gitlab.freedesktop.org/Fahien/gfx-pps.git && \ 287 cd gfx-pps && \ 288 git checkout "$GFX_PPS_VERSION" && \ 289 meson build -Dtest=false -Dbuildtype=debugoptimized && \ 290 ninja -C build 291 292COPY perf-testing/Docker/run_traces.sh /usr/local/. 293COPY perf-testing/Docker/run_perfetto_ui.sh /usr/local/. 294COPY perf-testing/Docker/run.sh /usr/local/. 295COPY perf-testing/Docker/perfetto-guest.cfg /usr/local/. 296COPY perf-testing/Docker/perfetto-host.cfg /usr/local/. 297COPY perf-testing/Docker/merge_traces.py /usr/local/. 298 299ENTRYPOINT ["/usr/local/run.sh"] 300