Пример #1
0
    def setUp(self):
        self.p = Process('process1', SyncFactory('threading'))

        self.p1, self.c1 = self.makeChildBlock('child1')
        self.p2, self.c2 = self.makeChildBlock('child2')
        self.p3, self.c3 = self.makeChildBlock('child3')

        # create a root block for the child blocks to reside in
        parts = [self.p1, self.p2, self.p3]
        params = RunnableController.MethodMeta.prepare_input_map(
            mri='mainBlock')
        self.c = RunnableController(self.p, parts, params)
        self.b = self.c.block

        params = ChildPart.MethodMeta.prepare_input_map(
            mri='mainBlock', name='mainPart')
        self.part = ChildPart(self.p, params)

        # Get the parent block into idle state
        self.p.start()

        # wait until block is Ready
        task = Task("block_ready_task", self.p)
        task.when_matches(self.c.block["state"], sm.IDLE, timeout=1)

        self.checkState(sm.IDLE)
Пример #2
0
 def _call_do_run(self):
     hook = self.Run
     while True:
         try:
             self.do_run(hook)
         except AbortedError:
             # Work out if it was an abort or pause
             state = self.state.value
             self.log_debug("Do run got AbortedError from %s", state)
             if state in (sm.SEEKING, sm.PAUSED):
                 # Wait to be restarted
                 task = Task("StateWaiter", self.process)
                 bad_states = [sm.DISABLING, sm.ABORTING, sm.FAULT]
                 try:
                     task.when_matches(self.state, sm.RUNNING, bad_states)
                 except BadValueError:
                     # raise AbortedError so we don't try to transition
                     raise AbortedError()
                 # Restart it
                 hook = self.Resume
                 self.status.set_value("Run resumed")
             else:
                 # just drop out
                 raise
         else:
             return
Пример #3
0
    def setUp(self):
        self.p = Process('process1', SyncFactory('threading'))

        # create a child ManagerController block
        params = ManagerController.MethodMeta. \
            prepare_input_map(mri='childBlock', configDir="/tmp")
        self.c_child = ManagerController(self.p, [], params)
        self.b_child = self.c_child.block

        self.sm = self.c_child.stateMachine

        params = Part.MethodMeta.prepare_input_map(name='part1')
        part1 = Part(self.p, params)
        params = {'name': 'part2', 'mri': 'childBlock'}
        params = ChildPart.MethodMeta.prepare_input_map(**params)
        part2 = ChildPart(self.p, params)

        # create a root block for the ManagerController block to reside in
        parts = [part1, part2]
        params = ManagerController.MethodMeta.prepare_input_map(
            mri='mainBlock', configDir="/tmp")
        self.c = ManagerController(self.p, parts, params)
        self.b = self.c.block

        # check that do_initial_reset works asynchronously
        self.p.start()

        # wait until block is Ready
        task = Task("block_ready_task", self.p)
        task.when_matches(self.b["state"], self.sm.READY, timeout=1)

        self.checkState(self.sm.READY)
Пример #4
0
 def test_server_hello_with_malcolm_client(self):
     block2 = self.process2.make_client_block("hello")
     task = Task("task", self.process2)
     futures = task.when_matches_async(block2["state"], "Ready")
     task.wait_all(futures, timeout=1)
     ret = block2.greet("me2")
     self.assertEqual(ret, dict(greeting="Hello me2"))
 def test_server_hello_with_malcolm_client(self):
     block2 = ClientController('hello', self.process2).block
     task = Task("task", self.process2)
     futures = task.when_matches(block2["state"], "Ready")
     task.wait_all(futures, timeout=1)
     ret = block2.say_hello("me2")
     self.assertEqual(ret, dict(greeting="Hello me2"))
Пример #6
0
    def setUp(self):
        self.p = Process('process1', SyncFactory('threading'))

        self.p1, self.c1 = self.makeChildBlock('child1')
        self.p2, self.c2 = self.makeChildBlock('child2')
        self.p3, self.c3 = self.makeChildBlock('child3')

        # create a root block for the child blocks to reside in
        parts = [self.p1, self.p2, self.p3]
        params = RunnableController.MethodMeta.prepare_input_map(
            mri='mainBlock', configDir="/tmp")
        self.c = RunnableController(self.p, parts, params)
        self.b = self.c.block

        params = ChildPart.MethodMeta.prepare_input_map(mri='mainBlock',
                                                        name='mainPart')
        self.part = ChildPart(self.p, params)

        # Get the parent block into idle state
        self.p.start()

        # wait until block is Ready
        task = Task("block_ready_task", self.p)
        task.when_matches(self.c.block["state"], sm.IDLE, timeout=1)

        self.checkState(sm.IDLE)
