Move internal code-coverage tool to use qa-tools public repo

- CI scripts to use qa-tools repository rather
than test-definitions.
- Consolidate functions to access qa-tools in a
file (qa-code-coverage.sh).
- Refactoring in merge reports script.

Signed-off-by: Saul Romero <saul.romero@arm.com>
Change-Id: I1b447273b216d739bcfcfeddf469a8f4f1c2b16b
diff --git a/script/build_bmcov.sh b/script/build_bmcov.sh
deleted file mode 100755
index 7fb48dc..0000000
--- a/script/build_bmcov.sh
+++ /dev/null
@@ -1,152 +0,0 @@
-#!/usr/bin/env bash
-#
-# Copyright (c) 2019-2020, Arm Limited. All rights reserved.
-#
-# SPDX-License-Identifier: BSD-3-Clause
-#
-
-set -e
-source "$CI_ROOT/utils.sh"
-
-prepare_json_configuration() {
-    set +e
-    elf_files="${1:-$LIST_OF_BINARIES}"
-    jenkins_sources="${2:-$JENKINS_SOURCES_WORKSPACE}"
-    elf_array=($elf_files)
-    elf=""
-    for index in "${!elf_array[@]}"
-    do
-        if [ "${DEBUG_ELFS}" = "True" ]; then
-            cp "${ELF_FOLDER}/${elf_array[$index]}.elf" ${OUTDIR}/.
-        fi
-        read -r -d '' elf << EOM
-${elf}
-                {
-                    "name": "${ELF_FOLDER}/${elf_array[$index]}.elf",
-                    "traces": [
-                                "${TRACE_FOLDER}/${trace_file_prefix:-covtrace}-*.log"
-                              ]
-                }
-EOM
-    if [ $index -lt $((${#elf_array[@]} - 1)) ];then
-        elf="${elf},"
-    fi
-    done
-    if [ "$REPO" = "SCP" ]; then
-        read -r -d '' sources << EOM
-                [
-                    {
-                    "type": "git",
-                    "URL":  "$CC_SCP_URL",
-                    "COMMIT": "$CC_SCP_COMMIT",
-                    "REFSPEC": "$CC_SCP_REFSPEC",
-                    "LOCATION": "scp"
-                    },
-                    {
-                    "type": "git",
-                    "URL":  "$CC_CMSIS_URL",
-                    "COMMIT": "$CC_CMSIS_COMMIT",
-                    "REFSPEC": "$CC_CMSIS_REFSPEC",
-                    "LOCATION": "scp/contrib/cmsis/git"
-                    }
-                ]
-EOM
-    elif [ "$REPO" = "TRUSTED_FIRMWARE" ]; then
-        read -r -d '' sources << EOM
-                [
-                    {
-                    "type": "git",
-                    "URL":  "$CC_TRUSTED_FIRMWARE_URL",
-                    "COMMIT": "$CC_TRUSTED_FIRMWARE_COMMIT",
-                    "REFSPEC": "$CC_TRUSTED_FIRMWARE_REFSPEC",
-                    "LOCATION": "trusted_firmware"
-                    },
-                    {
-                    "type": "http",
-                    "URL":  "$mbedtls_archive",
-                    "COMPRESSION": "xz",
-                    "EXTRA_PARAMS": "--strip-components=1",
-                    "LOCATION": "mbedtls"
-                    }
-                ]
-EOM
-    else
-        sources=""
-    fi
-metadata="\"BUILD_CONFIG\": \"${BUILD_CONFIG}\", \"RUN_CONFIG\": \"${RUN_CONFIG}\""
-cat <<EOF > "${CONFIG_JSON}"
-{
-    "configuration":
-        {
-        "remove_workspace": true,
-        "include_assembly": true
-        },
-    "parameters":
-        {
-        "sources": $sources,
-        "workspace": "${jenkins_sources}",
-        "output_file": "${OUTPUT_JSON}",
-        "metadata": {$metadata}
-        },
-    "elfs": [
-            ${elf}
-        ]
-}
-EOF
-set -e
-}
-
-prepare_html_pages() {
-    pushd ${OUTDIR}
-    cp ${BMCOV_REPORT_FOLDER}/reporter_cc.py ${OUTDIR}/.
-    if [ "${DEBUG_ELFS}" = "True" ]; then
-        cp "${TRACE_FOLDER}/${trace_file_prefix}"* ${OUTDIR}/.
-    fi
-    # to be run on the user locally
-    cat <<EOF > "server.sh"
-#!/usr/bin/env bash
-
-echo "Running server..."
-type -a firefox || (echo "Please install Firefox..." && exit 1)
-type -a python3 || (echo "Please install python3..." && exit 1)
-
-python - << EOT
-import os
-import reporter_cc
-
-output_file = os.getenv('OUTPUT_JSON', 'output_file.json')
-source_folder = os.getenv('CSOURCE_FOLDER', 'source')
-r = reporter_cc.ReportCC(output_file)
-r.clone_repo(source_folder)
-EOT
-(sleep 2; firefox --new-window http://localhost:8081) &
-python3 -m http.server 8081
-EOF
-    chmod 777 server.sh
-    zip -r server_side.zip *
-    popd
-}
-
-PVLIB_HOME=${PVLIB_HOME:-$warehouse/SysGen/PVModelLib/$model_version/$model_build/external}
-echo "Building Bmcov for code coverage..."
-source "$CI_ROOT/script/test_definitions.sh"
-export BMCOV_FOLDER="${BMCOV_FOLDER:-$workspace/test-definitions/scripts/tools/code_coverage/fastmodel_baremetal/bmcov}"
-pushd "${workspace}"
-git clone "${TEST_DEFINITIONS_REPO}" -b "${TEST_DEFINITIONS_REFSPEC}"
-popd
-pushd "${BMCOV_FOLDER}"
-export MODEL_PLUGIN_FOLDER="${BMCOV_FOLDER}"/model-plugin
-if [ -n "$(find "$warehouse" -maxdepth 0 -type d -empty 2>/dev/null)" ]; then
-    echo "$warehouse not mounted. Falling back to pre-built plugins.."
-    folder="http://files.oss.arm.com/downloads/tf-a/coverage-plugin"
-    wget -q ${folder}/{CoverageTrace.so,CoverageTrace.o,PluginUtils.o} \
-    -P "${MODEL_PLUGIN_FOLDER}"
- else
-    make -C model-plugin PVLIB_HOME="$PVLIB_HOME"
-fi
-
-export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$MODEL_PLUGIN_FOLDER
-export trace_file_prefix=covtrace
-export BMCOV_REPORT_FOLDER="${BMCOV_FOLDER}"/report
-export coverage_trace_plugin="${MODEL_PLUGIN_FOLDER}"/CoverageTrace.so
-popd
diff --git a/script/gen_merge_report.sh b/script/gen_merge_report.sh
index fed9256..6045a3b 100644
--- a/script/gen_merge_report.sh
+++ b/script/gen_merge_report.sh
@@ -1,32 +1,29 @@
 #!/usr/bin/env bash
 #
-# Copyright (c) 2019-2020, Arm Limited. All rights reserved.
+# Copyright (c) 2019-2023, Arm Limited. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
 
+set -x
 REPORT_JSON=$1
 REPORT_HTML=$2
-TEST_DEF_FOLDER="${WORKSPACE}/test-definitions"
 
 if echo "$JENKINS_URL" | grep -q "oss.arm.com"; then
-ARTIFACT_PATH='artifact/html'
-INFO_PATH='lcov_report/coverage.info'
-JSON_PATH='output_file.json'
+  ARTIFACT_PATH='artifact/html/qa-code-coverage'
+  INFO_PATH='coverage.info'
+  JSON_PATH='intermediate_layer.json'
 else
-ARTIFACT_PATH='artifact'
-INFO_PATH='trace_report/coverage.info'
-JSON_PATH='config_file.json'
+  ARTIFACT_PATH='artifact'
+  INFO_PATH='trace_report/coverage.info'
+  JSON_PATH='config_file.json'
 fi
 
-BRANCH_FOLDER="scripts/tools/code_coverage/fastmodel_baremetal/bmcov/report/branch_coverage"
-BMCOV_REPORT_FOLDER="$OUTDIR/$TEST_DEF_FOLDER/scripts/tools/code_coverage/fastmodel_baremetal/bmcov/report"
-
 #################################################################
 # Create json file for input to the merge.sh for Code Coverage
 # Globals:
 #   REPORT_JSON: Json file for SCP and TF ci gateway test results
-#   MERGE_JSON: Json file to be used as input to the merge.sh
+#   MERGE_CONFIGURATION: Json file to be used as input to the merge.sh
 # Arguments:
 #   None
 # Outputs:
@@ -46,7 +43,8 @@
 test_results = data['test_results']
 test_files = data['test_files']
 for index, build_number in enumerate(test_results):
-    if "bmcov" in test_files[index] and test_results[build_number] == "SUCCESS":
+    if ("bmcov" in test_files[index] or
+    "code-coverage" in test_files[index]) and test_results[build_number] == "SUCCESS":
         merge_number += 1
         base_url = "{}job/{}/{}/{}".format(
                         server, data['job'], build_number, "$ARTIFACT_PATH")
@@ -63,23 +61,78 @@
                                 }
                         })
 merge_json = { 'files' : _files }
-with open("$MERGE_JSON", 'w') as outfile:
-    json.dump(merge_json, outfile)
+with open("$MERGE_CONFIGURATION", 'w') as outfile:
+    json.dump(merge_json, outfile, indent=4)
 print(merge_number)
 EOF
 }
 
-generate_bmcov_header() {
-    cov_html=$1
-    out_report=$2
+generate_header() {
+    local cov_html=${OUTDIR}/${COVERAGE_FOLDER}/index.html
+    local out_report=$1
 python3 - << EOF
 import re
+import json
 cov_html="$cov_html"
 out_report = "$out_report"
+confs = ""
+with open("$REPORT_JSON") as json_file:
+    data = json.load(json_file)
+test_files = data['test_files']
+test_results = data['test_results']
+for index, build_number in enumerate(test_results):
+  test_file = test_files[index]
+  test_configuration = test_file.rsplit('%', 1)
+  if len(test_configuration) > 1:
+    confs += '<a target="_blank" href="artifact/${jenkins_archive_folder}/${COVERAGE_FOLDER}/{}/index.html">{}</a>'.format(build_number,
+      test_configuration[1])
+
 with open(cov_html, "r") as f:
     html_content = f.read()
 items = ["Lines", "Functions", "Branches"]
 s = """
+<style>
+.dropbtn {
+  background-color: #04AA6D;
+  color: white;
+  padding: 16px;
+  font-size: 16px;
+  border: none;
+}
+
+/* The container <div> - needed to position the dropdown content */
+.dropdown {
+  position: relative;
+  display: inline-block;
+}
+
+/* Dropdown Content (Hidden by Default) */
+.dropdown-content {
+  display: none;
+  position: absolute;
+  background-color: #f1f1f1;
+  min-width: 160px;
+  box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
+  z-index: 1;
+}
+
+/* Links inside the dropdown */
+.dropdown-content a {
+  color: black;
+  padding: 12px 16px;
+  text-decoration: none;
+  display: block;
+}
+
+/* Change color of dropdown links on hover */
+.dropdown-content a:hover {background-color: #ddd;}
+
+/* Show the dropdown menu on hover */
+.dropdown:hover .dropdown-content {display: block;}
+
+/* Change the background color of the dropdown button when the dropdown content is shown */
+.dropdown:hover .dropbtn {background-color: #3e8e41;}
+</style>
     <div id="div-cov">
     <hr>
         <table id="table-cov">
@@ -115,12 +168,20 @@
             </tbody>
         </table>
         <p>
-        <button onclick="window.open('artifact/$index/index.html','_blank');">Coverage Report</button>
+        <button onclick="window.open('artifact/${jenkins_archive_folder}/${COVERAGE_FOLDER}/index.html','_blank');">Total Coverage Report</button>
         </p>
+        <div class="dropdown">
+          <button class="dropbtn">Coverage Reports($number_of_files_to_merge)</button>
+          <div class="dropdown-content">
+          """ + confs + """
+          </div>
+        </div>
     </div>
+
 <script>
     document.getElementById('tf-report-main').appendChild(document.getElementById("div-cov"));
 </script>
+
 """
 with open(out_report, "a") as f:
     f.write(s)
@@ -131,38 +192,33 @@
 case "$TEST_GROUPS" in
     scp*)
             project="scp"
-            OUTDIR=${WORKSPACE}/reports
-            index=reports;;
+            jenkins_archive_folder=reports;;
     tf*)
             project="trusted_firmware"
-            OUTDIR=${WORKSPACE}/merge/outdir
-            index=merge/outdir;;
+            jenkins_archive_folder=merge/outdir;;
     *)
             exit 0;;
 esac
