def test_singleLong(self): u = self.u req = u.driver._ag.req aw = u.a._ag.data wIn = u.driver.w._ag w = u.w._ag.data b = u.b._ag.data # download one word from addr 0xff req.data.append(mkReq(0xff, self.LEN_MAX)) for i in range(self.LEN_MAX + 1 + 10): wIn.data.append((100 + 1, mask(8), i == self.LEN_MAX)) b.append((0, RESP_OKAY)) self.runSim((10 + self.LEN_MAX) * 10 * Time.ns) self.assertValSequenceEqual(aw, [ self.aTrans( id_=0, addr=0xff, len_=self.LEN_MAX) ]) self.assertEqual(len(w), self.LEN_MAX + 1) self.assertEmpty(b) self.assertEqual(len(u.driver._ag.ack.data), 1)
def test_multiple_randomized(self): u = self.u req = u.driver._ag.req aw = u.a._ag.data wIn = u.driver.w._ag w = u.w._ag.data b = u.b._ag.data N = 50 # download one word from addr 0xff for i in range(N): req.data.append(mkReq((i * 8) + 0xff, 0)) wIn.data.append((77, mask(64 // 8 - 1), 1)) b.append((0, RESP_OKAY)) ra = self.randomize ra(u.a) ra(u.b) ra(u.driver.req) ra(u.driver.ack) ra(u.w) ra(u.driver.w) self.runSim(N * 8 * 10 * Time.ns) self.assertValSequenceEqual(aw, [ self.aTrans(id_=0, addr=0xff + (8 * i), len_=0) for i in range(N) ]) self.assertEqual(len(w), N) self.assertEmpty(b) self.assertEqual(len(u.driver._ag.ack.data), N)
def test_multiple_randomized(self): u = self.u req = u.driver._ag.req aw = u.a._ag.data wIn = u.driver.w._ag w = u.w._ag.data b = u.b._ag.data N = 50 # download one word from addr 0xff for i in range(N): req.data.append(mkReq((i * 8) + 0xff, 0)) wIn.data.append((77, mask(64 // 8 - 1), 1)) b.append((0, RESP_OKAY)) ra = self.randomize ra(u.a) ra(u.b) ra(u.driver.req) ra(u.driver.ack) ra(u.w) ra(u.driver.w) self.runSim(N * 8 * 10 * Time.ns) self.assertValSequenceEqual(aw, [ self.aTrans( id_=0, addr=0xff + (8 * i), len_=0) for i in range(N) ]) self.assertEqual(len(w), N) self.assertEmpty(b) self.assertEqual(len(u.driver._ag.ack.data), N)
def test_simple(self): u = self.u req = u.driver._ag.req aw = u.a._ag.data # download one word from addr 0xff req.data.append(mkReq(0xff, 0)) self.runSim(200 * Time.ns) self.assertValSequenceEqual(aw, [self.aTrans(0, 255, 0)]) self.assertEmpty(u.w._ag.data)
def test_3x128(self, N=128): u = self.u m = Axi3DenseMem(u.clk, axiAW=u.aw, axiW=u.w, axiB=u.b) _mask = mask(self.DATA_WIDTH // 8) data = [[self._rand.getrandbits(self.DATA_WIDTH) for _ in range(N)] for _ in range(self.DRIVER_CNT)] dataAddress = [ m.malloc(N * self.DATA_WIDTH // 8) for _ in range(self.DRIVER_CNT) ] for di, _data in enumerate(data): req = u.drivers[di].req._ag wIn = u.drivers[di].w._ag dataIt = iter(_data) addr = dataAddress[di] end = False while True: frameSize = self._rand.getrandbits(4) + 1 frame = [] try: for _ in range(frameSize): frame.append(next(dataIt)) except StopIteration: end = True if frame: req.data.append(mkReq(addr, len(frame) - 1)) wIn.data.extend([(d, _mask, i == len(frame) - 1) for i, d in enumerate(frame)]) addr += len(frame) * self.DATA_WIDTH // 8 if end: break r = self.randomize for d in u.drivers: r(d.req) r(d.w) r(d.ack) r(u.aw) r(u.w) r(u.b) self.runSim(self.DRIVER_CNT * N * 40 * Time.ns) for i, baseAddr in enumerate(dataAddress): inMem = m.getArray(baseAddr, self.DATA_WIDTH // 8, N) self.assertValSequenceEqual(inMem, data[i], "driver:%d" % i)
def test_3x128(self): u = self.u m = DenseMemory(self.DATA_WIDTH, u.clk, wDatapumpIntf=u.wDatapump) N = 128 _mask = mask(self.DATA_WIDTH // 8) data = [[self._rand.getrandbits(self.DATA_WIDTH) for _ in range(N)] for _ in range(self.DRIVER_CNT)] dataAddress = [m.malloc(N * self.DATA_WIDTH // 8) for _ in range(self.DRIVER_CNT)] for di, _data in enumerate(data): req = u.drivers[di].req._ag wIn = u.drivers[di].w._ag dataIt = iter(_data) addr = dataAddress[di] end = False while True: frameSize = self._rand.getrandbits(4) + 1 frame = [] try: for _ in range(frameSize): frame.append(next(dataIt)) except StopIteration: end = True if frame: req.data.append(mkReq(addr, len(frame) - 1)) wIn.data.extend([(d, _mask, i == len(frame) - 1) for i, d in enumerate(frame)]) addr += len(frame) * self.DATA_WIDTH // 8 if end: break ra = self.randomize for d in u.drivers: ra(d.req) ra(d.w) ra(d.ack) ra(u.wDatapump.req) ra(u.wDatapump.w) ra(u.wDatapump.ack) self.runSim(self.DRIVER_CNT * N * 50 * Time.ns) for i, baseAddr in enumerate(dataAddress): inMem = m.getArray(baseAddr, self.DATA_WIDTH // 8, N) self.assertValSequenceEqual(inMem, data[i], "driver:%d" % i)
def test_multiple_randomized2(self): u = self.u req = u.driver._ag.req aw = u.a._ag.data wIn = u.driver.w._ag w = u.w._ag.data b = u.b._ag.data N = 50 L = 3 expectedWData = [] # download one word from addr 0xff for i in range(N): req.data.append(mkReq((i * 8) + 0xff, L - 1)) for i in range(L): d = 77 + i m = mask(64 // 8 - 1) last = int(i == (L - 1)) wIn.data.append((d, m, last)) beat = self.wTrans(d, last, strb=m, id_=0) expectedWData.append(beat) b.append((0, RESP_OKAY)) ra = self.randomize ra(u.a) ra(u.b) ra(u.driver.req) ra(u.driver.ack) ra(u.w) ra(u.driver.w) self.runSim(N * L * 10 * 5 * Time.ns) self.assertValSequenceEqual(aw, [ self.aTrans( id_=0, addr=0xff + (8 * i), len_=L - 1) for i in range(N) ]) self.assertEqual(len(w), N * 3) for expWD, wd in zip(expectedWData, w): self.assertValSequenceEqual(wd, expWD) self.assertEqual(len(b), 0) self.assertEqual(len(u.driver._ag.ack.data), N)
def test_simple(self): u = self.u req = u.driver._ag.req aw = u.a._ag.data # download one word from addr 0xff req.data.append(mkReq(0xff, 0)) self.runSim(200 * Time.ns) self.assertValSequenceEqual(aw, [ self.aTrans(0, 255, 0) ]) self.assertEmpty(u.w._ag.data)
def test_multiple_randomized2(self): u = self.u req = u.driver._ag.req aw = u.a._ag.data wIn = u.driver.w._ag w = u.w._ag.data b = u.b._ag.data N = 50 L = 3 expectedWData = [] # download one word from addr 0xff for i in range(N): req.data.append(mkReq((i * 8) + 0xff, L - 1)) for i in range(L): d = 77 + i m = mask(64 // 8 - 1) last = int(i == (L - 1)) wIn.data.append((d, m, last)) beat = self.wTrans(d, last, strb=m, id_=0) expectedWData.append(beat) b.append((0, RESP_OKAY)) ra = self.randomize ra(u.a) ra(u.b) ra(u.driver.req) ra(u.driver.ack) ra(u.w) ra(u.driver.w) self.runSim(N * L * 10 * 5 * Time.ns) self.assertValSequenceEqual(aw, [ self.aTrans(id_=0, addr=0xff + (8 * i), len_=L - 1) for i in range(N) ]) self.assertEqual(len(w), N * 3) for expWD, wd in zip(expectedWData, w): self.assertValSequenceEqual(wd, expWD) self.assertEqual(len(b), 0) self.assertEqual(len(u.driver._ag.ack.data), N)
def test_1024random(self): u = self.u req = u.driver._ag.req wIn = u.driver.w._ag dataMask = mask(self.DATA_WIDTH // 8) m = Axi3DenseMem(u.clk, axiAW=u.a, axiW=u.w, axiB=u.b) N = 1024 data = [self._rand.getrandbits(self.DATA_WIDTH) for _ in range(N)] buff = m.malloc(N * (self.DATA_WIDTH // 8)) dataIt = iter(data) end = False addr = 0 while True: frameSize = self._rand.getrandbits(self.LEN_MAX.bit_length()) + 1 frame = [] try: for _ in range(frameSize): frame.append(next(dataIt)) except StopIteration: end = True if frame: req.data.append(mkReq(addr, len(frame) - 1)) wIn.data.extend([(d, dataMask, i == len(frame) - 1) for i, d in enumerate(frame)]) addr += len(frame) * self.DATA_WIDTH // 8 if end: break ra = self.randomize ra(u.a) ra(u.b) ra(u.driver.req) ra(u.driver.ack) ra(u.w) ra(u.driver.w) self.runSim(N * 50 * Time.ns) inMem = m.getArray(buff, self.DATA_WIDTH // 8, N) self.assertValSequenceEqual(inMem, data)
def test_simpleWithData(self): u = self.u req = u.driver._ag.req aw = u.a._ag.data wIn = u.driver.w._ag w = u.w._ag.data b = u.b._ag.data # download one word from addr 0xff req.data.append(mkReq(0xff, 0)) wIn.data.append((77, mask(64 // 8), 1)) b.append((0, RESP_OKAY)) self.runSim(200 * Time.ns) self.assertValSequenceEqual(aw, [self.aTrans(0, 255, 0)]) self.assertValSequenceEqual( w, [self.wTrans(77, 1, strb=mask(64 // 8), id_=0)]) self.assertEmpty(b)
def test_simpleWithData(self): u = self.u req = u.driver._ag.req aw = u.a._ag.data wIn = u.driver.w._ag w = u.w._ag.data b = u.b._ag.data # download one word from addr 0xff req.data.append(mkReq(0xff, 0)) wIn.data.append((77, mask(64 // 8), 1)) b.append((0, RESP_OKAY)) self.runSim(200 * Time.ns) self.assertValSequenceEqual(aw, [ self.aTrans(0, 255, 0) ]) self.assertValSequenceEqual( w, [self.wTrans(77, 1, strb=mask(64 // 8), id_=0)]) self.assertEmpty(b)
def test_singleLong(self): u = self.u req = u.driver._ag.req aw = u.a._ag.data wIn = u.driver.w._ag w = u.w._ag.data b = u.b._ag.data # download one word from addr 0xff req.data.append(mkReq(0xff, self.LEN_MAX)) for i in range(self.LEN_MAX + 1 + 10): wIn.data.append((100 + 1, mask(8), i == self.LEN_MAX)) b.append((0, RESP_OKAY)) self.runSim((10 + self.LEN_MAX) * 10 * Time.ns) self.assertValSequenceEqual( aw, [self.aTrans(id_=0, addr=0xff, len_=self.LEN_MAX)]) self.assertEqual(len(w), self.LEN_MAX + 1) self.assertEmpty(b) self.assertEqual(len(u.driver._ag.ack.data), 1)