[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 0/7] tests: introduce a tree-wide code style checking facility
From: |
Daniel P . Berrangé |
Subject: |
[PATCH v2 0/7] tests: introduce a tree-wide code style checking facility |
Date: |
Mon, 4 Jul 2022 16:22:56 +0100 |
The first patch gives a detailed description, but the overall goal here
is to provide a code style checking facility to augment (and ideally
eventually replace) checkpatch.pl. The key conceptual differences are:
- Always applies to all code in tree, not merely patches
- Failures are always fatal, exceptions must be recorded
- Always runs as part of 'make check'
These combine to ensure that the in-tree code quality will be kept
at a high bar on an ongoing basis, with no silently ignoring rules,
any exceptions must be recorded explicitly to allow the check to
pass.
The first patch introduces the infrastructure, the remaining patches
illustrate its usage for three rules
- Prevent initializing an 'int' variable with 'true' / 'false'
- Look for commonly repeated words (ie the the)
- Ensure qemu/osdep.h is listed in all .c files
As noted above, it integrates with 'make check' via a new test suite
called 'style', so you can invoke it individually too:
$ make check-style
changing dir to build for make "check-style"...
/usr/bin/meson test --no-rebuild -t 0 --num-processes 1 --print-errorlogs
--suite style
1/3 qemu:style / int_assign_bool OK 0.28s
2/3 qemu:style / prohibit_doubled_word OK 1.78s
3/3 qemu:style / c_file_osdep_h OK 0.08s
Ok: 3
Expected Fail: 0
Fail: 0
Unexpected Pass: 0
Skipped: 0
Timeout: 0
Example of what it looks like when it fails:
$ make check-style
changing dir to build for make "check-style"...
make[1]: Entering directory '/home/berrange/src/virt/qemu/build'
GIT ui/keycodemapdb tests/fp/berkeley-testfloat-3
tests/fp/berkeley-softfloat-3 dtc slirp
/usr/bin/meson test --no-rebuild -t 0 --num-processes 1 --print-errorlogs
--suite style
1/3 qemu:style / int_assign_bool OK 0.27s
2/3 qemu:style / prohibit_doubled_word OK 1.77s
3/3 qemu:style / c_file_osdep_h FAIL 0.07s exit
status 2
>>> MALLOC_PERTURB_=217 /usr/bin/make -f
/home/berrange/src/virt/qemu/build/../tests/style.mak sc_c_file_osdep_h
――――――――――――――――――――――――――――――――――――――――――――――――――――― ✀
――――――――――――――――――――――――――――――――――――――――――――――――――――――
stdout:
make[2]: Entering directory '/home/berrange/src/virt/qemu'
c_file_osdep_h
scripts/coverity-scan/model.c
scripts/xen-detect.c
subprojects/libvduse/libvduse.c
subprojects/libvhost-user/libvhost-user-glib.c
subprojects/libvhost-user/libvhost-user.c
subprojects/libvhost-user/link-test.c
make[2]: Leaving directory '/home/berrange/src/virt/qemu'
stderr:
tests/style.mak: all C files must include qemu/osdep.h
make[2]: *** [/home/berrange/src/virt/qemu/build/../tests/style.mak:57:
sc_c_file_osdep_h] Error 1
―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
Summary of Failures:
3/3 qemu:style / c_file_osdep_h FAIL 0.07s exit status 2
Ok: 2
Expected Fail: 0
Fail: 1
Unexpected Pass: 0
Skipped: 0
Timeout: 0
If debugging new tests it can be preferrable to directly invoke it
bypassing meson:
$ make -f tests/style.mak
c_file_osdep_h
0.04 c_file_osdep_h
int_assign_bool
0.23 int_assign_bool
prohibit_doubled_word
1.73 prohibit_doubled_word
or
$ make -f tests/style.mak sc_c_file_osdep_h
c_file_osdep_h
scripts/coverity-scan/model.c
scripts/xen-detect.c
subprojects/libvduse/libvduse.c
subprojects/libvhost-user/libvhost-user-glib.c
subprojects/libvhost-user/libvhost-user.c
subprojects/libvhost-user/link-test.c
tests/style.mak: all C files must include qemu/osdep.h
make: *** [tests/style.mak:57: sc_c_file_osdep_h] Error 1
The speed of the test suite is largely driven by how quickly
'grep' can match through *every* file in the soruce tree (as
reported by 'git ls-tree').
The 'prohibit_doubled_word' test illustrates a more complex
check that uses perl. That runs a little more slowly but is
more flexible in what it checks for.
This style checking scheme is that same as that used by libvirt
and many other projects that historically used gnulib. Fortunately
the style check rules were easy to extract from gnulib, so libvirt
kept using them after droppping gnulib.
Daniel P. Berrangé (7):
tests: introduce tree-wide code style checking
misc: fix mixups of bool constants with int variables
tests/style: check for mixups of bool constants with int variables
misc: fix commonly doubled up words
tests/style: check for commonly doubled up words
misc: ensure qemu/osdep.h is included in all .c files
tests/style: check qemu/osdep.h is included in all .c files
block/linux-aio.c | 2 +-
block/qcow2-bitmap.c | 8 +-
block/vhdx-log.c | 2 +-
bsd-user/arm/signal.c | 2 +
bsd-user/arm/target_arch_cpu.c | 3 +
bsd-user/{elfcore.c => elfcore.c.inc} | 0
bsd-user/elfload.c | 2 +-
bsd-user/freebsd/os-sys.c | 2 +
bsd-user/i386/signal.c | 2 +
bsd-user/qemu.h | 1 -
bsd-user/x86_64/signal.c | 2 +
contrib/plugins/cache.c | 2 +-
crypto/rsakey.c | 1 +
disas/libvixl/vixl/invalset.h | 2 +-
docs/devel/qom.rst | 4 +-
docs/interop/live-block-operations.rst | 4 +-
docs/system/arm/cpu-features.rst | 2 +-
docs/system/devices/cxl.rst | 2 +-
docs/system/s390x/bootdevices.rst | 2 +-
docs/system/tls.rst | 2 +-
docs/tools/qemu-pr-helper.rst | 2 +-
hw/core/clock.c | 2 +-
hw/intc/arm_gicv3_redist.c | 2 +-
hw/misc/iotkit-secctl.c | 2 +-
hw/misc/iotkit-sysctl.c | 4 +-
hw/s390x/s390-ccw.c | 2 +-
hw/usb/u2f.h | 2 +-
hw/xtensa/sim.c | 4 +-
include/hw/qdev-core.h | 2 +-
include/user/safe-syscall.h | 2 +-
linux-user/i386/cpu_loop.c | 2 +-
meson.build | 3 +
nbd/client.c | 4 +-
pc-bios/s390-ccw/virtio-scsi.c | 2 +-
python/Makefile | 2 +-
python/qemu/utils/__init__.py | 2 +-
qga/cutils.c | 2 +
target/arm/translate.c | 2 +-
target/i386/cpu-dump.c | 3 +-
target/i386/cpu.c | 2 +-
tcg/i386/tcg-target.c.inc | 2 +-
tests/Makefile.include | 3 +-
tests/meson.build | 19 ++
tests/qtest/microbit-test.c | 4 +-
tests/style-excludes.mak | 33 +++
tests/style-infra.mak | 265 +++++++++++++++++++++++++
tests/style.mak | 60 ++++++
tools/virtiofsd/fuse_virtio.c | 2 +-
ui/spice-display.c | 4 +-
49 files changed, 441 insertions(+), 46 deletions(-)
rename bsd-user/{elfcore.c => elfcore.c.inc} (100%)
create mode 100644 tests/style-excludes.mak
create mode 100644 tests/style-infra.mak
create mode 100644 tests/style.mak
--
2.36.1
- [PATCH v2 0/7] tests: introduce a tree-wide code style checking facility,
Daniel P . Berrangé <=
- [PATCH v2 1/7] tests: introduce tree-wide code style checking, Daniel P . Berrangé, 2022/07/04
- [PATCH v2 3/7] tests/style: check for mixups of bool constants with int variables, Daniel P . Berrangé, 2022/07/04
- [PATCH v2 2/7] misc: fix mixups of bool constants with int variables, Daniel P . Berrangé, 2022/07/04
- [PATCH v2 5/7] tests/style: check for commonly doubled up words, Daniel P . Berrangé, 2022/07/04
- [PATCH v2 4/7] misc: fix commonly doubled up words, Daniel P . Berrangé, 2022/07/04