Enable LAVA test job submission for Cypress PSoC64 platform

Signed-off-by: Arthur She <arthur.she@linaro.org>
Change-Id: Ibb7dc1fe7e17889093c7f1d6805dcf1296514501
diff --git a/build_helper/build_helper_configs.py b/build_helper/build_helper_configs.py
index dae3a63..d50fb84 100755
--- a/build_helper/build_helper_configs.py
+++ b/build_helper/build_helper_configs.py
@@ -114,7 +114,24 @@
                                             "cd %(_tbm_build_dir_)s/bin;"
                                             "BIN_FILES=$(grep loadfile flash.jlink | awk '{print $2}');"
                                             "tar jcf lpcxpresso55s69-tfm.tar.bz2 flash.jlink ${BIN_FILES};"
-                                            "popd")]
+                                            "popd")],
+                   "cypress/psoc64": [("echo 'Sign binaries for Cypress PSoC64 platform';"
+                                       "pushd %(_tbm_build_dir_)s/..;"
+                                       "sudo /usr/local/bin/cysecuretools "
+                                       "--policy platform/ext/target/cypress/psoc64/security/policy/policy_multi_CM0_CM4_tfm.json "
+                                       "--target cy8ckit-064s0s2-4343w "
+                                       "sign-image "
+                                       "--hex %(_tbm_build_dir_)s/bin/tfm_s.hex "
+                                       "--image-type BOOT --image-id 1;"
+                                       "sudo /usr/local/bin/cysecuretools "
+                                       "--policy platform/ext/target/cypress/psoc64/security/policy/policy_multi_CM0_CM4_tfm.json "
+                                       "--target cy8ckit-064s0s2-4343w "
+                                       "sign-image "
+                                       "--hex %(_tbm_build_dir_)s/bin/tfm_ns.hex "
+                                       "--image-type BOOT --image-id 16;"
+                                       "mv %(_tbm_build_dir_)s/bin/tfm_s.hex %(_tbm_build_dir_)s/bin/tfm_s_signed.hex;"
+                                       "mv %(_tbm_build_dir_)s/bin/tfm_ns.hex %(_tbm_build_dir_)s/bin/tfm_ns_signed.hex;"
+                                       "popd")]
                    },
 
     # (Optional) If set will fail if those artefacts are missing post build
