Removed build and wpt-test output from mutation test log and refactored code.

This commit is contained in:
Sandeep Hegde 2017-10-25 19:56:26 -04:00
parent 6688b8a146
commit 2b8b98d3a6
2 changed files with 22 additions and 19 deletions

View file

@ -17,21 +17,21 @@ import test
def get_folders_list(path):
folder_list = []
for filename in listdir(path):
if (isdir(join(path, filename))):
if isdir(join(path, filename)):
folder_name = join(path, filename)
folder_list.append(folder_name)
return(folder_list)
return folder_list
def mutation_test_for(mutation_path):
test_mapping_file = join(mutation_path, 'Test_mapping.json')
if(isfile(test_mapping_file)):
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)
# Run mutation test for all source files in mapping file.
for src_file in test_mapping.keys():
test.mutation_test(join(mutation_path, src_file.encode('utf-8')), test_mapping[src_file])
# Run mutation test in all folder in the path.
for folder in get_folders_list(mutation_path):
mutation_test_for(folder)
else:

View file

@ -11,36 +11,39 @@ import fileinput
import re
import subprocess
import sys
import os
DEVNULL = open(os.devnull, 'wb')
def mutate_line(file_name, line_number):
for line in fileinput.input(file_name, inplace=True):
if(fileinput.lineno() == line_number):
if fileinput.lineno() == line_number:
line = re.sub(r'\s&&\s', ' || ', line)
print line.rstrip()
def mutation_test(file_name, tests):
lineNumbers = []
line_numbers = []
for line in fileinput.input(file_name):
if re.search(r'\s&&\s', line):
lineNumbers.append(fileinput.lineno())
line_numbers.append(fileinput.lineno())
for lineToMutate in lineNumbers:
print "Mutating {0} at line {1}".format(file_name, lineToMutate)
mutate_line(file_name, lineToMutate)
print "compling mutant {0}-{1}".format(file_name, lineToMutate)
for line_to_mutate in line_numbers:
print "Mutating {0} at line {1}".format(file_name, line_to_mutate)
mutate_line(file_name, line_to_mutate)
print "compling mutant {0}:{1}".format(file_name, line_to_mutate)
sys.stdout.flush()
subprocess.call('python mach build --release', shell=True)
print "running tests for mutant {0}-{1}".format(file_name, lineToMutate)
subprocess.call('python mach build --release', shell=True, stdout=DEVNULL)
print "running tests for mutant {0}:{1}".format(file_name, line_to_mutate)
sys.stdout.flush()
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')))
test_command = "python mach test-wpt {0} --release".format(test.encode('utf-8'))
test_status = subprocess.call(test_command, shell=True, stdout=DEVNULL)
if test_status != 0:
print("Failed in while running `{0}`".format(test_command))
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)
print "reverting mutant {0}:{1}".format(file_name, line_to_mutate)
sys.stdout.flush()
subprocess.call('git checkout {0}'.format(file_name), shell=True)