~ubuntu-branches/ubuntu/utopic/coreutils/utopic-proposed

« back to all changes in this revision

Viewing changes to tests/dd/sparse.sh

  • Committer: Package Import Robot
  • Author(s): Colin Watson
  • Date: 2012-11-28 03:03:42 UTC
  • mfrom: (8.3.4 sid)
  • Revision ID: package-import@ubuntu.com-20121128030342-21zanj8354gas5gr
Tags: 8.20-3ubuntu1
* Resynchronise with Debian.  Remaining changes:
  - Make 'uname -i -p' return the real processor/hardware, instead of
    unknown.
  - Build-depend on gettext:any instead of on gettext, so that apt-get can
    properly resolve build-dependencies on the tool when cross-building.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
 
 
3
# Copyright (C) 2012 Free Software Foundation, 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 3 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, see <http://www.gnu.org/licenses/>.
 
17
 
 
18
. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
 
19
print_ver_ dd
 
20
require_sparse_support_
 
21
 
 
22
# Ensure basic sparse generation works
 
23
truncate -s1M sparse
 
24
dd bs=32K if=sparse of=sparse.dd conv=sparse
 
25
test $(stat -c %s sparse) = $(stat -c %s sparse.dd) || fail=1
 
26
 
 
27
# Demonstrate that conv=sparse with oflag=append,
 
28
# will do ineffective seeks in the output
 
29
printf 'a\000\000b' > file.in
 
30
printf 'ab' > exp
 
31
dd if=file.in bs=1 conv=sparse oflag=append > out
 
32
compare exp out || fail=1
 
33
 
 
34
# Demonstrate conv=sparse with conv=notrunc,
 
35
# where data in file.out is not overwritten with NULs
 
36
printf '____' > out
 
37
printf 'a__b' > exp
 
38
dd if=file.in bs=1 conv=sparse,notrunc of=out
 
39
compare exp out || fail=1
 
40
 
 
41
# Ensure we fall back to write if seek fails
 
42
dd if=file.in bs=1 conv=sparse | cat > file.out
 
43
cmp file.in file.out || fail=1
 
44
 
 
45
# Setup for block size tests: create a 3MiB file with a 1MiB
 
46
# stretch of NUL bytes in the middle.
 
47
rm -f file.in
 
48
dd if=/dev/urandom of=file.in bs=1M count=3 iflag=fullblock || fail=1
 
49
dd if=/dev/zero    of=file.in bs=1M count=1 seek=1 conv=notrunc || fail=1
 
50
 
 
51
kb_alloc() { du -k "$1"|cut -f1; }
 
52
 
 
53
# If our just-created input file appears to be too small,
 
54
# skip the remaining tests.  On at least Solaris 10 with NFS,
 
55
# file.in is reported to occupy <= 1KiB for about 50 seconds
 
56
# after its creation.
 
57
if test $(kb_alloc file.in) -gt 3000; then
 
58
 
 
59
  # Ensure NUL blocks smaller than the block size are not made sparse.
 
60
  # Here, with a 2MiB block size, dd's conv=sparse must *not* introduce a hole.
 
61
  dd if=file.in of=file.out bs=2M conv=sparse
 
62
  test 2500 -lt $(kb_alloc file.out) || fail=1
 
63
 
 
64
  # Ensure that this 1MiB string of NULs *is* converted to a hole.
 
65
  dd if=file.in of=file.out bs=1M conv=sparse
 
66
  test $(kb_alloc file.out) -lt 2500 || fail=1
 
67
 
 
68
fi
 
69
 
 
70
Exit $fail