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 main_bisect_loop () {
115 # Perform the iterative part of bisect entry script.
117 # The logic is too complex to remain in the entry script.
119 # At the start, the loop assumes git bisect old/new has just been executed,
120 # and verified more iterations are needed.
121 # The iteration cleans the build directory and builds the new mid commit.
122 # Then, testbed is reserved, tests run, and testbed unreserved.
123 # Results are moved from default to archive location
124 # (indexed by iteration number) and analyzed.
125 # The new adjective ("old" or "new") is selected,
126 # and git bisect with the adjective is executed.
127 # The symlinks csit_early and csit_late are updated to tightest bounds.
128 # The git.log file is examined and if the bisect is finished, loop ends.
134 git clean -dffx "build"/ "build-root"/ || die
135 build_vpp_ubuntu "MIDDLE" || die
136 select_build "build-root" || die
137 check_download_dir || die
138 reserve_and_cleanup_testbed || die
140 move_test_results "csit_middle/${iteration}" || die
141 untrap_and_unreserve_testbed || die
142 rm -vf "csit_mid" || die
143 ln -s -T "csit_middle/${iteration}" "csit_mid" || die
145 python3 "${TOOLS_DIR}/integrated/compare_bisect.py"
148 if [[ "${bisect_rc}" == "3" ]]; then
150 rm -v "csit_late" || die
151 ln -s -T "csit_middle/${iteration}" "csit_late" || die
152 elif [[ "${bisect_rc}" == "0" ]]; then
154 rm -v "csit_early" || die
155 ln -s -T "csit_middle/${iteration}" "csit_early" || die
157 die "Unexpected return code: ${bisect_rc}"
159 git bisect "${adjective}" | tee "git.log" || die
162 if head -n 1 "git.log" | cut -b -11 | fgrep -q "Bisecting:"; then
163 echo "Still bisecting..."
165 echo "Bisecting done."
172 function move_test_results () {
175 # - ${1}: Directory to archive to. Required. Parent has to exist.
177 # - TARGET - Target archival directory, equivalent to the argument.
179 # - ARCHIVE_DIR - Path to where robot result files are created in.
180 # - VPP_DIR - Path to existing directory, root for to relative paths.
181 # Directories updated:
182 # - ${1} - Created, and robot and parsing files are moved/created there.
184 # - die - Print to stderr and exit, defined in common.sh
188 cd "${VPP_DIR}" || die "Change directory command failed."
189 TARGET="$(readlink -f "$1")"
190 mkdir -p "${TARGET}" || die "Directory creation failed."
191 file_list=("output.xml" "log.html" "report.html" "tests")
192 for filename in "${file_list[@]}"; do
193 mv "${ARCHIVE_DIR}/${filename}" "${TARGET}/${filename}" || die
198 function select_build () {
201 # - ${1} - Path to directory to copy VPP artifacts from. Required.
203 # - DOWNLOAD_DIR - Path to directory where Robot takes builds to test from.
204 # - VPP_DIR - Path to existing directory, root for relative paths.
206 # - ${1} - Existing directory with built new VPP artifacts (and DPDK).
207 # Directories updated:
208 # - ${DOWNLOAD_DIR} - Old content removed, .deb files from ${1} copied here.
210 # - die - Print to stderr and exit, defined in common.sh
214 cd "${VPP_DIR}" || die "Change directory operation failed."
215 source_dir="$(readlink -e "$1")"
216 rm -rf "${DOWNLOAD_DIR}"/* || die "Cleanup of download dir failed."
217 cp "${source_dir}"/*".deb" "${DOWNLOAD_DIR}" || die "Copy operation failed."
218 # TODO: Is there a nice way to create symlinks,
219 # so that if job fails on robot, results can be archived?
223 function set_aside_build_artifacts () {
225 # Function used to save VPP .deb artifacts from currently finished build.
227 # After the artifacts are copied to the target directory,
228 # the main git tree is cleaned up to not interfere with next build.
231 # - ${1} - String to derive the target directory name from. Required.
233 # - VPP_DIR - Path to existing directory, parent to accessed directories.
235 # - build-root - Existing directory with built VPP artifacts (also DPDK).
236 # Directories updated:
237 # - ${VPP_DIR} - A local git repository, parent commit gets checked out.
238 # - build_${1} - Old contents removed, content of build-root copied here.
240 # - die - Print to stderr and exit, defined in common.sh
244 cd "${VPP_DIR}" || die "Change directory operation failed."
245 dir_name="build_${1}" || die
246 rm -rf "${dir_name}" || die "Remove operation failed."
247 mkdir -p "${dir_name}" || die "Directory creation failed."
248 mv "build-root"/*".deb" "${dir_name}"/ || die "Move operation failed."
249 # The previous build could have left some incompatible leftovers,
250 # e.g. DPDK artifacts of different version (in build/external).
251 # Also, there usually is a copy of dpdk artifact in build-root.
252 git clean -dffx "build"/ "build-root"/ || die "Git clean operation failed."
257 function set_perpatch_dut () {
260 # - DUT - CSIT test/ subdirectory containing suites to execute.
262 # TODO: Detect DUT from job name, when we have more than just VPP perpatch.
270 function set_perpatch_vpp_dir () {
273 # - CSIT_DIR - Path to existing root of local CSIT git repository.
275 # - VPP_DIR - Path to existing root of local VPP git repository.
277 # - die - Print to stderr and exit, defined in common.sh
281 # In perpatch, CSIT is cloned inside VPP clone.
282 VPP_DIR="$(readlink -e "${CSIT_DIR}/..")" || die "Readlink failed."