Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: Richard Weinberger <richard@nod.at>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>

authored by

Richard Weinberger and committed by
Brian Norris
2a6a28e7 d2b51c80

+120 -24
+6
drivers/mtd/tests/mtd_nandecctest.c
··· 9 9 #include <linux/slab.h> 10 10 #include <linux/mtd/nand_ecc.h> 11 11 12 + #include "mtd_test.h" 13 + 12 14 /* 13 15 * Test the implementation for software ECC 14 16 * ··· 276 274 } 277 275 pr_info("ok - %s-%zd\n", 278 276 nand_ecc_test[i].name, size); 277 + 278 + err = mtdtest_relax(); 279 + if (err) 280 + break; 279 281 } 280 282 error: 281 283 kfree(error_data);
+12
drivers/mtd/tests/mtd_test.h
··· 1 1 #include <linux/mtd/mtd.h> 2 + #include <linux/sched.h> 3 + 4 + static inline int mtdtest_relax(void) 5 + { 6 + cond_resched(); 7 + if (signal_pending(current)) { 8 + pr_info("aborting test due to pending signal!\n"); 9 + return -EINTR; 10 + } 11 + 12 + return 0; 13 + } 2 14 3 15 int mtdtest_erase_eraseblock(struct mtd_info *mtd, unsigned int ebnum); 4 16 int mtdtest_scan_for_bad_eraseblocks(struct mtd_info *mtd, unsigned char *bbt,
+4
drivers/mtd/tests/nandbiterrs.c
··· 320 320 break; 321 321 } 322 322 323 + err = mtdtest_relax(); 324 + if (err) 325 + break; 326 + 323 327 opno++; 324 328 } 325 329
+21 -5
drivers/mtd/tests/oobtest.c
··· 112 112 return err; 113 113 if (i % 256 == 0) 114 114 pr_info("written up to eraseblock %u\n", i); 115 - cond_resched(); 115 + 116 + err = mtdtest_relax(); 117 + if (err) 118 + return err; 116 119 } 117 120 pr_info("written %u eraseblocks\n", i); 118 121 return 0; ··· 321 318 return err; 322 319 if (i % 256 == 0) 323 320 pr_info("verified up to eraseblock %u\n", i); 324 - cond_resched(); 321 + 322 + err = mtdtest_relax(); 323 + if (err) 324 + return err; 325 325 } 326 326 pr_info("verified %u eraseblocks\n", i); 327 327 return 0; ··· 435 429 goto out; 436 430 if (i % 256 == 0) 437 431 pr_info("verified up to eraseblock %u\n", i); 438 - cond_resched(); 432 + 433 + err = mtdtest_relax(); 434 + if (err) 435 + goto out; 439 436 } 440 437 pr_info("verified %u eraseblocks\n", i); 441 438 ··· 651 642 goto out; 652 643 if (i % 256 == 0) 653 644 pr_info("written up to eraseblock %u\n", i); 654 - cond_resched(); 645 + 646 + err = mtdtest_relax(); 647 + if (err) 648 + goto out; 649 + 655 650 addr += mtd->writesize; 656 651 } 657 652 } ··· 693 680 } 694 681 if (i % 256 == 0) 695 682 pr_info("verified up to eraseblock %u\n", i); 696 - cond_resched(); 683 + 684 + err = mtdtest_relax(); 685 + if (err) 686 + goto out; 697 687 } 698 688 pr_info("verified %u eraseblocks\n", i); 699 689
+8 -2
drivers/mtd/tests/pagetest.c
··· 407 407 goto out; 408 408 if (i % 256 == 0) 409 409 pr_info("written up to eraseblock %u\n", i); 410 - cond_resched(); 410 + 411 + err = mtdtest_relax(); 412 + if (err) 413 + goto out; 411 414 } 412 415 pr_info("written %u eraseblocks\n", i); 413 416 ··· 425 422 goto out; 426 423 if (i % 256 == 0) 427 424 pr_info("verified up to eraseblock %u\n", i); 428 - cond_resched(); 425 + 426 + err = mtdtest_relax(); 427 + if (err) 428 + goto out; 429 429 } 430 430 pr_info("verified %u eraseblocks\n", i); 431 431
+4 -1
drivers/mtd/tests/readtest.c
··· 190 190 if (!err) 191 191 err = ret; 192 192 } 193 - cond_resched(); 193 + 194 + err = mtdtest_relax(); 195 + if (err) 196 + goto out; 194 197 } 195 198 196 199 if (err)
+29 -7
drivers/mtd/tests/speedtest.c
··· 269 269 err = write_eraseblock(i); 270 270 if (err) 271 271 goto out; 272 - cond_resched(); 272 + 273 + err = mtdtest_relax(); 274 + if (err) 275 + goto out; 273 276 } 274 277 stop_timing(); 275 278 speed = calc_speed(); ··· 287 284 err = read_eraseblock(i); 288 285 if (err) 289 286 goto out; 290 - cond_resched(); 287 + 288 + err = mtdtest_relax(); 289 + if (err) 290 + goto out; 291 291 } 292 292 stop_timing(); 293 293 speed = calc_speed(); ··· 309 303 err = write_eraseblock_by_page(i); 310 304 if (err) 311 305 goto out; 312 - cond_resched(); 306 + 307 + err = mtdtest_relax(); 308 + if (err) 309 + goto out; 313 310 } 314 311 stop_timing(); 315 312 speed = calc_speed(); ··· 327 318 err = read_eraseblock_by_page(i); 328 319 if (err) 329 320 goto out; 330 - cond_resched(); 321 + 322 + err = mtdtest_relax(); 323 + if (err) 324 + goto out; 331 325 } 332 326 stop_timing(); 333 327 speed = calc_speed(); ··· 349 337 err = write_eraseblock_by_2pages(i); 350 338 if (err) 351 339 goto out; 352 - cond_resched(); 340 + 341 + err = mtdtest_relax(); 342 + if (err) 343 + goto out; 353 344 } 354 345 stop_timing(); 355 346 speed = calc_speed(); ··· 367 352 err = read_eraseblock_by_2pages(i); 368 353 if (err) 369 354 goto out; 370 - cond_resched(); 355 + 356 + err = mtdtest_relax(); 357 + if (err) 358 + goto out; 371 359 } 372 360 stop_timing(); 373 361 speed = calc_speed(); ··· 403 385 err = multiblock_erase(i, j); 404 386 if (err) 405 387 goto out; 406 - cond_resched(); 388 + 389 + err = mtdtest_relax(); 390 + if (err) 391 + goto out; 392 + 407 393 i += j; 408 394 } 409 395 stop_timing();
+4 -1
drivers/mtd/tests/stresstest.c
··· 221 221 err = do_operation(); 222 222 if (err) 223 223 goto out; 224 - cond_resched(); 224 + 225 + err = mtdtest_relax(); 226 + if (err) 227 + goto out; 225 228 } 226 229 pr_info("finished, %d operations done\n", op); 227 230
+20 -5
drivers/mtd/tests/subpagetest.c
··· 269 269 return err; 270 270 if (i % 256 == 0) 271 271 pr_info("verified up to eraseblock %u\n", i); 272 - cond_resched(); 272 + 273 + err = mtdtest_relax(); 274 + if (err) 275 + return err; 273 276 } 274 277 pr_info("verified %u eraseblocks\n", i); 275 278 return 0; ··· 349 346 goto out; 350 347 if (i % 256 == 0) 351 348 pr_info("written up to eraseblock %u\n", i); 352 - cond_resched(); 349 + 350 + err = mtdtest_relax(); 351 + if (err) 352 + goto out; 353 353 } 354 354 pr_info("written %u eraseblocks\n", i); 355 355 ··· 366 360 goto out; 367 361 if (i % 256 == 0) 368 362 pr_info("verified up to eraseblock %u\n", i); 369 - cond_resched(); 363 + 364 + err = mtdtest_relax(); 365 + if (err) 366 + goto out; 370 367 } 371 368 pr_info("verified %u eraseblocks\n", i); 372 369 ··· 392 383 goto out; 393 384 if (i % 256 == 0) 394 385 pr_info("written up to eraseblock %u\n", i); 395 - cond_resched(); 386 + 387 + err = mtdtest_relax(); 388 + if (err) 389 + goto out; 396 390 } 397 391 pr_info("written %u eraseblocks\n", i); 398 392 ··· 410 398 goto out; 411 399 if (i % 256 == 0) 412 400 pr_info("verified up to eraseblock %u\n", i); 413 - cond_resched(); 401 + 402 + err = mtdtest_relax(); 403 + if (err) 404 + goto out; 414 405 } 415 406 pr_info("verified %u eraseblocks\n", i); 416 407
+12 -3
drivers/mtd/tests/torturetest.c
··· 279 279 " for 0xFF... pattern\n"); 280 280 goto out; 281 281 } 282 - cond_resched(); 282 + 283 + err = mtdtest_relax(); 284 + if (err) 285 + goto out; 283 286 } 284 287 } 285 288 ··· 297 294 err = write_pattern(i, patt); 298 295 if (err) 299 296 goto out; 300 - cond_resched(); 297 + 298 + err = mtdtest_relax(); 299 + if (err) 300 + goto out; 301 301 } 302 302 303 303 /* Verify what we wrote */ ··· 320 314 "0x55AA55..." : "0xAA55AA..."); 321 315 goto out; 322 316 } 323 - cond_resched(); 317 + 318 + err = mtdtest_relax(); 319 + if (err) 320 + goto out; 324 321 } 325 322 } 326 323