Skip to content

Commit 213bb01

Browse files
Ryan Moellerbehlendorf
authored andcommitted
ZTS: Add tests for creation time
Reviewed-by: Tony Nguyen <[email protected]> Reviewed-by: Allan Jude <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Alexander Motin <[email protected]> Signed-off-by: Ryan Moeller <[email protected]> Closes #12432
1 parent 3c72042 commit 213bb01

File tree

10 files changed

+187
-5
lines changed

10 files changed

+187
-5
lines changed

configure.ac

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ AC_CONFIG_FILES([
327327
tests/zfs-tests/tests/functional/cli_user/zpool_status/Makefile
328328
tests/zfs-tests/tests/functional/compression/Makefile
329329
tests/zfs-tests/tests/functional/cp_files/Makefile
330+
tests/zfs-tests/tests/functional/crtime/Makefile
330331
tests/zfs-tests/tests/functional/ctime/Makefile
331332
tests/zfs-tests/tests/functional/deadman/Makefile
332333
tests/zfs-tests/tests/functional/delegate/Makefile

tests/runfiles/common.run

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,10 @@ tags = ['functional', 'compression']
574574
tests = ['cp_files_001_pos']
575575
tags = ['functional', 'cp_files']
576576

577+
[tests/functional/crtime]
578+
tests = ['crtime_001_pos' ]
579+
tags = ['functional', 'crtime']
580+
577581
[tests/functional/ctime]
578582
tests = ['ctime_001_pos' ]
579583
tags = ['functional', 'ctime']

tests/test-runner/bin/zts-report.py.in

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ python_deps_reason = 'Python modules missing: python-cffi'
7575
#
7676
tmpfile_reason = 'Kernel O_TMPFILE support required'
7777

78+
#
79+
# Some tests require the statx(2) system call on Linux which was first
80+
# introduced in the 4.11 kernel.
81+
#
82+
statx_reason = 'Kernel statx(2) system call required on Linux'
83+
7884
#
7985
# Some tests require that the NFS client and server utilities be installed.
8086
#
@@ -193,6 +199,7 @@ elif sys.platform.startswith('linux'):
193199
#
194200
maybe = {
195201
'chattr/setup': ['SKIP', exec_reason],
202+
'crtime/crtime_001_pos': ['SKIP', statx_reason],
196203
'cli_root/zdb/zdb_006_pos': ['FAIL', known_reason],
197204
'cli_root/zfs_destroy/zfs_destroy_dev_removal_condense':
198205
['FAIL', known_reason],

tests/zfs-tests/include/libtest.shlib

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4048,6 +4048,34 @@ function stat_size #<path>
40484048
esac
40494049
}
40504050

4051+
function stat_ctime #<path>
4052+
{
4053+
typeset path=$1
4054+
4055+
case $(uname) in
4056+
FreeBSD)
4057+
stat -f %c "$path"
4058+
;;
4059+
*)
4060+
stat -c %Z "$path"
4061+
;;
4062+
esac
4063+
}
4064+
4065+
function stat_crtime #<path>
4066+
{
4067+
typeset path=$1
4068+
4069+
case $(uname) in
4070+
FreeBSD)
4071+
stat -f %B "$path"
4072+
;;
4073+
*)
4074+
stat -c %W "$path"
4075+
;;
4076+
esac
4077+
}
4078+
40514079
# Run a command as if it was being run in a TTY.
40524080
#
40534081
# Usage:

tests/zfs-tests/tests/functional/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ SUBDIRS = \
1616
cli_user \
1717
compression \
1818
cp_files \
19+
crtime \
1920
ctime \
2021
deadman \
2122
delegate \

tests/zfs-tests/tests/functional/cli_root/zfs_diff/zfs_diff_timestamp.ksh

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,7 @@ do
8484
continue;
8585
fi
8686

