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;
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)
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
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
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
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
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