From nobody Wed May 14 13:18:30 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1523781313566198.76929916443441; Sun, 15 Apr 2018 01:35:13 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 364E0313469B; Sun, 15 Apr 2018 08:35:12 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0981062460; Sun, 15 Apr 2018 08:35:12 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id AF5FA5BBF7; Sun, 15 Apr 2018 08:35:11 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w3C7eE68006719 for ; Thu, 12 Apr 2018 03:40:14 -0400 Received: by smtp.corp.redhat.com (Postfix) id A186010B00AB; Thu, 12 Apr 2018 07:40:14 +0000 (UTC) Received: from dnr.brq.redhat.com (unknown [10.43.2.15]) by smtp.corp.redhat.com (Postfix) with ESMTP id 490BD10B009B for ; Thu, 12 Apr 2018 07:40:12 +0000 (UTC) From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Thu, 12 Apr 2018 09:40:10 +0200 Message-Id: <9e72a4444dd722b28a888165be3b9da0dddab907.1523518807.git.jtomko@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] syntax-check: check QEMU caps grouping X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Sun, 15 Apr 2018 08:35:12 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Introduce a perl script that is able to regroup both the QEMU_CAPS constants and the capability strings. Check correct grouping as a part of syntax check. For in-place regrouping after a rebase, just run: tests/group-qemu-caps.pl without any parameters. Signed-off-by: J=C3=A1n Tomko Reviewed-by: John Ferlan --- cfg.mk | 5 +- src/qemu/qemu_capabilities.h | 2 +- tests/group-qemu-caps.pl | 118 +++++++++++++++++++++++++++++++++++++++= ++++ 3 files changed, 123 insertions(+), 2 deletions(-) create mode 100755 tests/group-qemu-caps.pl diff --git a/cfg.mk b/cfg.mk index 4078bc2c6..7782ad6b3 100644 --- a/cfg.mk +++ b/cfg.mk @@ -1093,7 +1093,7 @@ _autogen_error: =20 ifneq ($(_gl-Makefile),) syntax-check: spacing-check test-wrap-argv \ - prohibit-duplicate-header mock-noinline + prohibit-duplicate-header mock-noinline group-qemu-caps endif =20 # Don't include duplicate header in the source (either *.c or *.h) @@ -1114,6 +1114,9 @@ test-wrap-argv: $(AM_V_GEN)files=3D`$(VC_LIST) | grep -E '\.(ldargs|args)'`; \ $(PERL) $(top_srcdir)/tests/test-wrap-argv.pl --check $$files =20 +group-qemu-caps: + $(PERL) $(top_srcdir)/tests/group-qemu-caps.pl --check + # sc_po_check can fail if generated files are not built first sc_po_check: \ $(srcdir)/src/remote/remote_daemon_dispatch_stubs.h \ diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index bec28cae9..00c76fdd1 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -46,7 +46,7 @@ * longer be used in code. Periodically we can then purge all the * X_ flags and re-group what's left. */ -typedef enum { +typedef enum { /* virQEMUCapsFlags grouping marker for syntax-check */ /* 0 */ X_QEMU_CAPS_KQEMU, /* Whether KQEMU is compiled in */ X_QEMU_CAPS_VNC_COLON, /* VNC takes or address + display */ diff --git a/tests/group-qemu-caps.pl b/tests/group-qemu-caps.pl new file mode 100755 index 000000000..847e36025 --- /dev/null +++ b/tests/group-qemu-caps.pl @@ -0,0 +1,118 @@ +#!/usr/bin/env perl +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library 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 +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library. If not, see +# . +# +# +# Regroup array values into smaller groups separated by numbered comments. +# +# If --check is the first parameter, the script will return +# a non-zero value if a file is not grouped correctly. +# Otherwise the files are regrouped in place. + +use strict; +use warnings; + +my $check =3D 0; + +if (defined $ARGV[0] && $ARGV[0] eq "--check") { + $check =3D 1; + shift @ARGV; +} + +my $ret =3D 0; +if (®roup_caps('src/qemu/qemu_capabilities.c', + '^VIR_ENUM_IMPL\(virQEMUCaps,', + '\);', + 0, + " ") < 0) { + $ret =3D 1; +} +if (®roup_caps('src/qemu/qemu_capabilities.h', + 'virQEMUCapsFlags grouping marker', + 'QEMU_CAPS_LAST \/\* this must', + 1, + " ") < 0) { + $ret =3D 1; +} + +exit $ret; + +sub regroup_caps { + my $filename =3D shift; + my $start_regex =3D shift; + my $end_regex =3D shift; + my $trailing_newline =3D shift; + my $counter_prefix =3D shift; + my $step =3D 5; + + open FILE, '<', $filename or die "cannot open $filename: $!"; + my @original =3D ; + close FILE; + + my @fixed; + my $game_on =3D 0; + my $counter =3D 0; + foreach (@original) { + if ($game_on) { + next if ($_ =3D~ '/\* [0-9]+ \*/'); + next if (/^\s+$/); + if ($counter % $step =3D=3D 0) { + if ($counter !=3D 0) { + push @fixed, "\n"; + } + push @fixed, "$counter_prefix/* $counter */\n"; + } + if (!($_ =3D~ '/\*' && !($_ =3D~ '\*/'))) { + # count two-line comments as one line + $counter++; + } + } + if (/$start_regex/) { + $game_on =3D 1; + } elsif ($game_on && $_ =3D~ /$end_regex/) { + if (($counter -1) % $step =3D=3D 0) { + pop @fixed; # /* $counter */ + if ($counter !=3D 1) { + pop @fixed; # \n + } + } + if ($trailing_newline) { + push @fixed, "\n"; + } + $game_on =3D 0; + } + push @fixed, $_; + } + + if ($check) { + my $nl =3D join('', @fixed); + my $ol =3D join('', @original); + unless ($nl eq $ol) { + open DIFF, "| diff -u $filename -" or die "cannot run diff: $!= "; + print DIFF $nl; + close DIFF; + + print STDERR "Incorrect array grouping in $filename\n"; + print STDERR "Use group-qemu-caps.pl to group long array membe= rs\n"; + return -1; + } + } else { + open FILE, '>', $filename or die "cannot open $filename: $!"; + foreach my $line (@fixed) { + print FILE $line; + } + close FILE; + } +} --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list