LAVA: Decouple LAVA monitors among reg tests

As the control on BL2, S/NS regression tests has been decoupled during
build stage, the one in LAVA monitor should also decoupled.

This patch groups monitors for regression tests based on the setting of
"TEST_REGRESSION". Also also update the code format to make it easy to
read.

Signed-off-by: Xinyu Zhang <xinyu.zhang@arm.com>
Change-Id: I508675c7acc54dc81078f255b4d40b6773150926
diff --git a/lava_helper/lava_create_jobs.py b/lava_helper/lava_create_jobs.py
index 242a5d6..419bfce 100755
--- a/lava_helper/lava_create_jobs.py
+++ b/lava_helper/lava_create_jobs.py
@@ -57,12 +57,12 @@
         if platform != os.getenv('TFM_PLATFORM'):
             continue
         recovery_image_url = get_recovery_url(recovery_store_url, recovery)
-        if os.getenv("TEST_REGRESSION") != "OFF":
-            monitor_name = "reg_tests"
-        elif os.getenv("TEST_PSA_API") != "OFF":
+        if os.getenv("TEST_PSA_API") != "OFF":
             monitor_name = "arch_tests"
-        else:
+        elif os.getenv("TEST_REGRESSION") == "OFF":
             monitor_name = "no_reg_tests"
+        else:
+            monitor_name = "reg_tests"
         params = {
             "job_name": "{}_{}_{}".format(os.getenv('CONFIG_NAME'), os.getenv("BUILD_NUMBER"), config["device_type"]),
             "build_name": os.getenv('CONFIG_NAME'),
diff --git a/lava_helper/lava_helper_configs.py b/lava_helper/lava_helper_configs.py
index 3896444..8878828 100644
--- a/lava_helper/lava_helper_configs.py
+++ b/lava_helper/lava_helper_configs.py
@@ -30,7 +30,7 @@
 # LAVA test-monitor definition for configs without regression tests.
 # "Non-Secure system starting..." is expected to indicate
 # that TF-M has been booted successfully.
-monitors_no_reg_tests = {
+no_reg_tests_monitors_cfg = {
     'name': 'NS_SYSTEM_BOOTING',
     'start': 'Non-Secure system',
     'end': r'starting\\.{3}',
@@ -41,7 +41,7 @@
 # LAVA test-monitor definitions for configs with tests.
 # Results of each test case is parsed separately, capturing test case id.
 # Works across any test suites enabled.
-monitors_mcuboot_tests = {
+mcuboot_tests_monitor_cfg = {
     'name': 'mcuboot_suite',
     'start': 'Execute test suites for the MCUBOOT area',
     'end': 'End of MCUBOOT test suites',
@@ -49,7 +49,7 @@
     'fixup': {"pass": "PASSED", "fail": "FAILED", "skip": "SKIPPED"},
 }
 
-monitors_s_reg_tests = {
+s_reg_tests_monitors_cfg = {
     'name': 'secure_regression_suite',
     'start': 'Execute test suites for the Secure area',
     'end': 'End of Secure test suites',
@@ -57,7 +57,7 @@
     'fixup': {"pass": "PASSED", "fail": "FAILED", "skip": "SKIPPED"},
 }
 
-monitors_ns_reg_tests = {
+ns_reg_tests_monitors_cfg = {
     'name': 'non_secure_regression_suite',
     'start': 'Execute test suites for the Non-secure area',
     'end': 'End of Non-secure test suites',
@@ -65,7 +65,7 @@
     'fixup': {"pass": "PASSED", "fail": "FAILED", "skip": "SKIPPED"},
 }
 
-monitors_arch_tests = {
+arch_tests_monitors_cfg = {
     'name': 'psa_api_suite',
     'start': 'Running..',
     'end': 'Entering standby..',
@@ -75,6 +75,16 @@
     'fixup': {"pass": "PASSED", "fail": "FAILED", "skip": "SKIPPED", "sim_error": "SIM ERROR"},
 }
 
+# Group related monitors into same list to simplify the code
+no_reg_tests_monitors = [no_reg_tests_monitors_cfg]
+
+reg_tests_monitors = [] + \
+                     ([mcuboot_tests_monitor_cfg] if "RegBL2" in os.getenv("TEST_REGRESSION") and os.getenv("BL2") == "True" else []) + \
+                     ([s_reg_tests_monitors_cfg] if "RegS" in os.getenv("TEST_REGRESSION") else []) + \
+                     ([ns_reg_tests_monitors_cfg] if "RegNS" in os.getenv("TEST_REGRESSION") else [])
+
+arch_tests_monitors = [arch_tests_monitors_cfg]
+
 
 # MPS2 with BL2 bootloader for AN521
 # IMAGE0ADDRESS: 0x10000000
@@ -96,10 +106,11 @@
         "bootloader": "bl2.bin"
     },
     "monitors": {
-        'no_reg_tests': [monitors_no_reg_tests],
+        'no_reg_tests': no_reg_tests_monitors,
         # FPU test on FPGA not supported yet
-        'reg_tests': ([monitors_s_reg_tests, monitors_ns_reg_tests] if 'FPON' not in os.getenv("EXTRA_PARAMS") else []) + ([monitors_mcuboot_tests] if os.getenv("BL2") == "Ture" else []),
-        'arch_tests': [monitors_arch_tests] if os.getenv("TEST_PSA_API") != "IPC" else [], # FF test on FPGA not supported in LAVA yet
+        'reg_tests': (reg_tests_monitors if 'FPON' not in os.getenv("EXTRA_PARAMS") else [mcuboot_tests_monitor_cfg]),
+        # FF test on FPGA not supported in LAVA yet
+        'arch_tests': (arch_tests_monitors if os.getenv("TEST_PSA_API") != "IPC" else []),
     }
 }
 
@@ -121,8 +132,8 @@
         "data": "tfm_s_ns_signed.bin"
     },
     "monitors": {
-        'no_reg_tests': [monitors_no_reg_tests],
-        'reg_tests': [monitors_s_reg_tests, monitors_ns_reg_tests] + ([monitors_mcuboot_tests] if os.getenv("BL2") == "Ture" else []),
+        'no_reg_tests': no_reg_tests_monitors,
+        'reg_tests': reg_tests_monitors,
     }
 }
 
@@ -145,9 +156,9 @@
         "data": "tfm_s_ns_signed.bin"
     },
     "monitors": {
-        'no_reg_tests': [monitors_no_reg_tests],
-        'reg_tests': [monitors_s_reg_tests, monitors_ns_reg_tests] + ([monitors_mcuboot_tests] if os.getenv("BL2") == "Ture" else []),
-        'arch_tests': [monitors_arch_tests],
+        'no_reg_tests': no_reg_tests_monitors,
+        'reg_tests': reg_tests_monitors,
+        'arch_tests': arch_tests_monitors,
     }
 }
 
@@ -171,8 +182,8 @@
         "data": "tfm_s_ns_signed.bin"
     },
     "monitors": {
-        'no_reg_tests': [monitors_no_reg_tests],
-        'reg_tests': [monitors_s_reg_tests, monitors_ns_reg_tests] + ([monitors_mcuboot_tests] if os.getenv("BL2") == "Ture" else []),
+        'no_reg_tests': no_reg_tests_monitors,
+        'reg_tests': reg_tests_monitors,
     }
 }
 
