def test_spo_proofs(self,delaytest=False): """Run analysis and check if the analysis results match the expected results. Skip the checking if delaytest is True. """ self.testresults.set_sevs() for creffile in self.get_cref_files(): creffilename = creffile.name cfilefilename = UF.get_cfile_filename(self.tgtxpath,creffilename) if not os.path.isfile(cfilefilename): raise XmlFileNotFoundError(cfilefilename) capp = CApplication(self.sempath,cfilename=creffilename,contractpath=self.contractpath) cappfile = capp.get_single_file() if creffile.has_domains(): for d in creffile.get_domains(): am = AnalysisManager(capp,onefile=True,verbose=self.verbose) am.generate_and_check_file(creffilename,d) cappfile.reinitialize_tables() spos = cappfile.get_spos() if delaytest: continue for cfun in creffile.get_functions(): fname = cfun.name funspos = [ spo for spo in spos if spo.cfun.name == fname ] refspos = cfun.get_spos() self.check_spo_proofs(creffilename,cfun,funspos,refspos)
def test_ppo_proofs(self,delaytest=False): """Run analysis and check if analysis results match expected results. Skip checking results if delaytest is true. """ if not os.path.isfile(self.config.canalyzer): raise AnalyzerMissingError(self.config.canalyzer) self.testresults.set_pevs() for creffile in self.get_cref_files(): cfilename = creffile.name cfilefilename = UF.get_cfile_filename(self.tgtxpath,cfilename) if not os.path.isfile(cfilefilename): raise XmlFileNotFoundError(cfilefilename) capp = CApplication(self.sempath,cfilename=cfilename,contractpath=self.contractpath) cfile = capp.get_single_file() # only generate invariants if required if creffile.has_domains(): for d in creffile.get_domains(): am = AnalysisManager(capp,onefile=True,verbose=self.verbose) am.generate_and_check_file(cfilename,d) cfile.reinitialize_tables() ppos = cfile.get_ppos() if delaytest: continue for cfun in creffile.get_functions(): fname = cfun.name funppos = [ ppo for ppo in ppos if ppo.cfun.name == fname ] refppos = cfun.get_ppos() self.check_ppo_proofs(cfilename,cfun,funppos,refppos)
def test_spos(self,delaytest=False): """Run analysis and check if all expected spos are created.""" try: for creffile in self.get_cref_files(): self.testresults.set_spos() cfilename = creffile.name cfilefilename = UF.get_cfile_filename(self.tgtxpath,cfilename) if not os.path.isfile(cfilefilename): raise XmlFileNotFoundError(xfilefilename) capp = CApplication(self.sempath,cfilename=cfilename,contractpath=self.contractpath) cappfile = capp.get_single_file() capp.update_spos() capp.collect_post_assumes() spos = cappfile.get_spos() if delaytest: continue for cfun in creffile.get_functions(): fname = cfun.name if self.saveref: if cfun.has_spos(): print('Spos not created for ' + fname + ' in ' + cfilename + ' (delete first)') else: self.create_reference_spos(cfilename,fname,spos[fname]) else: refspos = cfun.get_spos() funspos = [ spo for spo in spos if spo.cfun.name == fname ] if funspos is None and len(refspos) == 0: self.testresults.add_spo_count_success(cfilename,fname) elif len(refspos) == len(funspos): self.testresults.add_spo_count_success(cfilename,fname) self.check_spos(cfilename,fname,funspos,refspos) else: self.testresults.add_spo_count_error( cfilename,fname,len(funspos),len(refspos)) raise FunctionSPOError(cfilename + ':' + fname + ' (' + str(len(funspos)) + ')') except FunctionSPOError as detail: self.print_test_results() print('') print('*' * 80) print('Function SPO error: ' + str(detail)) print('*' * 80) exit() if self.saveref: self.testsetref.save() exit()
def test_ppos(self): """Create primary proof obligations and check if created as expected.""" if not os.path.isfile(self.config.canalyzer): raise AnalyzerMissingError(self.config.canalyzer) self.testresults.set_ppos() saved = False try: for creffile in self.get_cref_files(): creffilename = creffile.name creffilefilename = UF.get_cfile_filename(self.tgtxpath,creffilename) if not os.path.isfile(creffilefilename): raise XmlFileNotFoundError(creffilefilename) capp = CApplication(self.sempath,cfilename=creffilename,contractpath=self.contractpath) am = AnalysisManager(capp,onefile=True,verbose=self.verbose) am.create_file_primary_proofobligations(creffilename) cfile = capp.get_single_file() capp.collect_post_assumes() ppos = cfile.get_ppos() for creffun in creffile.get_functions(): fname = creffun.name cfun = cfile.get_function_by_name(fname) if self.saveref: if creffun.has_ppos(): print('Ppos not created for ' + fname + ' (delete first)') else: self.create_reference_ppos(creffilename,fname,cfun.get_ppos()) saved = True else: refppos = creffun.get_ppos() funppos = [ ppo for ppo in ppos if ppo.cfun.name == fname ] if len(refppos) == len(funppos): self.testresults.add_ppo_count_success(creffilename,fname) self.check_ppos(creffilename,fname,funppos,refppos) else: self.testresults.add_ppo_count_error( creffilename,fname,len(funppos),len(refppos)) raise FunctionPPOError(creffilename + ':' + fname) except FunctionPPOError as detail: self.print_test_results() print('Function PPO error: ' + str(detail)) exit() if self.saveref and saved: self.testsetref.save() exit()
def xcfile_exists(self,cfilename): """Checks existence of xml file for cfilename.""" xfilename = UF.get_cfile_filename(self.tgtxpath,cfilename) return os.path.isfile(xfilename)
print('Error in parsing ' + cfilename) print('*' * 80) exit(1) except OSError as e: print('Error in parsing file: ' + str(e)) exit(1) sempath = os.path.join(cpath, 'semantics') contractpath = os.path.join(cpath, 'ktacontracts') capp = CApplication(sempath, cfilename, contractpath=contractpath) cfile = capp.get_cfile() cfile.create_contract(contractpath) ktadvpath = capp.path xfilename = UF.get_cfile_filename(ktadvpath, cfilename) if not os.path.isfile(xfilename): print( UP.err_msg([ 'No semantics files found for ' + args.cfile, ' Expected to find the file ' + xfilename, ' Please parse the file first with chc_parse_file.py or ' + 'check the directory name' ])) exit(1) am = AnalysisManager(capp, onefile=True, wordsize=args.wordsize, thirdpartysummaries=wssummaries)
if (not os.path.isdir(sempath)) or args.deletesemantics: success = UF.unpack_tar_file(cpath,args.deletesemantics) if not success: print(UP.err_msg(['No file or directory found with semantics', ' Expected to find a directory ' + sempath, ' or a file semantics_linux.tar.gz in ' + cpath])) exit(1) if args.contractpath is None: contractpath = os.path.join(cpath,'ktacontracts') else: contractpath = args.contractpath capp = CApplication(sempath,args.cfile,contractpath=contractpath) ktadvpath = capp.path xfilename = UF.get_cfile_filename(ktadvpath,args.cfile) if not os.path.isfile(xfilename): print(UP.err_msg(['No semantics files found for ' + args.cfile, ' Expected to find the file ' + xfilename, ' Please parse the file first with chc_parse_file.py or ' + 'check the directory name' ])) exit(1) am = AnalysisManager(capp,onefile=True,wordsize=int(args.wordsize),verbose=args.verbose, unreachability=args.unreachability, thirdpartysummaries=args.thirdpartysummaries) cfilename = args.cfile if args.continueanalysis is None or (not args.continueanalysis):