def test_randomized(self, N=24): u = self.u if u.AXI_CLS in (Axi3Lite, Axi4Lite): m = Axi4LiteSimRam(axi=u.axi) else: m = AxiSimRam(axi=u.axi) MAGIC = 99 self.randomize(u.driver.r) self.randomize(u.driver.req) self.randomize(u.axi.ar) self.randomize(u.axi.r) r_ref = [] for _ in range(N): size = int(self._rand.random() * self.LEN_MAX_VAL) + 1 data = [MAGIC + i2 for i2 in range(size)] a = m.calloc(size, u.DATA_WIDTH // 8, initValues=data) _, _r_ref = self.spotReadMemcpyTransactions(a, size - 1, None, data=data) r_ref.extend(_r_ref) MAGIC += size self.runSim(len(r_ref) * 5 * CLK_PERIOD) self.assertEmpty(u.driver.req._ag.data) self.assertValSequenceEqual(u.driver.r._ag.data, r_ref)
def test_simpleUnalignedWithData(self, N=1, WORDS=1, OFFSET_B=None, randomize=False): u = self.u req = u.driver._ag.req if randomize: self.randomize(u.driver.req) self.randomize(u.driver.r) self.randomize(u.axi.ar) self.randomize(u.axi.r) if u.AXI_CLS in (Axi3Lite, Axi4Lite): m = Axi4LiteSimRam(axi=u.axi) else: m = AxiSimRam(axi=u.axi) if OFFSET_B is None: if self.ALIGNAS == self.DATA_WIDTH: # to trigger an alignment error OFFSET_B = 1 else: OFFSET_B = self.ALIGNAS // 8 addr_step = u.DATA_WIDTH // 8 offset = 8 ref_r_frames = [] for i in range(N): data = [ (i + i2) & 0xff for i2 in range((WORDS + 1) * addr_step)] a = m.calloc((WORDS + 1) * addr_step, 1, initValues=data) rem = (self.CHUNK_WIDTH % self.DATA_WIDTH) // 8 req.data.append(self.mkReq(a + OFFSET_B, WORDS - 1, rem=rem)) if rem == 0: rem = self.DATA_WIDTH ref_r_frames.append(data[OFFSET_B:((WORDS - 1) * addr_step) + rem + OFFSET_B]) t = (10 + N) * CLK_PERIOD if randomize: t *= 6 self.runSim(t) if u.ALIGNAS == u.DATA_WIDTH: # unsupported alignment check if error is set self.assertValEqual(u.errorAlignment._ag.data[-1], 1) else: if u.ALIGNAS != 8: # if alignment is on 1B the but the errorAlignment can not happen self.assertValEqual(u.errorAlignment._ag.data[-1], 0) ar_ref = [] if u.axi.LEN_WIDTH == 0: for i in range(N): for w_i in range(WORDS + 1): ar_ref.append( self.aTrans(0x100 + (i + w_i) * addr_step, WORDS, 0) ) else: for i in range(N): ar_ref.append( self.aTrans(0x100 + i * addr_step, WORDS, 0) ) driver_r = u.driver.r._ag.data for ref_frame in ref_r_frames: offset = None r_data = [] for w_i in range(WORDS): data, strb, last = driver_r.popleft() self.assertValEqual(last, int(w_i == WORDS - 1)) for B_i in range(addr_step): if strb[B_i]: if offset is None: offset = B_i + (addr_step * w_i) B = int(data[(B_i + 1) * 8: B_i * 8]) r_data.append(B) self.assertEqual(offset, 0) self.assertSequenceEqual(r_data, ref_frame) self.assertEmpty(u.axi.ar._ag.data) self.assertEmpty(u.axi.r._ag.data)