Tim Landscheidt has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/71115


Change subject: Add tests for jsub
......................................................................

Add tests for jsub

Change-Id: Ic7300c6c3c54b62ffa8508330920dc72f95a3bd1
---
M jobutils/bin/jsub
M tests/Makefile.am
A tests/dummy.sh
M tests/testsuite.at
4 files changed, 135 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/labs/toollabs 
refs/changes/15/71115/1

diff --git a/jobutils/bin/jsub b/jobutils/bin/jsub
index 20f683a..4c6098a 100755
--- a/jobutils/bin/jsub
+++ b/jobutils/bin/jsub
@@ -246,7 +246,7 @@
   push @args, '-q', $queue, '-b', 'y', $prog, @ARGV;
 }
 
-my $h = harness(['/usr/bin/qsub', @args], \$qsubinput, \$qsuboutput, 
\$qsuberror);
+my $h = harness([exists ($ENV {'JOBUTILS_QSUB'}) ? $ENV {'JOBUTILS_QSUB'} : 
'/usr/bin/qsub', @args], \$qsubinput, \$qsuboutput, \$qsuberror);
 if (!run ($h)) {
     print STDOUT $qsuboutput;
     print STDERR $qsuberror;
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 431f129..f0ee409 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -18,7 +18,8 @@
 TESTSUITE = $(srcdir)/testsuite
 
 check-local: atconfig $(TESTSUITE)
-       $(SHELL) '$(TESTSUITE)' $(TESTSUITEFLAGS)
+       $(SHELL) '$(TESTSUITE)' AUTOTEST_PATH=jobutils/bin:tests \
+         $($(TESTSUITEFLAGS)
 
 installcheck-local: atconfig $(TESTSUITE)
        $(SHELL) '$(TESTSUITE)' AUTOTEST_PATH='$(bindir)' \
@@ -33,3 +34,5 @@
 $(TESTSUITE): $(srcdir)/testsuite.at $(srcdir)/package.m4
        $(AUTOTEST) -I '$(srcdir)' -o $@.tmp $@.at
        mv $@.tmp $@
+
+check_SCRIPTS = dummy.sh
diff --git a/tests/dummy.sh b/tests/dummy.sh
new file mode 100755
index 0000000..c2d56e6
--- /dev/null
+++ b/tests/dummy.sh
@@ -0,0 +1,23 @@
+#!/bin/bash
+
+# This script dumps arguments to dummy.args, STDIN to dummy.in,
+# dummy.out to STDOUT, dummy.err to STDERR and exits with the status
+# contained in dummy.exitcode.
+
+# Abort on any error.
+set -e
+
+if [ $# -gt 0 ]; then
+  while [ $# -gt 1 ]; do
+    printf '%q ' "$1"
+    shift
+  done
+  printf '%q\n' "$1"
+fi > dummy.args
+cat > dummy.in
+cat dummy.out
+cat dummy.err 1>&2
+
+read EXITCODE < dummy.exitcode
+
+exit $EXITCODE
diff --git a/tests/testsuite.at b/tests/testsuite.at
index 8c0cead..dce1ced 100644
--- a/tests/testsuite.at
+++ b/tests/testsuite.at
@@ -15,6 +15,113 @@
 AT_CLEANUP()
 ])
 
+# _AT_TOOLLABS_JSUB(ARGS,
+#                   OUTPUT,
+#                   ERROR,
+#                   STATUS,
+#                   EXPARGS,
+#                   EXPINPUT,
+#                   EXPOUTPUT,
+#                   EXPERROR,
+#                   EXPSTATUS)
+# ----------------------------------
+# Check if jsub called with ARGS calls a qsub mock-up with EXPARGS and
+# EXPINPUT and upon receiving OUTPUT, ERROR and STATUS from a spawned
+# qsub mock-up produces EXPOUTPUT, EXPERROR and EXPSTATUS
+# respectively.
+m4_define([_AT_TOOLLABS_JSUB],
+[AT_DATA([dummy.out], [$2])
+AT_DATA([dummy.err], [$3])
+AT_DATA([dummy.exitcode], [$4
+])
+AT_CHECK([JOBUTILS_QSUB=dummy.sh jsub $1], [$9], [$7], [$8])
+AT_CHECK_UNQUOTED([cat dummy.args], [0], [$5], [])
+AT_CHECK([cat dummy.in], [0], [$6], [])
+])
+
+# AT_TOOLLABS_JSUB(TEST-GROUP-NAME,
+#                  ARGS,
+#                  OUTPUT,
+#                  ERROR,
+#                  STATUS,
+#                  EXPARGS,
+#                  EXPINPUT,
+#                  EXPOUTPUT,
+#                  EXPERROR,
+#                  EXPSTATUS)
+# ---------------------------------
+# Test if jsub called with ARGS calls a qsub mock-up with EXPARGS and
+# EXPINPUT and upon receiving OUTPUT, ERROR and STATUS from a spawned
+# qsub mock-up produces EXPOUTPUT, EXPERROR and EXPSTATUS
+# respectively.  Use TEST-GROUP-NAME for identification.
+m4_define([AT_TOOLLABS_JSUB],
+[AT_SETUP([$1])
+_AT_TOOLLABS_JSUB([$2], [$3], [$4], [$5], [$6], [$7], [$8], [$9], [$10])
+AT_CLEANUP()
+])
+
 # Test that Perl scripts do not have compilation errors.
 AT_TOOLLABS_PERL_COMPILE([jobutils/bin/job])
 AT_TOOLLABS_PERL_COMPILE([jobutils/bin/jsub])
+
+# Test jsub.
+
+# We use mainly true for tests, as jsub determines the path to the
+# script internally and we can predict with a great certainty that
+# true will be in /bin/true.
+
+# These tests will create two files (true.err and true.out) in the
+# home directory of the calling user.
+AT_TOOLLABS_JSUB([Normal call], [true], [Your job 501377 ("true") has been 
submitted
+], [], [0], [-e $HOME/true.err -o $HOME/true.out -N true -hard -l 
h_vmem=262144k -q task -b y /bin/true
+], [], [Your job 501377 ("true") has been submitted
+], [], [0])
+AT_TOOLLABS_JSUB([Quiet call], [-quiet true], [Your job 501377 ("true") has 
been submitted
+], [], [0], [-e $HOME/true.err -o $HOME/true.out -N true -hard -l 
h_vmem=262144k -q task -b y /bin/true
+], [], [], [], [0])
+
+# Test that umasks are handled properly.
+AT_SETUP([-o points to a non-existing file])
+_AT_TOOLLABS_JSUB([-o does-not-exist.log -quiet true], [Your job 501377 
("true") has been submitted
+], [], [0], [-o does-not-exist.log -e $HOME/true.err -N true -hard -l 
h_vmem=262144k -q task -b y /bin/true
+], [], [], [], [0])
+AT_CHECK([stat -c %a does-not-exist.log], [0], [600
+], [])
+AT_CLEANUP()
+
+AT_SETUP([-o points to a existing file])
+AT_CHECK([touch does-exist.log], [0], [], [])
+AT_CHECK([chmod 664 does-exist.log], [0], [], [])
+_AT_TOOLLABS_JSUB([-o does-exist.log -quiet true], [Your job 501377 ("true") 
has been submitted
+], [], [0], [-o does-exist.log -e $HOME/true.err -N true -hard -l 
h_vmem=262144k -q task -b y /bin/true
+], [], [], [], [0])
+AT_CHECK([stat -c %a does-exist.log], [0], [664
+], [])
+AT_CLEANUP()
+
+AT_SETUP([-o points to a non-existing file and -umask is used])
+_AT_TOOLLABS_JSUB([-o does-not-exist.log -quiet -umask 000 true], [Your job 
501377 ("true") has been submitted
+], [], [0], [-o does-not-exist.log -e $HOME/true.err -N true -hard -l 
h_vmem=262144k -q task -b y /bin/true
+], [], [], [], [0])
+AT_CHECK([stat -c %a does-not-exist.log], [0], [666
+], [])
+AT_CLEANUP()
+
+AT_SETUP([-o points to a existing file and -umask is used])
+AT_CHECK([touch does-exist.log], [0], [], [])
+AT_CHECK([chmod 664 does-exist.log], [0], [], [])
+_AT_TOOLLABS_JSUB([-o does-exist.log -quiet -umask 000 true], [Your job 501377 
("true") has been submitted
+], [], [0], [-o does-exist.log -e $HOME/true.err -N true -hard -l 
h_vmem=262144k -q task -b y /bin/true
+], [], [], [], [0])
+AT_CHECK([stat -c %a does-exist.log], [0], [664
+], [])
+AT_CLEANUP()
+
+AT_SETUP([-o points to a existing directory])
+AT_CHECK([mkdir does-exist], [0], [], [])
+_AT_TOOLLABS_JSUB([-o does-exist -quiet true], [Your job 501377 ("true") has 
been submitted
+], [], [0], [-o does-exist -e $HOME/true.err -N true -hard -l h_vmem=262144k 
-q task -b y /bin/true
+], [], [], [], [0])
+AT_CHECK([LANG=C ls does-exist/*], [2], [], [ls: cannot access does-exist/*: 
No such file or directory
+])
+AT_CLEANUP()

-- 
To view, visit https://gerrit.wikimedia.org/r/71115
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic7300c6c3c54b62ffa8508330920dc72f95a3bd1
Gerrit-PatchSet: 1
Gerrit-Project: labs/toollabs
Gerrit-Branch: master
Gerrit-Owner: Tim Landscheidt <t...@tim-landscheidt.de>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to