Persist variables to file (~/.whenjobs/variables).
[whenjobs.git] / tests / jobs / test_run.sh
1 #!/bin/bash -
2 # Copyright (C) 2012 Red Hat Inc.
3 #
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18 # Run the test script using the real daemon and tools.
19
20 unset CDPATH
21 set -e
22
23 testdir=$(pwd)
24 libdir=$(cd ../../lib; pwd)
25 toolsdir=$(cd ../../tools; pwd)
26 daemondir=$(cd ../../daemon; pwd)
27
28 export libdir
29
30 HOME="$testdir"
31 export HOME
32
33 rm -rf "$testdir/.whenjobs"
34 mkdir "$testdir/.whenjobs"
35 rm -f "$testdir/test_output"
36
37 PATH="$toolsdir:$daemondir:$PATH"
38 export PATH
39
40 # Kill the daemon and clean up when the script exits.
41 function cleanup {
42     kill `cat "$testdir/.whenjobs/daemon_pid"`
43     rm -rf "$testdir/.whenjobs"
44 }
45 trap cleanup INT TERM QUIT EXIT
46
47 # Run the daemon.
48 whenjobsd -d
49
50 # Copy the job into the directory.
51 cp "$1" "$testdir/.whenjobs/jobs.ml"
52
53 # Upload it to the daemon.
54 whenjobs --upload --lib "$libdir"
55
56 # Now wait until the test completes.  Note we cannot use 'wait'
57 # because the daemon is not a direct child of the script.
58 while [ -e /proc/`cat "$testdir/.whenjobs/daemon_pid"` ]; do
59     sleep 1
60 done
61
62 trap - INT TERM QUIT EXIT
63 rm -rf "$testdir/.whenjobs"
64
65 # Sort the output by job serial number, so that jobs that happened to
66 # fire off in parallel are still recorded in order.
67 sort -n -o "$testdir/test_output" "$testdir/test_output"
68
69 # Check the test output matches the expected output.
70 if ! cmp -s "$testdir/test_output" "$1.expected"; then
71     echo "$0: $1: test output did not match expected output"
72     echo "test output was:"
73     echo "-----"
74     cat "$testdir/test_output"
75     echo "-----"
76     exit 1
77 fi
78
79 rm -f "$testdir/test_output"