tests: Rename capitests -> tests/c-api.
[libguestfs.git] / tests / protocol / test-cancellation-download-librarycancels.sh
1 #!/bin/bash -
2 # libguestfs
3 # Copyright (C) 2009 Red Hat Inc.
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
19 # Test download where the library cancels.
20 #
21 # Download big and small files to /dev/full.  This should fail but not
22 # kill the appliance.  We test various randomized file sizes because
23 # there are many potential race conditions -- for example the daemon
24 # may or may not send all of its data because the error condition is
25 # detected.
26
27 set -e
28
29 rm -f test.img
30
31 size=$(awk 'BEGIN{ srand(); print int(16*1024*rand()) }')
32 echo "$0: test size $size (bytes)"
33
34 ../../fish/guestfish <<EOF
35 # We want the file to be fully allocated.
36 alloc test.img 10M
37 run
38
39 part-disk /dev/sda mbr
40 mkfs ext2 /dev/sda1
41 mount-options "" /dev/sda1 /
42
43 fallocate64 /file $size
44
45 # Download the file into /dev/full so it fails.
46 -download /file /dev/full
47
48 # The daemon should still be reachable after the failure.
49 ping-daemon
50
51 EOF
52
53 rm -f test.img