-export MERGE_JSON="$OUTDIR/merge.json"
-source "$CI_ROOT/script/test_definitions.sh"
+OUTDIR=${WORKSPACE}/${jenkins_archive_folder}
+source "$CI_ROOT/script/qa-code-coverage.sh"
+export MERGE_CONFIGURATION="$OUTDIR/merge_configuration.json"
+COVERAGE_FOLDER=lcov
+cd $WORKSPACE
+deploy_qa_tools
+cd -
 mkdir -p $OUTDIR
 pushd $OUTDIR
-    merge_files=$(create_merge_cfg)
-    echo "Merging $merge_files coverage files..."
+    number_of_files_to_merge=$(create_merge_cfg)
+    echo "Merging $number_of_files_to_merge coverage files..."
     # Only merge when more than 1 test result
-    if [ "$merge_files" -lt 2 ] ; then
+    if [ "$number_of_files_to_merge" -lt 2 ] ; then
+        echo "Only one file to merge."
         exit 0
     fi
-    git clone $TEST_DEFINITIONS_REPO $TEST_DEF_FOLDER
-    pushd $TEST_DEF_FOLDER
-        git checkout $TEST_DEFINITIONS_REFSPEC
-    popd
 
-    if echo "$JENKINS_URL" | grep -q "oss.arm.com"; then
-    bash $TEST_DEF_FOLDER/scripts/tools/code_coverage/fastmodel_baremetal/bmcov/report/branch_coverage/merge.sh \
-        -j $MERGE_JSON -l ${OUTDIR} -p $project
-    else
-    bash $TEST_DEF_FOLDER/coverage-tool/coverage-reporting/merge.sh \
-        -j $MERGE_JSON -l ${OUTDIR} -w $SHARE_FOLDER
-    fi
+    bash ${WORKSPACE}/qa-tools/coverage-tool/coverage-reporting/merge.sh \
+        -j $MERGE_CONFIGURATION -l ${OUTDIR}/${COVERAGE_FOLDER} -w $WORKSPACE -c -g
 
