Skip to content

Commit 32f000b

Browse files
committed
[GR-46348] Enable assertions in native images for CI tests
PullRequest: graalpython/2792
2 parents 7385b8a + c01a324 commit 32f000b

File tree

5 files changed

+29
-15
lines changed

5 files changed

+29
-15
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/PythonBuiltinClassType.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,7 @@ public final Shape getInstanceShape(PythonLanguage lang) {
656656
UnicodeDecodeError.redefinedSlots = new SpecialMethodSlot[]{SpecialMethodSlot.Str};
657657
UnicodeTranslateError.redefinedSlots = new SpecialMethodSlot[]{SpecialMethodSlot.Str};
658658
OSError.redefinedSlots = new SpecialMethodSlot[]{SpecialMethodSlot.Str};
659+
PStructUnpackIterator.redefinedSlots = new SpecialMethodSlot[]{SpecialMethodSlot.Next, SpecialMethodSlot.Iter, SpecialMethodSlot.LengthHint};
659660

660661
// These slots actually contain context independent values, but they are initialized in
661662
// StructSequence to artificial PBuiltinFunctions with artificial builtin node factories,

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinConstructors.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2219,7 +2219,11 @@ static Object doNativeSubclass(VirtualFrame frame, Object cls, Object obj, @Supp
22192219
@Cached @SuppressWarnings("unused") IsSubtypeNode isSubtype,
22202220
@Shared @Cached PyObjectStrAsObjectNode strNode,
22212221
@Cached CExtNodes.StringSubtypeNew subtypeNew) {
2222-
return subtypeNew.call(cls, strNode.execute(frame, obj));
2222+
if (obj == PNone.NO_VALUE) {
2223+
return subtypeNew.call(cls, T_EMPTY_STRING);
2224+
} else {
2225+
return subtypeNew.call(cls, strNode.execute(frame, obj));
2226+
}
22232227
}
22242228

22252229
protected static boolean isSubtypeOfString(VirtualFrame frame, IsSubtypeNode isSubtypeNode, Object cls) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextTupleBuiltins.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@
6262
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes.ListGeneralizationNode;
6363
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes.SetItemNode;
6464
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes.SetItemScalarNode;
65-
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodesFactory.GetItemScalarNodeGen;
6665
import com.oracle.graal.python.builtins.objects.tuple.PTuple;
6766
import com.oracle.graal.python.lib.PySliceNew;
6867
import com.oracle.graal.python.lib.PyTupleSizeNode;
@@ -136,7 +135,11 @@ abstract static class _PyTuple_SET_ITEM extends CApiTernaryBuiltinNode {
136135
int doManaged(PTuple tuple, long index, Object element,
137136
@Cached("createSetItem()") SequenceStorageNodes.SetItemNode setItemNode,
138137
@Cached ConditionProfile generalizedProfile) {
139-
assert GetItemScalarNodeGen.getUncached().execute(tuple.getSequenceStorage(), (int) index) == null;
138+
// we cannot assume that there is nothing already in the tuple, because the API usage
139+
// is valid if the tuple has never been visible to Python code so far, and it is up to
140+
// the extension author to take care of correct decref's for the previously contained
141+
// elements. c.f. _testcapi.c#test_k_code where a tuple's element 0 is set multiple
142+
// times
140143
SequenceStorage sequenceStorage = tuple.getSequenceStorage();
141144
checkBounds(sequenceStorage, index);
142145
SequenceStorage newStorage = setItemNode.execute(null, sequenceStorage, (int) index, element);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/transitions/ArgDescriptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ public enum ArgDescriptor {
233233
PY_UCS4_PTR("Py_UCS4*"),
234234
PY_UNICODE("Py_UNICODE"),
235235
PyUnicodeObject(ArgBehavior.PyObject, "PyUnicodeObject*"),
236-
PY_UNICODE_PTR("Py_UNICODE*"),
236+
PY_UNICODE_PTR(ArgBehavior.WrappedPointer, "Py_UNICODE*"),
237237
PyVarObject(ArgBehavior.PyObject, "PyVarObject*"),
238238
ConstPyVarObject(ArgBehavior.PyObject, "const PyVarObject*"),
239239
PYADDRPAIR_PTR("PyAddrPair*"),

mx.graalpython/mx_graalpython.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,17 @@
9797

9898
_COLLECTING_COVERAGE = False
9999

100-
def is_collectiong_coverage():
101-
return bool(mx_gate.get_jacoco_agent_args() or _COLLECTING_COVERAGE)
102-
100+
CI = os.environ.get("CI") == "true"
101+
BUILD_NATIVE_IMAGE_WITH_ASSERTIONS = CI and sys.platform != "win32" # disable assertions on win32 until we properly support that platform
103102

104-
if os.environ.get("CI") == "true" and not os.environ.get("GRAALPYTEST_FAIL_FAST"):
103+
if CI and not os.environ.get("GRAALPYTEST_FAIL_FAST"):
105104
os.environ["GRAALPYTEST_FAIL_FAST"] = "true"
106105

107106

107+
def is_collecting_coverage():
108+
return bool(mx_gate.get_jacoco_agent_args() or _COLLECTING_COVERAGE)
109+
110+
108111
def wants_debug_build(flags=os.environ.get("CFLAGS", "")):
109112
return any(x in flags for x in ["-g", "-ggdb", "-ggdb3"])
110113

@@ -252,7 +255,7 @@ def do_run_python(args, extra_vm_args=None, env=None, jdk=None, extra_dists=None
252255
if extra_dists:
253256
dists += extra_dists
254257

255-
if not os.environ.get("CI"):
258+
if not CI:
256259
# Try eagerly to include tools for convenience when running Python
257260
if not mx.suite("tools", fatalIfMissing=False):
258261
SUITE.import_suite("tools", version=None, urlinfos=None, in_subdir=True)
@@ -697,6 +700,9 @@ def _graalvm_home(*, envfile, extra_dy=""):
697700
mx_args = ["--dy", dy] + mx_args
698701
if mx._opts.verbose:
699702
mx.run_mx(mx_args + ["graalvm-show"])
703+
if BUILD_NATIVE_IMAGE_WITH_ASSERTIONS:
704+
mx_args.append("--extra-image-builder-argument=-ea")
705+
mx_args.append("--extra-image-builder-argument=--verbose")
700706
mx.run_mx(mx_args + ["build"])
701707
out = mx.OutputCapture()
702708
mx.run_mx(mx_args + ["graalvm-home"], out=out)
@@ -722,7 +728,7 @@ def python_gvm(_=None):
722728

723729
if mx_gate.get_jacoco_agent_args():
724730
# patch our launchers created under jacoco to also run with jacoco.
725-
# do not use is_collectiong_coverage() here, we only want to patch when
731+
# do not use is_collecting_coverage() here, we only want to patch when
726732
# jacoco agent is requested.
727733
def graalvm_vm_arg(java_arg):
728734
if java_arg.startswith("@") and os.path.exists(java_arg[1:]):
@@ -918,7 +924,7 @@ def run_python_unittests(python_binary, args=None, paths=None, aot_compatible=Fa
918924
args += ["--report", reportfile]
919925

920926
result = 0
921-
if is_collectiong_coverage():
927+
if is_collecting_coverage():
922928
env['ENABLE_THREADED_GRAALPYTEST'] = "false"
923929
if mx_gate.get_jacoco_agent_args():
924930
with open(python_binary, "r") as f:
@@ -1021,7 +1027,7 @@ def run_hpy_unittests(python_binary, args=None, include_native=True, env=None, n
10211027
nonZeroIsFatal=nonZeroIsFatal, env=env, timeout=timeout)
10221028
mx.run([python_binary] + args + ["-m", "pip", "install", "--user", "pytest<=6.2.3", "pytest-xdist", "filelock"],
10231029
nonZeroIsFatal=nonZeroIsFatal, env=env, timeout=timeout)
1024-
if not is_collectiong_coverage():
1030+
if not is_collecting_coverage():
10251031
# parallelize
10261032
import threading
10271033
threads = []
@@ -1115,8 +1121,8 @@ def run_tagged_unittests(python_binary, env=None, cwd=None, javaAsserts=False, n
11151121

11161122

11171123
def graalpython_gate_runner(args, tasks):
1118-
report = lambda: (not is_collectiong_coverage()) and task
1119-
nonZeroIsFatal = not is_collectiong_coverage()
1124+
report = lambda: (not is_collecting_coverage()) and task
1125+
nonZeroIsFatal = not is_collecting_coverage()
11201126

11211127
# JUnit tests
11221128
with Task('GraalPython JUnit', tasks, tags=[GraalPythonTags.junit]) as task:
@@ -1173,7 +1179,7 @@ def graalpython_gate_runner(args, tasks):
11731179
with Task('GraalPython Python tests', tasks, tags=[GraalPythonTags.tagged]) as task:
11741180
if task:
11751181
# don't fail this task if we're running with the jacoco agent, we know that some tests don't pass with it enabled
1176-
run_tagged_unittests(python_svm(), nonZeroIsFatal=(not is_collectiong_coverage()), report=report())
1182+
run_tagged_unittests(python_svm(), nonZeroIsFatal=(not is_collecting_coverage()), report=report())
11771183

11781184
with Task('GraalPython sandboxed Python tests', tasks, tags=[GraalPythonTags.tagged_sandboxed]) as task:
11791185
if task:

0 commit comments

Comments
 (0)