def parse_sail_to_pvs(project_name, only_print): project_info = data[project_name] sail_src_path = helper.preprocess_path(project_info['sail_src_path']) sail_src_files = project_info['sail_src_files'] lem_src_files = project_info['lem_src_files'] lem_embedded_lib = project_info['lem_embedded_lib'] lem_object_name = project_info['lem_object_name'] target_dir = helper.preprocess_path(project_info['target_dir']) lem_flags = project_info['lem_flags'] lem_source_libs = data['lem_source_libs'] if not os.path.exists(target_dir): os.mkdir(target_dir) sail_to_lem_cmd = construct_sail_to_lem_cmd(sail_src_files, lem_flags, lem_embedded_lib, lem_object_name) lem_to_ocaml_cmd = construct_from_lem_cmd('ocaml', sail_src_path, target_dir, lem_src_files, lem_source_libs) lem_to_pvs_cmd = construct_from_lem_cmd('pvs', sail_src_path, target_dir, lem_src_files, lem_source_libs) cmd = 'cd ' + sail_src_path + '; ' cmd += sail_to_lem_cmd + '; ' cmd += 'cd ' + helper.dir_path + '; ' cmd += lem_to_ocaml_cmd + '; ' cmd += lem_to_pvs_cmd + '; ' cmd += 'cd ' + target_dir + '; ' cmd += 'rm -f *_aux.pvs; cd ..' print(cmd) if not only_print: helper.execute_command(cmd) rewriteFiles.rewrite_files(target_dir, '')
def clear(only_print): lem_lib_name = data['lem_library']['pvs_library_name'] sail_lib_names = data['sail_libs'] cmd = 'rm -f ./' + lem_lib_name + '/*.pvs; ' for lib_name in sail_lib_names: target_dir = data[lib_name]['target_dir'] cmd += 'rm -rf ' + target_dir + '; ' print(cmd) if not only_print: helper.execute_command(cmd)
def generate_diff_patch(name, only_print): patch_info = data['patch'] dest_dir = os.path.join(patch_info['dest_dir'], name) src_dir = os.path.join(patch_info['src_dir'], name) patch_path = patch_info['patch_path'] cmd = 'diff -Naur ' cmd += dest_dir + ' ' cmd += src_dir cmd += ' > ' + os.path.join(patch_path, name + '.patch') print(cmd) if not only_print: helper.execute_command(cmd)
def remove_peer(ip_port): ''' Description : Removes a peer and returns any output on stdout and stderr Input : ip_port ip_port -- a string containing the ip address and port: 'ip port' Output : (stdout,error,comments) stdout -- a string for what is returned on stdout error -- a string for what is returned on stderr comments = {[], ['error comment 1', ...]} [] -- this means no errors occurred ['.', ''] -- A list of error messages ''' comments = [] (rc, stdout, error, timeout) = execute_command('./removepeer {}'.format(ip_port)) if rc != 0: comments.append('[removepeer] Return Code is: {}'.format(rc)) if error != 'Error: no such peer' and error != '': comments.append('[removepeer] Unknown Error String: {}'.format(error)) if stdout != '': comments.append( '[removepeer] There should be no output on stdout from removepeer: {}' .format(stdout)) if timeout != False: comments.append('[removepeer] Timed Out!') stdout = '' error = '' return (stdout, error, comments)
def remove_content(ip_port, key): ''' Description : Removes the content stored for a specific key. Should have no output on stdout, might have errors on stderr. Input : ip_port, key ip_port -- a string containing the ip address and port: 'ip port' key -- a string that holds an integer key Output : (content,error,comments) content -- a string for what is returned on stdout error -- a string for what is returned on stderr comments = {[], ['error comment 1', ...]} [] -- this means no errors occurred ['.', ''] -- A list of error messages ''' comments = [] (rc, content, error, timeout) = execute_command('./removecontent {} {}'.format(ip_port, key)) if rc != 0: comments.append('[removecontent] Return Code is: {}'.format(rc)) if error != '': if error != error_messages['no content'] and error != error_messages[ 'no peer']: comments.append( '[removecontent] Unknown Error String: {}'.format(error)) if timeout != False: comments.append('[removecontent] Timed Out!') content = '' error = '' return (content, error, comments)
def lookup_content(ip_port, key): ''' Description : Returns the content stored for a specific key or the Error message 'Error: no such content' if there is no content Input : ip_port, key ip_port -- a string containing the ip address and port: 'ip port' key -- a string that holds an integer key Output : (content,error,comments) content -- a string for what is returned on stdout error -- a string for what is returned on stderr comments = {[], ['error comment 1', ...]} [] -- this means no errors occurred ['.', ''] -- A list of error messages ''' comments = [] (rc, content, error, timeout) = execute_command('./lookupcontent {} {}'.format(ip_port, key)) if rc != 0: comments.append('[lookupcontent] Return Code is: {}'.format(rc)) if error != '': if error != 'Error: no such content' and error != 'Error: no such peer': comments.append( '[lookupcontent] Unknown Error String: {}'.format(error)) if timeout != False: comments.append('[lookupcontent] Timed Out!') content = '' error = '' return (content, error, comments)
def setup_sail2pvs(only_print): cmd = patch_lem_src('src') cmd += patch_lem_src('library') cmd += 'cp ./patches/*.ml ' + os.path.join(lem_path, 'src') + '; ' print(cmd) if not only_print: out = helper.execute_command(cmd) print(out)
def backup_new_file(name, only_print): patch_info = data['patch'] src_dir = os.path.join(patch_info['src_dir'], name) dest_dir = os.path.join(patch_info['dest_dir'], name) patch_path = patch_info['patch_path'] src_files = list(filter(lambda f: f.endswith('.ml'), os.listdir(src_dir))) copy_files = [] cmd = '' for file in src_files: if not os.path.exists(os.path.join(dest_dir, file)): copy_files.append(file) if copy_files: cmd += 'cp -f ' cmd += ' '.join( list(map(lambda f: os.path.join(src_dir, f), copy_files))) cmd += ' ' + patch_path print(cmd) if not only_print and cmd: helper.execute_command(cmd)
def add_peer(ip_port): ''' Description : Adds a peer to an existing network or starts a new network if ip_port is an empty string Input : ip_port -- a string containing the ip address and port: 'ip port' Output : (peer, comments) peer = {None, 'ip port'} None -- this means an error occurred and no peer was added to the network 'ip port' -- this is the ip address and port number of the newly added peer comments = {[], ['error comment 1', ...]} [] -- this means no errors occurred ['.', ''] -- A list of error messages ''' peer = None comments = [] (rc, out, err, timeout) = execute_command('./addpeer {}'.format(ip_port)) if rc != 0: comments.append('[addpeer] Return Code is: {}'.format(rc)) if err != '': comments.append('[addpeer] Error String: {}'.format(err)) if timeout != False: comments.append('[addpeer] Timed Out!') return (peer, comments) ################# # Checking for proper output format: ip_address port sp = out.split() if len(sp) != 2: comments.append( '[addpeer] Invalid return string: {}; expecting 2 elements but there are {} elements' .format(out, len(sp))) else: ip = sp[0] port = sp[1] ip_sp = ip.split('.') if len(ip_sp) != 4: comments.append('[addpeer] Invalid IP returned: {}'.format(ip)) else: # debug_msg(ip_sp) if not is_int(port) or not is_int(ip_sp[0]) or not is_int( ip_sp[1]) or not is_int(ip_sp[2]) or not is_int(ip_sp[3]): comments.append( '[addpeer] IP and Port must be integers {} {}'.format( ip, port)) # Checking for any errors found above if len(comments) == 0: # No errors peer = out return (peer, comments)
def parse_library_to_pvs(library_name, only_print): lem_executable = helper.preprocess_path(data['lem_executable']) lem_library_data = data[library_name] pvs_library_path = os.path.join(helper.dir_path, lem_library_data['pvs_library_name']) if os.path.exists(pvs_library_path): shutil.rmtree(pvs_library_path) os.mkdir(pvs_library_path) cmd = 'cd ' + lem_library_data['library_path'] + '; ' cmd += lem_executable + ' -pvs -outdir ' + pvs_library_path + ' ' cmd += lem_library_data['lem_flags'] + ' ' cmd += lem_library_data['lem_src_files'] + '; ' cmd += 'cd ' + pvs_library_path + '; ' cmd += 'rm -f *_aux.pvs; ' print(cmd) if not only_print: helper.execute_command(cmd) rewriteFiles.rewrite_files(pvs_library_path, lem_library_data['special_prefix']) cmd = 'cp -f ./pvs_aux/* ' + pvs_library_path helper.execute_command(cmd)
def all_keys(ip_port): ''' Description : Returns all keys stored on a peer Input : ip_port ip_port -- a string containing the ip address and port: 'ip port' Output : (keys, comments) key = {None, [], ['key1', ...]} None -- this means an error occurred and no peer was added to the network [] -- this means that no content is stored on this peer ['key1', ...] -- this is the list of content that is stored on this peer comments = {[], ['error comment 1', ...]} [] -- this means no errors occurred ['.', ''] -- A list of error messages ''' keys = None comments = [] (rc, out, err, timeout) = execute_command('./allkeys {}'.format(ip_port)) if rc != 0: comments.append('[allkeys] Return Code is: {}'.format(rc)) if err != '': comments.append('[allkeys] Error String: {}'.format(err)) if timeout != False: comments.append('[allkeys] Timed Out!') return (keys, comments) if out == '': keys = [] else: sp = out.split() passed_test = True for s in sp: if not is_int(s): passed_test = False break if not passed_test: comments.append( '[allkeys] All keys must be integers: {}'.format(out)) else: keys = sp return (keys, comments)
def add_content(ip_port, content): ''' Description : Adds content to an existing network Input : ip_port, content ip_port -- a string containing the ip address and port: 'ip port' content -- a string containing some content to be added to the network Output : (key, comments) key = {None, 'int'} None -- this means an error occurred and no peer was added to the network 'int' -- this is the unique key given for that content comments = {[], ['error comment 1', ...]} [] -- this means no errors occurred ['.', ''] -- A list of error messages ''' key = None comments = [] (rc, out, err, timeout) = execute_command('./addcontent {} "{}"'.format( ip_port, content)) if rc != 0: comments.append('[addcontent] Return Code is: {}'.format(rc)) if err != '': comments.append('[addcontent] Error String: {}'.format(err)) if timeout != False: comments.append('[addcontent] Timed Out!') return (key, comments) if not is_int(out): comments.append( '[addcontent] Output string must be a integer key: {}'.format(out)) else: # No errors key = out return (key, comments)
def command(): command = helper.get_command() helper.execute_command(command) command = ""
def setup_pvs(): pvs_home = os.environ.get('PVS_HOME') cmd = 'cp -R ./pvs-patches ' + pvs_home + '; ' cmd += 'cp ./Test_Cases/pvs-strategies ' + data[tags[T_TestDir]] helper.execute_command(cmd)
def clean(): cmd = 'cd ' + data[tags[T_TestDir]] + '; ' cmd += 'rm -f *.pvs *.prf *.prf~ *.summary' helper.execute_command(cmd)