diff --git a/jenkins/ci.jpl b/jenkins/ci.jpl
index 0204939..5655678 100644
--- a/jenkins/ci.jpl
+++ b/jenkins/ci.jpl
@@ -228,8 +228,8 @@
       error("Build failed at ${build_url}")
     } else {
         // Build successful
-        // Submit test job for NXP LPCXpresso55S69
-        if (params_collection["TFM_PLATFORM"].contains("lpcxpresso55s69")) {
+        // Submit test job for NXP LPCXpresso55S69 & Cypress PSoC64
+        if (params_collection["TFM_PLATFORM"].contains("lpcxpresso55s69") || params_collection["TFM_PLATFORM"].contains("psoc64")) {
           submit_lava_tests(config, results, build_res, params, params_collection)
         } else {
             // Configs without BL2 do not need LAVA tests
diff --git a/lava_helper/jinja2_templates/psoc64.jinja2 b/lava_helper/jinja2_templates/psoc64.jinja2
new file mode 100644
index 0000000..651efee
--- /dev/null
+++ b/lava_helper/jinja2_templates/psoc64.jinja2
@@ -0,0 +1,46 @@
+{#------------------------------------------------------------------------------
+# Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-----------------------------------------------------------------------------#}
+{% extends 'jinja2_templates/base.jinja2' %}
+{% block actions %}
+actions:
+    - deploy:
+        timeout:
+          minutes: 12
+        to: flasher
+        images:
+          spe:
+            url: {{ spe_url }}
+          nspe:
+            url: {{ nspe_url }}
+
+    - boot:
+        method: minimal
+
+    - test:
+        monitors:
+        {%- for monitor in test.monitors %}
+        - name: "{{monitor.name}}"
+          start: "{{monitor.start}}"
+          end: "{{monitor.end}}"
+          pattern: "{{monitor.pattern}}"
+          fixupdict:
+              '{{monitor.fixup.pass}}': pass
+              '{{monitor.fixup.fail}}': fail
+        {% endfor %}
+{% endblock %}
+
+{% block metadata %}
+metadata:
+  build_no: {{ build_no }}
+  compiler: {{ compiler }}
+  build_type: {{ build_type }}
+  boot_type: {{ boot_type }}
+  name: {{ name }}
+  platform: {{ platform }}
+  build_name: {{ build_name }}
+  build_job_url: {{ build_job_url }}
+{% endblock %}
diff --git a/lava_helper/lava_create_jobs.py b/lava_helper/lava_create_jobs.py
index 83be77d..f922a73 100755
--- a/lava_helper/lava_create_jobs.py
+++ b/lava_helper/lava_create_jobs.py
@@ -149,6 +149,16 @@
                                     params,
                                     test_dict.get("binaries").get("tarball"),
                                 ),
+                                "spe_url": get_artifact_url(
+                                    artifact_store_url,
+                                    params,
+                                    test_dict.get("binaries").get("spe_image"),
+                                ),
+                                "nspe_url": get_artifact_url(
+                                    artifact_store_url,
+                                    params,
+                                    test_dict.get("binaries").get("nspe_image"),
+                                ),
                             }
                         )
                         params.update(
@@ -189,7 +199,6 @@
         config["platforms"] = {platform: config["platforms"][platform]}
     # Generate the output definition
     definitions = generate_test_definitions(config, work_dir, user_args)
-
     # Write it into a file
     out_dir = os.path.abspath(user_args.lava_def_output)
     os.makedirs(out_dir, exist_ok=True)
diff --git a/lava_helper/lava_helper_configs.py b/lava_helper/lava_helper_configs.py
index 2b3e4ec..2758503 100644
--- a/lava_helper/lava_helper_configs.py
+++ b/lava_helper/lava_helper_configs.py
@@ -3504,6 +3504,135 @@
     }
 }
 
