device-crash-test: Convert to Python 3
PATCH 1/1 device-crash-test: Convert to Python 3
Apply 2to3 tool to scripts/device-crash-test.
Restrict whitelist entry stats in debug mode to be sorted only by "count", since Python 3 does not implicitly support comparing dictionaries.
--- scripts/device-crash-test | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
scripts/device-crash-test +4 -3
@@ -23,7 +23,7 @@ Run QEMU with all combinations of -machine and -device types, check for crashes and unexpected errors. """ -from __future__ import print_function + import sys import os
@@ -272,7 +272,7 @@ def qemuOptsEscape(s): def formatTestCase(t): """Format test case info as "key=value key=value" for prettier logging output""" - return ' '.join('%s=%s' % (k, v) for k, v in t.items()) + return ' '.join('%s=%s' % (k, v) for k, v in list(t.items())) def qomListTypeNames(vm, **kwargs):
@@ -574,7 +574,8 @@ def main(): logger.info("Skipped %d test cases", skipped) if args.debug: - stats = sorted([(len(wl_stats.get(i, [])), wl) for i, wl in enumerate(ERROR_WHITELIST)]) + stats = sorted([(len(wl_stats.get(i, [])), wl) for i, wl in + enumerate(ERROR_WHITELIST)], key=lambda x: x[0]) for count, wl in stats: dbg("whitelist entry stats: %d: %r", count, wl)
Signature · 1 line
2.19.2
Quoted 3 lines · Nisarg Shah
Apply 2to3 tool to
scripts/device-crash-test.
Restrict whitelist entry stats in debug mode to be sorted only by "count", since Python 3 does not implicitly support comparing dictionaries.
Thanks for the patch. Comments below:
Quoted 11 lines
Signed-off-by Nisarg Shah <[email protected]>--- scripts/device-crash-test | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)scripts/device-crash-test +0
-0
scripts/device-crash-test line 26
Quoted 5 lines
scripts/device-crash-test +1
-1@@ -23,7 +23,7 @@ Run QEMU with all combinations of -machine and -device types, check for crashes and unexpected errors. """ -from __future__ import print_function +
This breaks Python 2 support:
$ python2 scripts/device-crash-test
File "scripts/device-crash-test", line 534
print("No QEMU binary found", file=sys.stderr)
^
SyntaxError: invalid syntaxscripts/device-crash-test def qemuOptsEscape(s): · line 275
Quoted 9 lines
scripts/device-crash-test +1
-1import sys import os@@ -272,7 +272,7 @@ def qemuOptsEscape(s): def formatTestCase(t): """Format test case info as "key=value key=value" for prettier logging output""" - return ' '.join('%s=%s' % (k, v) for k, v in t.items()) + return ' '.join('%s=%s' % (k, v) for k, v in list(t.items()))
Why is this necessary?
scripts/device-crash-test def main(): · line 578
Quoted 10 lines
scripts/device-crash-test +2
-1def qomListTypeNames(vm, **kwargs):@@ -574,7 +574,8 @@ def main(): logger.info("Skipped %d test cases", skipped) if args.debug: - stats = sorted([(len(wl_stats.get(i, [])), wl) for i, wl in enumerate(ERROR_WHITELIST)]) + stats = sorted([(len(wl_stats.get(i, [])), wl) for i, wl in + enumerate(ERROR_WHITELIST)], key=lambda x: x[0])
This seems to be the only change that is described in the commit message. I'm applying this hunk after editing the commit message as shown below.
---
Quoted 1 line
From
9793d7e7874d944d115ab9ab933b02f8de793460Mon Sep 17 00:00:00 2001
From: Nisarg Shah <[email protected]>
Date: Thu, 17 Jan 2019 00:03:58 +0530
Subject: [PATCH] device-crash-test: Python 3 compatibility fix
Restrict whitelist entry stats in debug mode to be sorted only by "count", since Python 3 does not implicitly support comparing dictionaries.
Message-Id: <[email protected]>
--- scripts/device-crash-test | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
scripts/device-crash-test +2 -1
@@ -557,7 +557,8 @@ def main(): logger.info("Skipped %d test cases", skipped) if args.debug: - stats = sorted([(len(wl_stats.get(i, [])), wl) for i, wl in enumerate(ERROR_WHITELIST)]) + stats = sorted([(len(wl_stats.get(i, [])), wl) for i, wl in + enumerate(ERROR_WHITELIST)], key=lambda x: x[0]) for count, wl in stats: dbg("whitelist entry stats: %d: %r", count, wl)
Signature · 4 lines
2.18.0.rc1.1.g3f1ff2140 -- Eduardo
Thanks for the review.
Quoted 10 lines · Eduardo Habkost
This breaks Python 2 support:
$ python2 scripts/device-crash-test File "scripts/device-crash-test", line 534 print("No QEMU binary found", file=sys.stderr) ^ SyntaxError: invalid syntax
Apologies. This is my first patch to qemu and I did not consider backward compatibility with Python 2. I'll see if I can fix this.
Quoted 5 lines
Quoted 5 lines
import sys
import os(quoted diff) +0
-0@@ -272,7 +272,7 @@ def qemuOptsEscape(s):
Quoted 8 lines
Review def qemuOptsEscape(s): · line 275
Quoted 4 lines
(quoted diff) +1
-1def formatTestCase(t): """Format test case info as "key=value key=value" for prettier logging output""" - return ' '.join('%s=%s' % (k, v) for k, v in t.items()) + return ' '.join('%s=%s' % (k, v) for k, v in list(t.items()))Why is this necessary?
This was automatically modified by the 2to3 tool. I see that it is not really required.
Regards,
Nisarg