ad2bcde166c34ec6c5282bf33e7f6e2d9471a0df
[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 HOME="$testdir"
29 export HOME
30
31 rm -rf "$testdir/.whenjobs"
32 mkdir "$testdir/.whenjobs"
33 rm -f "$testdir/test_output"
34
35 PATH="$toolsdir:$daemondir:$PATH"
36 export PATH
37
38 # Kill the daemon and clean up when the script exits.
39 function cleanup {
40     kill `cat "$testdir/.whenjobs/daemon_pid"`
41     rm -rf "$testdir/.whenjobs"
42 }
43 trap cleanup INT TERM QUIT EXIT
44
45 # Run the daemon.
46 whenjobsd -d
47
48 # Copy the job into the directory.
49 cp "$1" "$testdir/.whenjobs/jobs.ml"
50
51 # Upload it to the daemon.
52 whenjobs --upload --lib "$libdir"
53
54 # Now wait until the test completes.  Note we cannot use 'wait'
55 # because the daemon is not a direct child of the script.
56 while [ -e /proc/`cat "$testdir/.whenjobs/daemon_pid"` ]; do
57     sleep 1
58 done
59
60 trap - INT TERM QUIT EXIT
61 rm -rf "$testdir/.whenjobs"
62
63 # Sort the output by job serial number, so that jobs that happened to
64 # fire off in parallel are still recorded in order.
65 sort -n -o "$testdir/test_output" "$testdir/test_output"
66
67 # Check the test output matches the expected output.
68 if ! cmp -s "$testdir/test_output" "$1.expected"; then
69     echo "$0: $1: test output did not match expected output"
70     echo "test output was:"
71     echo "-----"
72     cat "$testdir/test_output"
73     echo "-----"
74     exit 1
75 fi
76
77 rm -f "$testdir/test_output"