def test_neq_pure_const_diff(self): @dl.DeltaBlock() def baa(a: int) -> int: return 1 with dl.DeltaGraph() as g1: baa(baa(1)) with dl.DeltaGraph() as g2: baa(baa(2)) self.assertNotEqual(g1, g2)
def test_eq_func_and_const_graph(self): @dl.DeltaBlock() def baa(a: int) -> int: return 1 with dl.DeltaGraph() as g1: baa(baa(1)) with dl.DeltaGraph() as g2: baa(baa(1)) self.assertEqual(g1, g2)
def test_main(self): n_iter = 1000 s = dl.lib.StateSaver(int) gen = dl.lib.make_generator(1, reps=n_iter) @dl.DeltaBlock(allow_const=True) def return10_const() -> int: return 10 @dl.DeltaBlock(allow_const=False) def return10_non_const() -> int: return 10 @dl.DeltaBlock() def adder(a: dl.DOptional(int), b: int) -> int: if a is None: return b else: return a + b @dl.Interactive([('a', int)], int) def aggregator(node): result = 0 for _ in range(n_iter): a = node.receive('a') result += a node.send(result) # Case 1: const nodes always provide an input for optional ports with dl.DeltaGraph() as graph: total = adder(return10_const(), gen.call()) s.save_and_exit(aggregator.call(a=total)) dl.DeltaPySimulator(graph).run() self.assertEqual(s.saved[-1], 11 * n_iter) # Case 2: due to uncontrolled delays non-const nodes not always # provide an input for optional ports s.reset() gen = dl.lib.make_generator(1, reps=n_iter) with dl.DeltaGraph() as graph: total = adder(return10_non_const(), gen.call()) s.save_and_exit(aggregator.call(a=total)) dl.DeltaPySimulator(graph).run() self.assertLessEqual(s.saved[-1], 11 * n_iter)
def test_allow_top(self): """Top is allowed by default""" s = dl.lib.StateSaver() with dl.DeltaGraph() as graph: s.save_and_exit(return_1_const()) self.assertTrue(graph.check())
def test_const_selfloop(self): with dl.DeltaGraph() as graph: p = dl.placeholder_node_factory() p.specify_by_node(self.printer_1(p)) for node in graph.nodes: self.assertIsInstance(node.body, dl.wiring.PyFuncBody)
def test_neq_body_name_diff(self): @dl.DeltaBlock() def foo(a: int) -> int: return 1 @dl.DeltaBlock() def baa(a: int) -> int: return 1 with dl.DeltaGraph() as g1: baa(baa(1)) with dl.DeltaGraph() as g2: baa(foo(1)) self.assertNotEqual(g1, g2)
def test_exit_all_const_nodes(self): """Test that runtime runs correctly if all nodes are constant.""" with dl.DeltaGraph() as graph: self.const_save_exit(n=add(n1=1, n2=2)) with self.assertRaises(RuntimeError): dl.DeltaPySimulator(graph).run(100)
def generate_graph_interactive_input(verbose=False): """This function returns instead a cyclical graph: -> Checker -> one_shot_run -> HwResetShaper- | | -------------------------------------------- In this way we can assert and deassert the reset and verify that the migen code extend the reset signal for N clock cycles """ if verbose: lvl = logging.DEBUG else: lvl = logging.INFO with dl.DeltaGraph() as graph: ph = dl.placeholder_node_factory() oneshot = one_shot_run.call(status=ph) shaper = HwResetShaper(tb_num_iter=50, name='reset_shaper_one_shot', lvl=lvl, vcd_name='reset_shaper_one_shot.vcd') shaper_runner = shaper.call(pulse_in=oneshot) checker = LengthChecker(5, interactive=True).check_shape( shaper_runner.reset_out) ph.specify_by_node(checker) return (graph, shaper)
def test_Interactive(self): @dl.Interactive([('a', int)], dl.Void) def foo(node): print(node.receive("a")) with self.assertRaises(dl.data_types.DeltaIOError): with dl.DeltaGraph(): foo.call(a=foo.call(a=1))
def test_Interactive(self): @dl.Interactive([('a', int)], TwoIntsT) def foo(node): node.send(TwoInts(x=1, y=2)) with self.assertRaises(dl.data_types.DeltaIOError): with dl.DeltaGraph(): foo.call(a=foo.call(a=1).z)
def test_DeltaBlock(self): @dl.DeltaBlock() def foo(a: int) -> TwoIntsT: return TwoInts(x=1, y=2) with self.assertRaises(dl.data_types.DeltaIOError): with dl.DeltaGraph(): foo(foo(1).z)
def test_MigenNodeTemplate(self): class AMigenNode(dl.MigenNodeTemplate): def migen_body(self, template): template.add_pa_in_port('a', dl.DOptional(int)) with self.assertRaises(dl.data_types.DeltaIOError): with dl.DeltaGraph(): AMigenNode().call(a=AMigenNode().call(a=1))
def test_Interactive(self): @dl.Interactive(inputs=[('a', int)]) def foo(node): node.receive("a") with self.assertRaises(dl.data_types.DeltaIOError): with dl.DeltaGraph(): foo.call(b=1)
def test_DeltaBlock(self): @dl.DeltaBlock() def foo(a: int) -> dl.Void: print(a) with self.assertRaises(dl.data_types.DeltaIOError): with dl.DeltaGraph(): foo(foo(1))
def test_select_body_on_construction(self): """Test if single node bodies get their body auto-selected. Multi-body nodes do not undergo auto-selection. """ with dl.DeltaGraph() as graph: n = self.make_test_template().call(1, 2) self.check_executes_graph(graph, expect="func_1\n")
def test_no_allow_top(self): """Top is not allowed by if allow_top set to False""" s = dl.lib.StateSaver() with dl.DeltaGraph() as graph: s.save_and_exit(4) with self.assertRaises(DeltaTypeError): graph.check(allow_top=False)
def test_DeltaBlock(self): @dl.DeltaBlock(outputs=[('x', int), ('y', int)]) def foo(a: int): return 1, 2 with self.assertRaises(dl.data_types.DeltaIOError): with dl.DeltaGraph(): foo(foo(1).z)
def get_g2(): @dl.DeltaBlock() def foo(a: int) -> int: return 1 with dl.DeltaGraph() as g2: foo(foo(1)) return g2
def get_g1(): @dl.DeltaBlock() def foo(a: int) -> int: return 1 with dl.DeltaGraph() as g1: foo(1) return g1
def test_Interactive(self): @dl.Interactive([('a', int)], outputs=[('x', int), ('y', int)]) def foo(node): node.send(x=1, y=2) with self.assertRaises(dl.data_types.DeltaIOError): with dl.DeltaGraph(): foo.call(a=foo.call(a=1).z)
def test_non_forked(self): @dl.DeltaBlock() def baa(a: int) -> int: return 1 with self.assertRaises(dl.data_types.DeltaIOError): with dl.DeltaGraph(): baa(baa(1).z)
def test_splitting_non_const_non_const(self): """Non-const -> non-const -> exit.""" s = dl.lib.StateSaver(int, verbose=True) with dl.DeltaGraph() as graph: val = return_1_non_const() s.save_and_exit(add_non_const(val, val)) self.check_executes_graph(graph, "saving 2\n")
def test_exception_multi_specify_by_position_and_kwarg1(self): saver_x = dl.lib.StateSaver(int) with dl.DeltaGraph() as graph: i_send = multiple_specify_kwarg_position_first.call() saver_x.save_and_exit_if(i_send.x) self.check_executes_graph(graph, exception=RuntimeError)
def test_too_many_positional(self): ts = TripleStateSaver(1) with dl.DeltaGraph() as graph: i_send = too_many_positional.call() ts.multi_count_print_exit(i_send.x, i_send.y, i_send.z) self.check_executes_graph(graph, exception=RuntimeError)
def test_invalid_kwarg(self): ts = TripleStateSaver(1) with dl.DeltaGraph() as graph: i_send = invalid_kwarg.call() ts.multi_count_print_exit(i_send.x, i_send.y, i_send.z) self.check_executes_graph(graph, exception=RuntimeError)
def test_DeltaBlock(self): @dl.DeltaBlock() def foo(a: int): print(a) with dl.DeltaGraph(): node = foo(1) self.assertEqual(node.outputs, dl.Void)
def test_Interactive(self): @dl.Interactive([('a', int)], tags=['test_3']) def foo(node): print(node.receive("a")) with dl.DeltaGraph(): node = foo.call(a=1) self.assertIn('test_3', node.body.access_tags)
def test_DeltaBlock(self): @dl.DeltaBlock(allow_const=False, tags=['test_1']) def foo(a: int): print(a) with dl.DeltaGraph(): node = foo(1) self.assertIn('test_1', node.body.access_tags)
def test_PyMigenBody(self): s = dl.lib.StateSaver(int, verbose=True) with dl.DeltaGraph("test_migen_wiring") as graph: c1 = DUT1(name='counter1').call(i1=1000) c2 = DUT1(name='counter2').call(i1=c1.o1) s.save_and_exit(c2.o1) self.check_executes_graph(graph, "saving 10\n")
def setUp(self): self.inst = SomeClass() self.saver = dl.lib.StateSaver(int) with dl.DeltaGraph() as graph: method_node = self.inst.method() self.saver.save_and_exit(method_node) self.graph = graph self.method_node = graph.nodes[0]