blob: 3923ab8548b83bac439add701aba173c1eeef855 [file] [log] [blame]
Zelalem1af7a7b2020-08-04 17:34:32 -05001#!/bin/bash
2#
3# Copyright (c) 2019-2020, Arm Limited. All rights reserved.
4#
5# SPDX-License-Identifier: BSD-3-Clause
6#
7
8set -e
9source "$CI_ROOT/utils.sh"
10
11prepare_json_configuration() {
12 set +e
13 elf_files="${1:-$LIST_OF_BINARIES}"
14 jenkins_sources="${2:-$JENKINS_SOURCES_WORKSPACE}"
15 elf_array=($elf_files)
16 elf=""
17 for index in "${!elf_array[@]}"
18 do
19 if [ "${DEBUG_ELFS}" = "True" ]; then
20 cp "${ELF_FOLDER}/${elf_array[$index]}.elf" ${OUTDIR}/.
21 fi
22 read -r -d '' elf << EOM
23${elf}
24 {
25 "name": "${ELF_FOLDER}/${elf_array[$index]}.elf",
26 "traces": [
27 "${TRACE_FOLDER}/${trace_file_prefix:-covtrace}-*.log"
28 ]
29 }
30EOM
31 if [ $index -lt $((${#elf_array[@]} - 1)) ];then
32 elf="${elf},"
33 fi
34 done
35 if [ "$REPO" = "SCP" ]; then
36 read -r -d '' sources << EOM
37 [
38 {
39 "type": "git",
40 "URL": "$CC_SCP_URL",
41 "COMMIT": "$CC_SCP_COMMIT",
42 "REFSPEC": "$CC_SCP_REFSPEC",
43 "LOCATION": "scp"
44 },
45 {
46 "type": "git",
47 "URL": "$CC_CMSIS_URL",
48 "COMMIT": "$CC_CMSIS_COMMIT",
49 "REFSPEC": "$CC_CMSIS_REFSPEC",
50 "LOCATION": "scp/cmsis"
51 }
52 ]
53EOM
54 elif [ "$REPO" = "TRUSTED_FIRMWARE" ]; then
55 read -r -d '' sources << EOM
56 [
57 {
58 "type": "git",
59 "URL": "$CC_TRUSTED_FIRMWARE_URL",
60 "COMMIT": "$CC_TRUSTED_FIRMWARE_COMMIT",
61 "REFSPEC": "$CC_TRUSTED_FIRMWARE_REFSPEC",
62 "LOCATION": "trusted_firmware"
63 },
64 {
65 "type": "http",
66 "URL": "$mbedtls_archive",
67 "COMPRESSION": "xz",
68 "LOCATION": "mbedtls"
69 }
70 ]
71EOM
72 else
73 sources=""
74 fi
75metadata="\"BUILD_CONFIG\": \"${BUILD_CONFIG}\", \"RUN_CONFIG\": \"${RUN_CONFIG}\""
76cat <<EOF > "${CONFIG_JSON}"
77{
78 "configuration":
79 {
80 "remove_workspace": true,
81 "include_assembly": true
82 },
83 "parameters":
84 {
85 "sources": $sources,
86 "workspace": "${jenkins_sources}",
87 "output_file": "${OUTPUT_JSON}",
88 "metadata": {$metadata}
89 },
90 "elfs": [
91 ${elf}
92 ]
93}
94EOF
95set -e
96}
97
98prepare_html_pages() {
99 pushd ${OUTDIR}
100 cp ${BMCOV_REPORT_FOLDER}/reporter_cc.py ${OUTDIR}/.
101 if [ "${DEBUG_ELFS}" = "True" ]; then
102 cp "${TRACE_FOLDER}/${trace_file_prefix}"* ${OUTDIR}/.
103 fi
104 # to be run on the user locally
105 cat <<EOF > "server.sh"
106#!/bin/bash
107
108echo "Running server..."
109type -a firefox || (echo "Please install Firefox..." && exit 1)
110type -a python3 || (echo "Please install python3..." && exit 1)
111
112python - << EOT
113import os
114import reporter_cc
115
116output_file = os.getenv('OUTPUT_JSON', 'output_file.json')
117source_folder = os.getenv('CSOURCE_FOLDER', 'source')
118r = reporter_cc.ReportCC(output_file)
119r.clone_repo(source_folder)
120EOT
121(sleep 2; firefox --new-window http://localhost:8081) &
122python3 -m http.server 8081
123EOF
124 chmod 777 server.sh
125 zip -r server_side.zip *
126 popd
127}
128
129PVLIB_HOME=${PVLIB_HOME:-$warehouse/SysGen/PVModelLib/$model_version/$model_build/external}
130echo "Building Bmcov for code coverage..."
131source "$CI_ROOT/script/test_definitions.sh"
132export BMCOV_FOLDER="${BMCOV_FOLDER:-$workspace/test-definitions/scripts/tools/code_coverage/fastmodel_baremetal/bmcov}"
133pushd "${workspace}"
134git clone "${TEST_DEFINITIONS_REPO}" -b "${TEST_DEFINITIONS_REFSPEC}"
135popd
136pushd "${BMCOV_FOLDER}"
137export MODEL_PLUGIN_FOLDER="${BMCOV_FOLDER}"/model-plugin
138if [ -n "$(find "$warehouse" -maxdepth 0 -type d -empty 2>/dev/null)" ]; then
139 echo "$warehouse not mounted. Falling back to pre-built plugins.."
140 folder="http://files.oss.arm.com/downloads/tf-a/coverage-plugin"
141 wget -q ${folder}/{CoverageTrace.so,CoverageTrace.o,PluginUtils.o} \
142 -P "${MODEL_PLUGIN_FOLDER}"
143 else
144 make -C model-plugin PVLIB_HOME="$PVLIB_HOME"
145fi
146
147export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$MODEL_PLUGIN_FOLDER
148export trace_file_prefix=covtrace
149export BMCOV_REPORT_FOLDER="${BMCOV_FOLDER}"/report
150export coverage_trace_plugin="${MODEL_PLUGIN_FOLDER}"/CoverageTrace.so
151popd