2018-07-06 18:13:36 +00:00
|
|
|
TARGET = lfs.a
|
|
|
|
ifneq ($(wildcard test.c main.c),)
|
|
|
|
override TARGET = lfs
|
|
|
|
endif
|
2017-02-25 20:31:14 +00:00
|
|
|
|
2018-02-18 20:22:24 +00:00
|
|
|
CC ?= gcc
|
|
|
|
AR ?= ar
|
|
|
|
SIZE ?= size
|
2017-02-25 20:31:14 +00:00
|
|
|
|
2020-01-27 03:37:49 +00:00
|
|
|
SRC += $(wildcard *.c bd/*.c)
|
2017-02-25 20:31:14 +00:00
|
|
|
OBJ := $(SRC:.c=.o)
|
|
|
|
DEP := $(SRC:.c=.d)
|
|
|
|
ASM := $(SRC:.c=.s)
|
|
|
|
|
|
|
|
ifdef DEBUG
|
2018-01-29 17:30:53 +00:00
|
|
|
override CFLAGS += -O0 -g3
|
2017-02-25 20:31:14 +00:00
|
|
|
else
|
2018-01-29 17:30:53 +00:00
|
|
|
override CFLAGS += -Os
|
2017-02-25 20:31:14 +00:00
|
|
|
endif
|
|
|
|
ifdef WORD
|
2018-01-29 17:30:53 +00:00
|
|
|
override CFLAGS += -m$(WORD)
|
2017-02-25 20:31:14 +00:00
|
|
|
endif
|
2019-05-31 09:40:19 +00:00
|
|
|
ifdef TRACE
|
|
|
|
override CFLAGS += -DLFS_YES_TRACE
|
|
|
|
endif
|
2018-01-29 17:30:53 +00:00
|
|
|
override CFLAGS += -I.
|
2018-09-26 15:11:40 +00:00
|
|
|
override CFLAGS += -std=c99 -Wall -pedantic
|
2019-08-07 21:58:13 +00:00
|
|
|
override CFLAGS += -Wextra -Wshadow -Wjump-misses-init -Wundef
|
2019-02-12 06:11:01 +00:00
|
|
|
# Remove missing-field-initializers because of GCC bug
|
|
|
|
override CFLAGS += -Wno-missing-field-initializers
|
2017-02-25 20:31:14 +00:00
|
|
|
|
2020-01-27 03:37:49 +00:00
|
|
|
ifdef VERBOSE
|
|
|
|
override TFLAGS += -v
|
|
|
|
endif
|
|
|
|
|
2017-02-25 20:31:14 +00:00
|
|
|
|
|
|
|
all: $(TARGET)
|
|
|
|
|
|
|
|
asm: $(ASM)
|
|
|
|
|
|
|
|
size: $(OBJ)
|
|
|
|
$(SIZE) -t $^
|
|
|
|
|
2020-01-27 03:37:49 +00:00
|
|
|
test:
|
|
|
|
./scripts/test.py $(TFLAGS)
|
|
|
|
.SECONDEXPANSION:
|
|
|
|
test%: tests/test$$(firstword $$(subst \#, ,%)).toml
|
Fixed more bugs, mostly related to ENOSPC on different geometries
Fixes:
- Fixed reproducability issue when we can't read a directory revision
- Fixed incorrect erase assumption if lfs_dir_fetch exceeds block size
- Fixed cleanup issue caused by lfs_fs_relocate failing when trying to
outline a file in lfs_file_sync
- Fixed cleanup issue if we run out of space while extending a CTZ skip-list
- Fixed missing half-orphans when allocating blocks during lfs_fs_deorphan
Also:
- Added cycle-detection to readtree.py
- Allowed pseudo-C expressions in test conditions (and it's
beautifully hacky, see line 187 of test.py)
- Better handling of ctrl-C during test runs
- Added build-only mode to test.py
- Limited stdout of test failures to 5 lines unless in verbose mode
Explanation of fixes below
1. Fixed reproducability issue when we can't read a directory revision
An interesting subtlety of the block-device layer is that the
block-device is allowed to return LFS_ERR_CORRUPT on reads to
untouched blocks. This can easily happen if a user is using ECC or
some sort of CMAC on their blocks. Normally we never run into this,
except for the optimization around directory revisions where we use
uninitialized data to start our revision count.
We correctly handle this case by ignoring whats on disk if the read
fails, but end up using unitialized RAM instead. This is not an issue
for normal use, though it can lead to a small information leak.
However it creates a big problem for reproducability, which is very
helpful for debugging.
I ended up running into a case where the RAM values for the revision
count was different, causing two identical runs to wear-level at
different times, leading to one version running out of space before a
bug occured because it expanded the superblock early.
2. Fixed incorrect erase assumption if lfs_dir_fetch exceeds block size
This could be caused if the previous tag was a valid commit and we
lost power causing a partially written tag as the start of a new
commit.
Fortunately we already have a separate condition for exceeding the
block size, so we can force that case to always treat the mdir as
unerased.
3. Fixed cleanup issue caused by lfs_fs_relocate failing when trying to
outline a file in lfs_file_sync
Most operations involving metadata-pairs treat the mdir struct as
entirely temporary and throw it out if any error occurs. Except for
lfs_file_sync since the mdir is also a part of the file struct.
This is relevant because of a cleanup issue in lfs_dir_compact that
usually doesn't have side-effects. The issue is that lfs_fs_relocate
can fail. It needs to allocate new blocks to relocate to, and as the
disk reaches its end of life, it can fail with ENOSPC quite often.
If lfs_fs_relocate fails, the containing lfs_dir_compact would return
immediately without restoring the previous state of the mdir. If a new
commit comes in on the same mdir, the old state left there could
corrupt the filesystem.
It's interesting to note this is forced to happen in lfs_file_sync,
since it always tries to outline the file if it gets ENOSPC (ENOSPC
can mean both no blocks to allocate and that the mdir is full). I'm
not actually sure this bit of code is necessary anymore, we may be
able to remove it.
4. Fixed cleanup issue if we run out of space while extending a CTZ
skip-list
The actually CTZ skip-list logic itself hasn't been touched in more
than a year at this point, so I was surprised to find a bug here. But
it turns out the CTZ skip-list could be put in an invalid state if we
run out of space while trying to extend the skip-list.
This only becomes a problem if we keep the file open, clean up some
space elsewhere, and then continue to write to the open file without
modifying it. Fortunately an easy fix.
5. Fixed missing half-orphans when allocating blocks during
lfs_fs_deorphan
This was a really interesting bug. Normally, we don't have to worry
about allocations, since we force consistency before we are allowed
to allocate blocks. But what about the deorphan operation itself?
Don't we need to allocate blocks if we relocate while deorphaning?
It turns out the deorphan operation can lead to allocating blocks
while there's still orphans and half-orphans on the threaded
linked-list. Orphans aren't an issue, but half-orphans may contain
references to blocks in the outdated half, which doesn't get scanned
during the normal allocation pass.
Fortunately we already fetch directory entries to check CTZ lists, so
we can also check half-orphans here. However this causes
lfs_fs_traverse to duplicate all metadata-pairs, not sure what to do
about this yet.
2020-01-29 07:45:19 +00:00
|
|
|
./scripts/test.py $@ $(TFLAGS)
|
Created initial implementation of revamped test.py
This is the start of reworking littlefs's testing framework based on
lessons learned from the initial testing framework.
1. The testing framework needs to be _flexible_. It was hacky, which by
itself isn't a downside, but it wasn't _flexible_. This limited what
could be done with the tests and there ended up being many
workarounds just to reproduce bugs.
The idea behind this revamped framework is to separate the
description of tests (tests/test_dirs.toml) and the running of tests
(scripts/test.py).
Now, with the logic moved entirely to python, it's possible to run
the test under varying environments. In addition to the "just don't
assert" run, I'm also looking to run the tests in valgrind for memory
checking, and an environment with simulated power-loss.
The test description can also contain abstract attributes that help
control how tests can be ran, such as "leaky" to identify tests where
memory leaks are expected. This keeps test limitations at a minimum
without limiting how the tests can be ran.
2. Multi-stage-process tests didn't really add value and limited what
the testing environment.
Unmounting + mounting can be done in a single process to test the
same logic. It would be really difficult to make this fail only
when memory is zeroed, though that can still be caught by
power-resilient tests.
Requiring every test to be a single process adds several options
for test execution, such as using a RAM-backed block device for
speed, or even running the tests on a device.
3. Added fancy assert interception. This wasn't really a requirement,
but something I've been wanting to experiment with for a while.
During testing, scripts/explode_asserts.py is added to the build
process. This is a custom C-preprocessor that parses out assert
statements and replaces them with _very_ verbose asserts that
wouldn't normally be possible with just C macros.
It even goes as far as to report the arguments to strcmp, since the
lack of visibility here was very annoying.
tests_/test_dirs.toml:186:assert: assert failed with "..", expected eq "..."
assert(strcmp(info.name, "...") == 0);
One downside is that simply parsing C in python is slower than the
entire rest of the compilation, but fortunately this can be
alleviated by parallelizing the test builds through make.
Other neat bits:
- All generated files are a suffix of the test description, this helps
cleanup and means it's (theoretically) possible to parallelize the
tests.
- The generated test.c is shoved base64 into an ad-hoc Makefile, this
means it doesn't force a rebuild of tests all the time.
- Test parameterizing is now easier.
- Hopefully this framework can be repurposed also for benchmarks in the
future.
2019-12-29 05:13:59 +00:00
|
|
|
|
2017-02-25 20:31:14 +00:00
|
|
|
-include $(DEP)
|
|
|
|
|
2018-07-06 18:13:36 +00:00
|
|
|
lfs: $(OBJ)
|
2017-02-25 20:31:14 +00:00
|
|
|
$(CC) $(CFLAGS) $^ $(LFLAGS) -o $@
|
|
|
|
|
|
|
|
%.a: $(OBJ)
|
|
|
|
$(AR) rcs $@ $^
|
|
|
|
|
|
|
|
%.o: %.c
|
|
|
|
$(CC) -c -MMD $(CFLAGS) $< -o $@
|
|
|
|
|
|
|
|
%.s: %.c
|
|
|
|
$(CC) -S $(CFLAGS) $< -o $@
|
|
|
|
|
|
|
|
clean:
|
|
|
|
rm -f $(TARGET)
|
|
|
|
rm -f $(OBJ)
|
|
|
|
rm -f $(DEP)
|
|
|
|
rm -f $(ASM)
|
2020-01-27 03:37:49 +00:00
|
|
|
rm -f tests/*.toml.*
|