def __init__( self, capp, 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: 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.nofilter = nofilter self.wordsize = wordsize self.thirdpartysummaries = thirdpartysummaries self.unreachability = unreachability self.verbose = verbose
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, 'chcartifacts') 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_testdata_dict() -> Dict[str, Any]: 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: str) -> str: 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 + ".chc_analysis_log") return logfile else: logfile = os.path.join(path, "log.chc_analysis_log") return logfile
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 == "macOS" self.verbose = verbose self.sempath = os.path.join(self.cpath, "semantics") self.contractpath = os.path.join(self.cpath, "chccontracts") testfilename = os.path.join(self.cpath, testname + ".json") self.testsetref = TestSetRef(testfilename) self.testresults = TestResults(self.testsetref)
parser.add_argument('--keepUnused',help='keep unused variables',action='store_true') parser.add_argument('--savesemantics',help='create gzipped tar file with semantics files', action='store_true') parser.add_argument('--filter',help='filter out files with absolute filenames', action='store_true') parser.add_argument('--removesemantics',help='remove semantics directory if present', action='store_true') parser.add_argument('--platformwordsize',help='wordsize of target platform (32 or 64)',type=int, default='64') args = parser.parse_args() return args if __name__ == '__main__': args = parse() config = Config() if config.platform == 'macOS': print('*' * 80) print('Processing makefiles is not supported on macOS') print('*' * 80) exit(1) try: UF.check_parser() except UF.CHError as e: print(str(e.wrap())) exit(1) try: cpath = UF.get_project_path(args.path)
def get_workshop_path() -> str: return os.path.join(Config().testdir, "workshop")
def get_cgc_path() -> str: return os.path.join(Config().testdir, "cgc")
def get_functional_tests_path() -> str: return os.path.join(Config().testdir, "functional")
def get_libc_summary_test_path() -> str: return Config().libcsummarytestdir
def get_itc_path() -> str: sardpath = os.path.join(Config().testdir, "sard") return os.path.abspath(os.path.join(sardpath, "itc"))
def get_kendra_path() -> str: return Config().kendradir
def get_zitser_path() -> str: return Config().zitserdir
spos: total number of supporting proof obligations generated; %safe proven: percent of safe spos proven safe; %violation proven: percent of violations proven to be violation; %delegated: percent of spos delegated; open: number of open spos; predicates: predicates that are violated. """ import argparse import json import os from chc.util.Config import Config kendra = os.path.join(Config().testdir, "kendra") testcases = [(i, "id" + str(i) + "Q") for i in range(115, 394, 4)] def parse(): parser = argparse.ArgumentParser(description=__doc__) args = parser.parse_args() return args def get_ppo_count(spec): """Returns the number of ppos in the spec file.""" total = 0 for f in spec["cfiles"]: for ff in spec["cfiles"][f]["functions"]: total += len(spec["cfiles"][f]["functions"][ff]["ppos"])
print("Removing semantics directory") shutil.rmtree("semantics") if args.savesemantics: if os.path.isfile("semantics_linux.tar.gz"): print("Removing semantics_linux.tar.gz") os.remove("semantics_linux.tar.gz") parsemanager = ParseManager(cpath, targetpath) parsemanager.initialize_paths() try: basename = os.path.basename(cfilename) ifilename = parsemanager.preprocess_file_with_gcc(basename) result = parsemanager.parse_ifile(ifilename) if result != 0: print("*" * 80) print("Error in parsing " + cfilename) if Config().platform == "macOS": print( " (Problem may be related to standard header files on macOS)" ) print("*" * 80) exit(1) except OSError as e: print("Error when parsing file: " + str(e)) exit(1) if args.savesemantics: parsemanager.save_semantics()
def get_itc_path() -> str: sardpath = os.path.join(Config().testdir,'sard') return os.path.abspath(os.path.join(sardpath,'itc'))
if os.path.isdir('semantics'): print('Removing semantics directory') shutil.rmtree('semantics') if args.savesemantics: if os.path.isfile('semantics_linux.tar.gz'): print('Removing semantics_linux.tar.gz') os.remove('semantics_linux.tar.gz') parsemanager = ParseManager(cpath,targetpath) parsemanager.initialize_paths() try: basename = os.path.basename(cfilename) ifilename = parsemanager.preprocess_file_with_gcc(basename) result = parsemanager.parse_ifile(ifilename) if result != 0: print('*' * 80) print('Error in parsing ' + cfilename) if Config().platform == 'macOS': print(' (Problem may be related to standard header files on macOS)') print('*' * 80) exit(1) except OSError as e: print('Error when parsing file: ' + str(e)) exit(1) if args.savesemantics: parsemanager.save_semantics()
def get_libc_summary_test_path() -> str: return Config().libcsummarytestdir def get_libc_summary_test_list() -> Dict[str, Any]:
def get_zitser_path() -> str: return Config().zitserdir def get_zitser_summaries() -> str:
def get_kendra_path() -> str: return Config().kendradir def get_kendra_testpath(testname: str) -> str: