David Brazdil | e8ebf27 | 2020-07-24 10:00:31 +0000 | [diff] [blame] | 1 | # Copyright 2020 The Android KVM Authors |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
David Brazdil | ef8506d | 2020-07-27 19:56:16 +0000 | [diff] [blame] | 15 | SELF := $(abspath $(lastword $(MAKEFILE_LIST))) |
| 16 | |
Elena Petrova | 467cfd9 | 2021-01-15 14:56:04 +0000 | [diff] [blame] | 17 | CPUS ?= $(shell nproc) |
| 18 | MAKEFLAGS += --jobs=$(CPUS) |
David Brazdil | 94acb6f | 2021-08-23 08:35:03 +0000 | [diff] [blame] | 19 | SHELL ?= $(shell which bash) |
Elena Petrova | 467cfd9 | 2021-01-15 14:56:04 +0000 | [diff] [blame] | 20 | |
Fuad Tabba | 42a3b29 | 2020-05-13 15:04:03 +0100 | [diff] [blame] | 21 | ## |
| 22 | ## Folders |
| 23 | ## |
David Brazdil | acc8ea4 | 2020-04-28 16:01:08 +0100 | [diff] [blame] | 24 | ROOT_DIR := $(CURDIR) |
Fuad Tabba | d99cc75 | 2020-08-17 11:31:56 +0000 | [diff] [blame] | 25 | |
David Brazdil | acc8ea4 | 2020-04-28 16:01:08 +0100 | [diff] [blame] | 26 | OUT_DIR := $(ROOT_DIR)/out |
Fuad Tabba | cd90840 | 2021-02-09 17:18:15 +0000 | [diff] [blame] | 27 | |
| 28 | # DIST_DIR: target directory for artifacts and logs. |
| 29 | # The CI build (pKVM Busytown) uses it to separate artifacts from other |
| 30 | # temporary build files, which are placed in in OUT_DIR. |
| 31 | # For other users, OUT_DIR and DIST_DIR are typically the same. |
| 32 | DIST_DIR ?= $(OUT_DIR) |
| 33 | |
| 34 | # Copy specified file or directory only if OUT_DIR and DIST_DIR aren't the same. |
| 35 | # |
| 36 | # Parameters: |
| 37 | # $(1): Source files or directories (to be copied recursively) |
| 38 | # $(2): Destination directory (is created if it doesn't exist) |
| 39 | ifneq ($(abspath $(OUT_DIR)), $(abspath $(DIST_DIR))) |
| 40 | define copy_to_dist |
| 41 | mkdir -p $(2) && cp -r $(1) $(2) |
| 42 | endef |
Fuad Tabba | d99cc75 | 2020-08-17 11:31:56 +0000 | [diff] [blame] | 43 | endif |
| 44 | |
Fuad Tabba | a74ba08 | 2020-05-29 11:56:18 +0100 | [diff] [blame] | 45 | LINUX_OUT := $(OUT_DIR)/linux |
Fuad Tabba | cd90840 | 2021-02-09 17:18:15 +0000 | [diff] [blame] | 46 | LINUX_DIST := $(DIST_DIR)/linux |
David Brazdil | ef8506d | 2020-07-27 19:56:16 +0000 | [diff] [blame] | 47 | SCRIPTS_DIR := $(ROOT_DIR)/build |
David Brazdil | acc8ea4 | 2020-04-28 16:01:08 +0100 | [diff] [blame] | 48 | |
David Brazdil | f5d3276 | 2021-08-23 08:40:18 +0000 | [diff] [blame] | 49 | include $(SCRIPTS_DIR)/toolchain.mk |
| 50 | |
Fuad Tabba | 42a3b29 | 2020-05-13 15:04:03 +0100 | [diff] [blame] | 51 | ## |
| 52 | ## Common options |
| 53 | ## |
| 54 | VERBOSE ?= 0 |
Fuad Tabba | 7f167f7 | 2020-09-17 15:26:45 +0100 | [diff] [blame] | 55 | ARCH = arm64 |
Fuad Tabba | a74ba08 | 2020-05-29 11:56:18 +0100 | [diff] [blame] | 56 | |
David Brazdil | 880a1be | 2021-09-30 13:13:15 +0100 | [diff] [blame] | 57 | LINUX_OUT_IMAGE := $(LINUX_OUT)/arch/arm64/boot/Image |
| 58 | LINUX_OUT_MODULES := $(LINUX_OUT)/modules_install |
| 59 | LINUX_OUT_MODULES_DEP := $(LINUX_OUT)/modules_install.stamp |
| 60 | |
| 61 | # KERNEL_IMAGE/MODULES can be set to use own custom kernel image. |
| 62 | KERNEL_IMAGE ?= $(LINUX_OUT_IMAGE) |
| 63 | KERNEL_MODULES ?= $(LINUX_OUT_MODULES) |
| 64 | KERNEL_MODULES_DEP ?= $(LINUX_OUT_MODULES_DEP) |
Fuad Tabba | a74ba08 | 2020-05-29 11:56:18 +0100 | [diff] [blame] | 65 | |
David Brazdil | acc8ea4 | 2020-04-28 16:01:08 +0100 | [diff] [blame] | 66 | ## |
Fuad Tabba | 7f167f7 | 2020-09-17 15:26:45 +0100 | [diff] [blame] | 67 | ## Toolchain options and variables |
| 68 | ## |
| 69 | |
| 70 | # Specifies which toolchain of the prebuilt toolchains to use. |
David Brazdil | 53a7030 | 2021-08-20 13:32:11 +0000 | [diff] [blame] | 71 | # Can be either clang, gcc-5.1, or gcc-9.2. |
Fuad Tabba | 6761847 | 2021-04-27 11:56:35 +0100 | [diff] [blame] | 72 | # GCC will always use the latest version for building everything else other |
| 73 | # than the kernel. |
Fuad Tabba | 7f167f7 | 2020-09-17 15:26:45 +0100 | [diff] [blame] | 74 | TOOLCHAIN ?= clang |
David Brazdil | f5d3276 | 2021-08-23 08:40:18 +0000 | [diff] [blame] | 75 | $(eval $(call define_toolchain,$(TOOLCHAIN))) |
Fuad Tabba | 7f167f7 | 2020-09-17 15:26:45 +0100 | [diff] [blame] | 76 | |
| 77 | ## |
David Brazdil | acc8ea4 | 2020-04-28 16:01:08 +0100 | [diff] [blame] | 78 | ## Common targets |
| 79 | ## |
| 80 | |
Fuad Tabba | 6b9c08e | 2020-05-18 13:03:01 +0100 | [diff] [blame] | 81 | .DEFAULT_GOAL := default |
| 82 | |
| 83 | .PHONY: default |
David Brazdil | 54fb744 | 2020-07-27 09:54:56 +0000 | [diff] [blame] | 84 | default: kvm-unit-tests linux |
Fuad Tabba | 6b9c08e | 2020-05-18 13:03:01 +0100 | [diff] [blame] | 85 | |
David Brazdil | acc8ea4 | 2020-04-28 16:01:08 +0100 | [diff] [blame] | 86 | .PHONY: clean |
Andrew Walbran | b8b247c | 2021-11-12 14:10:34 +0000 | [diff] [blame^] | 87 | clean: bl_clean bl33_clean buildroot_clean kvm-unit-tests_clean linux_clean kselftest_clean tfa_clean |
David Brazdil | acc8ea4 | 2020-04-28 16:01:08 +0100 | [diff] [blame] | 88 | |
Fuad Tabba | 42a3b29 | 2020-05-13 15:04:03 +0100 | [diff] [blame] | 89 | .PHONY: distclean |
David Brazdil | f770f60 | 2020-07-27 09:53:28 +0000 | [diff] [blame] | 90 | distclean: |
Fuad Tabba | cd90840 | 2021-02-09 17:18:15 +0000 | [diff] [blame] | 91 | - rm -rf $(OUT_DIR) $(DIST_DIR) |
Fuad Tabba | 42a3b29 | 2020-05-13 15:04:03 +0100 | [diff] [blame] | 92 | |
David Brazdil | a8f60f1 | 2021-10-04 18:41:47 +0100 | [diff] [blame] | 93 | FORCE: |
| 94 | |
Fuad Tabba | 42a3b29 | 2020-05-13 15:04:03 +0100 | [diff] [blame] | 95 | .PHONY: all |
David Brazdil | e7f36f1 | 2021-09-29 13:37:51 +0100 | [diff] [blame] | 96 | all: buildroot kvm-unit-tests linux |
Fuad Tabba | 42a3b29 | 2020-05-13 15:04:03 +0100 | [diff] [blame] | 97 | |
| 98 | .PHONY: help |
| 99 | help: |
| 100 | @echo 'Generic Targets:' |
Fuad Tabba | 6b9c08e | 2020-05-18 13:03:01 +0100 | [diff] [blame] | 101 | @echo ' default - builds all generic targets except for buildroot' |
| 102 | @echo ' all - builds all generic targets' |
Andrew Walbran | b8b247c | 2021-11-12 14:10:34 +0000 | [diff] [blame^] | 103 | @echo ' bl - builds U-Boot and TF-A and copies them to the bl output directory' |
Andrew Walbran | 7cfab33 | 2021-11-09 14:35:55 +0000 | [diff] [blame] | 104 | @echo ' bl33 - U-Boot as BL33' |
Fuad Tabba | 42a3b29 | 2020-05-13 15:04:03 +0100 | [diff] [blame] | 105 | @echo ' buildroot - the buildroot rootfs image as well as the host qemu' |
David Brazdil | 54fb744 | 2020-07-27 09:54:56 +0000 | [diff] [blame] | 106 | @echo ' kvm-unit-tests - the kvm-unit-tests' |
David Brazdil | a8f60f1 | 2021-10-04 18:41:47 +0100 | [diff] [blame] | 107 | @echo ' linux - the Linux kernel' |
| 108 | @echo ' kselftest - the Linux kernel selftests' |
Andrew Walbran | b8b247c | 2021-11-12 14:10:34 +0000 | [diff] [blame^] | 109 | @echo ' tfa - Arm Trusted Firmware-A' |
Fuad Tabba | 42a3b29 | 2020-05-13 15:04:03 +0100 | [diff] [blame] | 110 | @echo '' |
| 111 | @echo 'Clean Targets:' |
| 112 | @echo ' clean - cleans all, but keeps the prebuilts' |
| 113 | @echo ' distclean - distclean for all targets' |
Andrew Walbran | b8b247c | 2021-11-12 14:10:34 +0000 | [diff] [blame^] | 114 | @echo ' bl_clean - TF-A, U-Boot and the bl output directory' |
Andrew Walbran | 7cfab33 | 2021-11-09 14:35:55 +0000 | [diff] [blame] | 115 | @echo ' bl33_clean - the U-Boot BL33' |
Fuad Tabba | 42a3b29 | 2020-05-13 15:04:03 +0100 | [diff] [blame] | 116 | @echo ' buildroot_clean - the buildroot rootfs image as well as the host qemu' |
David Brazdil | 54fb744 | 2020-07-27 09:54:56 +0000 | [diff] [blame] | 117 | @echo ' kvm-unit-tests_clean - the kvm-unit-tests' |
David Brazdil | a8f60f1 | 2021-10-04 18:41:47 +0100 | [diff] [blame] | 118 | @echo ' linux_clean - the Linux kernel' |
| 119 | @echo ' kselftest_clean - the Linux kernel selftests' |
Andrew Walbran | b8b247c | 2021-11-12 14:10:34 +0000 | [diff] [blame^] | 120 | @echo ' tfa_clean - Arm Trusted Firmware-A' |
Fuad Tabba | 42a3b29 | 2020-05-13 15:04:03 +0100 | [diff] [blame] | 121 | @echo '' |
David Brazdil | ef8506d | 2020-07-27 19:56:16 +0000 | [diff] [blame] | 122 | @echo 'Test Targets:' |
| 123 | @echo ' test - runs all tests in qemu-aarch64 simulated environment' |
| 124 | @echo ' test-kut - runs all kvm-unit-tests in qemu-aarch64 simulated environment' |
David Brazdil | b2162fe | 2021-10-04 18:52:09 +0100 | [diff] [blame] | 125 | @echo ' test-ksft - runs all kselftests in qemu-aarch64 simulated environment' |
David Brazdil | ef8506d | 2020-07-27 19:56:16 +0000 | [diff] [blame] | 126 | @echo ' test-list - lists all test targets' |
| 127 | @echo '' |
Pierre-Clément Tosi | aa7c390 | 2021-09-22 14:46:06 +0200 | [diff] [blame] | 128 | @echo 'Test Parameters:' |
Pierre-Clément Tosi | a4c90ba | 2021-09-22 14:28:04 +0200 | [diff] [blame] | 129 | @echo ' CROSVM_TAR_GZ - path to a custom cvd-host_package.tar.gz' |
| 130 | @echo ' (default: uses a pre-built version)' |
Pierre-Clément Tosi | aa7c390 | 2021-09-22 14:46:06 +0200 | [diff] [blame] | 131 | @echo ' VM_IMAGE - path to an image to be used by the VMM to boot the VM' |
| 132 | @echo ' (default: uses the host image)' |
| 133 | @echo '' |
Pierre-Clément Tosi | 4768c6c | 2021-08-02 09:53:29 +0000 | [diff] [blame] | 134 | @echo 'Test Flags:' |
| 135 | @echo ' VERBOSE=[0|1] - prints the verbose output of the scripts running the test' |
| 136 | @echo ' (default: 0)' |
| 137 | @echo ' QUIET=[0|1] - redirects the output to a file instead of stdout' |
| 138 | @echo ' (default: 1)' |
| 139 | @echo ' GDB=[0|1] - makes the started test wait for a GDB connection' |
| 140 | @echo ' (default: 0)' |
| 141 | @echo '' |
Fuad Tabba | 42a3b29 | 2020-05-13 15:04:03 +0100 | [diff] [blame] | 142 | @echo 'Misc Targets:' |
Fuad Tabba | 6b9c08e | 2020-05-18 13:03:01 +0100 | [diff] [blame] | 143 | @echo ' update-prebuilts - generates/update the prebuilt rootfs image (aarch64) and the qemu host (aarch64)' |
Fuad Tabba | 42a3b29 | 2020-05-13 15:04:03 +0100 | [diff] [blame] | 144 | |
David Brazdil | acc8ea4 | 2020-04-28 16:01:08 +0100 | [diff] [blame] | 145 | |
| 146 | ## |
| 147 | ## Buildroot |
| 148 | ## |
| 149 | |
Fuad Tabba | 714a692 | 2020-10-29 15:12:23 +0000 | [diff] [blame] | 150 | BR_DEFCONFIG ?= qemu_aarch64_virt_kvmunittests_defconfig |
Fuad Tabba | 42a3b29 | 2020-05-13 15:04:03 +0100 | [diff] [blame] | 151 | BR_VERBOSE ?= $(VERBOSE) |
David Brazdil | acc8ea4 | 2020-04-28 16:01:08 +0100 | [diff] [blame] | 152 | |
| 153 | BR_SRC := $(ROOT_DIR)/buildroot |
| 154 | BR_OUT := $(OUT_DIR)/buildroot |
| 155 | BR_MAKE := $(MAKE) -C $(BR_SRC) V=$(BR_VERBOSE) O=$(BR_OUT) |
| 156 | |
| 157 | .PHONY: buildroot |
| 158 | buildroot: |
Fuad Tabba | 42a3b29 | 2020-05-13 15:04:03 +0100 | [diff] [blame] | 159 | + $(BR_MAKE) $(BR_DEFCONFIG) |
| 160 | + $(BR_MAKE) all |
David Brazdil | acc8ea4 | 2020-04-28 16:01:08 +0100 | [diff] [blame] | 161 | |
| 162 | .PHONY: buildroot_clean |
| 163 | buildroot_clean: |
Fuad Tabba | 42a3b29 | 2020-05-13 15:04:03 +0100 | [diff] [blame] | 164 | + $(BR_MAKE) clean |
| 165 | |
Andrew Walbran | b8b247c | 2021-11-12 14:10:34 +0000 | [diff] [blame^] | 166 | # Bootloader stages come from TF-A, U-Boot, or just an empty file. |
| 167 | BL_DIR := $(OUT_DIR)/bl |
| 168 | BL1_BIN := $(BL_DIR)/bl1.bin |
| 169 | BL2_BIN := $(BL_DIR)/bl2.bin |
| 170 | BL31_BIN := $(BL_DIR)/bl31.bin |
| 171 | BL32_BIN := $(BL_DIR)/bl32.bin |
| 172 | BL33_BIN := $(BL_DIR)/bl33.bin |
| 173 | |
Andrew Walbran | 7cfab33 | 2021-11-09 14:35:55 +0000 | [diff] [blame] | 174 | ## |
| 175 | ## U-Boot |
| 176 | ## |
| 177 | UBOOT_SRC := $(ROOT_DIR)/u-boot |
| 178 | UBOOT_OUT := $(OUT_DIR)/u-boot |
Andrew Walbran | 7cfab33 | 2021-11-09 14:35:55 +0000 | [diff] [blame] | 179 | UBOOT_DEFCONFIG ?= qemu_arm64_defconfig |
| 180 | UBOOT_CONFIG := $(UBOOT_OUT)/.config |
| 181 | UBOOT_TOOLCHAIN ?= gcc-9.2 |
| 182 | UBOOT_VERBOSE ?= $(VERBOSE) |
| 183 | $(eval $(call define_toolchain,$(UBOOT_TOOLCHAIN),UBOOT_)) |
| 184 | UBOOT_MAKE := \ |
| 185 | PATH=$(UBOOT_TOOLCHAIN_BIN):$(PATH) \ |
| 186 | CROSS_COMPILE=aarch64-linux-gnu- \ |
| 187 | $(MAKE) \ |
| 188 | V=$(UBOOT_VERBOSE) \ |
| 189 | -C $(UBOOT_SRC) \ |
| 190 | O=$(UBOOT_OUT) |
| 191 | |
| 192 | .PHONY: bl33 |
Andrew Walbran | b8b247c | 2021-11-12 14:10:34 +0000 | [diff] [blame^] | 193 | bl33: $(UBOOT_OUT)/u-boot.bin |
Andrew Walbran | 7cfab33 | 2021-11-09 14:35:55 +0000 | [diff] [blame] | 194 | |
| 195 | $(UBOOT_CONFIG): $(UBOOT_SRC)/configs/$(UBOOT_DEFCONFIG) |
| 196 | + $(UBOOT_MAKE) $(UBOOT_DEFCONFIG) |
| 197 | $(LINUX_SRC)/scripts/config --file $(UBOOT_CONFIG) --set-val CONFIG_BOOTDELAY 0 |
| 198 | $(LINUX_SRC)/scripts/config --file $(UBOOT_CONFIG) --set-str CONFIG_BOOTCOMMAND \ |
| 199 | "qfw load 0x40000000 0x50000000 ; booti 0x40000000 - $$\{fdtcontroladdr\}" |
| 200 | |
| 201 | $(UBOOT_OUT)/u-boot.bin: $(UBOOT_CONFIG) FORCE |
| 202 | + $(UBOOT_MAKE) |
| 203 | |
Andrew Walbran | 7cfab33 | 2021-11-09 14:35:55 +0000 | [diff] [blame] | 204 | .PHONY: bl33_clean |
| 205 | bl33_clean: |
| 206 | + $(UBOOT_MAKE) distclean |
Andrew Walbran | b8b247c | 2021-11-12 14:10:34 +0000 | [diff] [blame^] | 207 | |
| 208 | ## |
| 209 | ## TF-A |
| 210 | ## |
| 211 | TFA_SRC := $(ROOT_DIR)/trusted-firmware-a |
| 212 | TFA_OUT := $(OUT_DIR)/trusted-firmware-a |
| 213 | TFA_TOOLCHAIN ?= gcc-9.2 |
| 214 | TFA_VERBOSE ?= $(VERBOSE) |
| 215 | $(eval $(call define_toolchain,$(TFA_TOOLCHAIN),TFA_)) |
| 216 | TFA_MAKE := \ |
| 217 | PATH=$(TFA_TOOLCHAIN_BIN):$(PATH) \ |
| 218 | $(MAKE) \ |
| 219 | CROSS_COMPILE="$(TFA_TARGET)-" \ |
| 220 | PLAT=qemu \ |
| 221 | ENABLE_SVE_FOR_NS=1 \ |
| 222 | QEMU_USE_GIC_DRIVER=QEMU_GICV3 \ |
| 223 | ARM_LINUX_KERNEL_AS_BL33=1 \ |
| 224 | SPD=trusty \ |
| 225 | TRUSTY_SPD_WITH_GENERIC_SERVICES=1 \ |
| 226 | V=$(TFA_VERBOSE) \ |
| 227 | -C $(TFA_SRC) \ |
| 228 | BUILD_BASE=$(TFA_OUT) |
| 229 | |
| 230 | .PHONY: tfa |
| 231 | tfa: $(TFA_OUT)/qemu/release/bl1.bin $(TFA_OUT)/qemu/release/bl2.bin $(TFA_OUT)/qemu/release/bl31.bin |
| 232 | |
| 233 | $(TFA_OUT)/qemu/release/bl1.bin $(TFA_OUT)/qemu/release/bl2.bin $(TFA_OUT)/qemu/release/bl31.bin &: FORCE |
| 234 | + $(TFA_MAKE) all |
| 235 | |
| 236 | .PHONY: tfa_clean |
| 237 | tfa_clean: |
| 238 | rm -rf $(TFA_OUT) |
| 239 | |
| 240 | ## |
| 241 | ## Copy bootloader stages to BL_DIR |
| 242 | ## |
| 243 | |
| 244 | $(BL_DIR): |
| 245 | mkdir -p $@ |
| 246 | |
| 247 | $(BL1_BIN) $(BL2_BIN) $(BL31_BIN): $(BL_DIR)/bl%.bin: $(TFA_OUT)/qemu/release/bl%.bin | $(BL_DIR) |
| 248 | cp $< $@ |
| 249 | |
| 250 | # An empty BL32 is enough for us, it just needs to exist. |
| 251 | $(BL32_BIN): | $(BL_DIR) |
| 252 | touch $@ |
| 253 | |
| 254 | .PHONY: bl |
| 255 | bl: $(BL1_BIN) $(BL2_BIN) $(BL31_BIN) $(BL32_BIN) $(BL33_BIN) |
| 256 | |
| 257 | $(BL33_BIN): $(UBOOT_OUT)/u-boot.bin | $(BL_DIR) |
| 258 | cp $< $@ |
| 259 | |
| 260 | .PHONY: bl_clean |
| 261 | bl_clean: tfa_clean bl33_clean |
| 262 | rm -rf $(BL_DIR) |
Fuad Tabba | 42a3b29 | 2020-05-13 15:04:03 +0100 | [diff] [blame] | 263 | |
| 264 | ## |
David Brazdil | 54fb744 | 2020-07-27 09:54:56 +0000 | [diff] [blame] | 265 | ## kvm-unit-tests |
Fuad Tabba | 42a3b29 | 2020-05-13 15:04:03 +0100 | [diff] [blame] | 266 | ## |
Fuad Tabba | 42a3b29 | 2020-05-13 15:04:03 +0100 | [diff] [blame] | 267 | KUT_SRC := $(ROOT_DIR)/kvm-unit-tests |
| 268 | KUT_OUT := $(OUT_DIR)/kvm-unit-tests |
Fuad Tabba | cd90840 | 2021-02-09 17:18:15 +0000 | [diff] [blame] | 269 | KUT_DIST := $(DIST_DIR)/kvm-unit-tests |
David Brazdil | ef8506d | 2020-07-27 19:56:16 +0000 | [diff] [blame] | 270 | KUT_STAMP := $(KUT_OUT)/kvm-unit-tests.stamp |
Fuad Tabba | 62b2119 | 2020-05-13 11:57:26 +0100 | [diff] [blame] | 271 | |
David Brazdil | f5d3276 | 2021-08-23 08:40:18 +0000 | [diff] [blame] | 272 | ifneq ($(TOOLCHAIN_IS_LEGACY),1) |
| 273 | KUT_TOOLCHAIN ?= $(TOOLCHAIN) |
| 274 | else |
| 275 | KUT_TOOLCHAIN ?= gcc-9.2 |
| 276 | endif |
| 277 | $(eval $(call define_toolchain,$(KUT_TOOLCHAIN),KUT_)) |
| 278 | |
| 279 | ifeq ($(KUT_TOOLCHAIN_IS_LLVM),1) |
| 280 | KUT_CFLAGS += --target=$(KUT_TARGET) -fpic |
| 281 | endif |
Fuad Tabba | 42a3b29 | 2020-05-13 15:04:03 +0100 | [diff] [blame] | 282 | |
David Brazdil | 54fb744 | 2020-07-27 09:54:56 +0000 | [diff] [blame] | 283 | .PHONY: kvm-unit-tests |
David Brazdil | ef8506d | 2020-07-27 19:56:16 +0000 | [diff] [blame] | 284 | kvm-unit-tests $(KUT_STAMP): |
David Brazdil | 8f61ea5 | 2020-07-27 09:50:56 +0000 | [diff] [blame] | 285 | mkdir -p $(KUT_OUT) |
| 286 | cd $(KUT_OUT) && \ |
| 287 | $(KUT_SRC)/configure \ |
| 288 | --erratatxt=$(KUT_SRC)/errata.txt \ |
Fuad Tabba | 7f167f7 | 2020-09-17 15:26:45 +0100 | [diff] [blame] | 289 | --prefix=$(KUT_OUT) --arch=$(ARCH) \ |
David Brazdil | f5d3276 | 2021-08-23 08:40:18 +0000 | [diff] [blame] | 290 | --cc=$(KUT_CC) --ld=$(KUT_LD) \ |
| 291 | --objcopy=$(KUT_OBJCOPY) --objdump=$(KUT_OBJDUMP) |
| 292 | COMMON_CFLAGS="$(KUT_CFLAGS)" \ |
David Brazdil | e6c2643 | 2020-07-27 16:17:44 +0000 | [diff] [blame] | 293 | $(MAKE) -C $(KUT_OUT) standalone |
Fuad Tabba | cd90840 | 2021-02-09 17:18:15 +0000 | [diff] [blame] | 294 | $(call copy_to_dist, $(KUT_OUT)/tests, $(KUT_DIST)) |
David Brazdil | ef8506d | 2020-07-27 19:56:16 +0000 | [diff] [blame] | 295 | touch $(KUT_STAMP) |
Fuad Tabba | 42a3b29 | 2020-05-13 15:04:03 +0100 | [diff] [blame] | 296 | |
David Brazdil | 54fb744 | 2020-07-27 09:54:56 +0000 | [diff] [blame] | 297 | .PHONY: kvm-unit-tests_clean |
| 298 | kvm-unit-tests_clean: |
David Brazdil | ef8506d | 2020-07-27 19:56:16 +0000 | [diff] [blame] | 299 | - rm -f $(KUT_STAMP) |
David Brazdil | 8f61ea5 | 2020-07-27 09:50:56 +0000 | [diff] [blame] | 300 | - $(MAKE) -C $(KUT_OUT) clean |
Fuad Tabba | 42a3b29 | 2020-05-13 15:04:03 +0100 | [diff] [blame] | 301 | |
| 302 | |
| 303 | ## |
| 304 | ## Linux kernel |
| 305 | ## |
| 306 | LINUX_DEFCONFIG ?= defconfig |
| 307 | LINUX_VERBOSE ?= $(VERBOSE) |
Fuad Tabba | 6b9c08e | 2020-05-18 13:03:01 +0100 | [diff] [blame] | 308 | LINUX_SRC ?= $(ROOT_DIR)/linux |
Fuad Tabba | cd90840 | 2021-02-09 17:18:15 +0000 | [diff] [blame] | 309 | LINUX_VMLINUX = $(LINUX_OUT)/vmlinux |
David Brazdil | f5d3276 | 2021-08-23 08:40:18 +0000 | [diff] [blame] | 310 | LINUX_CONFIG := $(LINUX_OUT)/.config |
Fuad Tabba | cd90840 | 2021-02-09 17:18:15 +0000 | [diff] [blame] | 311 | LINUX_DIST_FILES = $(LINUX_CONFIG) $(LINUX_VMLINUX) $(KERNEL_IMAGE) |
David Brazdil | 999861a | 2021-10-04 18:41:32 +0100 | [diff] [blame] | 312 | LINUX_LSMOD_TXT := $(LINUX_OUT)/lsmod.txt |
Fuad Tabba | 42a3b29 | 2020-05-13 15:04:03 +0100 | [diff] [blame] | 313 | |
David Brazdil | f5d3276 | 2021-08-23 08:40:18 +0000 | [diff] [blame] | 314 | LINUX_TOOLCHAIN ?= $(TOOLCHAIN) |
| 315 | $(eval $(call define_toolchain,$(LINUX_TOOLCHAIN),LINUX_)) |
| 316 | |
| 317 | ifeq ($(LINUX_TOOLCHAIN_IS_LLVM),1) |
| 318 | LINUX_EXTRA += LLVM=1 LLVM_IAS=1 |
| 319 | endif |
| 320 | |
Fuad Tabba | 6b9c08e | 2020-05-18 13:03:01 +0100 | [diff] [blame] | 321 | LINUX_MAKE := \ |
Fuad Tabba | 6761847 | 2021-04-27 11:56:35 +0100 | [diff] [blame] | 322 | PATH=$(LINUX_TOOLCHAIN_BIN):$(PATH) \ |
Fuad Tabba | 7f167f7 | 2020-09-17 15:26:45 +0100 | [diff] [blame] | 323 | ARCH=$(ARCH) \ |
Fuad Tabba | 6761847 | 2021-04-27 11:56:35 +0100 | [diff] [blame] | 324 | CROSS_COMPILE="$(LINUX_TARGET)-" \ |
Fuad Tabba | 6b9c08e | 2020-05-18 13:03:01 +0100 | [diff] [blame] | 325 | $(MAKE) \ |
Fuad Tabba | 6761847 | 2021-04-27 11:56:35 +0100 | [diff] [blame] | 326 | $(LINUX_EXTRA) \ |
David Brazdil | f5d3276 | 2021-08-23 08:40:18 +0000 | [diff] [blame] | 327 | CC=$(LINUX_CC) \ |
| 328 | LD=$(LINUX_LD) \ |
| 329 | OBJCOPY=$(LINUX_OBJCOPY) \ |
| 330 | OBJDUMP=$(LINUX_OBJDUMP) \ |
Fuad Tabba | 62b2119 | 2020-05-13 11:57:26 +0100 | [diff] [blame] | 331 | -C $(LINUX_SRC) \ |
| 332 | V=$(LINUX_VERBOSE) \ |
| 333 | O=$(LINUX_OUT) |
Fuad Tabba | 42a3b29 | 2020-05-13 15:04:03 +0100 | [diff] [blame] | 334 | |
David Brazdil | 999861a | 2021-10-04 18:41:32 +0100 | [diff] [blame] | 335 | LINUX_MODULES := \ |
| 336 | TEST_PRINTF |
| 337 | |
David Brazdil | ef8506d | 2020-07-27 19:56:16 +0000 | [diff] [blame] | 338 | .PHONY: linux_defconfig |
| 339 | linux_defconfig $(LINUX_CONFIG): |
Fuad Tabba | 6b9c08e | 2020-05-18 13:03:01 +0100 | [diff] [blame] | 340 | + $(LINUX_MAKE) $(LINUX_DEFCONFIG) |
David Brazdil | 999861a | 2021-10-04 18:41:32 +0100 | [diff] [blame] | 341 | # Disable all modules, then selectively enable those in LINUX_MODULES. |
| 342 | @ echo > $(LINUX_LSMOD_TXT) |
| 343 | + $(LINUX_MAKE) LSMOD=$(LINUX_LSMOD_TXT) localmodconfig |
| 344 | $(LINUX_SRC)/scripts/config --file $(LINUX_CONFIG) $(addprefix -m CONFIG_,$(LINUX_MODULES)) |
David Brazdil | ef8506d | 2020-07-27 19:56:16 +0000 | [diff] [blame] | 345 | |
David Brazdil | a7e3566 | 2020-12-03 09:40:38 +0000 | [diff] [blame] | 346 | .PHONY: linux_menuconfig |
| 347 | linux_menuconfig: $(LINUX_CONFIG) |
| 348 | + $(LINUX_MAKE) menuconfig |
| 349 | |
David Brazdil | ef8506d | 2020-07-27 19:56:16 +0000 | [diff] [blame] | 350 | .PHONY: linux |
| 351 | linux: $(LINUX_CONFIG) |
Fuad Tabba | 990105b | 2020-05-12 15:39:52 +0100 | [diff] [blame] | 352 | + $(LINUX_MAKE) |
Fuad Tabba | cd90840 | 2021-02-09 17:18:15 +0000 | [diff] [blame] | 353 | $(call copy_to_dist, $(LINUX_DIST_FILES), $(LINUX_DIST)) |
Fuad Tabba | 42a3b29 | 2020-05-13 15:04:03 +0100 | [diff] [blame] | 354 | |
Fuad Tabba | 6b9c08e | 2020-05-18 13:03:01 +0100 | [diff] [blame] | 355 | .PHONY: linux_image |
David Brazdil | 880a1be | 2021-09-30 13:13:15 +0100 | [diff] [blame] | 356 | linux_image $(LINUX_OUT_IMAGE): $(LINUX_CONFIG) |
David Brazdil | ef8506d | 2020-07-27 19:56:16 +0000 | [diff] [blame] | 357 | + $(LINUX_MAKE) Image.gz |
Fuad Tabba | cd90840 | 2021-02-09 17:18:15 +0000 | [diff] [blame] | 358 | $(call copy_to_dist, $(LINUX_DIST_FILES), $(LINUX_DIST)) |
David Brazdil | ef8506d | 2020-07-27 19:56:16 +0000 | [diff] [blame] | 359 | |
David Brazdil | 880a1be | 2021-09-30 13:13:15 +0100 | [diff] [blame] | 360 | .PHONY: linux_modules |
| 361 | linux_modules $(LINUX_OUT_MODULES_DEP): $(LINUX_OUT_IMAGE) |
| 362 | @ rm -rf $(LINUX_OUT_MODULES) |
| 363 | + $(LINUX_MAKE) modules |
| 364 | + $(LINUX_MAKE) INSTALL_MOD_PATH=$(LINUX_OUT_MODULES) modules_install |
| 365 | @ find $(LINUX_OUT_MODULES) -type f | sort | \ |
| 366 | xargs sha1sum > $(LINUX_OUT_MODULES_DEP).tmp |
| 367 | @ cmp $(LINUX_OUT_MODULES_DEP).tmp $(LINUX_OUT_MODULES_DEP) || \ |
| 368 | mv $(LINUX_OUT_MODULES_DEP).tmp $(LINUX_OUT_MODULES_DEP) |
| 369 | |
Fuad Tabba | 42a3b29 | 2020-05-13 15:04:03 +0100 | [diff] [blame] | 370 | .PHONY: linux_clean |
| 371 | linux_clean: |
Fuad Tabba | 42a3b29 | 2020-05-13 15:04:03 +0100 | [diff] [blame] | 372 | + $(LINUX_MAKE) mrproper |
| 373 | |
| 374 | |
| 375 | ## |
David Brazdil | a8f60f1 | 2021-10-04 18:41:47 +0100 | [diff] [blame] | 376 | ## Linux kselftest |
| 377 | ## |
| 378 | KSFT_VERBOSE ?= $(VERBOSE) |
| 379 | KSFT_SRC ?= $(LINUX_SRC) |
| 380 | KSFT_SRC_STAMP ?= $(KSFT_OUT)/ksefltest_src.stamp |
| 381 | KSFT_OUT ?= $(OUT_DIR)/kselftest |
| 382 | KSFT_OUT_CONFIG ?= $(KSFT_OUT)/.config |
| 383 | KSFT_INSTALL_DIR ?= $(KSFT_OUT)/tools/testing/selftests/kselftest_install |
| 384 | KSFT_STAMP ?= $(KSFT_INSTALL_DIR)/kselftest-list.txt |
| 385 | |
| 386 | KSFT_TESTS := \ |
| 387 | lib:printf.sh \ |
| 388 | kvm:kvm_create_max_vcpus \ |
| 389 | kvm:set_memory_region_test \ |
| 390 | kvm:steal_time |
| 391 | |
| 392 | ifneq ($(TOOLCHAIN_IS_LLVM),1) |
| 393 | KSFT_TOOLCHAIN ?= $(TOOLCHAIN) |
| 394 | else |
| 395 | KSFT_TOOLCHAIN ?= gcc-9.2 |
| 396 | endif |
| 397 | $(eval $(call define_toolchain,$(KSFT_TOOLCHAIN),KSFT_)) |
| 398 | |
| 399 | KSFT_MAKE := \ |
| 400 | PATH=$(KSFT_TOOLCHAIN_BIN):$(PATH) \ |
| 401 | ARCH=$(ARCH) \ |
| 402 | CROSS_COMPILE="$(KSFT_TARGET)-" \ |
| 403 | $(MAKE) \ |
| 404 | -C $(KSFT_OUT) \ |
| 405 | V=$(KSFT_VERBOSE) |
| 406 | |
| 407 | KSFT_MAKE_TARGETS := $(sort $(foreach t,$(KSFT_TESTS),$(firstword $(subst :, ,$(t))))) |
| 408 | |
| 409 | # Copy the source to another folder because 'kselftest-install' clobbers it. |
| 410 | # Stamp is touched if any files (not directories) were synced. |
| 411 | $(KSFT_SRC_STAMP): FORCE |
| 412 | @ mkdir -p $(KSFT_OUT) $(@D) |
| 413 | @ LIST="$$(rsync -a --info=name $(KSFT_SRC)/ $(KSFT_OUT) | grep -vE '/$$')"; \ |
| 414 | [ -f $@ -a -z "$$LIST" ] || touch $@ |
| 415 | |
| 416 | .PHONY: kselftest |
| 417 | kselftest $(KSFT_STAMP): $(KSFT_SRC_STAMP) $(LINUX_CONFIG) |
| 418 | @ cp $(LINUX_CONFIG) $(KSFT_OUT_CONFIG) |
| 419 | + $(KSFT_MAKE) olddefconfig prepare |
| 420 | + $(KSFT_MAKE) TARGETS="$(KSFT_MAKE_TARGETS)" kselftest-install |
| 421 | |
| 422 | .PHONY: kselftest_clean |
| 423 | kselftest_clean: |
| 424 | @ rm -rf $(KSFT_OUT) |
| 425 | |
| 426 | |
| 427 | ## |
Fuad Tabba | 62b2119 | 2020-05-13 11:57:26 +0100 | [diff] [blame] | 428 | ## Generating/Updating prebuilts |
| 429 | ## |
| 430 | |
Pierre-Clément Tosi | 58b789a | 2021-09-27 13:01:17 +0200 | [diff] [blame] | 431 | PREBUILTS_CROSVM_EXT4 := prebuilts/linux-aarch64/images/crosvm.ext4 |
David Brazdil | e3446db | 2021-02-02 20:58:49 +0000 | [diff] [blame] | 432 | PREBUILTS_ROOTFS_EXT4 := prebuilts/linux-aarch64/images/rootfs.ext4 |
| 433 | PREBUILTS_QEMU_ROM := prebuilts/linux-aarch64/images/efi-virtio.rom |
| 434 | PREBUILTS_QEMU_BIN := prebuilts/linux-x86/qemu |
| 435 | |
Pierre-Clément Tosi | 58b789a | 2021-09-27 13:01:17 +0200 | [diff] [blame] | 436 | CUSTOM_CROSVM_EXT4 := $(OUT_DIR)/images/crosvm.ext4 |
| 437 | |
Pierre-Clément Tosi | a4c90ba | 2021-09-22 14:28:04 +0200 | [diff] [blame] | 438 | ifeq ($(CROSVM_TAR_GZ),) |
Pierre-Clément Tosi | 58b789a | 2021-09-27 13:01:17 +0200 | [diff] [blame] | 439 | CROSVM_EXT4 := $(PREBUILTS_CROSVM_EXT4) |
Pierre-Clément Tosi | a4c90ba | 2021-09-22 14:28:04 +0200 | [diff] [blame] | 440 | else |
Pierre-Clément Tosi | 58b789a | 2021-09-27 13:01:17 +0200 | [diff] [blame] | 441 | CROSVM_EXT4 := $(CUSTOM_CROSVM_EXT4) |
Pierre-Clément Tosi | a4c90ba | 2021-09-22 14:28:04 +0200 | [diff] [blame] | 442 | endif |
Pierre-Clément Tosi | 609555c | 2021-09-22 14:13:20 +0200 | [diff] [blame] | 443 | |
Fuad Tabba | 7f167f7 | 2020-09-17 15:26:45 +0100 | [diff] [blame] | 444 | .PHONY:update-prebuilts |
Fuad Tabba | 62b2119 | 2020-05-13 11:57:26 +0100 | [diff] [blame] | 445 | update-prebuilts: \ |
David Brazdil | e3446db | 2021-02-02 20:58:49 +0000 | [diff] [blame] | 446 | $(PREBUILTS_ROOTFS_EXT4) \ |
Pierre-Clément Tosi | 609555c | 2021-09-22 14:13:20 +0200 | [diff] [blame] | 447 | update-prebuilts-crosvm \ |
David Brazdil | e3446db | 2021-02-02 20:58:49 +0000 | [diff] [blame] | 448 | $(PREBUILTS_QEMU_ROM) \ |
| 449 | $(PREBUILTS_QEMU_BIN) |
Fuad Tabba | 62b2119 | 2020-05-13 11:57:26 +0100 | [diff] [blame] | 450 | |
David Brazdil | e3446db | 2021-02-02 20:58:49 +0000 | [diff] [blame] | 451 | $(PREBUILTS_ROOTFS_EXT4): buildroot |
David Brazdil | 4f0603f | 2021-02-02 16:18:18 +0000 | [diff] [blame] | 452 | mkdir -p $(shell dirname $@) |
Fuad Tabba | 62b2119 | 2020-05-13 11:57:26 +0100 | [diff] [blame] | 453 | cp $(BR_OUT)/images/rootfs.ext4 $@ |
David Brazdil | 4f0603f | 2021-02-02 16:18:18 +0000 | [diff] [blame] | 454 | |
David Brazdil | e3446db | 2021-02-02 20:58:49 +0000 | [diff] [blame] | 455 | $(PREBUILTS_QEMU_ROM): buildroot |
David Brazdil | 4f0603f | 2021-02-02 16:18:18 +0000 | [diff] [blame] | 456 | mkdir -p $(shell dirname $@) |
Fuad Tabba | 62b2119 | 2020-05-13 11:57:26 +0100 | [diff] [blame] | 457 | cp $(BR_OUT)/per-package/host-qemu/host/share/qemu/efi-virtio.rom $@ |
| 458 | |
David Brazdil | 4f0603f | 2021-02-02 16:18:18 +0000 | [diff] [blame] | 459 | CF_DOWNLOAD_AOSP_SH := $(ROOT_DIR)/build/cuttlefish/download-aosp.sh |
Pierre-Clément Tosi | 609555c | 2021-09-22 14:13:20 +0200 | [diff] [blame] | 460 | |
| 461 | # A PHONY target is necessary for allowing the user to update the archive |
| 462 | # because, as we are downloading it from a remote server, make dependencies are |
| 463 | # unable to express the local-->remote dependency: |
| 464 | .PHONY: update-prebuilts-crosvm |
| 465 | update-prebuilts-crosvm $(PREBUILTS_CROSVM_TAR_GZ): |
| 466 | @rm -f $(PREBUILTS_CROSVM_TAR_GZ) # else, wget will create "$@.1" |
| 467 | cd $(dir $(PREBUILTS_CROSVM_TAR_GZ)) && $(CF_DOWNLOAD_AOSP_SH) -XCa arm64 |
| 468 | @touch -c $(PREBUILTS_CROSVM_TAR_GZ) # wget doesn't set timestamp to now |
| 469 | |
David Brazdil | 4f0603f | 2021-02-02 16:18:18 +0000 | [diff] [blame] | 470 | CROSVM_IMG_SIZE_MB := 1024 |
| 471 | |
Pierre-Clément Tosi | 58b789a | 2021-09-27 13:01:17 +0200 | [diff] [blame] | 472 | $(CUSTOM_CROSVM_EXT4): TMP_DIR := $(shell mktemp -d) |
| 473 | $(CUSTOM_CROSVM_EXT4): $(CROSVM_TAR_GZ) |
Pierre-Clément Tosi | 609555c | 2021-09-22 14:13:20 +0200 | [diff] [blame] | 474 | mkdir -p $(@D) |
| 475 | cd $(TMP_DIR) && tar xzvf $(abspath $<) |
David Brazdil | 4f0603f | 2021-02-02 16:18:18 +0000 | [diff] [blame] | 476 | dd if=/dev/zero of=$@.tmp bs=1M count=$(CROSVM_IMG_SIZE_MB) |
| 477 | mkfs.ext4 -d $(TMP_DIR) $@.tmp |
| 478 | rm -rf $(TMP_DIR) |
| 479 | mv $@.tmp $@ |
| 480 | |
Fuad Tabba | ce13552 | 2020-08-26 10:15:47 +0100 | [diff] [blame] | 481 | # The qemu binary |
David Brazdil | e3446db | 2021-02-02 20:58:49 +0000 | [diff] [blame] | 482 | .PHONY:$(PREBUILTS_QEMU_BIN) |
| 483 | $(PREBUILTS_QEMU_BIN): |
Fuad Tabba | 62b2119 | 2020-05-13 11:57:26 +0100 | [diff] [blame] | 484 | - rm -rf $@ |
Fuad Tabba | 7f167f7 | 2020-09-17 15:26:45 +0100 | [diff] [blame] | 485 | ${SCRIPTS_DIR}/aarch64/build_qemu.sh $(OUT_DIR)/qemu ${TOOLCHAIN_BIN} |
Fuad Tabba | 62b2119 | 2020-05-13 11:57:26 +0100 | [diff] [blame] | 486 | mkdir -p $@/bin |
Fuad Tabba | ce13552 | 2020-08-26 10:15:47 +0100 | [diff] [blame] | 487 | cp $(OUT_DIR)/qemu/qemu-system-aarch64 $@/bin |
Fuad Tabba | 62b2119 | 2020-05-13 11:57:26 +0100 | [diff] [blame] | 488 | |
Fuad Tabba | 62b2119 | 2020-05-13 11:57:26 +0100 | [diff] [blame] | 489 | ## |
David Brazdil | ef8506d | 2020-07-27 19:56:16 +0000 | [diff] [blame] | 490 | ## Run tests |
Fuad Tabba | 62b2119 | 2020-05-13 11:57:26 +0100 | [diff] [blame] | 491 | ## |
| 492 | |
Pierre-Clément Tosi | d181306 | 2021-07-30 15:50:41 +0000 | [diff] [blame] | 493 | KVM_MODES := vhe nvhe pkvm |
David Brazdil | b2162fe | 2021-10-04 18:52:09 +0100 | [diff] [blame] | 494 | |
Pierre-Clément Tosi | d181306 | 2021-07-30 15:50:41 +0000 | [diff] [blame] | 495 | hyphensuffix = $(lastword $(subst -, ,$(1))) |
David Brazdil | b2162fe | 2021-10-04 18:52:09 +0100 | [diff] [blame] | 496 | space := $(subst ,, ) |
| 497 | # Like wordlist but takes negative upper bounds (-2 means remove last two words) |
| 498 | revwordlist = $(wordlist $(1),$(shell echo '(($(2) - 1 + $(words $(3))) % $(words $(3))) + 1' | bc),$(3)) |
| 499 | hyphenlist = $(subst $(space),-,$(call revwordlist,$(1),$(2),$(subst -, ,$(3)))) |
Pierre-Clément Tosi | d181306 | 2021-07-30 15:50:41 +0000 | [diff] [blame] | 500 | |
Pierre-Clément Tosi | 253cd13 | 2021-08-02 08:49:39 +0000 | [diff] [blame] | 501 | RUN_TEST_SH := $(SCRIPTS_DIR)/kvm-unit-tests/run_test.sh |
| 502 | RUN_TEST = $(RUN_TEST_SH) \ |
| 503 | -d $@ \ |
| 504 | -M $(call hyphensuffix,$@) \ |
| 505 | -k "$(KERNEL_IMAGE)" \ |
Pierre-Clément Tosi | 253cd13 | 2021-08-02 08:49:39 +0000 | [diff] [blame] | 506 | $(RUN_TEST_ARGS) "$(RUN_TEST_HOST_SH)" \ |
David Brazdil | 880a1be | 2021-09-30 13:13:15 +0100 | [diff] [blame] | 507 | -- \ |
| 508 | -D modules:${KERNEL_MODULES}/lib/modules \ |
| 509 | $(RUN_TEST_QEMU_ARGS) |
Pierre-Clément Tosi | 253cd13 | 2021-08-02 08:49:39 +0000 | [diff] [blame] | 510 | |
Pierre-Clément Tosi | 4768c6c | 2021-08-02 09:53:29 +0000 | [diff] [blame] | 511 | ifeq ($(VERBOSE),1) |
| 512 | RUN_TEST_ARGS += -v |
| 513 | endif |
| 514 | |
| 515 | ifneq ($(QUIET),0) |
| 516 | RUN_TEST_ARGS += -o "$(RUN_TEST_LOG_DIR)/$@.log" |
| 517 | endif |
| 518 | |
| 519 | ifeq ($(GDB),1) |
| 520 | # RUN_TEST_SH defaults to no-timeout when -G is passed but -t forces one: |
| 521 | RUN_TEST_ARGS += -G |
| 522 | else |
| 523 | # Without -G, RUN_TEST_SH defaults to a non-zero timeout duration. |
| 524 | # RUN_TEST_TIMEOUT should be use if a specific value is wanted (see 'man timeout'). |
| 525 | # In particular, RUN_TEST_TIMEOUT=0 prevents the test from timing out. |
| 526 | RUN_TEST_ARGS += $(if $(RUN_TEST_TIMEOUT),-t ,)$(RUN_TEST_TIMEOUT) |
| 527 | endif |
| 528 | |
David Brazdil | ef8506d | 2020-07-27 19:56:16 +0000 | [diff] [blame] | 529 | # Root test targets. Dynamically generated per-test targets |
| 530 | # will add themselves as dependencies of these. |
| 531 | .PHONY: test test-list |
| 532 | test: |
| 533 | test-list: |
Fuad Tabba | 62b2119 | 2020-05-13 11:57:26 +0100 | [diff] [blame] | 534 | |
David Brazdil | ef8506d | 2020-07-27 19:56:16 +0000 | [diff] [blame] | 535 | # |
| 536 | # kvm-unit-tests |
| 537 | # |
| 538 | |
Pierre-Clément Tosi | 253cd13 | 2021-08-02 08:49:39 +0000 | [diff] [blame] | 539 | KUT_RUN_TEST = $(RUN_TEST_SH) |
David Brazdil | ef8506d | 2020-07-27 19:56:16 +0000 | [diff] [blame] | 540 | KUT_GEN_MAKEFILE := $(SCRIPTS_DIR)/kvm-unit-tests/gen_makefile.sh |
| 541 | KUT_MAKEFILE := $(OUT_DIR)/Makefile.kvm-unit-tests |
| 542 | KUT_TEST_DIR := $(KUT_OUT)/tests |
Fuad Tabba | cd90840 | 2021-02-09 17:18:15 +0000 | [diff] [blame] | 543 | KUT_LOG_DIR := $(DIST_DIR)/logs/kvm-unit-tests/ |
Fuad Tabba | 62b2119 | 2020-05-13 11:57:26 +0100 | [diff] [blame] | 544 | |
Fuad Tabba | 42a3b29 | 2020-05-13 15:04:03 +0100 | [diff] [blame] | 545 | # Exclude tests that require user interaction or are known to fail. |
David Brazdil | ef8506d | 2020-07-27 19:56:16 +0000 | [diff] [blame] | 546 | KUT_EXCLUDE := (.+migrat.+)|(gicv2-.+)|(pmu-event-introspection)|(micro-bench) |
Fuad Tabba | 42a3b29 | 2020-05-13 15:04:03 +0100 | [diff] [blame] | 547 | |
David Brazdil | ef8506d | 2020-07-27 19:56:16 +0000 | [diff] [blame] | 548 | # Generate a Makefile with targets per test and configuration. |
| 549 | # Pass in variable/target names from this Makefile that the |
| 550 | # generated Makefile will refer to. |
| 551 | $(KUT_MAKEFILE): $(SELF) $(KUT_GEN_MAKEFILE) $(KUT_STAMP) |
| 552 | @ mkdir -p $(shell dirname $@) |
| 553 | @ $(KUT_GEN_MAKEFILE) \ |
| 554 | $(KUT_TEST_DIR) "$(KUT_EXCLUDE)" \ |
| 555 | KERNEL_IMAGE KUT_LOG_DIR test test-list \ |
| 556 | > $@.tmp |
| 557 | @ mv $@.tmp $@ |
| 558 | include $(KUT_MAKEFILE) |
David Brazdil | 19d0b7a | 2021-02-02 18:15:44 +0000 | [diff] [blame] | 559 | |
| 560 | # |
David Brazdil | 490370a | 2021-03-10 22:55:02 +0000 | [diff] [blame] | 561 | # Basic boot tests in the various arm64 KVM modes |
| 562 | # |
| 563 | |
Pierre-Clément Tosi | d181306 | 2021-07-30 15:50:41 +0000 | [diff] [blame] | 564 | BOOT_TESTS := $(addprefix test-boot-,$(KVM_MODES)) |
David Brazdil | 490370a | 2021-03-10 22:55:02 +0000 | [diff] [blame] | 565 | |
David Brazdil | 490370a | 2021-03-10 22:55:02 +0000 | [diff] [blame] | 566 | .PHONY: test-boot |
| 567 | test-boot: $(BOOT_TESTS) |
| 568 | |
Pierre-Clément Tosi | 63d4087 | 2021-07-30 16:23:48 +0000 | [diff] [blame] | 569 | TEST_LISTS += test-list-boot |
| 570 | test-list-boot: LISTED_TESTS = $(BOOT_TESTS) |
David Brazdil | 490370a | 2021-03-10 22:55:02 +0000 | [diff] [blame] | 571 | |
Pierre-Clément Tosi | 4843686 | 2021-07-30 16:34:25 +0000 | [diff] [blame] | 572 | TESTS += $(BOOT_TESTS) |
Pierre-Clément Tosi | 253cd13 | 2021-08-02 08:49:39 +0000 | [diff] [blame] | 573 | $(BOOT_TESTS): RUN_TEST_LOG_DIR = $(DIST_DIR)/logs/boot |
| 574 | $(BOOT_TESTS): RUN_TEST_HOST_SH = $(SCRIPTS_DIR)/aarch64/test_boot.sh |
| 575 | $(BOOT_TESTS): RUN_TEST_QEMU_ARGS = -a "boot_test_mode=$(call hyphensuffix,$@)" |
David Brazdil | 490370a | 2021-03-10 22:55:02 +0000 | [diff] [blame] | 576 | |
| 577 | # |
David Brazdil | 19d0b7a | 2021-02-02 18:15:44 +0000 | [diff] [blame] | 578 | # CrosVM Hello World test |
| 579 | # |
| 580 | |
Pierre-Clément Tosi | d181306 | 2021-07-30 15:50:41 +0000 | [diff] [blame] | 581 | CROSVM_HELLOWORLD_TESTS := $(addprefix test-crosvm-helloworld-,$(KVM_MODES)) |
David Brazdil | 19d0b7a | 2021-02-02 18:15:44 +0000 | [diff] [blame] | 582 | |
Pierre-Clément Tosi | aa7c390 | 2021-09-22 14:46:06 +0200 | [diff] [blame] | 583 | VM_IMAGE ?= $(KERNEL_IMAGE) |
| 584 | |
David Brazdil | 19d0b7a | 2021-02-02 18:15:44 +0000 | [diff] [blame] | 585 | .PHONY: test-crosvm-helloworld |
| 586 | test-crosvm-helloworld: $(CROSVM_HELLOWORLD_TESTS) |
| 587 | |
Pierre-Clément Tosi | 63d4087 | 2021-07-30 16:23:48 +0000 | [diff] [blame] | 588 | TEST_LISTS += test-list-crosvm-helloworld |
| 589 | test-list-crosvm-helloworld: LISTED_TESTS = $(CROSVM_HELLOWORLD_TESTS) |
David Brazdil | 19d0b7a | 2021-02-02 18:15:44 +0000 | [diff] [blame] | 590 | |
Pierre-Clément Tosi | 4843686 | 2021-07-30 16:34:25 +0000 | [diff] [blame] | 591 | TESTS += $(CROSVM_HELLOWORLD_TESTS) |
Pierre-Clément Tosi | 609555c | 2021-09-22 14:13:20 +0200 | [diff] [blame] | 592 | $(CROSVM_HELLOWORLD_TESTS): $(CROSVM_EXT4) |
Pierre-Clément Tosi | 253cd13 | 2021-08-02 08:49:39 +0000 | [diff] [blame] | 593 | $(CROSVM_HELLOWORLD_TESTS): RUN_TEST_LOG_DIR = $(DIST_DIR)/logs/crosvm/helloworld |
| 594 | $(CROSVM_HELLOWORLD_TESTS): RUN_TEST_HOST_SH = $(SCRIPTS_DIR)/crosvm/helloworld/host.sh |
Pierre-Clément Tosi | 253cd13 | 2021-08-02 08:49:39 +0000 | [diff] [blame] | 595 | $(CROSVM_HELLOWORLD_TESTS): RUN_TEST_QEMU_ARGS = \ |
| 596 | -s 4 \ |
| 597 | -R $(SCRIPTS_DIR)/crosvm/helloworld/guest.sh \ |
Pierre-Clément Tosi | aa7c390 | 2021-09-22 14:46:06 +0200 | [diff] [blame] | 598 | -R $(VM_IMAGE) \ |
Pierre-Clément Tosi | 253cd13 | 2021-08-02 08:49:39 +0000 | [diff] [blame] | 599 | -R $(PREBUILTS_ROOTFS_EXT4) \ |
Pierre-Clément Tosi | 609555c | 2021-09-22 14:13:20 +0200 | [diff] [blame] | 600 | -R $(CROSVM_EXT4) |
Pierre-Clément Tosi | 4768c6c | 2021-08-02 09:53:29 +0000 | [diff] [blame] | 601 | $(CROSVM_HELLOWORLD_TESTS): RUN_TEST_TIMEOUT := 300s |
Pierre-Clément Tosi | 63d4087 | 2021-07-30 16:23:48 +0000 | [diff] [blame] | 602 | |
David Brazdil | b2162fe | 2021-10-04 18:52:09 +0100 | [diff] [blame] | 603 | # |
| 604 | # Linux kselftests |
| 605 | # |
| 606 | |
| 607 | KSFT_TEST_TARGETS := $(foreach t,$(KSFT_TESTS),$(foreach m,$(KVM_MODES),\ |
| 608 | test-ksft-$(subst :,-,$(t))-$(m))) |
| 609 | |
| 610 | .PHONY: test-ksft |
| 611 | test-ksft: $(KSFT_TEST_TARGETS) |
| 612 | |
| 613 | |
| 614 | TEST_LISTS += test-list-ksft |
| 615 | test-list-ksft: LISTED_TESTS = $(KSFT_TEST_TARGETS) |
| 616 | |
| 617 | TESTS += $(KSFT_TEST_TARGETS) |
| 618 | $(KSFT_TEST_TARGETS): $(KSFT_STAMP) |
| 619 | $(KSFT_TEST_TARGETS): RUN_TEST_LOG_DIR = $(DIST_DIR)/logs/kselftest |
| 620 | $(KSFT_TEST_TARGETS): RUN_TEST_HOST_SH = $(SCRIPTS_DIR)/kselftest/host.sh |
| 621 | $(KSFT_TEST_TARGETS): RUN_TEST_QEMU_ARGS = \ |
| 622 | -D kselftest:$(KSFT_INSTALL_DIR) \ |
| 623 | -a 'ksft=$(call hyphenlist,3,3,$@):$(call hyphenlist,4,-1,$@)' |
| 624 | |
Pierre-Clément Tosi | 4843686 | 2021-07-30 16:34:25 +0000 | [diff] [blame] | 625 | .PHONY test: $(TESTS) |
David Brazdil | 880a1be | 2021-09-30 13:13:15 +0100 | [diff] [blame] | 626 | $(TESTS): $(KERNEL_IMAGE) $(KERNEL_MODULES_DEP) |
Pierre-Clément Tosi | 253cd13 | 2021-08-02 08:49:39 +0000 | [diff] [blame] | 627 | @ $(RUN_TEST) |
Pierre-Clément Tosi | 63d4087 | 2021-07-30 16:23:48 +0000 | [diff] [blame] | 628 | .PHONY test-list: $(TEST_LISTS) |
| 629 | $(TEST_LISTS): |
| 630 | @ for x in $(LISTED_TESTS); do echo $$x; done |