def setUp(self): # obligatory and optional ports g = DeltaGraph() out_port_obl = OutPort( 'out', Int(), InPort(None, Int(), None, 0), RealNode(g, [], name='node_name'), ) out_port_opt = OutPort( 'out', Int(), InPort(None, Optional(Int()), None, 0), RealNode(g, [], name='node_name'), ) # 4 types of queues self.delta_queue_obl = DeltaQueue(out_port_obl) self.delta_queue_opt = DeltaQueue(out_port_opt) self.const_queue_obl = ConstQueue(out_port_obl) self.const_queue_opt = ConstQueue(out_port_opt) # test messages self.msg1 = QueueMessage(1) self.msg2 = QueueMessage(2) self.msg_with_none = QueueMessage(None) self.msg_unpackable = QueueMessage("abcde") # these messages should be received self.msg1_answer = QueueMessage(1) self.msg2_answer = QueueMessage(2) self.msg_with_none_answer = QueueMessage(None)
def test_out_port_capnp_wiring(self): """Generate wiring. Should just call same method in destination.""" in_port = Mock() out_port = OutPort(NamespacedName("node_name", None), as_delta_type(int), in_port, None) out_port.capnp_wiring([], None) in_port.capnp_wiring.assert_called_with([], None)
def setUp(self): # obligatory and optional ports out_port_obl = OutPort( NamespacedName("port_name", None), DInt(), InPort(NamespacedName("port_name", None), DInt(), None, 0), None ) out_port_opt = OutPort( NamespacedName("port_name", None), DInt(), InPort(NamespacedName("port_name", None), DOptional(DInt()), None, 0), None ) # 4 types of queues self.delta_queue_obl = DeltaQueue(out_port_obl) self.delta_queue_opt = DeltaQueue(out_port_opt) self.const_queue_obl = ConstQueue(out_port_obl) self.const_queue_opt = ConstQueue(out_port_opt) # test messages self.msg1 = QueueMessage(1) self.msg2 = QueueMessage(2) self.msg_with_none = QueueMessage(None) self.msg_unpackable = QueueMessage("abcde") # these messages should be received self.msg1_answer = QueueMessage(1) self.msg2_answer = QueueMessage(2) self.msg_with_none_answer = QueueMessage(None)
def test_out_port_capnp(self): """Generate out port.""" out_port = OutPort("index", as_delta_type(int), None, None) capnp_out_port = dotdf_capnp.OutPort.new_message() out_port.capnp(capnp_out_port) self.assertEqual(capnp_out_port.name, "index") self.assertEqual(dill.loads(capnp_out_port.type), as_delta_type(int)) with self.assertRaises(AttributeError): dummy = capnp_out_port.optional
def test_out_port_capnp_no_index(self): """Generate out port when index not provided. In this case, name should be empty string. """ out_port = OutPort(NamespacedName("node_name", None), as_delta_type(int), None, None) capnp_out_port = dotdf_capnp.OutPort.new_message() out_port.capnp(capnp_out_port) self.assertEqual(capnp_out_port.name, "") self.assertEqual(dill.loads(capnp_out_port.type), as_delta_type(int))
def test_neq_dest_diff(self): g1 = DeltaGraph() n1 = RealNode(g1, [], OrderedDict(), OrderedDict([('out_a', int)])) dest_n_1 = RealNode(g1, [], OrderedDict([('a', int)]), OrderedDict()) dest_1 = InPort('a', int, dest_n_1, 0) out_p_1 = OutPort('out_a', int, dest_1, n1) g2 = DeltaGraph() n2 = RealNode(g2, [], OrderedDict(), OrderedDict([('out_a', int)])) dest_n_2 = RealNode(g2, [], OrderedDict([('a', int)]), OrderedDict()) dest_2 = InPort('b', int, dest_n_2, 0) out_p_2 = OutPort('out_a', int, dest_2, n2) self.assertNotEqual(out_p_1, out_p_2)
def tb_pa_to_deltaqueue(pa): def transfer_pa_to_queue(pa, queue): """Emulates the movement of data from the PA to a DeltaQueue """ if not queue.full(): # read a single entry from the PA FIFO (the first entry) yield pa.rd_ready_in.eq(1) yield self.assertEqual((yield pa.rd_valid_out), 1) # write to the queue queue.put(QueueMessage((yield pa.rd_data_out))) yield pa.rd_ready_in.eq(0) yield # First create a DeltaQueue object # Hack: OutPort needs a "node" object with full_name attribute mock_parent_node = SimpleNamespace() mock_parent_node.full_name = "parent_node" in_port = InPort("in", dl.Int(), None, self.tb_buf_width) out_queue = DeltaQueue(OutPort("out", dl.Int(), in_port, mock_parent_node), maxsize=self.tb_buf_depth - 1) yield self.assertEqual((yield pa.rd_valid_out), 0) self.assertEqual((yield pa.wr_ready_out), 1) self.assertEqual((yield pa.rd_data_out), 0) yield pa.rd_ready_in.eq(0) # fill up PA FIFO so it has more items than max size of the DeltaQueue data = [] for i in range(self.tb_buf_depth): # generate random entry d = random.randint(0, pow(2, self.tb_buf_width)) data.append(d) # add entry to reference data for checking # write to the PA FIFO yield yield pa.wr_valid_in.eq(1) yield pa.wr_data_in.eq(d) yield yield pa.wr_valid_in.eq(0) yield # check PA FIFO is full self.assertEqual((yield pa.fifo.dout), data[0]) self.assertEqual((yield pa.fifo.we), 0) self.assertEqual((yield pa.almost_full), 1) self.assertEqual((yield pa.num_fifo_elements), self.tb_buf_depth) # fill up the DeltaQueue from the PA FIFO until its full for i in range(self.tb_buf_depth): yield from transfer_pa_to_queue(pa, out_queue) # check PA FIFO has been emptied except for 1 self.assertEqual((yield pa.almost_full), 0) self.assertEqual((yield pa.num_fifo_elements), 1) # check size of DeltaQueue self.assertEqual(out_queue.qsize(), self.tb_buf_depth - 1) # get a single item from the DeltaQueue self.assertEqual(out_queue.get().msg, data[0]) data.pop(0) # remove first entry from reference data # try and add remaining PA FIFO data to the DeltaQueue for i in range((yield pa.num_fifo_elements)): yield from transfer_pa_to_queue(pa, out_queue) # check PA FIFO has been emptied self.assertEqual((yield pa.almost_full), 0) self.assertEqual((yield pa.num_fifo_elements), 0) # check size of DeltaQueue self.assertEqual(out_queue.qsize(), self.tb_buf_depth - 1) # check the remaining data was moved into the DeltaQueue for i in range(out_queue.qsize()): self.assertEqual(out_queue.get().msg, data[i])
def tb_deltaqueue_to_pa(pa): def transfer_queue_to_pa(queue, pa): """Emulates the movement of data from the DeltaQueue to a PA """ if (yield pa.almost_full) != 1: # write to the PA FIFO yield yield pa.wr_valid_in.eq(1) yield pa.wr_data_in.eq(queue.get().msg) yield yield pa.wr_valid_in.eq(0) yield # First create a DeltaQueue object # Hack: OutPort needs a "node" object with full_name attribute mock_parent_node = SimpleNamespace() mock_parent_node.full_name = "parent_node" in_port = InPort("in", dl.Int(), None, self.tb_buf_width) in_queue = DeltaQueue(OutPort("out", dl.Int(), in_port, mock_parent_node), maxsize=self.tb_buf_depth + 1) # fill up the DeltaQueue so it has more items than the PA FIFO data = [] for i in range(self.tb_buf_depth + 1): # generate random entry d = random.randint(0, pow(2, self.tb_buf_width)) data.append(d) # add entry to reference data for checking in_queue.put(QueueMessage(d)) # check size of DeltaQueue self.assertEqual(in_queue.qsize(), self.tb_buf_depth + 1) # ensure PA is ready for consuming yield self.assertEqual((yield pa.rd_valid_out), 0) self.assertEqual((yield pa.wr_ready_out), 1) self.assertEqual((yield pa.rd_data_out), 0) yield pa.rd_ready_in.eq(0) # fill up the PA FIFO from the DeltaQueue until its full for i in range(in_queue.qsize()): yield from transfer_queue_to_pa(in_queue, pa) # check PA FIFO is full self.assertEqual((yield pa.fifo.dout), data[0]) self.assertEqual((yield pa.fifo.we), 0) self.assertEqual((yield pa.almost_full), 1) self.assertEqual((yield pa.num_fifo_elements), self.tb_buf_depth) # check size of DeltaQueue self.assertEqual(in_queue.qsize(), 1) # read a single entry from the PA FIFO (the first entry) yield pa.rd_ready_in.eq(1) yield self.assertEqual((yield pa.rd_valid_out), 1) self.assertEqual((yield pa.rd_data_out), data[0]) yield pa.rd_ready_in.eq(0) yield data.pop(0) # remove first entry from reference data # try and add remaining DeltaQueue data to the PA FIFO for i in range(in_queue.qsize()): if (yield pa.almost_full) != 1: yield from transfer_queue_to_pa(in_queue, pa) # check PA FIFO count hasn't changed self.assertEqual((yield pa.almost_full), 1) self.assertEqual((yield pa.num_fifo_elements), self.tb_buf_depth) # check size of DeltaQueue self.assertEqual(in_queue.qsize(), 0) # check original first entry in PA FIFO is gone and all others remain for d in data: yield pa.rd_ready_in.eq(1) yield self.assertEqual((yield pa.rd_data_out), d) yield pa.rd_ready_in.eq(0) yield
def test_DOptional(self): port = OutPort(NamespacedName("test_name", None), DOptional(DInt()), None, None) with self.assertRaises(TypeError): dummy = port.port_type
def test_non_DOptional(self): port = OutPort(NamespacedName("test_name", None), DInt(), None, None) self.assertEqual(port.port_type, DInt())
def test_Optional(self): port = OutPort(None, Optional(Int()), None, None) with self.assertRaises(TypeError): dummy = port.port_type
def test_non_Optional(self): port = OutPort(None, Int(), None, None) self.assertEqual(port.port_type, Int())