def main(): def run(portIn: str): global port port = portIn _thread.start_new_thread(arduinoLoop,()) def arduinoLoop(): arduino = Hardware(port=port) while True: # mode = 1 # sleep(1) # temp = manager.getTemp() # arduino.invoke(mode, temp) mode = 2 (cpu, ram) = manager.get() if cpu > 100: cpu = 100 if ram > 100: ram = 100 arduino.invoke(mode, cpu) mode = 3 sleep(1) arduino.invoke(mode, ram) manager = System_info_manager(interval=1) devices = Hardware.find() app = Application(devices) app.callback = lambda port: run(port) app.start()
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 profile(self, exec, params): time = float(0) app = Application(exec, params) self._logger.info("GDBFramework Profile run (rounds: %d)." % self._rounds) for iter in range(self._rounds): app.start() code = app.wait() self._logger.info( "\tprofile run (GDBFramework) round %d (code : %s)" % (iter, code)) time += app.get_exec_time() time /= self._rounds time = 0.98 * time self._logger.info( "Profile run (GDBFramework) finished. Exec time: %f (code : %s) " % (time, code)) with open('timing.json', 'w') as fh: json.dump({'exec_time': time}, fh)
from tkinter import * from App import Application root = Tk() root.title("Monty Hall") root.geometry("600x350+450+100") root.wm_maxsize(width=600, height=350) root.wm_minsize(width=600, height=350) app = Application(root) app.app_run()
from App import Application import time app = Application() if __name__ == "__main__": deltaTime = 0 while (True): start = time.time() app.Update(deltaTime) end = time.time() deltaTime = end - start
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)
from App import Application from PyQt4 import QtGui if __name__ == "__main__": import sys app = QtGui.QApplication(sys.argv) ui = Application() ui.show() sys.exit(app.exec_())
def run(self): self.log_msg('started successfully') self.log_msg("Workloads: %s" % str(self._workloads)) care_runtime_lib = Path(os.environ['CARE_ROOT']).joinpath( 'build/runtime/libCARERuntime.so').absolute() assert care_runtime_lib.exists( ), "the recovery runtime library is not setup yet!" os.environ["CARE_EXPR_PATH"] = str(self._expr_path) # preload the recovery runtime library os.environ["LD_PRELOAD"] = str(care_runtime_lib) os.environ["CARE_WORKER_ID"] = str(self._id) for w in self._workloads: fid = w.id fip = w.ip fiter = w.iter fbit = w.bit os.environ["CARE_INJECTION_ID"] = str(fid) print('\n\nWorker-%d (%d) -- perform job: ' % (self._id, self.pid), w) self.log_msg('perform job %s' % str(w)) wd = self._expr_path.joinpath(fid) # create injection folder and making it the current working directory if wd.exists(): self.log_msg( '\t[%s]: directory exists, and data could be overwritten.' % fid, logging.WARNING) else: wd.mkdir() os.chdir(str(wd)) gdbsession = GDBController(self._log, self._id, fid) app = Application(self._expr_exec, self._exec_args) while True: app.start() status = gdbsession.attach(app.pid()) if status == 'error' or status == 'timeout': self.log_msg( '\t[%s]: failed to attach to the target process (pid: %d). retry ...' % (fid, app.pid())) if app.is_alive: app.terminate() continue status = gdbsession.set_breakpoint(fip, fiter) if status == 'error' or status == 'timeout': self.log_msg( '\t[%s]: failed to set breakpoint at(PC: %s, iter: %d). retry ...' % (fid, fip, fiter)) if app.is_alive: app.terminate() continue else: bnumber = status status = gdbsession.exec_continue() if status == 'error' or status == 'timeout': self.log_msg( '\t[%s]: failed to continue the execution. retry ...' % fid) if app.is_alive: app.terminate() continue break code = gdbsession.get_code_as_bytes(address=int(fip, 16)) insn = GDBFIInstruction(code, int(fip, 16)) while not insn.is_injectable(): status = gdbsession.exec_nexti() pc = gdbsession.get_curr_pc() code = gdbsession.get_code_as_bytes(address=pc) insn = GDBFIInstruction(code, pc) assert (insn.is_valid()), 'meet an invalid instruction' print("inject fault to instruction: ", insn.get_inst_string()) # get the location where the fault will be injected loc = insn.get_inject_loc() gdbsession.exec_nexti() var = gdbsession.create_variable(loc) print("inject fault to location: ", loc, "\t curr pc: ", gdbsession.get_curr_pc()) # inject the fault by bitflipping data = gdbsession.read_variable(var) fvalue = data for bit in fbit: mask = 1 << bit fvalue = fvalue ^ mask print('Normal: ', data, '\tFaulty: ', fvalue) gdbsession.write_variable(var, fvalue) gdbsession.del_breakpoint(bnumber) # gdbsession.exec_continue() gdbsession.detach() status = app.wait() self.log_msg('\t[%s]: done. Exit status: %s' % (fid, status)) record = dict() record['id'] = fid record['loc'] = loc record['fault'] = str(w) record['status'] = status while self._queue.full(): self.log_msg('\t[%s]: queue is full. waiting ...' % fid) time.sleep(10) # self.log_msg('\t[%s]: put record into the queue: %s' % (name, str(record))) self.log_msg('\t[%s]: put record into the queue.' % (fid)) self._queue.put(record) os.chdir(str(self._expr_path)) # sync before exit self.log_msg('finished job and exit')
import sys import os sys.path.append(os.path.join(os.getcwd(), 'App')) from App import Application app = Application() app.boot()
import pygame from App import Application if __name__ == '__main__': pygame.init() app = Application() app.start()