@@ -193,7 +204,7 @@
     },
     "monitors": {
         # FPU test on AN521 qemu not supported yet
-        'reg_tests': ([monitors_s_reg_tests, monitors_ns_reg_tests] if 'FPON' not in os.getenv("EXTRA_PARAMS") else []) + ([monitors_mcuboot_tests] if os.getenv("BL2") == "Ture" else []),
+        'reg_tests': (reg_tests_monitors if 'FPON' not in os.getenv("EXTRA_PARAMS") else [mcuboot_tests_monitor_cfg]),
     }
 }
 
@@ -214,8 +225,8 @@
         "firmware": "tfm.hex",
     },
     "monitors": {
-        'no_reg_tests': [monitors_no_reg_tests],
-        'reg_tests': [monitors_s_reg_tests, monitors_ns_reg_tests] + ([monitors_mcuboot_tests] if os.getenv("BL2") == "Ture" else []),
+        'no_reg_tests': no_reg_tests_monitors,
+        'reg_tests': reg_tests_monitors,
     }
 }
 
@@ -233,7 +244,7 @@
         "tarball": "stm32l562e-dk-tfm.tar.bz2",
     },
     "monitors": {
-        'reg_tests': [monitors_s_reg_tests, monitors_ns_reg_tests] + ([monitors_mcuboot_tests] if os.getenv("BL2") == "Ture" else []),
+        'reg_tests': reg_tests_monitors,
     }
 }
 
@@ -251,8 +262,8 @@
         "tarball": "lpcxpresso55s69-tfm.tar.bz2",
     },
     "monitors": {
-        'no_reg_tests': [monitors_no_reg_tests],
-        'reg_tests': [monitors_s_reg_tests, monitors_ns_reg_tests],
+        'no_reg_tests': no_reg_tests_monitors,
+        'reg_tests': reg_tests_monitors,
     }
 }
 
@@ -271,7 +282,7 @@
         "nspe": "tfm_ns_signed.hex",
     },
     "monitors": {
-        'reg_tests': [monitors_s_reg_tests, monitors_ns_reg_tests],
+        'reg_tests': reg_tests_monitors,
     }
 }