Skip to contentSkip to conversation

tests: introduce a tree-wide code style checking facility

PATCH Superseded Daniel P. Berrangé 3 participants 22 messages Jul 4, 2022 – Jul 7, 2022

Subsystems (4)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover tests: introduce a tree-wide code style checking facility

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
Quoted 1 line
Quoted 1 line
Quoted 1 line

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
Signature · 1 line
2.36.1
#1 lore raw

PATCH v2 1/7 tests: introduce tree-wide code style checking

Historically QEMU has used the 'scripts/checkpatch.pl' script to validate various style rules but there are a number of issues:

- It requires the contributor to remember to run it as it is not wired into 'make check'

- While it can be told to check whole files, in practice it is usually only used to check patch diffs, because the former would flag up pages of pre-existing violations that have never been fixed

- It is said to be OK to ignore some things reported by the script, but don't record these exceptional cases anywere. Thus contributors looking at existing violations in tree are never sure whether they are intentional or historical unfixed technical debt.

- There is no distinct reporting for each type of check performed and as a consequence there is also no way to mark particular files to be skipped for particular checks

This commit aims to give us a better approach to checking many types of code style problems by introducing a flexible way to define whole tree style checks.

The logic is essentially an import of the 'top/maint.mk' file from GNULIB, with the following changes applied

- Logic unrelated to the GNULIB syntax-check functionality is removed.

- sc_excl is redefined, so that whitespace is turned into an '|' condition. This allows filename exclusion lists to span multiple lines making it more readable.

- VC_LIST is changed to directly invoke git instead of indirectly via the vc-list script, since QEMU does not need portaility across many source control systems.

- .DEFAULT_GOAL is set to 'syntax-check' since this is being used in a self-contained manner and thus doesn't need to play nice with our makefile rules QEMU has

This commit does the bare minimum introducing the basic infra:

- tests/style-infra.mak - the cut down import of maint.mk
- tests/style-excludes.mak - where the list of filename exclusions per test will be maintained (empty)
- tests/style.mak - where the interesting tests live (empty)

As a general rule new checks can be implemented by merely defining a regex matching the code pattern that should be blocked.

For example, consider we want to stop people using the 'bool' type entirely. A rule starting with the prefix 'sc_' is defined in the style.mak file:

sc_prohibit_bool:

	prohibit='\<bool\>' \
	halt='do not use the bool type' \
	$(_sc_search_regexp)

Where '$(_sc_search_regexp)' (acquired from style-infra.mak) contains all the magic to perform the tree-wide search for the offending code pattern, reporting '$(halt)' as the error message if violations are found.

If certain files need to be skipped for certain tests this can be achieved by defining a variable with 'exclude_file_name_regexp--' followed by the name of the check

  exclude_file_name_regexp--sc_prohibit_bool = \
        i-am-allowed-to-use-bool.c \
	and-so-am-i.c

Some checks can't be easily implemented by a simple per-line matching regex. Since the checks are just implemented in make/shell, custom rules can run essentially arbitrary logic.

Note that the checks require the use of 'git' to detect the list of source files to search. Thus the check is skipped when not running from a git repository.

---
 meson.build              |   3 +
 tests/Makefile.include   |   3 +-
 tests/meson.build        |  19 +++
 tests/style-excludes.mak |   4 +
 tests/style-infra.mak    | 265 +++++++++++++++++++++++++++++++++++++++
 tests/style.mak          |  24 ++++
 6 files changed, 317 insertions(+), 1 deletion(-)
 create mode 100644 tests/style-excludes.mak
 create mode 100644 tests/style-infra.mak
 create mode 100644 tests/style.mak
meson.build +3 -0
index 65a885ea69..420102353e 100644
@@ -18,6 +18,9 @@ config_host = keyval.load(meson.current_build_dir() / 'config-host.mak')
 enable_modules = 'CONFIG_MODULES' in config_host
 enable_static = 'CONFIG_STATIC' in config_host
 
+make = find_program(config_host['MAKE'])
+in_gitrepo = run_command('test', '-d', '.git', check: false).returncode() == 0
+
 # Allow both shared and static libraries unless --enable-static
 static_kwargs = enable_static ? {'static': true} : {}
 
tests/Makefile.include +2 -1
index 3accb83b13..f7c1d2644e 100644
@@ -3,12 +3,13 @@
 .PHONY: check-help
 check-help:
 	@echo "Regression testing targets:"
-	@echo " $(MAKE) check                  Run block, qapi-schema, unit, softfloat, qtest and decodetree tests"
+	@echo " $(MAKE) check                  Run block, qapi-schema, unit, style, softfloat, qtest and decodetree tests"
 	@echo " $(MAKE) bench                  Run speed tests"
 	@echo
 	@echo "Individual test suites:"
 	@echo " $(MAKE) check-qtest-TARGET     Run qtest tests for given target"
 	@echo " $(MAKE) check-qtest            Run qtest tests"
+	@echo " $(MAKE) check-style            Run style checks"
 	@echo " $(MAKE) check-unit             Run qobject tests"
 	@echo " $(MAKE) check-qapi-schema      Run QAPI schema tests"
 	@echo " $(MAKE) check-block            Run block tests"
tests/meson.build +19 -0
index 8e318ec513..e26cadbc8a 100644
@@ -89,6 +89,25 @@ if get_option('tcg').allowed()
   endif
 endif
 
+if in_gitrepo
+  rc = run_command(
+    'sed', '-n',
+    's/^sc_\\([a-zA-Z0-9_-]*\\):.*/\\1/p',
+    meson.current_source_dir() / 'style.mak',
+    check: true,
+  )
+
+  sc_tests = rc.stdout().strip().split()
+
+  foreach check: sc_tests
+     test(check,
+          make,
+          args: [ '-f', files('style.mak'), 'sc_' + check ],
+          workdir: meson.project_source_root(),
+          suite: 'style')
+  endforeach
+endif
+
 subdir('unit')
 subdir('qapi-schema')
 subdir('qtest')
tests/style-excludes.mak new file +4 -0
new file mode 100644
index 0000000000..32c0e9c328
@@ -0,0 +1,4 @@
+# -*- makefile -*-
+#
+# Filenames that should be excluded from specific
+# style checks performed by style.mak
tests/style-infra.mak new file +265 -0

265 lines not on this page · raw message

tests/style.mak new file +24 -0
new file mode 100644
index 0000000000..32c7e706ba
@@ -0,0 +1,24 @@
+# -*- makefile -*-
+#
+# Rules for simple code style checks applying across the
+# whole tree. Partially derived from GNULIB's 'maint.mk'
+#
+# Copyright (C) 2008-2019 Red Hat, Inc.
+# Copyright (C) 2003-2019 Free Software Foundation, Inc.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see
+# <http://www.gnu.org/licenses/>.
+
+include tests/style-infra.mak
+include tests/style-excludes.mak
Signature · 1 line
2.36.1
#2 lore raw

Re: [PATCH v2 1/7] tests: introduce tree-wide code style checking

Quoted 10 lines · Daniel P. Berrangé

Historically QEMU has used the 'scripts/checkpatch.pl' script to validate various style rules but there are a number of issues:

 meson.build              |   3 +
 tests/Makefile.include   |   3 +-
 tests/meson.build        |  19 +++
 tests/style-excludes.mak |   4 +
 tests/style-infra.mak    | 265 +++++++++++++++++++++++++++++++++++++++
 tests/style.mak          |  24 ++++

