# then, even better:
# ! expect (\1 > 500)
-# TODO: If the output is sorted, we should report it to the users. Corresponding perl chunk
-# print "WARNING: Both the observed output and expected output were sorted as requested.\n";
-# print "WARNING: Output were only sorted using the $sort_prefix first chars.\n"
-# if ( $sort_prefix > 0 );
-# print "WARNING: Use <! output sort 19> to sort by simulated date and process ID only.\n";
-#
-# print "----8<--------------- Begin of unprocessed observed output (as it should appear in file):\n";
-# map {print "> $_\n"} @{$cmd{'unsorted got'}};
-# print "--------------->8---- End of the unprocessed observed output.\n";
-
-
"""
# read file line per line (and concat line that ends with "\")
class FileReader(Singleton):
- def __init__(self, filename):
+ def __init__(self, filename=None):
if filename is None:
self.filename = "(stdin)"
self.f = sys.stdin
self.linenumber = 0
- def linenumber(self):
- return self.linenumber
-
def __repr__(self):
return self.filename+":"+str(self.linenumber)
-
+
def readfullline(self):
try:
line = next(self.f)
self.timeout = 10 # default value: 10 sec
self.wrapper = None
self.keep = False
-
+
def add_thread(self, thread):
self.threads.append(thread)
-
+
def join_all_threads(self):
for t in self.threads:
t.acquire()
self.timeout = TeshState().timeout
self.args = None
self.linenumber = -1
-
+
self.background = False
self.cwd = None
-
+
self.ignore_output = False
self.expect_return = 0
-
+
self.output_display = False
-
+
self.sort = -1
-
+
self.ignore_regexps = TeshState().ignore_regexps_common
def add_input_pipe(self, l):
def set_cmd(self, args, linenumber):
self.args = args
self.linenumber = linenumber
-
+
def add_ignore(self, txt):
self.ignore_regexps.append(re.compile(txt))
-
+
def remove_ignored_lines(self, lines):
for ign in self.ignore_regexps:
lines = [l for l in lines if not ign.match(l)]
if self.cwd is not None:
os.chdir(self.cwd)
self.cwd = None
-
+
#retrocompatibility: support ${aaa:=.} variable format
def replace_perl_variables(m):
vname = m.group(1)
#replace bash environment variables ($THINGS) to their values
self.args = expandvars2(self.args)
-
+
if re.match("^mkfile ", self.args) is not None:
self._cmd_mkfile(self.args)
if lock is not None: lock.release()
return
-
+
if re.match("^cd ", self.args) is not None:
self._cmd_cd(self.args)
if lock is not None: lock.release()
return
-
+
if TeshState().wrapper is not None:
self.timeout *= 20
self.args = TeshState().wrapper + self.args
self.timeout *= 10
self.args += TeshState().args_suffix
-
+
print("["+FileReader().filename+":"+str(self.linenumber)+"] "+self.args)
-
+
args = shlex.split(self.args)
#print (args)
#remove text colors
ansi_escape = re.compile(r'\x1b[^m]*m')
stdout_data = ansi_escape.sub('', stdout_data)
-
+
#print ((stdout_data, stderr_data))
-
+
if self.ignore_output:
print("(ignoring the output of <"+cmdName+"> as requested)")
else:
elif self.sort > 0:
stdouta.sort(key=lambda x: x[:self.sort].lower())
self.output_pipe_stdout.sort(key=lambda x: x[:self.sort].lower())
-
+
diff = list(difflib.unified_diff(self.output_pipe_stdout, stdouta,lineterm="",fromfile='expected', tofile='obtained'))
if len(diff) > 0:
print("Output of <"+cmdName+"> mismatch:")
if self.sort >= 0: # If sorted, truncate the diff output and show the unsorted version
difflen = 0;
for line in diff:
- if difflen<250:
+ if difflen<50:
print(line)
difflen += 1
- if difflen > 100:
- print("(diff truncated after 250 lines)")
+ if difflen > 50:
+ print("(diff truncated after 50 lines)")
print("Unsorted observed output:\n")
for line in stdcpy:
print(line)
else: # If not sorted, just display the diff
for line in diff:
print(line)
-
+
print("Test suite `"+FileReader().filename+"': NOK (<"+cmdName+"> output mismatch)")
if lock is not None: lock.release()
if TeshState().keep:
f.close()
print("Obtained output kept as requested: "+os.path.abspath("obtained"))
exit(2)
-
+
#print ((proc.returncode, self.expect_return))
-
+
if proc.returncode != self.expect_return:
if proc.returncode >= 0:
print("Test suite `"+FileReader().filename+"': NOK (<"+cmdName+"> returned code "+str(proc.returncode)+")")
print("Test suite `"+FileReader().filename+"': NOK (<"+cmdName+"> got signal "+SIGNALS_TO_NAMES_DICT[-proc.returncode]+")")
if lock is not None: lock.release()
exit(-proc.returncode)
-
+
if lock is not None: lock.release()
-
-
-
+
+
+
def can_run(self):
return self.args is not None
if __name__ == '__main__':
-
+
parser = argparse.ArgumentParser(description='tesh -- testing shell', add_help=True)
group1 = parser.add_argument_group('Options')
group1.add_argument('teshfile', nargs='?', help='Name of teshfile, stdin if omitted')
if options.cd is not None:
os.chdir(options.cd)
-
+
if options.ignore_jenkins:
print("Ignore all cruft seen on SimGrid's continous integration servers")
TeshState().ignore_regexps_common = [
re.compile("Unable to clean temporary file C:.*"),
re.compile(".*Configuration change: Set \'contexts/"),
re.compile(".*Picked up JAVA_TOOL_OPTIONS.*"),
+ re.compile("Picked up _JAVA_OPTIONS: .*"),
re.compile("==WARNING: ASan is ignoring requested __asan_handle_no_return: stack top:"),
re.compile("False positive error reports may follow"),
re.compile("For details see http://code.google.com/p/address-sanitizer/issues/detail?id=189"),
-
+
re.compile("Python runtime initialized with LC_CTYPE=C .*"),
]
TeshState().jenkins = True # This is a Jenkins build
-
+
if options.teshfile is None:
f = FileReader(None)
print("Test suite from stdin")
exit(3)
f = FileReader(options.teshfile)
print("Test suite '"+f.abspath+"'")
-
+
if options.setenv is not None:
for e in options.setenv:
setenv(e)
-
+
if options.cfg is not None:
TeshState().args_suffix += " --cfg="+options.cfg
if options.log is not None:
if options.wrapper is not None:
TeshState().wrapper = options.wrapper
-
+
if options.keep:
TeshState().keep = True
-
+
#cmd holds the current command line
# tech commands will add some parameters to it
# when ready, we execute it.
cmd = Cmd()
-
+
line = f.readfullline()
while line is not None:
#print(">>============="+line+"==<<")
#print ("END CMD block")
if cmd.run_if_possible():
cmd = Cmd()
-
+
elif line[0] == "#":
pass
-
+
elif line[0:2] == "p ":
print("["+str(FileReader())+"] "+line[2:])
-
+
elif line[0:2] == "< ":
cmd.add_input_pipe(line[2:])
elif line[0:1] == "<":
cmd.add_input_pipe(line[1:])
-
+
elif line[0:2] == "> ":
cmd.add_output_pipe_stdout(line[2:])
elif line[0:1] == ">":
cmd.add_output_pipe_stdout(line[1:])
-
+
elif line[0:2] == "$ ":
if cmd.run_if_possible():
cmd = Cmd()
cmd.set_cmd(line[2:], f.linenumber)
-
+
elif line[0:2] == "& ":
if cmd.run_if_possible():
cmd = Cmd()
cmd.set_cmd(line[2:], f.linenumber)
cmd.background = True
-
+
elif line[0:15] == "! output ignore":
cmd.ignore_output = True
#print("cmd.ignore_output = True")
cmd.timeout = None
else:
cmd.timeout = int(line[len("! timeout "):])
-
+
elif line[0:len("! output sort")] == "! output sort":
if len(line) >= len("! output sort "):
sort = int(line[len("! output sort "):])
cmd.sort = sort
elif line[0:len("! setenv ")] == "! setenv ":
setenv(line[len("! setenv "):])
-
+
elif line[0:len("! ignore ")] == "! ignore ":
cmd.add_ignore(line[len("! ignore "):])
-
+
else:
fatal_error("UNRECOGNIZED OPTION")
-
-
+
+
line = f.readfullline()
cmd.run_if_possible()
-
+
TeshState().join_all_threads()
-
+
if f.filename == "(stdin)":
print("Test suite from stdin OK")
else: