87817bccc1914a3f5fe2f083aba6a7ef5f625465
[xfstests-dev.git] / tests / generic / 258
1 #! /bin/bash
2 # FS QA Test No. 258
3 #
4 # Test timestamps prior to epoch
5 # On 64-bit, ext2/3/4 was sign-extending when read from disk
6 # See also commit 4d7bf11d649c72621ca31b8ea12b9c94af380e63
7 #
8 #-----------------------------------------------------------------------
9 # Copyright (c) 2011 Red Hat, Inc.  All Rights Reserved.
10 #
11 # This program is free software; you can redistribute it and/or
12 # modify it under the terms of the GNU General Public License as
13 # published by the Free Software Foundation.
14 #
15 # This program is distributed in the hope that it would be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 # GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write the Free Software Foundation,
22 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
23 #
24 #-----------------------------------------------------------------------
25 #
26
27 seq=`basename $0`
28 echo "QA output created by $seq"
29
30 here=`pwd`
31 tmp=/tmp/$$
32 status=1        # failure is the default!
33
34 _cleanup()
35 {
36     rm -f $tmp.*
37 }
38
39 trap "_cleanup ; exit \$status" 0 1 2 3 15
40
41 # get standard environment, filters and checks
42 . ./common.rc
43
44 # real QA test starts here
45 _supported_fs generic
46 _supported_os Linux
47
48 TESTFILE=$TEST_DIR/timestamp-test.txt
49
50 # Create a file with a timestamp prior to the epoch
51 echo "Creating file with timestamp of Jan 1, 1960"
52 touch -t 196001010101 $TESTFILE
53 # Should yield -315593940 (prior to epoch)
54 echo "Testing for negative seconds since epoch"
55 ts=`stat -c %X $TESTFILE`
56 if [ "$ts" -ge 0 ]; then
57         echo "Timestamp wrapped: $ts"
58         _fail "Timestamp wrapped"
59 fi
60
61 # unmount, remount, and check the timestamp
62 echo "Remounting to flush cache"
63 umount $TEST_DEV
64 mount $TEST_DEV $TEST_DIR
65
66 # Should yield -315593940 (prior to epoch)
67 echo "Testing for negative seconds since epoch"
68 ts=`stat -c %X $TESTFILE`
69 if [ "$ts" -ge 0 ]; then
70         echo "Timestamp wrapped: $ts"
71         _fail "Timestamp wrapped"
72 fi
73
74 status=0 ; exit