mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-11-22 22:41:30 +03:00
122 lines
2.9 KiB
Python
Executable File
122 lines
2.9 KiB
Python
Executable File
#!/usr/bin/python3
|
|
|
|
'''
|
|
NetSurf automated test runner
|
|
|
|
This script retrives a test plan from the NetSurf infrastructure and
|
|
executes it using the monkey frontend
|
|
'''
|
|
|
|
# If you have any poo, fling it now!
|
|
|
|
import sys
|
|
import getopt
|
|
import multiprocessing as mp
|
|
from urllib import request, parse
|
|
from io import StringIO
|
|
import yaml
|
|
import monkey_driver as driver
|
|
|
|
# Otherwise let's begin...
|
|
|
|
BASE_PATH = "https://test.netsurf-browser.org/cgi-bin/monkey-index.cgi"
|
|
MONKEY_PATH = "./nsmonkey"
|
|
|
|
mp.set_start_method('fork')
|
|
|
|
def child_run_test(verbose, parts):
|
|
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:")
|
|
print("STDOUT:\n{}\n".format(outcapture.getvalue()))
|
|
print("STDERR:\n{}\n".format(errcapture.getvalue()))
|
|
print("RERAISE:")
|
|
raise
|
|
else:
|
|
sys.stdout = oldout
|
|
sys.stderr = olderr
|
|
if verbose:
|
|
print("STDOUT:\n{}\n".format(outcapture.getvalue()))
|
|
|
|
def run_test(verbose, parts):
|
|
p = mp.Process(target=child_run_test, args=(verbose, parts, ))
|
|
p.start()
|
|
p.join()
|
|
return p.exitcode
|
|
|
|
def print_usage():
|
|
print('Usage:')
|
|
print(' ' + sys.argv[0] + ' [-v] [-h] [-d <division>] [-g group]')
|
|
|
|
def parse_argv(argv):
|
|
verbose = False
|
|
division = None
|
|
group = None
|
|
try:
|
|
opts, args = getopt.getopt(argv, "hvd:g:", [])
|
|
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"):
|
|
verbose = True
|
|
elif opt == '-d':
|
|
division = arg
|
|
elif opt == '-g':
|
|
group = arg
|
|
|
|
return verbose, division, group
|
|
|
|
def main():
|
|
verbose, division, group = parse_argv(sys.argv[1:])
|
|
|
|
print("Fetching tests...")
|
|
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()
|
|
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()
|