Commit 2a6a28e7 authored by Richard Weinberger's avatar Richard Weinberger Committed by Brian Norris

mtd: Make MTD tests cancelable

I always go nuts when I start an MTD test on a slow device and have to
wait forever until it finishes. From the debug output I already know
what the issue is but I have to wait or reset the board hard. Resetting
is often not an option (remote access, you don't want lose the current
state, etc...).

The solution is easy, check for pending signals at key positions in the
code. Using that one can even stop a test by pressing CTRL-C as
insmod/modprobe have SIGINT pending.
Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
Signed-off-by: default avatarBrian Norris <computersforpeace@gmail.com>
parent d2b51c80
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/mtd/nand_ecc.h> #include <linux/mtd/nand_ecc.h>
#include "mtd_test.h"
/* /*
* Test the implementation for software ECC * Test the implementation for software ECC
* *
...@@ -274,6 +276,10 @@ static int nand_ecc_test_run(const size_t size) ...@@ -274,6 +276,10 @@ static int nand_ecc_test_run(const size_t size)
} }
pr_info("ok - %s-%zd\n", pr_info("ok - %s-%zd\n",
nand_ecc_test[i].name, size); nand_ecc_test[i].name, size);
err = mtdtest_relax();
if (err)
break;
} }
error: error:
kfree(error_data); kfree(error_data);
......
#include <linux/mtd/mtd.h> #include <linux/mtd/mtd.h>
#include <linux/sched.h>
static inline int mtdtest_relax(void)
{
cond_resched();
if (signal_pending(current)) {
pr_info("aborting test due to pending signal!\n");
return -EINTR;
}
return 0;
}
int mtdtest_erase_eraseblock(struct mtd_info *mtd, unsigned int ebnum); int mtdtest_erase_eraseblock(struct mtd_info *mtd, unsigned int ebnum);
int mtdtest_scan_for_bad_eraseblocks(struct mtd_info *mtd, unsigned char *bbt, int mtdtest_scan_for_bad_eraseblocks(struct mtd_info *mtd, unsigned char *bbt,
......
...@@ -320,6 +320,10 @@ static int overwrite_test(void) ...@@ -320,6 +320,10 @@ static int overwrite_test(void)
break; break;
} }
err = mtdtest_relax();
if (err)
break;
opno++; opno++;
} }
......
...@@ -112,7 +112,10 @@ static int write_whole_device(void) ...@@ -112,7 +112,10 @@ static int write_whole_device(void)
return err; return err;
if (i % 256 == 0) if (i % 256 == 0)
pr_info("written up to eraseblock %u\n", i); pr_info("written up to eraseblock %u\n", i);
cond_resched();
err = mtdtest_relax();
if (err)
return err;
} }
pr_info("written %u eraseblocks\n", i); pr_info("written %u eraseblocks\n", i);
return 0; return 0;
...@@ -318,7 +321,10 @@ static int verify_all_eraseblocks(void) ...@@ -318,7 +321,10 @@ static int verify_all_eraseblocks(void)
return err; return err;
if (i % 256 == 0) if (i % 256 == 0)
pr_info("verified up to eraseblock %u\n", i); pr_info("verified up to eraseblock %u\n", i);
cond_resched();
err = mtdtest_relax();
if (err)
return err;
} }
pr_info("verified %u eraseblocks\n", i); pr_info("verified %u eraseblocks\n", i);
return 0; return 0;
...@@ -429,7 +435,10 @@ static int __init mtd_oobtest_init(void) ...@@ -429,7 +435,10 @@ static int __init mtd_oobtest_init(void)
goto out; goto out;
if (i % 256 == 0) if (i % 256 == 0)
pr_info("verified up to eraseblock %u\n", i); pr_info("verified up to eraseblock %u\n", i);
cond_resched();
err = mtdtest_relax();
if (err)
goto out;
} }
pr_info("verified %u eraseblocks\n", i); pr_info("verified %u eraseblocks\n", i);
...@@ -642,7 +651,11 @@ static int __init mtd_oobtest_init(void) ...@@ -642,7 +651,11 @@ static int __init mtd_oobtest_init(void)
goto out; goto out;
if (i % 256 == 0) if (i % 256 == 0)
pr_info("written up to eraseblock %u\n", i); pr_info("written up to eraseblock %u\n", i);
cond_resched();
err = mtdtest_relax();
if (err)
goto out;
addr += mtd->writesize; addr += mtd->writesize;
} }
} }
...@@ -680,7 +693,10 @@ static int __init mtd_oobtest_init(void) ...@@ -680,7 +693,10 @@ static int __init mtd_oobtest_init(void)
} }
if (i % 256 == 0) if (i % 256 == 0)
pr_info("verified up to eraseblock %u\n", i); pr_info("verified up to eraseblock %u\n", i);
cond_resched();
err = mtdtest_relax();
if (err)
goto out;
} }
pr_info("verified %u eraseblocks\n", i); pr_info("verified %u eraseblocks\n", i);
......
...@@ -407,7 +407,10 @@ static int __init mtd_pagetest_init(void) ...@@ -407,7 +407,10 @@ static int __init mtd_pagetest_init(void)
goto out; goto out;
if (i % 256 == 0) if (i % 256 == 0)
pr_info("written up to eraseblock %u\n", i); pr_info("written up to eraseblock %u\n", i);
cond_resched();
err = mtdtest_relax();
if (err)
goto out;
} }
pr_info("written %u eraseblocks\n", i); pr_info("written %u eraseblocks\n", i);
...@@ -422,7 +425,10 @@ static int __init mtd_pagetest_init(void) ...@@ -422,7 +425,10 @@ static int __init mtd_pagetest_init(void)
goto out; goto out;
if (i % 256 == 0) if (i % 256 == 0)
pr_info("verified up to eraseblock %u\n", i); pr_info("verified up to eraseblock %u\n", i);
cond_resched();
err = mtdtest_relax();
if (err)
goto out;
} }
pr_info("verified %u eraseblocks\n", i); pr_info("verified %u eraseblocks\n", i);
......
...@@ -190,7 +190,10 @@ static int __init mtd_readtest_init(void) ...@@ -190,7 +190,10 @@ static int __init mtd_readtest_init(void)
if (!err) if (!err)
err = ret; err = ret;
} }
cond_resched();
err = mtdtest_relax();
if (err)
goto out;
} }
if (err) if (err)
......
...@@ -269,7 +269,10 @@ static int __init mtd_speedtest_init(void) ...@@ -269,7 +269,10 @@ static int __init mtd_speedtest_init(void)
err = write_eraseblock(i); err = write_eraseblock(i);
if (err) if (err)
goto out; goto out;
cond_resched();
err = mtdtest_relax();
if (err)
goto out;
} }
stop_timing(); stop_timing();
speed = calc_speed(); speed = calc_speed();
...@@ -284,7 +287,10 @@ static int __init mtd_speedtest_init(void) ...@@ -284,7 +287,10 @@ static int __init mtd_speedtest_init(void)
err = read_eraseblock(i); err = read_eraseblock(i);
if (err) if (err)
goto out; goto out;
cond_resched();
err = mtdtest_relax();
if (err)
goto out;
} }
stop_timing(); stop_timing();
speed = calc_speed(); speed = calc_speed();
...@@ -303,7 +309,10 @@ static int __init mtd_speedtest_init(void) ...@@ -303,7 +309,10 @@ static int __init mtd_speedtest_init(void)
err = write_eraseblock_by_page(i); err = write_eraseblock_by_page(i);
if (err) if (err)
goto out; goto out;
cond_resched();
err = mtdtest_relax();
if (err)
goto out;
} }
stop_timing(); stop_timing();
speed = calc_speed(); speed = calc_speed();
...@@ -318,7 +327,10 @@ static int __init mtd_speedtest_init(void) ...@@ -318,7 +327,10 @@ static int __init mtd_speedtest_init(void)
err = read_eraseblock_by_page(i); err = read_eraseblock_by_page(i);
if (err) if (err)
goto out; goto out;
cond_resched();
err = mtdtest_relax();
if (err)
goto out;
} }
stop_timing(); stop_timing();
speed = calc_speed(); speed = calc_speed();
...@@ -337,7 +349,10 @@ static int __init mtd_speedtest_init(void) ...@@ -337,7 +349,10 @@ static int __init mtd_speedtest_init(void)
err = write_eraseblock_by_2pages(i); err = write_eraseblock_by_2pages(i);
if (err) if (err)
goto out; goto out;
cond_resched();
err = mtdtest_relax();
if (err)
goto out;
} }
stop_timing(); stop_timing();
speed = calc_speed(); speed = calc_speed();
...@@ -352,7 +367,10 @@ static int __init mtd_speedtest_init(void) ...@@ -352,7 +367,10 @@ static int __init mtd_speedtest_init(void)
err = read_eraseblock_by_2pages(i); err = read_eraseblock_by_2pages(i);
if (err) if (err)
goto out; goto out;
cond_resched();
err = mtdtest_relax();
if (err)
goto out;
} }
stop_timing(); stop_timing();
speed = calc_speed(); speed = calc_speed();
...@@ -385,7 +403,11 @@ static int __init mtd_speedtest_init(void) ...@@ -385,7 +403,11 @@ static int __init mtd_speedtest_init(void)
err = multiblock_erase(i, j); err = multiblock_erase(i, j);
if (err) if (err)
goto out; goto out;
cond_resched();
err = mtdtest_relax();
if (err)
goto out;
i += j; i += j;
} }
stop_timing(); stop_timing();
......
...@@ -221,7 +221,10 @@ static int __init mtd_stresstest_init(void) ...@@ -221,7 +221,10 @@ static int __init mtd_stresstest_init(void)
err = do_operation(); err = do_operation();
if (err) if (err)
goto out; goto out;
cond_resched();
err = mtdtest_relax();
if (err)
goto out;
} }
pr_info("finished, %d operations done\n", op); pr_info("finished, %d operations done\n", op);
......
...@@ -269,7 +269,10 @@ static int verify_all_eraseblocks_ff(void) ...@@ -269,7 +269,10 @@ static int verify_all_eraseblocks_ff(void)
return err; return err;
if (i % 256 == 0) if (i % 256 == 0)
pr_info("verified up to eraseblock %u\n", i); pr_info("verified up to eraseblock %u\n", i);
cond_resched();
err = mtdtest_relax();
if (err)
return err;
} }
pr_info("verified %u eraseblocks\n", i); pr_info("verified %u eraseblocks\n", i);
return 0; return 0;
...@@ -346,7 +349,10 @@ static int __init mtd_subpagetest_init(void) ...@@ -346,7 +349,10 @@ static int __init mtd_subpagetest_init(void)
goto out; goto out;
if (i % 256 == 0) if (i % 256 == 0)
pr_info("written up to eraseblock %u\n", i); pr_info("written up to eraseblock %u\n", i);
cond_resched();
err = mtdtest_relax();
if (err)
goto out;
} }
pr_info("written %u eraseblocks\n", i); pr_info("written %u eraseblocks\n", i);
...@@ -360,7 +366,10 @@ static int __init mtd_subpagetest_init(void) ...@@ -360,7 +366,10 @@ static int __init mtd_subpagetest_init(void)
goto out; goto out;
if (i % 256 == 0) if (i % 256 == 0)
pr_info("verified up to eraseblock %u\n", i); pr_info("verified up to eraseblock %u\n", i);
cond_resched();
err = mtdtest_relax();
if (err)
goto out;
} }
pr_info("verified %u eraseblocks\n", i); pr_info("verified %u eraseblocks\n", i);
...@@ -383,7 +392,10 @@ static int __init mtd_subpagetest_init(void) ...@@ -383,7 +392,10 @@ static int __init mtd_subpagetest_init(void)
goto out; goto out;
if (i % 256 == 0) if (i % 256 == 0)
pr_info("written up to eraseblock %u\n", i); pr_info("written up to eraseblock %u\n", i);
cond_resched();
err = mtdtest_relax();
if (err)
goto out;
} }
pr_info("written %u eraseblocks\n", i); pr_info("written %u eraseblocks\n", i);
...@@ -398,7 +410,10 @@ static int __init mtd_subpagetest_init(void) ...@@ -398,7 +410,10 @@ static int __init mtd_subpagetest_init(void)
goto out; goto out;
if (i % 256 == 0) if (i % 256 == 0)
pr_info("verified up to eraseblock %u\n", i); pr_info("verified up to eraseblock %u\n", i);
cond_resched();
err = mtdtest_relax();
if (err)
goto out;
} }
pr_info("verified %u eraseblocks\n", i); pr_info("verified %u eraseblocks\n", i);
......
...@@ -279,7 +279,10 @@ static int __init tort_init(void) ...@@ -279,7 +279,10 @@ static int __init tort_init(void)
" for 0xFF... pattern\n"); " for 0xFF... pattern\n");
goto out; goto out;
} }
cond_resched();
err = mtdtest_relax();
if (err)
goto out;
} }
} }
...@@ -294,7 +297,10 @@ static int __init tort_init(void) ...@@ -294,7 +297,10 @@ static int __init tort_init(void)
err = write_pattern(i, patt); err = write_pattern(i, patt);
if (err) if (err)
goto out; goto out;
cond_resched();
err = mtdtest_relax();
if (err)
goto out;
} }
/* Verify what we wrote */ /* Verify what we wrote */
...@@ -314,7 +320,10 @@ static int __init tort_init(void) ...@@ -314,7 +320,10 @@ static int __init tort_init(void)
"0x55AA55..." : "0xAA55AA..."); "0x55AA55..." : "0xAA55AA...");
goto out; goto out;
} }
cond_resched();
err = mtdtest_relax();
if (err)
goto out;
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment