Skip to content

Commit

Permalink
checker: ignore fields marked unused
Browse files Browse the repository at this point in the history
While comparing qemu-1.0 json output with qemu-2.1, a few fields got
marked unused.  These need to be skipped over, and not flagged as
mismatches.

For handling unused fields, the exact number of bytes need to be skipped
over as the size of the unused field.

Currently, only the term "unused" is matched.  When more field names
turn up, this will have to be updated based on the whitelist matching
method to match more such terms.

Signed-off-by: Amit Shah <[email protected]>
  • Loading branch information
amit3s committed Aug 4, 2014
1 parent bb9c363 commit 32ce1b4
Showing 1 changed file with 50 additions and 4 deletions.
54 changes: 50 additions & 4 deletions scripts/vmstate-static-checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def check_fields(src_fields, dest_fields, desc, sec):

advance_src = True
advance_dest = True
unused_count = 0

while True:
if advance_src:
Expand All @@ -156,9 +157,10 @@ def check_fields(src_fields, dest_fields, desc, sec):
s_iter = s_iter_list.pop()
continue
else:
# We want to avoid advancing just once -- when entering a
# dest substruct, or when exiting one.
advance_src = True
if unused_count == 0:
# We want to avoid advancing just once -- when entering a
# dest substruct, or when exiting one.
advance_src = True

if advance_dest:
try:
Expand All @@ -177,7 +179,37 @@ def check_fields(src_fields, dest_fields, desc, sec):
advance_src = False
continue
else:
advance_dest = True
if unused_count == 0:
advance_dest = True

if unused_count > 0:
if advance_dest == False:
unused_count = unused_count - s_item["size"]
if unused_count == 0:
advance_dest = True
continue
if unused_count < 0:
print "Section \"" + sec + "\",",
print "Description \"" + desc + "\":",
print "unused size mismatch near \"",
print s_item["field"] + "\""
bump_taint()
break
continue

if advance_src == False:
unused_count = unused_count - d_item["size"]
if unused_count == 0:
advance_src = True
continue
if unused_count < 0:
print "Section \"" + sec + "\",",
print "Description \"" + desc + "\":",
print "unused size mismatch near \"",
print d_item["field"] + "\""
bump_taint()
break
continue

if not check_fields_match(desc, s_item["field"], d_item["field"]):
# Some fields were put in substructs, keeping the
Expand Down Expand Up @@ -208,6 +240,20 @@ def check_fields(src_fields, dest_fields, desc, sec):
advance_dest = False
continue

if s_item["field"] == "unused" or d_item["field"] == "unused":
if s_item["size"] == d_item["size"]:
continue

if d_item["field"] == "unused":
advance_dest = False
unused_count = d_item["size"] - s_item["size"]
continue

if s_item["field"] == "unused":
advance_src = False
unused_count = s_item["size"] - d_item["size"]
continue

print "Section \"" + sec + "\",",
print "Description \"" + desc + "\":",
print "expected field \"" + s_item["field"] + "\",",
Expand Down

0 comments on commit 32ce1b4

Please sign in to comment.