4 # Copyright (C) 2007 Karel Zak <kzak@redhat.com>
6 # This file is part of util-linux-ng.
8 # This file is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License or
11 # (at your option) any later version.
13 # This file is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
19 TS_TOPDIR="$(dirname $0)/../.."
20 TS_DESC="system to hw"
21 NTP_SERVER="0.fedora.pool.ntp.org"
23 . $TS_TOPDIR/functions.sh
27 [ -x "/usr/sbin/ntpdate" ] || ts_skip "cannot found ntpdate command"
32 (ntpdate $NTP_SERVER | sed "s/^.*offset \([0-9.]*\) sec/\1/g") &> /dev/null
33 [ "$?" == "1" ] && ts_skip "cannot sync with $NTP_SERVER"
35 # sync again and check difference
36 OFFSET=$( ntpdate $NTP_SERVER 2> /dev/null | sed "s/^.*offset [\-]*\([0-9.]*\) sec/\1/g" )
37 [ "$?" == "1" ] && ts_skip "cannot sync with $NTP_SERVER (2nd attempt)"
39 DIFF=$( echo "$OFFSET > 1" | bc )
40 [ "$DIFF" == "1" ] && ts_skip "diff between systime and NTP is greated than 1 second"
43 for i in `seq 0 10`; do
45 $TS_CMD_HWCLOCK --systohc
46 $TS_CMD_HWCLOCK --hctosys
49 # sync with NTP and check new difference
50 OFFSET=$( ntpdate $NTP_SERVER 2> /dev/null | sed "s/^.*offset [\-]*\([0-9.]*\) sec/\1/g" )
51 [ "$?" == "1" ] && ts_skip "cannot sync with $NTP_SERVER (3rd attempt)"
53 DIFF=$( echo "$OFFSET > 1" | bc )
54 [ "$DIFF" == "1" ] && ts_failed "offset is $OFFSET"
56 ts_ok "offset is $OFFSET"