1 # Copyright (c) 2020 Cisco and/or its affiliates.
2 # Copyright (c) 2020 PANTHEON.tech s.r.o.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at:
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
17 # This library defines functions used mainly by per patch entry scripts.
18 # Generally, the functions assume "common.sh" library has been sourced already.
19 # Keep functions ordered alphabetically, please.
21 function archive_test_results () {
24 # - ${1}: Directory to archive to. Required. Parent has to exist.
26 # - TARGET - Target directory.
28 # - ARCHIVE_DIR - Path to where robot result files are created in.
29 # - VPP_DIR - Path to existing directory, root for to relative paths.
30 # Directories updated:
31 # - ${1} - Created, and robot and parsing files are moved/created there.
33 # - die - Print to stderr and exit, defined in common.sh
37 cd "${VPP_DIR}" || die "Change directory command failed."
38 TARGET="$(readlink -f "$1")"
39 mkdir -p "${TARGET}" || die "Directory creation failed."
40 for filename in "output.xml" "log.html" "report.html"; do
41 mv "${ARCHIVE_DIR}/${filename}" "${TARGET}/${filename}" || {
42 die "Attempt to move '${filename}' failed."
48 function archive_parse_test_results () {
51 # - ${1}: Directory to archive to. Required. Parent has to exist.
53 # - TARGET - Target directory.
55 # - die - Print to stderr and exit, defined in common.sh
56 # - archive_test_results - Archiving results.
57 # - parse_bmrr_results - See definition in this file.
61 archive_test_results "$1" || die
62 parse_bmrr_results "${TARGET}" || {
63 die "The function should have died on error."
68 function build_vpp_ubuntu_amd64 () {
70 # This function is using make pkg-verify to build VPP with all dependencies
71 # that is ARCH/OS aware. VPP repo is SSOT for building mechanics and CSIT
72 # is consuming artifacts. This way if VPP will introduce change in building
73 # mechanics they will not be blocked by CSIT repo.
75 # - ${1} - String identifier for echo, can be unset.
77 # - MAKE_PARALLEL_FLAGS - Make flags when building VPP.
78 # - MAKE_PARALLEL_JOBS - Number of cores to use when building VPP.
79 # - VPP_DIR - Path to existing directory, parent to accessed directories.
80 # Directories updated:
81 # - ${VPP_DIR} - Whole subtree, many files (re)created by the build process.
83 # - die - Print to stderr and exit, defined in common.sh
87 cd "${VPP_DIR}" || die "Change directory command failed."
88 if [ -n "${MAKE_PARALLEL_FLAGS-}" ]; then
89 echo "Building VPP. Number of cores for build set with" \
90 "MAKE_PARALLEL_FLAGS='${MAKE_PARALLEL_FLAGS}'."
91 elif [ -n "${MAKE_PARALLEL_JOBS-}" ]; then
92 echo "Building VPP. Number of cores for build set with" \
93 "MAKE_PARALLEL_JOBS='${MAKE_PARALLEL_JOBS}'."
95 echo "Building VPP. Number of cores not set, " \
96 "using build default ($(grep -c ^processor /proc/cpuinfo))."
99 make UNATTENDED=y pkg-verify || die "VPP build using make pkg-verify failed."
100 echo "* VPP ${1-} BUILD SUCCESSFULLY COMPLETED" || {
101 die "Argument not found."
106 function compare_test_results () {
109 # - VPP_DIR - Path to directory with VPP git repo (at least built parts).
110 # - ARCHIVE_DIR - Path to where robot result files are created in.
111 # - PYTHON_SCRIPTS_DIR - Path to directory holding comparison utility.
112 # Directories recreated:
113 # - csit_parent - Sibling to csit directory, for holding results
116 # - die - Print to stderr and exit, defined in common.sh
117 # - parse_bmrr_results - See definition in this file.
119 # - 0 - If the comparison utility sees no regression (nor data error).
120 # - 1 - If the comparison utility sees a regression (or data error).
124 cd "${VPP_DIR}" || die "Change directory operation failed."
125 # Reusing CSIT main virtualenv.
126 python3 "${TOOLS_DIR}/integrated/compare_perpatch.py"
127 # The exit code determines the vote result.
131 function initialize_csit_dirs () {
136 # - VPP_DIR - Path to WORKSPACE, parent of created directories.
137 # Directories created:
138 # - csit_current - Holding test results of the patch under test (PUT).
139 # - csit_parent - Holding test results of parent of PUT.
141 # - die - Print to stderr and exit, defined in common.sh
145 cd "${VPP_DIR}" || die "Change directory operation failed."
146 rm -rf "csit_current" "csit_parent" || {
147 die "Directory deletion failed."
149 mkdir -p "csit_current" "csit_parent" || {
150 die "Directory creation failed."
155 function parse_bmrr_results () {
157 # Currently "parsing" is just two greps.
158 # TODO: Re-use PAL parsing code, make parsing more general and centralized.
161 # - ${1} - Path to (existing) directory holding robot output.xml result.
163 # - output.xml - From argument location.
165 # - results.txt - (Re)created, in argument location.
167 # - die - Print to stderr and exit, defined in common.sh
171 rel_dir="$(readlink -e "${1}")" || die "Readlink failed."
172 in_file="${rel_dir}/output.xml"
173 out_file="${rel_dir}/results.txt"
174 # TODO: Do we need to check echo exit code explicitly?
175 echo "Parsing ${in_file} putting results into ${out_file}"
176 echo "TODO: Re-use parts of PAL when they support subsample test parsing."
177 pattern='Maximum Receive Rate trial results in packets'
178 pattern+=' per second: .*\]</status>'
179 grep -o "${pattern}" "${in_file}" | grep -o '\[.*\]' > "${out_file}" || {
180 die "Some parsing grep command has failed."
185 function select_build () {
188 # - ${1} - Path to directory to copy VPP artifacts from. Required.
190 # - DOWNLOAD_DIR - Path to directory where Robot takes builds to test from.
191 # - VPP_DIR - Path to existing directory, root for relative paths.
193 # - ${1} - Existing directory with built new VPP artifacts (and DPDK).
194 # Directories updated:
195 # - ${DOWNLOAD_DIR} - Old content removed, .deb files from ${1} copied here.
197 # - die - Print to stderr and exit, defined in common.sh
201 cd "${VPP_DIR}" || die "Change directory operation failed."
202 source_dir="$(readlink -e "$1")"
203 rm -rf "${DOWNLOAD_DIR}"/* || die "Cleanup of download dir failed."
204 cp "${source_dir}"/*".deb" "${DOWNLOAD_DIR}" || die "Copy operation failed."
205 # TODO: Is there a nice way to create symlinks,
206 # so that if job fails on robot, results can be archived?
210 function set_aside_commit_build_artifacts () {
212 # Function is copying VPP built artifacts from actual checkout commit for
213 # further use and clean git.
215 # - VPP_DIR - Path to existing directory, parent to accessed directories.
217 # - build-root - Existing directory with built VPP artifacts (also DPDK).
218 # Directories updated:
219 # - ${VPP_DIR} - A local git repository, parent commit gets checked out.
220 # - build_current - Old contents removed, content of build-root copied here.
222 # - die - Print to stderr and exit, defined in common.sh
226 cd "${VPP_DIR}" || die "Change directory operation failed."
227 rm -rf "build_current" || die "Remove operation failed."
228 mkdir -p "build_current" || die "Directory creation failed."
229 mv "build-root"/*".deb" "build_current"/ || die "Move operation failed."
230 # The previous build could have left some incompatible leftovers,
231 # e.g. DPDK artifacts of different version (in build/external).
232 # Also, there usually is a copy of dpdk artifact in build-root.
233 git clean -dffx "build"/ "build-root"/ || die "Git clean operation failed."
234 # Finally, check out the parent commit.
235 git checkout HEAD~ || die "Git checkout operation failed."
236 # Display any other leftovers.
237 git status || die "Git status operation failed."
241 function set_aside_parent_build_artifacts () {
243 # Function is copying VPP built artifacts from parent checkout commit for
244 # further use. Checkout to parent is not part of this function.
246 # - VPP_DIR - Path to existing directory, parent of accessed directories.
248 # - build-root - Existing directory with built VPP artifacts (also DPDK).
249 # Directories updated:
250 # - build_parent - Old directory removed, build-root debs moved here.
252 # - die - Print to stderr and exit, defined in common.sh
256 cd "${VPP_DIR}" || die "Change directory operation failed."
257 rm -rf "build_parent" || die "Remove failed."
258 mkdir -p "build_parent" || die "Directory creation operation failed."
259 mv "build-root"/*".deb" "build_parent"/ || die "Move operation failed."
263 function set_perpatch_dut () {
266 # - DUT - CSIT test/ subdirectory containing suites to execute.
268 # TODO: Detect DUT from job name, when we have more than just VPP perpatch.
276 function set_perpatch_vpp_dir () {
279 # - CSIT_DIR - Path to existing root of local CSIT git repository.
281 # - VPP_DIR - Path to existing root of local VPP git repository.
283 # - die - Print to stderr and exit, defined in common.sh
287 # In perpatch, CSIT is cloned inside VPP clone.
288 VPP_DIR="$(readlink -e "${CSIT_DIR}/..")" || die "Readlink failed."