summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPavel Raiskup <praiskup@redhat.com>2015-11-18 10:37:00 +0100
committerPavel Raiskup <praiskup@redhat.com>2015-11-19 13:21:26 +0100
commitd553d5e4e85e6f05dacfdc87833db5574fc662f4 (patch)
tree97b08bdfdb4f74718cf782bf68e22aec1eea1af8
parent84445f1f3de7ed4bdb73b8f4fce879208d82252f (diff)
downloaddtf-d553d5e4e85e6f05dacfdc87833db5574fc662f4.zip
dtf-d553d5e4e85e6f05dacfdc87833db5574fc662f4.tar.gz
dtf-d553d5e4e85e6f05dacfdc87833db5574fc662f4.tar.xz
lib: add 'tests' file
This is useful for particular test-cases. Also, this is generated for target system/architecture. * bin/dtf-gen: Include expanded 'tests' template into 'library'. * share/dtf/lib/tests: New library file.
-rwxr-xr-xbin/dtf-gen2
-rw-r--r--share/dtf/lib/tests119
2 files changed, 121 insertions, 0 deletions
diff --git a/bin/dtf-gen b/bin/dtf-gen
index 84f7312..7307520 100755
--- a/bin/dtf-gen
+++ b/bin/dtf-gen
@@ -121,6 +121,8 @@ test -d "$outputdir" && {
mkdir -p "$outputdir"
cat "$dtflibdir/default" > "$outputdir/library"
+dg_call --template "$dtflibdir/tests" >> "$outputdir/library"
+
count_recursive_walk "$toporigdir" . .
# Protect sources!
diff --git a/share/dtf/lib/tests b/share/dtf/lib/tests
new file mode 100644
index 0000000..b4a1a4c
--- /dev/null
+++ b/share/dtf/lib/tests
@@ -0,0 +1,119 @@
+#! /bin/sh
+
+# Library for dtf tests.
+
+# dtf_skip [REASON]
+# -----------------
+dtf_skip ()
+{
+ test -n "$1" && echo >&2 "SKIP: $1"
+ exit 77
+}
+
+dtf_fail ()
+{
+ test -n "$1" && echo >&2 "$1"
+ exit 1
+}
+
+
+__dtf_method_not_implemented ()
+{
+ dtf_fail "'$1' method is not implemented"
+}
+
+
+# dtf_pkg_installed PKGNAME
+# -------------------------
+dtf_pkg_installed ()
+{
+# {% if config.os.id in ["fedora", "rhel", "centos"] %}
+ rpm -q "$1" &>/dev/null
+# {% else %}
+ __dtf_method_not_implemented "dtf_pkg_installed"
+# {% endif %}
+}
+
+
+__dtf_assert_nargs ()
+{
+ _d_nargs=$1 ; shift
+ _d_method=$1 ; shift
+
+ test $# -ge "$_d_nargs" && return
+
+ if test "$_d_nargs" -eq 1; then
+ dtf_fail "method '$_d_method' requires at least 1 argument"
+ else
+ dtf_fail "method '$_d_method' requires at least $_d_nargs arguments"
+ fi
+}
+
+
+dtf_is_root ()
+{
+ _d_uid=`id -u`
+ test x"$_d_uid" = x0
+}
+
+
+dtf_assert ()
+{
+ __dtf_assert_nargs 1 'dtf_pkg_install' ${1+"$@"}
+
+ case $1 in
+ root|ROOT)
+ dtf_is_root || dtf_fail "root accout required"
+ ;;
+ *)
+ dtf_fail "dtf_assert '$1' not implemented"
+ ;;
+ esac
+}
+
+
+dtf_pkg_install ()
+{
+ __dtf_assert_nargs 1 'dtf_pkg_install' ${1+"$@"}
+
+ _d_pkg_inst=$1 ; shift
+
+ dtf_assert root
+
+ # {{ "\n " + commands.pkginstaller.install(['"$_d_pkg_inst"'], {'docs': True}) }}
+
+ test $? -eq 0 || dtf_fail "can't install '$_d_pkg_inst' package"
+}
+
+
+__dtf_prereq_pkg ()
+{
+ __dtf_assert_nargs 2 'dtf_prereq pkg' ${1+"$@"}
+
+ _d_pkg=$1 ; shift
+
+ dtf_pkg_installed "$_d_pkg" && return 0
+
+ dtf_pkg_install "$_d_pkg"
+}
+
+
+# dtf_prereq REQUIREMENT [ARGS..]
+# -------------------------------
+# Make sure the requirement is met or fail.
+dtf_prereq ()
+{
+ __dtf_assert_nargs 1 dtf_prereq ${1+"$@"}
+
+ _d_requirement=$1 ; shift
+
+ case $_d_requirement in
+ pkg)
+ __dtf_prereq_pkg "$@"
+ ;;
+
+ *)
+ dtf_fail "dtf_prereq: action '$_d_requirement' not implemented"
+ ;;
+ esac
+}