Assert on opened/closed file handles
This adopts upstream opened/closed assertions, which are useful for
catching user mistakes (note the bug fixes in our tests):
- Assert if already open in lfsr_*_open
- Assert if not open in lfsr_file_* and lfsr_dir_* functions
- Assert if any files/dirs are still open in lfsr_unmount
Unfortunately this had a surprising code cost for what really should
have been a noop as far as the compiler is concerned. And saved a bit of
stack? Maybe our assertion hints are causing a surprising amount of code
movement? I'm really not sure what's going on and this deserves more
investigation:
code stack
before: 33686 2592
after: 33904 (+0.6%) 2584 (-0.3%)
At the very least this didn't add a noticable amount of testing time. I
was a bit concerned because our orphan/zombie testing grows opened-list
operations ~O(n^2), but any measurable overhead is less than how much
our test runtime swings between runs (+-~20s).
This commit is contained in:
@@ -323,6 +323,7 @@ code = '''
|
||||
lfs_ssize_t d = lfsr_file_write(&lfs, &file, wbuf, SIZE);
|
||||
assert(d == SIZE || d == LFS_ERR_NOSPC);
|
||||
if (d == LFS_ERR_NOSPC) {
|
||||
lfsr_file_close(&lfs, &file) => 0;
|
||||
goto dead;
|
||||
}
|
||||
err = lfsr_file_close(&lfs, &file);
|
||||
|
||||
@@ -581,6 +581,7 @@ code = '''
|
||||
assert(memcmp(wbuf, rbuf, CHUNK) == 0);
|
||||
}
|
||||
|
||||
lfsr_file_close(&lfs, &file__) => 0;
|
||||
lfsr_unmount(&lfs) => 0;
|
||||
'''
|
||||
|
||||
@@ -781,6 +782,7 @@ code = '''
|
||||
assert(memcmp(wbuf, rbuf, CHUNK) == 0);
|
||||
}
|
||||
|
||||
lfsr_file_close(&lfs, &file) => 0;
|
||||
lfsr_unmount(&lfs) => 0;
|
||||
'''
|
||||
|
||||
|
||||
Reference in New Issue
Block a user