[Piglit] [PATCH] framework/dmesg.py: add a filtering mechanism

Thomas Wood thomas.wood at intel.com
Tue May 6 05:18:23 PDT 2014


Only update the test status if at least one of the lines in the dmesg
output matches the given regular expression.

v2: Style changes suggested by Ilia Mirkin and Dylan Baker
    Add a framework test for dmesg filtering

Signed-off-by: Thomas Wood <thomas.wood at intel.com>
---
 framework/dmesg.py             |  9 +++++++++
 framework/tests/dmesg_tests.py | 42 +++++++++++++++++++++++++++++++++++++++---
 2 files changed, 48 insertions(+), 3 deletions(-)

diff --git a/framework/dmesg.py b/framework/dmesg.py
index 3af8496..6590c1f 100644
--- a/framework/dmesg.py
+++ b/framework/dmesg.py
@@ -53,6 +53,7 @@ class LinuxDmesg(object):
         """ Create a dmesg instance """
         self._last_message = None
         self._new_messages = []
+        self.regex = None
 
         # Populate self.dmesg initially, otherwise the first test will always
         # be full of dmesg crud.
@@ -101,6 +102,14 @@ class LinuxDmesg(object):
         # if update_dmesg() found new entries replace the results of the test
         # and subtests
         if self._new_messages:
+
+            if self.regex:
+                for line in self._new_messages:
+                    if self.regex.search(line):
+                        break
+                else:
+                    return result
+
             result['result'] = replace(result['result'])
 
             # Replace any subtests
diff --git a/framework/tests/dmesg_tests.py b/framework/tests/dmesg_tests.py
index f713320..ce3d2af 100644
--- a/framework/tests/dmesg_tests.py
+++ b/framework/tests/dmesg_tests.py
@@ -23,6 +23,7 @@
 import os
 import sys
 import subprocess
+import re
 import nose.tools as nt
 from nose.plugins.skip import SkipTest
 from framework.dmesg import DummyDmesg, LinuxDmesg, get_dmesg, DmesgError
@@ -164,16 +165,19 @@ def test_dmesg_wrap_complete():
 
 def test_update_result_replace():
     """ Generates tests for update_result """
-    dmesg = _get_dmesg()
 
-    for res in ['pass', 'fail', 'crash', 'warn', 'skip', 'notrun']:
+    def create_test_result(res):
         result = TestResult()
         result['result'] = res
         result['subtest'] = {}
         result['subtest']['test'] = res
+        return result
 
+    dmesg = _get_dmesg()
+
+    for res in ['pass', 'fail', 'crash', 'warn', 'skip', 'notrun']:
         _write_dev_kmesg()
-        new_result = dmesg.update_result(result)
+        new_result = dmesg.update_result(create_test_result(res))
 
         # Create a yieldable and set the description for useful per-test names
         yieldable = check_update_result
@@ -183,6 +187,38 @@ def test_update_result_replace():
         yieldable.description = "Test update_result subtest: {0}".format(res)
         yield yieldable, new_result['subtest']['test'], res
 
+        # check that the status is not updated when Dmesg.regex is set and does
+        # not match the dmesg output
+        dmesg.regex = re.compile("(?!)")
+        _write_dev_kmesg()
+        new_result = dmesg.update_result(create_test_result(res))
+
+        yieldable = check_equal_result
+        yieldable.description = ("Test update_result with non-matching regex: "
+                                 "{0}".format(res))
+        yield yieldable, new_result['result'], res
+
+        # check that the status is updated when Dmesg.regex is set and matches
+        # the dmesg output
+        dmesg.regex = re.compile("piglit.*test")
+        _write_dev_kmesg()
+        new_result = dmesg.update_result(create_test_result(res))
+
+        yieldable = check_update_result
+        yieldable.description = ("Test update_result with matching regex: "
+                                "{0} ".format(res))
+        yield yieldable, new_result['result'], res
+
+def check_equal_result(result, status):
+    """ Tests that the result and status are equal
+
+    Dmesg.update_results() should not change the status if Dmesg.regex is set
+    and the dmesg output did not match it.
+
+    """
+
+    nt.assert_equal(result, status, msg="status should not have changed "
+                                        "from {} to {}".format(status, result))
 
 def check_update_result(result, status):
     """ Tests that update result replaces results correctly
-- 
1.9.0



More information about the Piglit mailing list