From ba2152900cc0aa82e62905033e943fb3e4320945 Mon Sep 17 00:00:00 2001 From: Sandeep Hegde Date: Tue, 24 Oct 2017 22:16:48 -0400 Subject: [PATCH] Added Test Mapping framework and running through a path. --- components/script/dom/Test_mapping.json | 10 +++++++++ python/servo/mutation/init.py | 29 +++++++++++++++++++++++++ python/servo/mutation/test.py | 19 ++++++++-------- 3 files changed, 48 insertions(+), 10 deletions(-) create mode 100644 components/script/dom/Test_mapping.json create mode 100644 python/servo/mutation/init.py diff --git a/components/script/dom/Test_mapping.json b/components/script/dom/Test_mapping.json new file mode 100644 index 00000000000..6ea27ad36ae --- /dev/null +++ b/components/script/dom/Test_mapping.json @@ -0,0 +1,10 @@ +{ + "xmlhttprequest.rs": + [ + "XMLHttpRequest" + ], + "range.rs": + [ + "dom/ranges" + ] +} diff --git a/python/servo/mutation/init.py b/python/servo/mutation/init.py new file mode 100644 index 00000000000..e3d4aea9bcd --- /dev/null +++ b/python/servo/mutation/init.py @@ -0,0 +1,29 @@ +from os import listdir +from os.path import isfile, isdir, join +import json +import sys +import test + +def get_folders_list(path): + folder_list = [] + for filename in listdir(path): + if (isdir(join(path, filename))): + folder_name = join(path,filename) + folder_list.append(folder_name) + return(folder_list) + +def mutation_test_for(mutation_path): + test_mapping_file = join(mutation_path, 'Test_mapping.json') + if(isfile(test_mapping_file)): + json_data = open(test_mapping_file).read() + test_mapping = json.loads(json_data) + + for src_file in test_mapping.keys(): + test.mutation_test(join(mutation_path,src_file.encode('utf-8')), test_mapping[src_file]) + + for folder in get_folders_list(mutation_path): + mutation_test_for(folder) + else: + print ("This folder %s has no test mapping file." %(mutation_path)) + +mutation_test_for(sys.argv[1]) diff --git a/python/servo/mutation/test.py b/python/servo/mutation/test.py index 790789f3fdd..533e7cffe4b 100644 --- a/python/servo/mutation/test.py +++ b/python/servo/mutation/test.py @@ -10,7 +10,7 @@ def mutate_line(file_name, line_number): out.writelines(lines) out.close() -def mutation_test(file_name): +def mutation_test(file_name, tests): lineNumbers = [] for line in fileinput.input(file_name): if re.search(r'\s&&\s', line): @@ -21,17 +21,16 @@ def mutation_test(file_name): mutate_line(file_name, lineToMutate) print "compling mutant {0}-{1}".format(file_name, lineToMutate) sys.stdout.flush() - subprocess.call('python mach build --release', shell=True) + #subprocess.call('python mach build --release', shell=True) print "running tests for mutant {0}-{1}".format(file_name, lineToMutate) sys.stdout.flush() - testStatus = subprocess.call('python mach test-wpt XMLHttpRequest --release', shell=True) - if testStatus != 0: - print('Failed in while running `python mach test-wpt XMLHttpRequest --release`') - print "mutated file {0} diff".format(file_name) - sys.stdout.flush() - subprocess.call('git --no-pager diff {0}'.format(file_name), shell=True) + for test in tests: + testStatus = subprocess.call("python mach test-wpt {0} --release".format(test.encode('utf-8')), shell=True) + if testStatus != 0: + print('Failed in while running `python mach test-wpt {0} --release`'.format(test.encode('utf-8'))) + print "mutated file {0} diff".format(file_name) + sys.stdout.flush() + subprocess.call('git --no-pager diff {0}'.format(file_name), shell=True) print "reverting mutant {0}-{1}".format(file_name, lineToMutate) sys.stdout.flush() subprocess.call('git checkout {0}'.format(file_name), shell=True) - -mutation_test('components/script/dom/xmlhttprequest.rs')