From 0dbb9808a6f4817b4222ad3232da815800b3e9f0 Mon Sep 17 00:00:00 2001 From: Dennis Kempin Date: Tue, 26 Jan 2021 16:14:41 -0800 Subject: [PATCH] Add Kokoro for ci/builders Adds the crosvm-side infrastructure to build and test in kokoro. There is a build script for testing on x86, aarch64 and a separte script for analysis (clippy, fmt). These will run in parallel on Kokoro. To test the scripts locally, a simulate script is provided. Runtime on my workstation: - aarch64: 10m - x86: 2:30m - analysis: 1:40m BUG=b:177951955 TEST=./ci/kokoro/simulate_all Change-Id: I2f666ec768e6c3391a258dc7f0cbd999ad9b2fb1 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2654413 Tested-by: Dennis Kempin Commit-Queue: Dennis Kempin Reviewed-by: Stephen Barber --- Cargo.lock | 1 + bin/clippy | 9 ++--- ci/Makefile | 8 +++-- ci/kokoro/build-aarch64.sh | 9 +++++ ci/kokoro/build-x86_64.sh | 10 ++++++ ci/kokoro/common.sh | 58 ++++++++++++++++++++++++++++++++ ci/kokoro/continuous-aarch64.cfg | 3 ++ ci/kokoro/continuous-x86_64.cfg | 3 ++ ci/kokoro/manifest.xml | 25 ++++++++++++++ ci/kokoro/presubmit-aarch64.cfg | 3 ++ ci/kokoro/presubmit-x86_64.cfg | 3 ++ ci/kokoro/simulate | 33 ++++++++++++++++++ ci/kokoro/simulate_all | 20 +++++++++++ ci/run_container.sh | 42 +++++++++++++++++------ devices/src/pci/ac97.rs | 12 ++++--- devices/src/pci/pci_device.rs | 2 +- 16 files changed, 218 insertions(+), 23 deletions(-) create mode 100755 ci/kokoro/build-aarch64.sh create mode 100755 ci/kokoro/build-x86_64.sh create mode 100755 ci/kokoro/common.sh create mode 100644 ci/kokoro/continuous-aarch64.cfg create mode 100644 ci/kokoro/continuous-x86_64.cfg create mode 100644 ci/kokoro/manifest.xml create mode 100644 ci/kokoro/presubmit-aarch64.cfg create mode 100644 ci/kokoro/presubmit-x86_64.cfg create mode 100755 ci/kokoro/simulate create mode 100755 ci/kokoro/simulate_all diff --git a/Cargo.lock b/Cargo.lock index 6943bbeb62..07c7f56ee4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -558,6 +558,7 @@ dependencies = [ "libc", "log", "protobuf", + "thiserror", ] [[package]] diff --git a/bin/clippy b/bin/clippy index 506d63d8d2..a9b70f6754 100755 --- a/bin/clippy +++ b/bin/clippy @@ -10,14 +10,14 @@ set -eo pipefail USE_CACHE=false -CLIPPY_ARGS=( "$@" ) +CLIPPY_ARGS=("$@") # TODO: When we add more options, use a fancier parsing mechanism such as # getopts. Also use the Rust convention of -- separating the arguments for this # script itself from the ones for clippy. -if (( "$#" > 0 )) && [[ "$1" == "--use-cache" ]]; then +if (("$#" > 0)) && [[ "$1" == "--use-cache" ]]; then USE_CACHE=true - CLIPPY_ARGS=( "${CLIPPY_ARGS[@]:1}" ) + CLIPPY_ARGS=("${CLIPPY_ARGS[@]:1}") fi # Change into directory of script, which is crosvm/bin. @@ -77,6 +77,7 @@ SUPPRESS=( unreadable_literal useless_let_if_seq useless_transmute + new-ret-no-self ) # Needed or else clippy won't re-run on code that has already compiled. @@ -91,4 +92,4 @@ RUSTFLAGS="${RUSTFLAGS:-}" export RUSTFLAGS="$RUSTFLAGS --sysroot=$RUST_SYSROOT" cargo clippy --all-features --all-targets -- ${SUPPRESS[@]/#/-Aclippy::} \ - "${CLIPPY_ARGS[@]}" -D warnings + "${CLIPPY_ARGS[@]}" -D warnings diff --git a/ci/Makefile b/ci/Makefile index 6ee41db0a3..21f0abc956 100644 --- a/ci/Makefile +++ b/ci/Makefile @@ -20,9 +20,11 @@ DOCKER ?= docker all: crosvm_builder crosvm_aarch64_builder upload: all - $(DOCKER) push $(TAG_BASE)/crosvm_base - $(DOCKER) push $(TAG_BASE)/crosvm_builder - $(DOCKER) push $(TAG_BASE)/crosvm_aarch64_builder + $(DOCKER) push $(TAG_BASE)/crosvm_base:$(TAG_VERSION) + $(DOCKER) push $(TAG_BASE)/crosvm_builder:$(TAG_VERSION) + $(DOCKER) push $(TAG_BASE)/crosvm_aarch64_builder:$(TAG_VERSION) + $(DOCKER) push $(TAG_BASE)/crosvm_test_vm_amd64:$(TAG_VERSION) + $(DOCKER) push $(TAG_BASE)/crosvm_test_vm_arm64:$(TAG_VERSION) crosvm_base: cd $@ && $(DOCKER) build -t $(TAG_BASE)/$@:$(TAG_VERSION) . diff --git a/ci/kokoro/build-aarch64.sh b/ci/kokoro/build-aarch64.sh new file mode 100755 index 0000000000..9e9a69992c --- /dev/null +++ b/ci/kokoro/build-aarch64.sh @@ -0,0 +1,9 @@ +#!/bin/bash +# Copyright 2021 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. + +source "$(dirname $0)/common.sh" + +cd "${KOKORO_ARTIFACTS_DIR}/cros/src/platform/crosvm" +./ci/aarch64_builder --vm ./run_tests --require-all diff --git a/ci/kokoro/build-x86_64.sh b/ci/kokoro/build-x86_64.sh new file mode 100755 index 0000000000..65ca780f33 --- /dev/null +++ b/ci/kokoro/build-x86_64.sh @@ -0,0 +1,10 @@ +#!/bin/bash +# Copyright 2021 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. + +source "$(dirname $0)/common.sh" + +./ci/builder --vm ./run_tests --require-all && \ + ./ci/builder "bin/clippy" && \ + ./ci/builder "bin/fmt --check" diff --git a/ci/kokoro/common.sh b/ci/kokoro/common.sh new file mode 100755 index 0000000000..b1709fd561 --- /dev/null +++ b/ci/kokoro/common.sh @@ -0,0 +1,58 @@ +#!/bin/bash +# Copyright 2021 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. + +crosvm_root="${KOKORO_ARTIFACTS_DIR}"/git/crosvm + +setup_source() { + if [ -z "${KOKORO_ARTIFACTS_DIR}" ]; then + echo "This script must be run in kokoro" + exit 1 + fi + + cd "${KOKORO_ARTIFACTS_DIR}" + + echo "" + echo "Downloading crosvm dependencies to $(pwd)/cros..." + mkdir cros + cd cros + + # repo gets confused by pyenv, make sure we select 3.6.1 as our default + # version. + if command -v pyenv; then + echo "Selecting Python 3.6.1" + pyenv global 3.6.1 + fi + curl -s https://storage.googleapis.com/git-repo-downloads/repo >repo + chmod +x repo + ./repo init --depth 1 -u https://chromium.googlesource.com/chromiumos/manifest.git \ + --repo-url https://chromium.googlesource.com/external/repo.git -g crosvm || return 1 + ./repo sync -j8 -c -m "${crosvm_root}/ci/kokoro/manifest.xml" || return 1 + + # Bind mount source into cros checkout. + echo "" + echo "Mounting crosvm source to $(pwd)/src/platform/crosvm..." + rm -rf src/platform/crosvm && mkdir -p src/platform/crosvm + if command -v bindfs; then + bindfs "${crosvm_root}" src/platform/crosvm || return 1 + else + sudo mount --bind "${crosvm_root}" src/platform/crosvm || return 1 + fi +} + +cleanup() { + if command -v bindfs; then + fusermount -uz "${KOKORO_ARTIFACTS_DIR}/cros/src/platform/crosvm" + else + sudo umount --lazy "${KOKORO_ARTIFACTS_DIR}/cros/src/platform/crosvm" + fi +} + +# Setup source when the script is loaded. Clean up on exit. +trap cleanup EXIT +setup_source || { + echo "Failed to setup_source" + exit 1 +} +cd "${KOKORO_ARTIFACTS_DIR}/cros/src/platform/crosvm" diff --git a/ci/kokoro/continuous-aarch64.cfg b/ci/kokoro/continuous-aarch64.cfg new file mode 100644 index 0000000000..f917d9011a --- /dev/null +++ b/ci/kokoro/continuous-aarch64.cfg @@ -0,0 +1,3 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +build_file: "crosvm/ci/kokoro/build-aarch64.sh" diff --git a/ci/kokoro/continuous-x86_64.cfg b/ci/kokoro/continuous-x86_64.cfg new file mode 100644 index 0000000000..ed9a3e73c6 --- /dev/null +++ b/ci/kokoro/continuous-x86_64.cfg @@ -0,0 +1,3 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +build_file: "crosvm/ci/kokoro/build-x86_64.sh" diff --git a/ci/kokoro/manifest.xml b/ci/kokoro/manifest.xml new file mode 100644 index 0000000000..89ae00ae0a --- /dev/null +++ b/ci/kokoro/manifest.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ci/kokoro/presubmit-aarch64.cfg b/ci/kokoro/presubmit-aarch64.cfg new file mode 100644 index 0000000000..f917d9011a --- /dev/null +++ b/ci/kokoro/presubmit-aarch64.cfg @@ -0,0 +1,3 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +build_file: "crosvm/ci/kokoro/build-aarch64.sh" diff --git a/ci/kokoro/presubmit-x86_64.cfg b/ci/kokoro/presubmit-x86_64.cfg new file mode 100644 index 0000000000..ed9a3e73c6 --- /dev/null +++ b/ci/kokoro/presubmit-x86_64.cfg @@ -0,0 +1,3 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +build_file: "crosvm/ci/kokoro/build-x86_64.sh" diff --git a/ci/kokoro/simulate b/ci/kokoro/simulate new file mode 100755 index 0000000000..51071b8173 --- /dev/null +++ b/ci/kokoro/simulate @@ -0,0 +1,33 @@ +#!/bin/bash +# Copyright 2021 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. +# +# Simulates a Kokoro run executing one of the build-*.sh scripts. +# e.g. ./ci/kokoro/simulate build-aarch64.sh + +kokoro_root=$(mktemp -d) +kokoro_src="${kokoro_root}/git/crosvm" +local_src=$(realpath $(dirname $0)/../../) + +cleanup() { + echo "Unmounting ${kokoro_src}" + umount --lazy "${kokoro_src}" || true + rm -rf "${kokoro_root}" +} + +main() { + # Bind mount source read-only to kokoro_src. + echo "Bind-mounting ${local_src} to ${kokoro_src}" + mkdir -p "${kokoro_src}" + bindfs "${local_src}" "${kokoro_src}" -p 0000,u=rxD + + # Run user-provided kokoro build script. + export KOKORO_ARTIFACTS_DIR="${kokoro_root}" + echo "Running $1 in ${kokoro_root}" + bash $(dirname $0)/$1 + echo "$1 returned $?" +} + +trap cleanup EXIT +main "$@" diff --git a/ci/kokoro/simulate_all b/ci/kokoro/simulate_all new file mode 100755 index 0000000000..1635b9fe01 --- /dev/null +++ b/ci/kokoro/simulate_all @@ -0,0 +1,20 @@ +#!/bin/bash +# Copyright 2021 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. +# +# Simulates all kokoro jobs (In parallel if tmux is installed) + +cd $(dirname "$0") + +if command -v tmux; then + TMUX= tmux \ + new-session './simulate build-x86_64.sh; + echo "press enter to close"; read' \; \ + split-window './simulate build-aarch64.sh; + echo "press enter to close"; read' \; +else + ./simulate build-x86.sh && + ./simulate build-analysis.sh && + ./simulate build-aarch64.sh +fi diff --git a/ci/run_container.sh b/ci/run_container.sh index 0ece8b883e..4174dca0a5 100755 --- a/ci/run_container.sh +++ b/ci/run_container.sh @@ -4,17 +4,25 @@ # found in the LICENSE file. # # Runs a crosvm builder. Will use podman if available, falls back to docker. +# Usage: +# run_container.sh builder_name [--clean] entry point args... crosvm_root=$(realpath "$(dirname $0)/..") cros_root=$(realpath "${crosvm_root}/../../..") -target=$( - cargo metadata --no-deps --format-version 1 | jq -r ".target_directory" -) +tmpdir="${TMPDIR:-/tmp}" if [ ! -d "${cros_root}/.repo" ]; then echo "The CI builder must be run from a cros checkout. See ci/README.md" exit 1 fi +# Parse parameters +builder="$1" +shift +if [ "$1" = "--clean" ]; then + shift + clean=1 +fi + # User podman if available for root-less execution. Fall-back to docker. if which podman >/dev/null; then run() { @@ -34,18 +42,32 @@ fi version=$(cat $(dirname $0)/image_tag) src="${cros_root}/src" -scratch="${target}/ci/$1" -mkdir -p "${scratch}" +scratch="${tmpdir}/crosvm-ci/${builder}" -echo "Using builder version: ${version}" +echo "Using builder: ${builder}:${version}" echo "Using source directory: ${src}" echo "Using scratch directory: ${scratch}" -echo "" -run --rm -it \ +if [[ -n "${clean}" ]]; then + rm -rf "${scratch}" + echo "Cleaned scratch directory." +fi +mkdir -p "${scratch}" + +docker_args=( + --rm --device /dev/kvm \ --volume /dev/log:/dev/log \ --volume "${src}":/workspace/src:rw \ --volume "${scratch}":/workspace/scratch:rw \ - "gcr.io/crosvm-packages/$1:${version}" \ - "${@:2}" +) + +# Enable interactive mode when running in an interactive terminal. +if [ -t 1 ]; then + docker_args+=( -it ) +fi + +echo "" +run ${docker_args[@]} \ + "gcr.io/crosvm-packages/${builder}:${version}" \ + "$@" diff --git a/devices/src/pci/ac97.rs b/devices/src/pci/ac97.rs index bd713b0b0f..73b28d3f42 100644 --- a/devices/src/pci/ac97.rs +++ b/devices/src/pci/ac97.rs @@ -14,10 +14,6 @@ use libcras::{CrasClient, CrasClientType, CrasSocketType}; use resources::{Alloc, MmioType, SystemAllocator}; use vm_memory::GuestMemory; -#[cfg(target_os = "linux")] -use crate::virtio::snd::vios_backend::VioSShmStreamSource; -#[cfg(not(target_os = "linux"))] -use crate::virtio::snd::vios_backend::Error as VioSError; use crate::pci::ac97_bus_master::Ac97BusMaster; use crate::pci::ac97_mixer::Ac97Mixer; use crate::pci::ac97_regs::*; @@ -26,6 +22,10 @@ use crate::pci::pci_configuration::{ }; use crate::pci::pci_device::{self, PciDevice, Result}; use crate::pci::{PciAddress, PciInterruptPin}; +#[cfg(not(target_os = "linux"))] +use crate::virtio::snd::vios_backend::Error as VioSError; +#[cfg(target_os = "linux")] +use crate::virtio::snd::vios_backend::VioSShmStreamSource; // Use 82801AA because it's what qemu does. const PCI_DEVICE_ID_INTEL_82801AA_5: u16 = 0x2415; @@ -179,7 +179,9 @@ impl Ac97Dev { return Ok(vios_audio); } #[cfg(not(target_os = "linux"))] - Err(pci_device::Error::CreateViosClientFailed(VioSError::PlatformNotSupported)) + Err(pci_device::Error::CreateViosClientFailed( + VioSError::PlatformNotSupported, + )) } fn create_null_audio_device(mem: GuestMemory) -> Result { diff --git a/devices/src/pci/pci_device.rs b/devices/src/pci/pci_device.rs index dd5de2d5bf..61e1bff988 100644 --- a/devices/src/pci/pci_device.rs +++ b/devices/src/pci/pci_device.rs @@ -10,9 +10,9 @@ use resources::{Error as SystemAllocatorFaliure, SystemAllocator}; use crate::pci::pci_configuration; use crate::pci::{PciAddress, PciInterruptPin}; -use crate::{BusAccessInfo, BusDevice}; #[cfg(feature = "audio")] use crate::virtio::snd::vios_backend::Error as VioSError; +use crate::{BusAccessInfo, BusDevice}; #[derive(Debug)] pub enum Error {