BL2: Align BL2 test with BL2

Disable BL2 test when BL2 is not enabled.

Signed-off-by: Jianliang Shen <jianliang.shen@arm.com>
Change-Id: I07cec8aab27c30011295963050d3c9e53128b428
diff --git a/build_helper/build_helper_configs.py b/build_helper/build_helper_configs.py
index 5eb20ed..4e2acd2 100755
--- a/build_helper/build_helper_configs.py
+++ b/build_helper/build_helper_configs.py
@@ -50,7 +50,6 @@
         "-DTFM_TOOLCHAIN_FILE=%(codebase_root_dir)s/%(compiler)s " + \
         "-DTFM_ISOLATION_LEVEL=%(isolation_level)s " + \
         "-DTEST_NS=%(test_regression)s -DTEST_S=%(test_regression)s -DTEST_NS_FLIH_IRQ=OFF " + \
-        "-DTEST_BL2=%(test_regression)s " + \
         "-DCMAKE_BUILD_TYPE=%(cmake_build_type)s " + \
         "-DTEST_PSA_API=%(test_psa_api)s " + \
         "-DBL2=%(with_bl2)s " + \
diff --git a/lava_helper/lava_helper_configs.py b/lava_helper/lava_helper_configs.py
index fab385b..fea1161 100644
--- a/lava_helper/lava_helper_configs.py
+++ b/lava_helper/lava_helper_configs.py
@@ -98,7 +98,7 @@
     "monitors": {
         'no_reg_tests': [monitors_no_reg_tests],
         # FPU test on FPGA not supported yet
-        'reg_tests': [monitors_mcuboot_tests, monitors_s_reg_tests, monitors_ns_reg_tests] if 'FPON' not in os.getenv("EXTRA_PARAMS") else [],
+        '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
     }
 }
@@ -122,7 +122,7 @@
     },
     "monitors": {
         'no_reg_tests': [monitors_no_reg_tests],
-        'reg_tests': [monitors_mcuboot_tests, monitors_s_reg_tests, monitors_ns_reg_tests],
+        'reg_tests': [monitors_s_reg_tests, monitors_ns_reg_tests] + ([monitors_mcuboot_tests] if os.getenv("BL2") == "Ture" else []),
     }
 }
 
@@ -146,7 +146,7 @@
     },
     "monitors": {
         'no_reg_tests': [monitors_no_reg_tests],
-        'reg_tests': [monitors_mcuboot_tests, monitors_s_reg_tests, monitors_ns_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],
     }
 }
@@ -172,7 +172,7 @@
     },
     "monitors": {
         'no_reg_tests': [monitors_no_reg_tests],
-        'reg_tests': [monitors_mcuboot_tests, monitors_s_reg_tests, monitors_ns_reg_tests],
+        'reg_tests': [monitors_s_reg_tests, monitors_ns_reg_tests] + ([monitors_mcuboot_tests] if os.getenv("BL2") == "Ture" else []),
     }
 }
 
@@ -193,7 +193,7 @@
     },
     "monitors": {
         # FPU test on AN521 qemu not supported yet
-        'reg_tests': [monitors_mcuboot_tests, monitors_s_reg_tests, monitors_ns_reg_tests] if 'FPON' not in os.getenv("EXTRA_PARAMS") else [],
+        '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 []),
     }
 }
 
@@ -215,7 +215,7 @@
     },
     "monitors": {
         'no_reg_tests': [monitors_no_reg_tests],
-        'reg_tests': [monitors_mcuboot_tests, monitors_s_reg_tests, monitors_ns_reg_tests],
+        'reg_tests': [monitors_s_reg_tests, monitors_ns_reg_tests] + ([monitors_mcuboot_tests] if os.getenv("BL2") == "Ture" else []),
     }
 }
 
@@ -233,7 +233,7 @@
         "tarball": "stm32l562e-dk-tfm.tar.bz2",
     },
     "monitors": {
-        'reg_tests': [monitors_mcuboot_tests, monitors_s_reg_tests, monitors_ns_reg_tests],
+        'reg_tests': [monitors_s_reg_tests, monitors_ns_reg_tests] + ([monitors_mcuboot_tests] if os.getenv("BL2") == "Ture" else []),
     }
 }
 
diff --git a/tfm_ci_pylib/tfm_build_manager.py b/tfm_ci_pylib/tfm_build_manager.py
index 68c2f16..8e66caa 100644
--- a/tfm_ci_pylib/tfm_build_manager.py
+++ b/tfm_ci_pylib/tfm_build_manager.py
@@ -409,6 +409,8 @@
             overwrite_params["test_psa_api"] += " -DCC312_LEGACY_DRIVER_API_ENABLED=OFF"
         if i.tfm_platform == "arm/musca_b1":
             overwrite_params["test_psa_api"] += " -DOTP_NV_COUNTERS_RAM_EMULATION=ON"
+        if i.test_regression:
+            overwrite_params["extra_params"] += " -DTEST_BL2=False" if not i.with_bl2 else " -DTEST_BL2=True"
         build_cfg["config_template"] %= overwrite_params
         if len(build_cfg["build_cmds"]) > 1:
             overwrite_build_dir = {"_tbm_build_dir_": build_dir}