def preCompile(): global G_ROOT_FOLDER G_ROOT_FOLDER = os.getcwd() # build yaffs oracle version for function return results. #myutils.exec_cmd('gcc -o yaffs2_oracle yaffs2/yaffs2.c testcaserunner.cpp -DNO_COVERAGE %s %s -lstdc++ -ldl'\ # %(YAFFS2_COMPILE_OPTIONS, OPTIMIZATION)) # gcov version for line and function coverage myutils.exec_cmd('gcc -o yaffs2_gcov yaffs2/yaffs2.c testcaserunner.cpp -DNO_COVERAGE %s %s -lstdc++ -ldl'\ %(YAFFS2_COMPILE_OPTIONS, '--coverage'))
def generateResultNew(tsfile, yaffs2exe): res = '' if os.path.exists('testresult.txt'): os.remove('testresult.txt') myutils.exec_cmd('timeout %ss %s -start %d -num %d -testcasefile %s'%(TIMEOUT_LIMIT, yaffs2exe, 0, 1, tsfile)) if( os.path.exists('testresult.txt')): res = myutils.readSingleLine('testresult.txt') os.remove('testresult.txt') if res == '': res = 'crash or infinite loop' return res
def generateResultNew(tsfile, yaffs2exe): os.chdir(G_TMP_FOLDER) res = "" if os.path.exists("testresult.txt"): os.remove("testresult.txt") myutils.exec_cmd("timeout %ss %s -start %d -num %d -testcasefile %s" % (TIMEOUT_LIMIT, yaffs2exe, 0, 1, tsfile)) if os.path.exists("testresult.txt"): res = myutils.readSingleLine("testresult.txt") os.remove("testresult.txt") if res == "": res = "crash or infinite loop" return res
def main(): global G_ROOT_FOLDER G_ROOT_FOLDER = os.getcwd() now = datetime.datetime.now() randseed = now.microsecond parser = OptionParser() parser.add_option("", "--testcasesdir", dest="testcasesdir", action="store", type="string") parser.add_option("", "--mutantid", dest="mutantid", action="store", type = "int") parser.add_option("", "--mukillfile", dest="mukillfile", action="store", type="string") (options, args) = parser.parse_args() # prepare mutant binary os.chdir('mutgen') myutils.exec_cmd('bash generateMutants.sh yaffs2.c yaffs2mutants %d'%(options.mutantid)) if os.path.exists('mutant1%06d_yaffs2.c'%(options.mutantid)): myutils.exec_cmd('cp mutant1%06d_yaffs2.c ../muyaffs2.c'%(options.mutantid)) else: assert(0) os.chdir(G_ROOT_FOLDER) myutils.exec_cmd('gcc -o yaffs2_oracle yaffs2/yaffs2.c testcaserunner.cpp -DNO_COVERAGE %s %s -lstdc++ -ldl'\ %(YAFFS2_COMPILE_OPTIONS, OPTIMIZATION)) myutils.exec_cmd('gcc -o yaffs2_mutant muyaffs2.c testcaserunner.cpp -DNO_COVERAGE %s %s -lstdc++ -ldl'\ %(YAFFS2_COMPILE_OPTIONS, OPTIMIZATION)) testcasefiles=glob.glob('%s/ts*.c'%(options.testcasesdir)) testcasefiles= testcasefiles +glob.glob('%s/ts*.c.cmin'%(options.testcasesdir)) # print testcasefiles testcasefiles.sort() myutils.exec_cmd('rm oracle_results.txt mutant_results.txt') files = [] for tsfile in testcasefiles: files.append(tsfile.split("/")[-1]) res = generateResultNew(tsfile, 'yaffs2_oracle') myutils.appendline2file('oracle_results.txt', res) res = generateResultNew(tsfile, 'yaffs2_mutant') myutils.appendline2file('mutant_results.txt', res) oracle_results=myutils.getFileLines('oracle_results.txt') mutant_results=myutils.getFileLines('mutant_results.txt') assert(len(oracle_results)==len(mutant_results)) cmpstr= 'M:' + str(options.mutantid) + ',' for i in range(0, len(oracle_results)): cmpstr += files[i]+':' if oracle_results[i] == mutant_results[i]: cmpstr += '0,' else: cmpstr += '1,' myutils.appendline2file(options.mukillfile, cmpstr)
def _test(self, deltas): # Build input input = "" for (index, character) in deltas: input = input + character # Write input to `input.c' out = open(newinput, 'w') out.write(input) out.close() print self.coerce(deltas) if deltas == []: return self.PASS # Invoke yaffs2 cmd='rm yaffs2.gcov yaffs2.gcda' myutils.exec_cmd(cmd)
def generateTestCases(startidx, endidx, eachsize, tslength, dir, configfile, randseed, strategy, format): # build test case generator myutils.exec_cmd('gcc -o testcasegenerator %s/testcasegenerator.cpp yaffs2/yaffs2.c -DENABLE_GMP -lgmp -I %s/include %s -lstdc++ -ldl'\ %(G_ROOT_FOLDER, TCLAP_LIB_PATH, YAFFS2_COMPILE_OPTIONS)) if not os.path.exists('testcasegenerator'): assert (0) global configs # only load configs file once if configfile != '' and configs == []: configs = myutils.getFileLines(configfile) for i in range(len(configs)): configs[i] = configs[i].replace('\n', '') if format == None: format = 'nonconcolic' os.chdir(G_TMP_FOLDER) myutils.ensuredir('%s/%06d' % (dir, tslength)) os.chdir(G_TMP_FOLDER) for i in range(startidx, endidx + 1): disabledapilist = '' if len(configs) > 0: disabledapilist = configs[i % (len(configs))] if strategy == None: myutils.exec_cmd('%s/testcasegenerator --randseed %d --startidx %d --endidx %d --eachsize %d --dir %s/%06d --tclength %d --format %s %s'\ %(G_ROOT_FOLDER,random.randint(0,20000000), i, i, eachsize, dir, tslength, tslength, format, disabledapilist)) else: myutils.exec_cmd('%s/testcasegenerator --randseed %d --startidx %d --endidx %d --eachsize %d --dir %s/%06d --tclength %d --strategy %s --format %s %s'\ %(G_ROOT_FOLDER,random.randint(0,sys.maxint), i, i, eachsize, dir, tslength, tslength, strategy, format, disabledapilist)) os.chdir(G_ROOT_FOLDER)
def generateTestCases(startidx, endidx, eachsize, tslength, dir, configfile, randseed, strategy, format): # build test case generator myutils.exec_cmd('gcc -o testcasegenerator %s/testcasegenerator.cpp yaffs2/yaffs2.c -DENABLE_GMP -lgmp -I %s/include %s -lstdc++ -ldl'\ %(G_ROOT_FOLDER, TCLAP_LIB_PATH, YAFFS2_COMPILE_OPTIONS)) if not os.path.exists('testcasegenerator'): assert(0) global configs # only load configs file once if configfile != '' and configs == []: configs = myutils.getFileLines(configfile) for i in range(len(configs)): configs[i] = configs[i].replace('\n', '') if format == None: format = 'nonconcolic' os.chdir(G_TMP_FOLDER) myutils.ensuredir('%s/%06d'%(dir, tslength)) os.chdir(G_TMP_FOLDER) for i in range(startidx, endidx+1): disabledapilist = '' if len(configs) > 0: disabledapilist = configs[i % (len(configs))] if strategy == None: myutils.exec_cmd('%s/testcasegenerator --randseed %d --startidx %d --endidx %d --eachsize %d --dir %s/%06d --tclength %d --format %s %s'\ %(G_ROOT_FOLDER,random.randint(0,20000000), i, i, eachsize, dir, tslength, tslength, format, disabledapilist)) else: myutils.exec_cmd('%s/testcasegenerator --randseed %d --startidx %d --endidx %d --eachsize %d --dir %s/%06d --tclength %d --strategy %s --format %s %s'\ %(G_ROOT_FOLDER,random.randint(0,sys.maxint), i, i, eachsize, dir, tslength, tslength, strategy, format, disabledapilist)) os.chdir(G_ROOT_FOLDER)
class MyDD(DD.DD): def __init__(self): DD.DD.__init__(self) def _test(self, deltas): # Build input input = "" for (index, character) in deltas: input = input + character # Write input to `input.c' out = open(newinput, 'w') out.write(input) out.close() print self.coerce(deltas) if deltas == []: return self.PASS # Invoke yaffs2 cmd='rm yaffs2.gcov yaffs2.gcda' myutils.exec_cmd(cmd) cmd='yaffs2_gcov -start 0 -num 1 -testcasefile %s'%(input) myutils.exec_cmd(cmd) if os.path.exists('yaffs2.gcda'): myutils.exec_cmd('gcov yaffs2.c') if os.path.exists('yaffs2.c.gov'): newcov=getLineCoverage('yaffs2.c.gcov') if newcov == origcov: return self.FAIL else: return self.PASS else: return self.UNRESOLVED else: self.UNRESOLVED
def _test(self, deltas): # Build input input = "" for (index, character) in deltas: input = input + character # Write input to `input.c' out = open(newinput, 'w') out.write(input) out.close() #print self.coerce(deltas) if deltas == []: return self.PASS # Invoke yaffs2 cmd = 'rm *.gcov *.gcda funccoverage' myutils.exec_cmd(cmd) cmd = 'yaffs2_gcov -start 0 -num 1 -testcasefile %s' % (newinput) myutils.exec_cmd(cmd) if os.path.exists('yaffs2.gcda'): myutils.exec_cmd('gcov -f yaffs2.c > funccoverage') if os.path.exists('yaffs2.c.gcov'): if covtype == '-l': newcov = getLineCoverage('yaffs2.c.gcov') else: newcov = getFunctionCoverage('funccoverage') if newcov == origcov: myutils.exec_cmd('cp {0} {1}'.format( newinput, testcaseinput + '.' + str(self.iteration).zfill(5) + '.cmin')) self.iteration += 1 return self.FAIL else: return self.PASS else: return self.UNRESOLVED else: self.UNRESOLVED
def _test(self, deltas): # Build input input = "" for (index, character) in deltas: input = input + character # Write input to `input.c' out = open(newinput, 'w') out.write(input) out.close() #print self.coerce(deltas) if deltas == []: return self.PASS # Invoke yaffs2 cmd='rm *.gcov *.gcda funccoverage' myutils.exec_cmd(cmd) cmd='yaffs2_gcov -start 0 -num 1 -testcasefile %s'%(newinput) myutils.exec_cmd(cmd) if os.path.exists('yaffs2.gcda'): myutils.exec_cmd('gcov -f yaffs2.c > funccoverage') if os.path.exists('yaffs2.c.gcov'): if covtype == '-l': newcov=getLineCoverage('yaffs2.c.gcov') else: newcov=getFunctionCoverage('funccoverage') if newcov == origcov: myutils.exec_cmd('cp {0} {1}'.format(newinput, testcaseinput + '.' + str(self.iteration).zfill(5) + '.cmin')) self.iteration += 1 return self.FAIL else: return self.PASS else: return self.UNRESOLVED else: self.UNRESOLVED
def generateCoverageInfo(startidx, endidx, tslength): myutils.exec_cmd('gcc -o yaffs2_gcov yaffs2/yaffs2.c testcaserunner.cpp -DNO_COVERAGE %s %s -lstdc++ -ldl'\ %(YAFFS2_COMPILE_OPTIONS, OPTIMIZATION)) # load mutants' lines information mutants = mkArray(1000) lines = myutils.getFileLines('yaffs2/mutants/m.txt') for idx in range(len(lines)): line = lines[idx] parts = line.split(':') lineno = parts[1].strip() #print(lineno) #print(idx) if len(lineno) > 0: mutants[idx] = int(lineno) #print mutants #return for tsidx in range(startidx, endidx + 1): myutils.exec_cmd('rm yaffs2.c.gcov') tsfile = '%s/testcases/%06d/ts%06d.c' % (G_WORKING_FOLDER, tslength, tsidx) myutils.exec_cmd('%s/yaffs2_gcov -start %d -num %d -testcasefile %s' % (G_ROOT_FOLDER, 0, 1, tsfile)) myutils.exec_cmd('gcov yaffs2.c') uncovered = mkArray(14761) getCoveredLines('yaffs2.c.gcov', uncovered) #print uncovered flags = mkArray(1000) for i in range(1000): if uncovered[mutants[i] - 1] == 1: flags[i] = 1 myutils.appendArray('filtertable', flags) os.chdir(G_ROOT_FOLDER)
def generateCoverageInfo(startidx, endidx, tslength): myutils.exec_cmd('gcc -o yaffs2_gcov yaffs2/yaffs2.c testcaserunner.cpp -DNO_COVERAGE %s %s -lstdc++ -ldl'\ %(YAFFS2_COMPILE_OPTIONS, OPTIMIZATION)) # load mutants' lines information mutants = mkArray(1000) lines = myutils.getFileLines('yaffs2/mutants/m.txt') for idx in range(len(lines)): line = lines[idx] parts = line.split(':') lineno = parts[1].strip() #print(lineno) #print(idx) if len(lineno) > 0: mutants[idx] = int(lineno) #print mutants #return for tsidx in range(startidx, endidx+1): myutils.exec_cmd('rm yaffs2.c.gcov') tsfile = '%s/testcases/%06d/ts%06d.c'%(G_WORKING_FOLDER, tslength, tsidx) myutils.exec_cmd('%s/yaffs2_gcov -start %d -num %d -testcasefile %s'%(G_ROOT_FOLDER, 0, 1, tsfile)) myutils.exec_cmd('gcov yaffs2.c') uncovered = mkArray(14761) getCoveredLines('yaffs2.c.gcov', uncovered) #print uncovered flags = mkArray(1000) for i in range(1000): if uncovered[ mutants[i]-1 ] == 1: flags[i] = 1 myutils.appendArray('filtertable', flags) os.chdir(G_ROOT_FOLDER)
def _test(self, deltas): # Build input input = "" for (index, character) in deltas: input = input + character # Write input to `input.c' out = open(newinput, "w") out.write(input) out.close() # print self.coerce(deltas) if deltas == []: return self.PASS # Invoke yaffs2 cmd = "rm *.gcov *.gcda funccoverage" myutils.exec_cmd(cmd) cmd = "yaffs2_gcov -start 0 -num 1 -testcasefile %s" % (newinput) myutils.exec_cmd(cmd) if os.path.exists("yaffs2.gcda"): myutils.exec_cmd("gcov -f yaffs2.c > funccoverage") if os.path.exists("yaffs2.c.gcov"): if covtype == "-l": newcov = getLineCoverage("yaffs2.c.gcov") else: newcov = getFunctionCoverage("funccoverage") if newcov == origcov: return self.FAIL else: return self.PASS else: return self.UNRESOLVED else: self.UNRESOLVED
def generateCoverageInfo(startidx, endidx, eachsize, tslength, dir, suitesize): os.chdir(G_TMP_FOLDER) if not os.path.exists("./blockcount"): myutils.exec_cmd("cp -f %s/blockcount ./" % (G_ROOT_FOLDER)) if not os.path.exists("./branchcount"): myutils.exec_cmd("cp -f %s/branchcount ./" % (G_ROOT_FOLDER)) if not os.path.exists("./cfginfofile"): myutils.exec_cmd("cp -f %s/cfginfofile ./" % (G_ROOT_FOLDER)) if not os.path.exists("./blockpredcount"): myutils.exec_cmd("cp -f %s/blockpredcount ./" % (G_ROOT_FOLDER)) if not os.path.exists("./stmtpredcount"): myutils.exec_cmd("cp -f %s/stmtpredcount ./" % (G_ROOT_FOLDER)) # instypes = ['block','branch', 'path', 'acyclicpath','pred', 'predStmt'] instypes = ["path", "acyclicpath"] myutils.ensuredir("%s/coverage/path" % (G_WORKING_FOLDER)) myutils.ensuredir("%s/coverage/acyclicpath" % (G_WORKING_FOLDER)) for instype in instypes: # starttime=time.time() for tsidx in range(startidx, endidx + 1): tsfile = "%s/testcases/%06d/ts%06d.c" % (G_WORKING_FOLDER, tslength, tsidx) # covdbname = '%s/coverage/%s.%06d.cov'%(G_WORKING_FOLDER, 'tpath', tsidx/suitesize) if instype == "path" or instype == "acyclicpath": covdbname = "%s/coverage/%s/path%06d.cov" % (G_WORKING_FOLDER, instype, tsidx) myutils.exec_cmd( "%s/yaffs2_%s -start %d -num %d -c -instype %s -testcasefile %s -covdbname %s" % (G_ROOT_FOLDER, instype, 0, 1, "path", tsfile, covdbname) ) if instype == "acyclicpath": myutils.exec_cmd("mv %s/acyclicpath.cov %s" % (G_TMP_FOLDER, covdbname)) else: covdbname = "%s/coverage/%s.cov" % (G_WORKING_FOLDER, instype) myutils.exec_cmd( "%s/yaffs2_%s -start %d -num %d -c -instype %s -testcasefile %s -covdbname %s" % (G_ROOT_FOLDER, instype, 0, 1, instype, tsfile, covdbname) ) # endtime=time.time() # print ('time is %f'%(endtime-starttime) ) os.chdir(G_ROOT_FOLDER)
input = input + character return input # -------------------------------------------------------- if __name__ == "__main__": # Load deltas from `bug.c' deltas = [] index = 1 for line in open(testcaseinput): # print ("Line = " + line) deltas.append((index, line)) index = index + 1 myutils.exec_cmd("python yaffs2tester.py --precompile") cmd = "rm *.gcov *.gcda funccoverage" myutils.exec_cmd(cmd) myutils.exec_cmd("yaffs2_gcov -start 0 -num 1 -testcasefile %s" % (testcaseinput)) myutils.exec_cmd("gcov -f yaffs2.c > funccoverage") if covtype == "-l": origcov = getLineCoverage("yaffs2.c.gcov") elif covtype == "-f": origcov = getFunctionCoverage("funccoverage") mydd = MyDD() print "Simplifying failure-inducing input..." c = mydd.ddmin(deltas) # Invoke DDMIN # print "The 1-minimal failure-inducing input is", mydd.coerce(c) print "Removing any element will make the failure go away."
for (index, character) in deltas: input = input + character return input #-------------------------------------------------------- if __name__ == '__main__': # Load deltas from `bug.c' deltas = [] index = 1 for line in open(testcaseinput): #print ("Line = " + line) deltas.append((index, line)) index = index + 1 myutils.exec_cmd('python yaffs2tester.py --precompile') cmd='rm *.gcov *.gcda funccoverage' myutils.exec_cmd(cmd) myutils.exec_cmd('yaffs2_gcov -start 0 -num 1 -testcasefile %s'%(testcaseinput)) myutils.exec_cmd('gcov -f yaffs2.c > funccoverage') if covtype == '-l': origcov=getLineCoverage('yaffs2.c.gcov') elif covtype == '-f': origcov=getFunctionCoverage('funccoverage') mydd = MyDD() print "Simplifying failure-inducing input..." c = mydd.ddmin(deltas) # Invoke DDMIN #print "The 1-minimal failure-inducing input is", mydd.coerce(c) print "Removing any element will make the failure go away."
def generateCoverageInfo(startidx, endidx, eachsize, tslength, dir, suitesize): os.chdir(G_TMP_FOLDER) if not os.path.exists('./blockcount'): myutils.exec_cmd('cp -f %s/blockcount ./' % (G_ROOT_FOLDER)) if not os.path.exists('./branchcount'): myutils.exec_cmd('cp -f %s/branchcount ./' % (G_ROOT_FOLDER)) if not os.path.exists('./cfginfofile'): myutils.exec_cmd('cp -f %s/cfginfofile ./' % (G_ROOT_FOLDER)) if not os.path.exists('./blockpredcount'): myutils.exec_cmd('cp -f %s/blockpredcount ./' % (G_ROOT_FOLDER)) if not os.path.exists('./stmtpredcount'): myutils.exec_cmd('cp -f %s/stmtpredcount ./' % (G_ROOT_FOLDER)) #instypes = ['block','branch', 'path', 'acyclicpath','pred', 'predStmt'] instypes = ['path', 'acyclicpath'] myutils.ensuredir('%s/coverage/path' % (G_WORKING_FOLDER)) myutils.ensuredir('%s/coverage/acyclicpath' % (G_WORKING_FOLDER)) for instype in instypes: #starttime=time.time() for tsidx in range(startidx, endidx + 1): tsfile = '%s/testcases/%06d/ts%06d.c' % (G_WORKING_FOLDER, tslength, tsidx) #covdbname = '%s/coverage/%s.%06d.cov'%(G_WORKING_FOLDER, 'tpath', tsidx/suitesize) if instype == 'path' or instype == 'acyclicpath': covdbname = '%s/coverage/%s/path%06d.cov' % (G_WORKING_FOLDER, instype, tsidx) myutils.exec_cmd('%s/yaffs2_%s -start %d -num %d -c -instype %s -testcasefile %s -covdbname %s'\ %(G_ROOT_FOLDER, instype, 0, 1, 'path', tsfile, covdbname)) if instype == 'acyclicpath': myutils.exec_cmd('mv %s/acyclicpath.cov %s' % (G_TMP_FOLDER, covdbname)) else: covdbname = '%s/coverage/%s.cov' % (G_WORKING_FOLDER, instype) myutils.exec_cmd('%s/yaffs2_%s -start %d -num %d -c -instype %s -testcasefile %s -covdbname %s'\ %(G_ROOT_FOLDER, instype, 0, 1, instype, tsfile, covdbname)) #endtime=time.time() #print ('time is %f'%(endtime-starttime) ) os.chdir(G_ROOT_FOLDER)
#!/usr/bin/python import os import shutil import subprocess import time import signal import re import getopt, sys import glob from optparse import OptionParser from time import localtime, strftime import string import datetime import myutils import itertools opt = '-DCONFIG_YAFFS_DIRECT -DCONFIG_YAFFS_YAFFS2 -DCONFIG_YAFFS_PROVIDE_DEFS -DCONFIG_YAFFSFS_PROVIDE_VALUES -DNO_Y_INLINE -DCONFIG_YAFFS_USE_PTHREADS' mutants = glob.glob('mutant*.c') mutants.sort() for mutant in mutants: myutils.exec_cmd('rm -rf a.o') myutils.exec_cmd('gcc %s -c %s -I ./inc -o a.o' % (opt, mutant)) if not os.path.exists('a.o'): myutils.exec_cmd('mv %s x_%s' % (mutant, mutant))
input = input + character return input #-------------------------------------------------------- if __name__ == '__main__': # Load deltas from `bug.c' deltas = [] index = 1 for line in open(testcaseinput): #print ("Line = " + line) deltas.append((index, line)) index = index + 1 myutils.exec_cmd('python yaffs2tester.py --precompile') cmd = 'rm *.gcov *.gcda funccoverage' myutils.exec_cmd(cmd) myutils.exec_cmd('yaffs2_gcov -start 0 -num 1 -testcasefile %s' % (testcaseinput)) myutils.exec_cmd('gcov -f yaffs2.c > funccoverage') if covtype == '-l': origcov = getLineCoverage('yaffs2.c.gcov') elif covtype == '-f': origcov = getFunctionCoverage('funccoverage') mydd = MyDD() print "Simplifying failure-inducing input..." c = mydd.ddmin(deltas) # Invoke DDMIN #print "The 1-minimal failure-inducing input is", mydd.coerce(c) print "Removing any element will make the failure go away."
#--------------------------------------------------------------------------------------------------------------------------------- G_WORKING_FOLDER="" G_TMP_FOLDER="" # grootfolder is the folder where this script stay G_ROOT_FOLDER="" #mutants=glob.glob('./yaffs2/mutants/500_b*/*_yaffs2.c') #mutants.sort() #for mutant in mutants: # lines = myutils.getFileLines(mutant) # for i in range(0, len(lines)): # if lines[i].find('struct yaffs_dev m18_1Dev;') >= 0: # lines[i] = 'struct yaffs_dev m18_1Dev;\r\n' # if lines[i].find('yaffs_add_device(&ram1Dev);') >= 0: # lines[i] = '\tyaffs_add_device(&ram1Dev);\r\n#endif\r\n' # if lines[i].find('yaffs_add_device(&m18_1Dev);') >= 0: # lines[i+1] = '\r\n' # # myutils.appendlines2filenonewline('%s.fixed'%(mutant),lines) #mutants=glob.glob('./yaffs2/mutants/500_b*/*_yaffs2.c') #mutants.sort() #for mutant in mutants: # myutils.exec_cmd('diff %s %s.fixed >> dr.txt'%(mutant, mutant)) mutants=glob.glob('./yaffs2/mutants/500_b*/*_yaffs2.c.fixed') mutants.sort() for mutant in mutants: myutils.exec_cmd('mv %s %s'%(mutant, mutant.replace('.fixed', '')))
def main(): global G_ROOT_FOLDER G_ROOT_FOLDER = os.getcwd() now = datetime.datetime.now() randseed = now.microsecond parser = OptionParser() parser.add_option("", "--testcasesdir", dest="testcasesdir", action="store", type="string") parser.add_option("", "--mutantid", dest="mutantid", action="store", type = "int") parser.add_option("", "--mukillfile", dest="mukillfile", action="store", type="string") (options, args) = parser.parse_args() # prepare mutant binary os.chdir('mutgen') myutils.exec_cmd('bash generateMutants.sh yaffs2.c yaffs2mutants %d'%(options.mutantid)) if os.path.exists('mutant1%06d_yaffs2.c'%(options.mutantid)): myutils.exec_cmd('cp mutant1%06d_yaffs2.c ../muyaffs2.c'%(options.mutantid)) else: assert(0) os.chdir(G_ROOT_FOLDER) myutils.exec_cmd('rm yaffs2_oracle yaffs2_mutant') myutils.exec_cmd('gcc -o yaffs2_oracle yaffs2/yaffs2.c testcaserunner.cpp -DNO_COVERAGE %s %s -lstdc++ -ldl'\ %(YAFFS2_COMPILE_OPTIONS, OPTIMIZATION)) myutils.exec_cmd('gcc -o yaffs2_mutant muyaffs2.c testcaserunner.cpp -DNO_COVERAGE %s %s -lstdc++ -ldl'\ %(YAFFS2_COMPILE_OPTIONS, OPTIMIZATION)) if not( os.path.exists('yaffs2_oracle') and os.path.exists('yaffs2_mutant')): return testcasefiles=glob.glob('%s/ts*.c'%(options.testcasesdir)) testcasefiles.sort() myutils.exec_cmd('rm oracle_results.txt mutant_results.txt') for tsfile in testcasefiles: res = generateResultNew(tsfile, 'yaffs2_oracle') myutils.appendline2file('oracle_results.txt', res) res = generateResultNew(tsfile, 'yaffs2_mutant') myutils.appendline2file('mutant_results.txt', res) oracle_results=myutils.getFileLines('oracle_results.txt') mutant_results=myutils.getFileLines('mutant_results.txt') assert(len(oracle_results)==len(mutant_results)) cmpstr='' for i in range(0, len(oracle_results)): if oracle_results[i] == mutant_results[i]: cmpstr += '0,' else: cmpstr += '1,' myutils.appendline2file(options.mukillfile, cmpstr)
input = input + character return input #-------------------------------------------------------- if __name__ == '__main__': # Load deltas from `bug.c' deltas = [] index = 1 for line in open(testcaseinput): print ("Line = " + line) deltas.append((index, line)) index = index + 1 cmd='rm yaffs2.gcov yaffs2.gcda' myutils.exec_cmd(cmd) myutils.exec_cmd(cmdline) myutils.exec_cmd('gcov yaffs2.c') origcov=getLineCoverage('yaffs2.c.gcov') mydd = MyDD() print "Simplifying failure-inducing input..." c = mydd.ddmin(deltas) # Invoke DDMIN print "The 1-minimal failure-inducing input is", mydd.coerce(c) print "Removing any element will make the failure go away." # Write input to `input.c' out = open('minimal.c', 'w') out.write(mydd.coerce(c)) out.close()