def __init__(self, cpath, tgtpath, filter=False, posix=False, verbose=True, keepUnused=False, tgtplatform='-m64'): """Initialize paths to code, results, and parser executable. Args: cpath: absolute path to toplevel C source directory tgtpath: absolute path to analysis directory Effects: creates tgtpath and subdirectories if necessary. """ self.cpath = cpath self.tgtpath = tgtpath self.filter = filter self.posix = posix self.keepUnused = keepUnused # keep variables that are not used self.sempath = os.path.join(self.tgtpath, 'semantics') self.tgtxpath = os.path.join(self.sempath, 'ktadvance') self.tgtspath = os.path.join(self.sempath, 'sourcefiles') # for .c and .i files self.config = Config() self.verbose = verbose self.tgtplatform = tgtplatform # compile to 32 bit or 64 bit platform (default 64 bit) if not (self.tgtplatform in ['-m64', '-m32']): printf('Warning: invalid target platform: ' + self.tgtplatform + '. Target platform is set to -m64') self.tgtplatform = '-m64'
def get_project_path(path): testdir = Config().testdir testdata = get_testdata_dict() if path in testdata: return os.path.join(testdir, str(testdata[path]['path'])) else: return os.path.abspath(path)
def __init__(self,capp,onefile=False,wordsize=0,unreachability=False, thirdpartysummaries=[],nofilter=True, verbose=True): """Initialize the analyzer location and target file location. Args: capp (CApplication): application entry point Keyword args: onefile (bool): analyzing one file at a time (default False) wordsize (int): architecture wordsize (0,16,32,64) (default 0 (unspecified)) unreachability (bool): use unreachability as justification to discharge (default False) thirdpartysummaries (string list): names of function summary jars verbose (bool): display analyzer output (default True) nofilter (bool): don't remove functions with absolute filename (default True) """ self.capp = capp self.contractpath = capp.contractpath self.config = Config() self.chsummaries = self.config.summaries self.path = self.capp.path self.canalyzer = self.config.canalyzer self.gui = self.config.chc_gui self.onefile = onefile self.nofilter = nofilter self.wordsize = wordsize self.thirdpartysummaries = thirdpartysummaries self.unreachability = unreachability self.verbose = verbose
def get_testdata_dict(): testdatapath = os.path.join(Config().testdir, 'testdata') testdatafile = os.path.join(testdatapath, 'testprojects.json') if os.path.isfile(testdatafile): with open(testdatafile, 'r') as fp: testdata = json.load(fp) return testdata return {}
def get_project_logfilename(path): testdir = Config().testdir testdata = get_testdata_dict() if path in testdata: logpath = os.path.join(testdir, str(testdata[path]['path'])) logfile = os.path.join(logpath, path + '.ktadvance_log') return logfile else: logfile = os.path.join(path, 'log.ktadvance_log') return logfile
def list_test_applications(): config = Config() lines = [] lines.append('*' * 80) lines.append('Test applications currently provided:') lines.append('-' * 80) maxlen = max(len(name) for name in config.projects) + 5 for name in sorted(config.projects): lines.append(name.ljust(maxlen) + config.projects[name]) lines.append('*' * 80) return '\n'.join(lines)
def __init__(self,cpath,tgtpath,testname,saveref=False,verbose=True): self.cpath = cpath self.tgtpath = tgtpath self.saveref = saveref self.config = Config() self.ismac = self.config.platform == 'mac' self.verbose = verbose self.contractpath = os.path.join(self.cpath,'ktacontracts') self.parsemanager = ParseManager(self.cpath,self.tgtpath,verbose=self.verbose) self.sempath = self.parsemanager.sempath self.tgtxpath = self.parsemanager.tgtxpath self.tgtspath = self.parsemanager.tgtspath testfilename = os.path.join(self.cpath,testname + '.json') self.testsetref = TestSetRef(testfilename) self.testresults = TestResults(self.testsetref)
' (e.g., CWE121/s01/CWE129_large)') parser.add_argument('--savesemantics', help='create gzipped tar file with semantics files', action='store_true') args = parser.parse_args() return args if __name__ == '__main__': args = parse() testpath = UF.get_juliet_testpath(args.path) cpath = os.path.abspath(testpath) print(cpath) if Config().platform == 'mac': print('*' * 80) print('Processing make files is not supported for mac') print('*' * 80) exit() if not os.path.isdir(cpath): print('*' * 80) print('Test directory ') print(' ' + cpath) print('not found.') print('*' * 80) exit() makefilename = os.path.join(cpath, 'Makefile') if not os.path.isfile(makefilename):
def missing_gui_err_msg(): config = Config() return err_msg([ 'Gui not found at ' + config.chc_gui, ' Please set gui location in Config.py' ])
def get_functional_tests_path(): return os.path.join(Config().testdir, 'functional')
def get_itc_path(): sardpath = os.path.join(Config().testdir, 'sard') return os.path.abspath(os.path.join(sardpath, 'itc'))
def get_juliet_path(): sardpath = os.path.join(Config().testdir, 'sard') return os.path.abspath(os.path.join(sardpath, 'juliet_v1.3'))
def get_zitser_path(): sardpath = os.path.join(Config().testdir, 'sard') return os.path.abspath(os.path.join(sardpath, 'zitser'))
def get_kendra_path(): sardpath = os.path.join(Config().testdir, 'sard') return os.path.abspath(os.path.join(sardpath, 'kendra'))
def parse(): parser = argparse.ArgumentParser() parser.add_argument('--cwe', help='only report on the given cwe') args = parser.parse_args() return args if __name__ == '__main__': args = parse() cwerequested = 'all' if args.cwe is not None: cwerequested = args.cwe config = Config() testdir = Config().testdir stotals = {} stotals[violations] = {} stotals[safecontrols] = {} for c in violationcategories: stotals[violations][c] = 0 for c in safecontrolcategories: stotals[safecontrols][c] = 0 vppototals = 0 sppototals = 0 vppohandled = 0 sppohandled = 0
def get_workshop_path(): return os.path.join(Config().testdir, 'workshop')
def my_cfiles_not_found_err_msg(testname): msg = ['Test ' + test + ' not found in my cfiles. Tests available: '] for t in Config().mycfiles: msg.append(t) return err_msg(msg)
def get_my_cfiles(testname): config = Config() if testname in config.mycfiles: testdata = config.mycfiles[testname] return (testdata['path'], testdata['file'])
def missing_analyzer_err_msg(): config = Config() return err_msg([ 'Analyzer not found at ' + config.canalyzer, ' Please set analyzer location in Config.py' ])
def get_svcomp_path(): return Config().svcompdir
parser.add_argument( '--open', help=('show only proof obligions on code that are still open' + ' or that indicate a violation'), action='store_true') parser.add_argument('--showinvs', help='show context invariants', action='store_true') args = parser.parse_args() return args if __name__ == '__main__': args = parse() config = Config() if args.path in config.projects: pdir = config.projects[args.path] cpath = os.path.join(config.testdir, pdir) else: cpath = os.path.abspath(args.path) if not os.path.isdir(cpath): print(UP.cpath_not_found_err_msg(cpath)) exit(1) sempath = os.path.join(cpath, 'semantics') if not os.path.isdir(sempath): print(UP.semantics_not_found_err_msg(cpath)) exit(1)
%safe (ppo) percent of safe ppos proven safe %violation (ppo) percent of violated ppos proven violation unknowns (ppo) number of ppos not discharged %safe (spo) percent of safe spos proven safe (N/A if there are no spos) %violation (spo) percent of violated spos proven violation (N/A if there are no spos) unknowns (spo) number of spos not discharged (N/A if there are no spos) ''' import argparse import json import os from advance.util.Config import Config kendra = os.path.join(os.path.join(Config().testdir, 'sard'), 'kendra') testcases = [(i, 'id' + str(i) + 'Q') for i in range(115, 394, 4)] def parse(): parser = argparse.ArgumentParser() parser.add_argument('--predicates', help='Show violated predicates with location', action='store_true') args = parser.parse_args() return args def getppocount(spec): total = 0 for f in spec["cfiles"]: