]> git.proxmox.com Git - mirror_zfs.git/blob - tests/zfs-tests/tests/functional/truncate/truncate_timestamps.ksh
ZTS: fix "not found" errors
[mirror_zfs.git] / tests / zfs-tests / tests / functional / truncate / truncate_timestamps.ksh
1 #!/bin/ksh -p
2 #
3 # This file and its contents are supplied under the terms of the
4 # Common Development and Distribution License ("CDDL"), version 1.0.
5 # You may only use this file in accordance with the terms of version
6 # 1.0 of the CDDL.
7 #
8 # A full copy of the text of the CDDL should have accompanied this
9 # source. A copy of the CDDL is also available via the Internet at
10 # http://www.illumos.org/license/CDDL.
11 #
12
13 #
14 # Copyright 2017, loli10K <ezomori.nozomu@gmail.com>. All rights reserved.
15 #
16
17 . $STF_SUITE/tests/functional/truncate/truncate.cfg
18 . $STF_SUITE/include/libtest.shlib
19 . $STF_SUITE/include/math.shlib
20
21 #
22 # DESCRIPTION:
23 # Ensure both truncate(2)/ftruncate(2) update target file mtime/ctime attributes
24 #
25 # STRATEGY:
26 # 1. Create a file
27 # 2. Truncate the file
28 # 3. Verify both mtime/ctime are updated
29 # 4. Rinse and repeat for both truncate(2) and ftruncate(2) with various sizes
30 #
31
32 verify_runnable "both"
33
34 function verify_truncate # <filename> <filesize> <option>
35 {
36 typeset filename="$1"
37 typeset -i size="$2"
38 typeset option="$3"
39
40 log_must mkfile $sizeavg $filename # always start with $sizeavg
41 typeset -i timestm="$(stat -c %Y $filename)"
42 typeset -i timestc="$(stat -c %Z $filename)"
43 log_must sleep 1
44 log_must $STF_SUITE/tests/functional/truncate/truncate_test -s $size $filename $option
45 verify_eq $size "$(stat -c %s $filename)" "size"
46 verify_ne $timestm "$(stat -c %Y $filename)" "mtime"
47 verify_ne $timestc "$(stat -c %Z $filename)" "ctime"
48 log_must rm -f $filename
49 }
50
51 function cleanup
52 {
53 [[ -f $truncfile ]] && rm -f $truncfile
54 }
55
56 log_assert "Ensure both truncate(2)/ftruncate(2) update target file timestamps"
57 log_onexit cleanup
58
59 truncfile="$TESTDIR/truncate.$$"
60 sizemin="123"
61 sizeavg="$((256*1024))"
62 sizemax="$((1024*1024))"
63
64 # truncate(2)
65 verify_truncate $truncfile $sizemin ""
66 verify_truncate $truncfile $sizeavg ""
67 verify_truncate $truncfile $sizemax ""
68
69 # ftruncate(2)
70 verify_truncate $truncfile $sizemin "-f"
71 verify_truncate $truncfile $sizeavg "-f"
72 verify_truncate $truncfile $sizemax "-f"
73
74 log_pass "Successful truncation correctly update timestamps"