~ubuntu-branches/ubuntu/raring/libvirt/raring

« back to all changes in this revision

Viewing changes to .pc/apparmor-allow-hugepages/tests/virt-aa-helper-test

  • Committer: Package Import Robot
  • Author(s): Serge Hallyn
  • Date: 2012-12-05 16:43:04 UTC
  • mfrom: (223.1.4 raring-proposed)
  • Revision ID: package-import@ubuntu.com-20121205164304-i4heapilb4ogcgzl
Tags: 1.0.0-0ubuntu4
* debian/patches/apparmor-allow-hugepages: update apparmor policies to
  allow use of hugepages.  (LP: #646468)
* debian/patches/vnc-socket.patch: If a vnc socket is in use, add it's
  path to the apparmor policy.  (LP: #1069534)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
#
 
3
# virt-aa-helper needs a working locale system. If testing this in a chroot
 
4
# system, need to make sure these are setup properly. On Debian-based systems
 
5
# this can be done with something like (as root):
 
6
#  locale-gen en_US.UTF-8
 
7
 
 
8
set -e
 
9
 
 
10
test_hostdev="no"
 
11
if [ "$1" = "test_hostdev" ]; then
 
12
    test_hostdev="yes"
 
13
    shift
 
14
fi
 
15
 
 
16
output="/dev/null"
 
17
use_valgrind=""
 
18
ld_library_path="../src/.libs/"
 
19
if [ ! -z "$1" ] && [ "$1" = "-d" ]; then
 
20
    output="/dev/stdout"
 
21
    shift
 
22
fi
 
23
 
 
24
exe="../src/virt-aa-helper"
 
25
if [ ! -z "$1" ]; then
 
26
    if [ "$1" = "-v" ]; then
 
27
        use_valgrind="yes"
 
28
        shift
 
29
    fi
 
30
    if [ -n "$1" ]; then
 
31
        exe="$1"
 
32
        shift
 
33
    fi
 
34
fi
 
35
 
 
36
if [ ! -x "$exe" ]; then
 
37
    echo "Could not find '$exe'"
 
38
    exit 1
 
39
fi
 
40
 
 
41
echo "testing `basename $exe`" >$output
 
42
if [ "$use_valgrind" = "yes" ]; then
 
43
    exe="valgrind --error-exitcode=2 --track-origins=yes $exe"
 
44
fi
 
45
 
 
46
extra_args="--dryrun"
 
47
errors=0
 
48
 
 
49
tmpdir=`mktemp -d`
 
50
trap "rm -rf $tmpdir" EXIT HUP INT QUIT TERM
 
51
 
 
52
template_xml="$tmpdir/template.xml"
 
53
test_xml="$tmpdir/test.xml"
 
54
 
 
55
uuid="00000000-0000-0000-0000-0123456789ab"
 
56
disk1="$tmpdir/1.img"
 
57
disk2="$tmpdir/2.img"
 
58
relative_disk1="$tmpdir/./../`basename $tmpdir`//./1.img"
 
59
nonexistent="$tmpdir/nonexistant.img"
 
60
bad_disk="/etc/passwd"
 
61
valid_uuid="libvirt-$uuid"
 
62
nonexistent_uuid="libvirt-00000000-0000-0000-0000-000000000001"
 
63
 
 
64
cat > "$template_xml" <<EOM
 
65
<domain type='kvm'>
 
66
  <name>virt-aa-helper-test</name>
 
67
  <uuid>###UUID###</uuid>
 
68
  <memory>524288</memory>
 
69
  <currentMemory>524288</currentMemory>
 
70
  <vcpu>1</vcpu>
 
71
  <os>
 
72
    <type arch='x86_64' machine='pc'>hvm</type>
 
73
    <boot dev='hd'/>
 
74
  </os>
 
75
  <features>
 
76
    <acpi/>
 
77
  </features>
 
78
  <clock offset='utc'/>
 
79
  <on_poweroff>destroy</on_poweroff>
 
80
  <on_reboot>restart</on_reboot>
 
81
  <on_crash>destroy</on_crash>
 
82
  <devices>
 
83
    <emulator>/usr/bin/kvm</emulator>
 
84
    <disk type='file' device='disk'>
 
85
      <driver name='qemu' type='raw'/>
 
86
      <source file='###DISK###'/>
 
87
      <target dev='hda' bus='ide'/>
 
88
    </disk>
 
89
    <interface type='network'>
 
90
      <mac address='52:54:00:50:4b:26'/>
 
91
      <source network='default'/>
 
92
      <model type='virtio'/>
 
93
    </interface>
 
94
    <input type='tablet' bus='usb'/>
 
95
    <input type='mouse' bus='ps2'/>
 
96
    <graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1'/>
 
97
    <video>
 
98
      <model type='cirrus' vram='9216' heads='1'/>
 
99
    </video>
 
100
  </devices>
 
101
</domain>
 
102
EOM
 
103
 
 
104
touch "$disk1" "$disk2"
 
105
 
 
106
testme() {
 
107
    expected="$1"
 
108
    outstr="$2"
 
109
    args="$3"
 
110
    input=""
 
111
 
 
112
    if [ -n "$4" ]; then
 
113
        input="$4"
 
114
        if [ ! -e "$input" ]; then
 
115
            echo "FAIL: could not find $input" >$output
 
116
            echo "FAIL: could not find $input"
 
117
            echo " '$extra_args $args': "
 
118
            errors=$(($errors + 1))
 
119
        fi
 
120
    fi
 
121
 
 
122
    printf %s "  $outstr: " >$output
 
123
    printf %s " '$extra_args $args" >$output
 
124
    if [ -n "$input" ]; then
 
125
        printf %s " < $input" >$output
 
126
    fi
 
127
    echo "': " >$output
 
128
    set +e
 
129
    if [ -n "$input" ]; then
 
130
        LD_LIBRARY_PATH="$ld_library_path" $exe $extra_args $args < $input >$output 2>&1
 
131
    else
 
132
        LD_LIBRARY_PATH="$ld_library_path" $exe $extra_args $args >$output 2>&1
 
133
    fi
 
134
    rc="$?"
 
135
    set -e
 
136
    if [ "$rc" = "$expected" ]; then
 
137
        echo "pass" >$output
 
138
    else
 
139
        echo "FAIL: exited with '$rc'" >$output
 
140
        echo "FAIL: exited with '$rc'"
 
141
        printf %s "  $outstr: "
 
142
        echo " '$extra_args $args': "
 
143
        errors=$(($errors + 1))
 
144
        #exit $rc
 
145
    fi
 
146
}
 
147
 
 
148
# Expected failures
 
149
echo "Expected failures:" >$output
 
150
testme "1" "invalid arg" "-z"
 
151
testme "1" "invalid case" "-A"
 
152
testme "1" "not enough args" "-c"
 
153
testme "1" "not enough args" "-p"
 
154
 
 
155
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" "$template_xml" > "$test_xml"
 
156
testme "1" "no -u with -c" "-c" "$test_xml"
 
157
testme "1" "bad uuid (bad digit)" "-c -u libvirt-00000000-0000-0000-0000-00000000000g" "$test_xml"
 
158
testme "1" "bad uuid (too long)" "-c -u ${valid_uuid}abcdef" "$test_xml"
 
159
testme "1" "bad uuid (too short)" "-c -u libvirt-00000000-0000-0000-0000-0123456789a" "$test_xml"
 
160
testme "1" "non-matching uuid" "-c -u libvirt-00000000-0000-0000-0000-00000000000a" "$test_xml"
 
161
testme "1" "missing uuid" "-c -u" "$test_xml"
 
162
testme "1" "no -u with -R" "-R"
 
163
testme "1" "non-existent uuid" "-R -u $nonexistent_uuid"
 
164
testme "1" "no -u with -r" "-r"
 
165
testme "1" "old '-n' option" "-c -n foo -u $valid_uuid" "$test_xml"
 
166
 
 
167
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$bad_disk,g" "$template_xml" > "$test_xml"
 
168
testme "1" "bad disk" "-c -u $valid_uuid" "$test_xml"
 
169
 
 
170
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$bad_disk,g" -e "s,</devices>,<disk type='file' device='disk'><driver name='qemu' type='raw'/><source file='$disk2'/><target dev='hda' bus='ide'/></disk></devices>,g" "$template_xml" > "$test_xml"
 
171
testme "1" "bad disk2" "-c -u $valid_uuid" "$test_xml"
 
172
 
 
173
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,</devices>,<devices>,g" "$template_xml" > "$test_xml"
 
174
testme "1" "malformed xml" "-c -u $valid_uuid" "$test_xml"
 
175
 
 
176
initrd=`ls -1 /boot/initrd* | head -1`
 
177
if [ -z "$initrd" ]; then
 
178
    echo "Skipping /boot/initrd* tests. Could not find /boot/initrd*"
 
179
else
 
180
    sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$initrd,g" "$template_xml" > "$test_xml"
 
181
    testme "1" "disk in /boot without probing" "-p 0 -r -u $valid_uuid" "$test_xml"
 
182
    testme "1" "disk in /boot with probing" "-p 1 -r -u $valid_uuid" "$test_xml"
 
183
 
 
184
    sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,/boot/initrd,g" "$template_xml" > "$test_xml"
 
185
    testme "1" "-r with invalid -f with probing" "-p 1 -r -u $valid_uuid -f $bad_disk" "$test_xml"
 
186
    testme "1" "-r with invalid -f without probing" "-p 0 -r -u $valid_uuid -f $bad_disk" "$test_xml"
 
187
    testme "1" "-r with invalid -F with probing" "-p 1 -r -u $valid_uuid -F $bad_disk" "$test_xml"
 
188
    testme "1" "-r with invalid -F without probing" "-p 0 -r -u $valid_uuid -F $bad_disk" "$test_xml"
 
189
fi
 
190
 
 
191
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1</disk>,g" "$template_xml" > "$test_xml"
 
192
testme "1" "-c with malformed xml" "-c -u $valid_uuid" "$test_xml"
 
193
 
 
194
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,<type arch='x86_64' machine='pc'>hvm</type>,,g" "$template_xml" > "$test_xml"
 
195
testme "1" "-c with no os.type" "-c -u $valid_uuid" "$test_xml"
 
196
 
 
197
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,<type arch='x86_64' machine='pc'>hvm</type>,<type>hvm</type>,g" "$template_xml" > "$test_xml"
 
198
testme "1" "-c with no architecture" "-c -u $valid_uuid" "$test_xml"
 
199
 
 
200
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,hvm</type>,hvm_invalid</type>,g" "$template_xml" > "$test_xml"
 
201
testme "1" "-c with invalid hvm" "-c -u $valid_uuid" "$test_xml"
 
202
 
 
203
 
 
204
echo "Expected pass:" >$output
 
205
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" "$template_xml" > "$test_xml"
 
206
testme "0" "create (x86_64)" "-c -u $valid_uuid" "$test_xml"
 
207
 
 
208
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,arch='x86_64',arch='i686',g" "$template_xml" > "$test_xml"
 
209
testme "0" "create (i686)" "-c -u $valid_uuid" "$test_xml"
 
210
 
 
211
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,arch='x86_64',arch='ppc',g" "$template_xml" > "$test_xml"
 
212
testme "0" "create (ppc)" "-c -u $valid_uuid" "$test_xml"
 
213
 
 
214
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,</disk>,</disk><disk type='file' device='disk'><driver name='qemu' type='raw'/><source file='$disk2'/><target dev='hdb' bus='ide'/></disk>,g" "$template_xml" > "$test_xml"
 
215
testme "0" "create multiple disks" "-c -u $valid_uuid" "$test_xml"
 
216
 
 
217
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###',${disk1}'/><readonly,g" "$template_xml" > "$test_xml"
 
218
testme "0" "create (readonly)" "-c -u $valid_uuid" "$test_xml"
 
219
 
 
220
if [ "$test_hostdev" = "yes" ]; then
 
221
    sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,</disk>,</disk><hostdev mode='subsystem' type='usb'><source><address bus='002' device='004'/></source></hostdev>,g" "$template_xml" > "$test_xml"
 
222
    testme "0" "create hostdev (USB)" "-c -u $valid_uuid" "$test_xml"
 
223
 
 
224
    sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,</disk>,</disk><hostdev mode='subsystem' type='pci'><source><address bus='0x00' slot='0x19' function='0x0'/></source></hostdev>,g" "$template_xml" > "$test_xml"
 
225
    testme "0" "create hostdev (PCI)" "-c -u $valid_uuid" "$test_xml"
 
226
fi
 
227
 
 
228
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$nonexistent,g" "$template_xml" > "$test_xml"
 
229
testme "0" "create (non-existent disk)" "-c -u $valid_uuid" "$test_xml"
 
230
 
 
231
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$relative_disk1,g" "$template_xml" > "$test_xml"
 
232
testme "0" "create (relative path)" "-c -u $valid_uuid" "$test_xml"
 
233
 
 
234
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk2,g" "$template_xml" > "$test_xml"
 
235
testme "0" "replace" "-r -u $valid_uuid" "$test_xml"
 
236
 
 
237
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$nonexistent,g" "$template_xml" > "$test_xml"
 
238
testme "0" "replace (non-existent disk)" "-r -u $valid_uuid" "$test_xml"
 
239
 
 
240
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" "$template_xml" > "$test_xml"
 
241
testme "0" "replace (adding disk)" "-r -u $valid_uuid -f $disk2" "$test_xml"
 
242
 
 
243
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" "$template_xml" > "$test_xml"
 
244
testme "0" "replace (adding non-existent disk)" "-r -u $valid_uuid -f $nonexistent" "$test_xml"
 
245
 
 
246
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" "$template_xml" > "$test_xml"
 
247
testme "0" "replace (appending disk)" "-r -u $valid_uuid -F $disk2" "$test_xml"
 
248
 
 
249
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" "$template_xml" > "$test_xml"
 
250
testme "0" "replace (appending non-existent disk)" "-r -u $valid_uuid -F $nonexistent" "$test_xml"
 
251
 
 
252
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,</devices>,<disk type='block' device='cdrom'><target dev='hdc' bus='ide'/><readonly/></disk></devices>,g" "$template_xml" > "$test_xml"
 
253
testme "0" "disk (empty cdrom)" "-r -u $valid_uuid" "$test_xml"
 
254
 
 
255
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,</devices>,<serial type='file'><source path='$tmpdir/serial.log'/><target port='0'/></serial></devices>,g" "$template_xml" > "$test_xml"
 
256
testme "0" "serial" "-r -u $valid_uuid" "$test_xml"
 
257
 
 
258
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,</devices>,<serial type='pty'><target port='0'/></serial></devices>,g" "$template_xml" > "$test_xml"
 
259
testme "0" "serial (pty)" "-r -u $valid_uuid" "$test_xml"
 
260
 
 
261
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,</devices>,<serial type='dev'><source path='/dev/ttyS0'/><target port='0'/></serial></devices>,g" "$template_xml" > "$test_xml"
 
262
testme "0" "serial (dev)" "-r -u $valid_uuid" "$test_xml"
 
263
 
 
264
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,</devices>,<serial type='pipe'><source path='$tmpdir/serial.pipe'/><target port='0'/></serial></devices>,g" "$template_xml" > "$test_xml"
 
265
mkfifo "$tmpdir/serial.pipe.in" "$tmpdir/serial.pipe.out"
 
266
testme "0" "serial (pipe)" "-r -u $valid_uuid" "$test_xml"
 
267
 
 
268
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,</devices>,<console type='file'><source path='$tmpdir/console.log'/><target port='0'/></console></devices>,g" "$template_xml" > "$test_xml"
 
269
touch "$tmpdir/console.log"
 
270
testme "0" "console" "-r -u $valid_uuid" "$test_xml"
 
271
 
 
272
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,</devices>,<console type='pty'><target port='0'/></console></devices>,g" "$template_xml" > "$test_xml"
 
273
testme "0" "console (pty)" "-r -u $valid_uuid" "$test_xml"
 
274
 
 
275
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,</devices>,<console type='pipe'><source path='$tmpdir/console.pipe'/><target port='0'/></console></devices>,g" "$template_xml" > "$test_xml"
 
276
mkfifo "$tmpdir/console.pipe.in" "$tmpdir/console.pipe.out"
 
277
testme "0" "console (pipe)" "-r -u $valid_uuid" "$test_xml"
 
278
 
 
279
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,</devices>,<parallel type='pty'><source path='/dev/pts/0'/><target port='0'/></parallel></devices>,g" "$template_xml" > "$test_xml"
 
280
testme "0" "parallel (pty)" "-r -u $valid_uuid" "$test_xml"
 
281
 
 
282
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,</devices>,<parallel type='pipe'><source path='$tmpdir/parallel.pipe'/><target port='0'/></parallel></devices>,g" "$template_xml" > "$test_xml"
 
283
mkfifo "$tmpdir/parallel.pipe.in" "$tmpdir/parallel.pipe.out"
 
284
testme "0" "parallel (pipe)" "-r -u $valid_uuid" "$test_xml"
 
285
 
 
286
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,</devices>,<channel type='unix'><source mode='bind' path='$tmpdir/guestfwd'/><target type='guestfwd' address='10.0.2.1' port='4600'/></channel></devices>,g" "$template_xml" > "$test_xml"
 
287
touch "$tmpdir/guestfwd"
 
288
testme "0" "channel (unix)" "-r -u $valid_uuid" "$test_xml"
 
289
 
 
290
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,</devices>,<channel type='pty'><target type='virtio'/></channel></devices>,g" "$template_xml" > "$test_xml"
 
291
testme "0" "channel (pty)" "-r -u $valid_uuid" "$test_xml"
 
292
 
 
293
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,</os>,<kernel>$tmpdir/kernel</kernel></os>,g" "$template_xml" > "$test_xml"
 
294
touch "$tmpdir/kernel"
 
295
testme "0" "kernel" "-r -u $valid_uuid" "$test_xml"
 
296
 
 
297
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,</os>,<initrd>$tmpdir/initrd</initrd></os>,g" "$template_xml" > "$test_xml"
 
298
touch "$tmpdir/initrd"
 
299
testme "0" "initrd" "-r -u $valid_uuid" "$test_xml"
 
300
 
 
301
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,</os>,<kernel>/boot/kernel</kernel></os>,g" "$template_xml" > "$test_xml"
 
302
testme "0" "kernel in /boot" "-r -u $valid_uuid" "$test_xml"
 
303
 
 
304
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,</os>,<initrd>/boot/initrd</initrd></os>,g" "$template_xml" > "$test_xml"
 
305
testme "0" "initrd in /boot" "-r -u $valid_uuid" "$test_xml"
 
306
 
 
307
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,</os>,<kernel>/vmlinuz</kernel></os>,g" "$template_xml" > "$test_xml"
 
308
testme "0" "kernel is /vmlinuz" "-r -u $valid_uuid" "$test_xml"
 
309
 
 
310
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,</os>,<initrd>/initrd/ramdisk</initrd></os>,g" "$template_xml" > "$test_xml"
 
311
testme "0" "initrd is /initrd/ramdisk" "-r -u $valid_uuid" "$test_xml"
 
312
 
 
313
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,</os>,<initrd>/initrd.img</initrd></os>,g" "$template_xml" > "$test_xml"
 
314
testme "0" "initrd is /initrd.img" "-r -u $valid_uuid" "$test_xml"
 
315
 
 
316
sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,<graphics*,<graphics type='sdl' display=':0.0' xauth='/home/myself/.Xauthority'/>,g" "$template_xml" > "$test_xml"
 
317
testme "0" "sdl Xauthority" "-r -u $valid_uuid" "$test_xml"
 
318
 
 
319
testme "0" "help" "-h"
 
320
 
 
321
echo "" >$output
 
322
if [ "$errors" != "0" ]; then
 
323
    echo "FAIL: $errors error(s)" >$output
 
324
    exit 1
 
325
fi
 
326
echo PASS >$output