Test: Add group in the build and test summary htmls

Give the information of group in summary to help user
find the certain group.

Signed-off-by: Jianliang Shen <jianliang.shen@arm.com>
Change-Id: If0749201760618f91b168196aaf24a04ae47a28f
diff --git a/configs.py b/configs.py
index e83c7d9..530980f 100755
--- a/configs.py
+++ b/configs.py
@@ -101,11 +101,11 @@
     if not ARGS.group or ARGS.group == ['all']:
         ARGS.group = list(_builtin_configs.keys())
 
-    all_configs = set()
+    all_configs = {}
     for group in ARGS.group:
         # By default print available configs
         if not ARGS.config:
-            all_configs.update(list_configs(group))
+            all_configs[group] = list_configs(group)
         else:
             try:
                 if ARGS.config_params:
@@ -121,6 +121,6 @@
                             ARGS.config, ARGS.group
                         )
                     )
-
-    for config in all_configs:
-        print(config)
+    for group in all_configs.keys():
+        for config in all_configs[group]:
+            print("{}:{}".format(config, group))
diff --git a/jenkins/ci.jpl b/jenkins/ci.jpl
index 7462632..4ede1e3 100644
--- a/jenkins/ci.jpl
+++ b/jenkins/ci.jpl
@@ -24,7 +24,7 @@
   return false
 }
 
-def submit_lava_tests(config, results, build_res, params, params_collection) {
+def submit_lava_tests(config, group, results, build_res, params, params_collection) {
   print("Doing LAVA stuff for ${build_res.getAbsoluteUrl()}")
   params += string(name: 'BUILD_NUMBER', value: "${build_res.number}")
   params += string(name: 'BUILD_URL', value: build_res.getAbsoluteUrl())
@@ -44,7 +44,10 @@
       lava_resubmitted = true
       lava_des = lava_des - " Submitted twice!"
     }
-    results['lava_jobs'] += lava_des
+    def lava_job = [:]
+    lava_job['res'] = lava_des
+    lava_job['group'] = group
+    results['lava_jobs'] += lava_job
   }
   links = "Build Config: ${config}\n"
   links += "Build URL: ${build_res.getAbsoluteUrl()}\n"
@@ -55,7 +58,7 @@
   print(links)
 }
 
-def listConfigs(config_list, filter_group) {
+def listConfigs(config_group, filter_group) {
   // In case filter group starts with spaces
   config_groups = filter_group.replaceAll(/^\s+/, '')
   // In case filter group ends with spaces
@@ -67,8 +70,11 @@
     """
     python3 ./tf-m-ci-scripts/configs.py -g ${config_groups}\n
     """, returnStdout: true).trim()
+  // The output string of configs.py is 'config:group\n'
   def build_config_list = build_config_list_raw.tokenize('\n')
-  config_list.addAll(build_config_list)
+  for (String build_config : build_config_list) {
+    config_group[build_config.tokenize(':')[0]] = build_config.tokenize(':')[1]
+  }
 }
 
 def obtainBuildParams(config) {
@@ -86,7 +92,7 @@
   return build_params
 }
 
-def buildConfig(config, results) {
+def buildConfig(config, group, results) {
   def params = []
   params_collection = obtainBuildParams(config)
   params_collection.each { param ->
@@ -137,7 +143,7 @@
         }
         // Submit LAVA tests
         else {
-          submit_lava_tests(config, results, build_res, params, params_collection)
+          submit_lava_tests(config, group, results, build_res, params, params_collection)
         }
     }
   }
