From a02ff8d75019ffe1082d694b7516156ec7ddcf30 Mon Sep 17 00:00:00 2001 From: Andrew Cooper Date: Fri, 5 Jan 2024 21:48:39 +0000 Subject: [PATCH] runner: More extensive Python 3 universal_newline fixes When pv32pae is disabled e.g. due to CET being active, under Python 3, we still get: Executing 'xl create -p tests/example/test-pv32pae-example.cfg' b'Parsing config from tests/example/test-pv32pae-example.cfg\nlibxl: error: ...\n' Error: Failed to create VM out, rather than `xl create`'s stdout/stderr rendered nicely. All subprocess invocations we make will want universal_newlines, so wrap the functions to have it active by default, but still allow it to be explicitly turned off by passing universal_newlines = None. Reinstate the use of check_output() now that we've upped the minimum python version to 2.7. Signed-off-by: Andrew Cooper --- xtf-runner | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/xtf-runner b/xtf-runner index 87ae321..b6f26fd 100755 --- a/xtf-runner +++ b/xtf-runner @@ -11,15 +11,24 @@ from __future__ import print_function, unicode_literals import json import sys, os, os.path as path +import subprocess +from functools import partial from optparse import OptionParser -from subprocess import Popen, PIPE, call as subproc_call +from subprocess import PIPE # Python 2/3 compatibility if sys.version_info >= (3, ): basestring = str + +# Wrap Subprocess functions to use universal_newlines by default +Popen = partial(subprocess.Popen, universal_newlines = True) +subproc_call = partial(subprocess.call, universal_newlines = True) +check_output = partial(subprocess.check_output, universal_newlines = True) + + # All results of a test, keep in sync with C code report.h. # Notes: # - WARNING is not a result on its own. @@ -400,10 +409,7 @@ def interpret_selection(opts): host_envs = [] - cmd = Popen(['xl', 'info'], stdout = PIPE, universal_newlines = True) - stdout, _ = cmd.communicate() - - for line in stdout.splitlines(): + for line in check_output(['xl', 'info']).splitlines(): if not line.startswith("xen_caps"): continue @@ -493,7 +499,7 @@ def run_test_console(opts, test): if console.returncode: raise RunnerError("Failed to obtain VM console") - lines = stdout.decode("utf-8").splitlines() + lines = stdout.splitlines() if lines: if not opts.quiet: -- 2.39.5