From 10feccf18c01a5da09b1c6d463ceadbbc342f81d Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Mon, 12 Aug 2024 20:01:47 -0500 Subject: [PATCH] Moved ckprogs behind LFS_CKPROGS ifdef So just like ckreads, ckprogs is now opt-in, requiring both 1. defining LFS_CKPROGS at compile-time, and 2. passing the LFS_M_CKPROGS flag during lfsr_mount. _Unlike_ ckreads, ckprogs is actually a very lightweight feature. So the difference between compiling with/without ckprogs is really quite small: code stack before: 36480 2680 yes-ckprogs: 36480 (+0.0%) 2680 (+0.0%) no-ckprogs: 36428 (-0.1%) 2680 (+0.0%) It's almost not worth putting behind an ifdef if not for consistency with ckreads. --- lfs.c | 12 +- lfs.h | 6 + lfs_util.h | 12 +- tests/test_badblocks.toml | 227 +++++++++++++++++++++++++------------ tests/test_ck.toml | 3 + tests/test_exhaustion.toml | 37 +++--- tests/test_mount.toml | 14 ++- 7 files changed, 212 insertions(+), 99 deletions(-) diff --git a/lfs.c b/lfs.c index 398e9473..1d0ee6ba 100644 --- a/lfs.c +++ b/lfs.c @@ -295,7 +295,9 @@ static int lfsr_bd_read(lfs_t *lfs, } // needed in lfsr_bd_prog_ for prog validation +#ifdef LFS_CKPROGS static inline bool lfsr_m_isckprogs(uint32_t flags); +#endif static lfs_scmp_t lfsr_bd_cmp(lfs_t *lfs, lfs_block_t block, lfs_size_t off, lfs_size_t hint, const void *buffer, lfs_size_t size); @@ -314,6 +316,7 @@ static int lfsr_bd_prog_(lfs_t *lfs, lfs_block_t block, lfs_size_t off, return err; } + #ifdef LFS_CKPROGS // check progs? if (lfsr_m_isckprogs(lfs->flags)) { // pcache should have been dropped at this point @@ -335,6 +338,7 @@ static int lfsr_bd_prog_(lfs_t *lfs, lfs_block_t block, lfs_size_t off, return LFS_ERR_CORRUPT; } } + #endif // update rcache if we can if (block == lfs->rcache.block @@ -6681,9 +6685,11 @@ static inline bool lfsr_m_isrdonly(uint32_t flags) { return flags & LFS_M_RDONLY; } +#ifdef LFS_CKPROGS static inline bool lfsr_m_isckprogs(uint32_t flags) { return flags & LFS_M_CKPROGS; } +#endif #ifdef LFS_CKREADS static inline bool lfsr_m_isckreads(uint32_t flags) { @@ -13345,7 +13351,7 @@ int lfsr_mount(lfs_t *lfs, uint32_t flags, LFS_ASSERT((flags & ~( LFS_M_RDWR | LFS_M_RDONLY - | LFS_M_CKPROGS + | LFS_IFDEF_CKPROGS(LFS_M_CKPROGS, 0) | LFS_IFDEF_CKREADS(LFS_M_CKREADS, 0) | LFS_M_FLUSH | LFS_M_SYNC @@ -13501,7 +13507,7 @@ int lfsr_format(lfs_t *lfs, uint32_t flags, // unknown flags? LFS_ASSERT((flags & ~( LFS_F_RDWR - | LFS_F_CKPROGS + | LFS_IFDEF_CKPROGS(LFS_F_CKPROGS, 0) | LFS_IFDEF_CKREADS(LFS_F_CKREADS, 0) | LFS_F_MTREEONLY | LFS_F_COMPACT @@ -13566,7 +13572,7 @@ int lfsr_fs_stat(lfs_t *lfs, struct lfs_fsinfo *fsinfo) { // return various filesystem flags fsinfo->flags = lfs->flags & ( LFS_I_RDONLY - | LFS_I_CKPROGS + | LFS_IFDEF_CKPROGS(LFS_I_CKPROGS, 0) | LFS_IFDEF_CKREADS(LFS_I_CKREADS, 0) | LFS_I_FLUSH | LFS_I_SYNC diff --git a/lfs.h b/lfs.h index 68809a8e..79229eac 100644 --- a/lfs.h +++ b/lfs.h @@ -153,7 +153,9 @@ enum lfs_type { // Filesystem format flags #define LFS_F_RDWR 0 // Format the filesystem as read and write +#ifdef LFS_CKPROGS #define LFS_F_CKPROGS 0x00100000 // Check progs by reading back progged data +#endif #ifdef LFS_CKREADS #define LFS_F_CKREADS 0x00200000 // Check reads via parity bits/checksums #endif @@ -168,7 +170,9 @@ enum lfs_type { #define LFS_M_RDONLY 1 // Mount the filesystem as read only #define LFS_M_FLUSH 0x00000040 // Open all files with LFS_O_FLUSH #define LFS_M_SYNC 0x00000080 // Open all files with LFS_O_SYNC +#ifdef LFS_CKPROGS #define LFS_M_CKPROGS 0x00100000 // Check progs by reading back progged data +#endif #ifdef LFS_CKREADS #define LFS_M_CKREADS 0x00200000 // Check reads via parity bits/checksums #endif @@ -185,7 +189,9 @@ enum lfs_type { #define LFS_I_RDONLY 0x00000001 // Filesystem mounted read only #define LFS_I_FLUSH 0x00000040 // Filesystem mounted with LFS_M_FLUSH #define LFS_I_SYNC 0x00000080 // Filesystem mounted with LFS_M_SYNC +#ifdef LFS_CKPROGS #define LFS_I_CKPROGS 0x00100000 // Filesystem mounted with LFS_M_CKPROGS +#endif #ifdef LFS_CKREADS #define LFS_I_CKREADS 0x00200000 // Filesystem mounted with LFS_M_CKREADS #endif diff --git a/lfs_util.h b/lfs_util.h index e5ec8104..4d99d618 100644 --- a/lfs_util.h +++ b/lfs_util.h @@ -138,10 +138,16 @@ extern "C" // Some ifdef conveniences -#ifdef LFS_CKREADS -#define LFS_IFDEF_CKREADS(a, b) a +#ifdef LFS_CKPROGS +#define LFS_IFDEF_CKPROGS(a, b) (a) #else -#define LFS_IFDEF_CKREADS(a, b) b +#define LFS_IFDEF_CKPROGS(a, b) (b) +#endif + +#ifdef LFS_CKREADS +#define LFS_IFDEF_CKREADS(a, b) (a) +#else +#define LFS_IFDEF_CKREADS(a, b) (b) #endif diff --git a/tests/test_badblocks.toml b/tests/test_badblocks.toml index 1e6d047c..6678a982 100644 --- a/tests/test_badblocks.toml +++ b/tests/test_badblocks.toml @@ -35,6 +35,7 @@ defines.N = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512] defines.LOOKAHEAD_SIZE = 'lfs_alignup(BLOCK_COUNT / 8, 8)' defines.SEED = 42 fuzz = 'SEED' +if = 'LFS_IFDEF_CKPROGS(true, !CKPROGS)' in = 'lfs.c' code = ''' // test all possible bad blocks @@ -50,7 +51,7 @@ code = ''' lfs_t lfs; lfs_init(&lfs, LFS_M_RDWR - | ((CKPROGS) ? LFS_M_CKPROGS : 0), + | ((CKPROGS) ? LFS_IFDEF_CKPROGS(LFS_M_CKPROGS, -1) : 0), CFG) => 0; // create free lookahead memset(lfs.lookahead.buffer, 0, CFG->lookahead_size); @@ -142,6 +143,7 @@ defines.BADBLOCK_BEHAVIOR = [ # we need prog checking to detect read errors defines.CKPROGS = 'BADBLOCK_BEHAVIOR >= LFS_EMUBD_BADBLOCK_READERROR' defines.N = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512] +if = 'LFS_IFDEF_CKPROGS(true, !CKPROGS)' code = ''' // test all possible bad blocks for (lfs_size_t i = 2; @@ -156,11 +158,11 @@ code = ''' lfs_t lfs; lfsr_format(&lfs, LFS_F_RDWR - | ((CKPROGS) ? LFS_F_CKPROGS : 0), + | ((CKPROGS) ? LFS_IFDEF_CKPROGS(LFS_F_CKPROGS, -1) : 0), CFG) => 0; lfsr_mount(&lfs, LFS_M_RDWR - | ((CKPROGS) ? LFS_M_CKPROGS : 0), + | ((CKPROGS) ? LFS_IFDEF_CKPROGS(LFS_M_CKPROGS, -1) : 0), CFG) => 0; // make this many directories @@ -177,7 +179,9 @@ code = ''' lfsr_unmount(&lfs) => 0; lfsr_mount(&lfs, LFS_M_RDWR - | ((CKPROGS) ? LFS_M_CKPROGS : 0), + | ((CKPROGS) + ? LFS_IFDEF_CKPROGS(LFS_M_CKPROGS, -1) + : 0), CFG) => 0; } @@ -258,6 +262,7 @@ defines.N = [1, 2, 4, 8, 16, 32, 64, 128, 256] defines.OPS = '2*N' defines.SEED = 42 fuzz = 'SEED' +if = 'LFS_IFDEF_CKPROGS(true, !CKPROGS)' code = ''' // test all possible bad blocks for (lfs_size_t i = 2; @@ -272,11 +277,11 @@ code = ''' lfs_t lfs; lfsr_format(&lfs, LFS_F_RDWR - | ((CKPROGS) ? LFS_F_CKPROGS : 0), + | ((CKPROGS) ? LFS_IFDEF_CKPROGS(LFS_F_CKPROGS, -1) : 0), CFG) => 0; lfsr_mount(&lfs, LFS_M_RDWR - | ((CKPROGS) ? LFS_M_CKPROGS : 0), + | ((CKPROGS) ? LFS_IFDEF_CKPROGS(LFS_M_CKPROGS, -1) : 0), CFG) => 0; // set up a simulation to compare against @@ -373,7 +378,9 @@ code = ''' lfsr_unmount(&lfs) => 0; lfsr_mount(&lfs, LFS_M_RDWR - | ((CKPROGS) ? LFS_M_CKPROGS : 0), + | ((CKPROGS) + ? LFS_IFDEF_CKPROGS(LFS_M_CKPROGS, -1) + : 0), CFG) => 0; } @@ -448,7 +455,10 @@ defines.SIZE = [ '2*BLOCK_SIZE', '4*BLOCK_SIZE', ] -if = '(SIZE*N)/BLOCK_SIZE <= 32' +if = [ + 'LFS_IFDEF_CKPROGS(true, !CKPROGS)', + '(SIZE*N)/BLOCK_SIZE <= 32', +] code = ''' // test all possible bad blocks for (lfs_size_t i = 2; @@ -463,11 +473,11 @@ code = ''' lfs_t lfs; lfsr_format(&lfs, LFS_F_RDWR - | ((CKPROGS) ? LFS_F_CKPROGS : 0), + | ((CKPROGS) ? LFS_IFDEF_CKPROGS(LFS_F_CKPROGS, -1) : 0), CFG) => 0; lfsr_mount(&lfs, LFS_M_RDWR - | ((CKPROGS) ? LFS_M_CKPROGS : 0), + | ((CKPROGS) ? LFS_IFDEF_CKPROGS(LFS_M_CKPROGS, -1) : 0), CFG) => 0; // create this many files @@ -494,7 +504,9 @@ code = ''' lfsr_unmount(&lfs) => 0; lfsr_mount(&lfs, LFS_M_RDWR - | ((CKPROGS) ? LFS_M_CKPROGS : 0), + | ((CKPROGS) + ? LFS_IFDEF_CKPROGS(LFS_M_CKPROGS, -1) + : 0), CFG) => 0; } @@ -558,7 +570,10 @@ defines.SIZE = [ ] defines.SEED = 42 fuzz = 'SEED' -if = '(SIZE*N)/BLOCK_SIZE <= 16' +if = [ + 'LFS_IFDEF_CKPROGS(true, !CKPROGS)', + '(SIZE*N)/BLOCK_SIZE <= 16', +] code = ''' // test all possible bad blocks for (lfs_size_t i = 2; @@ -573,11 +588,11 @@ code = ''' lfs_t lfs; lfsr_format(&lfs, LFS_F_RDWR - | ((CKPROGS) ? LFS_F_CKPROGS : 0), + | ((CKPROGS) ? LFS_IFDEF_CKPROGS(LFS_F_CKPROGS, -1) : 0), CFG) => 0; lfsr_mount(&lfs, LFS_M_RDWR - | ((CKPROGS) ? LFS_M_CKPROGS : 0), + | ((CKPROGS) ? LFS_IFDEF_CKPROGS(LFS_M_CKPROGS, -1) : 0), CFG) => 0; // set up a simulation to compare against @@ -711,7 +726,9 @@ code = ''' lfsr_unmount(&lfs) => 0; lfsr_mount(&lfs, LFS_M_RDWR - | ((CKPROGS) ? LFS_M_CKPROGS : 0), + | ((CKPROGS) + ? LFS_IFDEF_CKPROGS(LFS_M_CKPROGS, -1) + : 0), CFG) => 0; } @@ -810,6 +827,7 @@ defines.SYNC = [false, true] defines.SEED = 42 fuzz = 'SEED' if = [ + 'LFS_IFDEF_CKPROGS(true, !CKPROGS)', 'CHUNK <= SIZE', # this just saves testing time 'SIZE <= 4*1024*FRAGMENT_SIZE', @@ -828,11 +846,11 @@ code = ''' lfs_t lfs; lfsr_format(&lfs, LFS_F_RDWR - | ((CKPROGS) ? LFS_F_CKPROGS : 0), + | ((CKPROGS) ? LFS_IFDEF_CKPROGS(LFS_F_CKPROGS, -1) : 0), CFG) => 0; lfsr_mount(&lfs, LFS_M_RDWR - | ((CKPROGS) ? LFS_M_CKPROGS : 0), + | ((CKPROGS) ? LFS_IFDEF_CKPROGS(LFS_M_CKPROGS, -1) : 0), CFG) => 0; // create a file @@ -897,7 +915,9 @@ code = ''' lfsr_unmount(&lfs) => 0; lfsr_mount(&lfs, LFS_M_RDWR - | ((CKPROGS) ? LFS_M_CKPROGS : 0), + | ((CKPROGS) + ? LFS_IFDEF_CKPROGS(LFS_M_CKPROGS, -1) + : 0), CFG) => 0; } @@ -972,7 +992,10 @@ defines.SIZE = [ ] defines.SEED = 42 fuzz = 'SEED' -if = '(SIZE*N)/BLOCK_SIZE <= 16' +if = [ + 'LFS_IFDEF_CKPROGS(true, !CKPROGS)', + '(SIZE*N)/BLOCK_SIZE <= 16', +] code = ''' // test all possible bad blocks for (lfs_size_t i = 2; @@ -987,11 +1010,11 @@ code = ''' lfs_t lfs; lfsr_format(&lfs, LFS_F_RDWR - | ((CKPROGS) ? LFS_F_CKPROGS : 0), + | ((CKPROGS) ? LFS_IFDEF_CKPROGS(LFS_F_CKPROGS, -1) : 0), CFG) => 0; lfsr_mount(&lfs, LFS_M_RDWR - | ((CKPROGS) ? LFS_M_CKPROGS : 0), + | ((CKPROGS) ? LFS_IFDEF_CKPROGS(LFS_M_CKPROGS, -1) : 0), CFG) => 0; // set up a simulation to compare against @@ -1341,7 +1364,10 @@ defines.SIZE = [ ] defines.SEED = 42 fuzz = 'SEED' -if = '(SIZE*N)/BLOCK_SIZE <= 16' +if = [ + 'LFS_IFDEF_CKPROGS(true, !CKPROGS)', + '(SIZE*N)/BLOCK_SIZE <= 16', +] code = ''' // test all possible bad blocks for (lfs_size_t i = 2; @@ -1356,11 +1382,11 @@ code = ''' lfs_t lfs; lfsr_format(&lfs, LFS_F_RDWR - | ((CKPROGS) ? LFS_F_CKPROGS : 0), + | ((CKPROGS) ? LFS_IFDEF_CKPROGS(LFS_F_CKPROGS, -1) : 0), CFG) => 0; lfsr_mount(&lfs, LFS_M_RDWR - | ((CKPROGS) ? LFS_M_CKPROGS : 0), + | ((CKPROGS) ? LFS_IFDEF_CKPROGS(LFS_M_CKPROGS, -1) : 0), CFG) => 0; // set up a simulation to compare against @@ -1790,6 +1816,7 @@ defines.N = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512] defines.LOOKAHEAD_SIZE = 'lfs_alignup(BLOCK_COUNT / 8, 8)' defines.SEED = 42 fuzz = 'SEED' +if = 'LFS_IFDEF_CKPROGS(true, !CKPROGS)' in = 'lfs.c' code = ''' // test a large region of bad blocks @@ -1806,7 +1833,7 @@ code = ''' lfs_t lfs; lfs_init(&lfs, LFS_M_RDWR - | ((CKPROGS) ? LFS_M_CKPROGS : 0), + | ((CKPROGS) ? LFS_IFDEF_CKPROGS(LFS_M_CKPROGS, -1) : 0), CFG) => 0; // create free lookahead memset(lfs.lookahead.buffer, 0, CFG->lookahead_size); @@ -1894,6 +1921,7 @@ defines.BADBLOCK_BEHAVIOR = [ defines.CKPROGS = 'BADBLOCK_BEHAVIOR >= LFS_EMUBD_BADBLOCK_READERROR' defines.MIRROR = [false, true] defines.N = [1, 2, 4, 8, 16, 32, 64, 128, 256] +if = 'LFS_IFDEF_CKPROGS(true, !CKPROGS)' code = ''' // test a large region of bad blocks for (lfs_size_t i = 0; i < BLOCK_COUNT/2; i++) { @@ -1913,11 +1941,11 @@ code = ''' lfs_t lfs; lfsr_format(&lfs, LFS_F_RDWR - | ((CKPROGS) ? LFS_F_CKPROGS : 0), + | ((CKPROGS) ? LFS_IFDEF_CKPROGS(LFS_F_CKPROGS, -1) : 0), CFG) => 0; lfsr_mount(&lfs, LFS_M_RDWR - | ((CKPROGS) ? LFS_M_CKPROGS : 0), + | ((CKPROGS) ? LFS_IFDEF_CKPROGS(LFS_M_CKPROGS, -1) : 0), CFG) => 0; // make this many directories @@ -1934,7 +1962,9 @@ code = ''' lfsr_unmount(&lfs) => 0; lfsr_mount(&lfs, LFS_M_RDWR - | ((CKPROGS) ? LFS_M_CKPROGS : 0), + | ((CKPROGS) + ? LFS_IFDEF_CKPROGS(LFS_M_CKPROGS, -1) + : 0), CFG) => 0; } @@ -2011,6 +2041,7 @@ defines.N = [1, 2, 4, 8, 16, 32, 64, 128, 256] defines.OPS = '2*N' defines.SEED = 42 fuzz = 'SEED' +if = 'LFS_IFDEF_CKPROGS(true, !CKPROGS)' code = ''' // test a large region of bad blocks for (lfs_size_t i = 0; i < BLOCK_COUNT/2; i++) { @@ -2030,11 +2061,11 @@ code = ''' lfs_t lfs; lfsr_format(&lfs, LFS_F_RDWR - | ((CKPROGS) ? LFS_F_CKPROGS : 0), + | ((CKPROGS) ? LFS_IFDEF_CKPROGS(LFS_F_CKPROGS, -1) : 0), CFG) => 0; lfsr_mount(&lfs, LFS_M_RDWR - | ((CKPROGS) ? LFS_M_CKPROGS : 0), + | ((CKPROGS) ? LFS_IFDEF_CKPROGS(LFS_M_CKPROGS, -1) : 0), CFG) => 0; // set up a simulation to compare against @@ -2131,7 +2162,9 @@ code = ''' lfsr_unmount(&lfs) => 0; lfsr_mount(&lfs, LFS_M_RDWR - | ((CKPROGS) ? LFS_M_CKPROGS : 0), + | ((CKPROGS) + ? LFS_IFDEF_CKPROGS(LFS_M_CKPROGS, -1) + : 0), CFG) => 0; } @@ -2202,7 +2235,10 @@ defines.SIZE = [ '2*BLOCK_SIZE', '4*BLOCK_SIZE', ] -if = '(SIZE*N)/BLOCK_SIZE <= 32' +if = [ + 'LFS_IFDEF_CKPROGS(true, !CKPROGS)', + '(SIZE*N)/BLOCK_SIZE <= 32', +] code = ''' // test a large region of bad blocks for (lfs_size_t i = 0; i < BLOCK_COUNT/2; i++) { @@ -2222,11 +2258,11 @@ code = ''' lfs_t lfs; lfsr_format(&lfs, LFS_F_RDWR - | ((CKPROGS) ? LFS_F_CKPROGS : 0), + | ((CKPROGS) ? LFS_IFDEF_CKPROGS(LFS_F_CKPROGS, -1) : 0), CFG) => 0; lfsr_mount(&lfs, LFS_M_RDWR - | ((CKPROGS) ? LFS_M_CKPROGS : 0), + | ((CKPROGS) ? LFS_IFDEF_CKPROGS(LFS_M_CKPROGS, -1) : 0), CFG) => 0; // create this many files @@ -2253,7 +2289,9 @@ code = ''' lfsr_unmount(&lfs) => 0; lfsr_mount(&lfs, LFS_M_RDWR - | ((CKPROGS) ? LFS_M_CKPROGS : 0), + | ((CKPROGS) + ? LFS_IFDEF_CKPROGS(LFS_M_CKPROGS, -1) + : 0), CFG) => 0; } @@ -2313,7 +2351,10 @@ defines.SIZE = [ ] defines.SEED = 42 fuzz = 'SEED' -if = '(SIZE*N)/BLOCK_SIZE <= 16' +if = [ + 'LFS_IFDEF_CKPROGS(true, !CKPROGS)', + '(SIZE*N)/BLOCK_SIZE <= 16', +] code = ''' // test a large region of bad blocks for (lfs_size_t i = 0; i < BLOCK_COUNT/2; i++) { @@ -2333,11 +2374,11 @@ code = ''' lfs_t lfs; lfsr_format(&lfs, LFS_F_RDWR - | ((CKPROGS) ? LFS_F_CKPROGS : 0), + | ((CKPROGS) ? LFS_IFDEF_CKPROGS(LFS_F_CKPROGS, -1) : 0), CFG) => 0; lfsr_mount(&lfs, LFS_M_RDWR - | ((CKPROGS) ? LFS_M_CKPROGS : 0), + | ((CKPROGS) ? LFS_IFDEF_CKPROGS(LFS_M_CKPROGS, -1) : 0), CFG) => 0; // set up a simulation to compare against @@ -2471,7 +2512,9 @@ code = ''' lfsr_unmount(&lfs) => 0; lfsr_mount(&lfs, LFS_M_RDWR - | ((CKPROGS) ? LFS_M_CKPROGS : 0), + | ((CKPROGS) + ? LFS_IFDEF_CKPROGS(LFS_M_CKPROGS, -1) + : 0), CFG) => 0; } @@ -2566,6 +2609,7 @@ defines.SYNC = [false, true] defines.SEED = 42 fuzz = 'SEED' if = [ + 'LFS_IFDEF_CKPROGS(true, !CKPROGS)', 'CHUNK <= SIZE', # this just saves testing time 'SIZE <= 4*1024*FRAGMENT_SIZE', @@ -2589,11 +2633,11 @@ code = ''' lfs_t lfs; lfsr_format(&lfs, LFS_F_RDWR - | ((CKPROGS) ? LFS_F_CKPROGS : 0), + | ((CKPROGS) ? LFS_IFDEF_CKPROGS(LFS_F_CKPROGS, -1) : 0), CFG) => 0; lfsr_mount(&lfs, LFS_M_RDWR - | ((CKPROGS) ? LFS_M_CKPROGS : 0), + | ((CKPROGS) ? LFS_IFDEF_CKPROGS(LFS_M_CKPROGS, -1) : 0), CFG) => 0; // create a file @@ -2658,7 +2702,9 @@ code = ''' lfsr_unmount(&lfs) => 0; lfsr_mount(&lfs, LFS_M_RDWR - | ((CKPROGS) ? LFS_M_CKPROGS : 0), + | ((CKPROGS) + ? LFS_IFDEF_CKPROGS(LFS_M_CKPROGS, -1) + : 0), CFG) => 0; } @@ -2729,7 +2775,10 @@ defines.SIZE = [ ] defines.SEED = 42 fuzz = 'SEED' -if = '(SIZE*N)/BLOCK_SIZE <= 16' +if = [ + 'LFS_IFDEF_CKPROGS(true, !CKPROGS)', + '(SIZE*N)/BLOCK_SIZE <= 16', +] code = ''' // test a large region of bad blocks for (lfs_size_t i = 0; i < BLOCK_COUNT/2; i++) { @@ -2749,11 +2798,11 @@ code = ''' lfs_t lfs; lfsr_format(&lfs, LFS_F_RDWR - | ((CKPROGS) ? LFS_F_CKPROGS : 0), + | ((CKPROGS) ? LFS_IFDEF_CKPROGS(LFS_F_CKPROGS, -1) : 0), CFG) => 0; lfsr_mount(&lfs, LFS_M_RDWR - | ((CKPROGS) ? LFS_M_CKPROGS : 0), + | ((CKPROGS) ? LFS_IFDEF_CKPROGS(LFS_M_CKPROGS, -1) : 0), CFG) => 0; // set up a simulation to compare against @@ -3099,7 +3148,10 @@ defines.SIZE = [ ] defines.SEED = 42 fuzz = 'SEED' -if = '(SIZE*N)/BLOCK_SIZE <= 16' +if = [ + 'LFS_IFDEF_CKPROGS(true, !CKPROGS)', + '(SIZE*N)/BLOCK_SIZE <= 16' +] code = ''' // test a large region of bad blocks for (lfs_size_t i = 0; i < BLOCK_COUNT/2; i++) { @@ -3119,11 +3171,11 @@ code = ''' lfs_t lfs; lfsr_format(&lfs, LFS_F_RDWR - | ((CKPROGS) ? LFS_F_CKPROGS : 0), + | ((CKPROGS) ? LFS_IFDEF_CKPROGS(LFS_F_CKPROGS, -1) : 0), CFG) => 0; lfsr_mount(&lfs, LFS_M_RDWR - | ((CKPROGS) ? LFS_M_CKPROGS : 0), + | ((CKPROGS) ? LFS_IFDEF_CKPROGS(LFS_M_CKPROGS, -1) : 0), CFG) => 0; // set up a simulation to compare against @@ -3546,6 +3598,7 @@ defines.N = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512] defines.LOOKAHEAD_SIZE = 'lfs_alignup(BLOCK_COUNT / 8, 8)' defines.SEED = 42 fuzz = 'SEED' +if = 'LFS_IFDEF_CKPROGS(true, !CKPROGS)' in = 'lfs.c' code = ''' // test a large region of bad blocks @@ -3562,7 +3615,7 @@ code = ''' lfs_t lfs; lfs_init(&lfs, LFS_M_RDWR - | ((CKPROGS) ? LFS_M_CKPROGS : 0), + | ((CKPROGS) ? LFS_IFDEF_CKPROGS(LFS_M_CKPROGS, -1) : 0), CFG) => 0; // create free lookahead memset(lfs.lookahead.buffer, 0, CFG->lookahead_size); @@ -3650,6 +3703,7 @@ defines.BADBLOCK_BEHAVIOR = [ defines.CKPROGS = 'BADBLOCK_BEHAVIOR >= LFS_EMUBD_BADBLOCK_READERROR' defines.MIRROR = [false, true] defines.N = [1, 2, 4, 8, 16, 32, 64, 128, 256] +if = 'LFS_IFDEF_CKPROGS(true, !CKPROGS)' code = ''' // test a large region of bad blocks for (lfs_size_t i = 0; i < BLOCK_COUNT/2; i++) { @@ -3669,11 +3723,11 @@ code = ''' lfs_t lfs; lfsr_format(&lfs, LFS_F_RDWR - | ((CKPROGS) ? LFS_F_CKPROGS : 0), + | ((CKPROGS) ? LFS_IFDEF_CKPROGS(LFS_F_CKPROGS, -1) : 0), CFG) => 0; lfsr_mount(&lfs, LFS_M_RDWR - | ((CKPROGS) ? LFS_M_CKPROGS : 0), + | ((CKPROGS) ? LFS_IFDEF_CKPROGS(LFS_M_CKPROGS, -1) : 0), CFG) => 0; // make this many directories @@ -3690,7 +3744,9 @@ code = ''' lfsr_unmount(&lfs) => 0; lfsr_mount(&lfs, LFS_M_RDWR - | ((CKPROGS) ? LFS_M_CKPROGS : 0), + | ((CKPROGS) + ? LFS_IFDEF_CKPROGS(LFS_M_CKPROGS, -1) + : 0), CFG) => 0; } @@ -3767,6 +3823,7 @@ defines.N = [1, 2, 4, 8, 16, 32, 64, 128, 256] defines.OPS = '2*N' defines.SEED = 42 fuzz = 'SEED' +if = 'LFS_IFDEF_CKPROGS(true, !CKPROGS)' code = ''' // test a large region of bad blocks for (lfs_size_t i = 0; i < BLOCK_COUNT/2; i++) { @@ -3786,11 +3843,11 @@ code = ''' lfs_t lfs; lfsr_format(&lfs, LFS_F_RDWR - | ((CKPROGS) ? LFS_F_CKPROGS : 0), + | ((CKPROGS) ? LFS_IFDEF_CKPROGS(LFS_F_CKPROGS, -1) : 0), CFG) => 0; lfsr_mount(&lfs, LFS_M_RDWR - | ((CKPROGS) ? LFS_M_CKPROGS : 0), + | ((CKPROGS) ? LFS_IFDEF_CKPROGS(LFS_M_CKPROGS, -1) : 0), CFG) => 0; // set up a simulation to compare against @@ -3887,7 +3944,9 @@ code = ''' lfsr_unmount(&lfs) => 0; lfsr_mount(&lfs, LFS_M_RDWR - | ((CKPROGS) ? LFS_M_CKPROGS : 0), + | ((CKPROGS) + ? LFS_IFDEF_CKPROGS(LFS_M_CKPROGS, -1) + : 0), CFG) => 0; } @@ -3958,7 +4017,10 @@ defines.SIZE = [ '2*BLOCK_SIZE', '4*BLOCK_SIZE', ] -if = '(SIZE*N)/BLOCK_SIZE <= 32' +if = [ + 'LFS_IFDEF_CKPROGS(true, !CKPROGS)', + '(SIZE*N)/BLOCK_SIZE <= 32', +] code = ''' // test a large region of bad blocks for (lfs_size_t i = 0; i < BLOCK_COUNT/2; i++) { @@ -3978,11 +4040,11 @@ code = ''' lfs_t lfs; lfsr_format(&lfs, LFS_F_RDWR - | ((CKPROGS) ? LFS_F_CKPROGS : 0), + | ((CKPROGS) ? LFS_IFDEF_CKPROGS(LFS_F_CKPROGS, -1) : 0), CFG) => 0; lfsr_mount(&lfs, LFS_M_RDWR - | ((CKPROGS) ? LFS_M_CKPROGS : 0), + | ((CKPROGS) ? LFS_IFDEF_CKPROGS(LFS_M_CKPROGS, -1) : 0), CFG) => 0; // create this many files @@ -4009,7 +4071,9 @@ code = ''' lfsr_unmount(&lfs) => 0; lfsr_mount(&lfs, LFS_M_RDWR - | ((CKPROGS) ? LFS_M_CKPROGS : 0), + | ((CKPROGS) + ? LFS_IFDEF_CKPROGS(LFS_M_CKPROGS, -1) + : 0), CFG) => 0; } @@ -4069,7 +4133,10 @@ defines.SIZE = [ ] defines.SEED = 42 fuzz = 'SEED' -if = '(SIZE*N)/BLOCK_SIZE <= 16' +if = [ + 'LFS_IFDEF_CKPROGS(true, !CKPROGS)', + '(SIZE*N)/BLOCK_SIZE <= 16', +] code = ''' // test a large region of bad blocks for (lfs_size_t i = 0; i < BLOCK_COUNT/2; i++) { @@ -4089,11 +4156,11 @@ code = ''' lfs_t lfs; lfsr_format(&lfs, LFS_F_RDWR - | ((CKPROGS) ? LFS_F_CKPROGS : 0), + | ((CKPROGS) ? LFS_IFDEF_CKPROGS(LFS_F_CKPROGS, -1) : 0), CFG) => 0; lfsr_mount(&lfs, LFS_M_RDWR - | ((CKPROGS) ? LFS_M_CKPROGS : 0), + | ((CKPROGS) ? LFS_IFDEF_CKPROGS(LFS_M_CKPROGS, -1) : 0), CFG) => 0; // set up a simulation to compare against @@ -4227,7 +4294,9 @@ code = ''' lfsr_unmount(&lfs) => 0; lfsr_mount(&lfs, LFS_M_RDWR - | ((CKPROGS) ? LFS_M_CKPROGS : 0), + | ((CKPROGS) + ? LFS_IFDEF_CKPROGS(LFS_M_CKPROGS, -1) + : 0), CFG) => 0; } @@ -4322,6 +4391,7 @@ defines.SYNC = [false, true] defines.SEED = 42 fuzz = 'SEED' if = [ + 'LFS_IFDEF_CKPROGS(true, !CKPROGS)', 'CHUNK <= SIZE', # this just saves testing time 'SIZE <= 4*1024*FRAGMENT_SIZE', @@ -4345,11 +4415,11 @@ code = ''' lfs_t lfs; lfsr_format(&lfs, LFS_F_RDWR - | ((CKPROGS) ? LFS_F_CKPROGS : 0), + | ((CKPROGS) ? LFS_IFDEF_CKPROGS(LFS_F_CKPROGS, -1) : 0), CFG) => 0; lfsr_mount(&lfs, LFS_M_RDWR - | ((CKPROGS) ? LFS_M_CKPROGS : 0), + | ((CKPROGS) ? LFS_IFDEF_CKPROGS(LFS_M_CKPROGS, -1) : 0), CFG) => 0; // create a file @@ -4412,7 +4482,9 @@ code = ''' lfsr_unmount(&lfs) => 0; lfsr_mount(&lfs, LFS_M_RDWR - | ((CKPROGS) ? LFS_M_CKPROGS : 0), + | ((CKPROGS) + ? LFS_IFDEF_CKPROGS(LFS_M_CKPROGS, -1) + : 0), CFG) => 0; } @@ -4483,7 +4555,10 @@ defines.SIZE = [ ] defines.SEED = 42 fuzz = 'SEED' -if = '(SIZE*N)/BLOCK_SIZE <= 16' +if = [ + 'LFS_IFDEF_CKPROGS(true, !CKPROGS)', + '(SIZE*N)/BLOCK_SIZE <= 16', +] code = ''' // test a large region of bad blocks for (lfs_size_t i = 0; i < BLOCK_COUNT/2; i++) { @@ -4503,11 +4578,11 @@ code = ''' lfs_t lfs; lfsr_format(&lfs, LFS_F_RDWR - | ((CKPROGS) ? LFS_F_CKPROGS : 0), + | ((CKPROGS) ? LFS_IFDEF_CKPROGS(LFS_F_CKPROGS, -1) : 0), CFG) => 0; lfsr_mount(&lfs, LFS_M_RDWR - | ((CKPROGS) ? LFS_M_CKPROGS : 0), + | ((CKPROGS) ? LFS_IFDEF_CKPROGS(LFS_M_CKPROGS, -1) : 0), CFG) => 0; // set up a simulation to compare against @@ -4853,7 +4928,10 @@ defines.SIZE = [ ] defines.SEED = 42 fuzz = 'SEED' -if = '(SIZE*N)/BLOCK_SIZE <= 16' +if = [ + 'LFS_IFDEF_CKPROGS(true, !CKPROGS)', + '(SIZE*N)/BLOCK_SIZE <= 16', +] code = ''' // test a large region of bad blocks for (lfs_size_t i = 0; i < BLOCK_COUNT/2; i++) { @@ -4873,11 +4951,11 @@ code = ''' lfs_t lfs; lfsr_format(&lfs, LFS_F_RDWR - | ((CKPROGS) ? LFS_F_CKPROGS : 0), + | ((CKPROGS) ? LFS_IFDEF_CKPROGS(LFS_F_CKPROGS, -1) : 0), CFG) => 0; lfsr_mount(&lfs, LFS_M_RDWR - | ((CKPROGS) ? LFS_M_CKPROGS : 0), + | ((CKPROGS) ? LFS_IFDEF_CKPROGS(LFS_M_CKPROGS, -1) : 0), CFG) => 0; // set up a simulation to compare against @@ -5313,11 +5391,12 @@ defines.BADBLOCK_BEHAVIOR = [ ] # we need prog checking to detect read errors defines.CKPROGS = 'BADBLOCK_BEHAVIOR >= LFS_EMUBD_BADBLOCK_READERROR' +if = 'LFS_IFDEF_CKPROGS(true, !CKPROGS)' code = ''' lfs_t lfs; lfsr_format(&lfs, LFS_M_RDWR - | ((CKPROGS) ? LFS_M_CKPROGS : 0), + | ((CKPROGS) ? LFS_IFDEF_CKPROGS(LFS_M_CKPROGS, -1) : 0), CFG) => 0; if (BADBLOCKS & 0x1) { @@ -5329,7 +5408,7 @@ code = ''' lfsr_mount(&lfs, LFS_M_RDWR - | ((CKPROGS) ? LFS_M_CKPROGS : 0), + | ((CKPROGS) ? LFS_IFDEF_CKPROGS(LFS_M_CKPROGS, -1) : 0), CFG) => 0; for (lfs_size_t i = 0;; i++) { diff --git a/tests/test_ck.toml b/tests/test_ck.toml index cfdb628d..59b5385a 100644 --- a/tests/test_ck.toml +++ b/tests/test_ck.toml @@ -477,6 +477,7 @@ defines.BADBIT = -1 defines.BADBLOCK_BEHAVIOR = 'LFS_EMUBD_BADBLOCK_PROGFLIP' # this should stay inlined defines.SIZE = 'BLOCK_SIZE/16' +ifdef = 'LFS_CKPROGS' code = ''' // test all bad bits in the mroot for (lfs_size_t i = 0; @@ -555,6 +556,7 @@ defines.BADBIT = -1 defines.BADBLOCK_BEHAVIOR = 'LFS_EMUBD_BADBLOCK_PROGFLIP' # this should create a single block file defines.SIZE = 'BLOCK_SIZE' +ifdef = 'LFS_CKPROGS' code = ''' // first we need to figure out where the data block will actually // end up, fortunately our block randomization is intentionally @@ -664,6 +666,7 @@ defines.INLINE_SIZE = 0 defines.CRYSTAL_THRESH = -1 defines.FRAGMENT_SIZE = 'BLOCK_SIZE/8' defines.SIZE = '2*FRAGMENT_SIZE' +ifdef = 'LFS_CKPROGS' code = ''' // first we need to figure out where the btree block will actually // end up, fortunately our block randomization is intentionally diff --git a/tests/test_exhaustion.toml b/tests/test_exhaustion.toml index 1b79745c..1616c7de 100644 --- a/tests/test_exhaustion.toml +++ b/tests/test_exhaustion.toml @@ -36,6 +36,7 @@ defines.CKPROGS = 'BADBLOCK_BEHAVIOR >= LFS_EMUBD_BADBLOCK_READERROR' defines.N = [1, 2, 4, 8, 16, 32, 64, 128, 256] defines.SEED = 42 fuzz = 'SEED' +if = 'LFS_IFDEF_CKPROGS(true, !CKPROGS)' code = ''' // run our test twice, once with 1/2 the storage, once with 2/2 the // storage, and compare how many operations we were able to perform @@ -57,11 +58,11 @@ code = ''' lfs_t lfs; lfsr_format(&lfs, LFS_F_RDWR - | ((CKPROGS) ? LFS_F_CKPROGS : 0), + | ((CKPROGS) ? LFS_IFDEF_CKPROGS(LFS_F_CKPROGS, -1) : 0), &cfg) => 0; lfsr_mount(&lfs, LFS_M_RDWR - | ((CKPROGS) ? LFS_M_CKPROGS : 0), + | ((CKPROGS) ? LFS_IFDEF_CKPROGS(LFS_M_CKPROGS, -1) : 0), &cfg) => 0; // set up a simulation to compare against @@ -250,7 +251,10 @@ defines.SIZE = [ ] defines.SEED = 42 fuzz = 'SEED' -if = '(SIZE*N)/BLOCK_SIZE <= 16' +if = [ + 'LFS_IFDEF_CKPROGS(true, !CKPROGS)', + '(SIZE*N)/BLOCK_SIZE <= 16', +] code = ''' // run our test twice, once with 1/2 the storage, once with 2/2 the // storage, and compare how many operations we were able to perform @@ -272,11 +276,11 @@ code = ''' lfs_t lfs; lfsr_format(&lfs, LFS_F_RDWR - | ((CKPROGS) ? LFS_F_CKPROGS : 0), + | ((CKPROGS) ? LFS_IFDEF_CKPROGS(LFS_F_CKPROGS, -1) : 0), &cfg) => 0; lfsr_mount(&lfs, LFS_M_RDWR - | ((CKPROGS) ? LFS_M_CKPROGS : 0), + | ((CKPROGS) ? LFS_IFDEF_CKPROGS(LFS_M_CKPROGS, -1) : 0), &cfg) => 0; // set up a simulation to compare against @@ -534,6 +538,7 @@ defines.SYNC = [false, true] defines.SEED = 42 fuzz = 'SEED' if = [ + 'LFS_IFDEF_CKPROGS(true, !CKPROGS)', 'CHUNK <= SIZE', # this just saves testing time 'SIZE <= 4*1024*FRAGMENT_SIZE', @@ -559,11 +564,11 @@ code = ''' lfs_t lfs; lfsr_format(&lfs, LFS_F_RDWR - | ((CKPROGS) ? LFS_F_CKPROGS : 0), + | ((CKPROGS) ? LFS_IFDEF_CKPROGS(LFS_F_CKPROGS, -1) : 0), &cfg) => 0; lfsr_mount(&lfs, LFS_M_RDWR - | ((CKPROGS) ? LFS_M_CKPROGS : 0), + | ((CKPROGS) ? LFS_IFDEF_CKPROGS(LFS_M_CKPROGS, -1) : 0), &cfg) => 0; // create a file @@ -714,7 +719,10 @@ defines.SIZE = [ ] defines.SEED = 42 fuzz = 'SEED' -if = '(SIZE*N)/BLOCK_SIZE <= 16' +if = [ + 'LFS_IFDEF_CKPROGS(true, !CKPROGS)', + '(SIZE*N)/BLOCK_SIZE <= 16', +] code = ''' // run our test twice, once with 1/2 the storage, once with 2/2 the // storage, and compare how many operations we were able to perform @@ -736,11 +744,11 @@ code = ''' lfs_t lfs; lfsr_format(&lfs, LFS_F_RDWR - | ((CKPROGS) ? LFS_F_CKPROGS : 0), + | ((CKPROGS) ? LFS_IFDEF_CKPROGS(LFS_F_CKPROGS, -1) : 0), &cfg) => 0; lfsr_mount(&lfs, LFS_M_RDWR - | ((CKPROGS) ? LFS_M_CKPROGS : 0), + | ((CKPROGS) ? LFS_IFDEF_CKPROGS(LFS_M_CKPROGS, -1) : 0), &cfg) => 0; // set up a simulation to compare against @@ -1133,7 +1141,10 @@ defines.SIZE = [ ] defines.SEED = 42 fuzz = 'SEED' -if = '(SIZE*N)/BLOCK_SIZE <= 16' +if = [ + 'LFS_IFDEF_CKPROGS(true, !CKPROGS)', + '(SIZE*N)/BLOCK_SIZE <= 16', +] code = ''' // run our test twice, once with 1/2 the storage, once with 2/2 the // storage, and compare how many operations we were able to perform @@ -1155,11 +1166,11 @@ code = ''' lfs_t lfs; lfsr_format(&lfs, LFS_F_RDWR - | ((CKPROGS) ? LFS_F_CKPROGS : 0), + | ((CKPROGS) ? LFS_IFDEF_CKPROGS(LFS_F_CKPROGS, -1) : 0), &cfg) => 0; lfsr_mount(&lfs, LFS_M_RDWR - | ((CKPROGS) ? LFS_M_CKPROGS : 0), + | ((CKPROGS) ? LFS_IFDEF_CKPROGS(LFS_M_CKPROGS, -1) : 0), &cfg) => 0; // set up a simulation to compare against diff --git a/tests/test_mount.toml b/tests/test_mount.toml index deea68eb..0772758b 100644 --- a/tests/test_mount.toml +++ b/tests/test_mount.toml @@ -26,6 +26,7 @@ defines.COMPACT = [false, true] defines.CKMETA = [false, true] defines.CKDATA = [false, true] if = [ + 'LFS_IFDEF_CKPROGS(true, !CKPROGS)', 'LFS_IFDEF_CKREADS(true, !CKREADS)', '!RDONLY || !MKCONSISTENT', '!RDONLY || !LOOKAHEAD', @@ -38,8 +39,8 @@ code = ''' lfsr_format(&lfs, LFS_F_RDWR, CFG) => 0; lfsr_mount(&lfs, ((RDONLY) ? LFS_M_RDONLY : LFS_M_RDWR) - | ((CKPROGS) ? LFS_M_CKPROGS : 0) - | ((CKREADS) ? LFS_IFDEF_CKREADS(LFS_M_CKREADS, 0) : 0) + | ((CKPROGS) ? LFS_IFDEF_CKPROGS(LFS_M_CKPROGS, -1) : 0) + | ((CKREADS) ? LFS_IFDEF_CKREADS(LFS_M_CKREADS, -1) : 0) | ((FLUSH) ? LFS_M_FLUSH : 0) | ((SYNC) ? LFS_M_SYNC : 0) | ((MTREEONLY) ? LFS_M_MTREEONLY : 0) @@ -55,8 +56,8 @@ code = ''' lfsr_fs_stat(&lfs, &fsinfo) => 0; assert(fsinfo.flags == ( ((RDONLY) ? LFS_I_RDONLY : 0) - | ((CKPROGS) ? LFS_I_CKPROGS : 0) - | ((CKREADS) ? LFS_IFDEF_CKREADS(LFS_I_CKREADS, 0) : 0) + | ((CKPROGS) ? LFS_IFDEF_CKPROGS(LFS_I_CKPROGS, -1) : 0) + | ((CKREADS) ? LFS_IFDEF_CKREADS(LFS_I_CKREADS, -1) : 0) | ((FLUSH) ? LFS_I_FLUSH : 0) | ((SYNC) ? LFS_I_SYNC : 0) | ((!LOOKAHEAD) ? LFS_I_CANLOOKAHEAD : 0) @@ -76,6 +77,7 @@ defines.COMPACT = [false, true] defines.CKMETA = [false, true] defines.CKDATA = [false, true] if = [ + 'LFS_IFDEF_CKPROGS(true, !CKPROGS)', 'LFS_IFDEF_CKREADS(true, !CKREADS)', '!MTREEONLY || !CKDATA', ] @@ -83,8 +85,8 @@ code = ''' lfs_t lfs; lfsr_format(&lfs, LFS_F_RDWR - | ((CKPROGS) ? LFS_F_CKPROGS : 0) - | ((CKREADS) ? LFS_IFDEF_CKREADS(LFS_F_CKREADS, 0) : 0) + | ((CKPROGS) ? LFS_IFDEF_CKPROGS(LFS_F_CKPROGS, -1) : 0) + | ((CKREADS) ? LFS_IFDEF_CKREADS(LFS_F_CKREADS, -1) : 0) | ((MTREEONLY) ? LFS_M_MTREEONLY : 0) | ((COMPACT) ? LFS_M_COMPACT : 0) | ((CKMETA) ? LFS_M_CKMETA : 0)