diff --git a/ci/python-gate.libsonnet b/ci/python-gate.libsonnet index 179f0df580..465c54dd38 100644 --- a/ci/python-gate.libsonnet +++ b/ci/python-gate.libsonnet @@ -467,6 +467,7 @@ // logging ["mx"] + self.mx_parameters + self.dy + ["sversions"], ], + run+: [ ["sleep", "30m"] ], on_success+: [ ["rm", "-rf", "graal_dumps"], ], diff --git a/graalpython/com.oracle.graal.python.test/src/tests/__init__.py b/graalpython/com.oracle.graal.python.test/src/tests/__init__.py index eebb0d6d18..c6bb22484d 100644 --- a/graalpython/com.oracle.graal.python.test/src/tests/__init__.py +++ b/graalpython/com.oracle.graal.python.test/src/tests/__init__.py @@ -78,8 +78,8 @@ def get_setuptools(setuptools='setuptools==67.6.1'): else: py_executable = setuptools_path / 'bin' / 'python3' extra_args = [] - if sys.implementation.name == "graalpy" and not system_python and __graalpython__.is_bytecode_dsl_interpreter: - extra_args = ['--vm.Dpython.EnableBytecodeDSLInterpreter=true'] + if sys.implementation.name == "graalpy" and not system_python and not __graalpython__.is_native: + extra_args += [f'--vm.Dpython.EnableBytecodeDSLInterpreter={str(__graalpython__.is_bytecode_dsl_interpreter).lower()}'] subprocess.run([py_executable, *extra_args, "-m", "pip", "install", "--target", str(setuptools_path), setuptools], check=True) print('setuptools is installed in %s' % setuptools_path) diff --git a/graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_shutdown.py b/graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_shutdown.py index 111d06fb28..1c7a4fca16 100644 --- a/graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_shutdown.py +++ b/graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_shutdown.py @@ -1,4 +1,4 @@ -# Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # # The Universal Permissive License (UPL), Version 1.0 @@ -51,8 +51,8 @@ ARGS = [] if sys.implementation.name == 'graalpy': ARGS = ['--experimental-options', '--python.EnableDebuggingBuiltins'] - if not __graalpython__.is_native and __graalpython__.is_bytecode_dsl_interpreter: - ARGS += ['--vm.Dpython.EnableBytecodeDSLInterpreter=true'] + if not __graalpython__.is_native: + ARGS += [f'--vm.Dpython.EnableBytecodeDSLInterpreter={str(__graalpython__.is_bytecode_dsl_interpreter).lower()}'] COMMAND = [sys.executable, *ARGS, str(MODULE_PATH)] diff --git a/graalpython/com.oracle.graal.python.test/src/tests/test_frame_tests.py b/graalpython/com.oracle.graal.python.test/src/tests/test_frame_tests.py index 96f68b0030..88b51fff09 100644 --- a/graalpython/com.oracle.graal.python.test/src/tests/test_frame_tests.py +++ b/graalpython/com.oracle.graal.python.test/src/tests/test_frame_tests.py @@ -38,7 +38,7 @@ # SOFTWARE. import os import sys - +from tests import util # IMPORTANT: DO NOT MOVE! # This test checks that lineno works on frames, @@ -46,7 +46,7 @@ def test_lineno(): assert sys._getframe(0).f_lineno == 47 -if not os.environ.get('BYTECODE_DSL_INTERPRETER'): # Blocked by GR-61955 +if not util.IS_BYTECODE_DSL: # Blocked by GR-61955 # IMPORTANT: DO NOT MOVE! def test_nested_lineno(): def test_nested(): diff --git a/graalpython/com.oracle.graal.python.test/src/tests/test_generators.py b/graalpython/com.oracle.graal.python.test/src/tests/test_generators.py index bec89de817..f37a8843dd 100644 --- a/graalpython/com.oracle.graal.python.test/src/tests/test_generators.py +++ b/graalpython/com.oracle.graal.python.test/src/tests/test_generators.py @@ -6,6 +6,7 @@ import sys import os import unittest +from tests import util class ExceptionTest(unittest.TestCase): @@ -557,7 +558,7 @@ def gen(): assert f.f_globals is globals() assert f.f_locals == {'a': 1, 'b': 2, 'c': 3} # TODO GR-61955 - if sys.implementation.name != "graalpy" or not __graalpython__.is_bytecode_dsl_interpreter: + if not util.IS_BYTECODE_DSL: assert f.f_lineno == gen.__code__.co_firstlineno + 5 assert not g.gi_frame @@ -591,7 +592,7 @@ def gen(): assert f.f_globals is globals() assert f.f_locals == {'a': 1, 'b': 2} # TODO GR-61955 - if sys.implementation.name != "graalpy" or not __graalpython__.is_bytecode_dsl_interpreter: + if not util.IS_BYTECODE_DSL: assert f.f_lineno == gen.__code__.co_firstlineno + 3 diff --git a/graalpython/com.oracle.graal.python.test/src/tests/test_pdb.py b/graalpython/com.oracle.graal.python.test/src/tests/test_pdb.py index f66661927d..3028614d89 100644 --- a/graalpython/com.oracle.graal.python.test/src/tests/test_pdb.py +++ b/graalpython/com.oracle.graal.python.test/src/tests/test_pdb.py @@ -41,6 +41,7 @@ import doctest import sys import unittest +from tests import util # Copied from test_doctest @@ -69,8 +70,6 @@ def __exit__(self, *exc): if self.orig_trace: sys.settrace(self.orig_trace) - -@unittest.skipIf(os.environ.get('BYTECODE_DSL_INTERPRETER'), "TODO: FrameSlotTypeException with reparsing") def doctest_pdb_locals(): """ Test that locals get synced after breakpoint @@ -101,63 +100,61 @@ def doctest_pdb_locals(): """ -@unittest.skipIf(os.environ.get('BYTECODE_DSL_INTERPRETER'), "TODO: FrameSlotTypeException with reparsing") -def doctest_pdb_locals_generator(): - """ - Test that locals get synced after breakpoint in a generator - - >>> def test_function(): - ... a = 1 - ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace() - ... a = 2 - ... yield - - >>> with PdbTestInput([ - ... 'p a', - ... 'next', - ... 'p a', - ... 'continue', - ... ]): - ... next(test_function()) - > (4)test_function() - -> a = 2 - (Pdb) p a - 1 - (Pdb) next - > (5)test_function() - -> yield - (Pdb) p a - 2 - (Pdb) continue - """ - - -@unittest.skipIf(os.environ.get('BYTECODE_DSL_INTERPRETER'), "TODO: FrameSlotTypeException with reparsing") -def doctest_pdb_locals_sync_back(): - """ - Test that locals set by debugger get propagated back into the frame. - - >>> def test_function(): - ... foo = 1 - ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace() - ... return foo - - >>> with PdbTestInput([ - ... 'p foo', - ... 'foo = 5', - ... 'continue', - ... ]): - ... print(test_function()) - > (4)test_function() - -> return foo - (Pdb) p foo - 1 - (Pdb) foo = 5 - (Pdb) continue - 5 - """ +if not util.IS_BYTECODE_DSL: + def doctest_pdb_locals_generator(): + """ + Test that locals get synced after breakpoint in a generator + + >>> def test_function(): + ... a = 1 + ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace() + ... a = 2 + ... yield + + >>> with PdbTestInput([ + ... 'p a', + ... 'next', + ... 'p a', + ... 'continue', + ... ]): + ... next(test_function()) + > (4)test_function() + -> a = 2 + (Pdb) p a + 1 + (Pdb) next + > (5)test_function() + -> yield + (Pdb) p a + 2 + (Pdb) continue + """ + + + def doctest_pdb_locals_sync_back(): + """ + Test that locals set by debugger get propagated back into the frame. + + >>> def test_function(): + ... foo = 1 + ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace() + ... return foo + + >>> with PdbTestInput([ + ... 'p foo', + ... 'foo = 5', + ... 'continue', + ... ]): + ... print(test_function()) + > (4)test_function() + -> return foo + (Pdb) p foo + 1 + (Pdb) foo = 5 + (Pdb) continue + 5 + """ -@unittest.skipIf(os.environ.get('BYTECODE_DSL_INTERPRETER'), "TODO: FrameSlotTypeException with reparsing") def test_run_doctests(): doctest.testmod(sys.modules[__name__], raise_on_error=True) diff --git a/graalpython/com.oracle.graal.python.test/src/tests/test_repl.py b/graalpython/com.oracle.graal.python.test/src/tests/test_repl.py index d2860db5d1..05f1fce96f 100644 --- a/graalpython/com.oracle.graal.python.test/src/tests/test_repl.py +++ b/graalpython/com.oracle.graal.python.test/src/tests/test_repl.py @@ -45,6 +45,7 @@ import sys import tempfile import unittest +from tests import util from dataclasses import dataclass from textwrap import dedent @@ -191,7 +192,7 @@ def test_continuation(): ''')) - @unittest.skipIf(os.environ.get('BYTECODE_DSL_INTERPRETER'), "TODO: vs in traceback") + @util.skipIfBytecodeDSL("TODO: vs in traceback") def test_exceptions(): validate_repl(dedent("""\ >>> 1 / 0 diff --git a/graalpython/com.oracle.graal.python.test/src/tests/test_sys_settrace.py b/graalpython/com.oracle.graal.python.test/src/tests/test_sys_settrace.py index 9f5f14af92..6998f0dc44 100644 --- a/graalpython/com.oracle.graal.python.test/src/tests/test_sys_settrace.py +++ b/graalpython/com.oracle.graal.python.test/src/tests/test_sys_settrace.py @@ -42,7 +42,7 @@ import difflib import sys import signal - +from tests import util import builtins @@ -161,7 +161,7 @@ def test_case(self): return test_case -@unittest.skipIf(os.environ.get('BYTECODE_DSL_INTERPRETER'), "TODO: FrameSlotTypeException with reparsing") +@util.skipIfBytecodeDSL("TODO: FrameSlotTypeException with reparsing") class TraceTests(unittest.TestCase): def trace(self, frame, event, arg): code = frame.f_code @@ -254,8 +254,8 @@ def trace_function_with_offset(self, func, offset_func): return offset_func.__code__.co_firstlineno - self.first_line class TraceTestsStmtWith(TracingEventsUnitTest): - @unittest.skipIf(not os.environ.get('BYTECODE_DSL_INTERPRETER'), "TODO: Correct break in with statement manual interpreter tracing.") - @unittest.skipIf(os.environ.get('BYTECODE_DSL_INTERPRETER'), "TODO: Breaking from within with: __exit__ sometimes won't get traced.") + @util.skipUnlessBytecodeDSL("Incorrect break in with statement tracing.") + @util.skipIfBytecodeDSL("TODO: Breaking from within with: __exit__ sometimes won't get traced.") def test_09_break_in_with(self): class C: def __enter__(self): @@ -345,8 +345,8 @@ def func(): self.assert_events(self.events, events) - @unittest.skipIf(not os.environ.get('BYTECODE_DSL_INTERPRETER'), "TODO: Correct break in with statement manual interpreter tracing.") - @unittest.skipIf(os.environ.get('BYTECODE_DSL_INTERPRETER'), "TODO: Breaking from within with: __exit__ sometimes won't get traced.") + @util.skipUnlessBytecodeDSL("Incorrect break in with statement tracing.") + @util.skipIfBytecodeDSL("TODO: Breaking from within with: __exit__ sometimes won't get traced.") def test_11_break_in_with_nested(self): class C: def __enter__(self): @@ -400,7 +400,8 @@ def func(): self.assert_events(self.events, events) - @unittest.skipIf(not os.environ.get('BYTECODE_DSL_INTERPRETER'), "TODO: Correct reraise tracing for manual interpreter.") + @util.skipUnlessBytecodeDSL("Incorrect break in with statement tracing.") + @util.skipIfBytecodeDSL("TODO: Breaking from within with: __exit__ sometimes won't get traced.") def test_12_reraise(self): def func(): try: @@ -730,7 +731,7 @@ def func(): self.assert_events(self.events, events) class ExceptStarTraceTest(TracingEventsUnitTest): - @unittest.skipIf(not os.environ.get('BYTECODE_DSL_INTERPRETER'), "TODO: Implement try-except* in manual interpreter.") + @util.skipUnlessBytecodeDSL("try-except* not implemented") def test_01_except_star_with_name(self): def func(): try: @@ -760,7 +761,7 @@ def func(): self.assert_events(self.events, events) - @unittest.skipIf(not os.environ.get('BYTECODE_DSL_INTERPRETER'), "TODO: Implement try-except* in manual interpreter.") + @util.skipUnlessBytecodeDSL("try-except* not implemented") def test_02_except_star_multi_with_name(self): def func(): try: @@ -797,8 +798,8 @@ def func(): self.assert_events(self.events, events) - @unittest.skipIf(not os.environ.get('BYTECODE_DSL_INTERPRETER'), "TODO: Implement try-except* in manual interpreter.") - @unittest.skipIf(os.environ.get('BYTECODE_DSL_INTERPRETER'), "TODO: Fix return in finally.") + @util.skipUnlessBytecodeDSL("try-except* not implemented") + @util.skipIfBytecodeDSL("TODO: Fix return in finally.") def test_03_except_star_with_finally(self): def func(): try: @@ -831,8 +832,8 @@ def func(): self.assert_events(self.events, events) - @unittest.skipIf(not os.environ.get('BYTECODE_DSL_INTERPRETER'), "TODO: Implement try-except* in manual interpreter.") - @unittest.skipIf(os.environ.get('BYTECODE_DSL_INTERPRETER'), "TODO: Fix return in finally.") + @util.skipUnlessBytecodeDSL("try-except* not implemented") + @util.skipIfBytecodeDSL("TODO: Fix return in finally.") def test_04_test_try_except_star_with_wrong_type(self): def func(): try: @@ -860,7 +861,7 @@ def func(): self.assert_events(self.events, events) - @unittest.skipIf(not os.environ.get('BYTECODE_DSL_INTERPRETER'), "TODO: Implement try-except* in manual interpreter.") + @util.skipUnlessBytecodeDSL("try-except* not implemented") def test_05_if_false_in_try_except_star(self): def func(): try: @@ -880,7 +881,7 @@ def func(): self.assert_events(self.events, events) - @unittest.skipIf(not os.environ.get('BYTECODE_DSL_INTERPRETER'), "TODO: Implement try-except* in manual interpreter.") + @util.skipUnlessBytecodeDSL("try-except* not implemented") @unittest.skipIf(sys.implementation.name == "cpython", "TODO: seems broken on CPython") def test_06_try_in_try_with_exception(self): def func(): @@ -912,7 +913,7 @@ def func(): self.assert_events(self.events, events) - @unittest.skipIf(True, "TODO: Isn't even tagged from CPython tests.") + @unittest.skip("TODO: Isn't even tagged from CPython tests.") def test_07_tracing_exception_raised_in_with(self): class NullCtx: def __enter__(self): @@ -949,7 +950,7 @@ def func(): self.assert_events(self.events, events) - @unittest.skipIf(not os.environ.get('BYTECODE_DSL_INTERPRETER'), "TODO: Implement try-except* in manual interpreter.") + @util.skipUnlessBytecodeDSL("try-except* not implemented") def test_08_try_except_star_no_exception(self): def func(): try: @@ -983,7 +984,7 @@ def func(): self.assert_events(self.events, events) - @unittest.skipIf(not os.environ.get('BYTECODE_DSL_INTERPRETER'), "TODO: Implement try-except* in manual interpreter.") + @util.skipUnlessBytecodeDSL("try-except* not implemented") def test_09_try_except_star_named_no_exception(self): def func(): try: @@ -1008,7 +1009,7 @@ def func(): self.assert_events(self.events, events) - @unittest.skipIf(not os.environ.get('BYTECODE_DSL_INTERPRETER'), "TODO: Implement try-except* in manual interpreter.") + @util.skipUnlessBytecodeDSL("try-except* not implemented") def test_10_try_except_star_exception_caught(self): def func(): try: @@ -1035,7 +1036,7 @@ def func(): self.assert_events(self.events, events) - @unittest.skipIf(not os.environ.get('BYTECODE_DSL_INTERPRETER'), "TODO: Implement try-except* in manual interpreter.") + @util.skipUnlessBytecodeDSL("try-except* not implemented") def test_11_try_except_star_named_exception_caught(self): def func(): try: @@ -1062,7 +1063,7 @@ def func(): self.assert_events(self.events, events) - @unittest.skipIf(not os.environ.get('BYTECODE_DSL_INTERPRETER'), "TODO: Implement try-except* in manual interpreter.") + @util.skipUnlessBytecodeDSL("try-except* not implemented") def test_12_try_except_star_exception_not_caught(self): def func(): try: @@ -1089,7 +1090,7 @@ def func(): self.assert_events(self.events, events) - @unittest.skipIf(not os.environ.get('BYTECODE_DSL_INTERPRETER'), "TODO: Implement try-except* in manual interpreter.") + @util.skipUnlessBytecodeDSL("try-except* not implemented") def test_13_try_except_star_named_exception_not_caught(self): def func(): try: @@ -1116,7 +1117,7 @@ def func(): self.assert_events(self.events, events) - @unittest.skipIf(not os.environ.get('BYTECODE_DSL_INTERPRETER'), "TODO: Implement try-except* in manual interpreter.") + @util.skipUnlessBytecodeDSL("try-except* not implemented") def test_14_try_except_star_nested(self): def func(): try: diff --git a/graalpython/com.oracle.graal.python.test/src/tests/test_venv.py b/graalpython/com.oracle.graal.python.test/src/tests/test_venv.py index b1f6c1e63d..87a4394767 100644 --- a/graalpython/com.oracle.graal.python.test/src/tests/test_venv.py +++ b/graalpython/com.oracle.graal.python.test/src/tests/test_venv.py @@ -83,12 +83,14 @@ def test_venv_launcher(self): assert f"Hello {tmpfile}" in out, out assert f'Original "{sys.executable}"' in out, out - @unittest.skipIf(os.environ.get('BYTECODE_DSL_INTERPRETER'), "TODO: issue with passing Bytecode DSL flag to subprocesses") def test_create_and_use_basic_venv(self): run = None run_output = '' try: - subprocess.check_output([sys.executable, "-m", "venv", self.env_dir, "--without-pip"], stderr=subprocess.STDOUT) + extra_args = [] + if sys.implementation.name == "graalpy": + extra_args = [f'--vm.Dpython.EnableBytecodeDSLInterpreter={repr(__graalpython__.is_bytecode_dsl_interpreter).lower()}'] + subprocess.check_output([sys.executable] + extra_args + ["-m", "venv", self.env_dir, "--without-pip"], stderr=subprocess.STDOUT) run = subprocess.getoutput(f"{self.env_dir}/{BINDIR}/python{EXESUF} -m site") except subprocess.CalledProcessError as err: if err.output: @@ -98,12 +100,14 @@ def test_create_and_use_basic_venv(self): if sys.platform != 'win32': assert self.env_dir in run, run - @unittest.skipIf(os.environ.get('BYTECODE_DSL_INTERPRETER'), "TODO: issue with passing Bytecode DSL flag to subprocesses") def test_create_and_use_venv_with_pip(self): run = None msg = '' try: - subprocess.check_output([sys.executable, "-m", "venv", self.env_dir2], stderr=subprocess.STDOUT) + extra_args = [] + if sys.implementation.name == "graalpy": + extra_args = [f'--vm.Dpython.EnableBytecodeDSLInterpreter={repr(__graalpython__.is_bytecode_dsl_interpreter).lower()}'] + subprocess.check_output([sys.executable] + extra_args + ["-m", "venv", self.env_dir2], stderr=subprocess.STDOUT) run = subprocess.getoutput(f"{self.env_dir2}/{BINDIR}/python{EXESUF} -m pip list") except subprocess.CalledProcessError as err: if err.output: diff --git a/graalpython/com.oracle.graal.python.test/src/tests/util.py b/graalpython/com.oracle.graal.python.test/src/tests/util.py index 07ce36ae5c..b28238c01b 100644 --- a/graalpython/com.oracle.graal.python.test/src/tests/util.py +++ b/graalpython/com.oracle.graal.python.test/src/tests/util.py @@ -1,4 +1,4 @@ -# Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # # The Universal Permissive License (UPL), Version 1.0 @@ -37,6 +37,24 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. import sys +import unittest + +IS_BYTECODE_DSL = sys.implementation.name == 'graalpy' and __graalpython__.is_bytecode_dsl_interpreter + +def skipIfBytecodeDSL(reason=''): + def wrapper(test): + if IS_BYTECODE_DSL: + return unittest.skip(f"Skipped on Bytecode DSL interpreter. {reason}")(test) + return test + return wrapper + + +def skipUnlessBytecodeDSL(reason=''): + def wrapper(test): + if sys.implementation.name == 'graalpy' and not __graalpython__.is_bytecode_dsl_interpreter: + return unittest.skip(f"Skipped on manual interpreter. {reason}")(test) + return test + return wrapper def storage_to_native(s): diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode_dsl/PBytecodeDSLRootNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode_dsl/PBytecodeDSLRootNode.java index 5c1c55fa17..f2cff89968 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode_dsl/PBytecodeDSLRootNode.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode_dsl/PBytecodeDSLRootNode.java @@ -3607,11 +3607,10 @@ public static Object doObject(VirtualFrame frame, LocalAccessor accessor, int in @Specialization(replaces = "doObject") public static Object doObjectOrUnbound(VirtualFrame frame, LocalAccessor accessor, int index, @Bind BytecodeNode bytecodeNode) { - try { - return accessor.getObject(bytecodeNode, frame); - } catch (FrameSlotTypeException e) { + if (accessor.isCleared(bytecodeNode, frame)) { throw raiseUnbound(bytecodeNode, index); } + return accessor.getObject(bytecodeNode, frame); } } diff --git a/mx.graalpython/mx_graalpython.py b/mx.graalpython/mx_graalpython.py index 95982116eb..1d777f4bcf 100644 --- a/mx.graalpython/mx_graalpython.py +++ b/mx.graalpython/mx_graalpython.py @@ -1423,7 +1423,7 @@ def graalpython_gate_runner(_, tasks): if task: run_python_unittests( graalpy_standalone_jvm(), - nonZeroIsFatal=nonZeroIsFatal, + nonZeroIsFatal=False, report=report(), parallel=6, )