Example #1
0
class ActorTester(object):

    def __init__(self):
        self.store = ActorStore()
        self.actors = {}
        self.illegal_actors = {}
        self.components = {}
        self.id = "ActorTester"
        self.metering = metering.set_metering(metering.Metering(self))

    def collect_actors(self, actor):
        actors = [m + '.' + a for m in self.store.modules() for a in self.store.actors(m)]

        if actor:
            actors = [a for a in actors if actor in a]

        self.actor_names = actors

    def instantiate_actor(self, actorclass, actorname):
        try:
            actor = actorclass(actorname, disable_state_checks=True)
            if not hasattr(actor, 'test_set'):
                self.actors[actorname] = 'no_test'
                return
            actor._calvinsys = CalvinSysMock()
            actor._calvinsys['file'] = CalvinSysFileMock()
            actor._calvinsys['timer'] = CalvinSysTimerMock()
            actor.init(*actorclass.test_args, **actorclass.test_kwargs)
            actor.setup_complete()
        except Exception as e:
            self.illegal_actors[actorname] = "Failed to instantiate"
            sys.stderr.write("Actor %s: %s" % (actorname, e))
            import traceback
            sys.stderr.write(''.join(traceback.format_exc()))
            raise e

        for inport in actor.inports.values():
            inport.endpoint = DummyInEndpoint(inport)
        for outport in actor.outports.values():
            outport.fifo.add_reader(actor.id)

        self.actors[actorname] = actor

    def instantiate_actors(self):
        for a in self.actor_names:
            found, primitive, actorclass = self.store.lookup(a)
            if found and primitive:
                self.instantiate_actor(actorclass, a)
            elif found and not primitive:
                self.components[a] = "TODO: Cannot test components (%s)" % (a,)
            else:
                self.illegal_actors[a] = "Unknown actor - probably parsing issues"

    def load_actor(self, path):
        actorclass = self.store.load_from_path(path)
        if actorclass:
            self.instantiate_actor(actorclass, path)
        else:
            self.illegal_actors[path] = "Unknown actor - probably parsing issues"

    def test_actor(self, actor, aut):
        for idx in range(len(aut.test_set)):
            test_index = idx + 1
            test = aut.test_set[idx]

            setups = test.get('setup', [])
            inputs = test.get('in', {})
            outputs = test.get('out', {})
            postconds = test.get('postcond', [])

            for f in setups:
                try:
                    f(aut)
                except Exception as e:
                    print "Actor %s failed during setup of test %d: %s" % (actor, test_index, e.message)
                    raise Exception("Failed during setup of test %d" % (test_index, ))

            for port, values in inputs.iteritems():
                pwrite(aut, port, values)

            aut.fire()

            for port, values in outputs.iteritems():
                try:
                    vals = pread(aut, port, len(values))
                    assert vals == values, "Expected output '%s' does not match '%s'" % (vals, values)
                except AssertionError as e:
                    print "Error:", str(e)
                    raise AssertionError("Failed test %d" % (test_index,))

            if not all(f(aut) for f in postconds):
                raise AssertionError("Failed post condition of test %d" % (test_index, ))

        return True

    def test_actors(self):
        test_pass = []
        test_fail = {}
        no_test = []

        for actor in self.actors:
            aut = self.actors[actor]
            if aut == "no_test":
                no_test.append(actor)
                continue
            try:
                self.test_actor(actor, aut)
                test_pass.append(actor)
            except AssertionError as e:
                test_fail[actor] = e.message
                # raise e
            except Exception as e:
                self.illegal_actors[actor] = str(e)

        return {'pass': test_pass, 'fail': test_fail, 'skipped': no_test,
                'errors': self.illegal_actors, 'components': self.components}
