docs: Move release notes to their own section.
[nbdkit/ericb.git] / tests / test-shell.sh
blob028b8b9cd1f01880f2757ed95baa6e1ccb18730b
1 #!/usr/bin/env sh
3 # Assume that the current directory is the tests/ directory.
4 # If this fails we're probably running the test from the wrong
5 # directory.
6 f=test-shell.img
7 if [ ! -r $f ]; then
8 echo "cannot find disk image $f" >&2
9 exit 1
12 # nbdkit is supposed to set $tmpdir. If it doesn't, it's an error.
13 if [ ! -d $tmpdir ]; then
14 echo "\$tmpdir was not set" >&2
15 exit 1
18 # Check that SIGPIPE is not ignored unless we want it that way.
19 if (type yes) >/dev/null 2>&1; then
20 ignored=$(trap "" 13;
21 ({ yes; echo $? >&3; } | head -c1) 3>&1 >/dev/null 2>&1)
22 default=$(trap - 13;
23 ({ yes; echo $? >&3; } | head -c1) 3>&1 >/dev/null 2>&1)
24 if [ $ignored = $default ]; then
25 echo "SIGPIPE was inherited ignored" >&2
26 exit 1;
30 case "$1" in
31 thread_model)
32 echo parallel
35 open)
36 echo handle
39 get_size)
40 stat -L -c '%s' $f || exit 1
43 pread)
44 dd iflag=skip_bytes,count_bytes skip=$4 count=$3 if=$f || \
45 exit 1
48 pwrite)
49 case $5 in
50 '' | fua) ;;
51 *) echo "garbage flags: '$5'" >&2
52 exit 1;
53 esac
54 dd oflag=seek_bytes conv=notrunc seek=$4 of=$f || exit 1
56 can_write)
59 flush)
60 sync
62 can_flush)
65 trim)
66 case $5 in
67 '' | fua) ;;
68 *) echo "garbage flags: '$5'" >&2
69 exit 1;
70 esac
71 fallocate -p -o $4 -l $3 -n $f
73 can_trim)
74 # We can trim if the fallocate command exists.
75 fallocate --help >/dev/null 2>&1 || exit 3
78 zero)
79 case $5 in
80 '' | fua | may_trim | fua,may_trim ) ;;
81 *) echo "garbage flags: '$5'" >&2
82 exit 1;
83 esac
84 fallocate -z -o $4 -l $3 -n $f
86 can_zero)
87 # We can zero efficiently if the fallocate command exists.
88 fallocate --help >/dev/null 2>&1 || exit 3
92 # Unknown methods must exit with code 2.
93 exit 2
94 esac
96 exit 0