crosvm/integration_tests/guest_under_test/Makefile
Dennis Kempin 0797a55462 Framework for extended integration tests
This CL expands the existing boot.rs test to not just boot a kernel
but also provide a debian-based rootfs and a special init binary
that is used to communicate between test code and the guest VM.

The delegate binary listens for commands on /dev/ttyS1 and returns
the stdout of the executed command.
This allows the test code to setup pipes for the serial device to
issue commands in the client and receive the command output, which
provides a good foundation for tests of basic functionality without
the need to pass test binary code into the guest.

The integration tests will pull a prebuilt kernel and rootfs image
from cloud storage unless local files are specified via ENV variables.

The integration_tests/guest_under_test directory contains the files
needed to build and upload those prebuilts.

BUG=b:172926609
TEST=This is a test.

Cq-Depend: chromium:2551073
Change-Id: Iffb88a146a13d1b6ed7250df1b487bd87a5599d0
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2536831
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Auto-Submit: Dennis Kempin <denniskempin@google.com>
2021-01-20 17:48:10 +00:00

83 lines
2.7 KiB
Makefile

# Copyright 2020 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.
# Builds the kernel and rootfs for the guest used in integration testing.
#
# The main artifacts are:
# target/guest_under_test/bzImage
# target/guest_under_test/rootfs
# We are building everything in target/guest_under_test
CARGO_TARGET ?= $(shell cargo metadata --no-deps --format-version 1 | \
jq -r ".target_directory")
TARGET ?= $(CARGO_TARGET)/guest_under_test
$(shell mkdir -p $(TARGET))
# Currently only x86_64 is tested and supported.
ARCH = $(shell arch)
# Parameteters for building the kernel locally
KERNEL_REPO ?= https://chromium.googlesource.com/chromiumos/third_party/kernel
KERNEL_BRANCH ?= chromeos-4.19
# Build against the musl toolchain, which will produce a statically linked,
# portable binary that we can run on the alpine linux guest without needing
# libc at runtime
RUST_TARGET ?= $(ARCH)-unknown-linux-musl
################################################################################
# Main targets
all: $(TARGET)/rootfs $(TARGET)/bzImage
clean:
rm -rf $(TARGET)
################################################################################
# Build rootfs
dockerfile := $(shell pwd)/Dockerfile
# Build rootfs from Dockerfile and export into squashfs
$(TARGET)/rootfs: $(TARGET)/rootfs-build/delegate
# Build image from Dockerfile
cd $(TARGET)/rootfs-build && docker build -t crosvm_integration_test . \
-f $(dockerfile)
# Create container and export into squashfs, and don't forget to clean up
# the container afterwards.
set -x; \
CONTAINER=$$(docker create crosvm_integration_test); \
docker export $$CONTAINER | tar2sqfs -c gzip -f $@; \
docker rm $$CONTAINER
# Build and copy delegate binary into rootfs build directory
$(TARGET)/rootfs-build/delegate: delegate.rs
rustup target add $(RUST_TARGET)
rustc --edition=2018 delegate.rs --out-dir $(@D) --target $(RUST_TARGET)
################################################################################
# Build kernel
ifeq ($(ARCH), x86_64)
KERNEL_CONFIG ?= arch/x86/configs/chromiumos-container-vm-x86_64_defconfig
else
$(error Only x86_64 is supported)
endif
$(TARGET)/bzImage: $(TARGET)/kernel-source $(TARGET)/kernel-build
cd $(TARGET)/kernel-source && \
yes "" | make O=$(TARGET)/kernel-build -j$(shell nproc) bzImage
cp $(TARGET)/kernel-build/arch/x86/boot/bzImage $@
$(TARGET)/kernel-build: $(TARGET)/kernel-source
mkdir -p $@
cp -f $(TARGET)/kernel-source/$(KERNEL_CONFIG) $@/.config
$(TARGET)/kernel-source:
rm -rf $@
git clone --depth 1 --branch $(KERNEL_BRANCH) $(KERNEL_REPO) $@
.PHONY: clean all update-prebuilts