Imported Upstream version 20091031
[ltp-debian.git] / testcases / kernel / fs / ext4-new-features / ext4-nsec-timestamps / ext4_nsec_timestamps_test.sh
blobad7729ecbe66a442c30a7bde0444bcbe30f59e05
1 #!/bin/bash
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ##
20 ## ##
21 ## Author: Li Zefan <lizf@cn.fujitsu.com> ##
22 ## Miao Xie <miaox@cn.fujitsu.com> ##
23 ## ##
24 ################################################################################
26 cd $LTPROOT/testcases/bin
28 . ./ext4_funcs.sh
30 export TCID="ext4-nsec-timestamps"
31 export TST_TOTAL=2
32 export TST_COUNT=1
34 # $1: the test config
35 read_config $1
37 TEST_DIR=$PWD
39 # Test that file timestamps is second with 128 inode size
40 ext4_test_sec_timestamps()
42 tst_resm TINFO "Test timestamps with 128 inode size"
44 mkfs.ext4 -I 128 $EXT4_DEV > /dev/null
45 if [ $? -ne 0 ]; then
46 tst_resm TFAIL "failed to create ext4 filesystem"
47 return 1
50 tune2fs -E test_fs -O extents $EXT4_DEV
52 mount -t ext4 $EXT4_DEV mnt_point
53 if [ $? -ne 0 ]; then
54 tst_resm TFAIL "failed to mount ext4 filesystem"
55 return 1
58 touch mnt_point/tmp_file
60 atime=`./ext4_file_time mnt_point/tmp_file atime nsec`
61 mtime=`./ext4_file_time mnt_point/tmp_file mtime nsec`
62 ctime=`./ext4_file_time mnt_point/tmp_file ctime nsec`
64 if [ $atime -ne 0 -o $mtime -ne 0 -o $ctime -ne 0 ]; then
65 tst_resm TFAIL "Timestamp is not second(atime: $atime, mtime: \
66 $mtime, ctime: $ctime)"
67 umount mnt_point
68 return 1
71 umount mnt_point
72 if [ $? -ne 0 ]; then
73 tst_resm TFAIL "failed to umount ext4 filesystem"
74 return 1
77 tst_resm TPASS "Ext4 nanosecond timestamps test with 128 inode size pass"
80 # Test file timestamps is nanosecond with 256 inode size
81 ext4_test_nsec_timestamps()
83 tst_resm TINFO "Test timestamps with 256 inode size"
85 mkfs.ext3 -I 256 $EXT4_DEV > /dev/null
86 if [ $? -ne 0 ]; then
87 tst_resm TFAIL "failed to create ext4 filesystem"
88 return 1
91 tune2fs -E test_fs $EXT4_DEV
93 mount -t ext4 $EXT4_DEV mnt_point
94 if [ $? -ne 0 ]; then
95 tst_resm TFAIL "failed to mount ext4 filesystem"
96 return 1
99 # Create file
100 touch mnt_point/tmp_file
101 sleep 1
103 # Change atime, ctime and mtime of the file
104 touch mnt_point/tmp_file
106 cur_time=`date '+%s %N'`
107 sec=`echo $cur_time | awk {'print $1'}`
108 nsec=`echo $cur_time | awk {'print $2'}`
110 sec_atime=`./ext4_file_time mnt_point/tmp_file atime sec`
111 sec_mtime=`./ext4_file_time mnt_point/tmp_file mtime sec`
112 sec_ctime=`./ext4_file_time mnt_point/tmp_file ctime sec`
113 nsec_atime=`./ext4_file_time mnt_point/tmp_file atime nsec`
114 nsec_mtime=`./ext4_file_time mnt_point/tmp_file mtime nsec`
115 nsec_ctime=`./ext4_file_time mnt_point/tmp_file ctime nsec`
117 # Test nanosecond
118 if [ $nsec_atime -eq 0 -a $nsec_mtime -eq 0 -a $nsec_ctime -eq 0 ]
119 then
120 tst_resm TFAIL "The timestamp is not nanosecond(nsec_atime: $nsec_atime, nsec_mtime: $nsec_mtime, nsec_ctime: $nsec_ctime)"
121 umount mnt_point
122 return 1
125 diff1=$(( $sec_atime - $sec ))
126 diff2=$(( $sec_mtime - $sec ))
127 diff3=$(( $sec_ctime - $sec ))
129 # Test difference between file time and current time
130 if [ $diff1 -gt 1 -o $diff2 -gt 1 -o $diff2 -gt 1 ]; then
131 tst_resm TFAIL "The timestamp is wrong, it must be earlier \
132 than the current time we got.(sec_atime: $sec_atime, \
133 sec_mtime: $sec_mtime, sec_ctime: $sec_ctime, \
134 cur_time[s]: $sec)"
135 umount mnt_point
136 return 1
139 umount mnt_point
140 if [ $? -ne 0 ]; then
141 tst_resm TFAIL "failed to umount ext4 filesystem"
142 return 1
145 # Test mount to ext3 and then mount back to ext4
146 mount -t ext3 $EXT4_DEV mnt_point
147 if [ $? -ne 0 ]; then
148 tst_resm TFAIL "failed to mount to ext3"
149 return 1
151 umount mnt_point
153 mount -t ext4 $EXT4_DEV mnt_point
154 if [ $? -ne 0 ]; then
155 tst_resm TFAIL "failed to mount back to ext4"
156 return 1
159 nsec_atime2=`./ext4_file_time mnt_point/tmp_file atime nsec`
160 nsec_mtime2=`./ext4_file_time mnt_point/tmp_file mtime nsec`
161 nsec_ctime2=`./ext4_file_time mnt_point/tmp_file mtime nsec`
163 if [ $nsec_atime -ne $nsec_atime2 -o $nsec_ctime -ne $nsec_ctime2 -o \
164 $nsec_mtime -ne $nsec_mtime2 ]; then
165 tst_resm TFAIL "File nanosecond timestamp has changed \
166 unexpected. Before[atime mtime ctime]: $nsec_atime \
167 $nsec_mtime $nsec_ctime, After[atime mtime ctime]: \
168 $nsec_atime2 $nsec_mtime2 $nsec_ctime2)"
169 umount mnt_point
170 return 1
173 umount mnt_point
174 tst_resm TPASS "Ext4 nanosecond timestamps test with 256 inode size pass"
177 # main
178 ext4_setup
180 RET=0
182 ext4_test_sec_timestamps
183 if [$? -ne 0 ]; then
184 RET=1
186 : $((TST_COUNT++))
188 ext4_test_nsec_timestamps
189 if [$? -ne 0 ]; then
190 RET=1
192 : $((TST_COUNT++))
194 ext4_cleanup
195 exit $RET