qemu: Add more granular control for check tests

Add a new argument for script: qemu-check.exp as the type of tests to be
executed. After this change its possible to run tests granularly as
follows:
- Executes all tests:
  $ make check
  $ make check CHECK_TESTS=all
- Execute only xtest tests:
  $ make check CHECK_TESTS=xtest
- Execute only trusted-keys tests:
  $ make check CHECK_TESTS=trusted-keys

Signed-off-by: Sumit Garg <sumit.garg@linaro.org>
Acked-by: Jerome Forissier <jerome@forissier.org>
diff --git a/qemu-check.exp b/qemu-check.exp
index e3c6912..f64f231 100644
--- a/qemu-check.exp
+++ b/qemu-check.exp
@@ -1,11 +1,12 @@
 #!/usr/bin/expect -f
 #
 # This scripts starts QEMU, loads and boots Linux/OP-TEE, then runs
-# xtest in the guest. The return code is 0 for success, >0 for error.
+# tests in the guest. The return code is 0 for success, >0 for error.
 #
 # Options:
 #   --bios    Path to the binary to be run [../out/bios-qemu/bios.bin]
 #   -q        Suppress output to stdout (quiet)
+#   --tests   Type of tests to run, values: all, xtest and trusted-keys
 #   --timeout Timeout for each test (sub)case, in seconds [480]
 
 set bios "../out/bios-qemu/bios.bin"
@@ -21,6 +22,7 @@
 # The value here should be sufficient to run the whole optee_test suite
 # ('xtest') with all testsuites enabled (regression+gp+pkcs11).
 set timeout 900
+set tests "all"
 
 # Parse command line
 set myargs $argv
@@ -28,6 +30,7 @@
 	set myargs [lassign $myargs arg]
 	switch -exact -- $arg {
 		"--bios"	{set myargs [lassign $myargs ::bios]}
+		"--tests"	{set myargs [lassign $myargs ::tests]}
 		"--timeout"	{set myargs [lassign $myargs ::timeout]}
 		"-q"		{set ::quiet 1}
 	}
@@ -123,9 +126,11 @@
 # Toolchain libraries might be here or there
 send -- "export LD_LIBRARY_PATH=/lib:/lib/arm-linux-gnueabihf\r"
 expect "# "
-info "Running: $cmd...\n"
-send -- "$cmd\r"
-check_test_result $teecore
+if {$tests == "all" || $tests == "xtest"} {
+	info "Running: $cmd...\n"
+	send -- "$cmd\r"
+	check_test_result $teecore
+}
 if {$::env(XEN_BOOT) == "y"} {
 	info " Booting DomU.\n"
 	expect "# "
@@ -154,10 +159,14 @@
 	# Toolchain libraries might be here or there
 	send -- "export LD_LIBRARY_PATH=/lib:/lib/arm-linux-gnueabihf\r"
 	expect "# "
-	info "Running: $cmd...\n"
-	send -- "$cmd\r"
-	check_test_result $teecore
+	if {$tests == "all" || $tests == "xtest"} {
+		info "Running: $cmd...\n"
+		send -- "$cmd\r"
+		check_test_result $teecore
+	}
 }
-# Invoke Trusted Keys tests
-set basedir [file dirname $argv0]
-source $basedir/trusted-keys.exp
+if {$tests == "all" || $tests == "trusted-keys"} {
+	# Invoke Trusted Keys tests
+	set basedir [file dirname $argv0]
+	source $basedir/trusted-keys.exp
+}
diff --git a/qemu.mk b/qemu.mk
index bee7a25..3a607a1 100644
--- a/qemu.mk
+++ b/qemu.mk
@@ -182,6 +182,9 @@
 ifneq ($(TIMEOUT),)
 check-args += --timeout $(TIMEOUT)
 endif
+ifneq ($(CHECK_TESTS),)
+check-args += --tests $(CHECK_TESTS)
+endif
 
 check: $(CHECK_DEPS)
 	ln -sf $(ROOT)/out-br/images/rootfs.cpio.gz $(BINARIES_PATH)/
diff --git a/qemu_v8.mk b/qemu_v8.mk
index 46b7b80..9f8d6c9 100644
--- a/qemu_v8.mk
+++ b/qemu_v8.mk
@@ -410,6 +410,9 @@
 ifneq ($(TIMEOUT),)
 check-args := --timeout $(TIMEOUT)
 endif
+ifneq ($(CHECK_TESTS),)
+check-args += --tests $(CHECK_TESTS)
+endif
 
 check: $(CHECK_DEPS)
 	ln -sf $(ROOT)/out-br/images/rootfs.cpio.gz $(BINARIES_PATH)/