From ce06a36f0099ec79591773f3c99226b491f01515 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 13 Sep 2023 02:52:54 +0200 Subject: [PATCH 1/2] gh-109276: libregrtest: fix work dir on WASI On WASI platform, get_temp_dir() should behave differently since the parent process is a WASI process and uses a different get_temp_dir() path. Fix also WorkerThread._runtest(): don't read JSON file if the worker process exit code is non-zero. --- Lib/test/libregrtest/run_workers.py | 5 ++--- Lib/test/libregrtest/utils.py | 27 +++++++++++++++++++-------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/Lib/test/libregrtest/run_workers.py b/Lib/test/libregrtest/run_workers.py index f99ca343eefb06..45b2f424ce4e5d 100644 --- a/Lib/test/libregrtest/run_workers.py +++ b/Lib/test/libregrtest/run_workers.py @@ -338,12 +338,11 @@ def _runtest(self, test_name: TestName) -> MultiprocessResult: if retcode is None: raise WorkerError(self.test_name, None, stdout, state=State.TIMEOUT) + if retcode != 0: + raise WorkerError(self.test_name, f"Exit code {retcode}", stdout) result, stdout = self.read_json(json_file, json_tmpfile, stdout) - if retcode != 0: - raise WorkerError(self.test_name, f"Exit code {retcode}", stdout) - if tmp_files: msg = (f'\n\n' f'Warning -- {test_name} leaked temporary files ' diff --git a/Lib/test/libregrtest/utils.py b/Lib/test/libregrtest/utils.py index ce7342aabfffbe..3e30d92b869062 100644 --- a/Lib/test/libregrtest/utils.py +++ b/Lib/test/libregrtest/utils.py @@ -360,14 +360,25 @@ def get_temp_dir(tmp_dir: StrPath | None = None) -> StrPath: # to keep the test files in a subfolder. This eases the cleanup of leftover # files using the "make distclean" command. if sysconfig.is_python_build(): - tmp_dir = sysconfig.get_config_var('abs_builddir') - if tmp_dir is None: - # bpo-30284: On Windows, only srcdir is available. Using - # abs_builddir mostly matters on UNIX when building Python - # out of the source tree, especially when the source tree - # is read only. - tmp_dir = sysconfig.get_config_var('srcdir') - tmp_dir = os.path.join(tmp_dir, 'build') + if not support.is_wasi: + tmp_dir = sysconfig.get_config_var('abs_builddir') + if tmp_dir is None: + # bpo-30284: On Windows, only srcdir is available. Using + # abs_builddir mostly matters on UNIX when building Python + # out of the source tree, especially when the source tree + # is read only. + tmp_dir = sysconfig.get_config_var('srcdir') + tmp_dir = os.path.join(tmp_dir, 'build') + else: + # WASI platform + tmp_dir = sysconfig.get_config_var('projectbase') + tmp_dir = os.path.join(tmp_dir, 'build') + + # When get_temp_dir() is called in a worker process, + # get_temp_dir() path is different than in the parent process + # which is not a WASI process. So the parent does not create + # the same "tmp_dir" than the test worker process. + os.makedirs(self.tmp_dir, exist_ok=True) else: tmp_dir = tempfile.gettempdir() From 7e0204898551969c95941516ac5636eec6ff7f65 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 13 Sep 2023 03:13:16 +0200 Subject: [PATCH 2/2] Fix typo --- Lib/test/libregrtest/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/libregrtest/utils.py b/Lib/test/libregrtest/utils.py index 3e30d92b869062..880cec5cc50f4a 100644 --- a/Lib/test/libregrtest/utils.py +++ b/Lib/test/libregrtest/utils.py @@ -378,7 +378,7 @@ def get_temp_dir(tmp_dir: StrPath | None = None) -> StrPath: # get_temp_dir() path is different than in the parent process # which is not a WASI process. So the parent does not create # the same "tmp_dir" than the test worker process. - os.makedirs(self.tmp_dir, exist_ok=True) + os.makedirs(tmp_dir, exist_ok=True) else: tmp_dir = tempfile.gettempdir()