summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvan Benn <evanbenn@chromium.org>2022-08-16 17:02:02 +1000
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-10-25 09:36:59 +0000
commit148e5b836dc52e8d81bb67f29dea7c81aa3d720f (patch)
treedabea89841ec086a42a174378e405a185367a340
parenta9c47c41cc3801cd888bdcdfd18d8f4d9f787ce5 (diff)
downloadvboot-148e5b836dc52e8d81bb67f29dea7c81aa3d720f.tar.gz
Makefile: Fix and simplify the RUNTEST test wrapper
Remove the qemu logic from the Makefile. Document the RUNTEST, BUILD_RUN and SRC_RUN variables. Ensure those variables are used consistently throughout the Makefile and test scripts. BUG=b:231084609 BRANCH=None TEST=FEATURES=test emerge vboot_reference TEST=FEATURES=test emerge-amd64-generic vboot_reference TEST=FEATURES=test emerge-hatch coreboot TEST=(coreboot upstream with this patch) make all TEST=make BUILD=build1 runtests TEST=make BUILD=build2 RUNTEST=env runtests Cq-Depend: chromium:3934904 Change-Id: Ifd18463d681bedbf7464165f2df0181474b36791 Signed-off-by: Evan Benn <evanbenn@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/3831828 Reviewed-by: Yu-Ping Wu <yupingso@chromium.org>
-rw-r--r--Makefile98
-rw-r--r--tests/common.sh13
-rwxr-xr-xtests/futility/run_test_scripts.sh3
-rwxr-xr-xtests/gen_fuzz_test_cases.sh2
-rwxr-xr-xtests/test_using_qemu.sh40
5 files changed, 37 insertions, 119 deletions
diff --git a/Makefile b/Makefile
index d70e0215..9cfe65be 100644
--- a/Makefile
+++ b/Makefile
@@ -37,7 +37,6 @@
# We should only run pwd once, not every time we refer to ${BUILD}.
SRCDIR := $(shell pwd)
-export SRCDIR
BUILD = ${SRCDIR}/build
export BUILD
@@ -88,7 +87,7 @@ endif
_machname := $(shell uname -m)
HOST_ARCH ?= ${_machname}
-# ARCH and/or FIRMWARE_ARCH are defined by the Chromium OS ebuild.
+# ARCH and/or FIRMWARE_ARCH are defined by the ChromiumOS ebuild.
# Pick a valid target architecture if none is defined.
ifeq (${ARCH},)
ARCH := ${HOST_ARCH}
@@ -112,7 +111,7 @@ else
CROSSYSTEM_ARCH_C := host/arch/stub/lib/crossystem_arch.c
endif
-# FIRMWARE_ARCH is only defined by the Chromium OS ebuild if compiling
+# FIRMWARE_ARCH is only defined by the ChromiumOS ebuild if compiling
# for a firmware target (coreboot or depthcharge). It must map to the same
# consistent set of architectures as the host.
ifeq (${FIRMWARE_ARCH},i386)
@@ -291,39 +290,16 @@ endif
# Get major version of openssl (e.g. version 3.0.5 -> "3")
OPENSSL_VERSION := $(shell ${PKG_CONFIG} --modversion openssl | cut -d. -f1)
-# Determine QEMU architecture needed, if any
-ifeq (${ARCH},${HOST_ARCH})
- # Same architecture; no need for QEMU
- QEMU_ARCH :=
-else ifeq (${HOST_ARCH}-${ARCH},x86_64-x86)
- # 64-bit host can run 32-bit targets directly
- QEMU_ARCH :=
-else
- QEMU_ARCH := ${ARCH}
-endif
-
-# The top of the chroot for qemu must be passed in via the SYSROOT environment
-# variable. In the Chromium OS chroot, this is done automatically by the
-# ebuild.
-
-ifeq (${QEMU_ARCH},)
- # Path to build output for running tests is same as for building
- BUILD_RUN = ${BUILD}
- SRC_RUN = ${SRCDIR}
-else
- $(info Using qemu for testing.)
- # Path to build output for running tests is different in the chroot
- BUILD_RUN = $(subst ${SYSROOT},,${BUILD})
- SRC_RUN = $(subst ${SYSROOT},,${SRCDIR})
-
- QEMU_BIN = qemu-${QEMU_ARCH}
- QEMU_RUN = ${BUILD_RUN}/${QEMU_BIN}
- export QEMU_RUN
-
- RUNTEST = tests/test_using_qemu.sh
-endif
-
-export BUILD_RUN
+# A test wrapper can be specified. Tests are run inside the wrapper eg:
+# make RUNTEST=env runtests
+RUNTEST =
+# The Path to the $BUILD inside the runtest wrapper, used by the test scripts.
+# The top of the chroot for RUNTEST must be passed in via the SYSROOT
+# environment variable. In the ChromiumOS chroot, this is done automatically by
+# the ebuild.
+export BUILD_RUN = $(subst ${SYSROOT},,${BUILD})
+# Path to the $SRCDIR inside the wrapper, the test scripts rederive this.
+SRC_RUN = $(subst ${SYSROOT},,${SRCDIR})
##############################################################################
# The default target is here, to allow dependencies to be expressed below
@@ -1244,36 +1220,20 @@ ${FUTIL_CMD_LIST}: ${FUTIL_SRCS}
.PHONY: test_setup
test_setup:: cgpt ${UTIL_FILES_SDK} ${UTIL_FILES_BOARD} futil tests
-# Qemu setup for cross-compiled tests. Need to copy qemu binary into the
-# sysroot.
-ifneq (${QEMU_ARCH},)
-test_setup:: qemu_install
-
-.PHONY: qemu_install
-qemu_install:
-ifeq (${SYSROOT},)
- $(error SYSROOT must be set to the top of the target-specific root \
-when cross-compiling for qemu-based tests to run properly.)
-endif
- @${PRINTF} " Copying qemu binary.\n"
- ${Q}cp -fu /usr/bin/${QEMU_BIN} ${BUILD}/${QEMU_BIN}
- ${Q}chmod a+rx ${BUILD}/${QEMU_BIN}
-endif
-
# Generate test keys
.PHONY: genkeys
genkeys: install_for_test
- tests/gen_test_keys.sh
+ ${RUNTEST} ${SRC_RUN}/tests/gen_test_keys.sh
# Generate test cases
.PHONY: gentestcases
gentestcases: install_for_test
- tests/gen_test_cases.sh
+ ${RUNTEST} ${SRC_RUN}/tests/gen_test_cases.sh
# Generate test cases for fuzzing
.PHONY: genfuzztestcases
genfuzztestcases: install_for_test
- tests/gen_fuzz_test_cases.sh
+ ${RUNTEST} ${SRC_RUN}/tests/gen_fuzz_test_cases.sh
.PHONY: runcgpttests
runcgpttests: install_for_test
@@ -1281,15 +1241,15 @@ runcgpttests: install_for_test
.PHONY: runtestscripts
runtestscripts: install_for_test genfuzztestcases
- scripts/image_signing/sign_android_unittests.sh
- tests/load_kernel_tests.sh
- tests/run_cgpt_tests.sh ${BUILD_RUN}/cgpt/cgpt
- tests/run_cgpt_tests.sh ${BUILD_RUN}/cgpt/cgpt -D 358400
- tests/run_preamble_tests.sh
- tests/run_vbutil_kernel_arg_tests.sh
- tests/run_vbutil_tests.sh
- tests/vb2_rsa_tests.sh
- tests/vb2_firmware_tests.sh
+ ${RUNTEST} ${SRC_RUN}/scripts/image_signing/sign_android_unittests.sh
+ ${RUNTEST} ${SRC_RUN}/tests/load_kernel_tests.sh
+ ${RUNTEST} ${SRC_RUN}/tests/run_cgpt_tests.sh ${BUILD_RUN}/cgpt/cgpt
+ ${RUNTEST} ${SRC_RUN}/tests/run_cgpt_tests.sh ${BUILD_RUN}/cgpt/cgpt -D 358400
+ ${RUNTEST} ${SRC_RUN}/tests/run_preamble_tests.sh
+ ${RUNTEST} ${SRC_RUN}/tests/run_vbutil_kernel_arg_tests.sh
+ ${RUNTEST} ${SRC_RUN}/tests/run_vbutil_tests.sh
+ ${RUNTEST} ${SRC_RUN}/tests/vb2_rsa_tests.sh
+ ${RUNTEST} ${SRC_RUN}/tests/vb2_firmware_tests.sh
.PHONY: runmisctests
runmisctests: install_for_test
@@ -1330,14 +1290,14 @@ run2tests: install_for_test
${RUNTEST} ${BUILD_RUN}/tests/vb20_kernel_tests
${RUNTEST} ${BUILD_RUN}/tests/vb21_host_common_tests
${RUNTEST} ${BUILD_RUN}/tests/vb21_host_common2_tests ${TEST_KEYS}
- ${RUNTEST} ${BUILD_RUN}/tests/vb21_host_key_tests ${TEST_KEYS} ${BUILD}
- ${RUNTEST} ${BUILD_RUN}/tests/vb21_host_misc_tests ${BUILD}
+ ${RUNTEST} ${BUILD_RUN}/tests/vb21_host_key_tests ${TEST_KEYS} ${BUILD_RUN}
+ ${RUNTEST} ${BUILD_RUN}/tests/vb21_host_misc_tests ${BUILD_RUN}
${RUNTEST} ${BUILD_RUN}/tests/vb21_host_sig_tests ${TEST_KEYS}
${RUNTEST} ${BUILD_RUN}/tests/hmac_test
.PHONY: runfutiltests
runfutiltests: install_for_test
- tests/futility/run_test_scripts.sh
+ ${RUNTEST} ${SRC_RUN}/tests/futility/run_test_scripts.sh
${RUNTEST} ${BUILD_RUN}/tests/futility/test_file_types
${RUNTEST} ${BUILD_RUN}/tests/futility/test_not_really
@@ -1348,8 +1308,8 @@ runlongtests: install_for_test genkeys genfuzztestcases
${RUNTEST} ${BUILD_RUN}/tests/vb2_common2_tests ${TEST_KEYS} --all
${RUNTEST} ${BUILD_RUN}/tests/vb2_common3_tests ${TEST_KEYS} --all
${RUNTEST} ${BUILD_RUN}/tests/vb21_host_common2_tests ${TEST_KEYS} --all
- tests/run_preamble_tests.sh --all
- tests/run_vbutil_tests.sh --all
+ ${RUNTEST} ${SRC_RUN}/tests/run_preamble_tests.sh --all
+ ${RUNTEST} ${SRC_RUN}/tests/run_vbutil_tests.sh --all
.PHONY: rununittests
rununittests: runcgpttests runmisctests run2tests
diff --git a/tests/common.sh b/tests/common.sh
index 78512254..ed1c9f06 100644
--- a/tests/common.sh
+++ b/tests/common.sh
@@ -7,14 +7,13 @@
# Determine script directory.
SCRIPT_DIR="$(dirname "$(realpath "${BASH_SOURCE[0]}")")"
ROOT_DIR="$(dirname "${SCRIPT_DIR}")"
-SRCDIR="${SRCDIR:-${ROOT_DIR}}"
-BUILD="${BUILD:-${ROOT_DIR}/build}"
-BUILD_RUN="${BUILD_RUN:-${BUILD}}"
-SRC_RUN="${SRC_RUN:-${SRCDIR}}"
-BUILD_DIR="${BUILD}"
-BIN_DIR="${BUILD_DIR}/install_for_test/usr/bin"
+SRCDIR="${ROOT_DIR}"
+# BUILD_RUN should be supplied from the Makefile.
+# Some test scripts change the cwd so use an absolute path.
+BUILD_RUN="$(realpath "${BUILD_RUN}")"
+BIN_DIR="${BUILD_RUN}/install_for_test/usr/bin"
FUTILITY="${BIN_DIR}/futility"
-TEST_DIR="${BUILD_DIR}/tests"
+TEST_DIR="${BUILD_RUN}/tests"
TESTKEY_DIR="${SCRIPT_DIR}/testkeys"
TESTCASE_DIR="${SCRIPT_DIR}/testcases"
TESTKEY_SCRATCH_DIR="${TEST_DIR}/testkeys"
diff --git a/tests/futility/run_test_scripts.sh b/tests/futility/run_test_scripts.sh
index dc87f76b..09086998 100755
--- a/tests/futility/run_test_scripts.sh
+++ b/tests/futility/run_test_scripts.sh
@@ -6,11 +6,10 @@
# Load common constants and variables.
. "$(dirname "$0")/../common.sh"
-OUTDIR="${BUILD}/tests/futility_test_results"
+OUTDIR="${BUILD_RUN}/tests/futility_test_results"
[ -d "$OUTDIR" ] || mkdir -p "$OUTDIR"
# Let each test know where to find things...
-export BUILD
export BUILD_RUN
export SRCDIR
export FUTILITY
diff --git a/tests/gen_fuzz_test_cases.sh b/tests/gen_fuzz_test_cases.sh
index 1dede33d..0a9f6942 100755
--- a/tests/gen_fuzz_test_cases.sh
+++ b/tests/gen_fuzz_test_cases.sh
@@ -13,7 +13,7 @@ set -e
# Use a different directory for fuzzing test cases.
TESTKEY_DIR=${TESTKEY_DIR:-$(realpath "${SCRIPT_DIR}"/../tests/testkeys)}
-TESTCASE_DIR=${BUILD_DIR}/fuzz_testcases
+TESTCASE_DIR=${BUILD_RUN}/fuzz_testcases
TEST_IMAGE_FILE=${TESTCASE_DIR}/testimage
TEST_IMAGE_SIZE=500000
TEST_BOOTLOADER_FILE=${TESTCASE_DIR}/testbootloader
diff --git a/tests/test_using_qemu.sh b/tests/test_using_qemu.sh
deleted file mode 100755
index 99669d5e..00000000
--- a/tests/test_using_qemu.sh
+++ /dev/null
@@ -1,40 +0,0 @@
-#!/bin/bash
-#
-# Copyright 2013 The ChromiumOS Authors
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-#
-# Script to run a test under qemu
-#
-# Usage:
-# test_using_qemu.sh (command line to run)
-#
-# Required environment variables:
-# BUILD_RUN - path to build directory inside chroot
-# HOME - home directory inside chroot
-# QEMU_RUN - path to QEMU binary inside chroot
-# SYSROOT - path to root for target platform, outside chroot
-
-set -e
-
-# Set up mounts
-sudo mkdir -p "${SYSROOT}/proc" "${SYSROOT}/dev"
-sudo mount --bind /proc "${SYSROOT}/proc"
-sudo mount --bind /dev "${SYSROOT}/dev"
-
-# Don't exit on error, so we can capture the error code
-set +e
-sudo chroot "${SYSROOT}" "${QEMU_RUN}" \
- -E LD_LIBRARY_PATH=/lib64:/lib:/usr/lib64:/usr/lib \
- -E HOME="${HOME}" \
- -E BUILD="${BUILD_RUN}" \
- -- "$@"
-exit_code=$?
-set -e
-
-# Clean up mounts
-sudo umount -l "${SYSROOT}/proc"
-sudo umount -l "${SYSROOT}/dev"
-
-# Pass through exit code from command
-exit $exit_code