Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
156 changes: 51 additions & 105 deletions universalmutator/analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,138 +11,84 @@
import random
import os
import py_compile
import argparse

def main():

isWindows = platform.system()
args = sys.argv

if ("--help" in args) or (len(sys.argv) < 3):
if len(sys.argv) < 3:
print("ERROR: analyze_mutants requires at least two arguments\n")
print("USAGE: analyze_mutants <sourcefile> <cmd> [--mutantDir <dir>] [--fromFile <mutantfile>]")
print(" <cmd> is command to execute to run tests; non-zero return indicates mutant killed")
print(" --mutantDir: directory with all mutants; defaults to current directory")
print(" --fromFile: file containing list of mutants to process; others ignored")
print(" --timeout <val>: change the timeout setting")
print(" --show: show mutants")
print(" --verbose: show mutants and output of analysis")
print(" --seed: random seed for shuffling of mutants")
print(" --noShuffle: do not randomize order of mutants")
print(" --resume: use existing killed.txt and notkilled.txt, resume mutation analysis")
print(" --prefix: add a prefix to killed.txt and notkilled.txt")
print(" --numMutants: run with specific number of mutants")
print(" --compileCommand: compile command to run in selecting mutants")
sys.exit(0)

verbose = "--verbose" in sys.argv
if verbose:
args.remove("--verbose")

showM = "--show" in sys.argv
if showM:
args.remove("--show")

resume = "--resume" in sys.argv
if resume:
args.remove("--resume")

noShuffle = "--noShuffle" in sys.argv
if noShuffle:
args.remove("--noShuffle")
parser = argparse.ArgumentParser()

prefix = None
try:
prefixpos = args.index("--prefix")
except ValueError:
prefixpos = -1
parser.add_argument("sourcefile", help="a file to mutate", metavar="<sourcefile>")

if prefixpos != -1:
prefix = args[prefixpos + 1]
args.remove("--prefix")
args.remove(prefix)
parser.add_argument("cmd", help="<cmd> is command to execute to run tests; non-zero return indicates mutant killed", metavar="<cmd>")

fromFile = None
try:
filepos = args.index("--fromFile")
except ValueError:
filepos = -1
parser.add_argument("--mutantDir", help ="directory with all mutants; defaults to current directory", nargs = 1, metavar="<dir>")

if filepos != -1:
fromFile = args[filepos + 1]
args.remove("--fromFile")
args.remove(fromFile)
parser.add_argument("--fromFile", help="file containing list of mutants to process; others ignored", nargs=1, metavar="<mutantfile>")

seed = None
try:
seedpos = args.index("--seed")
except ValueError:
seedpos = -1
parser.add_argument("--timeout",nargs=1, help = "change the timeout setting", metavar="val",type=int)

if seedpos != -1:
seed = args[seedpos + 1]
args.remove("--seed")
args.remove(seed)
seed = int(seed)
parser.add_argument("--show", action="store_true", help="show mutants")

timeout = 30
try:
topos = args.index("--timeout")
except ValueError:
topos = -1
parser.add_argument("--verbose", help="show mutants and output of analysis", action="store_true")

if topos != -1:
timeout = args[topos + 1]
args.remove("--timeout")
args.remove(timeout)
timeout = float(timeout)
parser.add_argument("--seed", help="random seed for shuffling of mutants", nargs=1, type=int, metavar="<integer seed>")

numMutants = -1
try:
nmpos = args.index("--numMutants")
except ValueError:
nmpos = -1
parser.add_argument("--noShuffle", help="do not randomize order of mutants", action="store_true")

if nmpos != -1:
numMutants = args[nmpos + 1]
args.remove("--numMutants")
args.remove(numMutants)
numMutants = int(numMutants)
parser.add_argument("--resume", help="use existing killed.txt and notkilled.txt, resume mutation analysis", action="store_true")

compileCommand = None
try:
ccmdpos = args.index("--compileCommand")
except ValueError:
ccmdpos = -1
parser.add_argument("--prefix", help="add a prefix to killed.txt and notkilled.txt", nargs=1, metavar="<prefix>")

parser.add_argument("--numMutants", help="run with specific number of mutants", nargs=1, metavar="<int>", type=int)

parser.add_argument("--compileCommand", help="compile command to run in selecting mutants", action="store_true")

args = parser.parse_args()

if ccmdpos != -1:
compileCommand = args[ccmdpos + 1]
args.remove("--compileCommand")
args.remove(compileCommand)
verbose = args.verbose

showM = args.show

resume = args.resume

noShuffle = args.noShuffle

prefix = args.prefix


fromFile = args.fromFile

seed = args.seed

timeout = args.timeout
if timeout == None:
timeout=30

numMutants = args.numMutants
if(numMutants == None):
numMutants = -1

compileCommand = args.compileCommand

onlyMutants = None

if fromFile is not None:
with open(fromFile, 'r') as file:
onlyMutants = file.read().split()

mdir = "."
try:
mdirpos = args.index("--mutantDir")
except ValueError:
mdirpos = -1

if mdirpos != -1:
mdir = args[mdirpos + 1]
args.remove("--mutantDir")
args.remove(mdir)
mdir= args.mutantDir
if mdir == None:
mdir = "."
if mdir[-1] != "/":
mdir += "/"

src = args[1]
tstCmd = [args[2]]
src = args.sourcefile
tstCmd = args.cmd
ignore = []
if len(args) > 3:
with open(sys.argv[3]) as file:
if args.fromfile != None:
with open(args.fromfile) as file:
for l in file:
ignore.append(l.split()[0])

Expand Down
49 changes: 24 additions & 25 deletions universalmutator/checkcov.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,37 @@

import sys
import glob

import argparse

def main():

args = sys.argv

if ("--help" in args) or (len(sys.argv) < 4):
if len(sys.argv) < 4:
print("ERROR: check_covered requires at least three arguments\n")
print("USAGE: check_covered <sourcefile> <coverfile> <outfile> [--tstl] [--mutantDir directory]")
print(" --mutantDir: directory to put generated mutants in; defaults to current directory")
print(" --tstl: process <coverfile> that is output from TSTL internal report")
sys.exit(0)

mdir = "."
try:
mdirpos = args.index("--mutantDir")
except ValueError:
mdirpos = -1

if mdirpos != -1:
mdir = args[mdirpos + 1]
args.remove("--mutantDir")
args.remove(mdir)
parser = argparse.ArgumentParser()

parser.add_argument("sourcefile",nargs = 1, metavar="<sourcefile>")

parser.add_argument("coverfile",nargs = 1, metavar="<coverfile>")

parser.add_argument("outfile",nargs = 1, metavar="<outfile>")

parser.add_argument("--tstl", action="store_true", help = "process <coverfile> that is output from TSTL internal report")

parser.add_argument("--mutantDir", nargs=1, metavar="directory", help = "directory to put generated mutants in; defaults to current directory")

args = parser.parse_args()

mdir= args.mutantDir
if mdir == None:
mdir = "."
if mdir[-1] != "/":
mdir += "/"

src = args[1]
coverFile = args[2]
outFile = args[3]
src = args.sourcefile
coverFile = args.coverfile
outFile = args.outfile

tstl = "--tstl" in sys.argv
tstl = args.tstl
if tstl == None:
tstl = False

srcBase = src.split("/")[-1]
srcEnd = src.split(".")[-1]
Expand Down
Loading