1717
1818
1919# TODO: check function in avocado.utils after the next LTS
20- def check_dmesg_output (pattern , expect = True , session = None ):
20+ def check_dmesg_output (pattern , expect = True , session = None , ignore_status = True ):
2121 """
2222 Check whether certain pattern exists in dmesg.
2323
@@ -30,20 +30,30 @@ def check_dmesg_output(pattern, expect=True, session=None):
3030 func_get_dmesg = session .cmd if session else process .run
3131 dmesg = func_get_dmesg (dmesg_cmd )
3232
33- prefix = "" if expect else "Not "
34- LOG .info ('%sExpecting pattern: "%s".' , prefix , pattern )
35-
36- # Search for pattern
37- found = bool (re .search (pattern , dmesg ))
38- log_content = ("" if found else "Not" ) + 'Found "%s"' % pattern
39- LOG .debug (log_content )
40-
41- if found ^ expect :
42- LOG .error ("Dmesg output does not meet expectation." )
43- return False
33+ patterns = None
34+ if isinstance (pattern , str ):
35+ patterns = [pattern ]
36+ elif isinstance (pattern , list ):
37+ patterns = pattern
4438 else :
45- LOG .info ("Dmesg output met expectation" )
46- return True
39+ raise Exception ("Invalid parameter type, expecting str or list" )
40+ prefix = "" if expect else "Not "
41+ LOG .info ('%sExpecting pattern: "%s".' , prefix , patterns )
42+ for pat in patterns :
43+ # Search for pattern
44+ found = bool (re .search (pat , dmesg ))
45+ log_content = ("" if found else "Not" ) + 'Found "%s"' % pat
46+ LOG .debug (log_content )
47+
48+ if found ^ expect :
49+ LOG .error ("Dmesg output does not meet expectation." )
50+ if ignore_status :
51+ return False
52+ else :
53+ raise Exception ("Dmesg output does not meet expectation for pattern %s." % pat )
54+ else :
55+ LOG .info ("Dmesg output met expectation" )
56+ return True
4757
4858
4959def check_audit_log (audit_cmd , match_pattern ):
0 commit comments