Skip to content

Commit 3974e5e

Browse files
committed
Move downstream tests into a separate file
1 parent 3bea818 commit 3974e5e

File tree

2 files changed

+159
-92
lines changed

2 files changed

+159
-92
lines changed

mx.graalpython/downstream_tests.py

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
# Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
2+
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3+
#
4+
# The Universal Permissive License (UPL), Version 1.0
5+
#
6+
# Subject to the condition set forth below, permission is hereby granted to any
7+
# person obtaining a copy of this software, associated documentation and/or
8+
# data (collectively the "Software"), free of charge and under any and all
9+
# copyright rights in the Software, and any and all patent rights owned or
10+
# freely licensable by each licensor hereunder covering either (i) the
11+
# unmodified Software as contributed to or provided by such licensor, or (ii)
12+
# the Larger Works (as defined below), to deal in both
13+
#
14+
# (a) the Software, and
15+
#
16+
# (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
17+
# one is included with the Software each a "Larger Work" to which the Software
18+
# is contributed by such licensors),
19+
#
20+
# without restriction, including without limitation the rights to copy, create
21+
# derivative works of, display, perform, and distribute the Software and make,
22+
# use, sell, offer for sale, import, export, have made, and have sold the
23+
# Software and the Larger Work(s), and to sublicense the foregoing rights on
24+
# either these or other terms.
25+
#
26+
# This license is subject to the following condition:
27+
#
28+
# The above copyright notice and either this complete permission notice or at a
29+
# minimum a reference to the UPL must be included in all copies or substantial
30+
# portions of the Software.
31+
#
32+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
33+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
34+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
35+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
36+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
37+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
38+
# SOFTWARE.
39+
40+
import argparse
41+
import os
42+
import shlex
43+
import shutil
44+
import subprocess
45+
from pathlib import Path
46+
47+
DIR = Path(__file__).parent.parent
48+
DOWNSTREAM_TESTS = {}
49+
50+
51+
def run(*args, check=True, **kwargs):
52+
return subprocess.run(*args, check=check, **kwargs)
53+
54+
55+
def run_in_venv(venv, cmd, **kwargs):
56+
return run(['sh', '-c', f". {venv}/bin/activate && {shlex.join(cmd)}"], **kwargs)
57+
58+
59+
def downstream_test(name):
60+
def decorator(fn):
61+
DOWNSTREAM_TESTS[name] = fn
62+
return fn
63+
64+
return decorator
65+
66+
67+
@downstream_test('hpy')
68+
def downstream_test_hpy(graalpy, args=None, env=None, check=True, timeout=None):
69+
testdir = Path('upstream-tests').absolute()
70+
shutil.rmtree(testdir, ignore_errors=True)
71+
testdir.mkdir(exist_ok=True)
72+
hpy_root = DIR / "graalpython" / "hpy"
73+
shutil.copytree(hpy_root, testdir / "hpy")
74+
hpy_root = testdir / "hpy"
75+
hpy_test_root = hpy_root / "test"
76+
venv = testdir / 'hpy_venv'
77+
run([graalpy, "-m", "venv", str(venv)])
78+
run_in_venv(venv, ["pip", "install", "pytest", "pytest-xdist", "pytest-rerunfailures", "filelock"])
79+
env = env or os.environ.copy()
80+
env["SETUPTOOLS_SCM_PRETEND_VERSION"] = "0.9.0"
81+
run_in_venv(venv, ["pip", "install", "-e", "."], cwd=str(hpy_root), env=env)
82+
parallelism = str(min(os.cpu_count(), int(os.cpu_count() / 4)))
83+
args = args or []
84+
args = [
85+
"python",
86+
"--vm.ea",
87+
"--experimental-options=true",
88+
"--python.EnableDebuggingBuiltins",
89+
*args,
90+
"-m", "pytest",
91+
"-v",
92+
# for those cases where testing invalid handles corrupts the process so
93+
# much that we crash - we don't recover gracefully in some cases :(
94+
"--reruns", "3",
95+
"-n", parallelism,
96+
str(hpy_test_root),
97+
# test_distutils is just slow and testing the build infrastructure
98+
"-k", "not test_distutils"
99+
]
100+
return run_in_venv(venv, args, env=env, cwd=str(hpy_root), check=check, timeout=timeout)
101+
102+
103+
@downstream_test('pybind11')
104+
def downstream_test_pybind11(graalpy):
105+
testdir = Path('upstream-tests').absolute()
106+
shutil.rmtree(testdir, ignore_errors=True)
107+
testdir.mkdir(exist_ok=True)
108+
run(['git', 'clone', 'https://github.com/pybind/pybind11.git'], cwd=testdir)
109+
src = testdir / 'pybind11'
110+
venv = src / 'venv'
111+
run([graalpy, '-m', 'venv', str(venv)])
112+
run_in_venv(venv, ['pip', 'install', 'pytest'])
113+
run_in_venv(venv, ['cmake', '-S', '.', '-B', 'build', '-DPYBIND11_WERROR=ON'], cwd=src)
114+
run_in_venv(venv, ['cmake', '--build', 'build', '--parallel'], cwd=src)
115+
env = os.environ.copy()
116+
env['PYTHONPATH'] = 'build/tests'
117+
run_in_venv(venv, ['pytest', '-v', '--tb=short', 'tests'], cwd=src, env=env)
118+
119+
120+
@downstream_test('virtualenv')
121+
def downstream_test_virtualenv(graalpy):
122+
testdir = Path('upstream-tests').absolute()
123+
shutil.rmtree(testdir, ignore_errors=True)
124+
testdir.mkdir(exist_ok=True)
125+
run(['git', 'clone', 'https://github.com/pypa/virtualenv.git', '-b', 'main'], cwd=testdir)
126+
src = testdir / 'virtualenv'
127+
venv = src / 'venv'
128+
run([graalpy, '-m', 'venv', str(venv)])
129+
env = os.environ.copy()
130+
env.pop('VIRTUAL_ENV_DISABLE_PROMPT', None)
131+
env['CI_RUN'] = '1'
132+
# Need to avoid pulling in graalpy seeder
133+
env['PIP_GRAALPY_DISABLE_PATCHING'] = '1'
134+
run_in_venv(venv, ['pip', 'install', f'{src}[test]'], env=env)
135+
# Don't activate the venv, it interferes with the test
136+
run([
137+
str(venv / 'bin' / 'pytest'), '-v', '--tb=short', 'tests',
138+
'-k', 'not fish and not csh and not nushell and not powershell',
139+
], cwd=src, env=env)
140+
141+
142+
def run_downstream_test(python, project):
143+
DOWNSTREAM_TESTS[project](python)
144+
145+
146+
def main():
147+
parser = argparse.ArgumentParser("Runs important upstream packages tests using their main branch")
148+
parser.add_argument("python")
149+
parser.add_argument("project", choices=sorted(DOWNSTREAM_TESTS))
150+
args = parser.parse_args()
151+
run_downstream_test(args.python, args.project)
152+
153+
154+
if __name__ == '__main__':
155+
main()

