/ltmain.sh
/missing
/stamp-h1
+/tests/jobs/test_output
/tests/parsing/test_load
/tools/libdir.ml
/tools/whenjobs
EXTRA_DIST = COPYING README whenjobs.spec whenjobs.spec.in
-SUBDIRS = lib daemon tools tests/parsing
+SUBDIRS = \
+ lib \
+ daemon \
+ tools \
+ tests/parsing \
+ tests/jobs
CLEANFILES = *~
daemon/Makefile
lib/config.ml
lib/Makefile
+ tests/jobs/Makefile
tests/parsing/Makefile
tools/Makefile
whenjobs.spec])
--- /dev/null
+# whenjobs
+# Copyright (C) 2012 Red Hat Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# 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; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+EXTRA_DIST = test_run.sh $(TESTS)
+
+TESTS_ENVIRONMENT = ./test_run.sh
+TESTS = t100_counter.ml t101_updown.ml
+
+OCAMLPACKAGES = -package unix,num,camlp4.lib,calendar,rpc -I ../../lib
+
+OCAMLCFLAGS = -g -warn-error CDEFLMPSUVYZX $(OCAMLPACKAGES)
+OCAMLOPTFLAGS = $(OCAMLCFLAGS)
+
+PP = -pp '$(CAMLP4O) ../../lib/pa_when.cmo'
+
+# Rules for all OCaml files.
+%.cmi: %.mli ../../lib/pa_when.cmo
+ $(OCAMLFIND) ocamlc $(OCAMLCFLAGS) $(PP) -c $< -o $@
+%.cmo: %.ml ../../lib/pa_when.cmo
+ $(OCAMLFIND) ocamlc $(OCAMLCFLAGS) $(PP) -c $< -o $@
+#%.cmx: %.ml ../../lib/pa_when.cmo
+# $(OCAMLFIND) ocamlopt $(OCAMLOPTFLAGS) $(PP) -c $< -o $@
+
+SUFFIXES = .cmo .cmi .cmx .ml .mli .mll .mly
+
+# OCaml dependencies.
+depend: .depend
+
+.depend: $(SOURCES)
+ rm -f $@ $@-t
+ $(OCAMLFIND) ocamldep $(PP) $^ | \
+ $(SED) -e 's/ *$$//' | \
+ $(SED) -e :a -e '/ *\\$$/N; s/ *\\\n */ /; ta' | \
+ LANG=C sort > $@-t
+ mv $@-t $@
+
+-include .depend
+
+# Useful for debugging: print the generated AST for the tests.
+print:
+ @for f in $(check_SCRIPTS); do \
+ b=`basename $$f .cmo`; \
+ echo "Test: $$b.ml"; \
+ camlp4o ../../lib/pa_when.cmo -printer pr_o.cmo $$b.ml; \
+ done
+
+CLEANFILES = *.cmi *.cmo *.cmx *.cma *.cmxa *~
--- /dev/null
+(* whenjobs
+ * Copyright (C) 2012 Red Hat Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *)
+
+(* Test count to 3, then fire a whenjob. *)
+
+every 2 seconds :
+<<
+ echo $JOBNAME $counter >\> $HOME/test_output
+ whenjobs --set counter $(($counter+1)) --type int
+>>
+
+when counter = 3 :
+<<
+ echo $JOBNAME $counter >\> $HOME/test_output
+ whenjobs --daemon-stop
+>>
--- /dev/null
+job$1
+job$1 1
+job$1 2
+job$2 3
--- /dev/null
+(* whenjobs
+ * Copyright (C) 2012 Red Hat Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *)
+
+(* Reproduce a bug found during development where the everyjob would
+ * start running twice per period.
+ *)
+
+every second :
+<<
+ echo $JOBNAME >\> $HOME/test_output
+ whenjobs --set counter $(($counter+1)) --type int
+>>
+
+when counter < 5 && counter mod 2 == 0 :
+<<
+ echo $JOBNAME >\> $HOME/test_output
+>>
+
+when counter < 5 && counter mod 2 == 1 :
+<<
+ echo $JOBNAME >\> $HOME/test_output
+>>
+
+when counter == 5 :
+<<
+ echo $JOBNAME >\> $HOME/test_output
+ whenjobs --daemon-stop
+>>
--- /dev/null
+job$1
+job$3
+job$1
+job$2
+job$1
+job$3
+job$1
+job$2
+job$1
+job$4
--- /dev/null
+#!/bin/bash -
+# Copyright (C) 2012 Red Hat Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# 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; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+# Run the test script using the real daemon and tools.
+
+unset CDPATH
+set -e
+
+testdir=$(pwd)
+libdir=$(cd ../../lib; pwd)
+toolsdir=$(cd ../../tools; pwd)
+daemondir=$(cd ../../daemon; pwd)
+
+HOME="$testdir"
+export HOME
+
+rm -rf "$testdir/.whenjobs"
+mkdir "$testdir/.whenjobs"
+rm -f "$testdir/test_output"
+
+PATH="$toolsdir:$daemondir:$PATH"
+export PATH
+
+# Kill the daemon and clean up when the script exits.
+function cleanup {
+ kill `cat "$testdir/.whenjobs/daemon_pid"`
+ rm -rf "$testdir/.whenjobs"
+}
+trap cleanup INT TERM QUIT EXIT
+
+# Run the daemon.
+whenjobsd -d
+
+# Copy the job into the directory.
+cp "$1" "$testdir/.whenjobs/jobs.ml"
+
+# Upload it to the daemon.
+whenjobs --upload --lib "$libdir"
+
+# Now wait until the test completes. Note we cannot use 'wait'
+# because the daemon is not a direct child of the script.
+while [ -e /proc/`cat "$testdir/.whenjobs/daemon_pid"` ]; do
+ sleep 1
+done
+
+trap - INT TERM QUIT EXIT
+rm -rf "$testdir/.whenjobs"
+
+# Check the test output matches the expected output.
+if ! cmp -s "$testdir/test_output" "$1.expected"; then
+ echo "$0: $1: test output did not match expected output"
+ echo "test output was:"
+ echo "-----"
+ cat "$testdir/test_output"
+ echo "-----"
+ exit 1
+fi
+
+rm -f "$testdir/test_output"