[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 3/5] qemu-iotests: move command line and environment handling
From: |
Paolo Bonzini |
Subject: |
[PATCH v2 3/5] qemu-iotests: move command line and environment handling from TestRunner to TestEnv |
Date: |
Tue, 23 Mar 2021 19:19:25 +0100 |
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>
---
tests/qemu-iotests/testenv.py | 17 ++++++++++++++++-
tests/qemu-iotests/testrunner.py | 14 +-------------
2 files changed, 17 insertions(+), 14 deletions(-)
diff --git a/tests/qemu-iotests/testenv.py b/tests/qemu-iotests/testenv.py
index 1fbec854c1..341a4af4e9 100644
--- a/tests/qemu-iotests/testenv.py
+++ b/tests/qemu-iotests/testenv.py
@@ -25,7 +25,7 @@
import random
import subprocess
import glob
-from typing import Dict, Any, Optional, ContextManager
+from typing import List, Dict, Any, Optional, ContextManager
def isxfile(path: str) -> bool:
@@ -74,6 +74,21 @@ class TestEnv(ContextManager['TestEnv']):
'CACHEMODE_IS_DEFAULT', 'IMGFMT_GENERIC', 'IMGOPTSSYNTAX',
'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]:
env = {}
for v in self.env_variables:
diff --git a/tests/qemu-iotests/testrunner.py b/tests/qemu-iotests/testrunner.py
index 1fc61fcaa3..519924dc81 100644
--- a/tests/qemu-iotests/testrunner.py
+++ b/tests/qemu-iotests/testrunner.py
@@ -129,7 +129,6 @@ class TestRunner(ContextManager['TestRunner']):
def __init__(self, env: TestEnv, makecheck: bool = False,
color: str = 'auto') -> None:
self.env = env
- self.test_run_env = self.env.get_env()
self.makecheck = makecheck
self.last_elapsed = LastElapsedTime('.last-elapsed-cache', env)
@@ -243,18 +242,7 @@ def do_run_test(self, test: str) -> TestResult:
silent_unlink(p)
args = [str(f_test.resolve())]
- if self.env.debug:
- 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)
+ env = self.env.prepare_subprocess(args)
t0 = time.time()
with f_bad.open('w', encoding="utf-8") as f:
--
2.30.1
- Re: [PATCH v2 2/5] qemu-iotests: allow passing unittest.main arguments to the test scripts, (continued)
[PATCH v2 4/5] qemu-iotests: let "check" spawn an arbitrary test command, Paolo Bonzini, 2021/03/23
[PATCH v2 5/5] qemu-iotests: fix case of SOCK_DIR already in the environment, Paolo Bonzini, 2021/03/23
[PATCH v2 1/5] qemu-iotests: do not buffer the test output, Paolo Bonzini, 2021/03/23
[PATCH v2 3/5] qemu-iotests: move command line and environment handling from TestRunner to TestEnv,
Paolo Bonzini <=
Re: [PATCH v2 0/5] qemu-iotests: quality of life improvements, Emanuele Giuseppe Esposito, 2021/03/24
Re: [PATCH v2 0/5] qemu-iotests: quality of life improvements, Max Reitz, 2021/03/25
Re: [PATCH v2 0/5] qemu-iotests: quality of life improvements, Max Reitz, 2021/03/26