xref: /freebsd/contrib/pjdfstest/tests/utimensat/01.t (revision cc68614da8232d8baaca0ae0d0dd8f890f06623e)
1#! /bin/sh
2# vim: filetype=sh noexpandtab ts=8 sw=8
3# $FreeBSD$
4
5desc="utimensat with UTIME_NOW will set the will set typestamps to now"
6
7dir=`dirname $0`
8. ${dir}/../misc.sh
9
10require "utimensat"
11
12echo "1..7"
13
14n0=`namegen`
15n1=`namegen`
16TIME_MARGIN=300		# Allow up to a 5 minute delta between the timestamps
17
18expect 0 mkdir ${n1} 0755
19cdir=`pwd`
20cd ${n1}
21
22
23create_file regular ${n0}
24old_mtime=`$fstest lstat ${n0} mtime`
25old_atime=`$fstest lstat ${n0} atime`
26sleep 1	# Ensure that future timestamps will be different than this one
27
28expect 0 open . O_RDONLY : utimensat 0 ${n0} 0 UTIME_NOW 0 UTIME_NOW 0
29new_mtime=`$fstest lstat ${n0} mtime`
30new_atime=`$fstest lstat ${n0} atime`
31delta_mtime=$(( $new_mtime - $old_mtime ))
32delta_atime=$(( $new_atime - $old_atime ))
33
34if [ "$delta_mtime" -gt 0 ]; then
35	if [ "$delta_mtime" -lt $TIME_MARGIN ]; then
36		echo "ok 4"
37	else
38		echo "not ok 4 new mtime is implausibly far in the future"
39	fi
40else
41	echo "not ok 4 mtime was not updated"
42fi
43if [ "$delta_atime" -gt 0 ]; then
44	if [ "$delta_atime" -lt $TIME_MARGIN ]; then
45		echo "ok 5"
46	else
47		echo "not ok 5 new atime is implausibly far in the future"
48	fi
49else
50	echo "not ok 5 atime was not updated"
51fi
52ntest=$((ntest+2))
53expect 0 unlink ${n0}
54
55cd ${cdir}
56expect 0 rmdir ${n1}
57