Example #2
0
class ActorTester(object):
    def __init__(self):
        self.store = ActorStore()
        self.actors = {}
        self.illegal_actors = {}
        self.components = {}
        self.id = "ActorTester"
        setup_calvinlib()
        self.test_sys = setup_calvinsys()

    def collect_actors(self, actor):
        actors = [
            m + '.' + a for m in self.store.modules()
            for a in self.store.actors(m)
        ]

        if actor:
            actors = [a for a in actors if actor in a]

        self.actor_names = actors

    def instantiate_actor(self, actorclass, actorname):
        try:
            actor = actorclass(actorname, disable_state_checks=True)
            if not hasattr(actor, 'test_set'):
                self.actors[actorname] = 'no_test'
                _log.warning("%s not tested, no test_set defined." % actorname)
                return

            actor.init(*actorclass.test_args, **actorclass.test_kwargs)
            actor.setup_complete()
        except AssertionError as e:
            raise e
        except Exception as e:
            self.illegal_actors[actorname] = "Failed to instantiate"
            sys.stderr.write("Actor %s: %s" % (actorname, e))
            sys.stderr.write(''.join(traceback.format_exc()))
            raise e

        for inport in actor.inports.values():
            inport.set_queue(
                queue.fanout_fifo.FanoutFIFO(
                    {
                        'queue_length': 100,
                        'direction': "in"
                    }, {}))
            inport.endpoint = DummyInEndpoint(inport)
            inport.queue.add_reader(inport.id, {})
        for outport in actor.outports.values():
            outport.set_queue(
                queue.fanout_fifo.FanoutFIFO(
                    {
                        'queue_length': 100,
                        'direction': "out"
                    }, {}))
            outport.queue.add_reader(actor.id, {})
            outport.endpoints.append(DummyOutEndpoint(outport))

        self.actors[actorname] = actor

    def instantiate_actors(self):
        test_fail = {}
        for a in self.actor_names:
            found, primitive, actorclass, signer = self.store.lookup(a)
            if found and primitive:
                try:
                    self.instantiate_actor(actorclass, a)
                except AssertionError as e:
                    test_fail[a] = e.message
                except Exception as e:
                    raise e
            elif found and not primitive:
                self.components[a] = "TODO: Cannot test components (%s)" % (
                    a, )
            else:
                self.illegal_actors[
                    a] = "Unknown actor - probably parsing issues"

        return test_fail

    def load_actor(self, path):
        test_fail = {}
        actorclass, _ = self.store.load_from_path(path)
        if actorclass:
            try:
                self.instantiate_actor(actorclass, path)
            except AssertionError as e:
                test_fail[path] = e.message
            except Exception as e:
                raise e
        else:
            self.illegal_actors[
                path] = "Unknown actor - probably parsing issues"
        return test_fail

    def test_actor(self, actor, aut):
        for idx in range(len(aut.test_set)):
            test_index = idx + 1
            test = aut.test_set[idx]
            setups = test.get('setup', [])
            inputs = test.get('inports', {})
            outputs = test.get('outports', {})
            postconds = test.get('postcond', [])

            for f in setups:
                try:
                    f(aut)
                except Exception as e:
                    print "Actor %s failed during setup of test %d: %s" % (
                        actor, test_index, e.message)
                    raise Exception("Failed during setup of test %d" %
                                    (test_index, ))

            for port, values in inputs.iteritems():
                pwrite(aut, port, values)

            self.test_sys.verify_read_write_during_init(aut, actor)
            self.test_sys.init_done(actor)

            sched = scheduler.BaseScheduler(None, None)
            sched._fire_actor(aut)

            for port, values in outputs.iteritems():
                try:
                    vals = pread(aut, port, len(values))
                    if type(values) is set:
                        # disregard order
                        assert set(
                            vals
                        ) == values, "Expected output set '%s' does not match '%s'" % (
                            set(vals), values)
                    else:
                        assert vals == values, "Expected output '%s' does not match '%s'" % (
                            vals, values)
                except AssertionError as e:
                    print "Error:", str(e)
                    raise AssertionError("Failed test %d" % (test_index, ))

            if not all(f(aut) for f in postconds):
                raise AssertionError("Failed post condition of test %d" %
                                     (test_index, ))

        return True

    def test_actors(self):
        test_pass = []
        test_fail = {}
        no_test = []

        for actor in self.actors:
            aut = self.actors[actor]
            if aut == "no_test":
                no_test.append(actor)
                continue
            try:
                self.test_actor(actor, aut)
                test_pass.append(actor)
            except AssertionError as e:
                test_fail[actor] = e.message
            except Exception as e:
                self.illegal_actors[actor] = str(e) + '\n' + ''.join(
                    traceback.format_exception(sys.exc_type, sys.exc_value,
                                               sys.exc_traceback))

        return {
            'pass': test_pass,
            'fail': test_fail,
            'skipped': no_test,
            'errors': self.illegal_actors,
            'components': self.components
        }
