Git init
[external/ifupdown.git] / debian / testbuild
1 #!/bin/sh -e
2
3 rm -rf tests/
4 mkdir tests
5
6 cat >tests/testcase.1 <<EOF
7 # RUN: -a
8 auto eth0
9 iface eth0 inet static
10   address 1.2.3.4
11   netmask 255.255.255.0
12   up echo hi
13   post-up echo hello
14 EOF
15 cat >tests/up.1 <<EOF
16 ====stdout====
17 ====stderr====
18 Configuring interface eth0=eth0 (inet)
19 run-parts --verbose /etc/network/if-pre-up.d
20
21 ifconfig eth0 1.2.3.4 netmask 255.255.255.0      up
22
23 echo hi
24 echo hello
25 run-parts --verbose /etc/network/if-up.d
26 EOF
27
28 cat >tests/testcase.2 <<EOF
29 # RUN: -a
30 auto eth0 eth1 eth2
31 auto eth3 eth4 eth5
32 allow-hotplug eth6
33 iface eth0 inet static
34   address 1.2.3.4
35   netmask 255.255.255.0
36 iface eth1 inet static
37   address 1.3.4.5
38   netmask 255.255.255.0
39 iface eth2 inet static
40   address 1.4.5.6
41   netmask 255.255.255.0
42 iface eth3 inet static
43   address 1.5.6.7
44   netmask 255.255.255.0
45 iface eth4 inet static
46   address 1.7.8.9
47   netmask 255.255.255.0
48 iface eth5 inet static
49   address 1.8.9.10
50   netmask 255.255.255.0
51 iface eth6 inet static
52   address 1.11.12.13
53   netmask 255.255.255.0
54 iface eth7 inet static
55   address 1.14.15.16
56   netmask 255.255.255.0
57 EOF
58 cat >tests/up.2 <<EOF
59 ====stdout====
60 ====stderr====
61 Configuring interface eth0=eth0 (inet)
62 run-parts --verbose /etc/network/if-pre-up.d
63
64 ifconfig eth0 1.2.3.4 netmask 255.255.255.0      up
65
66 run-parts --verbose /etc/network/if-up.d
67 Configuring interface eth1=eth1 (inet)
68 run-parts --verbose /etc/network/if-pre-up.d
69
70 ifconfig eth1 1.3.4.5 netmask 255.255.255.0      up
71
72 run-parts --verbose /etc/network/if-up.d
73 Configuring interface eth2=eth2 (inet)
74 run-parts --verbose /etc/network/if-pre-up.d
75
76 ifconfig eth2 1.4.5.6 netmask 255.255.255.0      up
77
78 run-parts --verbose /etc/network/if-up.d
79 Configuring interface eth3=eth3 (inet)
80 run-parts --verbose /etc/network/if-pre-up.d
81
82 ifconfig eth3 1.5.6.7 netmask 255.255.255.0      up
83
84 run-parts --verbose /etc/network/if-up.d
85 Configuring interface eth4=eth4 (inet)
86 run-parts --verbose /etc/network/if-pre-up.d
87
88 ifconfig eth4 1.7.8.9 netmask 255.255.255.0      up
89
90 run-parts --verbose /etc/network/if-up.d
91 Configuring interface eth5=eth5 (inet)
92 run-parts --verbose /etc/network/if-pre-up.d
93
94 ifconfig eth5 1.8.9.10 netmask 255.255.255.0     up
95
96 run-parts --verbose /etc/network/if-up.d
97 EOF
98 cat >tests/testcase.3 <<EOF
99 # RUN: -a
100 auto eth0
101 iface eth0 inet static
102   address 1.2.3.4
103   netmask 255.255.255.0
104 iface eth0 inet6 static
105   address 3ffe:ffff:100:f101::1
106   netmask 64
107 EOF
108 cat >tests/up.3 <<EOF
109 ====stdout====
110 ====stderr====
111 Configuring interface eth0=eth0 (inet)
112 run-parts --verbose /etc/network/if-pre-up.d
113
114 ifconfig eth0 1.2.3.4 netmask 255.255.255.0             up
115
116 run-parts --verbose /etc/network/if-up.d
117 Configuring interface eth0=eth0 (inet6)
118 run-parts --verbose /etc/network/if-pre-up.d
119 ifconfig eth0    up
120 ifconfig eth0 add 3ffe:ffff:100:f101::1/64
121
122 run-parts --verbose /etc/network/if-up.d
123 EOF
124
125 cat >tests/testcase.4 <<EOF
126 # RUN: eth0=work
127 mapping eth0
128   script tests/map.eth0.work
129 iface work inet static
130   address 1.2.3.4
131   netmask 255.255.255.0
132   up echo hi
133   post-up echo hello
134 EOF
135 cat >tests/up.4 <<EOF
136 ====stdout====
137 ====stderr====
138 Configuring interface eth0=work (inet)
139 run-parts --verbose /etc/network/if-pre-up.d
140
141 ifconfig eth0 1.2.3.4 netmask 255.255.255.0      up
142
143 echo hi
144 echo hello
145 run-parts --verbose /etc/network/if-up.d
146 EOF
147
148
149 result=true
150 for test in 1 2 3 4; do
151         args="$(cat tests/testcase.$test | sed -n 's/^# RUN: //p')"
152         ./ifup -nv --force -i tests/testcase.$test $args \
153                 >tests/up-res-out.$test 2>tests/up-res-err.$test || 
154                 true
155         (echo "====stdout===="; cat tests/up-res-out.$test
156          echo "====stderr===="; cat tests/up-res-err.$test) > tests/up-res.$test
157
158         echo "Testcase $test: $args"
159         
160         if diff -ub tests/up.$test tests/up-res.$test; then
161                 echo "(okay)"
162         else
163                 echo "(failed)"
164                 result=false
165         fi
166         echo "=========="
167 done
168
169 if $result; then
170         echo "(okay overall)"
171         exit 0
172 else
173         echo "(failed overall)"
174         exit 1
175 fi