Makefile: Introduce KVM_MODES for generic rules

Exploit the <prefix>-<mode> target name pattern to synthesize the
existing rule triplets for test-crosvm-helloworld-{vhe,nvhe,pkvm} and
test-boot-{vhe,nvhe,pkvm} into two generic rules instead of 6.

Bug: 195395681
Test: make test
Change-Id: I2bc1d716ba7cbe98b9bb57465301b92381c1de20
diff --git a/Makefile b/Makefile
index d3dd945..3863926 100644
--- a/Makefile
+++ b/Makefile
@@ -343,6 +343,9 @@
 ## Run tests
 ##
 
+KVM_MODES := vhe nvhe pkvm
+hyphensuffix = $(lastword $(subst -, ,$(1)))
+
 # Root test targets. Dynamically generated per-test targets
 # will add themselves as dependencies of these.
 .PHONY: test test-list
@@ -380,7 +383,7 @@
 
 BOOT_TEST_SCRIPT_DIR := $(SCRIPTS_DIR)/aarch64/
 BOOT_TEST_LOG_DIR := $(DIST_DIR)/logs/boot/
-BOOT_TESTS := test-boot-vhe test-boot-nvhe test-boot-pkvm
+BOOT_TESTS := $(addprefix test-boot-,$(KVM_MODES))
 
 define gen_boot_test
 	$(KUT_RUN_TEST) -d $(1) -M $(2) \
@@ -400,17 +403,9 @@
 test-list-boot:
 	@ for x in $(BOOT_TESTS); do echo $x; done
 
-.PHONY: test-boot-vhe
-test-boot-vhe: $(KERNEL_IMAGE)
-	@ $(call gen_boot_test,$@,vhe)
-
-.PHONY: test-boot-nvhe
-test-boot-nvhe: $(KERNEL_IMAGE)
-	@ $(call gen_boot_test,$@,nvhe)
-
-.PHONY: test-boot-pkvm
-test-boot-pkvm: $(KERNEL_IMAGE)
-	@ $(call gen_boot_test,$@,pkvm)
+.PHONY: $(BOOT_TESTS)
+$(BOOT_TESTS): $(KERNEL_IMAGE)
+	@ $(call gen_boot_test,$@,$(call hyphensuffix,$@))
 
 #
 # CrosVM Hello World test
@@ -418,9 +413,7 @@
 
 CROSVM_HELLOWORLD_SCRIPT_DIR := $(SCRIPTS_DIR)/crosvm/helloworld/
 CROSVM_HELLOWORLD_LOG_DIR := $(DIST_DIR)/logs/crosvm/helloworld/
-CROSVM_HELLOWORLD_TESTS := test-crosvm-helloworld-vhe \
-			   test-crosvm-helloworld-nvhe \
-			   test-crosvm-helloworld-pkvm
+CROSVM_HELLOWORLD_TESTS := $(addprefix test-crosvm-helloworld-,$(KVM_MODES))
 
 define gen_crosvm_helloworld_test
 	$(KUT_RUN_TEST) -d $(1) -M $(2) -t 300s \
@@ -445,14 +438,6 @@
 test-list-crosvm-helloworld:
 	@ for x in $(CROSVM_HELLOWORLD_TESTS); do echo $x; done
 
-.PHONY: test-crosvm-helloworld-vhe
-test-crosvm-helloworld-vhe: $(KERNEL_IMAGE) $(UBOOT_BIN)
-	@ $(call gen_crosvm_helloworld_test,$@,vhe)
-
-.PHONY: test-crosvm-helloworld-nvhe
-test-crosvm-helloworld-nvhe: $(KERNEL_IMAGE) $(UBOOT_BIN)
-	@ $(call gen_crosvm_helloworld_test,$@,nvhe)
-
-.PHONY: test-crosvm-helloworld-pkvm
-test-crosvm-helloworld-pkvm: $(KERNEL_IMAGE) $(UBOOT_BIN)
-	@ $(call gen_crosvm_helloworld_test,$@,pkvm)
+.PHONY: $(CROSVM_HELLOWORLD_TESTS)
+$(CROSVM_HELLOWORLD_TESTS): $(KERNEL_IMAGE) $(UBOOT_BIN)
+	@ $(call gen_crosvm_helloworld_test,$@,$(call hyphensuffix,$@))