if not os.path.isdir(cpath): print(UP.cpath_not_found_err_msg(cpath)) exit(1) if not os.path.isfile(os.path.join(cpath,args.cfile)): print(UP.cfile_not_found_err_msg(cpath,args.cfile)) exit(1) sempath = os.path.join(args.path, 'semantics') if not os.path.isdir(sempath): print(UP.semantics_not_found_err_msg(cpath)) exit(1) cfapp = CApplication(sempath,args.cfile) cfile = cfapp.get_cfile() if args.showcode: if args.open and args.violations: def pofilter(po):return not po.is_closed() or po.is_violated() elif args.open: def pofilter(po):return not po.is_closed() elif args.violations: def pofilter(po):return po.is_violated() else: def pofilter(po):return True print(RP.file_code_tostring(cfile,pofilter=pofilter,showinvs=True)) print(RP.file_proofobligation_stats_tostring(cfile))
def parse(): parser = argparse.ArgumentParser() parser.add_argument('--fractions', help='plot relative values', action='store_true') parser.add_argument('--spo', help='include spos', action='store_true') parser.add_argument('--cwe', help='only report on this cwe (e.g., CWE121)') args = parser.parse_args() return args if __name__ == '__main__': args = parse() dsmethods = RP.get_dsmethods([]) cwe = 'all' if args.cwe is not None: cwe = args.cwe colors = RP.histogramcolors ppodmtotals = {} # dm -> totals list (per variant) spodmtotals = {} # dm -> totals list (per variant) ppofractions = {} # dm -> fractions list (per variant) spofractions = {} # dm -> fractions list (per variant) for dm in dsmethods: ppodmtotals[dm] = [] for dm in dsmethods:
print(UP.semantics_not_found_err_msg(cpath)) exit(1) capp = CApplication(sempath, cfilename) pofilter = lambda (p): True if args.predicates: pofilter = lambda (p): p.get_predicate_tag() in args.predicates openppos = capp.get_open_ppos() violations = capp.get_violations() delegated = capp.get_delegated() if len(openppos) > 0: print('Open proof obligations:\n' + ('=' * 80)) print(RP.tag_file_function_pos_tostring(openppos, pofilter=pofilter)) else: print('No open proof obligations found') if len(delegated) > 0: if args.xdelegated: print("Number of delegated ppo's: " + (str(len(delegated)))) else: print('\n\nDelegated proof obligations:\n' + ('=' * 80)) print( RP.tag_file_function_pos_tostring(delegated, pofilter=pofilter)) else: print('No delegated proof obligations found') if len(violations) > 0:
def v(f): global opencount global violationcount if len(f.get_violations()) > 0: fns.append(f) violationcount += len(f.get_violations()) opencount += len(f.get_open_ppos()) capp.iter_functions(v) print('~' * 80) print('Violation report for zitser application ' + args.path) print(' - universal violations : ' + str(violationcount)) print(' - open proof obligations: ' + str(opencount)) print('~' * 80) print('\n') if violationcount > 0: print('Universal violations: ') for f in fns: print(RP.function_code_violation_tostring(f)) if opencount > 0: print('>>>>> Note <<<<<') print('>>> Any of the ' + str(opencount) + ' open proof obligations could indicate a violation.') print( '>>> A program is proven safe only if ALL proof obligations are proven safe.' ) print('>>>>> Note <<<<<')
def get_juliet_projects(cwe): result = [] for c in JTC.testcases: if not ((cwe == 'all') or (c == cwe)): continue for p in JTC.testcases[c]: result.append(os.path.join(c, p)) return result if __name__ == '__main__': args = parse() config = Config() testdir = config.testdir dsmethods = RP.get_dsmethods([]) cwe = 'all' if args.cwe is not None: cwe = args.cwe colors = RP.histogramcolors ppodmtotals = {} # dm -> totals list (per test) spodmtotals = {} # dm -> totals list (per test) plotlegend = [] for dm in dsmethods: ppodmtotals[dm] = [] for dm in dsmethods: spodmtotals[dm] = [] width = 0.67 N = 0
args = parse() cpath = UF.get_itc_testpath(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) capp = CApplication(sempath) dc = ['deadcode'] print(RP.project_proofobligation_stats_tostring(capp, extradsmethods=dc)) contract_condition_violations = capp.get_contract_condition_violations() if len(contract_condition_violations) > 0: print('=' * 80) print( str(len(contract_condition_violations)) + ' CONTRACT CONDITION FAILURES') print('=' * 80) for (fn, cc) in contract_condition_violations: print(fn + ':') for (name, desc) in cc: print(' ' + name + ':' + desc) print('=' * 80)
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) capp = CApplication(sempath) timestamp = os.stat(capp.path).st_ctime try: result = RP.project_proofobligation_stats_to_dict(capp) result['timestamp'] = timestamp result['project'] = cpath UF.save_project_summary_results(cpath,result) except IndexedTableError as e: print( '\n' + ('*' * 80) + '\nThe analysis results format has changed' + '\nYou may have to re-run the analysis first: ' + '\n' + e.msg + '\n' + ('*' * 80))
cpath = wsdata['path'] cfilename = wsdata['file'] 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) capp = CApplication(sempath, cfilename) cfile = capp.get_cfile() print(RP.file_proofobligation_stats_tostring(cfile)) contract_condition_violations = capp.get_contract_condition_violations() if len(contract_condition_violations) > 0: print('=' * 80) print( str(len(contract_condition_violations)) + ' CONTRACT CONDITION FAILURES') print('=' * 80) for (fn, cc) in contract_condition_violations: print(fn + ':') for (name, desc) in cc: print(' ' + name + ':' + desc) print('=' * 80)
capp.iter_functions(v) print('~' * 80) print('Violation report for application ' + args.path) print(' - ppo violations suspected: ' + str(stats['ppoviolations'])) print(' - spo violations suspected: ' + str(stats['spoviolations'])) print(' - open ppos: ' + str(stats['openppos'])) print(' - open spos: ' + str(stats['openspos'])) print('~' * 80) print('\n') if stats['ppoviolations'] + stats['spoviolations'] > 0: pofilter = lambda po: po.is_violated() print('Violations suspected: ') for f in fns: if args.showcode: print(RP.function_code_violation_tostring(f)) else: print(RP.function_pos_to_string(f, pofilter=pofilter)) opencount = stats['openppos'] + stats['openspos'] if opencount > 0: print(('*' * 35) + ' Important ' + ('*' * 34)) print('* Any of the ' + str(opencount) + ' open proof obligations could indicate a violation.') print( '* A program is proven safe only if ALL proof obligations are proven safe.' ) print('*' * 80)
capp.reinitialize_tables() capp.update_spos() for i in range(5): capp.update_spos() am.generate_and_check_app('llrvisp', processes=args.maxprocesses) capp.reinitialize_tables() def filefilter(filename): return (not (filename in ["io", "main_linux", "std_thread"])) with timing('summarize'): contractviolations = capp.get_contract_condition_violations() if len(contractviolations) > 0: print(' --> ' + str(len(contractviolations)) + ' contract violations in ' + args.path) timestamp = os.stat(capp.path).st_ctime try: result = RP.project_proofobligation_stats_to_dict( capp, filefilter=filefilter) result['timestamp'] = timestamp result['project'] = cpath UF.save_project_summary_results(cpath, result) except IndexedTableError as e: print('\n' + ('*' * 80) + '\nThe analysis results format has changed' + '\nYou may have to re-run the analysis first: ' + '\n' + e.msg + '\n' + ('*' * 80))
pos[filename] = {} lines = [] for filename in pairs: for fn in sorted(pairs[filename]): fnlen = len(fn) lines.append('\n\n' + ('*' * 10) + ' Function: ' + fn + ' ' + ('*' * (70 - fnlen))) cfile = capp.get_file(filename) cfun = cfile.get_function_by_name(fn) ppos = [x[1] for x in pairs[filename][fn]] ppoids = [x.id for x in ppos] ppofilter = lambda ppo: (ppo.id in ppoids) and ppo.is_ppo() lines.append( RP.function_code_tostring(cfun, pofilter=ppofilter, showpreamble=False)) spos = sum((JTS.get_associated_spos(x, capp) for x in ppos), []) callers = {} for spo in spos: cfun = spo.cfun if not cfun.name in callers: callers[cfun.name] = {} callers[cfun.name]['cfun'] = cfun callers[cfun.name]['spos'] = [] callers[cfun.name]['spos'].append(spo.id) if len(callers) > 0: lines.append('-' * 80) lines.append('Callers') lines.append('-' * 80) for fn in callers:
cpath = UF.get_project_path(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) with timing('summarize'): summaries = UF.read_project_summary_results(cpath) try: if summaries == None: capp = CApplication(sempath) timestamp = os.stat(capp.path).st_ctime result = RP.project_proofobligation_stats_to_dict(capp) result['timestamp'] = timestamp result['project'] = cpath UF.save_project_summary_results(cpath, result) UF.save_project_summary_results_as_xml(cpath, result) summaries = UF.read_project_summary_results(cpath) print(RP.project_proofobligation_stats_dict_to_string(summaries)) except IndexedTableError as e: print('\n' + ('*' * 80) + '\nThe analysis results format has changed' + '\nYou may have to re-run the analysis first: ' + '\n' + e.msg + '\n' + ('*' * 80))
if not os.path.isfile(os.path.join(cpath,args.cfile)): print(UP.cfile_not_found_err_msg(cpath,args.cfile)) exit(1) sempath = os.path.join(args.path, 'semantics') if not os.path.isdir(sempath): print(UP.semantics_not_found_err_msg(cpath)) exit(1) cfapp = CApplication(sempath,args.cfile) cfile = cfapp.get_cfile() if not cfile.has_function_by_name(args.cfunction): print(UP.cfunction_not_found_err_sg(cpath,args.cfile,args.cfunction)) exit(1) cfunction = cfile.get_function_by_name(args.cfunction) if args.open and args.violations: def pofilter(po):return not po.is_closed() or po.is_violated() elif args.open: def pofilter(po):return not po.is_closed() elif args.violations: def pofilter(po):return po.is_violated() else: def pofilter(po):return True print(RP.function_code_tostring(cfunction,pofilter=pofilter))
from advance.app.CApplication import CApplication testcases = ['id' + str(i) for i in range(1283, 1311)] if __name__ == '__main__': projectstats = {} # project -> (linecount, clinecount, cfuncount) ppoprojecttotals = {} # project -> dm -> dmtotal spoprojecttotals = {} ppotagtotals = {} # tag -> dm -> dmtotal spotagtotals = {} nosummary = [] analysistimes = {} dsmethods = RP.get_dsmethods([]) for p in testcases: path = UF.get_zitser_testpath(p) results = UF.read_project_summary_results(path) if results is None: nosummary.append(p) continue pd = results try: ppod = pd['tagresults']['ppos'] spod = pd['tagresults']['spos'] ppoprojecttotals[p] = {} spoprojecttotals[p] = {} except: print('Problem with ' + str(p))
action='store_true') args = parser.parse_args() return args if __name__ == '__main__': args = parse() cpath = UF.get_svcomp_testpath(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) cfapp = CApplication(sempath, args.cfile) cfile = cfapp.getcfile() if args.showcode: if args.open: print(RP.file_code_open_tostring(cfile)) else: print(RP.file_code_tostring(cfile)) print(RP.file_proofobligation_stats_tostring(cfile))
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) cfapp = CApplication(sempath, args.cfile) cfile = cfapp.get_cfile() if not cfile.has_function_by_name(args.cfunction): print(UP.cfunction_not_found_err_msg(cpath, args.cfile, args.cfunction)) exit(1) cfunction = cfile.get_function_by_name(args.cfunction) dc = ['deadcode'] if args.open: print(RP.function_code_open_tostring(cfunction)) else: print(RP.function_code_tostring(cfunction)) print( RP.function_proofobligation_stats_tostring(cfunction, extradsmethods=dc))
if not os.path.isdir(sempath): print(UP.semantics_not_found_err_msg(cpath)) exit(1) excludefiles = ['io.c', 'main_linux.c', 'std_thread.c'] capp = CApplication(sempath, excludefiles=excludefiles) filterout = ['io', 'main_linux', 'std_thread'] dc = ['deadcode'] def filefilter(f): return (not f in filterout) print( RP.project_proofobligation_stats_tostring(capp, extradsmethods=dc, filefilter=filefilter)) contract_condition_violations = capp.get_contract_condition_violations() if len(contract_condition_violations) > 0: print('=' * 80) print( str(len(contract_condition_violations)) + ' CONTRACT CONDITION FAILURES') print('=' * 80) for (fn, cc) in contract_condition_violations: print(fn + ':') for (name, desc) in cc: print(' ' + name + ':' + desc) print('=' * 80)
parser.add_argument( 'variant', help=('sequence number of variant, e.g., 01, or 09 or 61, etc.' + ' (type ? to see a list of available variants)')) parser.add_argument('--cwe', help='only report on the given cwe, e.g., CWE121') args = parser.parse_args() return args if __name__ == '__main__': args = parse() cwe = 'all' if args.cwe is not None: cwe = args.cwe if not args.variant in JTC.variants: print('*' * 80) print('Variant ' + args.variant + ' not found. Variants available are: ') for v in sorted(JTC.variants): print(v + ': ' + JTC.variants[v]) print('*' * 80) exit(1) (ppoprojecttotals, spoprojecttotals, nosummary) = JVR.get_ppo_project_variant_totals(args.variant, cwe) print('\n\nPrimary Proof Obligations') print('\n'.join(RP.totals_to_string(ppoprojecttotals)))
from advance.util.Config import Config if __name__ == '__main__': config = Config() projectstats = {} # project -> (linecount, clinecount, cfuncount) ppoprojecttotals = {} # project -> dm -> dmtotal spoprojecttotals = {} ppotagtotals = {} # tag -> dm -> dmtotal spotagtotals = {} nosummary = [] analysistimes = {} dsmethods = RP.get_dsmethods([]) for p in range(231, 331): p = str(p) path = os.path.join(UF.get_itc_path(), str(p)) results = UF.read_project_summary_results(path) if results is None: nosummary.append(p) continue pd = results try: ppod = pd['tagresults']['ppos'] spod = pd['tagresults']['spos'] ppoprojecttotals[p] = {} spoprojecttotals[p] = {} except:
lines.append('*' * 80) lines.append(('Function ' + args.cfunction + ' not found in file ' + cfile.name + '; function names available:')) lines.append('-' * 80) for n in cfile.functionnames: lines.append(' ' + n) lines.append('*' * 80) print('\n'.join(lines)) exit(0) cfunction = cfile.get_function_by_name(args.cfunction) try: if args.open: print(RP.function_code_open_tostring(cfunction)) elif args.predicate: print(RP.function_code_predicate_tostring(cfunction,args.predicate,showinvs=args.showinvs)) else: print(RP.function_code_tostring(cfunction,showinvs=args.showinvs)) print(RP.function_proofobligation_stats_tostring(cfunction)) except IndexedTableError as e: print( '\n' + ('*' * 80) + '\nThe analysis results format has changed' + '\nYou may have to re-run the analysis first: ' + '\n' + e.msg + '\n' + ('*' * 80))
if __name__ == '__main__': args = parse() cpath = UF.get_svcomp_testpath(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) cfapp = CApplication(sempath, args.cfile) cfile = cfapp.getcfile() if not cfile.hasfunctionbyname(args.cfunction): print(UP.cfunction_not_found_err_sg(cpath, args.cfile, args.cfunction)) exit(1) cfunction = cfile.getfunctionbyname(args.cfunction) if args.open: print(RP.function_code_open_tostring(cfunction)) else: print(RP.function_code_tostring(cfunction)) print(RP.function_proofobligation_stats_tostring(cfunction))
sumppos = {} sumspos = {} for cwe in sorted(JTC.testcases): for t in JTC.testcases[cwe]: t = os.path.join(cwe, t) cpath = UF.get_juliet_testpath(t) sempath = os.path.join(cpath, 'semantics') if not os.path.isdir(sempath): missing.append(t) continue capp = CApplication(sempath) ppos = capp.get_ppos() spos = capp.get_spos() allppos.extend(ppos) allspos.extend(spos) sumppos[t] = RP.get_method_count(ppos) sumspos[t] = RP.get_method_count(spos) print( RP.row_method_count_tostring(sumppos, perc=True, rhlen=rhlen, header1='juliet testcase')) print('\nSupporting proof obligations\n') print( RP.row_method_count_tostring(sumspos, perc=True, rhlen=rhlen, header1='juliet testcase')) print('\nProof obligation types')
if not os.path.isfile(os.path.join(cpath,args.cfile)): print(UP.cfile_not_found_err_msg(cpath,args.cfile)) exit(1) sempath = os.path.join(cpath,'semantics') if not os.path.isdir(sempath): print(UP.semantics_not_found_err_msg(cpath)) exit(1) cfapp = CApplication(sempath,args.cfile) cfile = cfapp.get_cfile() if not cfile.has_function_by_name(args.cfunction): print(UP.cfunction_not_found_err_sg(cpath,args.cfile,args.cfunction)) exit(1) cfunction = cfile.get_function_by_name(args.cfunction) if args.open: print(RP.function_code_open_tostring(cfunction)) elif args.violations: print(RP.function_code_violation_tostring(cfunction)) elif args.predicate: print(RP.function_code_predicate_tostring(cfunction,args.predicate)) else: print(RP.function_code_tostring(cfunction)) print(RP.function_proofobligation_stats_tostring(cfunction))
def parse(): usage = ( '\nCall with the name of one of the sard/zitser projects, e.g., id1284' ) description = ('Reports the analysis results for a zitser project') parser = argparse.ArgumentParser(usage=usage, description=description) parser.add_argument( 'path', help='name of one of the zitser projects (e.g., id1284)') args = parser.parse_args() return args if __name__ == '__main__': args = parse() cpath = UF.get_zitser_testpath(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) capp = CApplication(sempath) print(RP.project_proofobligation_stats_tostring(capp))
def parse(): parser = argparse.ArgumentParser() parser.add_argument('cfilename', help='name of kendra c file (e.g., id115.c)') parser.add_argument('--show_invariants', help='show invariants in addition to diagnostic', action='store_true') args = parser.parse_args() return args if __name__ == '__main__': args = parse() cfilename = args.cfilename cpath = UF.get_kendra_cpath(cfilename) if cpath is None: print('*' * 80) print('Unable to find the test set for file ' + cfilename) print('*' * 80) exit(1) sempath = os.path.join(cpath, 'semantics') cfapp = CApplication(sempath, cfilename) cfile = cfapp.get_cfile() print(RP.file_code_tostring(cfile, showinvs=args.show_invariants)) print(RP.file_proofobligation_stats_tostring(cfile))
args = parse() cpath = UF.get_juliet_testpath(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) try: cfapp = CApplication(sempath, args.cfile) cfile = cfapp.get_cfile() except CFileNotFoundException as e: print(str(e)) exit(1) dc = ['deadcode'] if args.showcode: if args.open: print( RP.file_code_open_tostring(cfile, showinvs=args.showinvariants)) else: print(RP.file_code_tostring(cfile, showinvs=args.showinvariants)) print(RP.file_proofobligation_stats_tostring(cfile, extradsmethods=dc))