mx.graalpython/mx_graalpython.py

Lines changed: 4 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343

4444
from typing import cast
4545

46+
import downstream_tests
4647
import mx_graalpython_benchmark
4748
import mx_graalpython_gradleproject
4849
import mx_urlrewrites
@@ -1056,7 +1057,7 @@ def run_python_unittests(python_binary, args=None, paths=None, exclude=None, env
10561057

10571058
def run_hpy_unittests(python_binary, args=None, env=None, nonZeroIsFatal=True, timeout=None, report=False):
10581059
t0 = time.time()
1059-
result = downstream_test_hpy(python_binary, args=args, env=env, nonZeroIsFatal=nonZeroIsFatal, timeout=timeout)
1060+
result = downstream_tests.downstream_test_hpy(python_binary, args=args, env=env, check=nonZeroIsFatal, timeout=timeout)
10601061
if report:
10611062
mx_gate.make_test_report([{
10621063
"name": report.title,
@@ -2626,105 +2627,16 @@ def graalpy_jmh(args):
26262627
mx.run_java(vm_args + ['org.openjdk.jmh.Main'] + args)
26272628

26282629

2629-
def run_in_venv(venv, cmd, **kwargs):
2630-
return mx.run(['sh', '-c', f". {venv}/bin/activate && {shlex.join(cmd)}"], **kwargs)
2631-
2632-
2633-
DOWNSTREAM_TESTS = {}
2634-
2635-
def downstream_test(name):
2636-
def decorator(fn):
2637-
DOWNSTREAM_TESTS[name] = fn
2638-
return fn
2639-
return decorator
2640-
2641-
2642-
@downstream_test('hpy')
2643-
def downstream_test_hpy(graalpy, args=None, env=None, nonZeroIsFatal=True, timeout=None):
2644-
testdir = Path('upstream-tests').absolute()
2645-
shutil.rmtree(testdir, ignore_errors=True)
2646-
testdir.mkdir(exist_ok=True)
2647-
hpy_root = os.path.join(mx.dependency("hpy").dir)
2648-
shutil.copytree(hpy_root, testdir / "hpy")
2649-
hpy_root = testdir / "hpy"
2650-
hpy_test_root = hpy_root / "test"
2651-
venv = testdir / 'hpy_venv'
2652-
mx.run([graalpy, "-m", "venv", str(venv)])
2653-
run_in_venv(venv, ["pip", "install", "pytest", "pytest-xdist", "pytest-rerunfailures", "filelock"])
2654-
env = env or os.environ.copy()
2655-
env["SETUPTOOLS_SCM_PRETEND_VERSION"] = "0.9.0"
2656-
run_in_venv(venv, ["pip", "install", "-e", "."], cwd=str(hpy_root), env=env)
2657-
parallelism = str(min(os.cpu_count(), int(os.cpu_count() / 4)))
2658-
args = args or []
2659-
args = [
2660-
"python",
2661-
"--vm.ea",
2662-
"--experimental-options=true",
2663-
"--python.EnableDebuggingBuiltins",
2664-
*args,
2665-
"-m", "pytest",
2666-
"-v",
2667-
# for those cases where testing invalid handles corrupts the process so
2668-
# much that we crash - we don't recover gracefully in some cases :(
2669-
"--reruns", "3",
2670-
"-n", parallelism,
2671-
str(hpy_test_root),
2672-
# test_distutils is just slow and testing the build infrastructure
2673-
"-k", "not test_distutils"
2674-
]
2675-
mx.logv(shlex.join(args))
2676-
return run_in_venv(venv, args, env=env, cwd=str(hpy_root), nonZeroIsFatal=nonZeroIsFatal, timeout=timeout)
2677-
2678-
2679-
@downstream_test('pybind11')
2680-
def downstream_test_pybind11(graalpy):
2681-
testdir = Path('upstream-tests').absolute()
2682-
shutil.rmtree(testdir, ignore_errors=True)
2683-
testdir.mkdir(exist_ok=True)
2684-
mx.run(['git', 'clone', 'https://github.com/pybind/pybind11.git'], cwd=testdir)
2685-
src = testdir / 'pybind11'
2686-
venv = src / 'venv'
2687-
mx.run([graalpy, '-m', 'venv', str(venv)])
2688-
run_in_venv(venv, ['pip', 'install', 'pytest'])
2689-
run_in_venv(venv, ['cmake', '-S', '.', '-B', 'build', '-DPYBIND11_WERROR=ON'], cwd=src)
2690-
run_in_venv(venv, ['cmake', '--build', 'build', '--parallel'], cwd=src)
2691-
env = os.environ.copy()
2692-
env['PYTHONPATH'] = 'build/tests'
2693-
run_in_venv(venv, ['pytest', '-v', '--tb=short', 'tests'], cwd=src, env=env)
2694-
2695-
2696-
@downstream_test('virtualenv')
2697-
def downstream_test_virtualenv(graalpy):
2698-
testdir = Path('upstream-tests').absolute()
2699-
shutil.rmtree(testdir, ignore_errors=True)
2700-
testdir.mkdir(exist_ok=True)
2701-
mx.run(['git', 'clone', 'https://github.com/pypa/virtualenv.git', '-b', 'main'], cwd=testdir)
2702-
src = testdir / 'virtualenv'
2703-
venv = src / 'venv'
2704-
mx.run([graalpy, '-m', 'venv', str(venv)])
2705-
env = os.environ.copy()
2706-
env.pop('VIRTUAL_ENV_DISABLE_PROMPT', None)
2707-
env['CI_RUN'] = '1'
2708-
# Need to avoid pulling in graalpy seeder
2709-
env['PIP_GRAALPY_DISABLE_PATCHING'] = '1'
2710-
run_in_venv(venv, ['pip', 'install', f'{src}[test]'], env=env)
2711-
# Don't activate the venv, it interferes with the test
2712-
mx.run([
2713-
str(venv / 'bin' / 'pytest'), '-v', '--tb=short', 'tests',
2714-
'-k', 'not fish and not csh and not nushell and not powershell',
2715-
], cwd=src, env=env)
2716-
2717-
27182630
def run_downstream_test(args):
27192631
parser = ArgumentParser(description="Runs important upstream packages tests using their main branch")
2720-
parser.add_argument('project', choices=sorted(DOWNSTREAM_TESTS))
2632+
parser.add_argument('project')
27212633
parser.add_argument('--dev', action='store_true', help="Use JVM dev standalone")
27222634
args = parser.parse_args(args)
27232635
if args.dev:
27242636
graalpy = graalpy_standalone('jvm', dev=True)
27252637
else:
27262638
graalpy = graalpy_standalone_native()
2727-
DOWNSTREAM_TESTS[args.project](graalpy)
2639+
downstream_tests.run_downstream_test(graalpy, args.project)
27282640

27292641

27302642
# ----------------------------------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)