def test_root_buffering(parser): """Make sure that nodes with two inputs where only one of the inputs is a root node gets an unbuffered node in between. Furthermore, check that after topographic sorting, the root nodes are all at the top.""" parser.parse_file(get_path(u'basic_root_buffering.sgf')) model = DeviceModel() parser.compile(model=model) sg = parser.sensor_graph log = sg.sensor_log for x in sg.dump_nodes(): print(x) assert len(sg.nodes) == 21 #This check is to ensure that all root (input) nodes at the beginning after sorting. root_node_section_passed = False for node in sg.nodes: if not root_node_section_passed: if 'input' not in str(node): root_node_section_passed = True else: assert 'input' not in str(node) # Now make sure it produces the right output output11 = log.create_walker(DataStreamSelector.FromString('output 11')) output12 = log.create_walker(DataStreamSelector.FromString('output 12')) output13 = log.create_walker(DataStreamSelector.FromString('output 13')) output14 = log.create_walker(DataStreamSelector.FromString('output 14')) output15 = log.create_walker(DataStreamSelector.FromString('output 15')) sg.load_constants() sim = SensorGraphSimulator(sg) sim.stop_condition('run_time 20 minutes') sim.stimulus("1 minute: input 1 = 1") sim.stimulus("1 minute: input 2 = 1") sim.stimulus("11 minute: input 1 = 2") sim.run() sg.load_constants() print([str(x) for x in log._last_values.keys()]) assert output11.count() == 2 assert output12.count() == 2 assert output13.count() == 2 assert output14.count() == 2 assert output15.count() == 1
def main(argv=None): """Main entry point for iotile sensorgraph simulator. This is the iotile-sgrun command line program. It takes an optional set of command line parameters to allow for testing. Args: argv (list of str): An optional set of command line parameters. If not passed, these are taken from sys.argv. """ if argv is None: argv = sys.argv[1:] try: executor = None parser = build_args() args = parser.parse_args(args=argv) model = DeviceModel() parser = SensorGraphFileParser() parser.parse_file(args.sensor_graph) parser.compile(model) if not args.disable_optimizer: opt = SensorGraphOptimizer() opt.optimize(parser.sensor_graph, model=model) graph = parser.sensor_graph sim = SensorGraphSimulator(graph) for stop in args.stop: sim.stop_condition(stop) for watch in args.watch: watch_sel = DataStreamSelector.FromString(watch) graph.sensor_log.watch(watch_sel, watch_printer) # If we are semihosting, create the appropriate executor connected to the device if args.semihost_device is not None: executor = SemihostedRPCExecutor(args.port, args.semihost_device) sim.rpc_executor = executor for mock in args.mock_rpc: slot, rpc_id, value = process_mock_rpc(mock) sim.rpc_executor.mock(slot, rpc_id, value) for stim in args.stimulus: sim.stimulus(stim) graph.load_constants() if args.trace is not None: sim.record_trace() try: if args.connected: sim.step(user_connected, 8) sim.run(accelerated=not args.realtime) except KeyboardInterrupt: pass if args.trace is not None: sim.trace.save(args.trace) finally: if executor is not None: executor.hw.close() return 0