summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClark Williams <williams@redhat.com>2010-07-16 07:57:57 -0500
committerClark Williams <williams@redhat.com>2010-07-27 13:59:07 -0500
commit2149d0815501d3721ccfdb8203e54a7bcb59ff32 (patch)
tree9a826c9796826dbac7b3ecdf16814e08da1a027b
parented9826cee13b35c1c9df2a8018459394064767ff (diff)
downloadmock-2149d0815501d3721ccfdb8203e54a7bcb59ff32.tar.gz
mock-2149d0815501d3721ccfdb8203e54a7bcb59ff32.tar.xz
mock-2149d0815501d3721ccfdb8203e54a7bcb59ff32.zip
moved test suite to 'tests' directory
Moved test infrastructure into the tests directory and broke component tests out into individual scripts. Signed-off-by: Clark Williams <williams@redhat.com>
-rw-r--r--Makefile.am4
-rw-r--r--tests/daemontest.c104
-rw-r--r--tests/functions16
-rwxr-xr-xtests/runtests.sh90
-rw-r--r--tests/test1.tst15
-rw-r--r--tests/test2.tst14
-rw-r--r--tests/test3.tst14
-rw-r--r--tests/test4.tst14
-rw-r--r--tests/test5.tst14
-rw-r--r--tests/test6.tst21
-rw-r--r--tests/test7.tst27
-rw-r--r--tests/test8.tst21
-rw-r--r--tests/test9.tst16
13 files changed, 368 insertions, 2 deletions
diff --git a/Makefile.am b/Makefile.am
index b7f9b1c..ca05ec6 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -15,10 +15,10 @@ RELEASE_STRING = $(RELEASE_NAME)-$(RELEASE_VERSION)
VERSION = $(RELEASE_VERSION)
PACKAGE = $(RELEASE_NAME)
-CLEANFILES=mock-*.tar.gz mock-*.tar.bz2 mock-*.rpm _buildtemp version docs/daemontest
+CLEANFILES=mock-*.tar.gz mock-*.tar.bz2 mock-*.rpm _buildtemp version tests/daemontest
DISTCLEANFILES=*~ mock-unit-test/* x86_64/* noarch/* i386/*
-TESTS=./docs/runtests.sh
+TESTS=./tests/runtests.sh
$(TESTS): srpm
EXTRA_DIST = contrib
diff --git a/tests/daemontest.c b/tests/daemontest.c
new file mode 100644
index 0000000..3a31825
--- /dev/null
+++ b/tests/daemontest.c
@@ -0,0 +1,104 @@
+/* test program to test orhphanskill feature
+ * compile it (per below) and put it in /tmp/ of the chroot.
+ * Then:
+ * mock -r CFG chroot /tmp/daemontest
+ *
+ * Expected output:
+ * INFO: mock suid wrapper version 0.8.0
+ * INFO: mock.py version 0.8.0 starting...
+ * State Changed: start
+ * State Changed: init
+ * WARNING: Process ID 12180 still running in chroot. Killing...
+ *
+ */
+
+
+/*
+ * UNIX Daemon Server Programming Sample Program
+ * Levent Karakas <levent at mektup dot at> May 2001
+ *
+ * To compile: cc -o exampled examped.c
+ * To run: ./exampled
+ * To test daemon: ps -ef|grep exampled (or ps -aux on BSD systems)
+ * To test log: tail -f /tmp/exampled.log
+ * To test signal: kill -HUP `cat /tmp/exampled.lock`
+ * To terminate: kill `cat /tmp/exampled.lock`
+ * */
+
+#include <stdio.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+
+#define RUNNING_DIR "/tmp"
+#define LOCK_FILE "exampled.lock"
+#define LOG_FILE "exampled.log"
+
+void log_message(filename,message)
+char *filename;
+char *message;
+{
+FILE *logfile;
+ logfile=fopen(filename,"a");
+ if(!logfile) return;
+ fprintf(logfile,"%s\n",message);
+ fclose(logfile);
+}
+
+void signal_handler(sig)
+int sig;
+{
+ switch(sig) {
+ case SIGHUP:
+ log_message(LOG_FILE,"hangup signal catched");
+ break;
+ case SIGTERM:
+ log_message(LOG_FILE,"terminate signal catched");
+ exit(0);
+ break;
+ }
+}
+
+void daemonize()
+{
+int i,lfp;
+char str[10];
+ if(getppid()==1) return; /* already a daemon */
+ i=fork();
+ if (i<0) exit(1); /* fork error */
+ if (i>0) exit(0); /* parent exits */
+ /* child (daemon) continues */
+ setsid(); /* obtain a new process group */
+ for (i=getdtablesize();i>=0;--i) close(i); /* close all descriptors */
+ i=open("/dev/null",O_RDWR); dup(i); dup(i); /* handle standart I/O */
+ umask(027); /* set newly created file permissions */
+ chdir(RUNNING_DIR); /* change running directory */
+ lfp=open(LOCK_FILE,O_RDWR|O_CREAT,0640);
+ if (lfp<0) exit(1); /* can not open */
+ if (lockf(lfp,F_TLOCK,0)<0) exit(0); /* can not lock */
+ /* first instance continues */
+ sprintf(str,"%d\n",getpid());
+ write(lfp,str,strlen(str)); /* record pid to lockfile */
+ signal(SIGCHLD,SIG_IGN); /* ignore child */
+ signal(SIGTSTP,SIG_IGN); /* ignore tty signals */
+ signal(SIGTTOU,SIG_IGN);
+ signal(SIGTTIN,SIG_IGN);
+ signal(SIGHUP,signal_handler); /* catch hangup signal */
+ signal(SIGTERM,signal_handler); /* catch kill signal */
+}
+
+int main()
+{
+ daemonize();
+ // run for roughly 5 mins then exit. No need to stick around if unit test fails.
+ int i=0;
+ for( i=0; i<300; i++ ) sleep(1);
+ return 0;
+}
+
+/* EOF */
diff --git a/tests/functions b/tests/functions
new file mode 100644
index 0000000..ca597ac
--- /dev/null
+++ b/tests/functions
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+header() {
+ echo ""
+ echo "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
+ echo $1
+ echo "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
+ echo ""
+}
+
+runcmd() {
+ echo $1
+ ret=time sh -c "$1"
+ return $ret
+}
+
diff --git a/tests/runtests.sh b/tests/runtests.sh
new file mode 100755
index 0000000..d40a7a5
--- /dev/null
+++ b/tests/runtests.sh
@@ -0,0 +1,90 @@
+#!/bin/sh
+# vim:tw=0:ts=4:sw=4
+
+# this is a test script to run everything through its paces before you do a
+# release. The basic idea is:
+
+# 1) make distcheck to ensure that all autoconf stuff is setup properly
+# 2) run some basic tests to test different mock options.
+# 3) rebuild mock srpm using this version of mock under all distributed configs
+
+# This test will only run on a machine with full access to internet.
+# might work with http_proxy= env var, but I havent tested that.
+#
+# This test script expects to be run on an x86_64 machine. It will *not* run
+# properly on an i386 machine.
+#
+
+CURDIR=$(pwd)
+
+source ${CURDIR}/tests/functions
+
+MOCKSRPM=${CURDIR}/mock-*.src.rpm
+DIR=$(cd $(dirname $0); pwd)
+TOP_SRCTREE=$DIR/../
+cd $TOP_SRCTREE
+
+#
+# most tests below will use this mock command line
+#
+testConfig=fedora-13-x86_64
+uniqueext="$$-$RANDOM"
+outdir=${CURDIR}/mock-unit-test
+MOCKCMD="sudo ./py/mock.py --resultdir=$outdir --uniqueext=$uniqueext -r $testConfig $MOCK_EXTRA_ARGS"
+CHROOT=/var/lib/mock/${testConfig}-$uniqueext/root
+
+trap '$MOCKCMD --clean' INT HUP QUIT EXIT TERM
+
+export CURDIR MOCKSRPM DIR TOP_SRCTREE testConfig uniqueext outdir MOCKCMD CHROOT
+
+# clear out root cache so we get at least run without root cache present
+#sudo rm -rf /var/lib/mock/cache/${testConfig}/root_cache
+
+#
+# pre-populate yum cache for the rest of the commands below
+#
+header "pre-populating the cache"
+runcmd "$MOCKCMD --init"
+runcmd "$MOCKCMD --installdeps $MOCKSRPM"
+if [ ! -e $CHROOT/usr/include/python* ]; then
+ echo "installdeps test FAILED. could not find /usr/include/python*"
+ exit 1
+fi
+
+fails=0
+
+#
+# run regression tests
+#
+for i in ${CURDIR}/tests/*.tst; do
+ sh $i
+ if [ $? != 0 ]; then
+ fails=$(($fails + 1))
+ echo "**************** %i failed"
+ fi
+done
+
+printf "%d regression failures\n" $fails
+
+#
+# clean up
+#
+header "clean up from first round of tests"
+runcmd "$MOCKCMD --offline --clean"
+
+#
+# Test build all configs we ship.
+#
+for i in $(ls etc/mock | grep .cfg | grep -v default | egrep -v 'ppc|s390|sparc'); do
+ MOCKCMD="sudo ./py/mock.py --resultdir=$outdir --uniqueext=$uniqueext -r $(basename $i .cfg) $MOCK_EXTRA_ARGS"
+ if [ "${i#epel-4-x86_64.cfg}" != "" ]; then
+ header "testing config $(basename $i .cfg) with tmpfs plugin"
+ runcmd "$MOCKCMD --enable-plugin=tmpfs --rebuild $MOCKSRPM "
+ if [ $? != 0 ]; then fails=$(($fails+1)); fi
+ fi
+ header "testing config $(basename $i .cfg) *without* tmpfs plugin"
+ runcmd "$MOCKCMD --rebuild $MOCKSRPM"
+ if [ $? != 0 ]; then fails=$(($fails+1)); fi
+done
+
+printf "%d total failures\n" $fails
diff --git a/tests/test1.tst b/tests/test1.tst
new file mode 100644
index 0000000..0eb547d
--- /dev/null
+++ b/tests/test1.tst
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+source ${CURDIR}/tests/functions
+
+#
+# Test that chroot return code is properly passed up
+#
+
+header "testing that chroot return code is passed back correctly"
+runcmd "$MOCKCMD --offline --chroot -- bash -c 'exit 5'"
+res=$?
+if [ $res -ne 5 ]; then
+ echo "'mock --chroot' return code not properly passed back: $res"
+ exit 1
+fi
diff --git a/tests/test2.tst b/tests/test2.tst
new file mode 100644
index 0000000..0b68af6
--- /dev/null
+++ b/tests/test2.tst
@@ -0,0 +1,14 @@
+#!/bin/sh
+
+source ${CURDIR}/tests/functions
+
+#
+# test mock shell (interactive) and return code passing
+#
+header "testing interactive shell and return code"
+echo exit 5 | runcmd "$MOCKCMD --offline --shell"
+res=$?
+if [ $res -ne 5 ]; then
+ echo "'mock --chroot' return code not properly passed back: $res"
+ exit 1
+fi
diff --git a/tests/test3.tst b/tests/test3.tst
new file mode 100644
index 0000000..20ecce1
--- /dev/null
+++ b/tests/test3.tst
@@ -0,0 +1,14 @@
+#!/bin/sh
+
+source ${CURDIR}/tests/functions
+
+#
+# Test that chroot with one arg is getting passed though a shell (via os.system())
+#
+header "testing that args are passed correctly to a shell"
+runcmd "$MOCKCMD --offline --chroot 'touch /tmp/{foo,bar,baz}'"
+if [ ! -f $CHROOT/tmp/foo ] || [ ! -f $CHROOT/tmp/bar ] || [ ! -f $CHROOT/tmp/baz ]; then
+ echo "'mock --chroot' with one argument is not being passed to os.system()"
+ exit 1
+fi
+
diff --git a/tests/test4.tst b/tests/test4.tst
new file mode 100644
index 0000000..c72bdf0
--- /dev/null
+++ b/tests/test4.tst
@@ -0,0 +1,14 @@
+#!/bin/sh
+
+source ${CURDIR}/tests/functions
+
+#
+# Test that chroot with more than one arg is not getting passed through a shell
+#
+header "Test that chroot with more than one arg is not getting passed through a shell"
+runcmd "$MOCKCMD --offline --chroot touch '/tmp/{quux,wibble}'"
+if [ ! -f $CHROOT/tmp/\{quux,wibble\} ] || [ -f $CHROOT/tmp/quux ] || [ -f $CHROOT/tmp/wibble ]; then
+ echo "'mock --chroot' with more than one argument is being passed to os.system()"
+ exit 1
+fi
+
diff --git a/tests/test5.tst b/tests/test5.tst
new file mode 100644
index 0000000..0724d01
--- /dev/null
+++ b/tests/test5.tst
@@ -0,0 +1,14 @@
+#!/bin/sh
+
+source ${CURDIR}/tests/functions
+
+#
+# Test offline build as well as tmpfs
+#
+header "Test offline build as well as tmpfs"
+runcmd "$MOCKCMD --offline --enable-plugin=tmpfs --rebuild $MOCKSRPM"
+if [ ! -e $outdir/mock-*.noarch.rpm ]; then
+ echo "rebuild test FAILED. could not find $outdir/mock-*.noarch.rpm"
+ exit 1
+fi
+
diff --git a/tests/test6.tst b/tests/test6.tst
new file mode 100644
index 0000000..9c116e3
--- /dev/null
+++ b/tests/test6.tst
@@ -0,0 +1,21 @@
+#!/bin/sh
+
+source ${CURDIR}/tests/functions
+
+#
+# Test orphanskill feature (std)
+#
+header "Test orphanskill feature (std)"
+if pgrep daemontest; then
+ echo "Exiting because there is already a daemontest running."
+ exit 1
+fi
+runcmd "$MOCKCMD --offline --init"
+runcmd "$MOCKCMD --offline --copyin tests/daemontest.c /tmp"
+runcmd "$MOCKCMD --offline --chroot -- gcc -Wall -o /tmp/daemontest /tmp/daemontest.c"
+runcmd "$MOCKCMD --offline --chroot -- /tmp/daemontest"
+if pgrep daemontest; then
+ echo "Daemontest FAILED. found a daemontest process running after exit."
+ exit 1
+fi
+
diff --git a/tests/test7.tst b/tests/test7.tst
new file mode 100644
index 0000000..7dab5fc
--- /dev/null
+++ b/tests/test7.tst
@@ -0,0 +1,27 @@
+#!/bin/sh
+
+source ${CURDIR}/tests/functions
+
+#
+# Test orphanskill feature (explicit)
+#
+header "Test orphanskill feature (explicit)"
+runcmd "$MOCKCMD --offline --init"
+runcmd "$MOCKCMD --offline --copyin tests/daemontest.c /tmp"
+runcmd "$MOCKCMD --offline --chroot -- gcc -Wall -o /tmp/daemontest /tmp/daemontest.c"
+echo -e "#!/bin/sh\n/tmp/daemontest\nsleep 60\n" >> $CHROOT/tmp/try
+# the following should launch about three processes in the chroot: bash, sleep, daemontest
+$MOCKCMD --offline --chroot -- bash /tmp/try &
+mockpid=$!
+sleep 1
+# now we 'prematurely' kill mock. This should leave the three orphans above
+sudo kill -9 $mockpid
+if ! pgrep daemontest; then
+ echo "Daemontest failed. daemontest should be running now but is not."
+ exit 1
+fi
+$MOCKCMD --offline --orphanskill
+if pgrep daemontest; then
+ echo "Daemontest FAILED. found a daemontest process running after exit."
+ exit 1
+fi
diff --git a/tests/test8.tst b/tests/test8.tst
new file mode 100644
index 0000000..dd91ee7
--- /dev/null
+++ b/tests/test8.tst
@@ -0,0 +1,21 @@
+#!/bin/sh
+
+source ${CURDIR}/tests/functions
+
+#
+# test init/clean
+#
+header "test init/clean"
+runcmd "$MOCKCMD --offline --clean"
+if [ -e $CHROOT ]; then
+ echo "clean test FAILED. still found $CHROOT dir."
+ exit 1
+fi
+
+runcmd "$MOCKCMD --offline --init"
+runcmd "$MOCKCMD --offline --install ccache"
+if [ ! -e $CHROOT/usr/bin/ccache ]; then
+ echo "init/clean test FAILED. ccache not found."
+ exit 1
+fi
+
diff --git a/tests/test9.tst b/tests/test9.tst
new file mode 100644
index 0000000..1a5ed6e
--- /dev/null
+++ b/tests/test9.tst
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+source ${CURDIR}/tests/functions
+
+#
+# test old-style cmdline options
+#
+header "test old-style cmdline options"
+runcmd "$MOCKCMD --offline clean"
+runcmd "$MOCKCMD --offline init"
+runcmd "$MOCKCMD --offline install ccache"
+if [ ! -e $CHROOT/usr/bin/ccache ]; then
+ echo "init/clean test FAILED. ccache not found."
+ exit 1
+fi
+