Allowed overriding prettyasserts.py with an external prettyasserts tool

Unfortunately, prettyasserts.py is having a hard time keeping up with
the constantly increasing number of tests. This is creating real
friction when debugging, as it now takes ~6x the time to preprocess
asserts as it does to actually compile the thing:

  $ time ./scripts/prettyasserts.py \
      -a LFS_ASSERT -u LFS_UNREACHABLE \
      lfs.t.a.c -o lfs.t.c
  real    0m16.187s
  user    0m16.163s
  sys     0m0.025s

  $ time gcc -c -O0 -I. lfs.t.c -o lfs.o
  real    0m2.466s
  user    0m2.345s
  sys     0m0.105s

Externally, I've rewritten prettyasserts.py in Rust, with more attention
towards performance (prettyasserts.py does quite a number of string
allocations). The result is quite satisfying:

  $ time ~/prettyasserts/prettyasserts \
      -a LFS_ASSERT -u LFS_UNREACHABLE \
      lfs.t.a.c -o lfs.t.c
  real    0m0.504s
  user    0m0.464s
  sys     0m0.040s

However, adding Rust as a requirement to test littlefs would be, uh,
quite a big jump.

So instead, littlefs keeps prettyassert.py, so only Python is needed out
of the box, and if the slow preprocessing is too much users are welcome
to provide their own prettyasserts binary via the PRETTYASSERTS env
variable:

  $ time \
      DEBUG=1 \
      make test-runner -j
  real    0m22.204s
  user    0m44.841s
  sys     0m1.478s

  $ time \
      DEBUG=1 PRETTYASSERTS=~/prettyasserts/prettyasserts \
      make test-runner -j
  real    0m5.699s
  user    0m23.590s
  sys     0m1.151s
This commit is contained in:
Christopher Haster
2024-02-15 16:26:48 -06:00
parent 5128522fe2
commit 65dd669d83
+12 -11
View File
@@ -18,15 +18,16 @@ TARGET ?= $(BUILDDIR)/liblfs.a
endif endif
CC ?= gcc CC ?= gcc
AR ?= ar AR ?= ar
SIZE ?= size SIZE ?= size
CTAGS ?= ctags CTAGS ?= ctags
NM ?= nm NM ?= nm
OBJDUMP ?= objdump OBJDUMP ?= objdump
VALGRIND ?= valgrind VALGRIND ?= valgrind
GDB ?= gdb GDB ?= gdb
PERF ?= perf PERF ?= perf
PRETTYASSERTS ?= ./scripts/prettyasserts.py
SRC ?= $(filter-out $(wildcard *.t.* *.b.*),$(wildcard *.c)) SRC ?= $(filter-out $(wildcard *.t.* *.b.*),$(wildcard *.c))
OBJ := $(SRC:%.c=$(BUILDDIR)/%.o) OBJ := $(SRC:%.c=$(BUILDDIR)/%.o)
@@ -522,10 +523,10 @@ $(BUILDDIR)/%.s: %.c
$(CC) -S $(CFLAGS) $< -o $@ $(CC) -S $(CFLAGS) $< -o $@
$(BUILDDIR)/%.c: %.a.c $(BUILDDIR)/%.c: %.a.c
./scripts/prettyasserts.py -a LFS_ASSERT -u LFS_UNREACHABLE $< -o $@ $(PRETTYASSERTS) -a LFS_ASSERT -u LFS_UNREACHABLE $< -o $@
$(BUILDDIR)/%.c: $(BUILDDIR)/%.a.c $(BUILDDIR)/%.c: $(BUILDDIR)/%.a.c
./scripts/prettyasserts.py -a LFS_ASSERT -u LFS_UNREACHABLE $< -o $@ $(PRETTYASSERTS) -a LFS_ASSERT -u LFS_UNREACHABLE $< -o $@
$(BUILDDIR)/%.t.a.c: %.toml $(BUILDDIR)/%.t.a.c: %.toml
./scripts/test.py -c $< $(TESTCFLAGS) -o $@ ./scripts/test.py -c $< $(TESTCFLAGS) -o $@