From: Karel Zak Date: Mon, 23 Mar 2015 10:40:59 +0000 (+0100) Subject: dmesg: use GMT in tests, add DMESG_TEST_BOOTIME X-Git-Tag: v2.27-rc1~324 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5a34fb8a07de1716ca866832fa284b53109dee79;p=thirdparty%2Futil-linux.git dmesg: use GMT in tests, add DMESG_TEST_BOOTIME We don't want to hardcode anything to the test, just use env.variable DMESG_TEST_BOOTIME. Signed-off-by: Karel Zak --- diff --git a/sys-utils/dmesg.c b/sys-utils/dmesg.c index a17cc70af2..54612f5b17 100644 --- a/sys-utils/dmesg.c +++ b/sys-utils/dmesg.c @@ -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) diff --git a/tests/ts/dmesg/colors b/tests/ts/dmesg/colors index 2dfc93737d..156cb1ece7 100755 --- a/tests/ts/dmesg/colors +++ b/tests/ts/dmesg/colors @@ -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 diff --git a/tests/ts/dmesg/console-levels b/tests/ts/dmesg/console-levels index 9abd5b285a..f6a64e3b30 100755 --- a/tests/ts/dmesg/console-levels +++ b/tests/ts/dmesg/console-levels @@ -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 diff --git a/tests/ts/dmesg/decode b/tests/ts/dmesg/decode index 4725208d53..ada2eacdfc 100755 --- a/tests/ts/dmesg/decode +++ b/tests/ts/dmesg/decode @@ -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 diff --git a/tests/ts/dmesg/delta b/tests/ts/dmesg/delta index 4b55bf636f..a0983ccc22 100755 --- a/tests/ts/dmesg/delta +++ b/tests/ts/dmesg/delta @@ -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 diff --git a/tests/ts/dmesg/facilities b/tests/ts/dmesg/facilities index bc44c25465..d004a4f2e5 100755 --- a/tests/ts/dmesg/facilities +++ b/tests/ts/dmesg/facilities @@ -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 diff --git a/tests/ts/dmesg/indentation b/tests/ts/dmesg/indentation index 11a9e56626..9952c651d1 100755 --- a/tests/ts/dmesg/indentation +++ b/tests/ts/dmesg/indentation @@ -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