]> rtime.felk.cvut.cz Git - novaboot.git/blob - tests/novaboot.wv
tests: Fix iprelay-cmd test to work on both Debian an NixOS
[novaboot.git] / tests / novaboot.wv
1 #!/usr/bin/env bash
2
3 cd $(dirname $0)
4 . wvtest.sh
5
6 WVSTART Invoke with no script
7 WVPASS novaboot -t '' < /dev/null
8
9 WVSTART Invoke as script
10 create_dummy
11 WVPASS ./script --gen-only
12
13 WVSTART Invoke as script with absolute path
14 create_dummy
15 WVPASS $PWD/script --gen-only
16
17 WVSTART Pulsar root
18 create_dummy
19 WVPASS ./script --gen-only --pulsar --pulsar-root=ASDF
20 WVPASS grep "root ASDF" config-novaboot
21
22 WVSTART Pulsar supports chld
23 create_script <<EOF
24 chld grub
25 EOF
26 WVPASS ./script --gen-only --pulsar
27 WVPASS grep "chld grub" config-novaboot
28
29 WVSTART Configuration files
30 create_dummy
31 echo '1;' > .novaboot
32 WVPASS sh -c "./script --gen-only 2> log"
33 WVPASS grep "novaboot: Read $PWD/.novaboot" log
34
35 WVSTART Configuration files in symlinked directories
36 mkdir config
37 echo '1;' > config/.novaboot
38 mkdir script
39 ( cd script; create_dummy )
40 ln -s ../script config
41 WVPASS sh -c "./config/script/script --gen-only 2> log"
42 WVPASS grep "novaboot: Read $PWD/config/.novaboot" log
43
44 WVSTART Builddir configuration variable
45 WVPASS mkdir -p build
46 cat > .novaboot <<'EOF'
47 $builddir="build";
48 1;
49 EOF
50 create_script <<'EOF'
51 load file < echo Hello
52 EOF
53 WVPASS ./script --gen-only
54 WVPASS test -f build/file
55
56 WVSTART Configuration directory
57 mkdir -p dir
58 echo '$test_a = 1;' > dir/a
59 echo '$test_c = 2;' > dir/c
60 echo '$test_c = 1;' > dir/b     # Overriden by the 'c' file
61 echo '$test_ign=1;' > dir/b.txt # Ignored
62 WVPASS sh -c 'NOVABOOT_CONFIG_DIR=./dir novaboot --dump-config > config'
63 WVPASS sh -c 'grep \$test config > test'
64 WVPASS diff -u - test <<'EOF'
65 $test_a = 1;
66 $test_c = 2;
67 EOF
68
69 WVSTART Fail with unknown target
70 create_dummy
71 WVFAIL sh -c "./script --gen-only -t non-existing-target"
72
73 WVSTART BUILDDIR variable
74 WVPASS mkdir -p build
75 create_script <<'EOF'
76 BUILDDIR=build
77 load file < echo Hello
78 EOF
79 WVPASS ./script --gen-only
80 WVPASS test -f build/file
81
82 WVSTART Hypervisor configuration variable
83 create_dummy
84 echo '$hypervisor="HYP";' > .novaboot
85 WVPASS ./script --gen-only --pulsar
86 WVPASS grep "exec HYP" config-novaboot
87
88 WVSTART ISO image generation
89 create_dummy
90 WVPASS ./script --iso --gen-only
91
92 WVSTART Recursive target definition
93 create_dummy
94 cat > .novaboot <<EOF
95 %targets = (
96     't1' => '--reset-cmd="echo MyResetCmd"',
97     't2' => '--target t1',
98 );
99 EOF
100 WVPASS sh -c "./script --target=t2|tee output"
101 WVPASS grep -q ^MyResetCmd output
102
103 WVSTART Wrong target definition
104 create_dummy
105 cat > .novaboot <<EOF
106 %targets = ('t1' => '--nonsense');
107 EOF
108 WVPASS sh -c "./script --target=t1 2>&1 |tee output"
109 WVPASS grep -q "Error in target definition" output
110
111 WVSTART Different ways of specifying target
112 cat > .novaboot <<'EOF'
113 %targets = ('t1' => '--remote-cmd="echo Target1 > t"',
114             't2' => '--remote-cmd="echo Target2 > t"',
115             't3' => '--remote-cmd="echo Target3 > t"');
116 $default_target = 't1';
117 EOF
118 WVPASSSH 'novaboot /dev/null'
119 WVPASS test "$(cat t)" = Target1
120 WVPASSSH 'NOVABOOT_TARGET=t2 novaboot /dev/null'
121 WVPASS test "$(cat t)" = Target2
122 WVPASSSH 'NOVABOOT_TARGET=t2 novaboot --target t3 /dev/null'
123 WVPASS test "$(cat t)" = Target3
124
125 WVSTART --iprelay-cmd
126 WVPASS novaboot --iprelay-cmd="$(which echo) -e '<iprelayd: connected>\xFF\xFA\x2C\x97\xDF\xFF\xF0 \xFF\xFA\x2C\x97\xFF\xFF\xF0'" --on
127
128 WVSTART Killing of --remote-cmd when it ignores SIGHUP
129 WVPASS tee script <<'EOF'
130 $SIG{HUP}='IGNORE';
131 open(FH, ">", "pid") or die;
132 print FH "$$";
133 close FH;
134 print "ready pid=$$\n";
135 print "exit\n";
136 sleep;
137 EOF
138 WVPASS novaboot --remote-cmd='perl script' --remote-expect=ready --exiton=exit /dev/null
139 WVFAIL test -d /proc/$(cat pid)
140 coproc novaboot --remote-cmd='perl script' --remote-expect=ready /dev/null
141 WVPASS sed -e '/ready/q0' <&${COPROC[0]}
142 WVPASS kill $COPROC_PID
143 WVFAIL wait $COPROC_PID # Signal termination is considered a failure
144 WVFAIL test -d /proc/$(cat pid)
145
146 WVSTART Correct invocation path
147 WVPASS mkdir dir
148 WVPASS tee dir/.novaboot <<<'print "Config OK\n";'
149 (
150     WVPASS cd dir
151     WVPASS novaboot /dev/null | WVPASS grep "Config OK"
152 )
153 WVPASS tee dir/Makefile <<EOF
154 all:
155         novaboot /dev/null
156 EOF
157 WVPASS make -C dir | WVPASS grep "Config OK"
158
159 WVSTART "INTERACTION variable"
160 WVPASS novaboot --remote-cmd=cat <<<INTERACTION=0
161
162 WVSTART "Do not accept directories"
163 WVPASS mkdir -p tftproot
164 WVFAIL novaboot --server=tftproot <<<"load $PWD"
165
166 WVSTART "Accept /dev/null file"
167 WVPASS mkdir -p tftproot
168 WVPASS novaboot --server=tftproot <<<"load /dev/null"
169
170 # Hi-lock: (("^.*\\(?:WVSTART\\).*$" (0 (quote hi-black-b) t)))