]> git.karo-electronics.de Git - linux-beck.git/commitdiff
mtd: Make MTD tests cancelable
authorRichard Weinberger <richard@nod.at>
Sun, 29 Mar 2015 19:52:06 +0000 (21:52 +0200)
committerBrian Norris <computersforpeace@gmail.com>
Mon, 6 Apr 2015 01:12:53 +0000 (18:12 -0700)
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: Richard Weinberger <richard@nod.at>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
drivers/mtd/tests/mtd_nandecctest.c
drivers/mtd/tests/mtd_test.h
drivers/mtd/tests/nandbiterrs.c
drivers/mtd/tests/oobtest.c
drivers/mtd/tests/pagetest.c
drivers/mtd/tests/readtest.c
drivers/mtd/tests/speedtest.c
drivers/mtd/tests/stresstest.c
drivers/mtd/tests/subpagetest.c
drivers/mtd/tests/torturetest.c

index e579f9027c47d82bb1e4d577ddd13128324a0075..79316159eec63cbca36aa06d27bfaab561b62dc0 100644 (file)
@@ -9,6 +9,8 @@
 #include <linux/slab.h>
 #include <linux/mtd/nand_ecc.h>
 
+#include "mtd_test.h"
+
 /*
  * Test the implementation for software ECC
  *
@@ -274,6 +276,10 @@ static int nand_ecc_test_run(const size_t size)
                }
                pr_info("ok - %s-%zd\n",
                        nand_ecc_test[i].name, size);
+
+               err = mtdtest_relax();
+               if (err)
+                       break;
        }
 error:
        kfree(error_data);
index f437c776c54f499614746b78492d0d38139049af..4b7bee17c924bb0f29c007812568bdadb3226924 100644 (file)
@@ -1,4 +1,16 @@
 #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_scan_for_bad_eraseblocks(struct mtd_info *mtd, unsigned char *bbt,
index 273f7e5539541ee7fa2bdd7bed0eb659dc2bebca..09a4ccac53a2e74dd29aae1c9e8d41baad505609 100644 (file)
@@ -320,6 +320,10 @@ static int overwrite_test(void)
                        break;
                }
 
+               err = mtdtest_relax();
+               if (err)
+                       break;
+
                opno++;
        }
 
index c6b35644a10f13162fae8a06aca77773cae33718..8e8525f0202f60b2349cc0fcff0357b038d6417e 100644 (file)
@@ -112,7 +112,10 @@ static int write_whole_device(void)
                        return err;
                if (i % 256 == 0)
                        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);
        return 0;
@@ -318,7 +321,10 @@ static int verify_all_eraseblocks(void)
                        return err;
                if (i % 256 == 0)
                        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);
        return 0;
@@ -429,7 +435,10 @@ static int __init mtd_oobtest_init(void)
                        goto out;
                if (i % 256 == 0)
                        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);
 
@@ -642,7 +651,11 @@ static int __init mtd_oobtest_init(void)
                                goto out;
                        if (i % 256 == 0)
                                pr_info("written up to eraseblock %u\n", i);
-                       cond_resched();
+
+                       err = mtdtest_relax();
+                       if (err)
+                               goto out;
+
                        addr += mtd->writesize;
                }
        }
@@ -680,7 +693,10 @@ static int __init mtd_oobtest_init(void)
                }
                if (i % 256 == 0)
                        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);
 
index 88296e888e9d6518a398384d26c68a0d7744bcb9..ba1890d5632ce1607d5ce8371c3ff962f8b8cc41 100644 (file)
@@ -407,7 +407,10 @@ static int __init mtd_pagetest_init(void)
                        goto out;
                if (i % 256 == 0)
                        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);
 
@@ -422,7 +425,10 @@ static int __init mtd_pagetest_init(void)
                        goto out;
                if (i % 256 == 0)
                        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);
 
index a54cf1511114c31ed5d52a59a7d9814d792a334f..a3196b750a220663b22f866fbf8173ca6fe81d4a 100644 (file)
@@ -190,7 +190,10 @@ static int __init mtd_readtest_init(void)
                        if (!err)
                                err = ret;
                }
-               cond_resched();
+
+               err = mtdtest_relax();
+               if (err)
+                       goto out;
        }
 
        if (err)
index a77019cb55101480b89ba96273ad303f9e997d53..5a6f31af06f90c3337ae1316310e50af070d4f17 100644 (file)
@@ -269,7 +269,10 @@ static int __init mtd_speedtest_init(void)
                err = write_eraseblock(i);
                if (err)
                        goto out;
-               cond_resched();
+
+               err = mtdtest_relax();
+               if (err)
+                       goto out;
        }
        stop_timing();
        speed = calc_speed();
@@ -284,7 +287,10 @@ static int __init mtd_speedtest_init(void)
                err = read_eraseblock(i);
                if (err)
                        goto out;
-               cond_resched();
+
+               err = mtdtest_relax();
+               if (err)
+                       goto out;
        }
        stop_timing();
        speed = calc_speed();
@@ -303,7 +309,10 @@ static int __init mtd_speedtest_init(void)
                err = write_eraseblock_by_page(i);
                if (err)
                        goto out;
-               cond_resched();
+
+               err = mtdtest_relax();
+               if (err)
+                       goto out;
        }
        stop_timing();
        speed = calc_speed();
@@ -318,7 +327,10 @@ static int __init mtd_speedtest_init(void)
                err = read_eraseblock_by_page(i);
                if (err)
                        goto out;
-               cond_resched();
+
+               err = mtdtest_relax();
+               if (err)
+                       goto out;
        }
        stop_timing();
        speed = calc_speed();
@@ -337,7 +349,10 @@ static int __init mtd_speedtest_init(void)
                err = write_eraseblock_by_2pages(i);
                if (err)
                        goto out;
-               cond_resched();
+
+               err = mtdtest_relax();
+               if (err)
+                       goto out;
        }
        stop_timing();
        speed = calc_speed();
@@ -352,7 +367,10 @@ static int __init mtd_speedtest_init(void)
                err = read_eraseblock_by_2pages(i);
                if (err)
                        goto out;
-               cond_resched();
+
+               err = mtdtest_relax();
+               if (err)
+                       goto out;
        }
        stop_timing();
        speed = calc_speed();
@@ -385,7 +403,11 @@ static int __init mtd_speedtest_init(void)
                        err = multiblock_erase(i, j);
                        if (err)
                                goto out;
-                       cond_resched();
+
+                       err = mtdtest_relax();
+                       if (err)
+                               goto out;
+
                        i += j;
                }
                stop_timing();
index d90c1c01dac6b957c1ae1d8cde43e62483cc852e..e509f8aa9a7eea21db08004a8eca1608880ac7d1 100644 (file)
@@ -221,7 +221,10 @@ static int __init mtd_stresstest_init(void)
                err = do_operation();
                if (err)
                        goto out;
-               cond_resched();
+
+               err = mtdtest_relax();
+               if (err)
+                       goto out;
        }
        pr_info("finished, %d operations done\n", op);
 
index 0b835c631f9175301f6c3c1809930b37679d1189..aecc6ce5a9e1c131a38d657325356ab590de845c 100644 (file)
@@ -269,7 +269,10 @@ static int verify_all_eraseblocks_ff(void)
                        return err;
                if (i % 256 == 0)
                        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);
        return 0;
@@ -346,7 +349,10 @@ static int __init mtd_subpagetest_init(void)
                        goto out;
                if (i % 256 == 0)
                        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);
 
@@ -360,7 +366,10 @@ static int __init mtd_subpagetest_init(void)
                        goto out;
                if (i % 256 == 0)
                        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);
 
@@ -383,7 +392,10 @@ static int __init mtd_subpagetest_init(void)
                        goto out;
                if (i % 256 == 0)
                        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);
 
@@ -398,7 +410,10 @@ static int __init mtd_subpagetest_init(void)
                        goto out;
                if (i % 256 == 0)
                        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);
 
index 5045cf1b3160a892c5cedc7918ddbf3b8e60aef9..e5d6e6d9532fa5f12961ae9aae72d0766e296370 100644 (file)
@@ -279,7 +279,10 @@ static int __init tort_init(void)
                                               " for 0xFF... pattern\n");
                                        goto out;
                                }
-                               cond_resched();
+
+                               err = mtdtest_relax();
+                               if (err)
+                                       goto out;
                        }
                }
 
@@ -294,7 +297,10 @@ static int __init tort_init(void)
                        err = write_pattern(i, patt);
                        if (err)
                                goto out;
-                       cond_resched();
+
+                       err = mtdtest_relax();
+                       if (err)
+                               goto out;
                }
 
                /* Verify what we wrote */
@@ -314,7 +320,10 @@ static int __init tort_init(void)
                                               "0x55AA55..." : "0xAA55AA...");
                                        goto out;
                                }
-                               cond_resched();
+
+                               err = mtdtest_relax();
+                               if (err)
+                                       goto out;
                        }
                }