+# Cypress PSoC64
+psoc64 = {
+    "templ": "psoc64.jinja2",
+    "job_name": "psoc64",
+    "device_type": "cy8ckit-064s0s2-4343w",
+    "job_timeout": 120,
+    "action_timeout": 120,
+    "monitor_timeout": 120,
+    "poweroff_timeout": 5,
+    "platforms": {"psoc64": ""},
+    "compilers": ["GNUARM", "ARMCLANG"],
+    "build_types": ["Release", "Minsizerel"],
+    "boot_types": ["NOBL2"],
+    "tests": {
+        "Regression": {
+            "binaries": {
+                "spe_image": "tfm_s_signed.hex",
+                "nspe_image": "tfm_ns_signed.hex",
+            },
+            "monitors": [
+                {
+                    'name': 'Secure_Test_Suites_Summary',
+                    'start': 'Secure test suites summary',
+                    'end': 'End of Secure test suites',
+                    'pattern': r"Test suite '(?P<"
+                               r"test_case_id>[^\n]+)' has(.*) "
+                               r"(?P<result>PASSED|FAILED)",
+                    'fixup': {"pass": "PASSED", "fail": "FAILED"},
+                    'required': ["secure_image_initializing"]
+                },
+                {
+                    'name': 'Non_Secure_Test_Suites_Summary',
+                    'start': 'Non-secure test suites summary',
+                    'end': 'End of Non-secure test suites',
+                    'pattern': r"Test suite '(?P<"
+                               r"test_case_id>[^\n]+)' has(.*) "
+                               r"(?P<result>PASSED|FAILED)",
+                    'fixup': {"pass": "PASSED", "fail": "FAILED"},
+                    'required': ["secure_image_initializing"]
+                }
+            ]  # Monitors
+        },
+        "RegressionIPC": {
+            "binaries": {
+                "spe_image": "tfm_s_signed.hex",
+                "nspe_image": "tfm_ns_signed.hex",
+            },
+            "monitors": [
+                {
+                    'name': 'Secure_Test_Suites_Summary',
+                    'start': 'Secure test suites summary',
+                    'end': 'End of Secure test suites',
+                    'pattern': r"Test suite '(?P<"
+                               r"test_case_id>[^\n]+)' has(.*) "
+                               r"(?P<result>PASSED|FAILED)",
+                    'fixup': {"pass": "PASSED", "fail": "FAILED"},
+                    'required': ["secure_image_initializing"]
+                },
+                {
+                    'name': 'Non_Secure_Test_Suites_Summary',
+                    'start': 'Non-secure test suites summary',
+                    'end': 'End of Non-secure test suites',
+                    'pattern': r"Test suite '(?P<"
+                               r"test_case_id>[^\n]+)' has(.*) "
+                               r"(?P<result>PASSED|FAILED)",
+                    'fixup': {"pass": "PASSED", "fail": "FAILED"},
+                    'required': ["secure_image_initializing"]
+                }
+            ]  # Monitors
+        },
+        "RegressionIPCTfmLevel2": {
+            "binaries": {
+                "spe_image": "tfm_s_signed.hex",
+                "nspe_image": "tfm_ns_signed.hex",
+            },
+            "monitors": [
+                {
+                    'name': 'Secure_Test_Suites_Summary',
+                    'start': 'Secure test suites summary',
+                    'end': 'End of Secure test suites',
+                    'pattern': r"Test suite '(?P<"
+                               r"test_case_id>[^\n]+)' has(.*) "
+                               r"(?P<result>PASSED|FAILED)",
+                    'fixup': {"pass": "PASSED", "fail": "FAILED"},
+                    'required': ["secure_image_initializing"]
+                },
+                {
+                    'name': 'Non_Secure_Test_Suites_Summary',
+                    'start': 'Non-secure test suites summary',
+                    'end': 'End of Non-secure test suites',
+                    'pattern': r"Test suite '(?P<"
+                               r"test_case_id>[^\n]+)' has(.*) "
+                               r"(?P<result>PASSED|FAILED)",
+                    'fixup': {"pass": "PASSED", "fail": "FAILED"},
+                    'required': ["secure_image_initializing"]
+                }
+            ]  # Monitors
+        },
+        "RegressionIPCTfmLevel3": {
+            "binaries": {
+                "spe_image": "tfm_s_signed.hex",
+                "nspe_image": "tfm_ns_signed.hex",
+            },
+            "monitors": [
+                {
+                    'name': 'Secure_Test_Suites_Summary',
+                    'start': 'Secure test suites summary',
+                    'end': 'End of Secure test suites',
+                    'pattern': r"Test suite '(?P<"
+                               r"test_case_id>[^\n]+)' has(.*) "
+                               r"(?P<result>PASSED|FAILED)",
+                    'fixup': {"pass": "PASSED", "fail": "FAILED"},
+                    'required': ["secure_image_initializing"]
+                },
+                {
+                    'name': 'Non_Secure_Test_Suites_Summary',
+                    'start': 'Non-secure test suites summary',
+                    'end': 'End of Non-secure test suites',
+                    'pattern': r"Test suite '(?P<"
+                               r"test_case_id>[^\n]+)' has(.*) "
+                               r"(?P<result>PASSED|FAILED)",
+                    'fixup': {"pass": "PASSED", "fail": "FAILED"},
+                    'required': ["secure_image_initializing"]
+                }
+            ]  # Monitors
+        },
+    },
+}
+
 # All configurations should be mapped here
 lava_gen_config_map = {
     "mps2_an521_bl2": tfm_mps2_sse_200,
@@ -3516,6 +3645,7 @@
     "musca_b1_otp": musca_b1_otp_bl2,
     "stm32l562e_dk": stm32l562e_dk,
     "lpcxpresso55s69": lpcxpresso55s69,
+    "psoc64": psoc64,
 }
 
 lavagen_config_sort_order = [