Ejemplo n.º 1
0
def main():
    fd = fs.open_disk(0)
    if fd == -1:
        return

    wdata = fs.ucarray(4096)
    rdata = fs.ucarray(4096)
    seq_full = xrange(0xf0000 / 2 / 8)
    while True:
        for i in xrange(4096):
            wdata[i] = random.choice(xrange(0x100))
        lba = random.choice(seq_full) * 8
        
        res = fs.write_lba(fd, wdata, 8, lba)
        if res == -1:
            print 'Write lba failed in: %#X' % lba
            fs.close_disk(fd)
            return
        
        res = fs.read_lba(fd, rdata, 8, lba)
        if res == -1:
            print 'Read lba failed in: %#X' % lba
            fs.close_disk(fd)
            return

        for i in xrange(4096):
            if rdata[i] != wdata[i]:
                print 'Compare failed in lba: %#X' % lba
                fs.close_disk(fd)
                return

    fs.close_disk(fd)
Ejemplo n.º 2
0
def main():
    fd = fs.open_disk(0)
    if fd == -1:
        return

    param = fs.flash_param()
    param.ce = 4
    param.block = 64
    param.page = 128
    param.sect = 8
    res = fs.write_param(fd, param)
    if res != 0x50:
        print 'Write param failed. %#X' % res
        print fs.close_disk(fd)
        return

    test_len = 128
    cmd = fs.q_cmd()
    wdata = fs.ucarray(4096)
    rdata = fs.ucarray(4096)
    while True:
        # Write 4k-len data to random place before DATA_BASE/2 for each page
        wpids = random.sample(xrange((0xf0000/2 - 8)/8), test_len)
        for i in xrange(test_len):
            for j in xrange(4096):
                wdata[j] = i        # Init with cid
            res_write = fs.write_lba(fd, wdata, 8, wpids[i] * 8) # XXX: lba = pid * 8
            if res_write != 0x50:
                print 'Write lba failed %#X' % res_write
                print fs.close_disk(fd)
                return
            cmd.cid = i
            cmd.pid = wpids[i]
            cmd.type = fs.FT_PROGRAM
            cmd.page = i
            fs.append_cmd(0, cmd)
        res = fs.flush_send_queue(fd, 0)
        if res != 0x50:
            print 'Flush write queue failed %#X' % res
            print fs.close_disk(fd)
            return
       
        res = fs.read_complete_queue(fd, 0, 3000)
        if res == -1:           # timeout
            print 'Timeout in read write-queue complete status, wpids:'
            print 'Time: %s' % time.asctime()
            print '\n'.join(['%#X' % i for i in wpids])
            print fs.close_disk(fd)
            return

        # Send read
        rpids = random.sample(set(xrange((0xf0000/2 - 8)/8)) - set(wpids), test_len)
        for i in xrange(test_len):
            cmd.cid = i
            cmd.pid = rpids[i]
            cmd.type = fs.FT_READ
            cmd.page = i
            fs.append_cmd(0, cmd)
        res = fs.flush_send_queue(fd, 0)
        if res != 0x50:
            print 'Flush read queue failed %#X' % res
            print fs.close_disk(fd)
            return
        res = fs.read_complete_queue(fd, 0, 3000)
        if res == -1:           # timeout
            print 'Timeout in read read-queue complete status, rpids, %#X' % res
            print 'Time: %s' % time.asctime()
            print '\n'.join(['%#X' % i for i in rpids])
            print fs.close_disk(fd)
            return

        # Read data and compare
        for i in xrange(test_len):
            res_read = fs.read_lba(fd, rdata, 8, rpids[i] * 8) # XXX
            if res_read != 0x50:
                print 'Read lba faild: %#X' % res_read
                print fs.close_disk(fd)
                return
            # for j in xrange(8):
            #     if rdata[j] != i:
            #         break
            # else:
            continue
            print 'Compare error in pid: %#X, time: %s' % (rpids[i], time.asctime())
            print 'Error page %d, write_pid: %#X, read_pid: %#X' % (i, wpids[i], rpids[i])
            print 'Error bytes:'
            for i in range(32):
                print '%d - %#X' % (i, rdata[i])
            print fs.close_disk(fd)
            return

    fs.close_disk(fd)