Пример #7
0
 def _call_do_run(self):
     hook = self.Run
     while True:
         try:
             self.do_run(hook)
         except AbortedError:
             # Work out if it was an abort or pause
             state = self.state.value
             self.log_debug("Do run got AbortedError from %s", state)
             if state in (sm.SEEKING, sm.PAUSED):
                 # Wait to be restarted
                 task = Task("StateWaiter", self.process)
                 bad_states = [sm.DISABLING, sm.ABORTING, sm.FAULT]
                 try:
                     task.when_matches(self.state, sm.RUNNING, bad_states)
                 except BadValueError:
                     # raise AbortedError so we don't try to transition
                     raise AbortedError()
                 # Restart it
                 hook = self.Resume
                 self.status.set_value("Run resumed")
             else:
                 # just drop out
                 raise
         else:
             return
 def test_server_hello_with_malcolm_client(self):
     block2 = self.process2.make_client_block("hello")
     task = Task("task", self.process2)
     futures = task.when_matches_async(block2["state"], "Ready")
     task.wait_all(futures, timeout=1)
     ret = block2.greet("me2")
     self.assertEqual(ret, dict(greeting="Hello me2"))
Пример #9
0
    def setUp(self):
        self.maxDiff = 5000

        self.p = Process('process1', SyncFactory('threading'))

        # Make a ticker block to act as our child
        params = Ticker.MethodMeta.prepare_input_map(mri="childBlock",
                                                     configDir="/tmp")
        self.b_child = Ticker(self.p, params)[-1]

        # Make an empty part for our parent
        params = Part.MethodMeta.prepare_input_map(name='part1')
        part1 = Part(self.p, params)

        # Make a RunnableChildPart to control the ticker
        params = RunnableChildPart.MethodMeta.prepare_input_map(
            mri='childBlock', name='part2')
        part2 = RunnableChildPart(self.p, params)

        # create a root block for the RunnableController block to reside in
        params = RunnableController.MethodMeta.prepare_input_map(
            mri='mainBlock', configDir="/tmp")
        self.c = RunnableController(self.p, [part1, part2], params)
        self.b = self.c.block
        self.sm = self.c.stateMachine

        # start the process off
        self.p.start()

        # wait until block is Ready
        task = Task("block_ready_task", self.p)
        task.when_matches(self.b["state"], self.sm.IDLE, timeout=1)

        self.checkState(self.sm.IDLE)
    def setUp(self):
        self.p = Process("process1", SyncFactory("threading"))

        # create a child ManagerController block
        params = ManagerController.MethodMeta.prepare_input_map(mri="childBlock")
        self.c_child = ManagerController(self.p, [], params)
        self.b_child = self.c_child.block

        self.sm = self.c_child.stateMachine

        params = Part.MethodMeta.prepare_input_map(name="part1")
        part1 = Part(self.p, params)
        params = {"name": "part2", "mri": "childBlock"}
        params = ChildPart.MethodMeta.prepare_input_map(**params)
        part2 = ChildPart(self.p, params)

        # create a root block for the ManagerController block to reside in
        parts = [part1, part2]
        params = {"mri": "mainBlock"}
        params = ManagerController.MethodMeta.prepare_input_map(**params)
        self.c = ManagerController(self.p, parts, params)
        self.b = self.c.block

        # check that do_initial_reset works asynchronously
        self.p.start()

        # wait until block is Ready
        task = Task("block_ready_task", self.p)
        task.when_matches(self.b["state"], self.sm.READY, timeout=1)

        self.checkState(self.sm.READY)
    def setUp(self):
        self.maxDiff = 5000

        self.p = Process('process1', SyncFactory('threading'))

        # Make a ticker block to act as our child
        params = Ticker.MethodMeta.prepare_input_map(mri="childBlock")
        self.b_child = Ticker(self.p, params)[-1]

        # Make an empty part for our parent
        params = Part.MethodMeta.prepare_input_map(name='part1')
        part1 = Part(self.p, params)

        # Make a RunnableChildPart to control the ticker
        params = RunnableChildPart.MethodMeta.prepare_input_map(
            mri='childBlock', name='part2')
        part2 = RunnableChildPart(self.p, params)

        # create a root block for the RunnableController block to reside in
        params = RunnableController.MethodMeta.prepare_input_map(
            mri='mainBlock')
        self.c = RunnableController(self.p, [part1, part2], params)
        self.b = self.c.block
        self.sm = self.c.stateMachine

        # start the process off
        self.p.start()

        # wait until block is Ready
        task = Task("block_ready_task", self.p)
        task.when_matches(self.b["state"], self.sm.IDLE, timeout=1)

        self.checkState(self.sm.IDLE)
 def test_server_counter_with_malcolm_client(self):
     block2 = self.process2.make_client_block("counter")
     task = Task("task", self.process2)
     futures = task.when_matches_async(block2["state"], "Ready")
     task.wait_all(futures, timeout=1)
     self.assertEqual(block2.counter, 0)
     block2.increment()
     self.assertEqual(block2.counter, 1)
