static int mtd_test_bitfliptest(void) { int err = 0; unsigned int i = 0, op = 0; bufsize = mtd->erasesize * 2; readbuf = vmalloc(bufsize); if(!readbuf) { pr_err("%s, alloc readbuf failed!\n", __func__); return -ENOMEM; } writebuf = vmalloc(bufsize); if(!writebuf) { pr_err("%s, alloc writebuf failed!\n", __func__); vfree(readbuf); return -ENOMEM; } offsets = vmalloc(ebcnt * sizeof(int)); if(!offsets) { pr_err("%s, alloc offsets failed!\n", __func__); vfree(readbuf); vfree(writebuf); return -ENOMEM; } pr_info("bitfliptest begin!\n"); for (i = 0; i < ebcnt; i++) offsets[i] = mtd->erasesize; prandom_bytes(writebuf, bufsize); err = mtd_test_erase_whole_device(); if(err) goto out; while(1) { if ((op & 1023) == 0) pr_info("%d operations done\n", op); err = bitfliptest_do_operation(); if (err) goto out; if(errcnt >= threshold) { pr_info("Test times: %d, read times: %d, read pages: %d, bit-flip: %d.\n", op, rdcnt, rdpgcnt, errcnt); break; } cond_resched(); op += 1; } out: vfree(offsets); vfree(readbuf); vfree(writebuf); pr_info("bitfliptest finished, %d operations done!\n", op); return err; }
static int test_nodelta_obj_get(struct world *world, struct objagg *objagg, unsigned int key_id, bool should_create_root) { unsigned int orig_root_count = world->root_count; struct objagg_obj *objagg_obj; const struct root *root; int err; if (should_create_root) prandom_bytes(world->next_root_buf, sizeof(world->next_root_buf)); objagg_obj = world_obj_get(world, objagg, key_id); if (IS_ERR(objagg_obj)) { pr_err("Key %u: Failed to get object.\n", key_id); return PTR_ERR(objagg_obj); } if (should_create_root) { if (world->root_count != orig_root_count + 1) { pr_err("Key %u: Root was not created\n", key_id); err = -EINVAL; goto err_check_root_count; } } else { if (world->root_count != orig_root_count) { pr_err("Key %u: Root was incorrectly created\n", key_id); err = -EINVAL; goto err_check_root_count; } } root = objagg_obj_root_priv(objagg_obj); if (root->key.id != key_id) { pr_err("Key %u: Root has unexpected key id\n", key_id); err = -EINVAL; goto err_check_key_id; } if (should_create_root && memcmp(world->next_root_buf, root->buf, sizeof(root->buf))) { pr_err("Key %u: Buffer does not match the expected content\n", key_id); err = -EINVAL; goto err_check_buf; } return 0; err_check_buf: err_check_key_id: err_check_root_count: objagg_obj_put(objagg, objagg_obj); return err; }
static int nand_ecc_test_run(const size_t size) { int i; int err = 0; void *error_data; void *error_ecc; void *correct_data; void *correct_ecc; error_data = kmalloc(size, GFP_KERNEL); error_ecc = kmalloc(3, GFP_KERNEL); correct_data = kmalloc(size, GFP_KERNEL); correct_ecc = kmalloc(3, GFP_KERNEL); if (!error_data || !error_ecc || !correct_data || !correct_ecc) { err = -ENOMEM; goto error; } prandom_bytes(correct_data, size); __nand_calculate_ecc(correct_data, size, correct_ecc); for (i = 0; i < ARRAY_SIZE(nand_ecc_test); i++) { nand_ecc_test[i].prepare(error_data, error_ecc, correct_data, correct_ecc, size); err = nand_ecc_test[i].verify(error_data, error_ecc, correct_data, size); if (err) { pr_err("not ok - %s-%zd\n", nand_ecc_test[i].name, size); dump_data_ecc(error_data, error_ecc, correct_data, correct_ecc, size); break; } pr_info("ok - %s-%zd\n", nand_ecc_test[i].name, size); err = mtdtest_relax(); if (err) break; } error: kfree(error_data); kfree(error_ecc); kfree(correct_data); kfree(correct_ecc); return err; }
static void __init init_sample_table(void) { int col, i, new_idx; u8 rnd[MCS_GROUP_RATES]; memset(sample_table, 0xff, sizeof(sample_table)); for (col = 0; col < SAMPLE_COLUMNS; col++) { prandom_bytes(rnd, sizeof(rnd)); for (i = 0; i < MCS_GROUP_RATES; i++) { new_idx = (i + rnd[i]) % MCS_GROUP_RATES; while (sample_table[col][new_idx] != 0xff) new_idx = (new_idx + 1) % MCS_GROUP_RATES; sample_table[col][new_idx] = i; } } }
static int __init mtd_speedtest_init(void) { int err, i, blocks, j, k; long speed; uint64_t tmp; printk(KERN_INFO "\n"); printk(KERN_INFO "=================================================\n"); if (dev < 0) { pr_info("Please specify a valid mtd-device via module parameter\n"); pr_crit("CAREFUL: This test wipes all data on the specified MTD device!\n"); return -EINVAL; } if (count) pr_info("MTD device: %d count: %d\n", dev, count); else pr_info("MTD device: %d\n", dev); mtd = get_mtd_device(NULL, dev); if (IS_ERR(mtd)) { err = PTR_ERR(mtd); pr_err("error: cannot get MTD device\n"); return err; } if (mtd->writesize == 1) { pr_info("not NAND flash, assume page size is 512 " "bytes.\n"); pgsize = 512; } else pgsize = mtd->writesize; tmp = mtd->size; do_div(tmp, mtd->erasesize); ebcnt = tmp; pgcnt = mtd->erasesize / pgsize; pr_info("MTD device size %llu, eraseblock size %u, " "page size %u, count of eraseblocks %u, pages per " "eraseblock %u, OOB size %u\n", (unsigned long long)mtd->size, mtd->erasesize, pgsize, ebcnt, pgcnt, mtd->oobsize); if (count > 0 && count < ebcnt) ebcnt = count; err = -ENOMEM; iobuf = kmalloc(mtd->erasesize, GFP_KERNEL); if (!iobuf) goto out; prandom_bytes(iobuf, mtd->erasesize); bbt = kzalloc(ebcnt, GFP_KERNEL); if (!bbt) goto out; err = mtdtest_scan_for_bad_eraseblocks(mtd, bbt, 0, ebcnt); if (err) goto out; for (i = 0; i < ebcnt; i++) { if (!bbt[i]) goodebcnt++; } err = mtdtest_erase_good_eraseblocks(mtd, bbt, 0, ebcnt); if (err) goto out; /* Write all eraseblocks, 1 eraseblock at a time */ pr_info("testing eraseblock write speed\n"); start_timing(); for (i = 0; i < ebcnt; ++i) { if (bbt[i]) continue; err = write_eraseblock(i); if (err) goto out; cond_resched(); } stop_timing(); speed = calc_speed(); pr_info("eraseblock write speed is %ld KiB/s\n", speed); /* Read all eraseblocks, 1 eraseblock at a time */ pr_info("testing eraseblock read speed\n"); start_timing(); for (i = 0; i < ebcnt; ++i) { if (bbt[i]) continue; err = read_eraseblock(i); if (err) goto out; cond_resched(); } stop_timing(); speed = calc_speed(); pr_info("eraseblock read speed is %ld KiB/s\n", speed); err = mtdtest_erase_good_eraseblocks(mtd, bbt, 0, ebcnt); if (err) goto out; /* Write all eraseblocks, 1 page at a time */ pr_info("testing page write speed\n"); start_timing(); for (i = 0; i < ebcnt; ++i) { if (bbt[i]) continue; err = write_eraseblock_by_page(i); if (err) goto out; cond_resched(); } stop_timing(); speed = calc_speed(); pr_info("page write speed is %ld KiB/s\n", speed); /* Read all eraseblocks, 1 page at a time */ pr_info("testing page read speed\n"); start_timing(); for (i = 0; i < ebcnt; ++i) { if (bbt[i]) continue; err = read_eraseblock_by_page(i); if (err) goto out; cond_resched(); } stop_timing(); speed = calc_speed(); pr_info("page read speed is %ld KiB/s\n", speed); err = mtdtest_erase_good_eraseblocks(mtd, bbt, 0, ebcnt); if (err) goto out; /* Write all eraseblocks, 2 pages at a time */ pr_info("testing 2 page write speed\n"); start_timing(); for (i = 0; i < ebcnt; ++i) { if (bbt[i]) continue; err = write_eraseblock_by_2pages(i); if (err) goto out; cond_resched(); } stop_timing(); speed = calc_speed(); pr_info("2 page write speed is %ld KiB/s\n", speed); /* Read all eraseblocks, 2 pages at a time */ pr_info("testing 2 page read speed\n"); start_timing(); for (i = 0; i < ebcnt; ++i) { if (bbt[i]) continue; err = read_eraseblock_by_2pages(i); if (err) goto out; cond_resched(); } stop_timing(); speed = calc_speed(); pr_info("2 page read speed is %ld KiB/s\n", speed); /* Erase all eraseblocks */ pr_info("Testing erase speed\n"); start_timing(); err = mtdtest_erase_good_eraseblocks(mtd, bbt, 0, ebcnt); if (err) goto out; stop_timing(); speed = calc_speed(); pr_info("erase speed is %ld KiB/s\n", speed); /* Multi-block erase all eraseblocks */ for (k = 1; k < 7; k++) { blocks = 1 << k; pr_info("Testing %dx multi-block erase speed\n", blocks); start_timing(); for (i = 0; i < ebcnt; ) { for (j = 0; j < blocks && (i + j) < ebcnt; j++) if (bbt[i + j]) break; if (j < 1) { i++; continue; } err = multiblock_erase(i, j); if (err) goto out; cond_resched(); i += j; } stop_timing(); speed = calc_speed(); pr_info("%dx multi-block erase speed is %ld KiB/s\n", blocks, speed); } pr_info("finished\n"); out: kfree(iobuf); kfree(bbt); put_mtd_device(mtd); if (err) pr_info("error %d occurred\n", err); printk(KERN_INFO "=================================================\n"); return err; }
static void __uuid_gen_common(__u8 b[16]) { prandom_bytes(b, 16); /* reversion 0b10 */ b[8] = (b[8] & 0x3F) | 0x80; }
static int __init mtd_stresstest_init(void) { int err; int i, op; uint64_t tmp; printk(KERN_INFO "\n"); printk(KERN_INFO "=================================================\n"); if (dev < 0) { pr_info("Please specify a valid mtd-device via module parameter\n"); pr_crit("CAREFUL: This test wipes all data on the specified MTD device!\n"); return -EINVAL; } pr_info("MTD device: %d\n", dev); mtd = get_mtd_device(NULL, dev); if (IS_ERR(mtd)) { err = PTR_ERR(mtd); pr_err("error: cannot get MTD device\n"); return err; } if (mtd->writesize == 1) { pr_info("not NAND flash, assume page size is 512 " "bytes.\n"); pgsize = 512; } else pgsize = mtd->writesize; tmp = mtd->size; do_div(tmp, mtd->erasesize); ebcnt = tmp; pgcnt = mtd->erasesize / pgsize; pr_info("MTD device size %llu, eraseblock size %u, " "page size %u, count of eraseblocks %u, pages per " "eraseblock %u, OOB size %u\n", (unsigned long long)mtd->size, mtd->erasesize, pgsize, ebcnt, pgcnt, mtd->oobsize); if (ebcnt < 2) { pr_err("error: need at least 2 eraseblocks\n"); err = -ENOSPC; goto out_put_mtd; } /* Read or write up 2 eraseblocks at a time */ bufsize = mtd->erasesize * 2; err = -ENOMEM; readbuf = vmalloc(bufsize); writebuf = vmalloc(bufsize); offsets = kmalloc(ebcnt * sizeof(int), GFP_KERNEL); if (!readbuf || !writebuf || !offsets) { pr_err("error: cannot allocate memory\n"); goto out; } for (i = 0; i < ebcnt; i++) offsets[i] = mtd->erasesize; prandom_bytes(writebuf, bufsize); err = scan_for_bad_eraseblocks(); if (err) goto out; /* Do operations */ pr_info("doing operations\n"); for (op = 0; op < count; op++) { if ((op & 1023) == 0) pr_info("%d operations done\n", op); err = do_operation(); if (err) goto out; cond_resched(); } pr_info("finished, %d operations done\n", op); out: kfree(offsets); kfree(bbt); vfree(writebuf); vfree(readbuf); out_put_mtd: put_mtd_device(mtd); if (err) pr_info("error %d occurred\n", err); printk(KERN_INFO "=================================================\n"); return err; }