perf tests attr: Make compare_data global
Making compare_data global, so it could be used outside the Test class scope to compare command results. Signed-off-by: Jiri Olsa <jolsa@kernel.org> Cc: David Ahern <dsahern@gmail.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Thomas Richter <tmricht@linux.vnet.ibm.com> Link: http://lkml.kernel.org/r/20170703145030.12903-5-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
committed by
Arnaldo Carvalho de Melo
parent
10213e2ff2
commit
04c31bcf86
@@ -9,6 +9,20 @@ import logging
|
|||||||
import shutil
|
import shutil
|
||||||
import ConfigParser
|
import ConfigParser
|
||||||
|
|
||||||
|
def compare_data(a, b):
|
||||||
|
# Allow multiple values in assignment separated by '|'
|
||||||
|
a_list = a.split('|')
|
||||||
|
b_list = b.split('|')
|
||||||
|
|
||||||
|
for a_item in a_list:
|
||||||
|
for b_item in b_list:
|
||||||
|
if (a_item == b_item):
|
||||||
|
return True
|
||||||
|
elif (a_item == '*') or (b_item == '*'):
|
||||||
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
class Fail(Exception):
|
class Fail(Exception):
|
||||||
def __init__(self, test, msg):
|
def __init__(self, test, msg):
|
||||||
self.msg = msg
|
self.msg = msg
|
||||||
@@ -82,26 +96,12 @@ class Event(dict):
|
|||||||
self.add(base)
|
self.add(base)
|
||||||
self.add(data)
|
self.add(data)
|
||||||
|
|
||||||
def compare_data(self, a, b):
|
|
||||||
# Allow multiple values in assignment separated by '|'
|
|
||||||
a_list = a.split('|')
|
|
||||||
b_list = b.split('|')
|
|
||||||
|
|
||||||
for a_item in a_list:
|
|
||||||
for b_item in b_list:
|
|
||||||
if (a_item == b_item):
|
|
||||||
return True
|
|
||||||
elif (a_item == '*') or (b_item == '*'):
|
|
||||||
return True
|
|
||||||
|
|
||||||
return False
|
|
||||||
|
|
||||||
def equal(self, other):
|
def equal(self, other):
|
||||||
for t in Event.terms:
|
for t in Event.terms:
|
||||||
log.debug(" [%s] %s %s" % (t, self[t], other[t]));
|
log.debug(" [%s] %s %s" % (t, self[t], other[t]));
|
||||||
if not self.has_key(t) or not other.has_key(t):
|
if not self.has_key(t) or not other.has_key(t):
|
||||||
return False
|
return False
|
||||||
if not self.compare_data(self[t], other[t]):
|
if not compare_data(self[t], other[t]):
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -109,7 +109,7 @@ class Event(dict):
|
|||||||
for t in Event.terms:
|
for t in Event.terms:
|
||||||
if not self.has_key(t) or not other.has_key(t):
|
if not self.has_key(t) or not other.has_key(t):
|
||||||
continue
|
continue
|
||||||
if not self.compare_data(self[t], other[t]):
|
if not compare_data(self[t], other[t]):
|
||||||
log.warning("expected %s=%s, got %s" % (t, self[t], other[t]))
|
log.warning("expected %s=%s, got %s" % (t, self[t], other[t]))
|
||||||
|
|
||||||
# Test file description needs to have following sections:
|
# Test file description needs to have following sections:
|
||||||
@@ -218,9 +218,9 @@ class Test(object):
|
|||||||
self.perf, self.command, tempdir, self.args)
|
self.perf, self.command, tempdir, self.args)
|
||||||
ret = os.WEXITSTATUS(os.system(cmd))
|
ret = os.WEXITSTATUS(os.system(cmd))
|
||||||
|
|
||||||
log.info(" '%s' ret %d " % (cmd, ret))
|
log.info(" '%s' ret '%s', expected '%s'" % (cmd, str(ret), str(self.ret)))
|
||||||
|
|
||||||
if ret != int(self.ret):
|
if not compare_data(str(ret), str(self.ret)):
|
||||||
raise Unsup(self)
|
raise Unsup(self)
|
||||||
|
|
||||||
def compare(self, expect, result):
|
def compare(self, expect, result):
|
||||||
|
|||||||
Reference in New Issue
Block a user