Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion test/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,13 @@ def set_temp_dir(self, temp_dir):
# Explicitly set dedicated temporary directory for parallel tests
os.environ['EMCC_TEMP_DIR'] = self.temp_dir

def reset_temp_dir(self):
# Deleting these instance fields will mean that the class field is used
# instead.
del self.temp_dir
del self.canonical_temp_dir
del os.environ['EMCC_TEMP_DIR']

def parse_wasm(self, filename):
wat = self.get_wasm_text(filename)
imports = []
Expand Down Expand Up @@ -797,7 +804,8 @@ def setUp(self):
self.temp_files_before_run.append(os.path.normpath(os.path.join(root, filename)))

if self.runningInParallel():
self.working_dir = tempfile.mkdtemp(prefix='emscripten_test_' + self.__class__.__name__ + '_', dir=self.temp_dir)
# When running tests in parallel each test runs it its own new temp directory
self.working_dir = tempfile.mkdtemp(prefix='emtest_' + self.__class__.__name__ + '_', dir=self.temp_dir)
else:
self.working_dir = path_from_root('out/test')
if os.path.exists(self.working_dir):
Expand Down
7 changes: 0 additions & 7 deletions test/parallel_testsuite.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ def test_failed():
with lock:
allowed_failures_counter.value -= 1

olddir = os.getcwd()
result = BufferedParallelTestResult(lock, progress_counter, num_tests)
temp_dir = tempfile.mkdtemp(prefix='emtest_')
test.set_temp_dir(temp_dir)
try:
if test.__class__ not in seen_class:
seen_class.add(test.__class__)
Expand All @@ -71,10 +68,6 @@ def test_failed():
except Exception as e:
result.addError(test, e)
test_failed()
# Before attempting to delete the tmp dir make sure the current
# working directory is not within it.
os.chdir(olddir)
common.force_delete_dir(temp_dir)
return result


Expand Down
10 changes: 10 additions & 0 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import subprocess
import sys
import tarfile
import tempfile
import time
from datetime import datetime
from functools import wraps
Expand Down Expand Up @@ -142,6 +143,13 @@ def uses_canonical_tmp(func):
"""
@wraps(func)
def decorated(self, *args, **kwargs):
if self.runningInParallel():
# Becuase the canical temp directory is global/central location when
# tests use it in parallel they need to temporarily override the
# temp directory to ovoid clobbering each each.
new_temp = tempfile.mkdtemp(prefix='emtest_tmpdir_', dir=self.temp_dir)
self.set_temp_dir(new_temp)

# Before running the test completely remove the canonical_tmp
if os.path.exists(self.canonical_temp_dir):
shutil.rmtree(self.canonical_temp_dir)
Expand All @@ -155,6 +163,8 @@ def decorated(self, *args, **kwargs):
# test fails we would not clean it up, and if leak detection
# is set we will show that error instead of the actual one.
shutil.rmtree(self.canonical_temp_dir)
if self.runningInParallel():
self.reset_temp_dir()

return decorated

Expand Down