1 # Copyright (c) 2018 Cisco and/or its affiliates.
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at:
6 # http://www.apache.org/licenses/LICENSE-2.0
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
16 # This library defines functions used mainly by per patch entry scripts.
17 # Generally, the functions assume "common.sh" library has been sourced already.
18 # Keep functions ordered alphabetically, please.
20 function archive_test_results () {
23 # - ${1}: Directory to archive to. Required. Parent has to exist.
25 # - TARGET - Target directory.
27 # - ARCHIVE_DIR - Path to where robot result files are created in.
28 # - VPP_DIR - Path to existing directory, root for to relative paths.
29 # Directories updated:
30 # - ${1} - Created, and robot and parsing files are moved/created there.
32 # - die - Print to stderr and exit, defined in common.sh
36 cd "${VPP_DIR}" || die "Change directory command failed."
37 TARGET="$(readlink -f "$1")"
38 mkdir -p "${TARGET}" || die "Directory creation failed."
39 for filename in "output.xml" "log.html" "report.html"; do
40 mv "${ARCHIVE_DIR}/${filename}" "${TARGET}/${filename}" || {
41 die "Attempt to move '${filename}' failed."
47 function archive_parse_test_results () {
50 # - ${1}: Directory to archive to. Required. Parent has to exist.
52 # - TARGET - Target directory.
54 # - die - Print to stderr and exit, defined in common.sh
55 # - archive_test_results - Archiving results.
56 # - parse_bmrr_results - See definition in this file.
60 archive_test_results "$1" || die
61 parse_bmrr_results "${TARGET}" || {
62 die "The function should have died on error."
67 function build_vpp_ubuntu_amd64 () {
69 # This function is using make pkg-verify to build VPP with all dependencies
70 # that is ARCH/OS aware. VPP repo is SSOT for building mechanics and CSIT
71 # is consuming artifacts. This way if VPP will introduce change in building
72 # mechanics they will not be blocked by CSIT repo.
74 # - ${1} - String identifier for echo, can be unset.
76 # - VPP_DIR - Path to existing directory, parent to accessed directories.
77 # Directories updated:
78 # - ${VPP_DIR} - Whole subtree, many files (re)created by the build process.
80 # - die - Print to stderr and exit, defined in common.sh
84 cd "${VPP_DIR}" || die "Change directory command failed."
85 make UNATTENDED=y pkg-verify || die "VPP build using make pkg-verify failed."
86 echo "* VPP ${1-} BUILD SUCCESSFULLY COMPLETED" || {
87 die "Argument not found."
92 function compare_test_results () {
95 # - VPP_DIR - Path to directory with VPP git repo (at least built parts).
96 # - ARCHIVE_DIR - Path to where robot result files are created in.
97 # - PYTHON_SCRIPTS_DIR - Path to directory holding comparison utility.
98 # Directories recreated:
99 # - csit_parent - Sibling to csit directory, for holding results
102 # - die - Print to stderr and exit, defined in common.sh
103 # - parse_bmrr_results - See definition in this file.
105 # - 0 - If the comparison utility sees no regression (nor data error).
106 # - 1 - If the comparison utility sees a regression (or data error).
110 cd "${VPP_DIR}" || die "Change directory operation failed."
111 # Ply is installed as system level package, but not seen for some reason.
112 pip3 install -r "${PYTHON_SCRIPTS_DIR}/perpatch_requirements.txt" || {
113 die "Compare script Python requirements installation failed."
115 # Reusing CSIT main virtualenv.
116 python3 "${TOOLS_DIR}/integrated/compare_perpatch.py"
117 # The exit code determines the vote result.
121 function download_builds () {
123 # This is mostly useful only for Sandbox testing, to avoid recompilation.
126 # - ${1} - URL to download VPP builds from.
128 # - VPP_DIR - Path to WORKSPACE, parent of created directories.
129 # Directories created:
130 # - archive - Ends up empty, not to be confused with ${ARCHIVE_DIR}.
131 # - build_current - Holding built artifacts of the patch under test (PUT).
132 # - built_parent - Holding built artifacts of parent of PUT.
134 # - die - Print to stderr and exit, defined in common.sh
138 cd "${VPP_DIR}" || die "Change directory operation failed."
139 dirs=("build-root" "build_parent" "build_current" "archive" "csit_current")
140 rm -rf ${dirs[@]} || {
141 die "Directory removal failed."
143 wget -N --progress=dot:giga "${1}" || die "Wget download failed."
144 unzip "archive.zip" || die "Archive extraction failed."
145 mv "archive/build_parent" ./ || die "Move operation failed."
146 mv "archive/build_current" ./ || die "Move operation failed."
150 function initialize_csit_dirs () {
152 # This could be in prepare_test, but download_builds also needs this.
155 # - VPP_DIR - Path to WORKSPACE, parent of created directories.
156 # Directories created:
157 # - csit_current - Holding test results of the patch under test (PUT).
158 # - csit_parent - Holding test results of parent of PUT.
160 # - die - Print to stderr and exit, defined in common.sh
164 cd "${VPP_DIR}" || die "Change directory operation failed."
165 rm -rf "csit_current" "csit_parent" || {
166 die "Directory deletion failed."
168 mkdir -p "csit_current" "csit_parent" || {
169 die "Directory creation failed."
174 function parse_bmrr_results () {
176 # Currently "parsing" is just two greps.
177 # TODO: Re-use PAL parsing code, make parsing more general and centralized.
180 # - ${1} - Path to (existing) directory holding robot output.xml result.
182 # - output.xml - From argument location.
184 # - results.txt - (Re)created, in argument location.
186 # - die - Print to stderr and exit, defined in common.sh
190 rel_dir="$(readlink -e "${1}")" || die "Readlink failed."
191 in_file="${rel_dir}/output.xml"
192 out_file="${rel_dir}/results.txt"
193 # TODO: Do we need to check echo exit code explicitly?
194 echo "Parsing ${in_file} putting results into ${out_file}"
195 echo "TODO: Re-use parts of PAL when they support subsample test parsing."
196 pattern='Maximum Receive Rate trial results in packets'
197 pattern+=' per second: .*\]</status>'
198 grep -o "${pattern}" "${in_file}" | grep -o '\[.*\]' > "${out_file}" || {
199 die "Some parsing grep command has failed."
204 function select_build () {
207 # - ${1} - Path to directory to copy VPP artifacts from. Required.
209 # - DOWNLOAD_DIR - Path to directory where Robot takes builds to test from.
210 # - VPP_DIR - Path to existing directory, root for relative paths.
212 # - ${1} - Existing directory with built new VPP artifacts (and DPDK).
213 # Directories updated:
214 # - ${DOWNLOAD_DIR} - Old content removed, .deb files from ${1} copied here.
216 # - die - Print to stderr and exit, defined in common.sh
220 cd "${VPP_DIR}" || die "Change directory operation failed."
221 source_dir="$(readlink -e "$1")"
222 rm -rf "${DOWNLOAD_DIR}"/* || die "Cleanup of download dir failed."
223 cp "${source_dir}"/*".deb" "${DOWNLOAD_DIR}" || die "Copy operation failed."
224 # TODO: Is there a nice way to create symlinks,
225 # so that if job fails on robot, results can be archived?
229 function set_aside_commit_build_artifacts () {
231 # Function is copying VPP built artifacts from actual checkout commit for
232 # further use and clean git.
234 # - VPP_DIR - Path to existing directory, parent to accessed directories.
236 # - build-root - Existing directory with built VPP artifacts (also DPDK).
237 # Directories updated:
238 # - ${VPP_DIR} - A local git repository, parent commit gets checked out.
239 # - build_current - Old contents removed, content of build-root copied here.
241 # - die - Print to stderr and exit, defined in common.sh
245 cd "${VPP_DIR}" || die "Change directory operation failed."
246 rm -rf "build_current" || die "Remove operation failed."
247 mkdir -p "build_current" || die "Directory creation failed."
248 mv "build-root"/*".deb" "build_current"/ || die "Move operation failed."
249 # The previous build could have left some incompatible leftovers,
250 # e.g. DPDK artifacts of different version (in build/external).
251 # Also, there usually is a copy of dpdk artifact in build-root.
252 git clean -dffx "build"/ "build-root"/ || die "Git clean operation failed."
253 # Finally, check out the parent commit.
254 git checkout HEAD~ || die "Git checkout operation failed."
255 # Display any other leftovers.
256 git status || die "Git status operation failed."
260 function set_aside_parent_build_artifacts () {
262 # Function is copying VPP built artifacts from parent checkout commit for
263 # further use. Checkout to parent is not part of this function.
265 # - VPP_DIR - Path to existing directory, parent of accessed directories.
267 # - build-root - Existing directory with built VPP artifacts (also DPDK).
268 # Directories updated:
269 # - build_parent - Old directory removed, build-root debs moved here.
271 # - die - Print to stderr and exit, defined in common.sh
275 cd "${VPP_DIR}" || die "Change directory operation failed."
276 rm -rf "build_parent" || die "Remove failed."
277 mkdir -p "build_parent" || die "Directory creation operation failed."
278 mv "build-root"/*".deb" "build_parent"/ || die "Move operation failed."
282 function set_perpatch_dut () {
285 # - DUT - CSIT test/ subdirectory containing suites to execute.
287 # TODO: Detect DUT from job name, when we have more than just VPP perpatch.
295 function set_perpatch_vpp_dir () {
298 # - CSIT_DIR - Path to existing root of local CSIT git repository.
300 # - VPP_DIR - Path to existing root of local VPP git repository.
302 # - die - Print to stderr and exit, defined in common.sh
306 # In perpatch, CSIT is cloned inside VPP clone.
307 VPP_DIR="$(readlink -e "${CSIT_DIR}/..")" || die "Readlink failed."