From my point of view the main issue with checkpatch.pl is that nobody in the QEMU developers particularly understands it or is enthusiastic about trying to add more tests to it or adjust the existing ones where QEMU style diverges from the kernel style (but nor are we tracking and upgrading to newer versions of the kernel's script).

This seems to be aiming to replace a complex and hard to understand perl script with a complex and hard to understand makefile. I can't say I'm terribly enthusiastic :-/

thanks
-- PMM

#3 lore raw

Re: [PATCH v2 1/7] tests: introduce tree-wide code style checking

Quoted 19 lines · Peter Maydell
Quoted 10 lines · Daniel P. Berrangé

Historically QEMU has used the 'scripts/checkpatch.pl' script to validate various style rules but there are a number of issues:

 meson.build              |   3 +
 tests/Makefile.include   |   3 +-
 tests/meson.build        |  19 +++
 tests/style-excludes.mak |   4 +
 tests/style-infra.mak    | 265 +++++++++++++++++++++++++++++++++++++++
 tests/style.mak          |  24 ++++

From my point of view the main issue with checkpatch.pl is that nobody in the QEMU developers particularly understands it or is enthusiastic about trying to add more tests to it or adjust the existing ones where QEMU style diverges from the kernel style (but nor are we tracking and upgrading to newer versions of the kernel's script).

Quoted 3 lines

This seems to be aiming to replace a complex and hard to understand perl script with a complex and hard to understand makefile. I can't say I'm terribly enthusiastic :-/

I think the downsides comapred here are rather different orders of magnitude. The checkpatch.pl script is 3000 lines of code where we have years of experiance that no one in QEMU likes touching it.

The makefile here is 265 lines of which 50% is comments of license text. In terms of what contributors most care about though, is how you add new rules, and most of the time that's involves just adding a 3 line make rule based off a regex to match the code pattern you want to prohibit. Some of this is a bit crufty to look at, but we've got years of experiance in libvirt with many contributors frequently adding new tests.

It only gets hairy if the pattern you're trying to forbid needs to match across multiple lines of text - hence the difference in complexity between matching 'osdep.h' exists in .c, vs 'osdep.h' exists as the very first #include. IME, the single-line matches are most typical need that is addressed.

So while I wont claim this proposal is perfect, IMHO this would be a significant step fowards over checkpatch.pl.

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#4 lore raw

Re: [PATCH v2 1/7] tests: introduce tree-wide code style checking

In reply to Peter Maydell
Quoted 19 lines · Peter Maydell
Quoted 10 lines · Daniel P. Berrangé

Historically QEMU has used the 'scripts/checkpatch.pl' script to validate various style rules but there are a number of issues:

 meson.build              |   3 +
 tests/Makefile.include   |   3 +-
 tests/meson.build        |  19 +++
 tests/style-excludes.mak |   4 +
 tests/style-infra.mak    | 265 +++++++++++++++++++++++++++++++++++++++
 tests/style.mak          |  24 ++++

From my point of view the main issue with checkpatch.pl is that nobody in the QEMU developers particularly understands it or is enthusiastic about trying to add more tests to it or adjust the existing ones where QEMU style diverges from the kernel style (but nor are we tracking and upgrading to newer versions of the kernel's script).

Quoted 3 lines

This seems to be aiming to replace a complex and hard to understand perl script with a complex and hard to understand makefile. I can't say I'm terribly enthusiastic :-/

Taking that feedback on board, I've proposed a new version which is written in Python, and uses a plain yaml config file, which I admit results in an easier to understand and more attractive impl than this makefile based one.

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#5 lore raw

PATCH v2 2/7 misc: fix mixups of bool constants with int variables

In reply to Daniel P. Berrangé
---
 block/vhdx-log.c       | 2 +-
 hw/xtensa/sim.c        | 4 ++--
 nbd/client.c           | 4 ++--
 target/i386/cpu-dump.c | 3 ++-
 ui/spice-display.c     | 4 ++--
 5 files changed, 9 insertions(+), 8 deletions(-)
block/vhdx-log.c +1 -1
index ff0d4e0da0..8f34755a6f 100644
@@ -215,7 +215,7 @@ exit:
 static bool vhdx_log_hdr_is_valid(VHDXLogEntries *log, VHDXLogEntryHeader *hdr,
                                   BDRVVHDXState *s)
 {
-    int valid = false;
+    bool valid = false;
 
     if (hdr->signature != VHDX_LOG_SIGNATURE) {
         goto exit;
hw/xtensa/sim.c +2 -2
index 946c71cb5b..70fce7fb85 100644
@@ -97,9 +97,9 @@ void xtensa_sim_load_kernel(XtensaCPU *cpu, MachineState *machine)
 {
     const char *kernel_filename = machine->kernel_filename;
 #if TARGET_BIG_ENDIAN
-    int big_endian = true;
+    int big_endian = 1;
 #else
-    int big_endian = false;
+    int big_endian = 0;
 #endif
 
     if (kernel_filename) {
nbd/client.c +2 -2
index 30d5383cb1..fee3959d24 100644
@@ -832,8 +832,8 @@ static int nbd_list_meta_contexts(QIOChannel *ioc,
                                   Error **errp)
 {
     int ret;
-    int seen_any = false;
-    int seen_qemu = false;
+    bool seen_any = false;
+    bool seen_qemu = false;
 
     if (nbd_send_meta_query(ioc, NBD_OPT_LIST_META_CONTEXT,
                             info->name, NULL, errp) < 0) {
target/i386/cpu-dump.c +2 -1
index 08ac957e99..43521c74c8 100644
@@ -275,7 +275,8 @@ static void dump_apic_icr(APICCommonState *s, CPUX86State *env)
 static void dump_apic_interrupt(const char *name, uint32_t *ireg_tab,
                                 uint32_t *tmr_tab)
 {
-    int i, empty = true;
+    int i;
+    bool empty = true;
 
     qemu_printf("%s\t ", name);
     for (i = 0; i < 256; i++) {
ui/spice-display.c +2 -2
index 494168e7fe..5d3b64413f 100644
@@ -541,14 +541,14 @@ static int interface_get_command(QXLInstance *sin, QXLCommandExt *ext)
 {
     SimpleSpiceDisplay *ssd = container_of(sin, SimpleSpiceDisplay, qxl);
     SimpleSpiceUpdate *update;
-    int ret = false;
+    int ret = 0;
 
     qemu_mutex_lock(&ssd->lock);
     update = QTAILQ_FIRST(&ssd->updates);
     if (update != NULL) {
         QTAILQ_REMOVE(&ssd->updates, update, next);
         *ext = update->ext;
-        ret = true;
+        ret = 1;
     }
     qemu_mutex_unlock(&ssd->lock);
 
Signature · 1 line
2.36.1
#6 lore raw

Re: [PATCH v2 2/7] misc: fix mixups of bool constants with int variables

Quoted 15 lines · Daniel P. Berrangé
---
 block/vhdx-log.c       | 2 +-
 hw/xtensa/sim.c        | 4 ++--
 nbd/client.c           | 4 ++--
 target/i386/cpu-dump.c | 3 ++-
 ui/spice-display.c     | 4 ++--
 5 files changed, 9 insertions(+), 8 deletions(-)
nbd/client.c +0 -0
index 30d5383cb1..fee3959d24 100644

nbd/client.c static int nbd_list_meta_contexts(QIOChannel *ioc, · line 839

Quoted 10 lines
nbd/client.c +2 -2
@@ -832,8 +832,8 @@ static int nbd_list_meta_contexts(QIOChannel *ioc,
                                   Error **errp)
 {
     int ret;
-    int seen_any = false;
-    int seen_qemu = false;
+    bool seen_any = false;
+    bool seen_qemu = false;
 
     if (nbd_send_meta_query(ioc, NBD_OPT_LIST_META_CONTEXT,
                             info->name, NULL, errp) < 0) {

The code in this function does a bitwise OR into seen_qemu later -- bitwise OR into a bool also seems like bad style that something is probably going to complain about. (I guess currently -Wbool-operation doesn't care about it or else we don't enable that, but it might in future.)

The other changes look OK.

-- PMM

#7 lore raw

PATCH v2 3/7 tests/style: check for mixups of bool constants with int variables

In reply to Daniel P. Berrangé

The 'true' and 'false' constants should only ever be used with the 'bool' type, never 'int'.

---
 tests/style.mak | 6 ++++++
 1 file changed, 6 insertions(+)
tests/style.mak +6 -0
index 32c7e706ba..ae658395c9 100644
@@ -22,3 +22,9 @@
 
 include tests/style-infra.mak
 include tests/style-excludes.mak
+
+# Use 'bool', not 'int', when assigning true or false
+sc_int_assign_bool:
+	@prohibit='\<int\>.*= *(true|false)\b' \
+	halt='use bool type for boolean values' \
+	$(_sc_search_regexp)
Signature · 1 line
2.36.1
#8 lore raw

PATCH v2 4/7 misc: fix commonly doubled up words

In reply to Daniel P. Berrangé
---
 block/linux-aio.c                      | 2 +-
 block/qcow2-bitmap.c                   | 8 ++++----
 contrib/plugins/cache.c                | 2 +-
 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 +-
 include/hw/qdev-core.h                 | 2 +-
 include/user/safe-syscall.h            | 2 +-
 linux-user/i386/cpu_loop.c             | 2 +-
 pc-bios/s390-ccw/virtio-scsi.c         | 2 +-
 python/Makefile                        | 2 +-
 python/qemu/utils/__init__.py          | 2 +-
 target/arm/translate.c                 | 2 +-
 target/i386/cpu.c                      | 2 +-
 tcg/i386/tcg-target.c.inc              | 2 +-
 tests/qtest/microbit-test.c            | 4 ++--
 tools/virtiofsd/fuse_virtio.c          | 2 +-
 28 files changed, 35 insertions(+), 35 deletions(-)
block/linux-aio.c +1 -1
index 9c2393a2f7..d2cfb7f523 100644
@@ -461,7 +461,7 @@ LinuxAioState *laio_init(Error **errp)
     s = g_malloc0(sizeof(*s));
     rc = event_notifier_init(&s->e, false);
     if (rc < 0) {
-        error_setg_errno(errp, -rc, "failed to to initialize event notifier");
+        error_setg_errno(errp, -rc, "failed to initialize event notifier");
         goto out_free_state;
     }
 
block/qcow2-bitmap.c +4 -4
index 8fb4731551..5529368df4 100644
@@ -787,10 +787,10 @@ static int bitmap_list_store(BlockDriverState *bs, Qcow2BitmapList *bm_list,
         }
     }
 
-    /* Actually, even in in-place case ignoring QCOW2_OL_BITMAP_DIRECTORY is not
-     * necessary, because we drop QCOW2_AUTOCLEAR_BITMAPS when updating bitmap
-     * directory in-place (actually, turn-off the extension), which is checked
-     * in qcow2_check_metadata_overlap() */
+    /* Actually, even in the in-place case ignoring QCOW2_OL_BITMAP_DIRECTORY
+     * is not necessary, because we drop QCOW2_AUTOCLEAR_BITMAPS when updating
+     * bitmap directory in-place (actually, turn-off the extension), which is
+     * checked in qcow2_check_metadata_overlap() */
     ret = qcow2_pre_write_overlap_check(
             bs, in_place ? QCOW2_OL_BITMAP_DIRECTORY : 0, dir_offset, dir_size,
             false);
contrib/plugins/cache.c +1 -1
index b9226e7c40..ac1510aaa1 100644
@@ -38,7 +38,7 @@ enum EvictionPolicy policy;
  * put in any of the blocks inside the set. The number of block per set is
  * called the associativity (assoc).
  *
- * Each block contains the the stored tag and a valid bit. Since this is not
+ * Each block contains the stored tag and a valid bit. Since this is not
  * a functional simulator, the data itself is not stored. We only identify
  * whether a block is in the cache or not by searching for its tag.
  *
disas/libvixl/vixl/invalset.h +1 -1
index 2e0871f8c3..f5d6c43d81 100644
@@ -102,7 +102,7 @@ template<TEMPLATE_INVALSET_P_DECL> class InvalSet {
   size_t size() const;
 
   // Returns true if no elements are stored in the set.
-  // Note that this does not mean the the backing storage is empty: it can still
+  // Note that this does not mean the backing storage is empty: it can still
   // contain invalid elements.
   bool empty() const;
 
docs/devel/qom.rst +2 -2
index e5fe3597cd..62c39c9c88 100644
@@ -372,8 +372,8 @@ This accepts an array of interface type names.
                                       { TYPE_USER_CREATABLE },
                                       { NULL })
 
-If the type is not intended to be instantiated, then then
-the OBJECT_DEFINE_ABSTRACT_TYPE() macro can be used instead:
+If the type is not intended to be instantiated, then the
+OBJECT_DEFINE_ABSTRACT_TYPE() macro can be used instead:
 
 .. code-block:: c
    :caption: Defining a simple abstract type
docs/interop/live-block-operations.rst +2 -2
index 39e62c9915..135784ab33 100644
@@ -53,7 +53,7 @@ files in a disk image backing chain:
 
 (1) Directional: 'base' and 'top'.  Given the simple disk image chain
     above, image [A] can be referred to as 'base', and image [B] as
-    'top'.  (This terminology can be seen in in QAPI schema file,
+    'top'.  (This terminology can be seen in the QAPI schema file,
     block-core.json.)
 
 (2) Relational: 'backing file' and 'overlay'.  Again, taking the same
@@ -825,7 +825,7 @@ entire disk image chain, to a target, using ``blockdev-mirror`` would be:
     job ready to be completed
 
 (5) Gracefully complete the 'mirror' block device job, and notice the
-    the event ``BLOCK_JOB_COMPLETED``
+    event ``BLOCK_JOB_COMPLETED``
 
 (6) Shutdown the guest by issuing the QMP ``quit`` command so that
     caches are flushed
docs/system/arm/cpu-features.rst +1 -1
index 3fd76fa0b4..c2c01ec7d2 100644
@@ -284,7 +284,7 @@ SVE CPU Property Parsing Semantics
      CPU Property Dependencies and Constraints").
 
   4) If one or more vector lengths have been explicitly enabled and at
-     at least one of the dependency lengths of the maximum enabled length
+     least one of the dependency lengths of the maximum enabled length
      has been explicitly disabled, then an error is generated (see
      constraint (2) of "SVE CPU Property Dependencies and Constraints").
 
docs/system/devices/cxl.rst +1 -1
index a57e4c4e5c..36031325cc 100644
@@ -15,7 +15,7 @@ with CXL Host Bridges, which have CXL Root Ports which may be directly
 attached to CXL or PCI End Points. Alternatively there may be CXL Switches
 with CXL and PCI Endpoints attached below them.  In many cases additional
 control and capabilities are exposed via PCI Express interfaces.
-This sharing of interfaces and hence emulation code is is reflected
+This sharing of interfaces and hence emulation code is reflected
 in how the devices are emulated in QEMU. In most cases the various
 CXL elements are built upon an equivalent PCIe devices.
 
docs/system/s390x/bootdevices.rst +1 -1
index 9e591cb9dc..b5950133e8 100644
@@ -65,7 +65,7 @@ you can specify it via the ``-global s390-ipl.netboot_fw=filename``
 command line option.
 
 The ``bootindex`` property is especially important for booting via the network.
-If you don't specify the the ``bootindex`` property here, the network bootloader
+If you don't specify the ``bootindex`` property here, the network bootloader
 firmware code won't get loaded into the guest memory so that the network boot
 will fail. For a successful network boot, try something like this::
 
docs/system/tls.rst +1 -1
index 1a04674362..e284c82801 100644
@@ -182,7 +182,7 @@ certificates.
               --template client-hostNNN.info \
               --outfile client-hostNNN-cert.pem
 
-The subject alt name extension data is not required for clients, so the
+The subject alt name extension data is not required for clients, so
 the ``dns_name`` and ``ip_address`` fields are not included. The
 ``tls_www_client`` keyword is the key purpose extension to indicate this
 certificate is intended for usage in a web client. Although QEMU network
docs/tools/qemu-pr-helper.rst +1 -1
index eaebe40da0..bbd8b6c3ce 100644
@@ -22,7 +22,7 @@ storage fabric. QEMU's SCSI passthrough devices ``scsi-block``
 and ``scsi-generic`` support passing guest persistent reservation
 requests to a privileged external helper program. :program:`qemu-pr-helper`
 is that external helper; it creates a socket which QEMU can
-connect to to communicate with it.
+connect to communicate with it.
 
 If you want to run VMs in a setup like this, this helper should be
 started as a system service, and you should read the QEMU manual
hw/core/clock.c +1 -1
index 916875e07a..d82e44cd1a 100644
@@ -68,7 +68,7 @@ static uint64_t clock_get_child_period(Clock *clk)
 {
     /*
      * Return the period to be used for child clocks, which is the parent
-     * clock period adjusted for for multiplier and divider effects.
+     * clock period adjusted for multiplier and divider effects.
      */
     return muldiv64(clk->period, clk->multiplier, clk->divider);
 }
hw/intc/arm_gicv3_redist.c +1 -1
index f1ecb2502b..c92ceecc16 100644
@@ -492,7 +492,7 @@ static MemTxResult gicr_writel(GICv3CPUState *cs, hwaddr offset,
         return MEMTX_OK;
     case GICR_WAKER:
         /* Only the ProcessorSleep bit is writable. When the guest sets
-         * it it requests that we transition the channel between the
+         * it, it requests that we transition the channel between the
          * redistributor and the cpu interface to quiescent, and that
          * we set the ChildrenAsleep bit once the inteface has reached the
          * quiescent state.
hw/misc/iotkit-secctl.c +1 -1
index 7b41cfa8fc..b5a9e30a2c 100644
@@ -114,7 +114,7 @@ static const uint8_t iotkit_secctl_ns_sse300_idregs[] = {
  * AHB expansion, APB expansion) are all set up so that they are
  * in 16-aligned blocks so offsets 0xN0, 0xN4, 0xN8, 0xNC are PPCs
  * 0, 1, 2, 3 of that type, so we can convert a register address offset
- * into an an index into a PPC array easily.
+ * into an index into a PPC array easily.
  */
 static inline int offset_to_ppc_idx(uint32_t offset)
 {
hw/misc/iotkit-sysctl.c +2 -2
index 9ee8fe8495..7147e2f84e 100644
@@ -237,7 +237,7 @@ static uint64_t iotkit_sysctl_read(void *opaque, hwaddr offset,
             r = s->ewctrl;
             break;
         case ARMSSE_SSE300:
-            /* In SSE300 this offset is is NMI_ENABLE */
+            /* In SSE300 this offset is NMI_ENABLE */
             r = s->nmi_enable;
             break;
         default:
@@ -555,7 +555,7 @@ static void iotkit_sysctl_write(void *opaque, hwaddr offset,
             s->ewctrl = value;
             break;
         case ARMSSE_SSE300:
-            /* In SSE300 this offset is is NMI_ENABLE */
+            /* In SSE300 this offset is NMI_ENABLE */
             qemu_log_mask(LOG_UNIMP, "IoTKit SysCtl NMI_ENABLE unimplemented\n");
             s->nmi_enable = value;
             break;
hw/s390x/s390-ccw.c +1 -1
index 2fc8bb9c23..e2d86d96e7 100644
@@ -57,7 +57,7 @@ IOInstEnding s390_ccw_store(SubchDev *sch)
 
     /*
      * This code is called for both virtual and passthrough devices,
-     * but only applies to to the latter.  This ugly check makes that
+     * but only applies to the latter.  This ugly check makes that
      * distinction for us.
      */
     if (object_dynamic_cast(OBJECT(sch->driver_data), TYPE_S390_CCW)) {
hw/usb/u2f.h +1 -1
index db30f3586b..a408a82927 100644
@@ -74,7 +74,7 @@ typedef struct U2FKeyState {
 
 /*
  * API to be used by the U2F key device variants (i.e. hw/u2f-*.c)
- * to interact with the the U2F key base device (i.e. hw/u2f.c)
+ * to interact with the U2F key base device (i.e. hw/u2f.c)
  */
 void u2f_send_to_guest(U2FKeyState *key,
                        const uint8_t packet[U2FHID_PACKET_SIZE]);
include/hw/qdev-core.h +1 -1
index 98774e2835..785dd5a56e 100644
@@ -386,7 +386,7 @@ bool qdev_realize_and_unref(DeviceState *dev, BusState *bus, Error **errp);
  *
  *  - unrealize any child buses by calling qbus_unrealize()
  *    (this will recursively unrealize any devices on those buses)
- *  - call the the unrealize method of @dev
+ *  - call the unrealize method of @dev
  *
  * The device can then be freed by causing its reference count to go
  * to zero.
include/user/safe-syscall.h +1 -1
index 61a04e2b5a..ddceef12e2 100644
@@ -70,7 +70,7 @@
  * If the host libc is used then the implementation will appear to work
  * most of the time, but there will be a race condition where a
  * signal could arrive just before we make the host syscall inside libc,
- * and then then guest syscall will not correctly be interrupted.
+ * and then the guest syscall will not correctly be interrupted.
  * Instead the implementation of the guest syscall can use the safe_syscall
  * function but otherwise just return the result or errno in the usual
  * way; the main loop code will take care of restarting the syscall
linux-user/i386/cpu_loop.c +1 -1
index 492701dd9a..42837399bc 100644
@@ -137,7 +137,7 @@ static void emulate_vsyscall(CPUX86State *env)
     }
 
     /*
-     * Validate the the pointer arguments.
+     * Validate the pointer arguments.
      */
     switch (syscall) {
     case TARGET_NR_gettimeofday:
pc-bios/s390-ccw/virtio-scsi.c +1 -1
index 2c8d0f3097..45256b3fdb 100644
@@ -195,7 +195,7 @@ static bool scsi_read_capacity(VDev *vdev,
 /* virtio-scsi routines */
 
 /*
- * Tries to locate a SCSI device and and adds the information for the found
+ * Tries to locate a SCSI device and adds the information for the found
  * device to the vdev->scsi_device structure.
  * Returns 0 if SCSI device could be located, or a error code < 0 otherwise
  */
python/Makefile +1 -1
index 3334311362..b170708398 100644
@@ -29,7 +29,7 @@ help:
 	@echo "    Performs no environment setup of any kind."
 	@echo ""
 	@echo "make develop:"
-	@echo "    Install deps needed for for 'make check',"
+	@echo "    Install deps needed for 'make check',"
 	@echo "    and install the qemu package in editable mode."
 	@echo "    (Can be used in or outside of a venv.)"
 	@echo ""
python/qemu/utils/__init__.py +1 -1
index 9fb273b13d..017cfdcda7 100644
@@ -79,7 +79,7 @@ def add_visual_margin(
     :param content: The text to wrap and decorate.
     :param width:
         The number of columns to use, including for the decoration
-        itself. The default (None) uses the the available width of the
+        itself. The default (None) uses the available width of the
         current terminal, or a fallback of 72 lines. A negative number
         subtracts a fixed-width from the default size. The default obeys
         the COLUMNS environment variable, if set.
target/arm/translate.c +1 -1
index 6617de775f..73d1faf917 100644
@@ -8056,7 +8056,7 @@ static TCGv_i32 op_addr_block_pre(DisasContext *s, arg_ldst_block *a, int n)
          * If the writeback is incrementing SP rather than
          * decrementing it, and the initial SP is below the
          * stack limit but the final written-back SP would
-         * be above, then then we must not perform any memory
+         * be above, then we must not perform any memory
          * accesses, but it is IMPDEF whether we generate
          * an exception. We choose to do so in this case.
          * At this point 'addr' is the lowest address, so
target/i386/cpu.c +1 -1
index 6a57ef13af..194b5a31af 100644
@@ -3632,7 +3632,7 @@ static const X86CPUDefinition builtin_x86_defs[] = {
             CPUID_7_0_EDX_CORE_CAPABILITY,
         .features[FEAT_CORE_CAPABILITY] =
             MSR_CORE_CAP_SPLIT_LOCK_DETECT,
-        /* XSAVES is is added in version 3 */
+        /* XSAVES is added in version 3 */
         .features[FEAT_XSAVE] =
             CPUID_XSAVE_XSAVEOPT | CPUID_XSAVE_XSAVEC |
             CPUID_XSAVE_XGETBV1,
tcg/i386/tcg-target.c.inc +1 -1
index d52206ba4d..cb04e4b3ad 100644
@@ -1652,7 +1652,7 @@ static void tcg_out_branch(TCGContext *s, int call, const tcg_insn_unit *dest)
     } else {
         /* rip-relative addressing into the constant pool.
            This is 6 + 8 = 14 bytes, as compared to using an
-           an immediate load 10 + 6 = 16 bytes, plus we may
+           immediate load 10 + 6 = 16 bytes, plus we may
            be able to re-use the pool constant for more calls.  */
         tcg_out_opc(s, OPC_GRP5, 0, 0, 0);
         tcg_out8(s, (call ? EXT5_CALLN_Ev : EXT5_JMPN_Ev) << 3 | 5);
tests/qtest/microbit-test.c +2 -2
index 04e199ec33..6cc1f5d932 100644
@@ -449,9 +449,9 @@ static void test_nrf51_timer(void)
     timer_set_prescaler(qts, 0);
     /* Swept over in first step */
     timer_set_cc(qts, 0, 2);
-    /* Barely miss on first step */
+    /* Barely miss in first step */
     timer_set_cc(qts, 1, 162);
-    /* Spot on on third step */
+    /* Spot on in third step */
     timer_set_cc(qts, 2, 480);
 
     timer_assert_events(qts, 0, 0, 0, 0);
tools/virtiofsd/fuse_virtio.c +1 -1
index a52eacf82e..9368e292e4 100644
@@ -379,7 +379,7 @@ int virtio_send_data_iov(struct fuse_session *se, struct fuse_chan *ch,
     copy_iov(iov, count, in_sg, in_num, iov_len);
 
     /*
-     * Build a copy of the the in_sg iov so we can skip bits in it,
+     * Build a copy of the in_sg iov so we can skip bits in it,
      * including changing the offsets
      */
     in_sg_cpy = g_new(struct iovec, in_num);
Signature · 1 line
2.36.1
#9 lore raw

Re: [PATCH v2 4/7] misc: fix commonly doubled up words

docs/tools/qemu-pr-helper.rst storage fabric. QEMU's SCSI passthrough devices ``scsi-block`` · line 25

Quoted 12 lines · Daniel P. Berrangé

---

docs/tools/qemu-pr-helper.rst +1 -1
@@ -22,7 +22,7 @@ storage fabric. QEMU's SCSI passthrough devices ``scsi-block``
 and ``scsi-generic`` support passing guest persistent reservation
 requests to a privileged external helper program. :program:`qemu-pr-helper`
 is that external helper; it creates a socket which QEMU can
-connect to to communicate with it.
+connect to communicate with it.

This text is correct as it stands, and the change is wrong.

Quoted 5 lines
tests/qtest/microbit-test.c +0 -0
index 04e199ec33..6cc1f5d932 100644

tests/qtest/microbit-test.c static void test_nrf51_timer(void) · line 455

Quoted 9 lines
tests/qtest/microbit-test.c +2 -2
@@ -449,9 +449,9 @@ static void test_nrf51_timer(void)
     timer_set_prescaler(qts, 0);
     /* Swept over in first step */
     timer_set_cc(qts, 0, 2);
-    /* Barely miss on first step */
+    /* Barely miss in first step */
     timer_set_cc(qts, 1, 162);
-    /* Spot on on third step */
+    /* Spot on in third step */
     timer_set_cc(qts, 2, 480);

These changes also look wrong.

The rest seems OK.

thanks
-- PMM

#10 lore raw

Re: [PATCH v2 4/7] misc: fix commonly doubled up words

Quoted 5 lines · Peter Maydell
Quoted 3 lines · Daniel P. Berrangé

---

Quoted 10 lines

docs/tools/qemu-pr-helper.rst storage fabric. QEMU's SCSI passthrough devices ``scsi-block`` · line 25

Quoted 8 lines
docs/tools/qemu-pr-helper.rst +1 -1
@@ -22,7 +22,7 @@ storage fabric. QEMU's SCSI passthrough devices ``scsi-block``
 and ``scsi-generic`` support passing guest persistent reservation
 requests to a privileged external helper program. :program:`qemu-pr-helper`
 is that external helper; it creates a socket which QEMU can
-connect to to communicate with it.
+connect to communicate with it.

This text is correct as it stands, and the change is wrong.

I think the current text is a rather awkward, so I'll rephrase it next time.

Quoted 8 lines
Quoted 8 lines
tests/qtest/microbit-test.c +0 -0
index 04e199ec33..6cc1f5d932 100644
@@ -449,9 +449,9 @@ static void test_nrf51_timer(void)
     timer_set_prescaler(qts, 0);
     /* Swept over in first step */
     timer_set_cc(qts, 0, 2);
Quoted 8 lines

tests/qtest/microbit-test.c static void test_nrf51_timer(void) · line 455

Quoted 6 lines
tests/qtest/microbit-test.c +2 -2
-    /* Barely miss on first step */
+    /* Barely miss in first step */
     timer_set_cc(qts, 1, 162);
-    /* Spot on on third step */
+    /* Spot on in third step */
     timer_set_cc(qts, 2, 480);

These changes also look wrong.

It makes them consistent wth the first comment "Swept over in first step"

Also that 'Barely miss in first step' ought to say 'secound step'

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#11 lore raw

Re: [PATCH v2 4/7] misc: fix commonly doubled up words

Quoted 38 lines · Daniel P. Berrangé
Quoted 5 lines · Peter Maydell
Quoted 3 lines · Daniel P. Berrangé

---

Quoted 10 lines

docs/tools/qemu-pr-helper.rst storage fabric. QEMU's SCSI passthrough devices ``scsi-block`` · line 25

Quoted 8 lines
docs/tools/qemu-pr-helper.rst +1 -1
@@ -22,7 +22,7 @@ storage fabric. QEMU's SCSI passthrough devices ``scsi-block``
 and ``scsi-generic`` support passing guest persistent reservation
 requests to a privileged external helper program. :program:`qemu-pr-helper`
 is that external helper; it creates a socket which QEMU can
-connect to to communicate with it.
+connect to communicate with it.

This text is correct as it stands, and the change is wrong.

I think the current text is a rather awkward, so I'll rephrase it next time.

Quoted 8 lines
Quoted 8 lines
tests/qtest/microbit-test.c +0 -0
index 04e199ec33..6cc1f5d932 100644
@@ -449,9 +449,9 @@ static void test_nrf51_timer(void)
     timer_set_prescaler(qts, 0);
     /* Swept over in first step */
     timer_set_cc(qts, 0, 2);
Quoted 8 lines

tests/qtest/microbit-test.c static void test_nrf51_timer(void) · line 455

Quoted 6 lines
tests/qtest/microbit-test.c +2 -2
-    /* Barely miss on first step */
+    /* Barely miss in first step */
     timer_set_cc(qts, 1, 162);
-    /* Spot on on third step */
+    /* Spot on in third step */
     timer_set_cc(qts, 2, 480);

These changes also look wrong.

Quoted 1 line

It makes them consistent wth the first comment "Swept over in first step"

There's a difference between "in step X" -- during the duration of the step, and "on step X" -- at the point where the step stops.

-- PMM

#12 lore raw

PATCH v2 5/7 tests/style: check for commonly doubled up words

In reply to Daniel P. Berrangé

This style check looks for cases where the words

the then in an on if is it but for or at and do to

are repeated in a sentence. It doesn't use the simple regex match logic because it needs to match repeats across lines, so has a custom crafted rule.

---
 tests/style-excludes.mak | 12 ++++++++++++
 tests/style.mak          | 24 ++++++++++++++++++++++++
 2 files changed, 36 insertions(+)
tests/style-excludes.mak +12 -0
index 32c0e9c328..931dd03a64 100644
@@ -2,3 +2,15 @@
 #
 # Filenames that should be excluded from specific
 # style checks performed by style.mak
+
+exclude_file_name_regexp--sc_prohibit_doubled_word = \
+	disas/sparc\.c \
+	hw/char/terminal3270\.c \
+	include/crypto/afsplit\.h \
+	qemu-options\.hx \
+	scripts/checkpatch\.pl \
+	target/s390x/tcg/insn-data\.def \
+	pc-bios/slof\.bin \
+	tests/qemu-iotests/142(\.out)? \
+	tests/qtest/arm-cpu-features\.c \
+	ui/cursor\.c
tests/style.mak +24 -0
index ae658395c9..4056bde619 100644
@@ -28,3 +28,27 @@ sc_int_assign_bool:
 	@prohibit='\<int\>.*= *(true|false)\b' \
 	halt='use bool type for boolean values' \
 	$(_sc_search_regexp)
+
+prohibit_doubled_words_ = \
+    the then in an on if is it but for or at and do to can
+# expand the regex before running the check to avoid using expensive captures
+prohibit_doubled_word_expanded_ = \
+    $(join $(prohibit_doubled_words_),$(addprefix \s+,$(prohibit_doubled_words_)))
+prohibit_doubled_word_RE_ ?= \
+    /\b(?:$(subst $(_sp),|,$(prohibit_doubled_word_expanded_)))\b/gims
+prohibit_doubled_word_ =						\
+    -e 'while ($(prohibit_doubled_word_RE_))'				\
+    $(perl_filename_lineno_text_)
+
+# Define this to a regular expression that matches
+# any filename:dd:match lines you want to ignore.
+# The default is to ignore no matches.
+ignore_doubled_word_match_RE_ ?= ^$$
+
+sc_prohibit_doubled_word:
+	@$(VC_LIST_EXCEPT)						\
+	  | xargs perl -n -0777 $(prohibit_doubled_word_)		\
+	  | $(GREP) -vE '$(ignore_doubled_word_match_RE_)'		\
+	  | $(GREP) .							\
+	  && { echo '$(ME): doubled words' 1>&2; exit 1; }		\
+	  || :
Signature · 1 line
2.36.1
#13 lore raw

PATCH v2 6/7 misc: ensure qemu/osdep.h is included in all .c files

In reply to Daniel P. Berrangé

A few files relied on qemu/osdep.h being included via a common header. Another file didn't need it because it was actually an included file, so ought to have been named .c.inc

---
 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 ++
 crypto/rsakey.c                       | 1 +
 qga/cutils.c                          | 2 ++
 10 files changed, 15 insertions(+), 2 deletions(-)
 rename bsd-user/{elfcore.c => elfcore.c.inc} (100%)
bsd-user/arm/signal.c +2 -0
index 2b1dd745d1..eca20ac4d7 100644
@@ -17,6 +17,8 @@
  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
+#include "qemu/osdep.h"
+
 #include "qemu.h"
 
 /*
bsd-user/arm/target_arch_cpu.c +3 -0
index 02bf9149d5..186cf43fb9 100644
@@ -16,6 +16,9 @@
  *  You should have received a copy of the GNU General Public License
  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
+
+#include "qemu/osdep.h"
+
 #include "target_arch.h"
 
 void target_cpu_set_tls(CPUARMState *env, target_ulong newtls)
bsd-user/elfcore.c.inc renamed from bsd-user/elfcore.c +0 -0
similarity index 100%
rename from bsd-user/elfcore.c
rename to bsd-user/elfcore.c.inc
bsd-user/elfload.c +1 -1
index f8edb22f2a..1717a454dc 100644
@@ -121,7 +121,7 @@ static void bswap_note(struct elf_note *en) { }
 
 #endif /* ! BSWAP_NEEDED */
 
-#include "elfcore.c"
+#include "elfcore.c.inc"
 
 /*
  * 'copy_elf_strings()' copies argument/envelope strings from user
bsd-user/freebsd/os-sys.c +2 -0
index 309e27b9d6..1eab1be6f6 100644
@@ -17,6 +17,8 @@
  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
+#include "qemu/osdep.h"
+
 #include "qemu.h"
 #include "target_arch_sysarch.h"
 
bsd-user/i386/signal.c +2 -0
index 5dd975ce56..db5b774213 100644
@@ -17,6 +17,8 @@
  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
+#include "qemu/osdep.h"
+
 #include "qemu.h"
 
 /*
bsd-user/qemu.h +0 -1
index be6105385e..0ceecfb6df 100644
@@ -17,7 +17,6 @@
 #ifndef QEMU_H
 #define QEMU_H
 
-#include "qemu/osdep.h"
 #include "cpu.h"
 #include "qemu/units.h"
 #include "exec/cpu_ldst.h"
bsd-user/x86_64/signal.c +2 -0
index c3875bc4c6..217f9ceb66 100644
@@ -16,6 +16,8 @@
  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
+#include "qemu/osdep.h"
+
 #include "qemu.h"
 
 /*
crypto/rsakey.c +1 -0
index cc40e072f0..dcdbd9ec57 100644
@@ -19,6 +19,7 @@
  *
  */
 
+#include "qemu/osdep.h"
 #include "rsakey.h"
 
 void qcrypto_akcipher_rsakey_free(QCryptoAkCipherRSAKey *rsa_key)
qga/cutils.c +2 -0
index b8e142ef64..c53dd418c7 100644
@@ -2,6 +2,8 @@
  * This work is licensed under the terms of the GNU GPL, version 2 or later.
  * See the COPYING file in the top-level directory.
  */
+
+#include "qemu/osdep.h"
 #include "cutils.h"
 
 #include "qapi/error.h"
Signature · 1 line
2.36.1
Reviewed-by on v2 6/7
#14 lore raw

Re: [PATCH v2 6/7] misc: ensure qemu/osdep.h is included in all .c files

Quoted 5 lines · Daniel P. Berrangé

A few files relied on qemu/osdep.h being included via a common header. Another file didn't need it because it was actually an included file, so ought to have been named .c.inc

Quoted 14 lines
---
 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 ++
 crypto/rsakey.c                       | 1 +
 qga/cutils.c                          | 2 ++
 10 files changed, 15 insertions(+), 2 deletions(-)
 rename bsd-user/{elfcore.c => elfcore.c.inc} (100%)

The change to bsd-user is fine, though will cause many ripples in the upstream
branch when I merge it. The ripples likely are worth it in the long run, and knowing
they are coming and helps me prepare the tree for the merge.

It also reminds me that once I'm done upstreaming, there's likely benefit from having
a common elf loader / core generator as much of this code is copied from linux-user
with the qemu style layered on top....

Quoted 127 lines
bsd-user/arm/signal.c +2 -0
index 2b1dd745d1..eca20ac4d7 100644
@@ -17,6 +17,8 @@
  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
+#include "qemu/osdep.h"
+
 #include "qemu.h"
 
 /*
bsd-user/arm/target_arch_cpu.c +3 -0
index 02bf9149d5..186cf43fb9 100644
@@ -16,6 +16,9 @@
  *  You should have received a copy of the GNU General Public License
  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
+
+#include "qemu/osdep.h"
+
 #include "target_arch.h"
 
 void target_cpu_set_tls(CPUARMState *env, target_ulong newtls)
bsd-user/elfcore.c.inc renamed from bsd-user/elfcore.c +0 -0
similarity index 100%
rename from bsd-user/elfcore.c
rename to bsd-user/elfcore.c.inc
bsd-user/elfload.c +1 -1
index f8edb22f2a..1717a454dc 100644
@@ -121,7 +121,7 @@ static void bswap_note(struct elf_note *en) { }
 
 #endif /* ! BSWAP_NEEDED */
 
-#include "elfcore.c"
+#include "elfcore.c.inc"
 
 /*
  * 'copy_elf_strings()' copies argument/envelope strings from user
bsd-user/freebsd/os-sys.c +2 -0
index 309e27b9d6..1eab1be6f6 100644
@@ -17,6 +17,8 @@
  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
+#include "qemu/osdep.h"
+
 #include "qemu.h"
 #include "target_arch_sysarch.h"
 
bsd-user/i386/signal.c +2 -0
index 5dd975ce56..db5b774213 100644
@@ -17,6 +17,8 @@
  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
+#include "qemu/osdep.h"
+
 #include "qemu.h"
 
 /*
bsd-user/qemu.h +0 -1
index be6105385e..0ceecfb6df 100644
@@ -17,7 +17,6 @@
 #ifndef QEMU_H
 #define QEMU_H
 
-#include "qemu/osdep.h"
 #include "cpu.h"
 #include "qemu/units.h"
 #include "exec/cpu_ldst.h"
bsd-user/x86_64/signal.c +2 -0
index c3875bc4c6..217f9ceb66 100644
@@ -16,6 +16,8 @@
  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
+#include "qemu/osdep.h"
+
 #include "qemu.h"
 
 /*
crypto/rsakey.c +1 -0
index cc40e072f0..dcdbd9ec57 100644
@@ -19,6 +19,7 @@
  *
  */
 
+#include "qemu/osdep.h"
 #include "rsakey.h"
 
 void qcrypto_akcipher_rsakey_free(QCryptoAkCipherRSAKey *rsa_key)
qga/cutils.c +0 -0
index b8e142ef64..c53dd418c7 100644
@@ -2,6 +2,8 @@
  * This work is licensed under the terms of the GNU GPL, version 2 or

later.
* See the COPYING file in the top-level directory. */

qga/cutils.c +2 -1
+
+#include "qemu/osdep.h"
 #include "cutils.h"
 
 #include "qapi/error.h"
--

2.36.1

#15 lore raw

Re: [PATCH v2 6/7] misc: ensure qemu/osdep.h is included in all .c files

Quoted 23 lines · Warner Losh
Quoted 5 lines · Daniel P. Berrangé

A few files relied on qemu/osdep.h being included via a common header. Another file didn't need it because it was actually an included file, so ought to have been named .c.inc

Quoted 14 lines
---
 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 ++
 crypto/rsakey.c                       | 1 +
 qga/cutils.c                          | 2 ++
 10 files changed, 15 insertions(+), 2 deletions(-)
 rename bsd-user/{elfcore.c => elfcore.c.inc} (100%)
Quoted 5 lines

The change to bsd-user is fine, though will cause many ripples in the upstream
branch when I merge it. The ripples likely are worth it in the long run, and knowing
they are coming and helps me prepare the tree for the merge.

If you prefer to delay these changes I don't mind. It just means that it would need a 'bsd-user/.*' exclude rule in the next patch to temporarily skip this chck for bsd-user code.

Quoted 7 lines

It also reminds me that once I'm done upstreaming, there's likely benefit from having
a common elf loader / core generator as much of this code is copied from linux-user
with the qemu style layered on top....

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#16 lore raw

Re: [PATCH v2 6/7] misc: ensure qemu/osdep.h is included in all .c files

Quoted 30 lines · Daniel P. Berrangé
Quoted 23 lines · Warner Losh
Quoted 5 lines · Daniel P. Berrangé

A few files relied on qemu/osdep.h being included via a common header. Another file didn't need it because it was actually an included file, so ought to have been named .c.inc

Quoted 14 lines
---
 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 ++
 crypto/rsakey.c                       | 1 +
 qga/cutils.c                          | 2 ++
 10 files changed, 15 insertions(+), 2 deletions(-)
 rename bsd-user/{elfcore.c => elfcore.c.inc} (100%)
Quoted 5 lines

The change to bsd-user is fine, though will cause many ripples in the upstream
branch when I merge it. The ripples likely are worth it in the long run, and knowing
they are coming and helps me prepare the tree for the merge.

Quoted 4 lines

If you prefer to delay these changes I don't mind. It just means that it would need a 'bsd-user/.*' exclude rule in the next patch to temporarily skip this chck for bsd-user code.

No. Go ahead. I know I need to do something when I do the next merge. And it shouldn't be a big deal to do now, otherwise I'll forget...

Warner

Quoted 20 lines

It also reminds me that once I'm done upstreaming, there's likely benefit

Quoted 6 lines

from having
a common elf loader / core generator as much of this code is copied from linux-user
with the qemu style layered on top....

With regards,
Daniel
--
|: https://berrange.com -o-
https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o-
https://fstop138.berrange.com :|
|: https://entangle-photo.org -o-
https://www.instagram.com/dberrange :|

#17 lore raw

PATCH v2 7/7 tests/style: check qemu/osdep.h is included in all .c files

In reply to Daniel P. Berrangé
---
 tests/style-excludes.mak | 17 +++++++++++++++++
 tests/style.mak          |  6 ++++++
 2 files changed, 23 insertions(+)
tests/style-excludes.mak +17 -0
index 931dd03a64..df158e1d9d 100644
@@ -14,3 +14,20 @@ exclude_file_name_regexp--sc_prohibit_doubled_word = \
 	tests/qemu-iotests/142(\.out)? \
 	tests/qtest/arm-cpu-features\.c \
 	ui/cursor\.c
+
+exclude_file_name_regexp--sc_c_file_osdep_h = \
+	contrib/plugins/.* \
+	linux-user/(mips64|x86_64)/(signal|cpu_loop)\.c \
+	pc-bios/.* \
+	scripts/coverity-scan/model\.c \
+	scripts/xen-detect\.c \
+	subprojects/.* \
+	target/hexagon/(gen_semantics|gen_dectree_import)\.c \
+	target/s390x/gen-features\.c \
+	tests/migration/s390x/a-b-bios\.c \
+	tests/multiboot/.* \
+	tests/plugin/.* \
+	tests/tcg/.* \
+	tests/uefi-test-tools/.* \
+	tests/unit/test-rcu-(simpleq|slist|tailq)\.c \
+	tools/ebpf/rss.bpf.c
tests/style.mak +6 -0
index 4056bde619..301d978155 100644
@@ -52,3 +52,9 @@ sc_prohibit_doubled_word:
 	  | $(GREP) .							\
 	  && { echo '$(ME): doubled words' 1>&2; exit 1; }		\
 	  || :
+
+sc_c_file_osdep_h:
+	@require='#include "qemu/osdep.h"' \
+	in_vc_files='\.c$$' \
+	halt='all C files must include qemu/osdep.h' \
+	$(_sc_search_regexp)
Signature · 1 line
2.36.1
#18 lore raw

Re: [PATCH v2 7/7] tests/style: check qemu/osdep.h is included in all .c files

tests/style.mak sc_prohibit_doubled_word: · line 60

Quoted 9 lines · Daniel P. Berrangé
tests/style.mak +6 -0
+
+sc_c_file_osdep_h:
+       @require='#include "qemu/osdep.h"' \
+       in_vc_files='\.c$$' \
+       halt='all C files must include qemu/osdep.h' \
+       $(_sc_search_regexp)

The rule is not just "included in all C files", but "included as the *first* include in all C files".

thanks
-- PMM

#19 lore raw

Re: [PATCH v2 7/7] tests/style: check qemu/osdep.h is included in all .c files

Quoted 4 lines · Peter Maydell
Quoted 2 lines · Daniel P. Berrangé
Quoted 9 lines

tests/style.mak sc_prohibit_doubled_word: · line 60

Quoted 6 lines
tests/style.mak +6 -0
+
+sc_c_file_osdep_h:
+       @require='#include "qemu/osdep.h"' \
+       in_vc_files='\.c$$' \
+       halt='all C files must include qemu/osdep.h' \
+       $(_sc_search_regexp)

The rule is not just "included in all C files", but "included as the *first* include in all C files".

Oh right, so we can copy a rule from libvirt to validate that.

It would look like this, but s,config.h,qemu/osdep.h,

# Print each file name for which the first #include does not match # $(config_h_header). Like grep -m 1, this only looks at the first match. perl_config_h_first_ = \
-e 'BEGIN {$$ret = 0}' \
-e 'if (/^\# *include\b/) {' \
-e ' if (not m{^\# *include $(config_h_header)}) {' \
-e ' print "$$ARGV\n";' \
-e ' $$ret = 1;' \

  -e '  }' \
  -e '  \# Move on to next file after first include' \
  -e '  close ARGV;' \

-e '}' \
-e 'END {exit $$ret}'

# You must include <config.h> before including any other header file. # This can possibly be via a package-specific header, if given by syntax-check.mk. sc_require_config_h_first:

	@if $(VC_LIST_EXCEPT) | $(GREP) '\.c$$' > /dev/null; then \
	  files=$$($(VC_LIST_EXCEPT) | $(GREP) '\.c$$') && \
	  perl -n $(perl_config_h_first_) $$files || \
	    { echo 'the above files include some other header' \
		'before <config.h>' 1>&2; exit 1; } || :; \
	else :; \
	fi

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#20 lore raw

Re: [PATCH v2 7/7] tests/style: check qemu/osdep.h is included in all .c files

Quoted 38 lines · Daniel P. Berrangé
Quoted 4 lines · Peter Maydell
Quoted 2 lines · Daniel P. Berrangé
Quoted 9 lines

tests/style.mak sc_prohibit_doubled_word: · line 60

Quoted 6 lines
tests/style.mak +6 -0
+
+sc_c_file_osdep_h:
+       @require='#include "qemu/osdep.h"' \
+       in_vc_files='\.c$$' \
+       halt='all C files must include qemu/osdep.h' \
+       $(_sc_search_regexp)

The rule is not just "included in all C files", but "included as the *first* include in all C files".

Oh right, so we can copy a rule from libvirt to validate that.

It would look like this, but s,config.h,qemu/osdep.h,

# Print each file name for which the first #include does not match # $(config_h_header). Like grep -m 1, this only looks at the first match. perl_config_h_first_ = \
-e 'BEGIN {$$ret = 0}' \
-e 'if (/^\# *include\b/) {' \
-e ' if (not m{^\# *include $(config_h_header)}) {' \
-e ' print "$$ARGV\n";' \
-e ' $$ret = 1;' \

  -e '  }' \
  -e '  \# Move on to next file after first include' \
  -e '  close ARGV;' \

-e '}' \
-e 'END {exit $$ret}'

# You must include <config.h> before including any other header file. # This can possibly be via a package-specific header, if given by syntax-check.mk. sc_require_config_h_first:

Quoted 7 lines
        @if $(VC_LIST_EXCEPT) | $(GREP) '\.c$$' > /dev/null; then \
          files=$$($(VC_LIST_EXCEPT) | $(GREP) '\.c$$') && \
          perl -n $(perl_config_h_first_) $$files || \
            { echo 'the above files include some other header' \
                'before <config.h>' 1>&2; exit 1; } || :; \
        else :; \
        fi

As an example syntax checking rule I think this makes a pretty convincing case for the argument "make is the wrong language/framework for this job"...

thanks
-- PMM

#21 lore raw

Re: [PATCH v2 7/7] tests/style: check qemu/osdep.h is included in all .c files

Quoted 47 lines · Peter Maydell
Quoted 38 lines · Daniel P. Berrangé
Quoted 4 lines · Peter Maydell
Quoted 2 lines · Daniel P. Berrangé
Quoted 9 lines

tests/style.mak sc_prohibit_doubled_word: · line 60

Quoted 6 lines
tests/style.mak +6 -0
+
+sc_c_file_osdep_h:
+       @require='#include "qemu/osdep.h"' \
+       in_vc_files='\.c$$' \
+       halt='all C files must include qemu/osdep.h' \
+       $(_sc_search_regexp)

The rule is not just "included in all C files", but "included as the *first* include in all C files".

Oh right, so we can copy a rule from libvirt to validate that.

It would look like this, but s,config.h,qemu/osdep.h,

# Print each file name for which the first #include does not match # $(config_h_header). Like grep -m 1, this only looks at the first match. perl_config_h_first_ = \
-e 'BEGIN {$$ret = 0}' \
-e 'if (/^\# *include\b/) {' \
-e ' if (not m{^\# *include $(config_h_header)}) {' \
-e ' print "$$ARGV\n";' \
-e ' $$ret = 1;' \

  -e '  }' \
  -e '  \# Move on to next file after first include' \
  -e '  close ARGV;' \

-e '}' \
-e 'END {exit $$ret}'

# You must include <config.h> before including any other header file. # This can possibly be via a package-specific header, if given by syntax-check.mk. sc_require_config_h_first:

Quoted 7 lines
        @if $(VC_LIST_EXCEPT) | $(GREP) '\.c$$' > /dev/null; then \
          files=$$($(VC_LIST_EXCEPT) | $(GREP) '\.c$$') && \
          perl -n $(perl_config_h_first_) $$files || \
            { echo 'the above files include some other header' \
                'before <config.h>' 1>&2; exit 1; } || :; \
        else :; \
        fi
Quoted 3 lines

As an example syntax checking rule I think this makes a pretty convincing case for the argument "make is the wrong language/framework for this job"...

Matching contextually across multiple lines of text is admittedly hard. IME most of the usage of this syntax checking facility we had in libvirt can be handled using single line matches, which are trivial to provide.

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|