def _parse_config_and_format(path: pl.Path) -> typ.Tuple[pl.Path, str, str]: config_filepath = _pick_config_filepath(path) if config_filepath.is_absolute(): config_rel_path = str(config_filepath.relative_to(path.absolute())) else: config_rel_path = str(config_filepath) config_filepath = pl.Path.cwd() / config_filepath config_format = config_filepath.suffix[1:] return (config_filepath, config_rel_path, config_format)
def parse_arguments(args, opts): expr_path = opts['exprid'] assert (expr_path), "Specify an experiment name" faults = opts['file'] assert (faults), "We expect a json file from pure injection experiments.\n" faults = str(Path(faults).absolute()) num_workers = opts['num_workers'] Filter = opts['Filter'] print(Filter) if Filter: Filter = Path(Filter).absolute() print(Filter) if Filter and Filter.exists(): print(Filter) with open(Filter) as fh: Filter = fh.readlines() Filter = [line.strip() for line in Filter] else: Filter = None # this is to add support for passing applications and their arguments as a single string # e.g. gdbfi <options for gdbfi> apps <options for executable> # if options for applications contains params like "-i", there would be a problem since # python will consider it as python options. so we will make it as a string executable = args[0].split()[0] arguments = args[1:] arguments = args[0].split()[1:] + arguments # if an argument is a file, use the absolute path as final arguments for i in range(len(arguments)): path = Path(arguments[i]) if path.exists(): arguments[i] = str(path.absolute()) print("Expr: ", expr_path) print("Exec: ", executable) print("Args: ", arguments) print('Faluts: ', faults) print('Filter: ', Filter) print("Num_workers: ", num_workers) return (executable, arguments, expr_path, faults, Filter, num_workers)
def parse_arguments(args, opts): base = 0 if opts['base']: base = opts['base'] expr_path = opts['exprid'] if not expr_path: expr_path = 'GDBFI' framework = "pintool" if opts['framework']: framework = opts['framework'] if framework not in ['gdb', 'pintool']: raise Exception('Unsupported injection framework: %s' % framework) fmodel = 'bitflip' if opts['model']: fmodel = opts['model'] if fmodel not in ['bitflip', 'dbitflip', 'stuck-at-0', 'stuck-at-1']: raise Exception('Fault model (%s) is not supported' % fmodel) num_workers = opts['num_workers'] runs = 10000 if opts['runs']: runs = opts['runs'] skip_profile = False if opts['skip_profile']: skip_profile = opts['skip_profile'] # this is to add support for passing applications and their arguments as a single string # e.g. gdbfi <options for gdbfi> apps <options for executable> # if options for applications contains params like "-i", there would be a problem since # python will consider it as python options. so we will make it as a string executable = args[0].split()[0] arguments = args[1:] arguments = args[0].split()[1:] + arguments for i in range(len(arguments)): path = Path(arguments[i]) if path.exists(): arguments[i] = str(path.absolute()) return (executable, arguments, base, expr_path, framework, fmodel, num_workers, runs, skip_profile)
def parse_arguments(args, opts): expr_path = opts['exprid'] assert(expr_path), "Specify an experiment name" faults = opts['faults'] assert(faults), "We expect a json file from pure injection experiments.\n" faults = Path(faults).absolute() nprocesses = opts['nprocesses'] hosts = opts['hosts'] if hosts: hosts = str(Path(hosts).absolute()) # this is to add support for passing applications and their arguments as a single string # e.g. gdbfi <options for gdbfi> apps <options for executable> # if options for applications contains params like "-i", there would be a problem since # python will consider it as python options. so we will make it as a string executable = args[0].split()[0] arguments = args[1:] arguments = args[0].split()[1:] + arguments # if an argument is a file, use the absolute path as final arguments for i in range(len(arguments)): path = Path(arguments[i]) if path.exists(): arguments[i] = str(path.absolute()) print("Expr: ", expr_path) print("Exec: ", executable) print("Args: ", arguments) print('Hosts: ', hosts) print('Faluts: ', faults) print("nprocesses: ", nprocesses) return (executable, arguments, expr_path, hosts, faults, nprocesses)
def main(): global joint_names joint_names = [name for name in JOINT_NAMES] reverse_port = DEFAULT_REVERSE_PORT # Parses command line arguments """ parser = optparse.OptionParser(usage="usage: %prog robot_hostname [reverse_port]") (options, args) = parser.parse_args(rospy.myargv()[1:]) if len(args) < 1: parser.error("You must specify the robot hostname") elif len(args) == 1: robot_hostname = args[0] elif len(args) == 2: robot_hostname = args[0] reverse_port = int(args[1]) if not (0 <= reverse_port <= 65535): parser.error("You entered an invalid port number") else: parser.error("Wrong number of parameters") """ # Reads the calibrated joint offsets from the URDF #global joint_offsets #joint_offsets = load_joint_offsets(joint_names) """ if len(joint_offsets) > 0: rospy.loginfo("Loaded calibration offsets from urdf: %s" % joint_offsets) else: rospy.loginfo("No calibration offsets loaded from urdf") """ # Reads the maximum velocity # The max_velocity parameter is only used for debugging in the ur_driver. It's not related to actual velocity limits global max_velocity #max_velocity = rospy.get_param("~max_velocity", MAX_VELOCITY) # [rad/s] #rospy.loginfo("Max velocity accepted by ur_driver: %s [rad/s]" % max_velocity) # Reads the minimum payload global min_payload #min_payload = rospy.get_param("~min_payload", MIN_PAYLOAD) # Reads the maximum payload global max_payload #max_payload = rospy.get_param("~max_payload", MAX_PAYLOAD) #rospy.loginfo("Bounds for Payload: [%s, %s]" % (min_payload, max_payload)) # Sets up the server for the robot to connect to server = TCPServer(("", reverse_port), CommanderTCPHandler) thread_commander = threading.Thread(name="CommanderHandler", target=server.serve_forever) thread_commander.daemon = True thread_commander.start() #with open(roslib.packages.get_pkg_dir('ur_driver') + '/prog') as fin: pather = Path() path = pather.absolute() # robot_hostname="ur-2013216004" robot_hostname = "128.113.224.10" with open(str(path) + '/prog') as fin: programstring = fin.read() % { "driver_hostname": get_my_ip(robot_hostname, PORT), "driver_reverseport": reverse_port } program = bytearray(programstring) #,'utf-8') nodename = "URConnection" with RR.ServerNodeSetup(nodename, 2355) as node_setup: RRN.RegisterServiceTypeFromFile("com.robotraconteur.geometry") RRN.RegisterServiceTypeFromFile("com.robotraconteur.uuid") RRN.RegisterServiceTypeFromFile("com.robotraconteur.datetime") RRN.RegisterServiceTypeFromFile("com.robotraconteur.identifier") RRN.RegisterServiceTypeFromFile("com.robotraconteur.sensordata") RRN.RegisterServiceTypeFromFile("com.robotraconteur.resource") RRN.RegisterServiceTypeFromFile("com.robotraconteur.device") RRN.RegisterServiceTypeFromFile("com.robotraconteur.units") RRN.RegisterServiceTypeFromFile("com.robotraconteur.robotics.joints") RRN.RegisterServiceTypeFromFile( "com.robotraconteur.robotics.trajectory") RRN.RegisterServiceTypeFromFile("com.robotraconteur.datatype") RRN.RegisterServiceTypeFromFile("com.robotraconteur.signal") RRN.RegisterServiceTypeFromFile("com.robotraconteur.param") RRN.RegisterServiceTypeFromFile("com.robotraconteur.robotics.tool") RRN.RegisterServiceTypeFromFile("com.robotraconteur.robotics.payload") RRN.RegisterServiceTypeFromFile("com.robotraconteur.robotics.robot") #Add allowed origin for Web node_setup.tcp_transport.AddWebSocketAllowedOrigin("http://localhost") node_setup.tcp_transport.AddWebSocketAllowedOrigin( "http://localhost:8000") node_setup.tcp_transport.AddWebSocketAllowedOrigin( "https://johnwason.github.io") connection = URConnection(robot_hostname, PORT, program) connection.connect() connection.send_reset_program() connectionRT = URConnectionRT(robot_hostname, RT_PORT) connectionRT.connect() service_provider = None try: # Checks for disconnect if getConnectedRobot(wait=False): time.sleep(0.2) print("Got connected robot?") if prevent_programming: print("Programming now prevented") connection.send_reset_program() else: print("Disconnected. Reconnecting") #rospy.loginfo("Programming the robot") while True: # Sends the program to the robot while not connection.ready_to_program(): print("Waiting to program") time.sleep(1.0) connection.send_program() r = getConnectedRobot(wait=True, timeout=1.0) if r: break #rospy.loginfo("Robot connected") #provider for service calls action_server = UR_Joint_Listener(r, 1.0) action_server.set_robot(r) action_server.start() #password: cats111! authdata = "cats be7af03a538bf30343a501cb1c8237a0 objectlock" p = RR.PasswordFileUserAuthenticator(authdata) policies = {"requirevaliduser": "******"} s = RR.ServiceSecurityPolicy(p, policies) RRN.RegisterService("Universal_Robot", "com.robotraconteur.robotics.robot.Robot", action_server, s) raw_input("press enter to quit...\r\n") connection.disconnect() connectionRT.disconnect() action_server.stop() #Register the service type and the service #RRN.RegisterServiceTypeFromFile("universal_robotics") #RRN.RegisterService("Universal_Robot","robot.universalrobotics.Universal_Robot",action_server) #action_server.start() except KeyboardInterrupt: try: r = getConnectedRobot(wait=False) #rospy.signal_shutdown("KeyboardInterrupt") if r: r.send_quit() except: pass raise
def create_env(args): pkr_path = Path(args.path) create_pkr_folder(pkr_path) write('File structure created in : {}'.format(str( pkr_path.absolute())))
class PINFramework(Framework): # pin -t / home/cchen/Documents/Projects/CARE/src/GDBFI/pintool/pintool.so - - ./bench_gtc_care A.txt 100 1 def __init__(self, fmodel, logger): self._logger = logger self._insts = None self._distr = None self._pin = shutil.which('pin') if self._pin is None: sys.exit("Pin is not found. Please Add Pin the $PATH") self._pintool = Path( os.path.realpath(__file__)).parent.joinpath('pintool/pintool.so') if not self._pintool.exists(): sys.exit("pintool is not found in: %s" % self._pintool.absolute()) super(PINFramework, self).__init__(fmodel) def load_profile(self, profile_path): profile = profile_path.joinpath('gdbfi.profile') assert profile.exists(), "Profile file %s not found" % profile.name data = pd.read_csv(profile, sep=';') data = data.loc[data['Candidate'] == 1] data = data.loc[data['MemWrite'] == 0] total = data['executions'].sum() self._distr = data['executions'].tolist() / total self._execs = data['executions'].tolist() self._insts = data['addr'].tolist() # loading timing info profile = profile_path.joinpath('overview.json') assert profile.exists(), "profile file %s not found" % profile with open(str(profile)) as fh: data = json.load(fh) self._p_time = data['exec_time'] def get_injection_point(self): idx = np.random.choice(len(self._insts), p=self._distr) addr = self._insts[idx] upbound = min(self._execs[idx], 500) count = randint(1, upbound) return (addr, count) def profile(self, exec, params): parameters = ['-t', str(self._pintool), '--', exec] + params app = Application(self._pin, parameters) app.start() code = app.wait() self._logger.info("\tProfile run (PINFramework) finished (code : %s)" % code) data = pd.read_csv('gdbfi.profile', sep=';') total_dyn_insts = data['executions'].sum() total_mem_acc_insts = data.loc[((data['MemRead'] == 1) | (data['MemWrite'] == 1))]['executions'].sum() # app = Application(exec, params) # self._logger.info("Profile run for timing.") # app.start() # code = app.wait() # self._logger.info( # "\tProfile run for timing finished (code : %s)" % code) time = app.get_exec_time() time = 0.98 * time self._p_time = time with open('overview.json', 'w') as fh: json.dump( { 'dyn_insts': int(total_dyn_insts), 'mem_acc_insts': int(total_mem_acc_insts), 'ratio': float( total_mem_acc_insts * 1.0 / total_dyn_insts), 'exec_time': time }, fh) def start_and_inject(self, exec, params, wid, job): gdbsession = GDBController(self._logger, wid, job) while True: self._logger.info( "GDBFI-FIWorker (Worker %d, pid %d): \t[%s] doing/redoing" % (wid, os.getpid(), job)) (addr, count) = self.get_injection_point() app = Application(exec, params) app.start() status = gdbsession.attach(app.pid()) if status == 'error' or status == 'timeout': self._logger.info( 'GDBFI-FIWorker (Worker %d, pid %d):\t[%s]: ' 'failed to attach to the target process (pid: %d) (stop_point: %s). retrying...' % (wid, os.getpid(), job, app.pid(), str((addr, count)))) if app.is_alive: app.terminate() continue number = gdbsession.set_breakpoint(addr, count) if number == 'error': if app.is_alive: app.terminate() continue status = gdbsession.exec_continue() if status == 'error': if app.is_alive: app.terminate() continue self._logger.info( 'GDBFI-FIWorker (Worker %d, pid %d):\t[%s]: retrive and analyze the instruction' % (wid, os.getpid(), job)) pc = gdbsession.get_curr_pc() code = gdbsession.get_code_as_bytes(address=pc) insn = GDBFIInstruction(code, pc) if not insn.is_valid(): self._logger.info( 'GDBFI-FIWorker (Worker %d, pid %d):\t[%s]: meet an invalid PC. retrying ...' % (wid, os.getpid(), job)) if app.is_alive: app.terminate() continue redo = False while not insn.is_injectable(): self._logger.info( 'GDBFI-FIWorker (Worker %d, pid %d):\t[%s]: skip an uninjectable instruction' % (wid, os.getpid(), job)) status = gdbsession.exec_nexti() if status == 'error' or status == 'timeout': redo = True break pc = gdbsession.get_curr_pc() code = gdbsession.get_code_as_bytes(address=pc) insn = GDBFIInstruction(code, pc) if not insn.is_valid(): redo = True break # the insn is not valid and we will rerun the application if redo: self._logger.info( 'GDBFI-FIWorker (Worker %d, pid %d):\t[%s]: meet an error when finding inject targetr. retrying...' % (wid, os.getpid(), job)) if app.is_alive: app.terminate() continue fault = GDBFIFault((addr, count), gdbsession, insn, self._fmodel) # advance to the next step to update the target status = gdbsession.exec_nexti() if status == 'error' or status == 'timeout': if app.is_alive(): app.terminate() continue fault.inject() self._logger.info( 'GDBFI-FIWorker (Worker %d, pid %d):\t[%s]: injecte fault (%s) to instruction (%s).' % (wid, os.getpid(), job, str(fault), insn.get_inst_string())) self._logger.info( 'GDBFI-FIWorker (Worker %d, pid %d):\t[%s]: continue the execution to exit.' % (wid, os.getpid(), job)) break return (gdbsession, app, fault)
def abs_path(raw_path: Path) -> Path: str_path = str(raw_path) usr_path = os.path.expandvars(str_path) abs_path = Path(usr_path).expanduser() return abs_path.absolute()
class Veg(object): def __init__(self, filepath): self._path = Path(os.path.abspath(filepath)) def __fspath__(self): return str(self._path.absolute()) def __str__(self): return str(self.path) def __eq__(self, other): try: return self.abspath == other.abspath except AttributeError: return NotImplemented def __lt__(self, other): try: return self.abspath < other.abspath except AttributeError: return NotImplemented def __hash__(self): return hash(self.abspath) @property def exists(self): """Check existence of this path in filesystem. """ return self.path.exists() @property def path(self): """Filesystem path as a :class:`pathlib2.Path`. """ return self._path @property def abspath(self): """Absolute path. """ return str(self.path.absolute()) @property def relpath(self): """Relative path from current working directory. """ return os.path.relpath(str(self.path)) @property def parent(self): """Parent directory for this path. """ return Tree(str(self.path.parent)) @property def name(self): """Basename for this path. """ return os.path.basename(os.path.abspath(self.abspath))