1 # Copyright (c) 2023 Cisco and/or its affiliates.
2 # Copyright (c) 2023 PANTHEON.tech s.r.o.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at:
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
17 # This library defines functions used mainly by per patch entry scripts.
18 # Generally, the functions assume "common.sh" library has been sourced already.
19 # Keep functions ordered alphabetically, please.
21 function archive_test_results () {
24 # - ${1}: Directory to archive to. Required. Parent has to exist.
26 # - TARGET - Target directory.
28 # - ARCHIVE_DIR - Path to where robot result files are created in.
29 # - VPP_DIR - Path to existing directory, root for to relative paths.
30 # Directories updated:
31 # - ${1} - Created, and robot and parsing files are moved/created there.
33 # - 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 file_list=("output.xml" "log.html" "report.html" "tests")
41 for filename in "${file_list[@]}"; do
42 mv "${ARCHIVE_DIR}/${filename}" "${TARGET}/${filename}" || {
43 die "Attempt to move '${filename}' failed."
49 function archive_parse_test_results () {
52 # - ${1}: Directory to archive to. Required. Parent has to exist.
54 # - TARGET - Target directory.
56 # - die - Print to stderr and exit, defined in common.sh
57 # - archive_test_results - Archiving results.
58 # - parse_results - See definition in this file.
62 archive_test_results "$1" || die
63 parse_results "${TARGET}" || {
64 die "The function should have died on error."
69 function build_vpp_ubuntu_amd64 () {
71 # This function is using make pkg-verify to build VPP with all dependencies
72 # that is ARCH/OS aware. VPP repo is SSOT for building mechanics and CSIT
73 # is consuming artifacts. This way if VPP will introduce change in building
74 # mechanics they will not be blocked by CSIT repo.
76 # - ${1} - String identifier for echo, can be unset.
78 # - MAKE_PARALLEL_FLAGS - Make flags when building VPP.
79 # - MAKE_PARALLEL_JOBS - Number of cores to use when building VPP.
80 # - VPP_DIR - Path to existing directory, parent to accessed directories.
81 # Directories updated:
82 # - ${VPP_DIR} - Whole subtree, many files (re)created by the build process.
84 # - die - Print to stderr and exit, defined in common.sh
88 cd "${VPP_DIR}" || die "Change directory command failed."
89 if [ -n "${MAKE_PARALLEL_FLAGS-}" ]; then
90 echo "Building VPP. Number of cores for build set with" \
91 "MAKE_PARALLEL_FLAGS='${MAKE_PARALLEL_FLAGS}'."
92 elif [ -n "${MAKE_PARALLEL_JOBS-}" ]; then
93 echo "Building VPP. Number of cores for build set with" \
94 "MAKE_PARALLEL_JOBS='${MAKE_PARALLEL_JOBS}'."
96 echo "Building VPP. Number of cores not set, " \
97 "using build default ($(grep -c ^processor /proc/cpuinfo))."
100 make UNATTENDED=y pkg-verify || die "VPP build with make pkg-verify failed."
101 echo "* VPP ${1-} BUILD SUCCESSFULLY COMPLETED" || {
102 die "Argument not found."
107 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
119 # - 0 - If the comparison utility sees no regression (nor data error).
120 # - 1 - If the comparison utility sees a regression (or data error).
124 cd "${VPP_DIR}" || die "Change directory operation failed."
125 # Reusing CSIT main virtualenv.
126 python3 "${TOOLS_DIR}/integrated/compare_perpatch.py"
127 # The exit code determines the vote result.
131 function initialize_csit_dirs () {
136 # - VPP_DIR - Path to WORKSPACE, parent of created directories.
137 # Directories created:
138 # - csit_current - Holding test results of the patch under test (PUT).
139 # - csit_parent - Holding test results of parent of PUT.
141 # - die - Print to stderr and exit, defined in common.sh
145 cd "${VPP_DIR}" || die "Change directory operation failed."
146 rm -rf "csit_current" "csit_parent" || {
147 die "Directory deletion failed."
149 mkdir -p "csit_current" "csit_parent" || {
150 die "Directory creation failed."
155 function parse_results () {
157 # Currently "parsing" is just few greps on output.xml.
158 # TODO: Parse json outputs properly.
160 # The current implementation attempts to parse for BMRR, PDR and passrate.
161 # If failures are present, they are reported as fake throughput values,
162 # enabling bisection to focus on the cause (or the fix) of the failures.
164 # The fake values are created with MRR multiplicity,
165 # otherwise jumpavg (which dislikes short groups) could misclassify them.
168 # - ${1} - Path to (existing) directory holding robot output.xml result.
170 # - output.xml - From argument location.
172 # - results.txt - (Re)created, in argument location.
174 # - CSIT_PERF_TRIAL_MULTIPLICITY - To create fake results of this length.
176 # - die - Print to stderr and exit, defined in common.sh
177 # - parse_results_mrr - See definition in this file.
178 # - parse_results_ndrpdr - See definition in this file.
179 # - parse_results_passrate - See definition in this file.
180 # - parse_results_soak - See definition in this file.
184 rel_dir="$(readlink -e "${1}")" || die "Readlink failed."
185 in_file="${rel_dir}/output.xml" || die
186 out_file="${rel_dir}/results.txt" || die
187 echo "Parsing ${in_file} putting results into ${out_file}" || die
188 # Frst attempt: (B)MRR.
189 if parse_results_mrr "${in_file}" "${out_file}"; then
192 # BMRR parsing failed. Attempt PDR/NDR.
193 if parse_results_ndrpdr "${in_file}" "${out_file}"; then
196 # PDR/NDR parsing failed. Attempt soak.
197 if parse_results_soak "${in_file}" "${out_file}"; then
200 # Soak parsing failed.
201 # Probably not a perf test at all (or a failed one),
202 # but we can still bisect by passrate.
203 parse_results_passrate "${in_file}" "${out_file}" || die
207 function parse_results_mrr () {
209 # Parse MRR test message(s) into JSON-readable output.
211 # Return non-zero if parsing fails.
214 # - ${1} - Path to (existing) input file. Required.
215 # - ${2} - Path to (overwritten if exists) output file. Required.
217 # - output.xml - The input file from argument location.
219 # - results.txt - (Re)created, in argument location.
221 # - die - Print to stderr and exit, defined in common.sh
225 in_file="${1}" || die "Two arguments needed."
226 out_file="${2}" || die "Two arguments needed."
227 pattern='Maximum Receive Rate trial results in .*' || die
228 pattern+=' per second: .*\]</status>' || die
229 # RC of the following line is returned.
230 grep -o "${pattern}" "${in_file}" | grep -o '\[.*\]' > "${out_file}"
234 function parse_results_ndrpdr () {
236 # Parse NDRPDR test message(s) for PDR_LOWER, into JSON-readable output.
238 # Return non-zero if parsing fails.
239 # Parse for PDR, unless environment variable says NDR.
242 # - ${1} - Path to (existing) input file. Required.
243 # - ${2} - Path to (overwritten if exists) output file. Required.
245 # - FDIO_CSIT_PERF_PARSE_NDR - If defined and "yes", parse for NDR, not PDR.
247 # - output.xml - The input file from argument location.
249 # - results.txt - (Re)created, in argument location.
251 # - die - Print to stderr and exit, defined in common.sh
255 in_file="${1}" || die "Two arguments needed."
256 out_file="${2}" || die "Two arguments needed."
257 if [[ "${FDIO_CSIT_PERF_PARSE_NDR:-no}" == "yes" ]]; then
258 pattern1="Arguments: [ '\\nNDR_LOWER: " || die
260 pattern1="Arguments: [ '\\nPDR_LOWER: " || die
262 # Adapted from https://superuser.com/a/377084
263 pattern2='(?<=R: ).*(?= pps)' || die
264 if fgrep "${pattern1}" "${in_file}" | grep -Po "${pattern2}" >> "${out_file}"
266 # Add bracket https://www.shellhacks.com/sed-awk-add-end-beginning-line/
267 sed -i 's/.*/[&]/' "${out_file}"
268 # Returns nonzero if fails.
271 # Maybe it was CPS instead of pps?
272 pattern2='(?<=R: ).*(?= CPS)' || die
273 if fgrep "${pattern1}" "${in_file}" | grep -Po "${pattern2}" >> "${out_file}"
275 # Add bracket https://www.shellhacks.com/sed-awk-add-end-beginning-line/
276 sed -i 's/.*/[&]/' "${out_file}"
277 # Returns nonzero if fails.
285 function parse_results_passrate () {
287 # Create fake values for failed tests.
289 # This function always passes (or dies).
291 # A non-zero but small value is chosen for failed run, to distinguish from
292 # real nonzero perf (which are big in general) and real zero values.
293 # A medium sized value is chosen for a passed run.
294 # This way bisect can search for breakages and fixes in device tests.
295 # At least in theory, as device tests are bootstrapped too differently.
297 # The fake value is repeated according to BMRR multiplicity,
298 # because a single value can be lost in high stdev data.
299 # (And it does not hurt for single value outputs such as NDR.)
301 # TODO: Count number of tests and generate fake results for every one.
302 # Currently that would interfere with test retry logic.
305 # - ${1} - Path to (existing) input file. Required.
306 # - ${2} - Path to (overwritten if exists) output file. Required.
308 # - CSIT_PERF_TRIAL_MULTIPLICITY - To create fake results of this length.
310 # - output.xml - The input file from argument location.
312 # - results.txt - (Re)created, in argument location.
314 # - die - Print to stderr and exit, defined in common.sh
318 in_file="${1}" || die "Two arguments needed."
319 out_file="${2}" || die "Two arguments needed."
320 # The last status is the top level (global) robot status.
321 # It only passes if there were no (critical) test failures.
322 if fgrep '<status status=' "${out_file}" | tail -n 1 | fgrep '"PASS"'; then
323 fake_value="30.0" || die
325 fake_value="2.0" || die
328 for i in `seq "${CSIT_PERF_TRIAL_MULTIPLICITY:-1}"`; do
329 out_arr+=("${fake_value}" ",") || die
331 # The Python part uses JSON parser, the last comma has to be removed.
332 # Requires Bash 4.3 https://stackoverflow.com/a/36978740
333 out_arr[-1]="]" || die
334 # TODO: Is it possible to avoid space separation by manipulating IFS?
335 echo "${out_arr[@]}" > "${out_file}" || die
339 function parse_results_soak () {
341 # Parse soak test message(s) for lower bound, into JSON-readable output.
343 # Return non-zero if parsing fails.
346 # - ${1} - Path to (existing) input file. Required.
347 # - ${2} - Path to (overwritten if exists) output file. Required.
349 # - output.xml - The input file from argument location.
351 # - results.txt - (Re)created, in argument location.
353 # - die - Print to stderr and exit, defined in common.sh
357 in_file="${1}" || die "Two arguments needed."
358 out_file="${2}" || die "Two arguments needed."
359 pattern1='PLRsearch lower bound: .*, .*<' || die
360 # Adapted from https://superuser.com/a/377084
361 pattern2='(?<=: ).*(?= pps)' || die
362 if grep "${pattern1}" "${in_file}" | grep -Po "${pattern2}" >> "${out_file}"
364 # Add bracket https://www.shellhacks.com/sed-awk-add-end-beginning-line/
365 sed -i 's/.*/[&]/' "${out_file}"
366 # Returns nonzero if fails.
373 function select_build () {
376 # - ${1} - Path to directory to copy VPP artifacts from. Required.
378 # - DOWNLOAD_DIR - Path to directory where Robot takes builds to test from.
379 # - VPP_DIR - Path to existing directory, root for relative paths.
381 # - ${1} - Existing directory with built new VPP artifacts (and DPDK).
382 # Directories updated:
383 # - ${DOWNLOAD_DIR} - Old content removed, .deb files from ${1} copied here.
385 # - die - Print to stderr and exit, defined in common.sh
389 cd "${VPP_DIR}" || die "Change directory operation failed."
390 source_dir="$(readlink -e "$1")"
391 rm -rf "${DOWNLOAD_DIR}"/* || die "Cleanup of download dir failed."
392 cp "${source_dir}"/*".deb" "${DOWNLOAD_DIR}" || die "Copy operation failed."
393 # TODO: Is there a nice way to create symlinks,
394 # so that if job fails on robot, results can be archived?
398 function set_aside_commit_build_artifacts () {
400 # Function is copying VPP built artifacts from actual checkout commit for
401 # further use and clean git.
403 # - VPP_DIR - Path to existing directory, parent to accessed directories.
405 # - build-root - Existing directory with built VPP artifacts (also DPDK).
406 # Directories updated:
407 # - ${VPP_DIR} - A local git repository, parent commit gets checked out.
408 # - build_current - Old contents removed, content of build-root copied here.
410 # - die - Print to stderr and exit, defined in common.sh
414 cd "${VPP_DIR}" || die "Change directory operation failed."
415 rm -rf "build_current" || die "Remove operation failed."
416 mkdir -p "build_current" || die "Directory creation failed."
417 mv "build-root"/*".deb" "build_current"/ || die "Move operation failed."
418 # The previous build could have left some incompatible leftovers,
419 # e.g. DPDK artifacts of different version (in build/external).
420 # Also, there usually is a copy of dpdk artifact in build-root.
421 git clean -dffx "build"/ "build-root"/ || die "Git clean operation failed."
422 # Finally, check out the parent commit.
423 git checkout HEAD~ || die "Git checkout operation failed."
424 # Display any other leftovers.
425 git status || die "Git status operation failed."
429 function set_aside_parent_build_artifacts () {
431 # Function is copying VPP built artifacts from parent checkout commit for
432 # further use. Checkout to parent is not part of this function.
434 # - VPP_DIR - Path to existing directory, parent of accessed directories.
436 # - build-root - Existing directory with built VPP artifacts (also DPDK).
437 # Directories updated:
438 # - build_parent - Old directory removed, build-root debs moved here.
440 # - die - Print to stderr and exit, defined in common.sh
444 cd "${VPP_DIR}" || die "Change directory operation failed."
445 rm -rf "build_parent" || die "Remove failed."
446 mkdir -p "build_parent" || die "Directory creation operation failed."
447 mv "build-root"/*".deb" "build_parent"/ || die "Move operation failed."
451 function set_perpatch_dut () {
454 # - DUT - CSIT test/ subdirectory containing suites to execute.
456 # TODO: Detect DUT from job name, when we have more than just VPP perpatch.
464 function set_perpatch_vpp_dir () {
467 # - CSIT_DIR - Path to existing root of local CSIT git repository.
469 # - VPP_DIR - Path to existing root of local VPP git repository.
471 # - die - Print to stderr and exit, defined in common.sh
475 # In perpatch, CSIT is cloned inside VPP clone.
476 VPP_DIR="$(readlink -e "${CSIT_DIR}/..")" || die "Readlink failed."