def test_structManyInts_2x(self, dataWidth, randomize): t = structManyInts u = self.mySetUp(dataWidth, t, randomize) u.dataIn._ag.data.extend(packAxiSFrame( dataWidth, t.from_py(ref0_structManyInts))) u.dataIn._ag.data.extend(packAxiSFrame( dataWidth, t.from_py(ref1_structManyInts))) if randomize: # {DW: t} ts = { 15: 300, 16: 240, 32: 300, 51: 160, 64: 160, 128: 110, 512: 90, } t = ts[dataWidth] * CLK_PERIOD else: t = int(((8 * 64) / dataWidth) * 8 * CLK_PERIOD) self.runMatrixSim(t, dataWidth, randomize) for intf in u.dataOut._interfaces: n = intf._name d = [ref0_structManyInts[n], ref1_structManyInts[n]] self.assertValSequenceEqual(intf._ag.data, d, n)
def test_structManyInts_2x(self, dataWidth, randomize): t = structManyInts u = self.mySetUp(dataWidth, t, randomize) u.dataIn._ag.data.extend(packAxiSFrame(dataWidth, t.fromPy(reference0))) u.dataIn._ag.data.extend(packAxiSFrame(dataWidth, t.fromPy(reference1))) t = ((8 * 64) / dataWidth) * 80 * Time.ns if randomize: # {DW: t} ts = { 15: 300, 16: 240, 32: 300, 51: 160, 64: 160, 128: 110, 512: 90, } t = ts[dataWidth] * 10 * Time.ns self.runMatrixSim(t, dataWidth, randomize) for intf in u.dataOut._interfaces: n = intf._name d = [reference0[n], reference1[n]] self.assertValSequenceEqual(intf._ag.data, d, n)
def test_simpleUnion(self, dataWidth, randomize): t = unionSimple u = self.mySetUp(dataWidth, t, randomize) for d in [ref_unionSimple0, ref_unionSimple2, ref_unionSimple1, ref_unionSimple3]: u.dataIn._ag.data.extend(packAxiSFrame(dataWidth, t.from_py(d))) u.dataOut._select._ag.data.extend([0, 1, 0, 1]) t = 300 * Time.ns if randomize: # {DW: t} ts = { 15: 80, 16: 55, 32: 85, 51: 45, 64: 70, 128: 20, 512: 65, } t = ts[dataWidth] * 2 * CLK_PERIOD self.runMatrixSim(t, dataWidth, randomize) for i in [u.dataOut.a, u.dataOut.b]: if i._name == "a": v0 = ref_unionSimple0[1] v1 = ref_unionSimple1[1] else: v0 = ref_unionSimple2[1] v1 = ref_unionSimple3[1] self.assertValSequenceEqual(i._ag.data, [v0, v1], i._name)
def test_packAxiSFrame(self): t = structManyInts for DW in TEST_DW: d1 = t.from_py(ref0_structManyInts) f = list(packAxiSFrame(DW, d1)) d2 = unpackAxiSFrame(t, f, lambda x: x[0]) for k in ref0_structManyInts.keys(): self.assertEqual(getattr(d1, k), getattr(d2, k), (DW, k))
def test_unionOfStructs_noSel(self, dataWidth, randomize): t = unionOfStructs u = self.mySetUp(dataWidth, t, randomize) for d in [ref_unionOfStructs0, ref_unionOfStructs2]: u.dataIn._ag.data.extend(packAxiSFrame(dataWidth, t.from_py(d))) t = 15 * CLK_PERIOD self.runMatrixSim(t, dataWidth, randomize) for i in [u.dataOut.frameA, u.dataOut.frameB]: for intf in i._interfaces: self.assertEmpty(intf._ag.data)
def test_single(self): u = self.u rx_frame_bytes = list(chain(REF_FRAME, REF_CRC)) t = uint8_t[len(rx_frame_bytes)] # :attention: strb signal is reinterpreted as a keep signal rx_data = packAxiSFrame(self.DW, t.from_py(rx_frame_bytes), withStrb=True) if u.USE_STRB: rx_data_for_agent = ((d, m, 0, last) for d, m, last in rx_data) else: rx_data_for_agent = ((d, 0, last) for d, _, last in rx_data) u.phy_rx._ag.data.extend(rx_data_for_agent) self.runSim(CLK_PERIOD * (2 * len(u.phy_rx._ag.data) + 10)) o, f = axis_recieve_bytes(u.eth.rx) self.assertEqual(o, 0) self.assertValSequenceEqual(f, REF_FRAME) self.assertEmpty(u.eth.rx._ag.data)
def test_reply1x(self): u = self.u f = self.create_ICMP_echo_frame() u.rx._ag.data.extend(packAxiSFrame(self.DATA_WIDTH, f, withStrb=False)) u.myIp._ag.data.append( int.from_bytes(socket.inet_aton("192.168.0.2"), byteorder="little")) self.runSim(50 * CLK_PERIOD) res = unpackAxiSFrame(echoFrame_t, u.tx._ag.data) model_res = pingResponder_model(f) _res = iterBits(res, bitsInOne=8, skipPadding=False) _res = bytes(map(valToInt, _res)) # print("") # print("f", f) # print("res", res) # print("model_res", HdlValue_unpack(echoFrame_t, model_res, dataWidth=8)) self.assertEqual(_res, model_res)
def test_const_size_stream(self, dataWidth, frame_len, randomize): T = HStruct( (HStream(Bits(8), frame_len=frame_len), "frame0"), (uint16_t, "footer"), ) u = self.mySetUp(dataWidth, T, randomize, use_strb=True) u.dataIn._ag.data.extend( packAxiSFrame(dataWidth, T.from_py({"frame0": [i + 1 for i in range(frame_len)], "footer": 2}), withStrb=True, ) ) t = 20 if randomize: t *= 3 self.runMatrixSim2(t, dataWidth, frame_len, randomize) off, f = axis_recieve_bytes(u.dataOut.frame0) self.assertEqual(off, 0) self.assertValSequenceEqual(f, [i + 1 for i in range(frame_len)]) self.assertValSequenceEqual(u.dataOut.footer._ag.data, [2])
def test_unionOfStructs(self, dataWidth, randomize): t = unionOfStructs u = self.mySetUp(dataWidth, t, randomize) for d in [ reference_unionOfStructs0, reference_unionOfStructs2, reference_unionOfStructs1, reference_unionOfStructs3 ]: u.dataIn._ag.data.extend(packAxiSFrame(dataWidth, t.fromPy(d))) u.dataOut._select._ag.data.extend([0, 1, 0, 1]) t = 500 * Time.ns if randomize: # {DW: t} ts = { 15: 200, 16: 280, 32: 200, 51: 90, 64: 100, 128: 130, 512: 50, } t = ts[dataWidth] * 10 * Time.ns self.runMatrixSim(t, dataWidth, randomize) for i in [u.dataOut.frameA, u.dataOut.frameB]: if i._name == "frameA": v0 = reference_unionOfStructs0[1] v1 = reference_unionOfStructs1[1] else: v0 = reference_unionOfStructs2[1] v1 = reference_unionOfStructs3[1] for intf in i._interfaces: n = intf._name vals = v0[n], v1[n] self.assertValSequenceEqual(intf._ag.data, vals, (i._name, n))
def test_stream_and_footer(self, dataWidth, frame_len, prefix_suffix_as_padding, randomize): """ :note: Footer separation is tested in AxiS_footerSplitTC and this test only check that the AxiS_frameParser can connect wires correctly """ prefix_padding, suffix_padding = prefix_suffix_as_padding T = HStruct( (HStream(Bits(8)), "frame0"), (uint16_t, "footer"), ) fieldsToUse = set() if not prefix_padding: fieldsToUse.add("frame0") if not suffix_padding: fieldsToUse.add("footer") _T = HdlType_select(T, fieldsToUse) u = self.mySetUp(dataWidth, _T, randomize, use_strb=True) v = T.from_py({ "frame0": [i + 1 for i in range(frame_len)], "footer": frame_len + 1 }) u.dataIn._ag.data.extend( packAxiSFrame(dataWidth, v, withStrb=True) ) t = 20 if randomize: t *= 3 self.runMatrixSim2(t, dataWidth, frame_len, randomize) if not prefix_padding: off, f = axis_recieve_bytes(u.dataOut.frame0) self.assertEqual(off, 0) self.assertValSequenceEqual(f, [i + 1 for i in range(frame_len)]) if not suffix_padding: self.assertValSequenceEqual(u.dataOut.footer._ag.data, [frame_len + 1])