2019-02-16 17:57:11 +03:00
|
|
|
#!/usr/bin/python3
|
|
|
|
|
2019-11-29 01:45:34 +03:00
|
|
|
'''
|
|
|
|
NetSurf automated test runner
|
2019-02-16 17:57:11 +03:00
|
|
|
|
2019-11-29 01:45:34 +03:00
|
|
|
This script retrives a test plan from the NetSurf infrastructure and
|
|
|
|
executes it using the monkey frontend
|
|
|
|
'''
|
2019-02-16 17:57:11 +03:00
|
|
|
|
2019-11-29 01:45:34 +03:00
|
|
|
# If you have any poo, fling it now!
|
2019-02-16 17:57:11 +03:00
|
|
|
|
|
|
|
import sys
|
2019-06-05 22:57:55 +03:00
|
|
|
import getopt
|
2019-02-16 17:57:11 +03:00
|
|
|
import multiprocessing as mp
|
2019-11-29 01:45:34 +03:00
|
|
|
from urllib import request, parse
|
2019-02-16 17:57:11 +03:00
|
|
|
from io import StringIO
|
2019-11-29 01:45:34 +03:00
|
|
|
import yaml
|
2019-02-16 17:57:11 +03:00
|
|
|
import monkey_driver as driver
|
|
|
|
|
2019-11-29 01:45:34 +03:00
|
|
|
# Otherwise let's begin...
|
|
|
|
|
|
|
|
BASE_PATH = "https://test.netsurf-browser.org/cgi-bin/monkey-index.cgi"
|
|
|
|
MONKEY_PATH = "./nsmonkey"
|
|
|
|
|
2019-02-16 17:57:11 +03:00
|
|
|
mp.set_start_method('fork')
|
|
|
|
|
2019-11-29 01:45:34 +03:00
|
|
|
def child_run_test(verbose, parts):
|
2019-02-16 17:57:11 +03:00
|
|
|
outcapture = StringIO()
|
|
|
|
errcapture = StringIO()
|
|
|
|
oldout = sys.stdout
|
|
|
|
olderr = sys.stderr
|
|
|
|
sys.stdout = outcapture
|
|
|
|
sys.stderr = errcapture
|
|
|
|
try:
|
|
|
|
driver.run_preloaded_test(MONKEY_PATH, parts)
|
|
|
|
except:
|
|
|
|
sys.stdout = oldout
|
|
|
|
sys.stderr = olderr
|
|
|
|
print("FAIL:")
|
2019-06-06 00:48:11 +03:00
|
|
|
print("STDOUT:\n{}\n".format(outcapture.getvalue()))
|
|
|
|
print("STDERR:\n{}\n".format(errcapture.getvalue()))
|
2019-02-16 17:57:11 +03:00
|
|
|
print("RERAISE:")
|
|
|
|
raise
|
2019-06-04 23:50:43 +03:00
|
|
|
else:
|
|
|
|
sys.stdout = oldout
|
|
|
|
sys.stderr = olderr
|
2019-11-29 01:45:34 +03:00
|
|
|
if verbose:
|
2019-06-06 00:48:11 +03:00
|
|
|
print("STDOUT:\n{}\n".format(outcapture.getvalue()))
|
2019-02-16 17:57:11 +03:00
|
|
|
|
2019-11-29 01:45:34 +03:00
|
|
|
def run_test(verbose, parts):
|
|
|
|
p = mp.Process(target=child_run_test, args=(verbose, parts, ))
|
2019-02-16 17:57:11 +03:00
|
|
|
p.start()
|
|
|
|
p.join()
|
|
|
|
return p.exitcode
|
|
|
|
|
2019-06-05 22:57:55 +03:00
|
|
|
def print_usage():
|
|
|
|
print('Usage:')
|
2019-11-30 18:38:03 +03:00
|
|
|
print(' ' + sys.argv[0] + ' [-v] [-h] [-d <division>] [-g group]')
|
2019-06-05 22:57:55 +03:00
|
|
|
|
|
|
|
def parse_argv(argv):
|
2019-11-29 01:45:34 +03:00
|
|
|
verbose = False
|
2019-11-30 18:38:03 +03:00
|
|
|
division = None
|
|
|
|
group = None
|
2019-06-05 22:57:55 +03:00
|
|
|
try:
|
2019-11-30 18:38:03 +03:00
|
|
|
opts, args = getopt.getopt(argv, "hvd:g:", [])
|
2019-06-05 22:57:55 +03:00
|
|
|
except getopt.GetoptError:
|
|
|
|
print_usage()
|
|
|
|
sys.exit(2)
|
|
|
|
for opt, arg in opts:
|
|
|
|
if opt == '-h':
|
|
|
|
print_usage()
|
|
|
|
sys.exit()
|
|
|
|
elif opt in ("-v", "--verbose"):
|
2019-11-29 01:45:34 +03:00
|
|
|
verbose = True
|
|
|
|
elif opt == '-d':
|
|
|
|
division = arg
|
2019-11-30 18:38:03 +03:00
|
|
|
elif opt == '-g':
|
|
|
|
group = arg
|
2019-11-29 01:45:34 +03:00
|
|
|
|
2019-11-30 18:38:03 +03:00
|
|
|
return verbose, division, group
|
2019-11-29 01:45:34 +03:00
|
|
|
|
|
|
|
def main():
|
2019-11-30 18:38:03 +03:00
|
|
|
verbose, division, group = parse_argv(sys.argv[1:])
|
2019-11-29 01:45:34 +03:00
|
|
|
|
|
|
|
print("Fetching tests...")
|
2019-11-30 18:38:03 +03:00
|
|
|
data_dict = {}
|
|
|
|
if division is not None:
|
|
|
|
data_dict['division'] = division
|
|
|
|
if group is not None:
|
|
|
|
data_dict['group'] = group
|
|
|
|
|
|
|
|
data = parse.urlencode(data_dict).encode()
|
2019-11-29 01:45:34 +03:00
|
|
|
req = request.Request(BASE_PATH, data=data)
|
|
|
|
index = request.urlopen(req)
|
|
|
|
index = index.read()
|
|
|
|
|
|
|
|
print("Parsing tests...")
|
|
|
|
test_set = yaml.load_all(index)
|
|
|
|
|
|
|
|
print("Running tests...")
|
|
|
|
ret = 0
|
|
|
|
for test in test_set:
|
|
|
|
if test["kind"] == 'group':
|
|
|
|
print("Start group: {}".format(test["group"]))
|
|
|
|
print(" [ {} ]".format(test["description"]))
|
|
|
|
elif test["kind"] == 'test':
|
|
|
|
print(" => Run test: {}".format(test["filename"]))
|
|
|
|
ret = run_test(verbose, test["content"])
|
|
|
|
if ret != 0:
|
|
|
|
break
|
|
|
|
|
|
|
|
if ret != 0:
|
|
|
|
print("FAIL")
|
|
|
|
sys.exit(1)
|
|
|
|
else:
|
|
|
|
print("PASS")
|
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|