• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2
3################################################################################
4##                                                                            ##
5## Copyright (c) 2009 FUJITSU LIMITED                                         ##
6##                                                                            ##
7## This program is free software;  you can redistribute it and#or modify      ##
8## it under the terms of the GNU General Public License as published by       ##
9## the Free Software Foundation; either version 2 of the License, or          ##
10## (at your option) any later version.                                        ##
11##                                                                            ##
12## This program is distributed in the hope that it will be useful, but        ##
13## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ##
14## or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License   ##
15## for more details.                                                          ##
16##                                                                            ##
17## You should have received a copy of the GNU General Public License          ##
18## along with this program;  if not, write to the Free Software               ##
19## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA    ##
20##                                                                            ##
21## Author: Li Zefan <lizf@cn.fujitsu.com>                                     ##
22##         Miao Xie <miaox@cn.fujitsu.com>                                    ##
23##                                                                            ##
24################################################################################
25
26export TCID="ext4-nsec-timestamps"
27export TST_TOTAL=2
28
29. ext4_funcs.sh
30
31# Test that file timestamps is second with 128 inode size
32ext4_test_sec_timestamps()
33{
34	tst_resm TINFO "Test timestamps with 128 inode size"
35
36	mkfs.ext4 -I 128 $EXT4_DEV >/dev/null 2>&1
37	if [ $? -ne 0 ]; then
38		tst_resm TFAIL "failed to create ext4 filesystem"
39		return
40	fi
41
42	tune2fs -O extents $EXT4_DEV >/dev/null 2>&1
43
44	mount -t ext4 $EXT4_DEV mnt_point
45	if [ $? -ne 0 ]; then
46		tst_resm TFAIL "failed to mount ext4 filesystem"
47		return
48	fi
49
50	touch mnt_point/tmp_file
51
52	atime=`ext4_file_time mnt_point/tmp_file atime nsec`
53	mtime=`ext4_file_time mnt_point/tmp_file mtime nsec`
54	ctime=`ext4_file_time mnt_point/tmp_file ctime nsec`
55
56	if [ $atime -ne 0 -o $mtime -ne 0 -o $ctime -ne 0 ]; then
57		tst_resm TFAIL "Timestamp is not second(atime: $atime, mtime: \
58				$mtime, ctime: $ctime)"
59		tst_umount mnt_point
60		return
61	fi
62	tst_umount mnt_point
63
64	tst_resm TPASS "Ext4 nanosecond timestamps test with 128 inode size pass"
65}
66
67# Test file timestamps is nanosecond with 256 inode size
68ext4_test_nsec_timestamps()
69{
70	tst_resm TINFO "Test timestamps with 256 inode size"
71
72	mkfs.ext3 -I 256 $EXT4_DEV >/dev/null 2>&1
73	if [ $? -ne 0 ]; then
74		tst_resm TFAIL "failed to create ext3 filesystem"
75		return
76	fi
77
78	mount -t ext4 $EXT4_DEV mnt_point
79	if [ $? -ne 0 ]; then
80		tst_resm TFAIL "failed to mount ext4 filesystem"
81		return
82	fi
83
84	# Create file
85	touch mnt_point/tmp_file
86	sleep 1
87
88	# Change atime, ctime and mtime of the file
89	touch mnt_point/tmp_file
90
91	cur_time=`date '+%s %N'`
92	sec=`echo $cur_time | awk {'print $1'}`
93	nsec=`echo $cur_time | awk {'print $2'}`
94
95	sec_atime=`ext4_file_time mnt_point/tmp_file atime sec`
96	sec_mtime=`ext4_file_time mnt_point/tmp_file mtime sec`
97	sec_ctime=`ext4_file_time mnt_point/tmp_file ctime sec`
98	nsec_atime=`ext4_file_time mnt_point/tmp_file atime nsec`
99	nsec_mtime=`ext4_file_time mnt_point/tmp_file mtime nsec`
100	nsec_ctime=`ext4_file_time mnt_point/tmp_file ctime nsec`
101
102	# Test nanosecond
103	if [ $nsec_atime -eq 0 -a $nsec_mtime -eq 0 -a $nsec_ctime -eq 0 ]; then
104		tst_resm TFAIL "The timestamp is not nanosecond(nsec_atime: $nsec_atime, nsec_mtime: $nsec_mtime, nsec_ctime: $nsec_ctime)"
105		tst_umount mnt_point
106		return
107	fi
108
109	diff1=$(( $sec_atime - $sec ))
110	diff2=$(( $sec_mtime - $sec ))
111	diff3=$(( $sec_ctime - $sec ))
112
113	# Test difference between file time and current time
114	if [ $diff1 -gt 1 -o $diff2 -gt 1 -o $diff2 -gt 1 ]; then
115		tst_resm TFAIL "The timestamp is wrong, it must be earlier \
116			than the current time we got.(sec_atime: $sec_atime, \
117			sec_mtime: $sec_mtime, sec_ctime: $sec_ctime, \
118			cur_time[s]: $sec)"
119		tst_umount mnt_point
120		return
121	fi
122
123	tst_umount mnt_point
124
125	# Test mount to ext3 and then mount back to ext4
126	mount -t ext3 $EXT4_DEV mnt_point
127	if [ $? -ne 0 ]; then
128		tst_resm TFAIL "failed to mount to ext3"
129		return
130	fi
131	tst_umount mnt_point
132
133	mount -t ext4 $EXT4_DEV mnt_point
134	if [ $? -ne 0 ]; then
135		tst_resm TFAIL "failed to mount back to ext4"
136		return
137	fi
138
139	nsec_atime2=`ext4_file_time mnt_point/tmp_file atime nsec`
140	nsec_mtime2=`ext4_file_time mnt_point/tmp_file mtime nsec`
141	nsec_ctime2=`ext4_file_time mnt_point/tmp_file ctime nsec`
142
143	if [ $nsec_atime -ne $nsec_atime2 -o $nsec_ctime -ne $nsec_ctime2 -o \
144	     $nsec_mtime -ne $nsec_mtime2 ]; then
145		tst_resm TFAIL "File nanosecond timestamp has changed \
146			unexpected. Before[atime mtime ctime]: $nsec_atime \
147			$nsec_mtime $nsec_ctime, After[atime mtime ctime]: \
148			$nsec_atime2 $nsec_mtime2 $nsec_ctime2)"
149		tst_umount mnt_point
150		return
151	fi
152
153	tst_umount mnt_point
154	tst_resm TPASS "Ext4 nanosecond timestamps test with 256 inode size pass"
155}
156
157# main
158ext4_setup
159
160ext4_test_sec_timestamps
161ext4_test_nsec_timestamps
162
163tst_exit
164