xref: /spdk/test/common/config/pkgdep/git (revision b3bec07939ebe2ea2e0c43931705d32aa9e06719)
1function install_qat() {
2	if ! hash yasm; then
3		install yasm
4	fi
5
6	in_syms() {
7		local syms
8		if [[ -e /proc/kallsyms ]]; then
9			syms=/proc/kallsyms
10		elif [[ -e /boot/System.map-$kernel_ver ]]; then
11			syms=/boot/System.map-$kernel_ver
12		else
13			return 0
14		fi
15
16		grep -q "$1" "$syms"
17	}
18
19	if [[ -e /sys/module/qat_c62x ]]; then
20		sudo modprobe -r qat_c62x || :
21	fi
22	if [[ -d $GIT_REPOS/QAT ]]; then
23		sudo rm -rf "$GIT_REPOS/QAT"
24	fi
25
26	mkdir "$GIT_REPOS/QAT"
27
28	tar -C "$GIT_REPOS/QAT" -xzof - < <(wget -O- "$DRIVER_LOCATION_QAT")
29
30	if ge "$kernel_ver" 6.3.0; then
31		patch --dir="$GIT_REPOS/QAT" -p1
32	fi < "$rootdir/test/common/config/pkgdep/patches/qat/0001-iommu_map.patch"
33
34	if ge "$kernel_ver" 6.4.0; then
35		patch --dir="$GIT_REPOS/QAT" -p1 \
36			< "$rootdir/test/common/config/pkgdep/patches/qat/0001-driver-core+semaphore.patch"
37		patch --dir="$GIT_REPOS/QAT" -p1 \
38			< "$rootdir/test/common/config/pkgdep/patches/qat/0001-algapi.patch"
39	fi
40
41	(cd "$GIT_REPOS/QAT" && sudo ./configure --enable-icp-sriov=host && sudo make install)
42
43	if ! sudo service qat_service start; then
44		echo "failed to start the qat service. Something may be wrong with your device or package."
45	fi
46}
47
48function install_rocksdb() {
49	# Rocksdb is installed for use with the blobfs tests.
50	if [ ! -d /usr/src/rocksdb ]; then
51		git clone "${GIT_REPO_ROCKSDB}" "$GIT_REPOS/rocksdb"
52		git -C "$GIT_REPOS/rocksdb" checkout 6.15.fb
53		sudo mv "$GIT_REPOS/rocksdb" /usr/src/
54	else
55		sudo git -C /usr/src/rocksdb checkout 6.15.fb
56		echo "rocksdb already in /usr/src. Not checking out again"
57	fi
58}
59
60function install_fio() {
61	# This version of fio is installed in /usr/src/fio to enable
62	# building the spdk fio plugin.
63	local fio_version="fio-3.35"
64
65	if [ ! -d /usr/src/fio ]; then
66		if [ ! -d fio ]; then
67			git clone "${GIT_REPO_FIO}" "$GIT_REPOS/fio"
68			sudo mv "$GIT_REPOS/fio" /usr/src/
69		else
70			sudo mv "$GIT_REPOS/fio" /usr/src/
71		fi
72		(
73			git -C /usr/src/fio checkout master \
74				&& git -C /usr/src/fio pull \
75				&& git -C /usr/src/fio checkout $fio_version \
76				&& if [ $OSID == 'freebsd' ]; then
77					gmake -C /usr/src/fio -j${jobs} \
78						&& sudo gmake -C /usr/src/fio install
79				else
80					make -C /usr/src/fio -j${jobs} \
81						&& sudo make -C /usr/src/fio install
82				fi
83		)
84	else
85		echo "fio already in /usr/src/fio. Not installing"
86	fi
87}
88
89function install_flamegraph() {
90	# Flamegraph is used when printing out timing graphs for the tests.
91	if [ ! -d /usr/local/FlameGraph ]; then
92		git clone "${GIT_REPO_FLAMEGRAPH}" "$GIT_REPOS/FlameGraph"
93		mkdir -p /usr/local
94		sudo mv "$GIT_REPOS/FlameGraph" /usr/local/FlameGraph
95	else
96		echo "flamegraph already installed. Skipping"
97	fi
98}
99
100function _install_qemu() {
101	local repo=$1
102	local branch=$2
103	local prefix=${3:-}
104
105	mkdir -p "$GIT_REPOS/qemu"
106
107	local repo_dir=$GIT_REPOS/qemu/$branch
108	if [[ -n $prefix ]]; then
109		repo_dir=$GIT_REPOS/qemu/$prefix-$branch
110	fi
111
112	if [[ ! -d $repo_dir ]]; then
113		git clone "$repo" -b "$branch" "$repo_dir"
114	else
115		echo "qemu already checked out. Skipping"
116	fi
117
118	declare -a opt_params=("--prefix=/usr/local/qemu/${repo_dir##*/}")
119	declare -a extra_cflags=()
120
121	opt_params+=("--disable-docs")
122	if ((gcc_version >= 9)); then
123		opt_params+=("--disable-glusterfs")
124	fi
125
126	extra_cflags+=("-Wno-error")
127
128	# Most tsocks proxies rely on a configuration file in /etc/tsocks.conf.
129	# If using tsocks, please make sure to complete this config before trying to build qemu.
130	if [[ $INSTALL_TSOCKS == true && $NO_TSOCKS != true ]]; then
131		if hash tsocks 2> /dev/null; then
132			opt_params+=("--with-git='tsocks git'")
133		fi
134	fi
135	opt_params+=("--extra-cflags=${extra_cflags[*]}")
136
137	if [[ $prefix == vanilla ]]; then
138		# Latest qemu seems to take sysconfdir from the prefix and instead of checking /etc
139		# it looks under /usr/local/qemu/vanilla*/bin/../etc which is a bit peculiar. Fix it.
140		opt_params+=("--sysconfdir=/etc/")
141	fi
142
143	# The qemu configure script places several output files in the CWD.
144	(cd "$repo_dir" && ./configure "${opt_params[@]}" --target-list="x86_64-softmmu" --enable-kvm --enable-linux-aio --enable-numa)
145
146	make -C "$repo_dir" -j${jobs}
147	sudo make -C "$repo_dir" install
148}
149
150function install_qemu() {
151	# Four versions of QEMU are used in the tests, three are installed
152	# directly from the source. Each QEMU is dedicated for different
153	# use-cases:
154	#  - Packed QEMU: version provided by given distro. Used to boot VMs
155	#    from within vhost tests.
156	#  - vfio-user QEMU: A special fork to test libvfio-user components.
157	#  - Vanilla QEMU: Used by the CI to boot the testing VMs.
158
159	_install_qemu $GIT_REPO_QEMU_VFIO $VFIO_QEMU_BRANCH
160	_install_qemu "$GIT_REPO_QEMU" "$VANILLA_QEMU_BRANCH" vanilla
161}
162
163function install_nvmecli() {
164	# nvme-cli >1.11.1 should be used.
165	rm -rf "$GIT_REPOS/nvme-cli-cuse"
166	git clone "https://github.com/linux-nvme/nvme-cli.git" "$GIT_REPOS/nvme-cli-cuse"
167	git -C "$GIT_REPOS/nvme-cli-cuse" checkout v2.5
168
169	meson setup --force-fallback-for=libnvme \
170		"$GIT_REPOS/nvme-cli-cuse/.build" \
171		"$GIT_REPOS/nvme-cli-cuse"
172	meson compile -C "$GIT_REPOS/nvme-cli-cuse/.build"
173
174	rm -rf /usr/local/src/nvme-cli
175	mv "$GIT_REPOS/nvme-cli-cuse" /usr/local/src/nvme-cli
176
177	# Make sure binary is available for the cuse tests
178	if [[ -e /usr/local/src/nvme-cli/.build/nvme ]]; then
179		sudo ln -s .build/nvme /usr/local/src/nvme-cli/
180	fi
181}
182
183# This function install version of nvme-cli, that support listing spdk nvme
184# devices, should be remove after changes present in nvme-cli upstream.
185function install_nvmecli_plugin() {
186	rm -rf "$GIT_REPOS/nvme-cli-plugin"
187
188	git clone $GIT_REPO_NVME_CLI "$GIT_REPOS/nvme-cli-plugin"
189	git -C "$GIT_REPOS/nvme-cli-plugin" fetch $GIT_REPO_NVME_CLI refs/changes/95/16795/12
190	git -C "$GIT_REPOS/nvme-cli-plugin" checkout FETCH_HEAD
191
192	meson setup --force-fallback-for=libnvme \
193		"$GIT_REPOS/nvme-cli-plugin/.build" \
194		"$GIT_REPOS/nvme-cli-plugin"
195	meson compile -C "$GIT_REPOS/nvme-cli-plugin/.build"
196
197	rm -rf /usr/local/src/nvme-cli-plugin
198	mv "$GIT_REPOS/nvme-cli-plugin" /usr/local/src/nvme-cli-plugin
199
200	# Make sure binary is available for the plugin tests
201	if [[ -e /usr/local/src/nvme-cli-plugin/.build/nvme ]]; then
202		sudo ln -s .build/nvme /usr/local/src/nvme-cli-plugin/
203	fi
204}
205
206function install_libiscsi() {
207	# We currently don't make any changes to the libiscsi repository for our tests, but it is possible that we will need
208	# to later. Cloning from git is just future proofing the machines.
209	if [[ ! -d $GIT_REPOS/libiscsi ]]; then
210		git clone "${GIT_REPO_LIBISCSI}" "$GIT_REPOS/libiscsi"
211	else
212		echo "libiscsi already checked out. Skipping"
213	fi
214	(cd "$GIT_REPOS/libiscsi" && ./autogen.sh && ./configure --prefix=/usr/local/libiscsi)
215	make -C "$GIT_REPOS/libiscsi" -j${jobs} WARN_CFLAGS=
216	sudo make -C "$GIT_REPOS/libiscsi" install
217}
218
219function install_git() {
220	if type -P git; then
221		if ge "$(git --version | awk '{print $3}')" "$GIT_VERSION"; then
222			return 0
223		fi
224	fi >/dev/null
225
226	install zlib-devel curl-devel
227	tar -C "$GIT_REPOS" -xzof <(wget -qO- "$GIT_REPO_GIT")
228	(cd "$GIT_REPOS/git-$GIT_VERSION" \
229		&& make configure \
230		&& ./configure \
231		&& sudo make -j${jobs} install)
232}
233
234function install_extra_pkgs() {
235	if [[ $INSTALL_QAT == true ]]; then
236		install libudev-devel || install libudev-dev || :
237	fi
238
239	if [[ $INSTALL_QEMU == true ]]; then
240		install qemu-system-x86 qemu-img \
241			|| install qemu-system-x86 qemu-utils \
242			|| install qemu
243
244		# Install extra dependency which was removed from Qemu 7.2 source tree
245		install libslirp-devel \
246			|| install libslirp-dev
247	fi || :
248}
249
250function install_vagrant() {
251	local vagrant_version="2.2.7"
252	local vagrant_installer="vagrant_${vagrant_version}_x86_64.deb"
253	local vagrant_plugins=(vagrant-libvirt vagrant-sshfs vagrant-cachier vagrant-proxyconf)
254
255	if [[ $OSID != ubuntu ]]; then
256		echo "Currently, Vagrant installation is supported only on ubuntu"
257		return 0
258	fi
259
260	# Install vagrant and it's plugins dependencies
261	# function should be defined in pkgdep/$package_manager file
262	install_vagrant_dependencies
263
264	# Download and install vagrant
265	if hash vagrant &> /dev/null; then
266		echo "Vagrant is already installed"
267	else
268		wget "https://releases.hashicorp.com/vagrant/${vagrant_version}/${vagrant_installer}"
269		sudo dpkg -i "${vagrant_installer}"
270	fi
271	vagrant --version
272
273	# Install vagrant plugins
274	local vagrant_plugin_list
275	vagrant_plugin_list=$(vagrant plugin list)
276
277	local plugin
278	for plugin in "${vagrant_plugins[@]}"; do
279		if grep -Fq "$plugin" <<< "$vagrant_plugin_list"; then
280			echo "$plugin already installed"
281		else
282			vagrant plugin install "$plugin"
283		fi
284	done
285}
286
287function install_igb_uio() {
288	git clone "${GIT_REPO_DPDK_KMODS}" "$GIT_REPOS/dpdk-kmods"
289
290	(cd "$GIT_REPOS/dpdk-kmods/linux/igb_uio" && make -j ${jobs})
291	sudo mkdir -p "/lib/modules/$(uname -r)/extra/dpdk"
292	sudo cp "$GIT_REPOS/dpdk-kmods/linux/igb_uio/igb_uio.ko" "/lib/modules/$(uname -r)/extra/dpdk"
293	sudo depmod
294}
295
296function install_irdma() {
297	local RDMA_CORE_VERSION=42.0
298	local RDMA_CORE=https://github.com/linux-rdma/rdma-core/releases/download/v$RDMA_CORE_VERSION/rdma-core-$RDMA_CORE_VERSION.tar.gz
299
300	if [[ $ID != fedora ]]; then
301		echo "Installation of the irdma can be attempted only on Fedora"
302		return 0
303	fi
304
305	# Install extra dependencies needed by the rdma-core
306	install ninja-build pandoc perl-generators valgrind-devel python-docutils libnl3 libnl3-devel python3-Cython
307
308	rm -rf "$GIT_REPOS/irdma-$IRDMA_VERSION"
309	rm -rf "$GIT_REPOS/rdma-core-$RDMA_CORE_VERSION"
310
311	curl -L -o- "$IRDMA_DRIVER" | tar -C "$GIT_REPOS" -xzf -
312	[[ -e $GIT_REPOS/irdma-$IRDMA_VERSION/build.sh ]]
313
314	(
315		cd "$GIT_REPOS/irdma-$IRDMA_VERSION"
316		sed -i "s/IRDMA_FLUSH_DELAY_MS 1500/IRDMA_FLUSH_DELAY_MS 50/" \
317			"$GIT_REPOS/irdma-$IRDMA_VERSION/src/irdma/verbs.h"
318		"$GIT_REPOS/irdma-$IRDMA_VERSION/build.sh"
319	)
320
321	# Fetch and build the rdma-core irdma depends on
322	curl -L -o- "$RDMA_CORE" | tar -C "$GIT_REPOS" -xzf -
323	[[ -e $GIT_REPOS/irdma-$IRDMA_VERSION/libirdma-$RDMA_CORE_VERSION.patch ]]
324
325	patch --dir="$GIT_REPOS/rdma-core-$RDMA_CORE_VERSION" -p2 \
326		< "$GIT_REPOS/irdma-$IRDMA_VERSION/libirdma-$RDMA_CORE_VERSION.patch"
327
328	# Note that paths and the name of the package are hardcoded into .spec, hence they need to stay like this.
329	[[ -e $GIT_REPOS/rdma-core-$RDMA_CORE_VERSION/redhat/rdma-core.spec ]]
330	mkdir -p "$HOME/rpmbuild/"{SOURCES,SPECS}
331	cp "$GIT_REPOS/rdma-core-$RDMA_CORE_VERSION/redhat/rdma-core.spec" "$HOME/rpmbuild/SPECS"
332
333	# Re-package the source
334	tar -czf "$HOME/rpmbuild/SOURCES/rdma-core-$RDMA_CORE_VERSION.tgz" -C "$GIT_REPOS" "rdma-core-$RDMA_CORE_VERSION"
335
336	# Build the rpms
337	(
338		cd "$HOME/rpmbuild/SPECS"
339		# Make sure stock ninja-build is used
340		PATH="/usr/bin:$PATH" rpmbuild -ba rdma-core.spec
341	)
342
343	# Now, don't install the packages since this will, most likely, conflict with packages already installed
344	# in the system. Instead, simply inform user what the next step is and note what potential issues it may
345	# have with the installation.
346
347	shopt -s nullglob
348	local rpms=("$HOME/rpmbuild/RPMS/x86_64/"*.rpm)
349	shopt -u nullglob
350	((${#rpms[@]} > 0))
351
352	cat <<-EOF
353
354		INFO: rdma-core-$RDMA_CORE_VERSION was successfully built, following packages are
355		available for installation:
356
357		$(printf '  - %s\n' "${rpms[@]##*/}")
358
359		Note that installing the above packages may raise conflicts with their
360		potentially newer versions already installed on the system. Dependent
361		packages may be uninstalled during the process as well. Please, run the
362		following command to finish the installation:
363
364		  $package_manager install [--allowerasing] $HOME/rpmbuild/RPMS/x86_64/*.rpm
365
366	EOF
367}
368
369function install_ice() {
370	rm -rf "$GIT_REPOS/ice-$ICE_VERSION"
371
372	curl -L -o- "$ICE_DRIVER" | tar -C "$GIT_REPOS" -xzf -
373
374	if ge "$kernel_ver" 6.2.0; then
375		patch --dir="$GIT_REPOS/ice-$ICE_VERSION" -p1
376	fi < "$rootdir/test/common/config/pkgdep/patches/ice/0001-devlink-info-driver.patch"
377
378	if ge "$kernel_ver" 6.3.0; then
379		patch --dir="$GIT_REPOS/ice-$ICE_VERSION" -p1 \
380			 < "$rootdir/test/common/config/pkgdep/patches/ice/0001-devlink-set-features.patch"
381		patch --dir="$GIT_REPOS/ice-$ICE_VERSION" -p1 \
382			 < "$rootdir/test/common/config/pkgdep/patches/ice/0001-stats-fetch_*_irq.patch"
383	fi
384
385	(
386		cd "$GIT_REPOS/ice-$ICE_VERSION/src"
387		sudo make -j"$(nproc)" install
388	)
389}
390
391function install_lcov() {
392	local lcov_version=v1.15
393
394	rm -rf /usr/src/lcov
395	sudo git clone "$GIT_REPO_LCOV" --branch "$lcov_version" /usr/src/lcov
396	(cd /usr/src/lcov; sudo make install)
397}
398
399function install_bpftrace() {
400	local deps=() bcc_rev
401
402	deps+=(cereal-devel)
403	deps+=(clang-devel)
404	deps+=(cmake)
405	deps+=(dwarves)
406	deps+=(gmock-devel)
407	deps+=(gtest-devel)
408	deps+=(llvm-devel)
409
410	install "${deps[@]}"
411
412	rm -rf $GIT_REPOS/bpftrace
413
414	git clone $GIT_REPO_BPFTRACE $GIT_REPOS/bpftrace --recurse-submodules
415	git -C $GIT_REPOS/bpftrace checkout $BPFTRACE_VERSION
416	mkdir -p $GIT_REPOS/bpftrace/build
417	mkdir -p "$GIT_REPOS/bpftrace/build/build-libs/bcc"
418
419	if ge "$(clang -dumpversion)" 16.0.0; then
420		# Make sure LLVM-Config.cmake does not trip when it's touched through bcc's find_package()
421		# calls. Do so by manually "initializing" cmake's cache dedicated for the bcc build. The
422		# "UNDEFINED" is the type cmake would select via cmake_policy().
423		echo "CMAKE_POLICY_DEFAULT_CMP0057:UNDEFINED=NEW" > \
424			 "$GIT_REPOS/bpftrace/build/build-libs/bcc/CMakeCache.txt"
425
426		# Make sure bpftrace builds bcc at a revision which supports llvm >= 16.0.0
427		# https://github.com/iovisor/bcc/commit/daf35cdbeaeba649509d88cf1674302affa263e3
428		git -C "$GIT_REPOS/bpftrace/bcc" checkout daf35cdbeaeba649509d88cf1674302affa263e3
429
430		# As of now, the latest bpftrace revision does not support LLVM >= 16 as it hardcodes
431		# the MAJOR version inside its CMakeLists.txt. Override it.
432		sed -i -e 's/set(MAX_LLVM_MAJOR 15)/set(MAX_LLVM_MAJOR 16)/g' \
433			"$GIT_REPOS/bpftrace/CMakeLists.txt"
434	fi
435
436	bcc_rev=$(git -C "$GIT_REPOS/bpftrace/bcc" describe --tags --abbrev=0) bcc_rev=${bcc_rev#v}
437	echo "REVISION:STRING=$bcc_rev" >> "$GIT_REPOS/bpftrace/build/build-libs/bcc/CMakeCache.txt"
438
439
440	# Use build-libs.sh to build necessary libraries in the bpftrace tree
441	(cd $GIT_REPOS/bpftrace/build && ../build-libs.sh)
442
443	cmake \
444		-Wno-dev \
445		-DCMAKE_BUILD_TYPE=Release \
446		-B "$GIT_REPOS/bpftrace/build" \
447		-S "$GIT_REPOS/bpftrace"
448
449	make -C $GIT_REPOS/bpftrace/build -j$(nproc)
450	sudo make -C $GIT_REPOS/bpftrace/build install
451}
452
453function install_sources() {
454	if [[ $ID == centos ]] && (( VERSION_ID == 7 )); then
455		# install proper version of the git first
456		install_git
457	fi
458
459	IFS="," read -ra conf_env <<< "$CONF"
460	for conf in "${conf_env[@]}"; do
461		export "INSTALL_${conf^^}=true"
462	done
463
464	if [[ $OSID == freebsd ]]; then
465		jobs=$(($(sysctl -n hw.ncpu) * 2))
466	else
467		jobs=$(($(nproc) * 2))
468		sources+=(
469			install_irdma
470			install_libiscsi
471			install_nvmecli
472			install_nvmecli_plugin
473			install_qat
474			install_rocksdb
475			install_flamegraph
476			install_qemu
477			install_igb_uio
478			install_ice
479			install_lcov
480			install_bpftrace
481		)
482		install_extra_pkgs
483	fi
484	sources+=(install_fio)
485	sources+=(install_vagrant)
486
487	sudo mkdir -p /usr/{,local}/src
488	sudo mkdir -p "$GIT_REPOS"
489
490	for source in "${sources[@]}"; do
491		source_conf=${source^^}
492		if [[ ${!source_conf} == true ]]; then
493			"$source"
494		fi
495	done
496}
497
498GIT_VERSION=2.25.1
499IRDMA_VERSION=1.11.16.6
500ICE_VERSION=1.11.17.1
501
502BPFTRACE_VERSION=${BPFTRACE_VERSION:-42d55a0}
503VFIO_QEMU_BRANCH=${VFIO_QEMU_BRANCH:-vfio-user-p3.0}
504VANILLA_QEMU_BRANCH=${VANILLA_QEMU_BRANCH:-v8.0.0}
505
506: ${GIT_REPO_ROCKSDB=https://review.spdk.io/spdk/rocksdb}
507export GIT_REPO_ROCKSDB
508: ${GIT_REPO_FIO=https://github.com/axboe/fio.git}
509export GIT_REPO_FIO
510: ${GIT_REPO_FLAMEGRAPH=https://github.com/brendangregg/FlameGraph.git}
511export GIT_REPO_FLAMEGRAPH
512: ${GIT_REPO_QEMU=https://github.com/qemu/qemu}
513export GIT_REPO_QEMU
514: ${GIT_REPO_QEMU_VFIO=https://github.com/oracle/qemu}
515export GIT_REPO_QEMU_VFIO
516: ${GIT_REPO_LIBISCSI=https://github.com/sahlberg/libiscsi}
517export GIT_REPO_LIBISCSI
518: ${DRIVER_LOCATION_QAT=https://downloadmirror.intel.com/773821/QAT.L.4.21.0-00001.tar.gz}
519export DRIVER_LOCATION_QAT
520: ${GIT_REPO_GIT=https://github.com/git/git/archive/v${GIT_VERSION}.tar.gz}
521export GIT_REPO_GIT
522: ${GIT_REPO_DPDK_KMODS=http://dpdk.org/git/dpdk-kmods}
523export GIT_REPO_DPDK_KMODS
524: ${IRDMA_DRIVER=https://downloadmirror.intel.com/763932/irdma-$IRDMA_VERSION.tgz}
525export IRDMA_DRIVER
526: ${ICE_DRIVER="https://sourceforge.net/projects/e1000/files/ice%20stable/$ICE_VERSION/ice-$ICE_VERSION.tar.gz"}
527export ICE_DRIVER
528: ${GIT_REPO_LCOV=https://github.com/linux-test-project/lcov}
529export GIT_REPO_LCOV
530: ${GIT_REPO_BCC=https://github.com/iovisor/bcc.git}
531export GIT_REPO_BCC
532: ${GIT_REPO_BPFTRACE=https://github.com/iovisor/bpftrace.git}
533export GIT_REPO_BPFTRACE
534: ${GIT_REPO_NVME_CLI=https://review.spdk.io/gerrit/spdk/nvme-cli}
535export GIT_REPO_NVME_CLI
536
537GIT_REPOS=${GIT_REPOS:-$HOME}
538
539gcc_version=$(gcc -dumpversion) gcc_version=${gcc_version%%.*}
540if [[ -e /proc/sys/kernel/osrelease ]]; then
541	kernel_ver=$(< /proc/sys/kernel/osrelease)
542fi
543