-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmsh_tester.py
71 lines (66 loc) · 2.17 KB
/
msh_tester.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import json
import subprocess
import sys
def exec_process(test, md):
try:
cmds = test['commands']
cmds.insert(0, sys.argv[1])
bf = ""
for cmd in cmds:
bf += "echo -e '{0}'\n".format(cmd)
if test['sleeptime'] > 0:
bf += "sleep {0}\n".format(test['sleeptime'])
tst_file = open("tmp", "w")
tst_file.write(bf)
tst_file.close()
eproc = subprocess.Popen(("/bin/bash", "-C", "tmp"), stdout=subprocess.PIPE)
exc = sys.argv[1] if not md else "tcsh"
proc = subprocess.Popen((exc), stdout=subprocess.PIPE, stderr=subprocess.STDOUT, stdin=eproc.stdout)
proc.wait(10)
ot = proc.stdout.read()
return proc.returncode, ot
except TimeoutExpired:
return 139, None
except Exception as e:
return -1, None
def start_test(test):
mrcode, mot = exec_process(test, False)
trcode, tmot = exec_process(test, True)
expcode = test['override_excode']
# TODO better code, this is a crappy one
if expcode >= 0 and mrcode != expcode:
print("Test [{0}]: Test failed.")
return False
elif expcode < 0 and (mrcode == 139 or mrcode == 11):
print("Test [{0}]: Test crashed.".format(test['name']))
return False
if mrcode == -1:
print("Test [{0}]: Test failed. Unable to start.".format(test['name']))
return False
if mot != tmot:
print(mot)
print("--------")
print(tmot)
print("Test [{0}]: Test failed. Difference.".format(test['name']))
return False
print("Test [{0}]: Test passed.".format(test['name']))
return True
def main():
tests = None
if len(sys.argv) != 2:
print("Usage: python msh_tester.py <shell_executable>")
return 1
try:
fl = open("tests.json")
cnt = fl.read()
tests = json.loads(cnt)
except IOError as e:
print("Unable to open tests.json: no such file or permission denied.")
return 1
if tests is None:
print("Unable to load tests from tests.json.")
return 1
[start_test(q) for q in tests]
return 0
if __name__ == "__main__":
exit(main())