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.
19 # Keep functions ordered alphabetically, please.
21 function archive_test_results () {
26 # - ${1}: Directory to archive to. Required. Parent has to exist.
28 # - TARGET - Target directory.
30 # - ARCHIVE_DIR - Path to where robot result files are created in.
31 # - VPP_DIR - Path to existing directory, root for to relative paths.
32 # Directories updated:
33 # - ${1} - Created, and robot and parsing files are moved/created there.
35 # - 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 () {
53 # - ${1}: Directory to archive to. Required. Parent has to exist.
55 # - TARGET - Target directory.
57 # - die - Print to stderr and exit, defined in common.sh
58 # - archive_test_results - Archiving results.
59 # - 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 () {
72 # This function is using Vagrant script to build VPP with all dependencies
73 # that is ARCH/OS aware. VPP repo is SSOT for building mechanics and CSIT
74 # is consuming artifacts. This way if VPP will introduce change in building
75 # mechanics they will not be blocked by CSIT repo.
77 # - ${1} - String identifier for echo, can be unset.
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
85 cd "${VPP_DIR}" || die "Change directory command failed."
86 echo 'Building using "make build-root/vagrant/build.sh"'
87 build-root/vagrant/"build.sh" || die "Vagrant VPP build script failed."
88 echo "*******************************************************************"
89 echo "* VPP ${1-} BUILD SUCCESSFULLY COMPLETED" || {
90 die "Argument not found."
92 echo "*******************************************************************"
96 function compare_test_results () {
101 # - VPP_DIR - Path to directory with VPP git repo (at least built parts).
102 # - ARCHIVE_DIR - Path to where robot result files are created in.
103 # - PYTHON_SCRIPTS_DIR - Path to directory holding comparison utility.
104 # Directories recreated:
105 # - csit_parent - Sibling to csit directory, for holding results
108 # - die - Print to stderr and exit, defined in common.sh
109 # - parse_bmrr_results - See definition in this file.
111 # - 0 - If the comparison utility sees no regression (nor data error).
112 # - 1 - If the comparison utility sees a regression (or data error).
114 cd "${VPP_DIR}" || die "Change directory operation failed."
115 # Reusing CSIT main virtualenv.
116 pip install -r "${PYTHON_SCRIPTS_DIR}/perpatch_requirements.txt" || {
117 die "Perpatch Python requirements installation failed."
119 python "${PYTHON_SCRIPTS_DIR}/compare_perpatch.py"
120 # The exit code determines the vote result.
124 function download_builds () {
128 # This is mostly useful only for Sandbox testing, to avoid recompilation.
131 # - ${1} - URL to download VPP builds from.
133 # - VPP_DIR - Path to WORKSPACE, parent of created directories.
134 # Directories created:
135 # - archive - Ends up empty, not to be confused with ${ARCHIVE_DIR}.
136 # - build_current - Holding built artifacts of the patch under test (PUT).
137 # - built_parent - Holding built artifacts of parent of PUT.
139 # - die - Print to stderr and exit, defined in common.sh
141 cd "${VPP_DIR}" || die "Change directory operation failed."
142 dirs=("build-root" "build_parent" "build_current" "archive" "csit_current")
143 rm -rf ${dirs[@]} || {
144 die "Directory removal failed."
146 wget -N --progress=dot:giga "${1}" || die "Wget download failed."
147 unzip "archive.zip" || die "Archive extraction failed."
148 mv "archive/build_parent" ./ || die "Move operation failed."
149 mv "archive/build_current" ./ || die "Move operation failed."
153 function initialize_csit_dirs () {
157 # This could be in prepare_test, but download_builds also needs this.
160 # - VPP_DIR - Path to WORKSPACE, parent of created directories.
161 # Directories created:
162 # - csit_current - Holding test results of the patch under test (PUT).
163 # - csit_parent - Holding test results of parent of PUT.
165 # - die - Print to stderr and exit, defined in common.sh
167 cd "${VPP_DIR}" || die "Change directory operation failed."
168 rm -rf "csit_current" "csit_parent" || {
169 die "Directory deletion failed."
171 mkdir -p "csit_current" "csit_parent" || {
172 die "Directory creation failed."
177 function parse_bmrr_results () {
181 # Currently "parsing" is just two greps.
182 # TODO: Re-use PAL parsing code, make parsing more general and centralized.
185 # - ${1} - Path to (existing) directory holding robot output.xml result.
187 # - output.xml - From argument location.
189 # - results.txt - (Re)created, in argument location.
191 # - die - Print to stderr and exit, defined in common.sh
193 rel_dir="$(readlink -e "${1}")" || die "Readlink failed."
194 in_file="${rel_dir}/output.xml"
195 out_file="${rel_dir}/results.txt"
196 # TODO: Do we need to check echo exit code explicitly?
197 echo "Parsing ${in_file} putting results into ${out_file}"
198 echo "TODO: Re-use parts of PAL when they support subsample test parsing."
199 pattern='Maximum Receive Rate trial results in packets'
200 pattern+=' per second: .*\]</status>'
201 grep -o "${pattern}" "${in_file}" | grep -o '\[.*\]' > "${out_file}" || {
202 die "Some parsing grep command has failed."
207 function select_build () {
212 # - ${1} - Path to directory to copy VPP artifacts from. Required.
214 # - DOWNLOAD_DIR - Path to directory where Robot takes builds to test from.
215 # - VPP_DIR - Path to existing directory, root for relative paths.
217 # - ${1} - Existing directory with built new VPP artifacts (and DPDK).
218 # Directories updated:
219 # - ${DOWNLOAD_DIR} - Old content removed, .deb files from ${1} copied here.
221 # - die - Print to stderr and exit, defined in common.sh
223 cd "${VPP_DIR}" || die "Change directory operation failed."
224 source_dir="$(readlink -e "$1")"
225 rm -rf "${DOWNLOAD_DIR}"/* || die "Cleanup of download dir failed."
226 cp "${source_dir}"/*".deb" "${DOWNLOAD_DIR}" || die "Copy operation failed."
227 # TODO: Is there a nice way to create symlinks,
228 # so that if job fails on robot, results can be archived?
232 function set_aside_commit_build_artifacts () {
236 # Function is copying VPP built artifacts from actual checkout commit for
237 # further use and clean git.
239 # - VPP_DIR - Path to existing directory, parent to accessed directories.
241 # - build-root - Existing directory with built VPP artifacts (also DPDK).
242 # Directories updated:
243 # - ${VPP_DIR} - A local git repository, parent commit gets checked out.
244 # - build_current - Old contents removed, content of build-root copied here.
246 # - die - Print to stderr and exit, defined in common.sh
248 cd "${VPP_DIR}" || die "Change directory operation failed."
249 rm -rf "build_current" || die "Remove operation failed."
250 mkdir -p "build_current" || die "Directory creation failed."
251 mv "build-root"/*".deb" "build_current"/ || die "Move operation failed."
252 # The previous build could have left some incompatible leftovers,
253 # e.g. DPDK artifacts of different version (in build/external).
254 # Also, there usually is a copy of dpdk artifact in build-root.
255 git clean -dffx "build"/ "build-root"/ || die "Git clean operation failed."
256 # Finally, check out the parent commit.
257 git checkout HEAD~ || die "Git checkout operation failed."
258 # Display any other leftovers.
259 git status || die "Git status operation failed."
263 function set_aside_parent_build_artifacts () {
267 # Function is copying VPP built artifacts from parent checkout commit for
268 # further use. Checkout to parent is not part of this function.
270 # - VPP_DIR - Path to existing directory, parent of accessed directories.
272 # - build-root - Existing directory with built VPP artifacts (also DPDK).
273 # Directories updated:
274 # - build_parent - Old directory removed, build-root debs moved here.
276 # - die - Print to stderr and exit, defined in common.sh
278 cd "${VPP_DIR}" || die "Change directory operation failed."
279 rm -rf "build_parent" || die "Remove failed."
280 mkdir -p "build_parent" || die "Directory creation operation failed."
281 mv "build-root"/*".deb" "build_parent"/ || die "Move operation failed."
285 function set_perpatch_dut () {
290 # - DUT - CSIT test/ subdirectory containing suites to execute.
292 # TODO: Detect DUT from job name, when we have more than just VPP perpatch.
298 function set_perpatch_vpp_dir () {
303 # - CSIT_DIR - Path to existing root of local CSIT git repository.
305 # - VPP_DIR - Path to existing root of local VPP git repository.
307 # - die - Print to stderr and exit, defined in common.sh
309 # In perpatch, CSIT is cloned inside VPP clone.
310 VPP_DIR="$(readlink -e "${CSIT_DIR}/..")" || die "Readlink failed."