Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/littlefs-project/littlefs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/bd
diff options
context:
space:
mode:
authorChristopher Haster <chaster@utexas.edu>2020-01-30 02:50:38 +0300
committerChristopher Haster <chaster@utexas.edu>2020-02-09 21:00:22 +0300
commit77e3078b9f28ff689e5a623250eae5c85ae8b3aa (patch)
tree6df4d5638a012fbe0da96dc974d3013b61e78102 /bd
parent517d3414c5e04eedb07be2e58107c1f96b8b8684 (diff)
Added/fixed tests for noop writes (where bd error can't be trusted)
It's interesting how many ways block devices can show failed writes: 1. prog can error 2. erase can error 3. read can error after writing (ECC failure) 4. prog doesn't error but doesn't write the data correctly 5. erase doesn't error but doesn't erase correctly Can read fail without an error? Yes, though this appears the same as prog and erase failing. These weren't all simulated by testbd since I unintentionally assumed the block device could always error. Fixed by added additional bad-black behaviors to testbd. Note: This also includes a small fix where we can miss bad writes if the underlying block device contains a valid commit with the exact same size in the exact same offset.
Diffstat (limited to 'bd')
-rw-r--r--bd/lfs_testbd.c31
-rw-r--r--bd/lfs_testbd.h20
2 files changed, 33 insertions, 18 deletions
diff --git a/bd/lfs_testbd.c b/bd/lfs_testbd.c
index 62cba01..8de7dcb 100644
--- a/bd/lfs_testbd.c
+++ b/bd/lfs_testbd.c
@@ -47,7 +47,7 @@ int lfs_testbd_createcfg(const struct lfs_config *cfg, const char *path,
memset(bd->wear, 0, sizeof(lfs_testbd_wear_t) * cfg->block_count);
}
-
+
// create underlying block device
if (bd->persist) {
bd->u.file.cfg = (struct lfs_filebd_config){
@@ -155,9 +155,8 @@ int lfs_testbd_read(const struct lfs_config *cfg, lfs_block_t block,
LFS_ASSERT(block < cfg->block_count);
// block bad?
- if (bd->cfg->erase_cycles &&
- bd->cfg->badblock_behavior == LFS_TESTBD_BADBLOCK_NOREAD &&
- bd->wear[block] >= bd->cfg->erase_cycles) {
+ if (bd->cfg->erase_cycles && bd->wear[block] >= bd->cfg->erase_cycles &&
+ bd->cfg->badblock_behavior == LFS_TESTBD_BADBLOCK_READERROR) {
LFS_TRACE("lfs_testbd_read -> %d", LFS_ERR_CORRUPT);
return LFS_ERR_CORRUPT;
}
@@ -180,11 +179,18 @@ int lfs_testbd_prog(const struct lfs_config *cfg, lfs_block_t block,
LFS_ASSERT(block < cfg->block_count);
// block bad?
- if (bd->cfg->erase_cycles &&
- bd->cfg->badblock_behavior == LFS_TESTBD_BADBLOCK_NOPROG &&
- bd->wear[block] >= bd->cfg->erase_cycles) {
- LFS_TRACE("lfs_testbd_prog -> %d", LFS_ERR_CORRUPT);
- return LFS_ERR_CORRUPT;
+ if (bd->cfg->erase_cycles && bd->wear[block] >= bd->cfg->erase_cycles) {
+ if (bd->cfg->badblock_behavior ==
+ LFS_TESTBD_BADBLOCK_PROGERROR) {
+ LFS_TRACE("lfs_testbd_prog -> %d", LFS_ERR_CORRUPT);
+ return LFS_ERR_CORRUPT;
+ } else if (bd->cfg->badblock_behavior ==
+ LFS_TESTBD_BADBLOCK_PROGNOOP ||
+ bd->cfg->badblock_behavior ==
+ LFS_TESTBD_BADBLOCK_ERASENOOP) {
+ LFS_TRACE("lfs_testbd_prog -> %d", 0);
+ return 0;
+ }
}
// prog
@@ -219,9 +225,14 @@ int lfs_testbd_erase(const struct lfs_config *cfg, lfs_block_t block) {
// block bad?
if (bd->cfg->erase_cycles) {
if (bd->wear[block] >= bd->cfg->erase_cycles) {
- if (bd->cfg->badblock_behavior == LFS_TESTBD_BADBLOCK_NOERASE) {
+ if (bd->cfg->badblock_behavior ==
+ LFS_TESTBD_BADBLOCK_ERASEERROR) {
LFS_TRACE("lfs_testbd_erase -> %d", LFS_ERR_CORRUPT);
return LFS_ERR_CORRUPT;
+ } else if (bd->cfg->badblock_behavior ==
+ LFS_TESTBD_BADBLOCK_ERASENOOP) {
+ LFS_TRACE("lfs_testbd_erase -> %d", 0);
+ return 0;
}
} else {
// mark wear
diff --git a/bd/lfs_testbd.h b/bd/lfs_testbd.h
index 78580d4..68180ac 100644
--- a/bd/lfs_testbd.h
+++ b/bd/lfs_testbd.h
@@ -19,14 +19,18 @@ extern "C"
#endif
-// Mode determining how "bad blocks" behave during testing. This
-// simulates some real-world circumstances such as writes not
-// going through (noprog), erases not sticking (noerase), and ECC
-// failures (noread).
+// Mode determining how "bad blocks" behave during testing. This simulates
+// some real-world circumstances such as progs not sticking (prog-noop),
+// a readonly disk (erase-noop), and ECC failures (read-error).
+//
+// Not that read-noop is not allowed. Read _must_ return a consistent (but
+// may be arbitrary) value on every read.
enum lfs_testbd_badblock_behavior {
- LFS_TESTBD_BADBLOCK_NOPROG = 0,
- LFS_TESTBD_BADBLOCK_NOERASE = 1,
- LFS_TESTBD_BADBLOCK_NOREAD = 2,
+ LFS_TESTBD_BADBLOCK_PROGERROR,
+ LFS_TESTBD_BADBLOCK_ERASEERROR,
+ LFS_TESTBD_BADBLOCK_READERROR,
+ LFS_TESTBD_BADBLOCK_PROGNOOP,
+ LFS_TESTBD_BADBLOCK_ERASENOOP,
};
// Type for measuring wear
@@ -82,7 +86,7 @@ typedef struct lfs_testbd {
/// Block device API ///
// Create a test block device using the geometry in lfs_config
-//
+//
// Note that filebd is used if a path is provided, if path is NULL
// testbd will use rambd which can be much faster.
int lfs_testbd_create(const struct lfs_config *cfg, const char *path);