LAVA: Run test cases only on FVP in per-patch job

LAVA tests on physical boards and QEMU are disabled in per-patch job,
which could help to improve the performance of per-patch job.

Signed-off-by: Xinyu Zhang <xinyu.zhang@arm.com>
Change-Id: I96019b8122d19142fd42540ac42573d31eb29d64
diff --git a/jenkins/lava-submit.jpl b/jenkins/lava-submit.jpl
index 9e27631..84eaf78 100644
--- a/jenkins/lava-submit.jpl
+++ b/jenkins/lava-submit.jpl
@@ -1,11 +1,17 @@
 #!/usr/bin/env groovy
 //-------------------------------------------------------------------------------
-// Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+// Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
 //
 // SPDX-License-Identifier: BSD-3-Clause
 //
 //-------------------------------------------------------------------------------
 
+@NonCPS
+def getUpstreamJob() {
+  def cause = manager.build.getAction(hudson.model.CauseAction.class).getCauses()
+  return cause
+}
+
 node("docker-amd64-tf-m-bionic") {
   stage("Init") {
     cleanWs()
@@ -14,6 +20,14 @@
     }
   }
   stage("LAVA") {
+
+    def fvp_only_cmd = ""
+    def upstreamProject = getUpstreamJob()[0].upstreamProject
+    if (upstreamProject == "tf-m-build-and-test") {
+      fvp_only_cmd = "--fvp-only "
+      print("Run test cases only on FVP in per-patch.")
+    }
+
     withCredentials([usernamePassword(credentialsId: env.LAVA_CREDENTIALS, passwordVariable: 'LAVA_TOKEN', usernameVariable: 'LAVA_USER')]) {
       print("Generating LAVA jobs...")
       def bl2_string = ""
@@ -27,7 +41,7 @@
       }
       dir("tf-m-ci-scripts") {
         def res = sh(script: """./lava_helper/lava_create_jobs.py \
---build-number ${env.BUILD_NUMBER} --output-dir lava_jobs \
+--build-number ${env.BUILD_NUMBER} --output-dir lava_jobs ${fvp_only_cmd}\
 --compiler ${env.COMPILER} --platform ${env.TARGET_PLATFORM} \
 ${bl2_string} ${psa_string} --build-type ${env.CMAKE_BUILD_TYPE} \
 --jenkins-build-url ${env.BUILD_URL} --proj-config ${env.PROJ_CONFIG} \
diff --git a/lava_helper/lava_create_jobs.py b/lava_helper/lava_create_jobs.py
index 2e803c3..1cffdb8 100755
--- a/lava_helper/lava_create_jobs.py
+++ b/lava_helper/lava_create_jobs.py
@@ -4,7 +4,7 @@
 
 __copyright__ = """
 /*
- * Copyright (c) 2020, Arm Limited. All rights reserved.
+ * Copyright (c) 2020-2021, Arm Limited. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  *
@@ -195,7 +195,11 @@
 
 def main(user_args):
     user_args.template_dir = "jinja2_templates"
-    config_keys = lava_gen_config_map.keys()
+    config_keys = list(lava_gen_config_map.keys())
+    if user_args.fvp_only:
+        for key in config_keys:
+            if "fvp" not in key:
+                config_keys.remove(key)
     if user_args.config_key:
         config_keys = [user_args.config_key]
     for config_key in config_keys:
@@ -257,6 +261,12 @@
         help="Set the jenkins job name",
     )
     cmdargs.add_argument(
+        "--fvp-only",
+        dest="fvp_only",
+        action="store_true",
+        help="Run test cases on FVP only",
+    )
+    cmdargs.add_argument(
         "--proj-config", dest="proj_config", action="store", help="Proj config"
     )
     cmdargs.add_argument(