qemu-iotests: move command line and environment handling from TestRunner to TestEnv

In the next patch, "check" will learn how to execute a test script without
going through TestRunner.  To enable this, keep only the text output
and subprocess handling in the TestRunner; move into TestEnv the logic
to prepare for running a subprocess.

Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Tested-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Message-Id: <20210323181928.311862-4-pbonzini@redhat.com>
Message-Id: <20210503110110.476887-4-pbonzini@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
This commit is contained in:
Paolo Bonzini 2021-05-03 13:01:08 +02:00 committed by Max Reitz
parent 00dbc85e0e
commit c64430d238
2 changed files with 17 additions and 14 deletions

View file

@ -25,7 +25,7 @@ import collections
import random import random
import subprocess import subprocess
import glob import glob
from typing import Dict, Any, Optional, ContextManager from typing import List, Dict, Any, Optional, ContextManager
def isxfile(path: str) -> bool: def isxfile(path: str) -> bool:
@ -74,6 +74,21 @@ class TestEnv(ContextManager['TestEnv']):
'CACHEMODE_IS_DEFAULT', 'IMGFMT_GENERIC', 'IMGOPTSSYNTAX', 'CACHEMODE_IS_DEFAULT', 'IMGFMT_GENERIC', 'IMGOPTSSYNTAX',
'IMGKEYSECRET', 'QEMU_DEFAULT_MACHINE', 'MALLOC_PERTURB_'] 'IMGKEYSECRET', 'QEMU_DEFAULT_MACHINE', 'MALLOC_PERTURB_']
def prepare_subprocess(self, args: List[str]) -> Dict[str, str]:
if self.debug:
args.append('-d')
with open(args[0], encoding="utf-8") as f:
try:
if f.readline().rstrip() == '#!/usr/bin/env python3':
args.insert(0, self.python)
except UnicodeDecodeError: # binary test? for future.
pass
os_env = os.environ.copy()
os_env.update(self.get_env())
return os_env
def get_env(self) -> Dict[str, str]: def get_env(self) -> Dict[str, str]:
env = {} env = {}
for v in self.env_variables: for v in self.env_variables:

View file

@ -129,7 +129,6 @@ class TestRunner(ContextManager['TestRunner']):
def __init__(self, env: TestEnv, makecheck: bool = False, def __init__(self, env: TestEnv, makecheck: bool = False,
color: str = 'auto') -> None: color: str = 'auto') -> None:
self.env = env self.env = env
self.test_run_env = self.env.get_env()
self.makecheck = makecheck self.makecheck = makecheck
self.last_elapsed = LastElapsedTime('.last-elapsed-cache', env) self.last_elapsed = LastElapsedTime('.last-elapsed-cache', env)
@ -243,18 +242,7 @@ class TestRunner(ContextManager['TestRunner']):
silent_unlink(p) silent_unlink(p)
args = [str(f_test.resolve())] args = [str(f_test.resolve())]
if self.env.debug: env = self.env.prepare_subprocess(args)
args.append('-d')
with f_test.open(encoding="utf-8") as f:
try:
if f.readline().rstrip() == '#!/usr/bin/env python3':
args.insert(0, self.env.python)
except UnicodeDecodeError: # binary test? for future.
pass
env = os.environ.copy()
env.update(self.test_run_env)
t0 = time.time() t0 = time.time()
with f_bad.open('w', encoding="utf-8") as f: with f_bad.open('w', encoding="utf-8") as f: