def test1_trans_topology_a(): ao = ActiveObject() ao.start_at(outer) pp(ao.spy_full()) assert (ao.spy_full() == [ 'START', 'SEARCH_FOR_SUPER_SIGNAL:outer', 'ENTRY_SIGNAL:outer', 'INIT_SIGNAL:outer', '<- Queued:(0) Deferred:(0)' ]) pp(ao.spy_full()) print(ao.trace()) event_w = Event(signal=signals.WaitComplete) ao.clear_trace() ao.post_fifo(event_w) import time time.sleep(0.1) pp(ao.spy_rtc()) print(ao.trace()) # clear the spy and the trace ao.clear_spy() ao.clear_trace() # post a number of events and see what happens event_wait_complete = Event(signal=signals.WaitComplete) event_reset_chart = Event(signal=signals.ResetChart) ao.post_fifo(event_wait_complete) ao.post_fifo(event_reset_chart) ao.post_fifo(event_wait_complete) ao.post_fifo(event_reset_chart) time.sleep(0.3) print(ao.trace()) pp(ao.spy_full())
def test_trace_testing(fabric_fixture): tazor = ActiveObject() tazor.start_at(arming) time.sleep(0.4) target_with_timestamp = tazor.trace() print(target_with_timestamp) other_with_timestamp = tazor.trace() with stripped(target_with_timestamp) as twt, \ stripped(other_with_timestamp) as owt: for target_item, other_item in zip(twt, owt): print(target_item) assert(target_item == other_item) with stripped('[2017-11-05 15:17:39.424492] [75c8c] e->BATTERY_CHARGE() armed->armed') as swt: assert(swt == '[75c8c] e->BATTERY_CHARGE() armed->armed') assert(tazor.state.fun.__name__ == 'armed')
def test_trace_testing(): tazor = ActiveObject() tazor.start_at(arming) time.sleep(0.4) target_with_timestamp = tazor.trace() print(target_with_timestamp) other_with_timestamp = tazor.trace() with stripped(target_with_timestamp) as twt, \ stripped(other_with_timestamp) as owt: for target_item, other_item in zip(twt, owt): print(target_item) assert (target_item == other_item) with stripped( '[2017-11-05 15:17:39.424492] [75c8c] e->BATTERY_CHARGE() armed->armed' ) as swt: assert (swt == '[75c8c] e->BATTERY_CHARGE() armed->armed') assert (tazor.state.fun.__name__ == 'armed')
def test1_trans_topology_a(): ao = ActiveObject() ao.start_at(outer) pp(ao.spy_full()) assert(ao.spy_full() == ['START', 'SEARCH_FOR_SUPER_SIGNAL:outer', 'ENTRY_SIGNAL:outer', 'INIT_SIGNAL:outer', '<- Queued:(0) Deferred:(0)'] ) pp(ao.spy_full()) print(ao.trace()) event_w = Event(signal=signals.WaitComplete) ao.clear_trace() ao.post_fifo(event_w) import time time.sleep(0.1) pp(ao.spy_rtc()) print(ao.trace()) # stop the threads ao.stop() # clear the spy and the trace ao.clear_spy() ao.clear_trace() # post a number of events and see what happens event_wait_complete = Event(signal=signals.WaitComplete) event_reset_chart = Event(signal=signals.ResetChart) ao.post_fifo(event_wait_complete) ao.post_fifo(event_reset_chart) ao.post_fifo(event_wait_complete) ao.post_fifo(event_reset_chart) time.sleep(0.3) print(ao.trace()) pp(ao.spy_full())
def test_tazor_example(): tazor = ActiveObject() tazor.start_at(arming) time.sleep(0.4) tazor.post_fifo(Event(signal=signals.TRIGGER_PULLED)) time.sleep(0.1) # if you don't wait it won't look like it is working assert (tazor.spy_full() == [ 'START', 'SEARCH_FOR_SUPER_SIGNAL:arming', 'SEARCH_FOR_SUPER_SIGNAL:tazor_operating', 'ENTRY_SIGNAL:tazor_operating', 'ENTRY_SIGNAL:arming', 'INIT_SIGNAL:arming', '<- Queued:(0) Deferred:(0)', 'BATTERY_CHARGE:arming', 'SEARCH_FOR_SUPER_SIGNAL:armed', 'ENTRY_SIGNAL:armed', 'POST_DEFERRED:CAPACITOR_CHARGE', 'INIT_SIGNAL:armed', '<- Queued:(0) Deferred:(1)', 'BATTERY_CHARGE:armed', 'BATTERY_CHARGE:arming', 'EXIT_SIGNAL:armed', 'SEARCH_FOR_SUPER_SIGNAL:armed', 'ENTRY_SIGNAL:armed', 'POST_DEFERRED:CAPACITOR_CHARGE', 'INIT_SIGNAL:armed', '<- Queued:(0) Deferred:(2)', 'BATTERY_CHARGE:armed', 'BATTERY_CHARGE:arming', 'EXIT_SIGNAL:armed', 'SEARCH_FOR_SUPER_SIGNAL:armed', 'ENTRY_SIGNAL:armed', 'POST_DEFERRED:CAPACITOR_CHARGE', 'INIT_SIGNAL:armed', '<- Queued:(0) Deferred:(3)', 'TRIGGER_PULLED:armed', 'TRIGGER_PULLED:arming', 'TRIGGER_PULLED:tazor_operating', 'RECALL:CAPACITOR_CHARGE', 'POST_FIFO:CAPACITOR_CHARGE', 'TRIGGER_PULLED:tazor_operating:HOOK', '<- Queued:(1) Deferred:(2)', 'CAPACITOR_CHARGE:armed', 'CAPACITOR_CHARGE:arming', 'CAPACITOR_CHARGE:tazor_operating', 'EXIT_SIGNAL:armed', 'EXIT_SIGNAL:arming', 'EXIT_SIGNAL:tazor_operating', 'ENTRY_SIGNAL:tazor_operating', 'RECALL:CAPACITOR_CHARGE', 'POST_FIFO:CAPACITOR_CHARGE', 'INIT_SIGNAL:tazor_operating', '<- Queued:(1) Deferred:(1)', 'CAPACITOR_CHARGE:tazor_operating', 'EXIT_SIGNAL:tazor_operating', 'ENTRY_SIGNAL:tazor_operating', 'RECALL:CAPACITOR_CHARGE', 'POST_FIFO:CAPACITOR_CHARGE', 'INIT_SIGNAL:tazor_operating', '<- Queued:(1) Deferred:(0)', 'CAPACITOR_CHARGE:tazor_operating', 'EXIT_SIGNAL:tazor_operating', 'ENTRY_SIGNAL:tazor_operating', 'INIT_SIGNAL:tazor_operating', '<- Queued:(0) Deferred:(0)' ]) print(tazor.trace())
def test_tazor_example(fabric_fixture): tazor = ActiveObject() tazor.start_at(arming) time.sleep(0.4) tazor.post_fifo(Event(signal=signals.TRIGGER_PULLED)) time.sleep(0.1) # if you don't wait it won't look like it is working assert(tazor.spy_full() == ['START', 'SEARCH_FOR_SUPER_SIGNAL:arming', 'SEARCH_FOR_SUPER_SIGNAL:tazor_operating', 'ENTRY_SIGNAL:tazor_operating', 'ENTRY_SIGNAL:arming', 'INIT_SIGNAL:arming', '<- Queued:(0) Deferred:(0)', 'BATTERY_CHARGE:arming', 'SEARCH_FOR_SUPER_SIGNAL:armed', 'ENTRY_SIGNAL:armed', 'POST_DEFERRED:CAPACITOR_CHARGE', 'INIT_SIGNAL:armed', '<- Queued:(0) Deferred:(1)', 'BATTERY_CHARGE:armed', 'BATTERY_CHARGE:arming', 'EXIT_SIGNAL:armed', 'SEARCH_FOR_SUPER_SIGNAL:armed', 'ENTRY_SIGNAL:armed', 'POST_DEFERRED:CAPACITOR_CHARGE', 'INIT_SIGNAL:armed', '<- Queued:(0) Deferred:(2)', 'BATTERY_CHARGE:armed', 'BATTERY_CHARGE:arming', 'EXIT_SIGNAL:armed', 'SEARCH_FOR_SUPER_SIGNAL:armed', 'ENTRY_SIGNAL:armed', 'POST_DEFERRED:CAPACITOR_CHARGE', 'INIT_SIGNAL:armed', '<- Queued:(0) Deferred:(3)', 'TRIGGER_PULLED:armed', 'TRIGGER_PULLED:arming', 'TRIGGER_PULLED:tazor_operating', 'RECALL:CAPACITOR_CHARGE', 'POST_FIFO:CAPACITOR_CHARGE', 'TRIGGER_PULLED:tazor_operating:HOOK', '<- Queued:(1) Deferred:(2)', 'CAPACITOR_CHARGE:armed', 'CAPACITOR_CHARGE:arming', 'CAPACITOR_CHARGE:tazor_operating', 'EXIT_SIGNAL:armed', 'EXIT_SIGNAL:arming', 'EXIT_SIGNAL:tazor_operating', 'ENTRY_SIGNAL:tazor_operating', 'RECALL:CAPACITOR_CHARGE', 'POST_FIFO:CAPACITOR_CHARGE', 'INIT_SIGNAL:tazor_operating', '<- Queued:(1) Deferred:(1)', 'CAPACITOR_CHARGE:tazor_operating', 'EXIT_SIGNAL:tazor_operating', 'ENTRY_SIGNAL:tazor_operating', 'RECALL:CAPACITOR_CHARGE', 'POST_FIFO:CAPACITOR_CHARGE', 'INIT_SIGNAL:tazor_operating', '<- Queued:(1) Deferred:(0)', 'CAPACITOR_CHARGE:tazor_operating', 'EXIT_SIGNAL:tazor_operating', 'ENTRY_SIGNAL:tazor_operating', 'INIT_SIGNAL:tazor_operating', '<- Queued:(0) Deferred:(0)']) print(tazor.trace())
@spy_on def c2(chart, e): status = return_status.UNHANDLED if (e.signal == signals.ENTRY_SIGNAL): print("c2 entered") status = return_status.HANDLED elif (e.signal == signals.A): status = chart.trans(c1) else: chart.temp.fun = c status = return_status.SUPER return status if __name__ == "__main__": ao = ActiveObject('start_example') print("calling: start_at(c2)") ao.start_at(c2) time.sleep(0.2) print(ao.trace()) # print what happened from the start_at call ao.clear_trace() # clear our instrumentation print("sending B, then A, then A:") ao.post_fifo(Event(signal=signals.B)) ao.post_fifo(Event(signal=signals.A)) ao.post_fifo(Event(signal=signals.A)) time.sleep(0.2) print(ao.trace()) # print what happened