Skip to content

Commit 1d93f3c

Browse files
committed
parallelize hpy tests
1 parent 5054609 commit 1d93f3c

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

graalpython/lib-graalpython/modules/hpy/test/conftest.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,16 @@
2020
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2121
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
# SOFTWARE.
23+
import os
2324
import sys
2425
import pytest
2526
from .support import ExtensionCompiler, DefaultExtensionTemplate,\
2627
PythonSubprocessRunner, HPyDebugCapture
2728
from hpy.debug.leakdetector import LeakDetector
2829

30+
SELECTED_ABI_MODE = os.environ.get("TEST_HPY_ABI", None)
31+
if SELECTED_ABI_MODE:
32+
SELECTED_ABI_MODE = [SELECTED_ABI_MODE]
2933
IS_VALGRIND_RUN = False
3034
GRAALPYTHON_NATIVE = sys.implementation.name == 'graalpython' and __graalpython__.platform_id == 'native'
3135
def pytest_addoption(parser):
@@ -64,7 +68,7 @@ def hpy_devel(request):
6468
from hpy.devel import HPyDevel
6569
return HPyDevel()
6670

67-
@pytest.fixture(params=['cpython', 'universal', 'debug', 'nfi'] if GRAALPYTHON_NATIVE else ['cpython', 'universal', 'debug'])
71+
@pytest.fixture(params=SELECTED_ABI_MODE or (['cpython', 'universal', 'debug', 'nfi'] if GRAALPYTHON_NATIVE else ['cpython', 'universal', 'debug']))
6872
def hpy_abi(request):
6973
abi = request.param
7074
if abi == 'debug':

mx.graalpython/mx_graalpython.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,9 @@ def is_included(path):
674674
return testfiles
675675

676676

677-
def run_python_unittests(python_binary, args=None, paths=None, aot_compatible=False, exclude=None, env=None, use_pytest=False, cwd=None):
677+
def run_python_unittests(python_binary, args=None, paths=None, aot_compatible=False, exclude=None, env=None, use_pytest=False, cwd=None, lock=None):
678+
if lock:
679+
lock.acquire()
678680
# ensure that the test distribution is up-to-date
679681
mx.command_function("build")(["--dep", "com.oracle.graal.python.test"])
680682

@@ -737,6 +739,8 @@ def graalvm_vm_arg(java_arg):
737739
else:
738740
args += testfiles
739741
mx.logv(" ".join([python_binary] + args))
742+
if lock:
743+
lock.release()
740744
return mx.run([python_binary] + args, nonZeroIsFatal=True, env=env, cwd=cwd)
741745

742746

@@ -766,8 +770,31 @@ def run_hpy_unittests(python_binary, args=None):
766770
mx.log("LLVM Toolchain (vanilla): {!s}".format(env["LLVM_TOOLCHAIN_VANILLA"]))
767771
mx.log("Ensure 'setuptools' is installed")
768772
mx.run([python_binary] + args + ["-m", "ginstall", "install", "--user", "pytest"], nonZeroIsFatal=True, env=env)
769-
770-
return run_python_unittests(python_binary, args=args, paths=[_hpy_test_root()], env=env, use_pytest=True)
773+
# parallelize
774+
import threading
775+
threads = []
776+
lock = threading.RLock()
777+
778+
class RaisingThread(threading.Thread):
779+
def run(self):
780+
self.exc = None
781+
try:
782+
super().run()
783+
except Exception as e:
784+
self.exc = e
785+
786+
for abi in ['cpython', 'universal', 'debug', 'nfi']:
787+
env["TEST_HPY_ABI"] = abi
788+
threads.append(RaisingThread(target=run_python_unittests, args=(python_binary, ), kwargs={
789+
"args": args, "paths": [_hpy_test_root()], "env": env.copy(), "use_pytest": True, "lock": lock,
790+
}))
791+
threads[-1].start()
792+
retval = 0
793+
for t in threads:
794+
t.join()
795+
for t in threads:
796+
if t.exc:
797+
raise t.exc
771798

772799

773800
def run_tagged_unittests(python_binary, env=None, cwd=None):

0 commit comments

Comments
 (0)