Beispiel #1
0
def scribe_record(args,
                  logfile=None,
                  pre_record=def_pre_script,
                  post_record=def_post_script):
    if not logfile:
        logfile = args.path + '.log'
    with execute.open(jailed=args.jailed,
                      chroot=args.chroot,
                      root=args.root,
                      scratch=args.scratch,
                      persist=args.pdir) as exe:

        if pre_record:
            logging.info('    running pre-record callback...')
            pre_record(exe, args)

        logging.info('    recording ...')
        cmd = args._run if os.path.isabs(args._run) else './' + args._run

        flags = scribe.SCRIBE_SYSCALL_RET | \
                scribe.SCRIBE_SYSCALL_EXTRA | \
                scribe.SCRIBE_SIG_COOKIE | \
                scribe.SCRIBE_RES_EXTRA | \
                scribe.SCRIBE_DATA_EXTRA | \
                scribe.SCRIBE_DATA_STRING_ALWAYS | \
                scribe.SCRIBE_RES_ALWAYS | \
                scribe.SCRIBE_REGS

        if args.initproc:
            flags |= scribe.SCRIBE_CUSTOM_INIT
        if args.netns:
            flags |= scribe.SCRIBE_CLONE_NEWNET

        with open(logfile, 'w') as file:
            try:
                context, pinit = _do_scribe_exec(cmd,
                                                 file,
                                                 exe,
                                                 args.redirect,
                                                 flags,
                                                 record=True)
                _do_scribe_wait(context,
                                pinit,
                                args.max_runtime,
                                kill=not not args.max_runtime)
            except Exception as e:
                logging.error('failed recording: %s' % e)
                success = False
            else:
                logging.info('record completed')
                success = True

        if post_record:
            logging.info('    running post-record callback...')
            post_record(exe, args)

        return success
Beispiel #2
0
    def run(self):
        stop_requested = [False]
        replayer = [None]

        def do_stop(signum, stack):
            logging.info("Stop Requested")
            stop_requested[0] = True
            replayer[0].stop()

        signal.signal(signal.SIGINT, do_stop)

        self.add_execution(None, self.root)

        num_run = 0
        while not stop_requested[0]:
            if self.num_state(
                    ExecutionStates.SUCCESS) >= self.num_success_to_stop:
                break

            todos = filter(lambda e: e.state == ExecutionStates.TODO,
                           self.executions)
            if len(todos) == 0:
                break
            self.print_status(num_run)
            execution = max(todos, key=lambda e: e.score)

            num_run += 1
            with execute.open(jailed=self.isolate) as exe:
                execution.num_run = num_run
                execution.num_success = len(
                    list([
                        e for e in self.executions
                        if e.state == ExecutionStates.SUCCESS
                    ]))

                replayer[0] = Replayer(execution)
                replayer[0].run(exe)

        signal.signal(signal.SIGINT, signal.SIG_DFL)

        print("Number of Replays: %d" % num_run)

        if self.num_success_to_stop != 1:
            print("")
            self.print_status(num_run)
            print("Summary of good executions:")
            self.executions.sort(key=lambda e: e.score)
            for execution in self.executions:
                if execution.state == ExecutionStates.SUCCESS:
                    print("%d %d %d %s:" %
                          (execution.score, execution.num_run,
                           execution.num_success + 1, execution))
                    execution.print_diff()
                    print("")
Beispiel #3
0
def main(server=SERVER):
    #c = MQTTClient (CLIENT_ID, server, PORT_NO, USERNAME, PASSWORD, 60)
    # Subscribed messages will be delivered to this callback
    #c.set_callback(sub_cb)
    #c.connect()
    #c.subscribe(TOPIC)
    #print("Connected to %s, subscribed to %s topic" % (server, TOPIC))
    #change=1
    #try:
    while 1:
        c = MQTTClient(CLIENT_ID, server, PORT_NO, USERNAME, PASSWORD, 60)
        # Subscribed messages will be delivered to this callback
        c.set_callback(sub_cb)
        c.connect()
        c.subscribe(TOPIC)
        print("Connected to %s, subscribed to %s topic" % (server, TOPIC))
        change = 1
        #micropython.mem_info()
        led = machine.Pin(9, machine.Pin.IN)
        led2 = machine.Pin(12, machine.Pin.IN)
        if led.value() is 0:
            c.publish(TOPIC_Publish, '1')
            print("SD2 ok!")
        if led2.value() is 0:
            c.publish(TOPIC_Publish2, '1')
            print("D6 ok!")
        c.wait_msg()
        del sys.modules['execute']
        import execute
        execute.open()
        f = open('execute.py', 'r')
        sss = f.read()
        print(sss)
        f.close()
        print("finish")
        c.disconnect()
