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.
22 function build_vpp_ubuntu () {
24 # This function is using make pkg-verify to build VPP with all dependencies
25 # that is ARCH/OS aware. VPP repo is SSOT for building mechanics and CSIT
26 # is consuming artifacts. This way if VPP will introduce change in building
27 # mechanics they will not be blocked by CSIT repo.
30 # - ${1} - String identifier for echo, can be unset.
32 # - MAKE_PARALLEL_FLAGS - Make flags when building VPP.
33 # - MAKE_PARALLEL_JOBS - Number of cores to use when building VPP.
34 # - VPP_DIR - Path to existing directory, parent to accessed directories.
35 # Directories updated:
36 # - ${VPP_DIR} - Whole subtree, many files (re)created by the build process.
38 # - die - Print to stderr and exit, defined in common.sh
42 cd "${VPP_DIR}" || die "Change directory command failed."
43 if [ -n "${MAKE_PARALLEL_FLAGS-}" ]; then
44 echo "Building VPP. Number of cores for build set with" \
45 "MAKE_PARALLEL_FLAGS='${MAKE_PARALLEL_FLAGS}'."
46 elif [ -n "${MAKE_PARALLEL_JOBS-}" ]; then
47 echo "Building VPP. Number of cores for build set with" \
48 "MAKE_PARALLEL_JOBS='${MAKE_PARALLEL_JOBS}'."
50 echo "Building VPP. Number of cores not set, " \
51 "using build default ($(grep -c ^processor /proc/cpuinfo))."
54 make UNATTENDED=y pkg-verify || die "VPP build with make pkg-verify failed."
55 echo "* VPP ${1-} BUILD SUCCESSFULLY COMPLETED" || {
56 die "Argument not found."
61 function compare_test_results () {
64 # - VPP_DIR - Path to directory with VPP git repo (at least built parts).
65 # - ARCHIVE_DIR - Path to where robot result files are created in.
66 # - PYTHON_SCRIPTS_DIR - Path to directory holding comparison utility.
67 # Directories recreated:
68 # - csit_parent - Sibling to csit directory, for holding results
71 # - die - Print to stderr and exit, defined in common.sh
73 # - 0 - If the comparison utility sees no regression (nor data error).
74 # - 1 - If the comparison utility sees a regression (or data error).
78 cd "${VPP_DIR}" || die "Change directory operation failed."
79 # Reusing CSIT main virtualenv.
80 python3 "${TOOLS_DIR}/integrated/compare_perpatch.py"
81 # The exit code determines the vote result.
85 function initialize_csit_dirs () {
90 # - VPP_DIR - Path to WORKSPACE, parent of created directories.
91 # Directories created:
92 # - csit_{part} - See the caller what it is used for.
94 # - die - Print to stderr and exit, defined in common.sh
98 cd "${VPP_DIR}" || die "Change directory operation failed."
100 if [[ ${#} < 1 ]]; then
101 # All directories created.
104 name_part="${1}" || die
106 dir_name="csit_${name_part}" || die
107 rm -rf "${dir_name}" || die "Directory deletion failed."
108 mkdir -p "${dir_name}" || die "Directory creation failed."
113 function move_test_results () {
116 # - ${1}: Directory to archive to. Required. Parent has to exist.
118 # - TARGET - Target archival directory, equivalent to the argument.
120 # - ARCHIVE_DIR - Path to where robot result files are created in.
121 # - VPP_DIR - Path to existing directory, root for to relative paths.
122 # Directories updated:
123 # - ${1} - Created, and robot and parsing files are moved/created there.
125 # - die - Print to stderr and exit, defined in common.sh
129 cd "${VPP_DIR}" || die "Change directory command failed."
130 TARGET="$(readlink -f "$1")"
131 mkdir -p "${TARGET}" || die "Directory creation failed."
132 file_list=("output.xml" "log.html" "report.html" "tests")
133 for filename in "${file_list[@]}"; do
134 mv "${ARCHIVE_DIR}/${filename}" "${TARGET}/${filename}" || die
139 function select_build () {
142 # - ${1} - Path to directory to copy VPP artifacts from. Required.
144 # - DOWNLOAD_DIR - Path to directory where Robot takes builds to test from.
145 # - VPP_DIR - Path to existing directory, root for relative paths.
147 # - ${1} - Existing directory with built new VPP artifacts (and DPDK).
148 # Directories updated:
149 # - ${DOWNLOAD_DIR} - Old content removed, .deb files from ${1} copied here.
151 # - die - Print to stderr and exit, defined in common.sh
155 cd "${VPP_DIR}" || die "Change directory operation failed."
156 source_dir="$(readlink -e "$1")"
157 rm -rf "${DOWNLOAD_DIR}"/* || die "Cleanup of download dir failed."
158 cp "${source_dir}"/*".deb" "${DOWNLOAD_DIR}" || die "Copy operation failed."
159 # TODO: Is there a nice way to create symlinks,
160 # so that if job fails on robot, results can be archived?
164 function set_aside_build_artifacts () {
166 # Function used to save VPP .deb artifacts from currently finished build.
168 # After the artifacts are copied to the target directory,
169 # the main git tree is cleaned up to not interfere with next build.
172 # - ${1} - String to derive the target directory name from. Required.
174 # - VPP_DIR - Path to existing directory, parent to accessed directories.
176 # - build-root - Existing directory with built VPP artifacts (also DPDK).
177 # Directories updated:
178 # - ${VPP_DIR} - A local git repository, parent commit gets checked out.
179 # - build_${1} - Old contents removed, content of build-root copied here.
181 # - die - Print to stderr and exit, defined in common.sh
185 cd "${VPP_DIR}" || die "Change directory operation failed."
186 dir_name="build_${1}" || die
187 rm -rf "${dir_name}" || die "Remove operation failed."
188 mkdir -p "${dir_name}" || die "Directory creation failed."
189 mv "build-root"/*".deb" "${dir_name}"/ || die "Move operation failed."
190 # The previous build could have left some incompatible leftovers,
191 # e.g. DPDK artifacts of different version (in build/external).
192 # Also, there usually is a copy of dpdk artifact in build-root.
193 git clean -dffx "build"/ "build-root"/ || die "Git clean operation failed."
198 function set_perpatch_dut () {
201 # - DUT - CSIT test/ subdirectory containing suites to execute.
203 # TODO: Detect DUT from job name, when we have more than just VPP perpatch.
211 function set_perpatch_vpp_dir () {
214 # - CSIT_DIR - Path to existing root of local CSIT git repository.
216 # - VPP_DIR - Path to existing root of local VPP git repository.
218 # - die - Print to stderr and exit, defined in common.sh
222 # In perpatch, CSIT is cloned inside VPP clone.
223 VPP_DIR="$(readlink -e "${CSIT_DIR}/..")" || die "Readlink failed."