summaryrefslogtreecommitdiff
path: root/testing
diff options
context:
space:
mode:
authorAlexey Neyman <stilor@att.net>2018-04-15 21:29:09 (GMT)
committerAlexey Neyman <stilor@att.net>2018-04-15 21:29:09 (GMT)
commit715d6376bf87e102fd8a46af2f18dcc83ca913e0 (patch)
tree004f2d724771e2bf5e1e8ee165923199fb46cb2b /testing
parent5472517b31bde9b1ab71fd3369f3370e813e0351 (diff)
First stab at docker-based test framework
Signed-off-by: Alexey Neyman <stilor@att.net>
Diffstat (limited to 'testing')
-rw-r--r--testing/docker/archlinux/Dockerfile3
-rwxr-xr-xtesting/docker/common-scripts/ctng-build-all10
-rwxr-xr-xtesting/docker/common-scripts/ctng-install10
-rwxr-xr-xtesting/docker/common-scripts/su-as-user15
-rwxr-xr-xtesting/docker/dmgr.sh105
5 files changed, 143 insertions, 0 deletions
diff --git a/testing/docker/archlinux/Dockerfile b/testing/docker/archlinux/Dockerfile
new file mode 100644
index 0000000..eee2f47
--- /dev/null
+++ b/testing/docker/archlinux/Dockerfile
@@ -0,0 +1,3 @@
+FROM hoverbear/archlinux
+RUN pacman -Syu --noconfirm
+RUN pacman -S --noconfirm base-devel git help2man python
diff --git a/testing/docker/common-scripts/ctng-build-all b/testing/docker/common-scripts/ctng-build-all
new file mode 100755
index 0000000..f29093a
--- /dev/null
+++ b/testing/docker/common-scripts/ctng-build-all
@@ -0,0 +1,10 @@
+#!/bin/bash
+
+set -e
+cd
+rm -rf bld-ctng
+mkdir bld-ctng
+cd bld-ctng
+/crosstool-ng/configure --prefix=$HOME/inst-ctng
+make
+make install
diff --git a/testing/docker/common-scripts/ctng-install b/testing/docker/common-scripts/ctng-install
new file mode 100755
index 0000000..f29093a
--- /dev/null
+++ b/testing/docker/common-scripts/ctng-install
@@ -0,0 +1,10 @@
+#!/bin/bash
+
+set -e
+cd
+rm -rf bld-ctng
+mkdir bld-ctng
+cd bld-ctng
+/crosstool-ng/configure --prefix=$HOME/inst-ctng
+make
+make install
diff --git a/testing/docker/common-scripts/su-as-user b/testing/docker/common-scripts/su-as-user
new file mode 100755
index 0000000..7f262ac
--- /dev/null
+++ b/testing/docker/common-scripts/su-as-user
@@ -0,0 +1,15 @@
+#!/bin/bash
+
+usr=$1
+uid=$2
+grp=$3
+gid=$4
+shift 4
+
+groupadd -g ${gid} ${grp}
+useradd -d /home/${usr} -m -g ${gid} -u ${uid} ${usr}
+if [ -z "$*" ]; then
+ exec su -l ${usr}
+else
+ exec su -l -c "/bin/bash -c '$*'"
+fi
diff --git a/testing/docker/dmgr.sh b/testing/docker/dmgr.sh
new file mode 100755
index 0000000..6d88d51
--- /dev/null
+++ b/testing/docker/dmgr.sh
@@ -0,0 +1,105 @@
+#!/bin/bash
+
+# Run from the directory containing this script
+cd `dirname $0`
+
+msg()
+{
+ echo "INFO :: $*" >&2
+}
+
+error()
+{
+ echo "ERROR :: $*" >&2
+ exit 1
+}
+
+usage()
+{
+ cat >&2 <<EOF
+${1:+ERROR :: $1
+
+}Usage: $0 [action] [containters]
+
+Action is one of:
+
+ build Build or rebuild the specified containers.
+
+If containers are not specified, the action is applied to all available containers.
+EOF
+ exit 1
+}
+
+# Build a docker container, store its ID.
+action_build()
+{
+ local cntr=$1
+
+ msg "Building Docker container for ${cntr}"
+ docker build -t "ctng-${cntr}" "${cntr}"
+}
+
+# Common backend for enter/test
+_dckr()
+{
+ local topdir=`cd ../.. && pwd`
+ local cntr=$1
+ shift
+
+ mkdir -p build-${cntr}
+ docker run --rm -i -t \
+ -v `pwd`/common-scripts:/setup-scripts:ro \
+ -v ${topdir}:/crosstool-ng:ro \
+ -v `pwd`/build-${cntr}:/home \
+ ctng-${cntr} \
+ /setup-scripts/su-as-user `id -un` `id -u` `id -gn` `id -g` "$@"
+}
+
+# Run the test
+action_test()
+{
+ local cntr=$1
+
+ # The test assumes the top directory is bootstrapped, but clean.
+ msg "Setting up crosstool-NG in ${cntr}"
+ _dckr "${cntr}" /setup-scripts/ctng-install
+ msg "Running build-all in ${cntr}"
+ _dckr "${cntr}" /setup-scripts/ctng-build-all
+}
+
+# Enter the container using the same user account/environment as for testing.
+action_enter()
+{
+ local cntr=$1
+
+ msg "Entering ${cntr}"
+ _dckr "${cntr}"
+}
+
+# Clean up after test suite run
+action_clean()
+{
+ local cntr=$1
+
+ msg "Cleaning up after ${cntr}"
+ rm -rf build-${cntr}
+}
+
+action=$1
+shift
+all_containers=`ls */Dockerfile | sed 's,/Dockerfile,,'`
+selected_containers="${*:-${all_containers}}"
+
+case "${action}" in
+ build|test|enter|clean)
+ for c in ${selected_containers}; do
+ eval "action_${action} $c"
+ done
+ ;;
+ "")
+ usage "No action specified."
+ ;;
+ *)
+ usage "Unknown action ${action}."
+ ;;
+esac