-    generate_bmcov_header ${OUTDIR}/index.html ${REPORT_HTML}
+    generate_header ${REPORT_HTML}
     cp ${REPORT_HTML} $OUTDIR
 popd
diff --git a/script/qa-code-coverage.sh b/script/qa-code-coverage.sh
new file mode 100644
index 0000000..4fc0d9a
--- /dev/null
+++ b/script/qa-code-coverage.sh
@@ -0,0 +1,264 @@
+#!/usr/bin/env bash
+#
+# Copyright (c) 2023, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+# Include variables and functions to be used by these scripts
+source "$CI_ROOT/utils.sh"
+################################################################################
+# CI VARIABLES:
+# workspace, warehouse, artefacts
+# GLOBAL VARIABLES:
+# OUTDIR, PROJECT, FALLBACK_PLUGIN_URL, FALLBACK_FILES, PLUGIN_BINARY
+################################################################################
+# Defining constants
+GERRIT_URL=${GERRIT_URL:-https://gerrit.oss.arm.com}
+QA_REPO_USER=jenkins_auto
+QA_REPO_INTERNAL=${QA_REPO_INTERNAL:-https://${QA_REPO_USER}:${QA_REPO_TOKEN}@git.gitlab.arm.com/tooling/qa-tools-internal.git}
+QA_REPO_PUBLIC=${QA_REPO_PUBLIC:-https://git.gitlab.arm.com/tooling/qa-tools.git}
+QA_REPO_NAME=qa-tools
+# Internal globals
+CODE_COVERAGE_FOLDER="${OUTDIR:-$workspace}/qa-code-coverage"
+DEBUG_FOLDER=${artefacts}/debug
+RELEASE_FOLDER=${artefacts}/release
+TRACE_FILE_PREFIX=covtrace
+CONFIG_JSON=${CODE_COVERAGE_FOLDER}/configuration_file.json
+INTERMEDIATE_LAYER_FILE=${CODE_COVERAGE_FOLDER}/intermediate_layer.json
+INFO_FILE=${CODE_COVERAGE_FOLDER}/coverage.info
+REPORT_FOLDER=${CODE_COVERAGE_FOLDER}/lcov
+
+if echo "$JENKINS_URL" | grep -q "oss.arm.com"; then
+  QA_REPO=${QA_REPO_PUBLIC}
+  QA_REFSPEC=${QA_REFSPEC:-master}
+else
+  QA_REPO="https://review.trustedfirmware.org/ci/qa-tools"
+  QA_REFSPEC="openci"
+fi
+
+
+################################################################################
+# Deploy qa-tools into the current directory
+# GLOBALS:
+#   QA_REPO, QA_REPO_NAME, QA_REFSPEC
+# ARGUMENTS:
+#   None
+# OUTPUTS:
+#   Clones the qa-tools repo from the global variables with the given
+#   commit hash.
+# RETURN:
+#   0 if succeeds, non-zero on error.
+################################################################################
+deploy_qa_tools() {
+  git clone "${QA_REPO}" ${QA_REPO_NAME}
+  cd ${QA_REPO_NAME} && git checkout "${QA_REFSPEC}" && cd ..
+}
+
+
+################################################################################
+# Builds or downloads the QA Code Coverage Tool
+# GLOBALS:
+#   CODE_COVERAGE_FOLDER, QA_REPO, QA_REPO_NAME, QA_REFSPEC, FALLBACK_PLUGIN_URL
+# ARGUMENTS:
+#   None
+# OUTPUTS:
+#   Creates coverage folder and builds/downloads there the plugin binaries.
+#   It exports the binary plugin location to coverage_trace_plugin.
+# RETURN:
+#   0 if succeeds, non-zero on error.
+################################################################################
+build_tool() {
+  echo "Building QA Code coverage tool..."
+  PLUGIN_BINARY="${FALLBACK_FILES%%,*}" # The first in the list of the binary files
+  local PVLIB_HOME="warehouse/SysGen/PVModelLib/$model_version/$model_build/external"
+  local LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CODE_COVERAGE_FOLDER
+  mkdir -p ${CODE_COVERAGE_FOLDER}
+  pushd "${CODE_COVERAGE_FOLDER}"
+  deploy_qa_tools
+  local cc_source=$(find . -type f -name 'coverage_trace.cc')
+  local fallback="wget -q ${FALLBACK_PLUGIN_URL}/{$FALLBACK_FILES}"
+  echo "Warehouse=${warehouse}"
+  eval "$fallback"
+  ls -al
+  export coverage_trace_plugin="${CODE_COVERAGE_FOLDER}/${PLUGIN_BINARY}"
+  popd
+}
+
+  ################################################################################
+  # Creates configuration file for intermediate layer generation
+  # GLOBALS:
+  #   PROJECT, CONFIG_JSON, INTERMEDIATE_LAYER_FILE, CODE_COVERAGE_FOLDER
+  # ARGUMENTS:
+  #   $1 Folder where are the elf/axf files.
+  #   $2 List of elf/axf file names.
+  #   $3 Path for trace files.
+  #   $4 Root folder name where all the repos are cloned.
+  # OUTPUTS:
+  #   Creates coverage folder and builds/downloads there the plugin binaries.
+  # RETURN:
+  #   0 if succeeds, non-zero on error.
+  ################################################################################
+create_config_json() {
+  set +e
+  if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]
+  then
+    cat << END
+Missing argument at '${FUNCNAME[0]}'.
+USAGE:
+  create_config_json ' Glob binaries' 'Glob trace files' 'Repos root folder name'
+  Example:
+    create_config_json 'bl1.elf bl2.elf' 'tf'
+END
+    exit 1
+  fi
+  local ELF_FOLDER=$1
+  local dwarf_array=($2)
+  local TRACE_FOLDER=$3
+  local root_repos_foolder="${4:-$workspace}"
+  local scm_sources=""
+
+  # Obtaining binaries from array
+  bin_section=""
+  for index in "${!dwarf_array[@]}"
+  do
+      local elf_file="${ELF_FOLDER}/${dwarf_array[$index]}"
+      cp "$elf_file" ${CODE_COVERAGE_FOLDER}/.
+      read -r -d '' bin_section << EOM
+${bin_section}
+              {
+                  "name": "$elf_file",
+                  "traces": [
+                              "${TRACE_FOLDER}/${TRACE_FILE_PREFIX:-covtrace}-*.log"
+                            ]
+              }
+EOM
+  if [ $index -lt $((${#dwarf_array[@]} - 1)) ];then
+      bin_section="${bin_section},"
+  fi
+  done
+
+  if [ "$PROJECT" = "SCP" ]; then
+      read -r -d '' scm_sources << EOM
+              [
+                  {
+                  "type": "git",
+                  "URL":  "$CC_SCP_URL",
+                  "COMMIT": "$CC_SCP_COMMIT",
+                  "REFSPEC": "$CC_SCP_REFSPEC",
+                  "LOCATION": "scp"
+                  },
+                  {
+                  "type": "git",
+                  "URL":  "$CC_CMSIS_URL",
+                  "COMMIT": "$CC_CMSIS_COMMIT",
+                  "REFSPEC": "$CC_CMSIS_REFSPEC",
+                  "LOCATION": "scp/contrib/cmsis/git"
+                  }
+              ]
+EOM
+elif [ "$PROJECT" = "TF-A" ]; then
+      read -r -d '' scm_sources << EOM
+              [
+                  {
+                  "type": "git",
+                  "URL":  "$CC_TRUSTED_FIRMWARE_URL",
+                  "COMMIT": "$CC_TRUSTED_FIRMWARE_COMMIT",
+                  "REFSPEC": "$CC_TRUSTED_FIRMWARE_REFSPEC",
+                  "LOCATION": "trusted_firmware"
+                  },
+                  {
+                  "type": "http",
+                  "URL":  "$mbedtls_archive",
+                  "COMPRESSION": "xz",
+                  "EXTRA_PARAMS": "--strip-components=1",
+                  "LOCATION": "mbedtls"
+                  }
+              ]
+EOM
+  else
+      echo "SCM sources not provided for project '${PROJECT}'"
+      exit 1
+  fi
+local metadata="\"BUILD_CONFIG\": \"${BUILD_CONFIG}\", \"RUN_CONFIG\": \"${RUN_CONFIG}\""
+cat <<EOF > "${CONFIG_JSON}"
+{
+  "configuration":
+      {
+      "remove_workspace": true,
+      "include_assembly": true
+      },
+  "parameters":
+      {
+      "objdump": "${OBJDUMP}",
+      "readelf": "${READELF}",
+      "sources": $scm_sources,
+      "workspace": "${root_repos_foolder}",
+      "output_file": "${INTERMEDIATE_LAYER_FILE}",
+      "metadata": {$metadata}
+      },
+  "elfs": [
+          ${bin_section}
+      ]
+}
+EOF
+
+}
+
+################################################################################
+# Creates intermediate layer json file with trace coverage data.
+#
+# Creates a configuration JSON file to be the input for the intermediate
+# layer file creation.
+# GLOBALS:
+#   TRACE_FILE_PREFIX, CODE_COVERAGE_FOLDER
+# ARGUMENTS:
+#   $1 Location of trace files.
+#   $2 Location of elf/axf files.
+#   $3 List of binaries to be checked the traces.
+#   $4 Root folder name where all the repos are cloned.
+# OUTPUTS:
+#   A configuration JSON file.
+#   An intermediate layer JSON  file.
+# RETURN:
+#   0 if succeeds, non-zero on error.
+################################################################################
+create_intermediate_layer() {
+  local TRACE_FOLDER="$1"
+  local ELF_FOLDER="$2"
+  local LIST_OF_BINARIES="$3"
+  local root_repos_foolder="$4"
+
+  # Copying trace files into the qa-tools executables folder
+  if [ $(ls -1 ${TRACE_FOLDER}/${TRACE_FILE_PREFIX}-* 2>/dev/null | wc -l) != 0 ]; then
+    cp ${TRACE_FOLDER}/${TRACE_FILE_PREFIX}-* ${CODE_COVERAGE_FOLDER}/.
+  else
+    echo "Trace files not present, aborting reports..."
+    ls -al ${TRACE_FOLDER}
+    exit -1
+  fi
+  create_config_json "${ELF_FOLDER}" "${LIST_OF_BINARIES}" "${TRACE_FOLDER}" "$root_repos_foolder"
+  python3 ${CODE_COVERAGE_FOLDER}/qa-tools/coverage-tool/coverage-reporting/intermediate_layer.py \
+    --config-json ${CONFIG_JSON}
+
+}
+
+
+################################################################################
+# Creates LCOV coverage report.
+# GLOBALS:
+#   CODE_COVERAGE_FOLDER, workspace, INTERMEDIATE_LAYER_FILE, INFO_FILE,
+#   REPORT_FOLDER
+# ARGUMENTS:
+#   None
+# OUTPUTS:
+#   A coverage info file.
+#   LCOV HTML coverage report.
+# RETURN:
+#   0 if succeeds, non-zero on error.
+################################################################################
+create_coverage_report() {
+	python3 ${CODE_COVERAGE_FOLDER}/qa-tools/coverage-tool/coverage-reporting/generate_info_file.py \
+	--workspace ${workspace} --json ${INTERMEDIATE_LAYER_FILE} --info ${INFO_FILE}
+	genhtml --branch-coverage ${INFO_FILE} --output-directory ${REPORT_FOLDER}
+}
diff --git a/script/run_package.sh b/script/run_package.sh
index 26cb745..c0a1f8e 100755
--- a/script/run_package.sh
+++ b/script/run_package.sh
@@ -10,7 +10,6 @@
 # Enable job control to have background processes run in their own process
 # group. That way, we can kill a background process group in one go.
 set -m
-
 ci_root="$(readlink -f "$(dirname "$0")/..")"
 source "$ci_root/utils.sh"
 
@@ -169,7 +168,6 @@
 
 if [ "${COVERAGE_ON}" == "1" ]; then
 	# Adding code coverage plugin
-	echo -e "\t-C TRACE.CoverageTrace.trace-file-prefix=$trace_file_prefix \\" >> "$run_sh"
 	echo -e "\t--plugin $coverage_trace_plugin \\" >> "$run_sh"
 fi
 echo -e "\t\"\$@\"" >> "$run_sh"
diff --git a/script/test_definitions.sh b/script/test_definitions.sh
deleted file mode 100644
index 6b83bc7..0000000
--- a/script/test_definitions.sh
+++ /dev/null
@@ -1,18 +0,0 @@
-#!/usr/bin/env bash
-#
-# Copyright (c) 2019-2023, Arm Limited. All rights reserved.
-#
-# SPDX-License-Identifier: BSD-3-Clause
-#
-if echo "$JENKINS_URL" | grep -q "oss.arm.com"; then
-
-export GERRIT_URL=${GERRIT_URL:-https://gerrit.oss.arm.com}
-export TEST_DEFINITIONS_REPO=${TEST_DEFINITIONS_REPO:-${GERRIT_URL}/tests/lava/test-definitions.git}
-export TEST_DEFINITIONS_REFSPEC=${TEST_DEFINITIONS_REFSPEC:-tools-coverage-workflow_2020-10-06}
-
-else
-
-export TEST_DEFINITIONS_REPO=${QA_TOOLS_REPO:-https://review.trustedfirmware.org/ci/qa-tools}
-export TEST_DEFINITIONS_REFSPEC=${QA_TOOLS_BRANCH:-openci}
-
-fi