[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 07/19] qemu-iotests: move command line and environment handling fr
From: |
Max Reitz |
Subject: |
[PULL 07/19] qemu-iotests: move command line and environment handling from TestRunner to TestEnv |
Date: |
Fri, 14 May 2021 18:45:02 +0200 |
From: Paolo Bonzini <pbonzini@redhat.com>
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>
---
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 6d27712617..fca3a609e0 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.31.1
- [PULL 00/19] Block patches, Max Reitz, 2021/05/14
- [PULL 01/19] iotests/231: Update expected deprecation message, Max Reitz, 2021/05/14
- [PULL 04/19] mirror: stop cancelling in-flight requests on non-force cancel in READY, Max Reitz, 2021/05/14
- [PULL 02/19] block/rbd: Add an escape-aware strchr helper, Max Reitz, 2021/05/14
- [PULL 06/19] qemu-iotests: allow passing unittest.main arguments to the test scripts, Max Reitz, 2021/05/14
- [PULL 05/19] qemu-iotests: do not buffer the test output, Max Reitz, 2021/05/14
- [PULL 09/19] qemu-iotests: fix case of SOCK_DIR already in the environment, Max Reitz, 2021/05/14
- [PULL 07/19] qemu-iotests: move command line and environment handling from TestRunner to TestEnv,
Max Reitz <=
- [PULL 03/19] monitor: hmp_qemu_io: acquire aio contex, fix crash, Max Reitz, 2021/05/14
- [PULL 08/19] qemu-iotests: let "check" spawn an arbitrary test command, Max Reitz, 2021/05/14
- [PULL 12/19] qemu-iotests: fix pylint 2.8 consider-using-with error, Max Reitz, 2021/05/14
- [PULL 11/19] block/copy-on-read: use bdrv_drop_filter() and drop s->active, Max Reitz, 2021/05/14
- [PULL 10/19] Document qemu-img options data_file and data_file_raw, Max Reitz, 2021/05/14
- [PULL 14/19] block: drop write notifiers, Max Reitz, 2021/05/14
- [PULL 13/19] block/write-threshold: don't use write notifiers, Max Reitz, 2021/05/14
- [PULL 15/19] test-write-threshold: rewrite test_threshold_(not_)trigger tests, Max Reitz, 2021/05/14