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_perf.sh" entry script.
17 # Generally, the functions assume "common.sh" library has been sourced already.
19 # Keep functions ordered alphabetically, please.
21 # TODO: Add a link to bash style guide.
24 function archive_parse_test_results () {
29 # - ${1}: Directory to archive to. Required. Parent has to exist.
31 # - ARCHIVE_DIR - Path to where robot result files are created in.
32 # - VPP_DIR - Path to existing directory, root for to relative paths.
33 # Directories updated:
34 # - ${1} - Created, and robot and parsing files are moved/created there.
36 # - die - Print to stderr and exit, defined in common.sh
37 # - parse_bmrr_results - See definition in this file.
39 cd "${VPP_DIR}" || die "Change directory command failed."
40 target="$(readlink -f "$1")"
41 mkdir -p "${target}" || die "Directory creation failed."
42 for filename in "output.xml" "log.html" "report.html"; do
43 mv "${ARCHIVE_DIR}/${filename}" "${target}/${filename}" || {
44 die "Attempt to move '${filename}' failed."
47 parse_bmrr_results "${target}" || {
48 die "The function should have died on error."
53 function build_vpp_ubuntu_amd64 () {
57 # This function is using Vagrant script to build VPP with all dependencies
58 # that is ARCH/OS aware. VPP repo is SSOT for building mechanics and CSIT
59 # is consuming artifacts. This way if VPP will introduce change in building
60 # mechanics they will not be blocked by CSIT repo.
62 # - ${1} - String identifier for echo, can be unset.
64 # - VPP_DIR - Path to existing directory, parent to accessed directories.
65 # Directories updated:
66 # - ${VPP_DIR} - Whole subtree, many files (re)created by the build process.
68 # - die - Print to stderr and exit, defined in common.sh
70 cd "${VPP_DIR}" || die "Change directory command failed."
71 echo 'Building using "make build-root/vagrant/build.sh"'
72 build-root/vagrant/"build.sh" || die "Vagrant VPP build script failed."
73 echo "*******************************************************************"
74 echo "* VPP ${1-} BUILD SUCCESSFULLY COMPLETED" || {
75 die "Argument not found."
77 echo "*******************************************************************"
81 function compare_test_results () {
86 # - VPP_DIR - Path to directory with VPP git repo (at least built parts).
87 # - ARCHIVE_DIR - Path to where robot result files are created in.
88 # - PYTHON_SCRIPTS_DIR - Path to directory holding comparison utility.
89 # Directories recreated:
90 # - csit_parent - Sibling to csit directory, for holding results
93 # - die - Print to stderr and exit, defined in common.sh
94 # - parse_bmrr_results - See definition in this file.
96 # - 0 - If the comparison utility sees no regression (nor data error).
97 # - 1 - If the comparison utility sees a regression (or data error).
99 cd "${VPP_DIR}" || die "Change directory operation failed."
100 # Reusing CSIT main virtualenv.
101 pip install -r "${PYTHON_SCRIPTS_DIR}/perpatch_requirements.txt" || {
102 die "Perpatch Python requirements installation failed."
104 python "${PYTHON_SCRIPTS_DIR}/compare_perpatch.py"
105 # The exit code determines the vote result.
109 function download_builds () {
113 # This is mostly useful only for Sandbox testing, to avoid recompilation.
116 # - ${1} - URL to download VPP builds from.
118 # - VPP_DIR - Path to WORKSPACE, parent of created directories.
119 # Directories created:
120 # - archive - Ends up empty, not to be confused with ${ARCHIVE_DIR}.
121 # - build_current - Holding built artifacts of the patch under test (PUT).
122 # - built_parent - Holding built artifacts of parent of PUT.
124 # - die - Print to stderr and exit, defined in common.sh
126 cd "${VPP_DIR}" || die "Change directory operation failed."
127 dirs=("build-root" "build_parent" "build_current" "archive" "csit_current")
128 rm -rf ${dirs[@]} || {
129 die "Directory removal failed."
131 wget -N --progress=dot:giga "${1}" || die "Wget download failed."
132 unzip "archive.zip" || die "Archive extraction failed."
133 mv "archive/build_parent" ./ || die "Move operation failed."
134 mv "archive/build_current" ./ || die "Move operation failed."
138 function initialize_csit_dirs () {
142 # This could be in prepare_test, but download_builds also needs this.
145 # - VPP_DIR - Path to WORKSPACE, parent of created directories.
146 # Directories created:
147 # - csit_current - Holding test results of the patch under test (PUT).
148 # - csit_parent - Holding test results of parent of PUT.
150 # - die - Print to stderr and exit, defined in common.sh
152 cd "${VPP_DIR}" || die "Change directory operation failed."
153 rm -rf "csit_current" "csit_parent" || {
154 die "Directory deletion failed."
156 mkdir -p "csit_current" "csit_parent" || {
157 die "Directory creation failed."
162 function parse_bmrr_results () {
166 # Currently "parsing" is just two greps.
167 # TODO: Re-use PAL parsing code, make parsing more general and centralized.
170 # - ${1} - Path to (existing) directory holding robot output.xml result.
172 # - output.xml - From argument location.
174 # - results.txt - (Re)created, in argument location.
176 # - die - Print to stderr and exit, defined in common.sh
178 rel_dir="$(readlink -e "${1}")" || die "Readlink failed."
179 in_file="${rel_dir}/output.xml"
180 out_file="${rel_dir}/results.txt"
181 # TODO: Do we need to check echo exit code explicitly?
182 echo "Parsing ${in_file} putting results into ${out_file}"
183 echo "TODO: Re-use parts of PAL when they support subsample test parsing."
184 pattern='Maximum Receive Rate trial results in packets'
185 pattern+=' per second: .*\]</status>'
186 grep -o "${pattern}" "${in_file}" | grep -o '\[.*\]' > "${out_file}" || {
187 die "Some parsing grep command has failed."
192 function select_build () {
197 # - ${1} - Path to directory to copy VPP artifacts from. Required.
199 # - DOWNLOAD_DIR - Path to directory where Robot takes builds to test from.
200 # - VPP_DIR - Path to existing directory, root for relative paths.
202 # - ${1} - Existing directory with built new VPP artifacts (and DPDK).
203 # Directories updated:
204 # - ${DOWNLOAD_DIR} - Old content removed, .deb files from ${1} copied here.
206 # - die - Print to stderr and exit, defined in common.sh
208 cd "${VPP_DIR}" || die "Change directory operation failed."
209 source_dir="$(readlink -e "$1")"
210 rm -rf "${DOWNLOAD_DIR}"/* || die "Cleanup of download dir failed."
211 cp "${source_dir}"/*".deb" "${DOWNLOAD_DIR}" || die "Copy operation failed."
212 # TODO: Is there a nice way to create symlinks,
213 # so that if job fails on robot, results can be archived?
217 function set_aside_commit_build_artifacts () {
221 # Function is copying VPP built artifacts from actual checkout commit for
222 # further use and clean git.
224 # - VPP_DIR - Path to existing directory, parent to accessed directories.
226 # - build-root - Existing directory with built VPP artifacts (also DPDK).
227 # Directories updated:
228 # - ${VPP_DIR} - A local git repository, parent commit gets checked out.
229 # - build_current - Old contents removed, content of build-root copied here.
231 # - die - Print to stderr and exit, defined in common.sh
233 cd "${VPP_DIR}" || die "Change directory operation failed."
234 rm -rf "build_current" || die "Remove operation failed."
235 mkdir -p "build_current" || die "Directory creation failed."
236 mv "build-root"/*".deb" "build_current"/ || die "Move operation failed."
237 # The previous build could have left some incompatible leftovers,
238 # e.g. DPDK artifacts of different version (in build/external).
239 # Also, there usually is a copy of dpdk artifact in build-root.
240 git clean -dffx "build"/ "build-root"/ || die "Git clean operation failed."
241 # Finally, check out the parent commit.
242 git checkout HEAD~ || die "Git checkout operation failed."
243 # Display any other leftovers.
244 git status || die "Git status operation failed."
248 function set_aside_parent_build_artifacts () {
252 # Function is copying VPP built artifacts from parent checkout commit for
253 # further use. Checkout to parent is not part of this function.
255 # - VPP_DIR - Path to existing directory, parent of accessed directories.
257 # - build-root - Existing directory with built VPP artifacts (also DPDK).
258 # Directories updated:
259 # - build_parent - Old directory removed, build-root debs moved here.
261 # - die - Print to stderr and exit, defined in common.sh
263 cd "${VPP_DIR}" || die "Change directory operation failed."
264 rm -rf "build_parent" || die "Remove failed."
265 mkdir -p "build_parent" || die "Directory creation operation failed."
266 mv "build-root"/*".deb" "build_parent"/ || die "Move operation failed."
270 function set_perpatch_dut () {
275 # - DUT - CSIT test/ subdirectory containing suites to execute.
277 # TODO: Detect DUT from job name, when we have more than just VPP perpatch.
283 function set_perpatch_vpp_dir () {
288 # - CSIT_DIR - Path to existing root of local CSIT git repository.
290 # - VPP_DIR - Path to existing root of local VPP git repository.
292 # - die - Print to stderr and exit, defined in common.sh
294 # In perpatch, CSIT is cloned inside VPP clone.
295 VPP_DIR="$(readlink -e "${CSIT_DIR}/..")" || die "Readlink failed."