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):
        success = UF.unpack_tar_file(cpath)
        if not success:
            print(UP.semantics_tar_not_found_err_msg(cpath))
            exit(1)

    capp = CApplication(sempath)
    if args.contractpath is None:
        contractpath = os.path.join(cpath, 'ktacontracts')
    else:
        contractpath = args.contractpath

    ignorefns = {}

    if not args.ignorefile is None:
        if os.path.isfile(args.ignorefile):
            with open(args.ignorefile, 'r') as fp:
                headers = json.load(fp)
            for h in headers:
                for fn in headers[h]['functions']:
                    ignorefns[fn] = h

    capp.iter_files(lambda f: f.create_contract(
        contractpath, args.preservesmemory, ignorefns=ignorefns))
                    lines.append('    postcondition requests:')
                    for p in fn.api.get_postcondition_requests():
                        if p.has_open_pos():                    
                            lines.append('      ' + str(p))
                            stats['npost'] += 1
                            stats['ndepppo'] += len(p.get_open_ppos())
                            stats['ndepspo'] += len(p.get_open_spos())
                if fn.api.has_outstanding_global_requests():
                    lines.append('    global assumption requests:')
                    for p in fn.api.get_global_assumption_requests():
                        if p.has_open_pos():                    
                            lines.append('      ' + str(p))
                            stats['nglobal'] += 1
                            stats['ndepppo'] += len(p.get_open_ppos())
                            stats['ndepspo'] += len(p.get_open_spos())
        fi.iter_functions(f)

    capp.iter_files(report_requests)

    print('\n'.join(lines))
    
    print('\n' + ('-' * 80))
    print('Postcondition requests: ' + str(stats['npost']).rjust(4))
    print('Global requests       : ' + str(stats['nglobal']).rjust(4))
    print('Dependent ppos        : ' + str(stats['ndepppo']).rjust(4))
    print('Dependent spos        : ' + str(stats['ndepspo']).rjust(4))
    print('-' * 80)
    

    
Exemple #3
0
        def indexfn(cfun):
            if not cfun.name in functionindex:
                functionindex[cfun.name] = []
            cfunrecord = {}
            cfunrecord['f'] = cfile.name
            cfunrecord['s'] = cfun.svar.get_vstorage()
            functionindex[cfun.name].append(cfunrecord)

        cfile.iter_functions(indexfn)

    capp = CApplication(sempath)

    with timing('indexing functions'):

        if args.verbose:
            print('-' * 80)
            print('Indexing files ...')
        capp.iter_files(indexfile)

        if args.verbose:
            print('-' * 80)
            print('Index:')
            for fn in sorted(functionindex):
                print('  - ' + fn)
                for fnrec in functionindex[fn]:
                    pstatic = ' (static)' if fnrec['s'] == 's' else ''
                    print('      ~ ' + fnrec['f'] + pstatic)
            print('-' * 80)

        UF.save_functionindex(cpath, functionindex)
    parser = argparse.ArgumentParser()
    parser.add_argument('path', help='sequence number of testcase, e.g., 231')
    args = parser.parse_args()
    return args


if __name__ == '__main__':

    args = parse()
    testpath = UF.get_itc_testpath(args.path)
    cpath = os.path.abspath(testpath)

    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):
        success = UF.unpack_tar_file(cpath)
        if not success:
            print(UP.semantics_tar_not_found_err_msg(cpath))
            exit(1)

    contractpath = os.path.join(cpath, 'ktacontracts')
    capp = CApplication(sempath, contractpath=contractpath)

    def create(cfile):
        cfile.create_contract(contractpath)

    capp.iter_files(create)
Exemple #5
0
        print(UP.cpath_not_found_err_msg(cpath))
        exit()

    sempath = os.path.join(testpath, 'semantics')
    success = UF.unpack_tar_file(cpath, True)
    if not success:
        print(UP.semantics_tar_not_found_err_msg(cpath))
        exit(1)

    excludefiles = ['io.c', 'main_linux.c', 'std_thread.c']

    capp = CApplication(sempath, excludefiles=excludefiles)
    linker = CLinker(capp)
    linker.link_compinfos()
    linker.link_varinfos()
    capp.iter_files(save_xrefs)
    linker.save_global_compinfos()

    if args.contractpath is None:
        contractpath = os.path.join(cpath, 'ktacontracts')
    else:
        contractpath = args.contractpath

    # have to reinitialize capp to get linking info properly initialized

    capp = CApplication(sempath,
                        contractpath=contractpath,
                        excludefiles=excludefiles)

    # assume wordsize of 64
    # use unreachability as a means of proof obligation discharge
    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):
        success = UF.unpack_tar_file(cpath, args.deletesemantics)
        if not success:
            print(UP.semantics_tar_not_found_err_msg(cpath))
            exit(1)

    if args.contractpath is None:
        contractpath = os.path.join(cpath, 'ktacontracts')
    else:
        contractpath = args.contractpath

    capp = CApplication(sempath, contractpath=contractpath)

    lines = []

    def f(fi):
        if fi.has_file_contracts():
            if (not args.xpost) and fi.contracts.has_postconditions():
                lines.append(str(fi.contracts.report_postconditions()))
            if (not args.xpre) and fi.contracts.has_preconditions():
                lines.append(str(fi.contracts.report_preconditions()))

    capp.iter_files(f)

    print('\n'.join(lines))
            exit(1)

    if args.contractpath is None:
        contractpath = os.path.join(cpath, 'ktacontracts')
    else:
        contractpath = args.contractpath

    capp = CApplication(sempath, contractpath=contractpath)

    lines = []

    def showall(fi):
        if fi.has_file_contracts():
            try:
                if fi.contracts.has_assertions():
                    lines.append(str(fi.contracts))
            except Exception as e:
                print('Error in file: ' + fi.name + ': ' + str(e))

    def showpost(fi):
        if fi.has_file_contracts():
            if fi.contracts.has_postconditions():
                lines.append(str(fi.contracts.report_postconditions()))

    if args.post:
        capp.iter_files(showpost)
    else:
        capp.iter_files(showall)

    print('\n'.join(lines))
        exit(1)

    if args.contractpath is None:
        contractpath = os.path.join(cpath,'ktacontracts')
    else:
        contractpath = args.contractpath

    capp = CApplication(sempath,contractpath=contractpath)

    # check linkinfo
    globaldefs = os.path.join(sempath,os.path.join('ktadvance','globaldefinitions.xml'))
    if not os.path.isfile(globaldefs):
        linker = CLinker(capp)
        linker.link_compinfos()
        linker.link_varinfos()
        capp.iter_files(save_xrefs)

        linker.save_global_compinfos()

    # have to reinitialized capp to get linking info properly initialized
    capp = CApplication(sempath,contractpath=contractpath)

    filecounts = {}
    def f(cfile):
        decls = cfile.declarations
        filecounts[cfile.name] = (decls.get_max_line(),decls.get_code_line_count())
    capp.iter_files(f)    
    
    am = AnalysisManager(capp,verbose=args.verbose,wordsize=args.wordsize)

    with timing('analysis'):