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, but we need that file.
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 # CSIT also needs the external dependency artifacts, which is not in
99 mv -v "build/external/vpp-ext-deps"*".deb" "build-root"/ || {
100 die "*.deb move failed."
102 echo "*******************************************************************"
103 echo "* VPP ${1-} BUILD SUCCESSFULLY COMPLETED" || {
104 die "Argument not found."
106 echo "*******************************************************************"
110 function compare_test_results () {
115 # - VPP_DIR - Path to directory with VPP git repo (at least built parts).
116 # - ARCHIVE_DIR - Path to where robot result files are created in.
117 # - PYTHON_SCRIPTS_DIR - Path to directory holding comparison utility.
118 # Directories recreated:
119 # - csit_parent - Sibling to csit directory, for holding results
122 # - die - Print to stderr and exit, defined in common.sh
123 # - parse_bmrr_results - See definition in this file.
125 # - 0 - If the comparison utility sees no regression (nor data error).
126 # - 1 - If the comparison utility sees a regression (or data error).
128 cd "${VPP_DIR}" || die "Change directory operation failed."
129 # Reusing CSIT main virtualenv.
130 pip install -r "${PYTHON_SCRIPTS_DIR}/perpatch_requirements.txt" || {
131 die "Perpatch Python requirements installation failed."
133 python "${PYTHON_SCRIPTS_DIR}/compare_perpatch.py"
134 # The exit code determines the vote result.
138 function download_builds () {
142 # This is mostly useful only for Sandbox testing, to avoid recompilation.
145 # - ${1} - URL to download VPP builds from.
147 # - VPP_DIR - Path to WORKSPACE, parent of created directories.
148 # Directories created:
149 # - archive - Ends up empty, not to be confused with ${ARCHIVE_DIR}.
150 # - build_new - Holding built artifacts of the patch under test (PUT).
151 # - built_parent - Holding built artifacts of parent of PUT.
153 # - die - Print to stderr and exit, defined in common.sh
155 cd "${VPP_DIR}" || die "Change directory operation failed."
156 rm -rf "build-root" "build_parent" "build_new" "archive" "csit_new" || {
157 die "Directory removal failed."
159 wget -N --progress=dot:giga "${1}" || die "Wget download failed."
160 unzip "archive.zip" || die "Archive extraction failed."
161 mv "archive/build_parent" ./ || die "Move operation failed."
162 mv "archive/build_new" ./ || die "Move operation failed."
166 function initialize_csit_dirs () {
170 # This could be in prepare_test, but download_builds also needs this.
173 # - VPP_DIR - Path to WORKSPACE, parent of created directories.
174 # Directories created:
175 # - csit_new - Holding test results of the patch under test (PUT).
176 # - csit_parent - Holding test results of parent of PUT.
178 # - die - Print to stderr and exit, defined in common.sh
180 cd "${VPP_DIR}" || die "Change directory operation failed."
181 rm -rf "csit_new" "csit_parent" || {
182 die "Directory deletion failed."
184 mkdir -p "csit_new" "csit_parent" || {
185 die "Directory creation failed."
190 function parse_bmrr_results () {
194 # Currently "parsing" is just two greps.
195 # TODO: Re-use PAL parsing code, make parsing more general and centralized.
198 # - ${1} - Path to (existing) directory holding robot output.xml result.
200 # - output.xml - From argument location.
202 # - results.txt - (Re)created, in argument location.
204 # - die - Print to stderr and exit, defined in common.sh
206 rel_dir="$(readlink -e "${1}")" || die "Readlink failed."
207 in_file="${rel_dir}/output.xml"
208 out_file="${rel_dir}/results.txt"
209 # TODO: Do we need to check echo exit code explicitly?
210 echo "Parsing ${in_file} putting results into ${out_file}"
211 echo "TODO: Re-use parts of PAL when they support subsample test parsing."
212 pattern='Maximum Receive Rate trial results in packets'
213 pattern+=' per second: .*\]</status>'
214 grep -o "${pattern}" "${in_file}" | grep -o '\[.*\]' > "${out_file}" || {
215 die "Some parsing grep command has failed."
220 function prepare_build_parent () {
225 # - VPP_DIR - Path to existing directory, parent to accessed directories.
227 # - build-root - Existing directory with built VPP artifacts (also DPDK).
228 # Directories updated:
229 # - ${VPP_DIR} - A local git repository, parent commit gets checked out.
230 # - build_new - Old contents removed, content of build-root copied here.
232 # - die - Print to stderr and exit, defined in common.sh
234 cd "${VPP_DIR}" || die "Change directory operation failed."
235 rm -rf "build_new" || die "Remove operation failed."
236 mkdir -p "build_new" || die "Directory creation failed."
237 mv "build-root"/*".deb" "build_new"/ || die "Move operation failed."
238 # The previous build could have left some incompatible leftovers,
239 # e.g. DPDK artifacts of different version (in build/external).
240 # Also, there usually is a copy of dpdk artifact in build-root.
241 git clean -dffx "build"/ "build-root"/ || die "Git clean operation failed."
242 # Finally, check out the parent commit.
243 git checkout HEAD~ || die "Git checkout operation failed."
244 # Display any other leftovers.
245 git status || die "Git status operation failed."
249 function prepare_test () {
254 # - VPP_DIR - Path to existing directory, parent of accessed directories.
256 # - build-root - Existing directory with built VPP artifacts (also DPDK).
257 # Directories updated:
258 # - build_parent - Old directory removed, build-root debs moved here.
260 # - die - Print to stderr and exit, defined in common.sh
262 cd "${VPP_DIR}" || die "Change directory operation failed."
263 rm -rf "build_parent" || die "Remove failed."
264 mkdir -p "build_parent" || die "Directory creation operation failed."
265 mv "build-root"/*".deb" "build_parent"/ || die "Move operation failed."
269 function select_build () {
274 # - ${1} - Path to directory to copy VPP artifacts from. Required.
276 # - DOWNLOAD_DIR - Path to directory where Robot takes builds to test from.
277 # - VPP_DIR - Path to existing directory, root for relative paths.
279 # - ${1} - Existing directory with built new VPP artifacts (and DPDK).
280 # Directories updated:
281 # - ${DOWNLOAD_DIR} - Old content removed, .deb files from ${1} copied here.
283 # - die - Print to stderr and exit, defined in common.sh
285 cd "${VPP_DIR}" || die "Change directory operation failed."
286 source_dir="$(readlink -e "$1")"
287 rm -rf "${DOWNLOAD_DIR}"/* || die "Cleanup of download dir failed."
288 cp "${source_dir}"/*".deb" "${DOWNLOAD_DIR}" || die "Copy operation failed."
289 # TODO: Is there a nice way to create symlinks,
290 # so that if job fails on robot, results can be archived?
294 function set_perpatch_dut () {
299 # - DUT - CSIT test/ subdirectory containing suites to execute.
301 # TODO: Detect DUT from job name, when we have more than just VPP perpatch.
307 function set_perpatch_vpp_dir () {
312 # - CSIT_DIR - Path to existing root of local CSIT git repository.
314 # - VPP_DIR - Path to existing root of local VPP git repository.
316 # - die - Print to stderr and exit, defined in common.sh
318 # In perpatch, CSIT is cloned inside VPP clone.
319 VPP_DIR="$(readlink -e "${CSIT_DIR}/..")" || die "Readlink failed."