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 # TODO: Make sure whether this works on other distros/archs too.
60 # - ${1} - String identifier for echo, can be unset.
62 # - VPP_DIR - Path to existing directory, parent to accessed directories.
63 # Directories updated:
64 # - ${VPP_DIR} - Whole subtree, many files (re)created by the build process.
65 # - ${VPP_DIR}/build-root - Final build artifacts for CSIT end up here.
66 # - ${VPP_DIR}/dpdk - The dpdk artifact is built, but moved to build-root/.
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 # TODO: Do we want to support "${DRYRUN}" == "True"?
73 make UNATTENDED=yes install-dep || die "Make install-dep failed."
74 # The per_patch script calls this function twice, first for the new commit,
75 # then for its parent commit. On Jenkins, no dpdk is installed at first,
76 # locally it might have been installed. New dpdk is installed second call.
77 # If make detects installed vpp-ext-deps with matching version,
78 # it skips building vpp-ext-deps entirely.
79 # On the other hand, if parent uses different dpdk version,
80 # the new vpp-ext-deps is built, but the old one is not removed
81 # from the build directory if present. (Further functions move both,
82 # and during test dpkg would decide randomly which version gets installed.)
83 # As per_patch is too dumb (yet) to detect any of that,
84 # the only safe solution is to clean build directory and force rebuild.
85 # TODO: Make this function smarter and skip DPDK rebuilds if possible.
86 cmd=("dpkg-query" "--showformat='$${Version}'" "--show" "vpp-ext-deps")
87 installed_deb_ver="$(sudo "${cmd[@]}" || true)"
88 if [[ -n "${installed_deb_ver}" ]]; then
89 sudo dpkg --purge "vpp-ext-deps" || {
90 die "DPDK package uninstalation failed."
93 make UNATTENDED=yes install-ext-deps || {
94 die "Make install-ext-deps failed."
96 build-root/vagrant/"build.sh" || die "Vagrant VPP build script failed."
97 echo "*******************************************************************"
98 echo "* VPP ${1-} BUILD SUCCESSFULLY COMPLETED" || {
99 die "Argument not found."
101 echo "*******************************************************************"
105 function compare_test_results () {
110 # - VPP_DIR - Path to directory with VPP git repo (at least built parts).
111 # - ARCHIVE_DIR - Path to where robot result files are created in.
112 # - PYTHON_SCRIPTS_DIR - Path to directory holding comparison utility.
113 # Directories recreated:
114 # - csit_parent - Sibling to csit directory, for holding results
117 # - die - Print to stderr and exit, defined in common.sh
118 # - parse_bmrr_results - See definition in this file.
120 # - 0 - If the comparison utility sees no regression (nor data error).
121 # - 1 - If the comparison utility sees a regression (or data error).
123 cd "${VPP_DIR}" || die "Change directory operation failed."
124 # Reusing CSIT main virtualenv.
125 pip install -r "${PYTHON_SCRIPTS_DIR}/perpatch_requirements.txt" || {
126 die "Perpatch Python requirements installation failed."
128 python "${PYTHON_SCRIPTS_DIR}/compare_perpatch.py"
129 # The exit code determines the vote result.
133 function download_builds () {
137 # This is mostly useful only for Sandbox testing, to avoid recompilation.
140 # - ${1} - URL to download VPP builds from.
142 # - VPP_DIR - Path to WORKSPACE, parent of created directories.
143 # Directories created:
144 # - archive - Ends up empty, not to be confused with ${ARCHIVE_DIR}.
145 # - build_new - Holding built artifacts of the patch under test (PUT).
146 # - built_parent - Holding built artifacts of parent of PUT.
148 # - die - Print to stderr and exit, defined in common.sh
150 cd "${VPP_DIR}" || die "Change directory operation failed."
151 rm -rf "build-root" "build_parent" "build_new" "archive" "csit_new" || {
152 die "Directory removal failed."
154 wget -N --progress=dot:giga "${1}" || die "Wget download failed."
155 unzip "archive.zip" || die "Archive extraction failed."
156 mv "archive/build_parent" ./ || die "Move operation failed."
157 mv "archive/build_new" ./ || die "Move operation failed."
161 function initialize_csit_dirs () {
165 # This could be in prepare_test, but download_builds also needs this.
168 # - VPP_DIR - Path to WORKSPACE, parent of created directories.
169 # Directories created:
170 # - csit_new - Holding test results of the patch under test (PUT).
171 # - csit_parent - Holding test results of parent of PUT.
173 # - die - Print to stderr and exit, defined in common.sh
175 cd "${VPP_DIR}" || die "Change directory operation failed."
176 rm -rf "csit_new" "csit_parent" || {
177 die "Directory deletion failed."
179 mkdir -p "csit_new" "csit_parent" || {
180 die "Directory creation failed."
185 function parse_bmrr_results () {
189 # Currently "parsing" is just two greps.
190 # TODO: Re-use PAL parsing code, make parsing more general and centralized.
193 # - ${1} - Path to (existing) directory holding robot output.xml result.
195 # - output.xml - From argument location.
197 # - results.txt - (Re)created, in argument location.
199 # - die - Print to stderr and exit, defined in common.sh
201 rel_dir="$(readlink -e "${1}")" || die "Readlink failed."
202 in_file="${rel_dir}/output.xml"
203 out_file="${rel_dir}/results.txt"
204 # TODO: Do we need to check echo exit code explicitly?
205 echo "Parsing ${in_file} putting results into ${out_file}"
206 echo "TODO: Re-use parts of PAL when they support subsample test parsing."
207 pattern='Maximum Receive Rate trial results in packets'
208 pattern+=' per second: .*\]</status>'
209 grep -o "${pattern}" "${in_file}" | grep -o '\[.*\]' > "${out_file}" || {
210 die "Some parsing grep command has failed."
215 function prepare_build_parent () {
220 # - VPP_DIR - Path to existing directory, parent to accessed directories.
222 # - build-root - Existing directory with built VPP artifacts (also DPDK).
223 # Directories updated:
224 # - ${VPP_DIR} - A local git repository, parent commit gets checked out.
225 # - build_new - Old contents removed, content of build-root copied here.
227 # - die - Print to stderr and exit, defined in common.sh
229 cd "${VPP_DIR}" || die "Change directory operation failed."
230 rm -rf "build_new" || die "Remove operation failed."
231 mkdir -p "build_new" || die "Directory creation failed."
232 mv "build-root"/*".deb" "build_new"/ || die "Move operation failed."
233 # The previous build could have left some incompatible leftovers,
234 # e.g. DPDK artifacts of different version (in build/external).
235 # Also, there usually is a copy of dpdk artifact in build-root.
236 git clean -dffx "build"/ "build-root"/ || die "Git clean operation failed."
237 # Finally, check out the parent commit.
238 git checkout HEAD~ || die "Git checkout operation failed."
239 # Display any other leftovers.
240 git status || die "Git status operation failed."
244 function prepare_test () {
249 # - VPP_DIR - Path to existing directory, parent of accessed directories.
251 # - build-root - Existing directory with built VPP artifacts (also DPDK).
252 # Directories updated:
253 # - build_parent - Old directory removed, build-root debs moved here.
255 # - die - Print to stderr and exit, defined in common.sh
257 cd "${VPP_DIR}" || die "Change directory operation failed."
258 rm -rf "build_parent" || die "Remove failed."
259 mkdir -p "build_parent" || die "Directory creation operation failed."
260 mv "build-root"/*".deb" "build_parent"/ || die "Move operation failed."
264 function select_build () {
269 # - ${1} - Path to directory to copy VPP artifacts from. Required.
271 # - DOWNLOAD_DIR - Path to directory where Robot takes builds to test from.
272 # - VPP_DIR - Path to existing directory, root for relative paths.
274 # - ${1} - Existing directory with built new VPP artifacts (and DPDK).
275 # Directories updated:
276 # - ${DOWNLOAD_DIR} - Old content removed, .deb files from ${1} copied here.
278 # - die - Print to stderr and exit, defined in common.sh
280 cd "${VPP_DIR}" || die "Change directory operation failed."
281 source_dir="$(readlink -e "$1")"
282 rm -rf "${DOWNLOAD_DIR}"/* || die "Cleanup of download dir failed."
283 cp "${source_dir}"/*".deb" "${DOWNLOAD_DIR}" || die "Copy operation failed."
284 # TODO: Is there a nice way to create symlinks,
285 # so that if job fails on robot, results can be archived?
289 function set_perpatch_dut () {
294 # - DUT - CSIT test/ subdirectory containing suites to execute.
296 # TODO: Detect DUT from job name, when we have more than just VPP perpatch.
302 function set_perpatch_vpp_dir () {
307 # - CSIT_DIR - Path to existing root of local CSIT git repository.
309 # - VPP_DIR - Path to existing root of local VPP git repository.
311 # - die - Print to stderr and exit, defined in common.sh
313 # In perpatch, CSIT is cloned inside VPP clone.
314 VPP_DIR="$(readlink -e "${CSIT_DIR}/..")" || die "Readlink failed."