]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
dmesg: use GMT in tests, add DMESG_TEST_BOOTIME
authorKarel Zak <kzak@redhat.com>
Mon, 23 Mar 2015 10:40:59 +0000 (11:40 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 23 Mar 2015 10:40:59 +0000 (11:40 +0100)
We don't want to hardcode anything to the test, just use
env.variable DMESG_TEST_BOOTIME.

Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/dmesg.c
tests/ts/dmesg/colors
tests/ts/dmesg/console-levels
tests/ts/dmesg/decode
tests/ts/dmesg/delta
tests/ts/dmesg/facilities
tests/ts/dmesg/indentation

index a17cc70af206b027b12faa91fcd5be2f8f4d2d26..54612f5b1781c5dad6b3a61e92a983e06a914fab 100644 (file)
@@ -1193,6 +1193,24 @@ static int which_time_format(const char *optarg)
        errx(EXIT_FAILURE, _("unknown time format: %s"), optarg);
 }
 
+#ifdef TEST_DMESG
+static inline int dmesg_get_boot_time(struct timeval *tv)
+{
+       char *str = getenv("DMESG_TEST_BOOTIME");
+       uintmax_t sec, usec;
+
+       if (str && sscanf(str, "%ju.%ju", &sec, &usec) == 2) {
+               tv->tv_sec = sec;
+               tv->tv_usec = usec;
+               return tv->tv_sec >= 0 && tv->tv_usec >= 0 ? 0 : -EINVAL;
+       }
+
+       return get_boot_time(tv);
+}
+#else
+# define dmesg_get_boot_time   get_boot_time
+#endif
+
 int main(int argc, char *argv[])
 {
        char *buf = NULL;
@@ -1377,14 +1395,8 @@ int main(int argc, char *argv[])
        if (is_timefmt(&ctl, RELTIME) ||
            is_timefmt(&ctl, CTIME) ||
            is_timefmt(&ctl, ISO8601)) {
-
-#ifdef TEST_DMESG
-               ctl.boot_time.tv_sec = 1234567890;
-               ctl.boot_time.tv_usec = 123456;
-#else
-               if (get_boot_time(&ctl.boot_time) != 0)
+               if (dmesg_get_boot_time(&ctl.boot_time) != 0)
                        ctl.time_fmt = DMESG_TIMEFTM_NONE;
-#endif
        }
 
        if (delta)
index 2dfc93737debf375276a440c8ab5437b3a21a2d3..156cb1ece7ed612dfa263ae2298af5b937c8fc8a 100755 (executable)
@@ -20,6 +20,9 @@ ts_init "$*"
 
 ts_check_test_command "$TS_HELPER_DMESG"
 
+export TZ="GMT"
+export DMESG_TEST_BOOTIME="1234567890.123456"
+
 $TS_HELPER_DMESG --color=always -F $TS_SELF/input -x >> $TS_OUTPUT 2>/dev/null
 
 ts_finalize
index 9abd5b285a2bbf75e1396d869594fd1b2512435c..f6a64e3b3088c73eba002671e2d79663987cee78 100755 (executable)
@@ -20,6 +20,9 @@ ts_init "$*"
 
 ts_check_test_command "$TS_HELPER_DMESG"
 
+export TZ="GMT"
+export DMESG_TEST_BOOTIME="1234567890.123456"
+
 for I in {-1..8}; do
        $TS_HELPER_DMESG -F $TS_SELF/input -l $I >> $TS_OUTPUT 2>/dev/null
 done
index 4725208d53dcc661650e07e61dcdab8904a373b1..ada2eacdfc13834c4642ca053ab2da879a5c056e 100755 (executable)
@@ -20,6 +20,9 @@ ts_init "$*"
 
 ts_check_test_command "$TS_HELPER_DMESG"
 
+export TZ="GMT"
+export DMESG_TEST_BOOTIME="1234567890.123456"
+
 $TS_HELPER_DMESG -x -F $TS_SELF/input >> $TS_OUTPUT 2>/dev/null
 
 ts_finalize
index 4b55bf636f667dac253d224a2f097fa8c74b042c..a0983ccc22e3525ab6b2618b7fe9ad478f1016f8 100755 (executable)
@@ -20,6 +20,9 @@ ts_init "$*"
 
 ts_check_test_command "$TS_HELPER_DMESG"
 
+export TZ="GMT"
+export DMESG_TEST_BOOTIME="1234567890.123456"
+
 $TS_HELPER_DMESG -d -F $TS_SELF/input >> $TS_OUTPUT 2>/dev/null
 
 ts_finalize
index bc44c25465cb6d62283bd4827df80bd25caf9d15..d004a4f2e5d0b2536e6e9e9cf84dfc580ae723f3 100755 (executable)
@@ -20,6 +20,9 @@ ts_init "$*"
 
 ts_check_test_command "$TS_HELPER_DMESG"
 
+export TZ="GMT"
+export DMESG_TEST_BOOTIME="1234567890.123456"
+
 for I in {-1..12}; do
        $TS_HELPER_DMESG -F $TS_SELF/input -f $I >> $TS_OUTPUT 2>/dev/null
 done
index 11a9e566267ee12ae8ad0efdbd957870a05d480b..9952c651d10577be3c87995eb627af3d4fa96cae 100755 (executable)
@@ -20,6 +20,9 @@ ts_init "$*"
 
 ts_check_test_command "$TS_HELPER_DMESG"
 
+export TZ="GMT"
+export DMESG_TEST_BOOTIME="1234567890.123456"
+
 $TS_HELPER_DMESG -F $TS_SELF/newlines > $TS_OUTPUT 2>&1
 
 $TS_HELPER_DMESG -F $TS_SELF/newlines -x >> $TS_OUTPUT 2>&1