Example #3
0
class ActorTester(object):
    def __init__(self):
        self.store = ActorStore()
        self.actors = {}
        self.illegal_actors = {}
        self.components = {}

    def collect_actors(self, actor):
        actors = [
            m + '.' + a for m in self.store.modules()
            for a in self.store.actors(m)
        ]

        if actor:
            actors = [a for a in actors if actor in a]

        self.actor_names = actors

    def instantiate_actor(self, actorclass, actorname):
        try:
            actor = actorclass(actorname, disable_state_checks=True)
            if not hasattr(actor, 'test_set'):
                self.actors[actorname] = 'no_test'
                return
            actor._calvinsys = CalvinSysMock()
            actor._calvinsys['file'] = CalvinSysFileMock()
            actor._calvinsys['timer'] = CalvinSysTimerMock()
            actor.init(*actorclass.test_args, **actorclass.test_kwargs)
            actor.setup_complete()
        except Exception as e:
            self.illegal_actors[actorname] = "Failed to instantiate"
            sys.stderr.write("Actor %s: %s" % (actorname, e))
            import traceback
            sys.stderr.write(''.join(traceback.format_exc()))
            raise e

        for inport in actor.inports.values():
            inport.endpoint = DummyInEndpoint(inport)
        for outport in actor.outports.values():
            outport.fifo.add_reader(actor.id)

        self.actors[actorname] = actor

    def instantiate_actors(self):
        for a in self.actor_names:
            found, primitive, actorclass = self.store.lookup(a)
            if found and primitive:
                self.instantiate_actor(actorclass, a)
            elif found and not primitive:
                self.components[a] = "TODO: Cannot test components (%s)" % (
                    a, )
            else:
                self.illegal_actors[
                    a] = "Unknown actor - probably parsing issues"

    def load_actor(self, path):
        actorclass = self.store.load_from_path(path)
        if actorclass:
            self.instantiate_actor(actorclass, path)
        else:
            self.illegal_actors[
                path] = "Unknown actor - probably parsing issues"

    def test_actor(self, actor, aut):
        for idx in range(len(aut.test_set)):
            test_index = idx + 1
            test = aut.test_set[idx]

            setups = test.get('setup', [])
            inputs = test.get('in', {})
            outputs = test.get('out', {})
            postconds = test.get('postcond', [])

            for f in setups:
                try:
                    f(aut)
                except Exception as e:
                    print "Actor %s failed during setup of test %d: %s" % (
                        actor, test_index, e.message)
                    raise Exception("Failed during setup of test %d" %
                                    (test_index, ))

            for port, values in inputs.iteritems():
                pwrite(aut, port, values)

            aut.fire()

            for port, values in outputs.iteritems():
                try:
                    vals = pread(aut, port, len(values))
                    assert vals == values, "Expected output '%s' does not match '%s'" % (
                        vals, values)
                except AssertionError as e:
                    print "Error:", str(e)
                    raise AssertionError("Failed test %d" % (test_index, ))

            if not all(f(aut) for f in postconds):
                raise AssertionError("Failed post condition of test %d" %
                                     (test_index, ))

        return True

    def test_actors(self):
        test_pass = []
        test_fail = {}
        no_test = []

        for actor in self.actors:
            aut = self.actors[actor]
            if aut == "no_test":
                no_test.append(actor)
                continue
            try:
                self.test_actor(actor, aut)
                test_pass.append(actor)
            except AssertionError as e:
                test_fail[actor] = e.message
                # raise e
            except Exception as e:
                self.illegal_actors[actor] = str(e)

        return {
            'pass': test_pass,
            'fail': test_fail,
            'skipped': no_test,
            'errors': self.illegal_actors,
            'components': self.components
        }