Beispiel #4
0
def scribe_record(args, logfile=None,
                  pre_record=def_pre_script,
                  post_record=def_post_script):
    if not logfile:
        logfile = args.path + '.log'
    with execute.open(jailed=args.jailed, chroot=args.chroot, root=args.root,
                      scratch=args.scratch, persist=args.pdir) as exe:

        if pre_record:
            logging.info('    running pre-record callback...')
            pre_record(exe, args)

        logging.info('    recording ...')
        cmd = args._run if os.path.isabs(args._run) else './' + args._run

        flags = scribe.SCRIBE_SYSCALL_RET | \
                scribe.SCRIBE_SYSCALL_EXTRA | \
                scribe.SCRIBE_SIG_COOKIE | \
                scribe.SCRIBE_RES_EXTRA | \
                scribe.SCRIBE_DATA_EXTRA | \
                scribe.SCRIBE_DATA_STRING_ALWAYS | \
                scribe.SCRIBE_RES_ALWAYS | \
                scribe.SCRIBE_REGS

        if args.initproc:
            flags |= scribe.SCRIBE_CUSTOM_INIT
        if args.netns:
            flags |= scribe.SCRIBE_CLONE_NEWNET

        with open(logfile, 'w') as file:
            try:
                context, pinit = _do_scribe_exec(
                        cmd, file, exe, args.redirect, flags, record=True)
                _do_scribe_wait(context, pinit, args.max_runtime,
                                kill=not not args.max_runtime)
            except Exception as e:
                logging.error('failed recording: %s' % e)
                success = False
            else:
                logging.info('record completed')
                success = True

        if post_record:
            logging.info('    running post-record callback...')
            post_record(exe, args)

        return success
Beispiel #5
0
    def run(self):
        stop_requested = [False]
        replayer = [None]
        def do_stop(signum, stack):
            logging.info("Stop Requested")
            stop_requested[0] = True
            replayer[0].stop()

        signal.signal(signal.SIGINT, do_stop)

        self.add_execution(None, self.root)

        num_run = 0
        while not stop_requested[0]:
            if self.num_state(ExecutionStates.SUCCESS) >= self.num_success_to_stop:
                break

            todos = filter(lambda e: e.state == ExecutionStates.TODO, self.executions)
            if len(todos) == 0:
                break
            self.print_status(num_run)
            execution = max(todos, key=lambda e: e.score)

            num_run += 1
            with execute.open(jailed=self.isolate) as exe:
                execution.num_run = num_run
                execution.num_success = len(list([e for e in self.executions if e.state == ExecutionStates.SUCCESS]))

                replayer[0] = Replayer(execution)
                replayer[0].run(exe)

        signal.signal(signal.SIGINT, signal.SIG_DFL)

        print("Number of Replays: %d" % num_run)

        if self.num_success_to_stop != 1:
            print("")
            self.print_status(num_run)
            print("Summary of good executions:")
            self.executions.sort(key=lambda e: e.score)
            for execution in self.executions:
                if execution.state == ExecutionStates.SUCCESS:
                    print("%d %d %d %s:" % (execution.score, execution.num_run, execution.num_success+1, execution))
                    execution.print_diff()
                    print("")
