From nobody Sun Feb 8 03:58:34 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 15021350170385.936400457852187; Mon, 7 Aug 2017 12:43:37 -0700 (PDT) Received: from localhost ([::1]:39073 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1denw7-0002Jm-OG for importer@patchew.org; Mon, 07 Aug 2017 15:43:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46905) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dentO-0000nL-PH for qemu-devel@nongnu.org; Mon, 07 Aug 2017 15:40:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dentJ-0006rQ-1g for qemu-devel@nongnu.org; Mon, 07 Aug 2017 15:40:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43846) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dentI-0006pt-Oh for qemu-devel@nongnu.org; Mon, 07 Aug 2017 15:40:40 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9A279883A0 for ; Mon, 7 Aug 2017 19:40:39 +0000 (UTC) Received: from dverma.bos.com (dhcp-17-188.bos.redhat.com [10.18.17.188]) by smtp.corp.redhat.com (Postfix) with ESMTP id F0C8A18039; Mon, 7 Aug 2017 19:40:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 9A279883A0 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=dverma@redhat.com From: dverma To: qemu-devel@nongnu.org Date: Mon, 7 Aug 2017 15:40:04 -0400 Message-Id: <1502134806-13669-2-git-send-email-dverma@redhat.com> In-Reply-To: <1502134806-13669-1-git-send-email-dverma@redhat.com> References: <1502134806-13669-1-git-send-email-dverma@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Mon, 07 Aug 2017 19:40:39 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 1/3] Fix format and styles; make code more pythonic X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dverma , dgilbert@redhat.com, jen@redhat.com, quintela@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" - Format fixes, cleaned up the print statement - Style fixes, e.g. changed "if not x in y" to "if x not in y" - Improved variable names Signed-off-by: Deepak Verma --- scripts/vmstate-static-checker.py | 111 +++++++++++++++++++++-------------= ---- 1 file changed, 62 insertions(+), 49 deletions(-) diff --git a/scripts/vmstate-static-checker.py b/scripts/vmstate-static-che= cker.py index bcef7ee..b416b66 100755 --- a/scripts/vmstate-static-checker.py +++ b/scripts/vmstate-static-checker.py @@ -19,6 +19,11 @@ # You should have received a copy of the GNU General Public License along # with this program; if not, see . =20 +# +# 2017 Deepak Verma +# Added few functions and fields for whitelisting +# + import argparse import json import sys @@ -26,6 +31,7 @@ import sys # Count the number of errors found taint =3D 0 =20 + def bump_taint(): global taint =20 @@ -92,7 +98,7 @@ def check_fields_match(name, s_field, d_field): 'io_win_size', 'mig_io_win_size'], } =20 - if not name in changed_names: + if name not in changed_names: return False =20 if s_field in changed_names[name] and d_field in changed_names[name]: @@ -100,6 +106,7 @@ def check_fields_match(name, s_field, d_field): =20 return False =20 + def get_changed_sec_name(sec): # Section names can change -- see commit 292b1634 for an example. changes =3D { @@ -114,16 +121,17 @@ def get_changed_sec_name(sec): return item return "" =20 + def exists_in_substruct(fields, item): # Some QEMU versions moved a few fields inside a substruct. This # kept the on-wire format the same. This function checks if # something got shifted inside a substruct. For example, the # change in commit 1f42d22233b4f3d1a2933ff30e8d6a6d9ee2d08f =20 - if not "Description" in fields: + if "Description" not in fields: return False =20 - if not "Fields" in fields["Description"]: + if "Fields" not in fields["Description"]: return False =20 substruct_fields =3D fields["Description"]["Fields"] @@ -176,10 +184,10 @@ def check_fields(src_fields, dest_fields, desc, sec): except StopIteration: if d_iter_list =3D=3D []: # We were not in a substruct - print "Section \"" + sec + "\",", - print "Description " + "\"" + desc + "\":", - print "expected field \"" + s_item["field"] + "\",", - print "while dest has no further fields" + print('Section "' + sec + '", ' + 'Description "' + desc + '": ' + 'expected field "' + s_item["field"] + '", ' + 'while dest has no further fields') bump_taint() break =20 @@ -191,30 +199,28 @@ def check_fields(src_fields, dest_fields, desc, sec): advance_dest =3D True =20 if unused_count !=3D 0: - if advance_dest =3D=3D False: + if not advance_dest: unused_count =3D unused_count - s_item["size"] if unused_count =3D=3D 0: advance_dest =3D True continue if unused_count < 0: - print "Section \"" + sec + "\",", - print "Description \"" + desc + "\":", - print "unused size mismatch near \"", - print s_item["field"] + "\"" + print('Section "' + sec + '", ' + 'Description "' + desc + '": ' + 'unused size mismatch near "' + s_item["field"] = + '"') bump_taint() break continue =20 - if advance_src =3D=3D False: + if not advance_src: unused_count =3D unused_count - d_item["size"] if unused_count =3D=3D 0: advance_src =3D True continue if unused_count < 0: - print "Section \"" + sec + "\",", - print "Description \"" + desc + "\":", - print "unused size mismatch near \"", - print d_item["field"] + "\"" + print('Section "' + sec + '", ' + 'Description "' + desc + '": ' + 'unused size mismatch near "' + d_item["field"] = + '"') bump_taint() break continue @@ -262,16 +268,16 @@ def check_fields(src_fields, dest_fields, desc, sec): unused_count =3D s_item["size"] - d_item["size"] continue =20 - print "Section \"" + sec + "\",", - print "Description \"" + desc + "\":", - print "expected field \"" + s_item["field"] + "\",", - print "got \"" + d_item["field"] + "\"; skipping rest" + print('Section "' + sec + '", ' + 'Description "' + desc + '": ' + 'expected field "' + s_item["field"] + '", ' + 'got "' + d_item["field"] + '"; skipping rest') bump_taint() break =20 check_version(s_item, d_item, sec, desc) =20 - if not "Description" in s_item: + if "Description" not in s_item: # Check size of this field only if it's not a VMSTRUCT entry check_size(s_item, d_item, sec, desc, s_item["field"]) =20 @@ -289,18 +295,20 @@ def check_subsections(src_sub, dest_sub, desc, sec): check_descriptions(s_item, d_item, sec) =20 if not found: - print "Section \"" + sec + "\", Description \"" + desc + "\":", - print "Subsection \"" + s_item["name"] + "\" not found" + print('Section "' + sec + '", ' + 'Description "' + desc + '": ' + 'Subsection "' + s_item["name"] + '" not found') bump_taint() =20 =20 def check_description_in_list(s_item, d_item, sec, desc): - if not "Description" in s_item: + if "Description" not in s_item: return =20 - if not "Description" in d_item: - print "Section \"" + sec + "\", Description \"" + desc + "\",", - print "Field \"" + s_item["field"] + "\": missing description" + if "Description" not in d_item: + print('Section "' + sec + '", ' + 'Description "' + desc + '", ' + 'Field "' + s_item["field"] + '": missing description') bump_taint() return =20 @@ -311,17 +319,17 @@ def check_descriptions(src_desc, dest_desc, sec): check_version(src_desc, dest_desc, sec, src_desc["name"]) =20 if not check_fields_match(sec, src_desc["name"], dest_desc["name"]): - print "Section \"" + sec + "\":", - print "Description \"" + src_desc["name"] + "\"", - print "missing, got \"" + dest_desc["name"] + "\" instead; skippin= g" + print('Section "' + sec + '": ' + 'Description "' + src_desc["name"] + '" ' + 'missing, got "' + dest_desc["name"] + '" instead; skipping') bump_taint() return =20 for f in src_desc: if not f in dest_desc: - print "Section \"" + sec + "\"", - print "Description \"" + src_desc["name"] + "\":", - print "Entry \"" + f + "\" missing" + print('Section "' + sec + '" ' + 'Description "' + src_desc["name"] + '": ' + 'Entry "' + field + '" missing') bump_taint() continue =20 @@ -340,15 +348,15 @@ def check_version(s, d, sec, desc=3DNone): print "version error:", s["version_id"], ">", d["version_id"] bump_taint() =20 - if not "minimum_version_id" in d: + if "minimum_version_id" not in dest_ver: return =20 if s["version_id"] < d["minimum_version_id"]: print "Section \"" + sec + "\"", if desc: - print "Description \"" + desc + "\":", - print "minimum version error:", s["version_id"], "<", - print d["minimum_version_id"] + print('Description "' + desc + '": ' + + 'minimum version error: ' + str(src_ver["version_id"]) += ' < ' + + str(dest_ver["minimum_version_id"])) bump_taint() =20 =20 @@ -363,15 +371,21 @@ def check_size(s, d, sec, desc=3DNone, field=3DNone): bump_taint() =20 =20 -def check_machine_type(s, d): - if s["Name"] !=3D d["Name"]: - print "Warning: checking incompatible machine types:", - print "\"" + s["Name"] + "\", \"" + d["Name"] + "\"" + +def check_machine_type(src, dest): + if src["Name"] !=3D dest["Name"]: + print('Warning: checking incompatible machine types: ' + '"' + src["Name"] + '", "' + dest["Name"] + '"') return =20 =20 def main(): - help_text =3D "Parse JSON-formatted vmstate dumps from QEMU in files S= RC and DEST. Checks whether migration from SRC to DEST QEMU versions would= break based on the VMSTATE information contained within the JSON outputs. = The JSON output is created from a QEMU invocation with the -dump-vmstate p= arameter and a filename argument to it. Other parameters to QEMU do not ma= tter, except the -M (machine type) parameter." + help_text =3D ("Parse JSON-formatted vmstate dumps from QEMU in files " + "SRC and DEST. Checks whether migration from SRC to DEST QEMU version= s " + "would break based on the VMSTATE information contained within the JSO= N " + "outputs. The JSON output is created from a QEMU invocation with the " + "-dump-vmstate parameter and a filename argument to it. Other paramete= rs to " + "QEMU do not matter, except the -M (machine type) parameter.") =20 parser =3D argparse.ArgumentParser(description=3Dhelp_text) parser.add_argument('-s', '--src', type=3Dfile, required=3DTrue, @@ -395,12 +409,12 @@ def main(): =20 for sec in src_data: dest_sec =3D sec - if not dest_sec in dest_data: + if dest_sec not in dest_data: # Either the section name got changed, or the section # doesn't exist in dest. dest_sec =3D get_changed_sec_name(sec) - if not dest_sec in dest_data: - print "Section \"" + sec + "\" does not exist in dest" + if dest_sec not in dest_data: + print('Section "' + sec + '" does not exist in dest') bump_taint() continue =20 @@ -414,9 +428,8 @@ def main(): check_version(s, d, sec) =20 for entry in s: - if not entry in d: - print "Section \"" + sec + "\": Entry \"" + entry + "\"", - print "missing" + if entry not in d: + print('Section "' + sec + '": Entry "' + entry + '" missin= g') bump_taint() continue =20 --=20 1.8.3.1