2021-01-02 05:50:59 +00:00
|
|
|
ifdef BUILDDIR
|
|
|
|
# make sure BUILDDIR ends with a slash
|
|
|
|
override BUILDDIR := $(BUILDDIR)/
|
|
|
|
# bit of a hack, but we want to make sure BUILDDIR directory structure
|
|
|
|
# is correct before any commands
|
|
|
|
$(if $(findstring n,$(MAKEFLAGS)),, $(shell mkdir -p \
|
|
|
|
$(BUILDDIR) \
|
|
|
|
$(BUILDDIR)bd \
|
|
|
|
$(BUILDDIR)tests))
|
|
|
|
endif
|
|
|
|
|
|
|
|
# overridable target/src/tools/flags/etc
|
2018-07-06 18:13:36 +00:00
|
|
|
ifneq ($(wildcard test.c main.c),)
|
2021-01-02 05:50:59 +00:00
|
|
|
TARGET ?= $(BUILDDIR)lfs
|
|
|
|
else
|
|
|
|
TARGET ?= $(BUILDDIR)lfs.a
|
2018-07-06 18:13:36 +00:00
|
|
|
endif
|
2017-02-25 20:31:14 +00:00
|
|
|
|
2021-01-03 21:38:48 +00:00
|
|
|
|
2023-06-05 11:01:07 +00:00
|
|
|
CC ?= gcc
|
|
|
|
AR ?= ar
|
|
|
|
SIZE ?= size
|
|
|
|
CTAGS ?= ctags
|
|
|
|
NM ?= nm
|
|
|
|
OBJDUMP ?= objdump
|
|
|
|
LCOV ?= lcov
|
2017-02-25 20:31:14 +00:00
|
|
|
|
2021-01-05 08:49:30 +00:00
|
|
|
SRC ?= $(wildcard *.c)
|
2021-01-03 21:38:48 +00:00
|
|
|
OBJ := $(SRC:%.c=$(BUILDDIR)%.o)
|
|
|
|
DEP := $(SRC:%.c=$(BUILDDIR)%.d)
|
|
|
|
ASM := $(SRC:%.c=$(BUILDDIR)%.s)
|
2023-06-05 11:01:07 +00:00
|
|
|
CGI := $(SRC:%.c=$(BUILDDIR)%.ci)
|
2017-02-25 20:31:14 +00:00
|
|
|
|
|
|
|
ifdef DEBUG
|
2023-06-05 11:01:07 +00:00
|
|
|
override CFLAGS += -O0
|
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
|
2019-05-31 09:40:19 +00:00
|
|
|
ifdef TRACE
|
|
|
|
override CFLAGS += -DLFS_YES_TRACE
|
|
|
|
endif
|
2023-06-05 11:01:07 +00:00
|
|
|
override CFLAGS += -g3
|
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
|
2017-02-25 20:31:14 +00:00
|
|
|
|
2020-01-27 03:37:49 +00:00
|
|
|
ifdef VERBOSE
|
2023-06-05 11:01:07 +00:00
|
|
|
override TESTFLAGS += -v
|
|
|
|
override CALLSFLAGS += -v
|
|
|
|
override CODEFLAGS += -v
|
|
|
|
override DATAFLAGS += -v
|
|
|
|
override STACKFLAGS += -v
|
|
|
|
override STRUCTSFLAGS += -v
|
2021-01-02 05:50:59 +00:00
|
|
|
override COVERAGEFLAGS += -v
|
2020-01-27 03:37:49 +00:00
|
|
|
endif
|
2020-12-31 19:41:35 +00:00
|
|
|
ifdef EXEC
|
2021-01-02 05:50:59 +00:00
|
|
|
override TESTFLAGS += --exec="$(EXEC)"
|
|
|
|
endif
|
2023-06-05 11:01:07 +00:00
|
|
|
ifdef COVERAGE
|
|
|
|
override TESTFLAGS += --coverage
|
|
|
|
endif
|
2021-01-02 05:50:59 +00:00
|
|
|
ifdef BUILDDIR
|
2023-06-05 11:01:07 +00:00
|
|
|
override TESTFLAGS += --build-dir="$(BUILDDIR:/=)"
|
|
|
|
override CALLSFLAGS += --build-dir="$(BUILDDIR:/=)"
|
|
|
|
override CODEFLAGS += --build-dir="$(BUILDDIR:/=)"
|
|
|
|
override DATAFLAGS += --build-dir="$(BUILDDIR:/=)"
|
|
|
|
override STACKFLAGS += --build-dir="$(BUILDDIR:/=)"
|
|
|
|
override STRUCTSFLAGS += --build-dir="$(BUILDDIR:/=)"
|
|
|
|
override COVERAGEFLAGS += --build-dir="$(BUILDDIR:/=)"
|
2021-01-02 05:50:59 +00:00
|
|
|
endif
|
|
|
|
ifneq ($(NM),nm)
|
|
|
|
override CODEFLAGS += --nm-tool="$(NM)"
|
2023-06-05 11:01:07 +00:00
|
|
|
override DATAFLAGS += --nm-tool="$(NM)"
|
|
|
|
endif
|
|
|
|
ifneq ($(OBJDUMP),objdump)
|
|
|
|
override STRUCTSFLAGS += --objdump-tool="$(OBJDUMP)"
|
2020-12-31 19:41:35 +00:00
|
|
|
endif
|
2020-01-27 03:37:49 +00:00
|
|
|
|
2017-02-25 20:31:14 +00:00
|
|
|
|
2021-01-02 05:50:59 +00:00
|
|
|
# commands
|
Switched to lcov for coverage collection, greatly simplified coverage.py
Since we already have fairly complicated scriptts, I figured it wouldn't
be too hard to use the gcov tools and directly parse their output. Boy
was I wrong.
The gcov intermediary format is a bit of a mess. In version 5.4, a
text-based intermediary format is written to a single .gcov file per
executable. This changed sometime before version 7.5, when it started
writing separate .gcov files per .o files. And in version 9 this
intermediary format has been entirely replaced with an incompatible json
format!
Ironically, this means the internal-only .gcda/.gcno binary format has
actually been more stable than the intermediary format.
Also there's no way to avoid temporary .gcov files generated in the
project root, which risks messing with how test.py runs parallel tests.
Fortunately this looks like it will be fixed in gcov version 9.
---
Ended up switching to lcov, which was the right way to go. lcov handles
all of the gcov parsing, provides an easily parsable output, and even
provides a set of higher-level commands to manage coverage collection
from different runs.
Since this is all provided by lcov, was able to simplify coverage.py
quite a bit. Now it just parses the .info files output by lcov.
2021-01-02 05:35:16 +00:00
|
|
|
.PHONY: all build
|
|
|
|
all build: $(TARGET)
|
2017-02-25 20:31:14 +00:00
|
|
|
|
Switched to lcov for coverage collection, greatly simplified coverage.py
Since we already have fairly complicated scriptts, I figured it wouldn't
be too hard to use the gcov tools and directly parse their output. Boy
was I wrong.
The gcov intermediary format is a bit of a mess. In version 5.4, a
text-based intermediary format is written to a single .gcov file per
executable. This changed sometime before version 7.5, when it started
writing separate .gcov files per .o files. And in version 9 this
intermediary format has been entirely replaced with an incompatible json
format!
Ironically, this means the internal-only .gcda/.gcno binary format has
actually been more stable than the intermediary format.
Also there's no way to avoid temporary .gcov files generated in the
project root, which risks messing with how test.py runs parallel tests.
Fortunately this looks like it will be fixed in gcov version 9.
---
Ended up switching to lcov, which was the right way to go. lcov handles
all of the gcov parsing, provides an easily parsable output, and even
provides a set of higher-level commands to manage coverage collection
from different runs.
Since this is all provided by lcov, was able to simplify coverage.py
quite a bit. Now it just parses the .info files output by lcov.
2021-01-02 05:35:16 +00:00
|
|
|
.PHONY: asm
|
2017-02-25 20:31:14 +00:00
|
|
|
asm: $(ASM)
|
|
|
|
|
Switched to lcov for coverage collection, greatly simplified coverage.py
Since we already have fairly complicated scriptts, I figured it wouldn't
be too hard to use the gcov tools and directly parse their output. Boy
was I wrong.
The gcov intermediary format is a bit of a mess. In version 5.4, a
text-based intermediary format is written to a single .gcov file per
executable. This changed sometime before version 7.5, when it started
writing separate .gcov files per .o files. And in version 9 this
intermediary format has been entirely replaced with an incompatible json
format!
Ironically, this means the internal-only .gcda/.gcno binary format has
actually been more stable than the intermediary format.
Also there's no way to avoid temporary .gcov files generated in the
project root, which risks messing with how test.py runs parallel tests.
Fortunately this looks like it will be fixed in gcov version 9.
---
Ended up switching to lcov, which was the right way to go. lcov handles
all of the gcov parsing, provides an easily parsable output, and even
provides a set of higher-level commands to manage coverage collection
from different runs.
Since this is all provided by lcov, was able to simplify coverage.py
quite a bit. Now it just parses the .info files output by lcov.
2021-01-02 05:35:16 +00:00
|
|
|
.PHONY: size
|
2017-02-25 20:31:14 +00:00
|
|
|
size: $(OBJ)
|
|
|
|
$(SIZE) -t $^
|
|
|
|
|
2021-01-02 05:50:59 +00:00
|
|
|
.PHONY: tags
|
|
|
|
tags:
|
2021-01-05 08:49:30 +00:00
|
|
|
$(CTAGS) --totals --c-types=+p $(shell find -H -name '*.h') $(SRC)
|
2021-01-02 05:50:59 +00:00
|
|
|
|
2023-06-05 11:01:07 +00:00
|
|
|
.PHONY: calls
|
|
|
|
calls: $(CGI)
|
|
|
|
./scripts/calls.py $^ $(CALLSFLAGS)
|
2020-12-13 14:35:31 +00:00
|
|
|
|
Switched to lcov for coverage collection, greatly simplified coverage.py
Since we already have fairly complicated scriptts, I figured it wouldn't
be too hard to use the gcov tools and directly parse their output. Boy
was I wrong.
The gcov intermediary format is a bit of a mess. In version 5.4, a
text-based intermediary format is written to a single .gcov file per
executable. This changed sometime before version 7.5, when it started
writing separate .gcov files per .o files. And in version 9 this
intermediary format has been entirely replaced with an incompatible json
format!
Ironically, this means the internal-only .gcda/.gcno binary format has
actually been more stable than the intermediary format.
Also there's no way to avoid temporary .gcov files generated in the
project root, which risks messing with how test.py runs parallel tests.
Fortunately this looks like it will be fixed in gcov version 9.
---
Ended up switching to lcov, which was the right way to go. lcov handles
all of the gcov parsing, provides an easily parsable output, and even
provides a set of higher-level commands to manage coverage collection
from different runs.
Since this is all provided by lcov, was able to simplify coverage.py
quite a bit. Now it just parses the .info files output by lcov.
2021-01-02 05:35:16 +00:00
|
|
|
.PHONY: test
|
2020-01-27 03:37:49 +00:00
|
|
|
test:
|
2021-01-02 05:50:59 +00:00
|
|
|
./scripts/test.py $(TESTFLAGS)
|
2020-01-27 03:37:49 +00:00
|
|
|
.SECONDEXPANSION:
|
|
|
|
test%: tests/test$$(firstword $$(subst \#, ,%)).toml
|
2021-01-02 05:50:59 +00:00
|
|
|
./scripts/test.py $@ $(TESTFLAGS)
|
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
|
|
|
|
2023-06-05 11:01:07 +00:00
|
|
|
.PHONY: code
|
|
|
|
code: $(OBJ)
|
|
|
|
./scripts/code.py $^ -S $(CODEFLAGS)
|
|
|
|
|
|
|
|
.PHONY: data
|
|
|
|
data: $(OBJ)
|
|
|
|
./scripts/data.py $^ -S $(DATAFLAGS)
|
|
|
|
|
|
|
|
.PHONY: stack
|
|
|
|
stack: $(CGI)
|
|
|
|
./scripts/stack.py $^ -S $(STACKFLAGS)
|
|
|
|
|
|
|
|
.PHONY: structs
|
|
|
|
structs: $(OBJ)
|
|
|
|
./scripts/structs.py $^ -S $(STRUCTSFLAGS)
|
|
|
|
|
2021-01-03 21:38:48 +00:00
|
|
|
.PHONY: coverage
|
|
|
|
coverage:
|
2023-06-05 11:01:07 +00:00
|
|
|
./scripts/coverage.py $(BUILDDIR)tests/*.toml.info -s $(COVERAGEFLAGS)
|
|
|
|
|
|
|
|
.PHONY: summary
|
|
|
|
summary: $(BUILDDIR)lfs.csv
|
|
|
|
./scripts/summary.py -Y $^ $(SUMMARYFLAGS)
|
|
|
|
|
2021-01-03 21:38:48 +00:00
|
|
|
|
2021-01-02 05:50:59 +00:00
|
|
|
# rules
|
2017-02-25 20:31:14 +00:00
|
|
|
-include $(DEP)
|
2021-01-02 05:50:59 +00:00
|
|
|
.SUFFIXES:
|
2017-02-25 20:31:14 +00:00
|
|
|
|
2021-01-02 05:50:59 +00:00
|
|
|
$(BUILDDIR)lfs: $(OBJ)
|
2017-02-25 20:31:14 +00:00
|
|
|
$(CC) $(CFLAGS) $^ $(LFLAGS) -o $@
|
|
|
|
|
2023-06-05 11:01:07 +00:00
|
|
|
$(BUILDDIR)lfs.a: $(OBJ)
|
2017-02-25 20:31:14 +00:00
|
|
|
$(AR) rcs $@ $^
|
|
|
|
|
2023-06-05 11:01:07 +00:00
|
|
|
$(BUILDDIR)lfs.csv: $(OBJ) $(CGI)
|
|
|
|
./scripts/code.py $(OBJ) -q $(CODEFLAGS) -o $@
|
|
|
|
./scripts/data.py $(OBJ) -q -m $@ $(DATAFLAGS) -o $@
|
|
|
|
./scripts/stack.py $(CGI) -q -m $@ $(STACKFLAGS) -o $@
|
|
|
|
./scripts/structs.py $(OBJ) -q -m $@ $(STRUCTSFLAGS) -o $@
|
|
|
|
$(if $(COVERAGE),\
|
|
|
|
./scripts/coverage.py $(BUILDDIR)tests/*.toml.info \
|
|
|
|
-q -m $@ $(COVERAGEFLAGS) -o $@)
|
|
|
|
|
2021-01-02 05:50:59 +00:00
|
|
|
$(BUILDDIR)%.o: %.c
|
2017-02-25 20:31:14 +00:00
|
|
|
$(CC) -c -MMD $(CFLAGS) $< -o $@
|
|
|
|
|
2021-01-02 05:50:59 +00:00
|
|
|
$(BUILDDIR)%.s: %.c
|
2017-02-25 20:31:14 +00:00
|
|
|
$(CC) -S $(CFLAGS) $< -o $@
|
|
|
|
|
2023-06-05 11:01:07 +00:00
|
|
|
# gcc depends on the output file for intermediate file names, so
|
|
|
|
# we can't omit to .o output. We also need to serialize with the
|
|
|
|
# normal .o rule because otherwise we can end up with multiprocess
|
|
|
|
# problems with two instances of gcc modifying the same .o
|
|
|
|
$(BUILDDIR)%.ci: %.c | $(BUILDDIR)%.o
|
|
|
|
$(CC) -c -MMD -fcallgraph-info=su $(CFLAGS) $< -o $|
|
|
|
|
|
2021-01-02 05:50:59 +00:00
|
|
|
# clean everything
|
Switched to lcov for coverage collection, greatly simplified coverage.py
Since we already have fairly complicated scriptts, I figured it wouldn't
be too hard to use the gcov tools and directly parse their output. Boy
was I wrong.
The gcov intermediary format is a bit of a mess. In version 5.4, a
text-based intermediary format is written to a single .gcov file per
executable. This changed sometime before version 7.5, when it started
writing separate .gcov files per .o files. And in version 9 this
intermediary format has been entirely replaced with an incompatible json
format!
Ironically, this means the internal-only .gcda/.gcno binary format has
actually been more stable than the intermediary format.
Also there's no way to avoid temporary .gcov files generated in the
project root, which risks messing with how test.py runs parallel tests.
Fortunately this looks like it will be fixed in gcov version 9.
---
Ended up switching to lcov, which was the right way to go. lcov handles
all of the gcov parsing, provides an easily parsable output, and even
provides a set of higher-level commands to manage coverage collection
from different runs.
Since this is all provided by lcov, was able to simplify coverage.py
quite a bit. Now it just parses the .info files output by lcov.
2021-01-02 05:35:16 +00:00
|
|
|
.PHONY: clean
|
2017-02-25 20:31:14 +00:00
|
|
|
clean:
|
2023-06-05 11:01:07 +00:00
|
|
|
rm -f $(BUILDDIR)lfs
|
|
|
|
rm -f $(BUILDDIR)lfs.a
|
|
|
|
rm -f $(BUILDDIR)lfs.csv
|
2017-02-25 20:31:14 +00:00
|
|
|
rm -f $(OBJ)
|
2023-06-05 11:01:07 +00:00
|
|
|
rm -f $(CGI)
|
2017-02-25 20:31:14 +00:00
|
|
|
rm -f $(DEP)
|
|
|
|
rm -f $(ASM)
|
2021-01-02 05:50:59 +00:00
|
|
|
rm -f $(BUILDDIR)tests/*.toml.*
|