Beispiel #6
0
def scribe_replay(args,
                  logfile=None,
                  verbose='',
                  bookmark_cb=None,
                  pre_replay=def_pre_script,
                  post_replay=def_post_script,
                  test_replay=None):
    if not logfile:
        logfile = args.path + '.log'
    with execute.open(jailed=args.jailed,
                      chroot=args.chroot,
                      root=args.root,
                      scratch=args.scratch,
                      persist=args.pdir) as exe:
        if bookmark_cb:
            bookmark_cb = Callback(bookmark_cb, exe=exe, logfile=logfile)

        if pre_replay:
            logging.info('    running pre-replay callback...')
            pre_replay(exe, args)

        logging.info('    replaying ...')
        with open(logfile, 'r') as file:
            pinit = None
            ret = None
            try:
                context, pinit = _do_scribe_exec(None,
                                                 file,
                                                 exe,
                                                 args.redirect,
                                                 0,
                                                 deadlock=1,
                                                 replay=True,
                                                 bookmark_cb=bookmark_cb)
                ret = _do_scribe_wait(context, pinit, args.max_runtime,
                                      not not args.max_runtime)
            except scribe.DeadlockError as derr:
                logging.info(str(derr))
                if verbose:
                    print(verbose + 'replay deadlock')
                success = False
            except scribe.DivergeError as derr:
                logging.info(str(derr))
                if verbose:
                    print(verbose + 'replay diverge (%d)' % derr.err)
                success = False
            except Exception as e:
                logging.error('failed replaying: %s' % e)
                success = False
            else:
                if args.max_runtime:
                    if ret is None:
                        print('replay in-transit')
                        success = True
                    else:
                        print(verbose + 'replay died early (%d)' % ret)
                else:
                    logging.info('replay completed')
                success = True

        if test_replay and success:
            logging.info('    running test-replay callback...')
            if test_replay(exe, args):
                print(verbose + 'BUG REPRODUCED')
            else:
                print(verbose + 'BUG not triggered')
        elif success and verbose:
            print(verbose + 'BUG replayed but not tested')

        if args.max_runtime and success:
            _do_scribe_wait(context, pinit, 0.01, True)

        if post_replay:
            logging.info('    running post-replay callback...')
            post_replay(exe, args)

        if args.jailed and args.archive:
            logdir = args.path + '.rw'
            exec_piped('rm -rf %s' % logdir)
            exec_piped('cp -ax %s %s' % (exe.scratch, logdir))

        return success
Beispiel #7
0
def scribe_replay(args, logfile=None, verbose='', bookmark_cb=None,
                  pre_replay=def_pre_script,
                  post_replay=def_post_script,
                  test_replay=None):
    if not logfile:
        logfile = args.path + '.log'
    with execute.open(jailed=args.jailed, chroot=args.chroot, root=args.root,
                      scratch=args.scratch, persist=args.pdir) as exe:
        if bookmark_cb:
            bookmark_cb = Callback(bookmark_cb, exe=exe, logfile=logfile)

        if pre_replay:
            logging.info('    running pre-replay callback...')
            pre_replay(exe, args)

        logging.info('    replaying ...')
        with open(logfile, 'r') as file:
            pinit = None
            ret = None
            try:
                context, pinit =  _do_scribe_exec(
                        None, file, exe, args.redirect, 0, deadlock=1,
                        replay=True, bookmark_cb=bookmark_cb)
                ret = _do_scribe_wait(context, pinit, args.max_runtime,
                                      not not args.max_runtime)
            except scribe.DeadlockError as derr:
                logging.info(str(derr))
                if verbose:
                    print(verbose + 'replay deadlock')
                success = False
            except scribe.DivergeError as derr:
                logging.info(str(derr))
                if verbose:
                    print(verbose + 'replay diverge (%d)' % derr.err)
                success = False
            except Exception as e:
                logging.error('failed replaying: %s' % e)
                success = False
            else:
                if args.max_runtime:
                    if ret is None:
                        print('replay in-transit')
                        success = True
                    else:
                        print(verbose + 'replay died early (%d)' % ret)
                else:
                    logging.info('replay completed')
                success = True

        if test_replay and success:
            logging.info('    running test-replay callback...')
            if test_replay(exe, args):
                print(verbose + 'BUG REPRODUCED')
            else:
                print(verbose + 'BUG not triggered')
        elif success and verbose:
            print(verbose + 'BUG replayed but not tested')

        if args.max_runtime and success:
            _do_scribe_wait(context, pinit, 0.01, True)

        if post_replay:
            logging.info('    running post-replay callback...')
            post_replay(exe, args)

        if args.jailed and args.archive:
            logdir = args.path + '.rw'
            exec_piped('rm -rf %s' % logdir)
            exec_piped('cp -ax %s %s' % (exe.scratch, logdir))

        return success