Makefile: Support VERBOSE,QUIET,GDB in RUN_TEST

Allow the user to trigger a "verbose" test (in the sense of
run_test.sh's -v) through VERBOSE and/or to avoid redirecting the test's
output to a log file through QUIET and/or to allow a GDB connection
through GDB:

    make VERBOSE=1 test-boot              # prints commands
    make QUIET=0 test-crosvm-helloworld   # prints VM outputs to screen
    make GDB=1 test-boot                  # QEMU waits for GDB
    make QUIET=0 VERBOSE=1 test-boot      # they can be combined

Bug: 195395681
Test: make VERBOSE=<?> QUIET=<?> GDB=<?> test-boot
Change-Id: I73b860d141b663cb22d4e23dc927f6fadc57e31b
diff --git a/Makefile b/Makefile
index cb2583e..088e1e0 100644
--- a/Makefile
+++ b/Makefile
@@ -159,6 +159,14 @@
 	@echo '   test-kut             - runs all kvm-unit-tests in qemu-aarch64 simulated environment'
 	@echo '   test-list            - lists all test targets'
 	@echo ''
+	@echo 'Test Flags:'
+	@echo '   VERBOSE=[0|1]        - prints the verbose output of the scripts running the test'
+	@echo '                          (default: 0)'
+	@echo '   QUIET=[0|1]          - redirects the output to a file instead of stdout'
+	@echo '                          (default: 1)'
+	@echo '   GDB=[0|1]            - makes the started test wait for a GDB connection'
+	@echo '                          (default: 0)'
+	@echo ''
 	@echo 'Misc Targets:'
 	@echo '   update-prebuilts     - generates/update the prebuilt rootfs image (aarch64) and the qemu host (aarch64)'
 
@@ -351,10 +359,27 @@
 		-d $@ \
 		-M $(call hyphensuffix,$@) \
 		-k "$(KERNEL_IMAGE)" \
-		-o "$(RUN_TEST_LOG_DIR)/$@.log" \
 		$(RUN_TEST_ARGS) "$(RUN_TEST_HOST_SH)" \
 		$(if $(RUN_TEST_QEMU_ARGS),-- ,)$(RUN_TEST_QEMU_ARGS)
 
+ifeq ($(VERBOSE),1)
+RUN_TEST_ARGS += -v
+endif
+
+ifneq ($(QUIET),0)
+RUN_TEST_ARGS += -o "$(RUN_TEST_LOG_DIR)/$@.log"
+endif
+
+ifeq ($(GDB),1)
+# RUN_TEST_SH defaults to no-timeout when -G is passed but -t forces one:
+RUN_TEST_ARGS += -G
+else
+# Without -G, RUN_TEST_SH defaults to a non-zero timeout duration.
+# RUN_TEST_TIMEOUT should be use if a specific value is wanted (see 'man timeout').
+# In particular, RUN_TEST_TIMEOUT=0 prevents the test from timing out.
+RUN_TEST_ARGS += $(if $(RUN_TEST_TIMEOUT),-t ,)$(RUN_TEST_TIMEOUT)
+endif
+
 # Root test targets. Dynamically generated per-test targets
 # will add themselves as dependencies of these.
 .PHONY: test test-list
@@ -420,7 +445,6 @@
 $(CROSVM_HELLOWORLD_TESTS): RUN_TEST_LOG_DIR = $(DIST_DIR)/logs/crosvm/helloworld
 $(CROSVM_HELLOWORLD_TESTS): RUN_TEST_HOST_SH = $(SCRIPTS_DIR)/crosvm/helloworld/host.sh
 $(CROSVM_HELLOWORLD_TESTS): RUN_TEST_ARGS += \
-		-t 300s \
 		-F $(UBOOT_BIN)
 $(CROSVM_HELLOWORLD_TESTS): RUN_TEST_QEMU_ARGS = \
 		-s 4 \
@@ -428,6 +452,7 @@
 		-R $(KERNEL_IMAGE) \
 		-R $(PREBUILTS_ROOTFS_EXT4) \
 		-R $(PREBUILTS_CROSVM_EXT4)
+$(CROSVM_HELLOWORLD_TESTS): RUN_TEST_TIMEOUT := 300s
 
 .PHONY test: $(TESTS)
 $(TESTS): $(KERNEL_IMAGE)