Skip to content

Commit ce06a36

Browse files
committed
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.
1 parent 715f663 commit ce06a36

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

Lib/test/libregrtest/run_workers.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -338,12 +338,11 @@ def _runtest(self, test_name: TestName) -> MultiprocessResult:
338338

339339
if retcode is None:
340340
raise WorkerError(self.test_name, None, stdout, state=State.TIMEOUT)
341+
if retcode != 0:
342+
raise WorkerError(self.test_name, f"Exit code {retcode}", stdout)
341343

342344
result, stdout = self.read_json(json_file, json_tmpfile, stdout)
343345

344-
if retcode != 0:
345-
raise WorkerError(self.test_name, f"Exit code {retcode}", stdout)
346-
347346
if tmp_files:
348347
msg = (f'\n\n'
349348
f'Warning -- {test_name} leaked temporary files '

Lib/test/libregrtest/utils.py

+19-8
Original file line numberDiff line numberDiff line change
@@ -360,14 +360,25 @@ def get_temp_dir(tmp_dir: StrPath | None = None) -> StrPath:
360360
# to keep the test files in a subfolder. This eases the cleanup of leftover
361361
# files using the "make distclean" command.
362362
if sysconfig.is_python_build():
363-
tmp_dir = sysconfig.get_config_var('abs_builddir')
364-
if tmp_dir is None:
365-
# bpo-30284: On Windows, only srcdir is available. Using
366-
# abs_builddir mostly matters on UNIX when building Python
367-
# out of the source tree, especially when the source tree
368-
# is read only.
369-
tmp_dir = sysconfig.get_config_var('srcdir')
370-
tmp_dir = os.path.join(tmp_dir, 'build')
363+
if not support.is_wasi:
364+
tmp_dir = sysconfig.get_config_var('abs_builddir')
365+
if tmp_dir is None:
366+
# bpo-30284: On Windows, only srcdir is available. Using
367+
# abs_builddir mostly matters on UNIX when building Python
368+
# out of the source tree, especially when the source tree
369+
# is read only.
370+
tmp_dir = sysconfig.get_config_var('srcdir')
371+
tmp_dir = os.path.join(tmp_dir, 'build')
372+
else:
373+
# WASI platform
374+
tmp_dir = sysconfig.get_config_var('projectbase')
375+
tmp_dir = os.path.join(tmp_dir, 'build')
376+
377+
# When get_temp_dir() is called in a worker process,
378+
# get_temp_dir() path is different than in the parent process
379+
# which is not a WASI process. So the parent does not create
380+
# the same "tmp_dir" than the test worker process.
381+
os.makedirs(self.tmp_dir, exist_ok=True)
371382
else:
372383
tmp_dir = tempfile.gettempdir()
373384

0 commit comments

Comments
 (0)