summaryrefslogtreecommitdiff
path: root/test/common
diff options
context:
space:
mode:
authorAndrew Lee (李健秋) <ajqlee@debian.org>2018-09-19 08:58:42 +0200
committerAndrew Lee (李健秋) <ajqlee@debian.org>2018-09-19 08:58:42 +0200
commit64b447c72956f11e88ad360446c19008c3138d63 (patch)
treed11c974d6336a1cb59551fdc6435ff327edea512 /test/common
Import obs-build_20180831.orig.tar.gz
[dgit import orig obs-build_20180831.orig.tar.gz]
Diffstat (limited to 'test/common')
-rw-r--r--test/common109
1 files changed, 109 insertions, 0 deletions
diff --git a/test/common b/test/common
new file mode 100644
index 0000000..73ffec4
--- /dev/null
+++ b/test/common
@@ -0,0 +1,109 @@
+#!/bin/bash
+# common functions for build script testing
+################################################################
+#
+# Copyright (c) 2009 SUSE Linux Products GmbH
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 or 3 as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program (see the file COPYING); if not, write to the
+# Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+#
+################################################################
+#
+
+set -e
+. ${0%/*}/config
+if [ -e ${0%/*}/config.local ]; then
+ . ${0%/*}/config.local
+fi
+
+: ${BUILD_DIR:=/usr/lib/build}
+
+#if [ ! -e "$build_vm_img" ]; then
+# sudo dd if=/dev/zero of="$build_vm_img" bs=512 count=0 seek=$((build_vm_image_size*2*1024))
+#fi
+#if [ ! -e "$build_vm_swap" ]; then
+# sudo dd if=/dev/zero of="$build_vm_swap" bs=512 count=0 seek=$((build_vm_swap_size*2*1024))
+#fi
+
+die()
+{
+ test -z "$1" || echo "$*" >&2
+ exit 1
+}
+
+fail()
+{
+ echo FAILED
+ test -z "$1" || echo "$*"
+ exit 2
+}
+
+skip()
+{
+ echo skipped
+ test -z "$1" || echo "$*"
+ exit 3
+}
+
+build_args=()
+repos=()
+repo()
+{
+ local dir
+ eval dir="\"\$repo_$1\""
+ [ -n "$dir" ] || die "repo $1 not defined, try adding repo_$1=/path/to/repo to config.local"
+ test -d "$dir" || skip
+ repos[${#repos[@]}]="--repository";
+ repos[${#repos[@]}]="$dir";
+}
+
+linux32=
+arch32bit()
+{
+ local hostarch=`uname -m`
+ case "$hostarch" in
+ x86_64) linux32=linux32 ;;
+ *) skip ;;
+ esac
+}
+
+enable_kvm()
+{
+ test -w /dev/kvm || skip "no kvm support"
+ build_args+=(--kvm)
+ [ -z "$build_vm_img" ] || build_args+=("$build_vm_img")
+ [ -z "$build_vm_swap" ] || build_args+=(--swap "$build_vm_swap")
+ [ -z "$build_vm_mem" ] || build_args+=(--memory "$build_vm_mem")
+}
+
+run_build()
+{
+ for i in "$@"; do
+ if [ "$i" = '--kvm' ]; then
+ enable_kvm
+ else
+ build_args+=("$i")
+ fi
+ done
+ SU_WRAPPER=""
+ [ -x /usr/bin/sudo ] && SU_WRAPPER="sudo env"
+ set -- $linux32 $SU_WRAPPER \
+ $BUILD_DIR/build \
+ --root "${build_root}" \
+ "${repos[@]}" \
+ "${build_args[@]}"
+ echo "$@"
+ "$@" || fail
+ find $build_root/.build.packages/ -type f -name '*.rpm' -print0 | xargs --no-run-if-empty -0 rpm -K || fail
+}