class ActorTester(object):

    def __init__(self):
        self.store = ActorStore()
        self.actors = {}
        self.illegal_actors = {}
        self.components = {}
        self.id = "ActorTester"
        setup_calvinlib()
        self.test_sys = setup_calvinsys()

    def collect_actors(self, actor):
        actors = [m + '.' + a for m in self.store.modules() for a in self.store.actors(m)]

        if actor:
            actors = [a for a in actors if actor in a]

        self.actor_names = actors

    def instantiate_actor(self, actorclass, actorname):
        try:
            actor = actorclass(actorname, disable_state_checks=True)
            if not hasattr(actor, 'test_set'):
                self.actors[actorname] = 'no_test'
                _log.warning("%s not tested, no test_set defined." % actorname)
                return

            actor.init(*actorclass.test_args, **actorclass.test_kwargs)
            actor.setup_complete()
        except AssertionError as e:
            raise e
        except Exception as e:
            self.illegal_actors[actorname] = "Failed to instantiate"
            sys.stderr.write("Actor %s: %s" % (actorname, e))
            sys.stderr.write(''.join(traceback.format_exc()))
            raise e

        for inport in actor.inports.values():
            inport.set_queue(queue.fanout_fifo.FanoutFIFO({'queue_length': 100, 'direction': "in"}, {}))
            inport.endpoint = DummyInEndpoint(inport)
            inport.queue.add_reader(inport.id, {})
        for outport in actor.outports.values():
            outport.set_queue(queue.fanout_fifo.FanoutFIFO({'queue_length': 100, 'direction': "out"}, {}))
            outport.queue.add_reader(actor.id, {})
            outport.endpoints.append(DummyOutEndpoint(outport))

        self.actors[actorname] = actor

    def instantiate_actors(self):
        test_fail = {}
        for a in self.actor_names:
            found, primitive, actorclass, signer = self.store.lookup(a)
            if found and primitive:
                try:
                    self.instantiate_actor(actorclass, a)
                except AssertionError as e:
                    test_fail[a] = e.message
                except Exception as e:
                    raise e
            elif found and not primitive:
                self.components[a] = "TODO: Cannot test components (%s)" % (a,)
            else:
                self.illegal_actors[a] = "Unknown actor - probably parsing issues"

        return test_fail

    def load_actor(self, path):
        test_fail = {}
        actorclass, _ = self.store.load_from_path(path)
        if actorclass:
            try:
                self.instantiate_actor(actorclass, path)
            except AssertionError as e:
                test_fail[path] = e.message
            except Exception as e:
                raise e
        else:
            self.illegal_actors[path] = "Unknown actor - probably parsing issues"
        return test_fail

    def test_actor(self, actor, aut):
        for idx in range(len(aut.test_set)):
            test_index = idx + 1
            test = aut.test_set[idx]
            setups = test.get('setup', [])
            inputs = test.get('inports', {})
            outputs = test.get('outports', {})
            postconds = test.get('postcond', [])

            for f in setups:
                try:
                    f(aut)
                except Exception as e:
                    print "Actor %s failed during setup of test %d: %s" % (actor, test_index, e.message)
                    raise Exception("Failed during setup of test %d" % (test_index, ))

            for port, values in inputs.iteritems():
                pwrite(aut, port, values)

            self.test_sys.verify_read_write_during_init(aut, actor)
            self.test_sys.init_done(actor)

            sched = scheduler.BaseScheduler(None, None)
            sched._fire_actor(aut)

            for port, values in outputs.iteritems():
                try:
                    vals = pread(aut, port, len(values))
                    if type(values) is set:
                        # disregard order
                        assert set(vals) == values, "Expected output set '%s' does not match '%s'" % (set(vals), values)
                    else:
                        assert vals == values, "Expected output '%s' does not match '%s'" % (vals, values)
                except AssertionError as e:
                    print "Error:", str(e)
                    raise AssertionError("Failed test %d" % (test_index,))

            if not all(f(aut) for f in postconds):
                raise AssertionError("Failed post condition of test %d" % (test_index, ))

        return True

    def test_actors(self):
        test_pass = []
        test_fail = {}
        no_test = []

        for actor in self.actors:
            aut = self.actors[actor]
            if aut == "no_test":
                no_test.append(actor)
                continue
            try:
                self.test_actor(actor, aut)
                test_pass.append(actor)
            except AssertionError as e:
                test_fail[actor] = e.message
            except Exception as e:
                self.illegal_actors[actor] = str(e) + '\n' + ''.join(
                    traceback.format_exception(sys.exc_type, sys.exc_value, sys.exc_traceback))

        return {'pass': test_pass, 'fail': test_fail, 'skipped': no_test,
                'errors': self.illegal_actors, 'components': self.components}