lib: lutil matching without changing newlines

Prior behavior of luCommand was to convert newlines to spaces in DUT
output before pattern matching. New method operating in parallel uses
re.DOTALL to mimic same behavior and allow preserving original DUT output.
The original output is needed for some scripts that parse line-by-line.

There is also some test code to compare match results using the
old way and new way and log a message if they are different. After
some short time we can develop confidence that using this new method
will not break any existing tests.

Signed-off-by: G. Paul Ziemba <paulz@labn.net>
This commit is contained in:
G. Paul Ziemba 2018-04-11 23:03:43 -07:00 committed by Donald Sharp
parent d86321ae94
commit c63906e8cf

View File

@ -46,6 +46,8 @@ class lUtil:
l_filename = '' l_filename = ''
l_last = None l_last = None
l_line = 0 l_line = 0
l_dotall_experiment = False
l_last_nl = None
fout = '' fout = ''
fsum = '' fsum = ''
@ -196,6 +198,17 @@ Total %-4d %-4d %d\n\
js = None js = None
self.log('WARNING: JSON load failed -- confirm command output is in JSON format.') self.log('WARNING: JSON load failed -- confirm command output is in JSON format.')
self.log('COMMAND OUTPUT:%s:' % report) self.log('COMMAND OUTPUT:%s:' % report)
# Experiment: can we achieve the same match behavior via DOTALL
# without converting newlines to spaces?
out_nl = out
search_nl = re.search(regexp, out_nl, re.DOTALL);
self.l_last_nl = search_nl
# Set up for comparison
if search_nl != None:
group_nl = search_nl.group()
group_nl_converted = " ".join(group_nl.splitlines())
out = " ".join(out.splitlines()) out = " ".join(out.splitlines())
search = re.search(regexp, out) search = re.search(regexp, out)
self.l_last = search self.l_last = search
@ -212,6 +225,9 @@ Total %-4d %-4d %d\n\
success = True success = True
else: else:
success = False success = False
# Experiment: compare matched strings obtained each way
if self.l_dotall_experiment and (group_nl_converted != ret):
self.log('DOTALL experiment: strings differ dotall=[%s] orig=[%s]' % (group_nl_converted, ret))
if op == 'pass' or op == 'fail': if op == 'pass' or op == 'fail':
self.result(target, success, result) self.result(target, success, result)
if js != None: if js != None:
@ -255,6 +271,8 @@ def luStart(baseScriptDir='.', baseLogDir='.', net='',
if fsum != None: if fsum != None:
LUtil.fsum_name = baseLogDir + '/' + fsum LUtil.fsum_name = baseLogDir + '/' + fsum
LUtil.l_level = level LUtil.l_level = level
LUtil.l_dotall_experiment = False
LUtil.l_dotall_experiment = True
def luCommand(target, command, regexp='.', op='none', result='', time=10, returnJson=False): def luCommand(target, command, regexp='.', op='none', result='', time=10, returnJson=False):
if op != 'wait': if op != 'wait':
@ -262,10 +280,15 @@ def luCommand(target, command, regexp='.', op='none', result='', time=10, return
else: else:
return LUtil.wait(target, command, regexp, op, result, time, returnJson) return LUtil.wait(target, command, regexp, op, result, time, returnJson)
def luLast(): def luLast(usenl=False):
if LUtil.l_last != None: if usenl:
LUtil.log('luLast:%s:' % LUtil.l_last.group()) if LUtil.l_last_nl != None:
return LUtil.l_last LUtil.log('luLast:%s:' % LUtil.l_last_nl.group())
return LUtil.l_last_nl
else:
if LUtil.l_last != None:
LUtil.log('luLast:%s:' % LUtil.l_last.group())
return LUtil.l_last
def luInclude(filename, CallOnFail=None): def luInclude(filename, CallOnFail=None):
tstFile = LUtil.base_script_dir + '/' + filename tstFile = LUtil.base_script_dir + '/' + filename