• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
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		umount mnt_point
60		return
61	fi
62
63	umount mnt_point
64	if [ $? -ne 0 ]; then
65		tst_resm TFAIL "failed to umount ext4 filesystem"
66		return
67	fi
68
69	tst_resm TPASS "Ext4 nanosecond timestamps test with 128 inode size pass"
70}
71
72# Test file timestamps is nanosecond with 256 inode size
73ext4_test_nsec_timestamps()
74{
75	tst_resm TINFO "Test timestamps with 256 inode size"
76
77	mkfs.ext3 -I 256 $EXT4_DEV >/dev/null 2>&1
78	if [ $? -ne 0 ]; then
79		tst_resm TFAIL "failed to create ext4 filesystem"
80		return
81	fi
82
83	mount -t ext4 $EXT4_DEV mnt_point
84	if [ $? -ne 0 ]; then
85		tst_resm TFAIL "failed to mount ext4 filesystem"
86		return
87	fi
88
89	# Create file
90	touch mnt_point/tmp_file
91	sleep 1
92
93	# Change atime, ctime and mtime of the file
94	touch mnt_point/tmp_file
95
96	cur_time=`date '+%s %N'`
97	sec=`echo $cur_time | awk {'print $1'}`
98	nsec=`echo $cur_time | awk {'print $2'}`
99
100	sec_atime=`ext4_file_time mnt_point/tmp_file atime sec`
101	sec_mtime=`ext4_file_time mnt_point/tmp_file mtime sec`
102	sec_ctime=`ext4_file_time mnt_point/tmp_file ctime sec`
103	nsec_atime=`ext4_file_time mnt_point/tmp_file atime nsec`
104	nsec_mtime=`ext4_file_time mnt_point/tmp_file mtime nsec`
105	nsec_ctime=`ext4_file_time mnt_point/tmp_file ctime nsec`
106
107	# Test nanosecond
108	if [ $nsec_atime -eq 0 -a $nsec_mtime -eq 0 -a $nsec_ctime -eq 0 ]
109	then
110		tst_resm TFAIL "The timestamp is not nanosecond(nsec_atime: $nsec_atime, nsec_mtime: $nsec_mtime, nsec_ctime: $nsec_ctime)"
111		umount mnt_point
112		return
113	fi
114
115	diff1=$(( $sec_atime - $sec ))
116	diff2=$(( $sec_mtime - $sec ))
117	diff3=$(( $sec_ctime - $sec ))
118
119	# Test difference between file time and current time
120	if [ $diff1 -gt 1 -o $diff2 -gt 1 -o $diff2 -gt 1 ]; then
121		tst_resm TFAIL "The timestamp is wrong, it must be earlier \
122			than the current time we got.(sec_atime: $sec_atime, \
123			sec_mtime: $sec_mtime, sec_ctime: $sec_ctime, \
124			cur_time[s]: $sec)"
125		umount mnt_point
126		return
127	fi
128
129	umount mnt_point
130	if [ $? -ne 0 ]; then
131		tst_resm TFAIL "failed to umount ext4 filesystem"
132		return
133	fi
134
135	# Test mount to ext3 and then mount back to ext4
136	mount -t ext3 $EXT4_DEV mnt_point
137	if [ $? -ne 0 ]; then
138		tst_resm TFAIL "failed to mount to ext3"
139		return
140	fi
141	umount mnt_point
142
143	mount -t ext4 $EXT4_DEV mnt_point
144	if [ $? -ne 0 ]; then
145		tst_resm TFAIL "failed to mount back to ext4"
146		return
147	fi
148
149	nsec_atime2=`ext4_file_time mnt_point/tmp_file atime nsec`
150	nsec_mtime2=`ext4_file_time mnt_point/tmp_file mtime nsec`
151	nsec_ctime2=`ext4_file_time mnt_point/tmp_file mtime nsec`
152
153	if [ $nsec_atime -ne $nsec_atime2 -o $nsec_ctime -ne $nsec_ctime2 -o \
154	     $nsec_mtime -ne $nsec_mtime2 ]; then
155		tst_resm TFAIL "File nanosecond timestamp has changed \
156			unexpected. Before[atime mtime ctime]: $nsec_atime \
157			$nsec_mtime $nsec_ctime, After[atime mtime ctime]: \
158			$nsec_atime2 $nsec_mtime2 $nsec_ctime2)"
159		umount mnt_point
160		return
161	fi
162
163	umount mnt_point
164	tst_resm TPASS "Ext4 nanosecond timestamps test with 256 inode size pass"
165}
166
167# main
168ext4_setup
169
170ext4_test_sec_timestamps
171ext4_test_nsec_timestamps
172
173tst_exit
174