@@ -165,7 +171,7 @@
 }
 
 def generateEmailBody(stage, results) {
-  // Results format: [CONFIG_NAME: [URL: "", RESULT: "", ...]]
+  // Results format: [CONFIG_NAME: [URL: "", RESULT: "", GROUP: "", ...]]
   failed_jobs = ""
   results.each { job ->
     if (job.value['RESULT'] == 'FAILURE') {
@@ -246,7 +252,7 @@
 }
 
 def generateCsvContent(results) {
-  // Results format: [CONFIG_NAME: [URL: "", RESULT: "", ...]]
+  // Results format: [CONFIG_NAME: [URL: "", RESULT: "", GROUP: "", ...]]
   // CSV format: CONFIG_NAME, RESULT
   csv_header = obtainBuildParams(results.keySet()[0]).keySet().toList()
   csv_header.add('RESULT')
@@ -263,11 +269,11 @@
 }
 
 def generateHtmlContent(results) {
-  // Results format: [CONFIG_NAME: [URL: "", RESULT: "", ...]]
+  // Results format: [CONFIG_NAME: [URL: "", RESULT: "", GROUP: "", ...]]
   // HTML format: CONFIG_NAME: Job/Logs/Artifacts RESULT
   htmlContent = []
   results.each { result ->
-    htmlContent.add("${result.key}: <a href=\"${result.value['URL']}\">Job</a>/<a href=\"${result.value['URL']}/consoleText\">Logs</a>/<a href=\"${result.value['URL']}/artifact/\">Artifacts</a> ${result.value['RESULT']}<br/>")
+    htmlContent.add("${result.key}, ${result.value['GROUP']}: <a href=\"${result.value['URL']}\">Job</a>/<a href=\"${result.value['URL']}/consoleText\">Logs</a>/<a href=\"${result.value['URL']}/artifact/\">Artifacts</a> ${result.value['RESULT']}<br/>")
   }
   htmlContent.sort()
   return htmlContent.join("\n")
@@ -308,16 +314,19 @@
 
 def submitJobsToList(results) {
   def all_jobs = []
-  for (String result : results){
-    jobs_s = result.split('JOBS: ')
+  for (String result : results){ 
+    jobs_s = result['res'].split('JOBS: ')
     if (jobs_s.size() > 1) {
-      all_jobs += jobs_s[1]
+      // One build config may have different tests on different platforms, e.g. AN521
+      for (String job_s : jobs_s[1].split(',')){
+        all_jobs += "${job_s}:${result['group']}"
+      }
     }
   }
   return(all_jobs)
 }
 
-def configs = []
+def config_group = [:]
 def builds = [:]
 def results = [:]
 
@@ -336,11 +345,11 @@
     stage("Configs") {
       dir(".") {
         // Populate configs
-        listConfigs(configs, env.FILTER_GROUP)
+        listConfigs(config_group, env.FILTER_GROUP)
         results['builds'] = [:]
         results['lava_jobs'] = []
-        for (config in configs) {
-          builds[config] = buildConfig(config, results)
+        config_group.each { group ->
+          builds[group.key] = buildConfig(group.key, group.value, results)
         }
         if (!env.JOB_NAME.equals("tf-m-extra-build")) {
           builds["docs"] = buildDocs(results)
@@ -367,7 +376,8 @@
           def build_results_for_summary = [:]
           results['builds'].each { build ->
             build_results_for_summary[build.key] = ['URL': build.value.getAbsoluteUrl(),
-                                                    'RESULT': build.value.result]
+                                                    'RESULT': build.value.result,
+                                                    'GROUP': config_group[build.key]]
           }
           emailNotification('build', build_results_for_summary)
           writeCsv(build_results_for_summary, "build_results.csv")
@@ -395,7 +405,7 @@
               lava_timeout = 19800    // 5.5h
             }
             withCredentials([usernamePassword(credentialsId: env.LAVA_CREDENTIALS, passwordVariable: 'LAVA_TOKEN', usernameVariable: 'LAVA_USER')]) {
-              sh(script: """./tf-m-ci-scripts/lava_helper/lava_wait_jobs.py --job-ids ${all_jobs.join(",")} \
+              sh(script: """./tf-m-ci-scripts/lava_helper/lava_wait_jobs.py --job-ids-groups ${all_jobs.join(",")} \
                          --lava-url ${env.LAVA_URL} --lava-user ${LAVA_USER} --lava-token ${LAVA_TOKEN} \
                          --artifacts-path cfgs --lava-timeout ${lava_timeout} > output.log
                          """)
diff --git a/lava_helper/jinja2_templates/test_summary.jinja2 b/lava_helper/jinja2_templates/test_summary.jinja2
index 5c0ebb4..2d449af 100644
--- a/lava_helper/jinja2_templates/test_summary.jinja2
+++ b/lava_helper/jinja2_templates/test_summary.jinja2
@@ -13,7 +13,7 @@
 {% else %}
 <font color="red">
 {% endif %}
-Job: {{ job_id }}<br/>
+Job: {{ job_id }}  Group: {{ data[0]['group'] }}<br/>
 Description: {{ data[0]['description'] }}<br/>
 Device Type: {{ data[0]['device_type']}}  Health: {{ data[0]['health'] }}  <a href="{{ data[0]['metadata']['build_job_url'] }}">Build Job</a></br>
 <a href="{{ data[0]['artifacts_dir'] }}/definition.yaml">LAVA Definition</a>  <a href="{{ data[0]['lava_url'] }}">LAVA Job</a>  <a href="{{ data[0]['artifacts_dir'] }}/target_log.txt">Target Log</a></br>
diff --git a/lava_helper/lava_wait_jobs.py b/lava_helper/lava_wait_jobs.py
index 37ea4d2..9576782 100755
--- a/lava_helper/lava_wait_jobs.py
+++ b/lava_helper/lava_wait_jobs.py
@@ -33,7 +33,7 @@
 
 
 def wait_for_jobs(user_args):
-    job_list = user_args.job_ids.split(",")
+    job_list = [x.split(':')[0] for x in user_args.job_ids_groups.split(",")]
     job_list = [int(x) for x in job_list if x != '']
     lava = test_lava_dispatch_credentials(user_args)
     finished_jobs = get_finished_jobs(job_list, user_args, lava)
@@ -162,7 +162,9 @@
     # parsing of test results is WIP
     fail_j = []
     jinja_data = []
+    job_dict = {item.split(':')[0]: item.split(':')[1] for item in user_args.job_ids_groups.split(",")}
     for job, info in jobs.items():
+        info['group'] = job_dict[str(job)]
         info['result'] = 'SUCCESS'
         if info['health'] != 'Complete':
             info['result'] = 'FAILURE'
@@ -227,7 +229,7 @@
             else:
                 raise e
     process_finished_jobs(finished_jobs, user_args)
-    if len(finished_jobs) < len(user_args.job_ids.split(",")):
+    if len(finished_jobs) < len(user_args.job_ids_groups.split(",")):
         raise Exception("Some LAVA jobs cancelled.")
 
 def get_cmd_args():
@@ -242,7 +244,7 @@
         "--lava-url", dest="lava_url", action="store", help="LAVA lab URL (without RPC2)"
     )
     cmdargs.add_argument(
-        "--job-ids", dest="job_ids", action="store", required=True, help="Comma separated list of job IDS"
+        "--job-ids-groups", dest="job_ids_groups", action="store", required=True, help="Comma separated list of job IDS and groups \'id:group\'"
     )
     cmdargs.add_argument(
         "--lava-token", dest="lava_token", action="store", help="LAVA auth token"