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 download_builds () {
133 # This is mostly useful only for Sandbox testing, to avoid recompilation.
136 # - ${1} - URL to download VPP builds from.
138 # - VPP_DIR - Path to WORKSPACE, parent of created directories.
139 # Directories created:
140 # - archive - Ends up empty, not to be confused with ${ARCHIVE_DIR}.
141 # - build_current - Holding built artifacts of the patch under test (PUT).
142 # - built_parent - Holding built artifacts of parent of PUT.
144 # - die - Print to stderr and exit, defined in common.sh
148 cd "${VPP_DIR}" || die "Change directory operation failed."
149 dirs=("build-root" "build_parent" "build_current" "archive" "csit_current")
150 rm -rf ${dirs[@]} || {
151 die "Directory removal failed."
153 wget -N --progress=dot:giga "${1}" || die "Wget download failed."
154 unzip "archive.zip" || die "Archive extraction failed."
155 mv "archive/build_parent" ./ || die "Move operation failed."
156 mv "archive/build_current" ./ || die "Move operation failed."
160 function initialize_csit_dirs () {
162 # This could be in prepare_test, but download_builds also needs this.
165 # - VPP_DIR - Path to WORKSPACE, parent of created directories.
166 # Directories created:
167 # - csit_current - Holding test results of the patch under test (PUT).
168 # - csit_parent - Holding test results of parent of PUT.
170 # - die - Print to stderr and exit, defined in common.sh
174 cd "${VPP_DIR}" || die "Change directory operation failed."
175 rm -rf "csit_current" "csit_parent" || {
176 die "Directory deletion failed."
178 mkdir -p "csit_current" "csit_parent" || {
179 die "Directory creation failed."
184 function parse_bmrr_results () {
186 # Currently "parsing" is just two greps.
187 # TODO: Re-use PAL parsing code, make parsing more general and centralized.
190 # - ${1} - Path to (existing) directory holding robot output.xml result.
192 # - output.xml - From argument location.
194 # - results.txt - (Re)created, in argument location.
196 # - die - Print to stderr and exit, defined in common.sh
200 rel_dir="$(readlink -e "${1}")" || die "Readlink failed."
201 in_file="${rel_dir}/output.xml"
202 out_file="${rel_dir}/results.txt"
203 # TODO: Do we need to check echo exit code explicitly?
204 echo "Parsing ${in_file} putting results into ${out_file}"
205 echo "TODO: Re-use parts of PAL when they support subsample test parsing."
206 pattern='Maximum Receive Rate trial results in packets'
207 pattern+=' per second: .*\]</status>'
208 grep -o "${pattern}" "${in_file}" | grep -o '\[.*\]' > "${out_file}" || {
209 die "Some parsing grep command has failed."
214 function select_build () {
217 # - ${1} - Path to directory to copy VPP artifacts from. Required.
219 # - DOWNLOAD_DIR - Path to directory where Robot takes builds to test from.
220 # - VPP_DIR - Path to existing directory, root for relative paths.
222 # - ${1} - Existing directory with built new VPP artifacts (and DPDK).
223 # Directories updated:
224 # - ${DOWNLOAD_DIR} - Old content removed, .deb files from ${1} copied here.
226 # - die - Print to stderr and exit, defined in common.sh
230 cd "${VPP_DIR}" || die "Change directory operation failed."
231 source_dir="$(readlink -e "$1")"
232 rm -rf "${DOWNLOAD_DIR}"/* || die "Cleanup of download dir failed."
233 cp "${source_dir}"/*".deb" "${DOWNLOAD_DIR}" || die "Copy operation failed."
234 # TODO: Is there a nice way to create symlinks,
235 # so that if job fails on robot, results can be archived?
239 function set_aside_commit_build_artifacts () {
241 # Function is copying VPP built artifacts from actual checkout commit for
242 # further use and clean git.
244 # - VPP_DIR - Path to existing directory, parent to accessed directories.
246 # - build-root - Existing directory with built VPP artifacts (also DPDK).
247 # Directories updated:
248 # - ${VPP_DIR} - A local git repository, parent commit gets checked out.
249 # - build_current - Old contents removed, content of build-root copied here.
251 # - die - Print to stderr and exit, defined in common.sh
255 cd "${VPP_DIR}" || die "Change directory operation failed."
256 rm -rf "build_current" || die "Remove operation failed."
257 mkdir -p "build_current" || die "Directory creation failed."
258 mv "build-root"/*".deb" "build_current"/ || die "Move operation failed."
259 # The previous build could have left some incompatible leftovers,
260 # e.g. DPDK artifacts of different version (in build/external).
261 # Also, there usually is a copy of dpdk artifact in build-root.
262 git clean -dffx "build"/ "build-root"/ || die "Git clean operation failed."
263 # Finally, check out the parent commit.
264 git checkout HEAD~ || die "Git checkout operation failed."
265 # Display any other leftovers.
266 git status || die "Git status operation failed."
270 function set_aside_parent_build_artifacts () {
272 # Function is copying VPP built artifacts from parent checkout commit for
273 # further use. Checkout to parent is not part of this function.
275 # - VPP_DIR - Path to existing directory, parent of accessed directories.
277 # - build-root - Existing directory with built VPP artifacts (also DPDK).
278 # Directories updated:
279 # - build_parent - Old directory removed, build-root debs moved here.
281 # - die - Print to stderr and exit, defined in common.sh
285 cd "${VPP_DIR}" || die "Change directory operation failed."
286 rm -rf "build_parent" || die "Remove failed."
287 mkdir -p "build_parent" || die "Directory creation operation failed."
288 mv "build-root"/*".deb" "build_parent"/ || die "Move operation failed."
292 function set_perpatch_dut () {
295 # - DUT - CSIT test/ subdirectory containing suites to execute.
297 # TODO: Detect DUT from job name, when we have more than just VPP perpatch.
305 function set_perpatch_vpp_dir () {
308 # - CSIT_DIR - Path to existing root of local CSIT git repository.
310 # - VPP_DIR - Path to existing root of local VPP git repository.
312 # - die - Print to stderr and exit, defined in common.sh
316 # In perpatch, CSIT is cloned inside VPP clone.
317 VPP_DIR="$(readlink -e "${CSIT_DIR}/..")" || die "Readlink failed."