87-
if is_freebsd; then
88-
filetime="$(stat -f "%c" $file)"
89-
else
90-
filetime="$(stat -c '%Z' $file)"
91-
fi
87+
filetime=$(stat_ctime $file)
9288
if [[ "$filetime" != "$ctime" ]]; then
9389
log_fail "Unexpected ctime for file $file ($filetime != $ctime)"
9490
else
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/crtime
2+
dist_pkgdata_SCRIPTS = \
3+
cleanup.ksh \
4+
setup.ksh \
5+
crtime_001_pos.ksh
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/ksh -p
2+
#
3+
# CDDL HEADER START
4+
#
5+
# The contents of this file are subject to the terms of the
6+
# Common Development and Distribution License (the "License").
7+
# You may not use this file except in compliance with the License.
8+
#
9+
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10+
# or http://www.opensolaris.org/os/licensing.
11+
# See the License for the specific language governing permissions
12+
# and limitations under the License.
13+
#
14+
# When distributing Covered Code, include this CDDL HEADER in each
15+
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16+
# If applicable, add the following below this CDDL HEADER, with the
17+
# fields enclosed by brackets "[]" replaced with your own identifying
18+
# information: Portions Copyright [yyyy] [name of copyright owner]
19+
#
20+
# CDDL HEADER END
21+
#
22+
23+
#
24+
# Copyright 2007 Sun Microsystems, Inc. All rights reserved.
25+
# Use is subject to license terms.
26+
#
27+
28+
#
29+
# Copyright (c) 2013 by Delphix. All rights reserved.
30+
#
31+
32+
. $STF_SUITE/include/libtest.shlib
33+
34+
default_cleanup
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/bin/ksh -p
2+
#
3+
# CDDL HEADER START
4+
#
5+
# The contents of this file are subject to the terms of the
6+
# Common Development and Distribution License (the "License").
7+
# You may not use this file except in compliance with the License.
8+
#
9+
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10+
# or http://www.opensolaris.org/os/licensing.
11+
# See the License for the specific language governing permissions
12+
# and limitations under the License.
13+
#
14+
# When distributing Covered Code, include this CDDL HEADER in each
15+
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16+
# If applicable, add the following below this CDDL HEADER, with the
17+
# fields enclosed by brackets "[]" replaced with your own identifying
18+
# information: Portions Copyright [yyyy] [name of copyright owner]
19+
#
20+
# CDDL HEADER END
21+
#
22+
# Portions Copyright 2021 iXsystems, Inc.
23+
#
24+
25+
. $STF_SUITE/include/libtest.shlib
26+
27+
#
28+
# DESCRIPTION:
29+
#
30+
# Verify crtime is functional with xattr=on|sa
31+
32+
verify_runnable "both"
33+
34+
#
35+
# The statx system call was first added in the 4.11 Linux kernel. Prior to this
36+
# change there was no mechanism to obtain birth time on Linux. Therefore, this
37+
# test is expected to fail on older kernels and is skipped.
38+
#
39+
if is_linux; then
40+
if [[ $(linux_version) -lt $(linux_version "4.11") ]]; then
41+
log_unsupported "Requires statx(2) system call on Linux"
42+
fi
43+
typeset stat_version=$(stat --version | awk '{ print $NF; exit }')
44+
if compare_version_gte "8.30" "${stat_version}"; then
45+
log_unsupported "Requires coreutils stat(1) > 8.30 on Linux"
46+
fi
47+
fi
48+
49+
log_assert "Verify crtime is functional."
50+
51+
set -A args "sa" "on"
52+
typeset TESTFILE=$TESTDIR/testfile
53+
54+
for arg in ${args[*]}; do
55+
log_note "Testing with xattr set to $arg"
56+
log_must zfs set xattr=$arg $TESTPOOL
57+
rm -f $TESTFILE
58+
log_must touch $TESTFILE
59+
typeset -i crtime=$(stat_crtime $TESTFILE)
60+
typeset -i ctime=$(stat_ctime $TESTFILE)
61+
if (( crtime != ctime )); then
62+
log_fail "Incorrect crtime ($crtime != $ctime)"
63+
fi
64+
log_must touch $TESTFILE
65+
typeset -i crtime1=$(stat_crtime $TESTFILE)
66+
if (( crtime1 != crtime )); then
67+
log_fail "touch modified crtime ($crtime1 != $crtime)"
68+
fi
69+
done
70+
71+
log_pass "Verified crtime is functional."
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/ksh -p
2+
#
3+
# CDDL HEADER START
4+
#
5+
# The contents of this file are subject to the terms of the
6+
# Common Development and Distribution License (the "License").
7+
# You may not use this file except in compliance with the License.
8+
#
9+
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10+
# or http://www.opensolaris.org/os/licensing.
11+
# See the License for the specific language governing permissions
12+
# and limitations under the License.
13+
#
14+
# When distributing Covered Code, include this CDDL HEADER in each
15+
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16+
# If applicable, add the following below this CDDL HEADER, with the
17+
# fields enclosed by brackets "[]" replaced with your own identifying
18+
# information: Portions Copyright [yyyy] [name of copyright owner]
19+
#
20+
# CDDL HEADER END
21+
#
22+
23+
#
24+
# Copyright 2007 Sun Microsystems, Inc. All rights reserved.
25+
# Use is subject to license terms.
26+
#
27+
28+
#
29+
# Copyright (c) 2013 by Delphix. All rights reserved.
30+
#
31+
32+
. $STF_SUITE/include/libtest.shlib
33+
34+
DISK=${DISKS%% *}
35+
default_setup $DISK

0 commit comments

Comments
 (0)