summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sys-utils/dmesg.c26
-rwxr-xr-xtests/ts/dmesg/colors3
-rwxr-xr-xtests/ts/dmesg/console-levels3
-rwxr-xr-xtests/ts/dmesg/decode3
-rwxr-xr-xtests/ts/dmesg/delta3
-rwxr-xr-xtests/ts/dmesg/facilities3
-rwxr-xr-xtests/ts/dmesg/indentation3
7 files changed, 37 insertions, 7 deletions
diff --git a/sys-utils/dmesg.c b/sys-utils/dmesg.c
index a17cc70af..54612f5b1 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 2dfc93737..156cb1ece 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 9abd5b285..f6a64e3b3 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 4725208d5..ada2eacdf 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 4b55bf636..a0983ccc2 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 bc44c2546..d004a4f2e 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 11a9e5662..9952c651d 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