[Piglit] [PATCH] dmesg.py: Make timestamp check slightly smarter

Ben Widawsky ben at bwidawsk.net
Thu Aug 7 16:16:39 PDT 2014


If users wish to clear their dmesg before a piglit run, the current code
will emit a warning. It is possible to query the information about the
running kernel, and most distros do package that, so default to that.
The live kernel config is more future proof than regex parsing of the
timestamp (although I'd be shocked if either ever stopped working), and
it works for the empty dmesg case.
---
 framework/dmesg.py | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/framework/dmesg.py b/framework/dmesg.py
index 1a8faa2..54f7119 100644
--- a/framework/dmesg.py
+++ b/framework/dmesg.py
@@ -40,6 +40,7 @@ import sys
 import subprocess
 import warnings
 import abc
+import gzip
 
 __all__ = [
     'BaseDmesg',
@@ -163,8 +164,22 @@ class LinuxDmesg(BaseDmesg):
         # on Linux because each entry is guaranteed unique by timestamps.
         self._last_message = None
         super(LinuxDmesg, self).__init__()
-
-        if not self._last_message:
+        printk_has_timestamps = False
+
+        # First check to see if we can find the live kernel config.
+        try:
+            f = gzip.open("/proc/config.gz", 'r')
+            for line in f:
+                if line.startswith("CONFIG_PRINTK_TIME=y"):
+                    printk_has_timestamps = True
+                    break
+            f.close()
+        except Exception:
+            pass
+
+        if printk_has_timestamps:
+            return
+        elif not self._last_message:
             # We need to ensure that there is something in dmesg to check
             # timestamps.
             warnings.warn("Cannot check dmesg for timestamp support. If you "
-- 
2.0.4



More information about the Piglit mailing list