Example #1
0
    def _test_s0(self, u):
        DW = 64
        N = 3
        self.prepareUnit(u)

        m = DenseMemory(DW, u.clk, u.rDatapump)

        # init expectedFieldValues
        expectedFieldValues = {}
        for f in s0.fields:
            if f.name is not None:
                expectedFieldValues[f.name] = []

        for _ in range(N):
            d = s0RandVal(self)
            for name, val in d.items():
                expectedFieldValues[name].append(val)

            asFrame = list(
                iterBits(s0.fromPy(d),
                         bitsInOne=DW,
                         skipPadding=False,
                         fillup=True))
            addr = m.calloc(len(asFrame), DW // 8, initValues=asFrame)
            u.get._ag.data.append(addr)

        self.runSim(500 * Time.ns)

        for f in s0.fields:
            if f.name is not None:
                expected = expectedFieldValues[f.name]
                got = u.dataOut._fieldsToInterfaces[f]._ag.data
                self.assertValSequenceEqual(got, expected)
    def test_downloadFullBlockRandomized5x(self):
        u = self.u
        N = self.ITEMS_IN_BLOCK * 5
        MAGIC = 456
        m = DenseMemory(self.DATA_WIDTH, u.clk, u.rDatapump)

        data = []
        ADDR_BASE = None
        lastAddr = None
        for i in range(5):
            a, d = self.createBlock(m, i * MAGIC)
            if ADDR_BASE is None:
                ADDR_BASE = a
            if lastAddr is not None:
                self.updateNextAddr(m, lastAddr, a)
            lastAddr = a
            data.extend(d)
        self.updateNextAddr(m, lastAddr, ADDR_BASE)

        self.randomize(u.rDatapump.r)
        self.randomize(u.rDatapump.req)
        self.randomize(u.dataOut)

        u.baseAddr._ag.dout.append(ADDR_BASE)
        u.wrPtr._ag.dout.extend([NOP, N])

        self.runSim(N * 50 * Time.ns)

        self.assertValSequenceEqual(u.dataOut._ag.data, data)
Example #3
0
    def test_fullFill_randomized(self):
        u = self.u
        N = 2 * 16 - 1
        m = DenseMemory(self.DATA_WIDTH, u.clk, wDatapumpIntf=u.wDatapump)
        ITEM_SIZE = self.DATA_WIDTH // 8
        MAGIC = 88

        self.randomize(u.items)
        self.randomize(u.wDatapump.w)
        self.randomize(u.wDatapump.req)
        self.randomize(u.wDatapump.ack)

        BASE = m.malloc(ITEM_SIZE * N)
        u.baseAddr._ag.dout.append(BASE)
        u.items._ag.data.extend([MAGIC + i for i in range(N)])

        self.runSim(200 * 10 * Time.ns)

        self.assertEmpty(u.items._ag.data)

        self.assertEmpty(u.wDatapump.ack._ag.data)

        BASE_INDX = BASE // ITEM_SIZE
        for i in range(N):
            self.assertEqual(m.data[BASE_INDX + i], MAGIC + i)

        self.assertValEqual(self.u.uploaded._ag.data[-1], N)
Example #4
0
    def test_randomized2(self):
        u = self.u
        m = DenseMemory(self.DATA_WIDTH, u.clk, u.rDatapump)
        N = 17

        for d in u.drivers:
            self.randomize(d.req)
            self.randomize(d.r)
        self.randomize(u.rDatapump.req)
        self.randomize(u.rDatapump.r)
        _mask = mask(self.DATA_WIDTH // 8)

        expected = [[] for _ in u.drivers]
        for _id, d in enumerate(u.drivers):
            for i in range(N):
                size = self._rand.getrandbits(3) + 1
                magic = self._rand.getrandbits(16)
                values = [i + magic for i in range(size)]
                addr = m.calloc(size, 8, initValues=values)

                d.req._ag.data.append((_id, addr, size - 1, 0))

                for i2, v in enumerate(values):
                    data = (_id, v, _mask, int(i2 == size - 1))
                    expected[_id].append(data)

        self.runSim(self.DRIVERS_CNT * N * 200 * Time.ns)

        for expect, driver in zip(expected, u.drivers):
            self.assertValSequenceEqual(driver.r._ag.data, expect)
    def test_regularUpload2(self):
        u = self.u
        t = 200
        BASE = 0x1020
        BASE2 = 0x2020
        ITEMS = self.ITEMS_IN_BLOCK * 2
        MAGIC = 50

        u.baseAddr._ag.dout.append(BASE)
        u.rdPtr._ag.dout.append(ITEMS)

        m = DenseMemory(self.DATA_WIDTH, u.clk, u.rDatapump, u.wDatapump)

        self.spotNextBaseAddr(m, BASE, BASE2)
        self.spotNextBaseAddr(m, BASE2, BASE + BASE2)
        self.spotNextBaseAddr(m, BASE + BASE2, BASE + BASE2 + BASE)

        for i in range(ITEMS):
            self.u.dataIn._ag.data.append(i + MAGIC)

        self.runSim(t * 10 * Time.ns)

        baseIndex = BASE // (self.DATA_WIDTH // 8)

        for i in range(ITEMS):
            try:
                d = m.data[baseIndex + i]
            except KeyError:  # pragma: no cover
                raise AssertionError("Invalid data on index %d" % i)
            self.assertValEqual(d, i + MAGIC, "Invalid data on index %d" % i)
Example #6
0
    def test_translate10xRandomized(self):
        u = self.u
        N = 10
        # self.randomize(u.rDatapump.req)
        self.randomize(u.rDatapump.r)
        self.randomize(u.virtIn)
        self.randomize(u.physOut)

        m = DenseMemory(self.DATA_WIDTH, u.clk, rDatapumpIntf=u.rDatapump)
        virt = u.virtIn._ag.data
        virt.extend([NOP for _ in range(N)])

        expected = []
        for i in range(N):
            lvl2pgtData = [int(2 ** 12) * i2 if i + 1 == i2 else -1
                           for i2 in range(self.LVL2_PAGE_TABLE_ITEMS)]
            lvl2pgt = m.calloc(self.LVL2_PAGE_TABLE_ITEMS,
                               4,
                               initValues=lvl2pgtData)

            u.lvl1Table._ag.requests.append((WRITE, i, lvl2pgt))
            v = self.buildVirtAddr(i, i + 1, i + 1)
            virt.append(v)
            expected.append(int(2 ** 12) * (i + 1) + i + 1)

        self.runSim(N*300 * Time.ns)

        self.assertValSequenceEqual(u.physOut._ag.data, expected)
        self.assertValEqual(u.segfault._ag.data[-1], 0)
Example #7
0
    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)
Example #8
0
    def test_get(self):
        u = self.u
        MAGIC = 99
        N = self.ITEMS
        t = 10 + N

        m = DenseMemory(self.DATA_WIDTH, u.clk, rDatapumpIntf=u.rDatapump)
        base = m.calloc(self.ITEMS,
                        self.ITEM_WIDTH // 8,
                        initValues=[MAGIC + i for i in range(N)])
        u.base._ag.data.append(base)
        u.index._ag.data.extend([i for i in range(N)])

        self.runSim(t * 10 * Time.ns)

        self.assertValSequenceEqual(u.item._ag.data,
                                    [MAGIC + i for i in range(N)])
    def test_downloadFullBlockNextAddrInSeparateReq(self):
        u = self.u
        N = self.ITEMS_IN_BLOCK + 1
        MAGIC = 5896

        m = DenseMemory(self.DATA_WIDTH, u.clk, u.rDatapump)

        ADDR_BASE, data = self.createBlock(m, MAGIC)
        NEXT_BASE, data2 = self.createBlock(m, MAGIC*2)
        self.updateNextAddr(m, ADDR_BASE, NEXT_BASE)

        u.baseAddr._ag.dout.append(ADDR_BASE)
        u.wrPtr._ag.dout.extend([NOP, self.MAX_LEN] 
                                + [NOP for _ in range(self.MAX_LEN + 4)] + [N])

        self.runSim(N * 50 * Time.ns)
        self.assertValSequenceEqual(u.dataOut._ag.data, data+ [data2[0]])
Example #10
0
    def test_singleGet(self):
        u = self.u
        t = 5
        BASE = 8 * (self.DATA_WIDTH // 8)
        MAGIC = 99
        INDEX = self.ITEMS - 1

        u.base._ag.data.append(BASE)
        u.index._ag.data.append(INDEX)

        m = DenseMemory(self.DATA_WIDTH, u.clk, rDatapumpIntf=u.rDatapump)
        m.data[BASE // 8 + INDEX] = MAGIC

        self.runSim(t * 10 * Time.ns)

        self.assertValSequenceEqual(u.item._ag.data, [
            MAGIC,
        ])
Example #11
0
    def test_randomized2(self):
        u = self.u
        m = DenseMemory(self.DATA_WIDTH, u.clk, wDatapumpIntf=u.wDatapump)
        N = 25
        _mask = mask(self.DATA_WIDTH // 8)

        for d in u.drivers:
            self.randomize(d.req)
            self.randomize(d.w)
            self.randomize(d.ack)

        self.randomize(u.wDatapump.req)
        self.randomize(u.wDatapump.w)
        self.randomize(u.wDatapump.ack)

        sectors = []
        framesCnt = [0 for _ in range(self.DRIVER_CNT)]
        for i in range(N):
            for _id, d in enumerate(u.drivers):
                size = self._rand.getrandbits(3) + 1
                magic = self._rand.getrandbits(16)
                addr = m.calloc(size, 8, initValues=[None for _ in range(size)])

                d.req._ag.data.append((_id, addr, size - 1, 0))
                for i in range(size):
                    data = (magic + i, _mask, int(i == size - 1))
                    d.w._ag.data.append(data)

                values = [i + magic for i in range(size)]
                sectors.append((_id, addr, values))
                framesCnt[_id] += 1

        self.runSim(self.DRIVER_CNT * N * 250 * Time.ns)

        for _id, d in enumerate(u.drivers):
            self.assertEmpty(d.req._ag.data)
            self.assertEmpty(d.w._ag.data)
            self.assertEqual(len(u.drivers[_id].ack._ag.data),
                              framesCnt[_id])

        for _id, addr, expected in sectors:
            v = m.getArray(addr, 8, len(expected))
            self.assertSequenceEqual(v, expected)
    def test_downloadFullBlockRandomized(self):
        u = self.u
        N = self.ITEMS_IN_BLOCK
        MAGIC = 6413

        m = DenseMemory(self.DATA_WIDTH, u.clk, u.rDatapump)

        ADDR_BASE, data = self.createBlock(m, MAGIC)
        self.updateNextAddr(m, ADDR_BASE, ADDR_BASE)

        self.randomize(u.rDatapump.r)
        self.randomize(u.rDatapump.req)
        self.randomize(u.dataOut)

        u.baseAddr._ag.dout.append(ADDR_BASE)
        u.wrPtr._ag.dout.extend([NOP, N])

        self.runSim(N * 60 * Time.ns)
        self.assertValSequenceEqual(u.dataOut._ag.data, data)
Example #13
0
    def test_lvl2_fault(self):
        u = self.u
        MAGIC = 45

        m = DenseMemory(self.DATA_WIDTH, u.clk, rDatapumpIntf=u.rDatapump)

        lvl2pgt = m.calloc(self.LVL2_PAGE_TABLE_ITEMS, 4,
                           initValues=[-1 for _ in range(self.LVL2_PAGE_TABLE_ITEMS)])

        u.lvl1Table._ag.requests.append((WRITE, MAGIC, lvl2pgt))

        va = self.buildVirtAddr(MAGIC, 0, 0)
        # wait for lvl1Table storage init
        u.virtIn._ag.data.extend([NOP, NOP, va])

        self.runSim(100 * Time.ns)

        self.assertEmpty(u.physOut._ag.data)
        self.assertValEqual(u.segfault._ag.data[-1], 1)
Example #14
0
    def test_randomized(self):
        u = self.u
        m = DenseMemory(self.DATA_WIDTH, u.clk, u.rDatapump)

        for d in u.drivers:
            self.randomize(d.req)
            self.randomize(d.r)
        self.randomize(u.rDatapump.req)
        self.randomize(u.rDatapump.r)

        def prepare(driverIndex, addr, size, valBase=1, _id=1):
            driver = u.drivers[driverIndex]
            driver.req._ag.data.append((_id, addr, size - 1, 0))
            expected = []
            _mask = mask(self.DATA_WIDTH // 8)
            index = addr // (self.DATA_WIDTH // 8)
            for i in range(size):
                v = valBase + i
                m.data[index + i] = v
                d = (_id, v, _mask, int(i == size - 1))
                expected.append(d)
            return expected

        def check(driverIndex, expected):
            driverData = u.drivers[driverIndex].r._ag.data
            self.assertEqual(len(driverData), len(expected))
            for d, e in zip(driverData, expected):
                self.assertValSequenceEqual(d, e)

        d0 = prepare(
            0, 0x1000, 3, 99, _id=0
        )  # + prepare(0, 0x2000, 1, 100, _id=0) + prepare(0, 0x3000, 16, 101)
        d1 = prepare(1, 0x4000, 3, 200, _id=1) + prepare(
            1, 0x5000, 1, 201, _id=1
        )  # + prepare(1, 0x6000, 16, 202) #+ prepare(1, 0x7000, 16, 203)

        self.runSim(1000 * Time.ns)

        check(0, d0)
        check(1, d1)
Example #15
0
    def test_randomized(self):
        u = self.u
        m = DenseMemory(self.DATA_WIDTH, u.clk, wDatapumpIntf=u.wDatapump)

        for d in u.drivers:
            self.randomize(d.req)
            self.randomize(d.w)
            self.randomize(d.ack)

        self.randomize(u.wDatapump.req)
        self.randomize(u.wDatapump.w)
        self.randomize(u.wDatapump.ack)

        sectors = []

        def prepare(driverIndex, addr, size, valBase=1, _id=1):
            driver = u.drivers[driverIndex]
            driver.req._ag.data.append((_id, addr, size - 1, 0))
            _mask = mask(self.DATA_WIDTH // 8)

            for i in range(size):
                d = (valBase + i, _mask, int(i == size - 1))

                driver.w._ag.data.append(d)
                u.wDatapump.ack._ag.data.append(driverIndex)

            sectors.append((addr, valBase, size))

        prepare(0, 0x1000, 3, 99, _id=0)
        prepare(0, 0x2000, 1, 100, _id=0)
        prepare(0, 0x3000, 16, 101)
        prepare(1, 0x4000, 3, 200, _id=1)
        prepare(1, 0x5000, 1, 201, _id=1)  # + prepare(1, 0x6000, 16, 202) #+ prepare(1, 0x7000, 16, 203)

        self.runSim(2000 * Time.ns)

        for addr, seed, size in sectors:
            expected = [seed + i for i in range(size)]
            self.assertValSequenceEqual(m.getArray(addr, 8, size), expected)
Example #16
0
    def test_fullFill_randomized3(self, N=None):
        u = self.u
        BASE = 0x1230
        MAGIC = 1
        if N is None:
            N = self.ITEMS + 10

        m = DenseMemory(self.DATA_WIDTH, u.clk, wDatapumpIntf=u.wDatapump)

        u.baseAddr._ag.dout.append(BASE)
        for i in range(N):
            u.items._ag.data.append(MAGIC + i)

        def enReq(s):
            u.wDatapump.req._ag.enable = False
            yield s.wait(32 * 10 * Time.ns)
            yield from self.simpleRandomizationProcess(u.wDatapump.req._ag)(s)

        self.procs.append(enReq)

        self.randomize(u.wDatapump.w)
        self.randomize(u.items)
        # self.randomize(u.req)
        self.randomize(u.wDatapump.ack)

        self.runSim(N * 40 * Time.ns)

        self.assertEmpty(u.items._ag.data)
        d = m.getArray(BASE, self.DATA_WIDTH // 8, self.ITEMS)

        expected = [
            i + MAGIC if i >= 10 else i + self.ITEMS + MAGIC
            for i in range(self.ITEMS)
        ]

        self.assertValSequenceEqual(d, expected)
        self.assertValEqual(u.uploaded._ag.data[-1], N)
Example #17
0
 def buildEnv(self, structT):
     u = self.u = StructWriter(structT)
     u.DATA_WIDTH.set(64)
     self.prepareUnit(u)
     m = DenseMemory(int(u.DATA_WIDTH), u.clk, wDatapumpIntf=u.wDatapump)
     return m