Add working libguestfs tests.
[patchq.git] / test-functions
diff --git a/test-functions b/test-functions
new file mode 100644 (file)
index 0000000..78f7054
--- /dev/null
@@ -0,0 +1,108 @@
+# -*- shell-script -*-
+# These are some common functions used to test libguestfs.
+
+function pick_project ()
+{
+    # Try to guess which project this patch series is for.
+    # You should put [PATCH hivex ...] or [PATCH supermin ...]
+    # in the subject line.
+    subject="$(grep -i -m1 '^Subject: ' $1)"
+    project=libguestfs
+    if [[ "$subject" =~ \[PATCH.*hivex.*\] ]]; then
+        project=hivex
+    elif [[ "$subject" =~ \[PATCH.*supermin.*\] ]]; then
+        project=supermin
+    elif [[ "$subject" =~ \[PATCH.*nbdkit.*\] ]]; then
+        project=nbdkit
+    fi
+    url=https://github.com/libguestfs/$project
+}
+
+function checkout_sources ()
+{
+    echo
+    echo "Checking out sources from $url ..."
+    echo
+
+    # Save network by using the local copy if it exists.
+    if [ -d $HOME/d/$project ]; then
+        cp -a $HOME/d/$project .
+        pushd $project
+        git checkout -f master
+        git clean -xdf
+        git pull
+        popd
+    else
+        git clone $url
+    fi
+}
+
+# Try to apply the patches.
+function apply_patches ()
+{
+    echo
+    echo "Applying patches ..."
+    echo
+    cp "$@" $project/
+    pushd $project
+    git am "$@"
+    popd
+}
+
+# Set up localconfigure and localenv appropriately.
+function local_config ()
+{
+    pushd $project
+    case "$project" in
+        libguestfs)
+            cat > localconfigure <<'EOF'
+./autogen.sh \
+    --prefix /usr \
+    --libdir /usr/lib64 \
+    --disable-static \
+    --enable-werror \
+    --disable-golang \
+    -C \
+    "$@"
+EOF
+            cat > localenv <<'EOF'
+export SKIP_TEST_PARALLEL_MOUNT_LOCAL=1
+export SKIP_TEST_FUSE_UMOUNT_RACE_SH=1
+export SKIP_TEST_GUESTMOUNT_FD=1
+export SKIP_TEST_XFS_ADMIN=1
+export SKIP_TEST_XFS_MISC_PL=1
+export SKIP_TEST_SYSLINUX_PL=1
+EOF
+            ;;
+
+        hivex)
+            cat > localconfigure <<'EOF'
+./autogen.sh \
+    --prefix /usr \
+    --libdir /usr/lib64 \
+    --enable-gcc-warnings
+EOF
+            ;;
+
+        supermin)
+            cat > localconfigure <<'EOF'
+./autogen.sh \
+    --prefix /usr \
+    --libdir /usr/lib64 \
+    --enable-werror
+EOF
+            ;;
+
+        nbdkit)
+            cat > localconfigure <<'EOF'
+./configure \
+    --prefix /usr \
+    --libdir /usr/lib64 \
+    --enable-gcc-warnings \
+    "$@"
+EOF
+            ;;
+    esac
+    chmod +x localconfigure
+    popd
+}