Пример #13
0
 def test_server_counter_with_malcolm_client(self):
     block2 = self.process2.make_client_block("counter")
     task = Task("task", self.process2)
     futures = task.when_matches_async(block2["state"], "Ready")
     task.wait_all(futures, timeout=1)
     self.assertEqual(block2.counter, 0)
     block2.increment()
     self.assertEqual(block2.counter, 1)
 def test_server_counter_with_malcolm_client(self):
     block2 = ClientController('counter', self.process2).block
     task = Task("task", self.process2)
     futures = task.when_matches(block2["state"], "Ready")
     task.wait_all(futures, timeout=1)
     self.assertEqual(block2.counter, 0)
     block2.increment()
     self.assertEqual(block2.counter, 1)
Пример #15
0
    def test_sever_all_inports(self):
        self.c1.block.inportConnector = 'Connector'
        self.c2.block.inportConnector = 'Connector'
        self.c3.block.inportConnector = 'Connector3'

        task = Task("Task1", self.p)
        self.p1.sever_all_inports(task)
        task.wait_all([], 5)
        self.assertEqual(self.c1.block.inportConnector, '')
        self.assertEqual(self.c2.block.inportConnector, 'Connector')
        self.assertEqual(self.c3.block.inportConnector, 'Connector3')
Пример #16
0
    def test_sever_all_inports(self):
        self.c1.block.inportConnector = 'Connector'
        self.c2.block.inportConnector = 'Connector'
        self.c3.block.inportConnector = 'Connector3'

        task = Task("Task1" , self.p)
        self.p1.sever_all_inports(task)
        task.wait_all([],5)
        self.assertEqual(self.c1.block.inportConnector, '')
        self.assertEqual(self.c2.block.inportConnector, 'Connector')
        self.assertEqual(self.c3.block.inportConnector, 'Connector3')
Пример #17
0
    def test_sever_inports_connected_to(self):
        self.c1.block.inportConnector = 'Connector'

        self.assertEqual(self.c1.block.inportConnector, 'Connector')

        task = Task("Task1", self.p)
        out_port = {'Connector': 'pos'}
        self.p1.sever_inports_connected_to(task, out_port)
        self.assertEqual(self.c1.block.inportConnector, '')
 def _call_do_run(self):
     try:
         self.do_run()
     except StopIteration:
         # Work out if it was an abort or pause
         with self.lock:
             state = self.state.value
         self.log_debug("Do run got StopIteration from %s", state)
         if state in (sm.REWINDING, sm.PAUSED):
             # Wait to be restarted
             self.log_debug("Waiting for PreRun")
             task = Task("StateWaiter", self.process)
             futures = task.when_matches(
                 self.state, sm.PRERUN,
                 [sm.DISABLING, sm.ABORTING, sm.FAULT])
             task.wait_all(futures)
             # Restart it
             self.do_run()
         else:
             # just drop out
             self.log_debug("We were aborted")
             raise
Пример #19
0
from malcolm.core import SyncFactory, Process, Task
from malcolm.blocks.demo import SimulatorPMACManager
from scanpointgenerator import LineGenerator, CompoundGenerator, FixedDurationMutator

# Make the top level objects
sf = SyncFactory("Sync")
process = Process("Process", sf)

# Make the malcolm object
params = SimulatorPMACManager.MethodMeta.prepare_input_map(mriPrefix="TST-PMAC")
SimulatorPMACManager(process, params)
sim = process.get_block("TST-PMAC")

# Start the process
process.start()

# Wait for everything to settle down
task = Task("waiter", process)
task.when_matches(sim["state"], "Idle", timeout=10)

# Do a test
xs = LineGenerator("m1", "mm", -8.0, -12.0, 121, alternate_direction=True)
ys = LineGenerator("m2", "mm", -4.0, -6.0, 21)
gen = CompoundGenerator([ys, xs], [], [FixedDurationMutator(0.005)])
for i in range(1):
    sim.configure(gen)
    sim.run()

# process.stop()
Пример #20
0
from malcolm.blocks.demo import SimulatorPMACManager
from scanpointgenerator import LineGenerator, CompoundGenerator, \
    FixedDurationMutator

# Make the top level objects
sf = SyncFactory("Sync")
process = Process("Process", sf)

# Make the malcolm object
params = SimulatorPMACManager.MethodMeta.prepare_input_map(
    mriPrefix="TST-PMAC")
SimulatorPMACManager(process, params)
sim = process.get_block("TST-PMAC")

# Start the process
process.start()

# Wait for everything to settle down
task = Task("waiter", process)
task.when_matches(sim["state"], "Idle", timeout=10)

# Do a test
xs = LineGenerator("m1", "mm", -8., -12., 121, alternate_direction=True)
ys = LineGenerator("m2", "mm", -4., -6., 21)
gen = CompoundGenerator([ys, xs], [], [FixedDurationMutator(0.005)])
for i in range(1):
    sim.configure(gen)
    sim.run()

#process.stop()