Skip to content

Commit 5d903f1

Browse files
Ryan MoellerRyan Moeller
authored andcommitted
ZTS: Add tests for creation time
Signed-off-by: Ryan Moeller <[email protected]>
1 parent ca36909 commit 5d903f1

File tree

10 files changed

+183
-5
lines changed

10 files changed

+183
-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
@@ -575,6 +575,10 @@ tags = ['functional', 'compression']
575575
tests = ['cp_files_001_pos']
576576
tags = ['functional', 'cp_files']
577577

578+
[tests/functional/crtime]
579+
tests = ['crtime_001_pos' ]
580+
tags = ['functional', 'crtime']
581+
578582
[tests/functional/ctime]
579583
tests = ['ctime_001_pos' ]
580584
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
@@ -4024,6 +4024,34 @@ function stat_size #<path>
40244024
esac
40254025
}
40264026

4027+
function stat_ctime #<path>
4028+
{
4029+
typeset path=$1
4030+
4031+
case $(uname) in
4032+
FreeBSD)
4033+
stat -f %c "$path"
4034+
;;
4035+
*)
4036+
stat -c %Z "$path"
4037+
;;
4038+
esac
4039+
}
4040+
4041+
function stat_crtime #<path>
4042+
{
4043+
typeset path=$1
4044+
4045+
case $(uname) in
4046+
FreeBSD)
4047+
stat -f %B "$path"
4048+
;;
4049+
*)
4050+
stat -c %W "$path"
4051+
;;
4052+
esac
4053+
}
4054+
40274055
# Run a command as if it was being run in a TTY.
40284056
#
40294057
# 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: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
fi
44+
45+
log_assert "Verify crtime is functional."
46+
47+
set -A args "sa" "on"
48+
typeset TESTFILE=$TESTDIR/testfile
49+
50+
for arg in ${args[*]}; do
51+
log_note "Testing with xattr set to $arg"
52+
log_must zfs set xattr=$arg $TESTPOOL
53+
rm -f $TESTFILE
54+
log_must touch $TESTFILE
55+
typeset -i crtime=$(stat_crtime $TESTFILE)
56+
typeset -i ctime=$(stat_ctime $TESTFILE)
57+
if (( crtime != ctime )); then
58+
log_fail "Incorrect crtime ($crtime != $ctime)"
59+
fi
60+
log_must touch $TESTFILE
61+
typeset -i crtime1=$(stat_crtime $TESTFILE)
62+
if (( crtime1 != crtime )); then
63+
log_fail "touch modified crtime ($crtime1 != $crtime)"
64+
fi
65+
done
66+
67+
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)