summaryrefslogtreecommitdiffstats
path: root/debian/tests/util
diff options
context:
space:
mode:
Diffstat (limited to 'debian/tests/util')
-rw-r--r--debian/tests/util68
1 files changed, 68 insertions, 0 deletions
diff --git a/debian/tests/util b/debian/tests/util
new file mode 100644
index 0000000..4278ee7
--- /dev/null
+++ b/debian/tests/util
@@ -0,0 +1,68 @@
+#!/bin/sh
+
+# $1: share name
+# $2: comma separated list of vfs_objects to use, if any
+add_share() {
+ local share="$1"
+ local vfs="$2"
+ if ! testparm -s 2>&1 | grep -E "^\[${share}\]"; then
+ echo "Adding [${share}] share"
+ cat >> /etc/samba/smb.conf <<EOFEOF
+[${share}]
+ read only = no
+ guest ok = no
+ path = /${share}
+EOFEOF
+ if [ -n "${vfs}" ]; then
+ echo "vfs objects = ${vfs}" >> /etc/samba/smb.conf
+ fi
+ systemctl restart smbd.service
+ else
+ echo "Share [${share}] already exists, continuing"
+ fi
+}
+
+# $1: username
+# $2: password
+add_user() {
+ local username="$1"
+ local password="$2"
+
+ echo "Creating a local and samba user called ${username}"
+ useradd -m "${username}"
+ echo "Setting samba password for the ${username} user"
+ printf '%s\n%s\n' "${password}" "${password}" | smbpasswd -s -a ${username}
+}
+
+# $1: share name
+populate_share() {
+ local sharename="$1"
+ local usergroup="$2"
+ local sharepath="/${sharename}"
+
+ mkdir -p "${sharepath}"
+ dd if=/dev/urandom bs=4096 count=1000 2>/dev/null | base64 > "${sharepath}/data"
+ cd "${sharepath}"
+ md5sum data > data.md5
+ chown -R "${usergroup}:${usergroup}" "${sharepath}"
+}
+
+ensure_uring_available() {
+
+ # uring is supported starting with kernel 5.1.x
+ local kver=$(uname -r)
+ case "$kver" in
+ ( [0-4].* | 5.0.* ) # everything before 5.1
+ echo "uring not available in kernel version ${kver%%-*}, skipping test"
+ exit 77
+ ;;
+ esac
+
+ # ubuntu does not build liburing on i386,
+ # so io_uring vfs object is unavailable too
+ : ${DEB_HOST_MULTIARCH:=$(dpkg-architecture -qDEB_BUILD_MULTIARCH)}
+ if [ ! -f /usr/lib/$DEB_HOST_MULTIARCH/samba/vfs/io_uring.so ]; then
+ echo "io_uring vfs object is not available on this architecture, skipping test"
+ exit 77
+ fi
+}