Skip to content

Commit 45cb602

Browse files
committed
add a gate tag to run our python unittests with and aot binary
PullRequest: graalpython/77
2 parents ef9f41c + ebeb94a commit 45cb602

File tree

4 files changed

+103
-43
lines changed

4 files changed

+103
-43
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/PythonLanguage.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ protected void finalizeContext(PythonContext context) {
102102

103103
@Override
104104
protected boolean patchContext(PythonContext context, Env newEnv) {
105+
ensureSysExecutable(context);
105106
ensureHomeInOptions(newEnv);
106107
if (!optionsAllowPreInitializedContext(context, newEnv)) {
107108
// Incompatible options - cannot use pre-initialized context
@@ -114,6 +115,11 @@ protected boolean patchContext(PythonContext context, Env newEnv) {
114115
return true;
115116
}
116117

118+
private static void ensureSysExecutable(PythonContext context) {
119+
PythonModule sys = context.getCore().lookupBuiltinModule("sys");
120+
sys.setAttribute("executable", Compiler.command(new Object[]{"com.oracle.svm.core.posix.GetExecutableName"}));
121+
}
122+
117123
private static boolean optionsAllowPreInitializedContext(PythonContext context, Env newEnv) {
118124
// Verify that the option for using a shared core is the same as
119125
// at image building time

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

Lines changed: 57 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
import com.oracle.graal.python.builtins.objects.dict.PDict;
5656
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
5757
import com.oracle.graal.python.runtime.exception.PythonErrorType;
58+
import com.oracle.truffle.api.TruffleOptions;
5859
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
5960
import com.oracle.truffle.api.dsl.Fallback;
6061
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
@@ -211,62 +212,76 @@ public abstract static class SetLocaleNode extends PythonBuiltinNode {
211212
@Specialization(guards = {"category >= 0", "category <= 6"})
212213
@TruffleBoundary
213214
public Object setLocale(int category, @SuppressWarnings("unused") PNone posixLocaleID) {
214-
Locale.Category displayCategory = Locale.Category.DISPLAY;
215-
Locale.Category formatCategory = Locale.Category.FORMAT;
216-
217-
switch (category) {
218-
case LC_COLLATE:
219-
case LC_CTYPE:
220-
case LC_MESSAGES:
221-
formatCategory = null;
222-
break;
223-
case LC_MONETARY:
224-
case LC_NUMERIC:
225-
case LC_TIME:
226-
displayCategory = null;
227-
break;
228-
case LC_ALL:
229-
default:
230-
}
231-
232215
Locale defaultLocale;
233-
if (displayCategory != null) {
234-
defaultLocale = Locale.getDefault(displayCategory);
216+
Locale.Category displayCategory = null;
217+
Locale.Category formatCategory = null;
218+
if (!TruffleOptions.AOT) {
219+
displayCategory = Locale.Category.DISPLAY;
220+
formatCategory = Locale.Category.FORMAT;
221+
222+
switch (category) {
223+
case LC_COLLATE:
224+
case LC_CTYPE:
225+
case LC_MESSAGES:
226+
formatCategory = null;
227+
break;
228+
case LC_MONETARY:
229+
case LC_NUMERIC:
230+
case LC_TIME:
231+
displayCategory = null;
232+
break;
233+
case LC_ALL:
234+
default:
235+
}
236+
if (displayCategory != null) {
237+
defaultLocale = Locale.getDefault(displayCategory);
238+
} else {
239+
defaultLocale = Locale.getDefault(formatCategory);
240+
}
235241
} else {
236-
defaultLocale = Locale.getDefault(formatCategory);
242+
defaultLocale = Locale.getDefault();
237243
}
244+
238245
return toPosix(defaultLocale);
239246
}
240247

241248
@SuppressWarnings("fallthrough")
242249
@Specialization(guards = {"category >= 0", "category <= 6"})
243250
@TruffleBoundary
244251
public Object setLocale(int category, String posixLocaleID) {
245-
Locale.Category displayCategory = Locale.Category.DISPLAY;
246-
Locale.Category formatCategory = Locale.Category.FORMAT;
247-
248-
switch (category) {
249-
case LC_COLLATE:
250-
case LC_CTYPE:
251-
case LC_MESSAGES:
252-
formatCategory = null;
253-
break;
254-
case LC_MONETARY:
255-
case LC_NUMERIC:
256-
case LC_TIME:
257-
displayCategory = null;
258-
break;
259-
case LC_ALL:
260-
default:
252+
Locale.Category displayCategory = null;
253+
Locale.Category formatCategory = null;
254+
if (!TruffleOptions.AOT) {
255+
displayCategory = Locale.Category.DISPLAY;
256+
formatCategory = Locale.Category.FORMAT;
257+
258+
switch (category) {
259+
case LC_COLLATE:
260+
case LC_CTYPE:
261+
case LC_MESSAGES:
262+
formatCategory = null;
263+
break;
264+
case LC_MONETARY:
265+
case LC_NUMERIC:
266+
case LC_TIME:
267+
displayCategory = null;
268+
break;
269+
case LC_ALL:
270+
default:
271+
}
261272
}
262273

263274
Locale newLocale = fromPosix(posixLocaleID);
264275
if (newLocale != null) {
265-
if (displayCategory != null) {
266-
Locale.setDefault(displayCategory, newLocale);
267-
}
268-
if (formatCategory != null) {
269-
Locale.setDefault(formatCategory, newLocale);
276+
if (!TruffleOptions.AOT) {
277+
if (displayCategory != null) {
278+
Locale.setDefault(displayCategory, newLocale);
279+
}
280+
if (formatCategory != null) {
281+
Locale.setDefault(formatCategory, newLocale);
282+
}
283+
} else {
284+
Locale.setDefault(newLocale);
270285
}
271286
} else {
272287
throw raise(PythonErrorType.ValueError, "unsupported locale setting");

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ public void initialize(PythonCore core) {
100100
builtinConstants.put("copyright", LICENSE);
101101
builtinConstants.put("dont_write_bytecode", true);
102102
if (TruffleOptions.AOT) {
103-
builtinConstants.put("executable", Compiler.command(new Object[]{"com.oracle.svm.core.posix.GetExecutableName"}));
103+
// cannot set the path at this time since the binary is not yet known; will be patched
104+
// in the context
105+
builtinConstants.put("executable", PNone.NONE);
104106
} else {
105107
StringBuilder sb = new StringBuilder();
106108
sb.append(System.getProperty("java.home")).append(PythonCore.FILE_SEPARATOR).append("bin").append(PythonCore.FILE_SEPARATOR).append("java ");

mx.graalpython/mx_graalpython.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ class GraalPythonTags(object):
255255
junit = 'python-junit'
256256
unittest = 'python-unittest'
257257
cpyext = 'python-cpyext'
258+
svmunit = 'python-svm-unittest'
258259
benchmarks = 'python-benchmarks'
259260
downstream = 'python-downstream'
260261
graalvm = 'python-graalvm'
@@ -356,6 +357,42 @@ def graalpython_gate_runner(args, tasks):
356357
mx.log("Running tests with CPython")
357358
mx.run(["python3"] + test_args, nonZeroIsFatal=True)
358359

360+
with Task('GraalPython Python tests on SVM', tasks, tags=[GraalPythonTags.svmunit]) as task:
361+
if task:
362+
if not os.path.exists("./graalpython-svm"):
363+
python_svm(["-h"])
364+
if os.path.exists("./graalpython-svm"):
365+
langhome = mx_subst.path_substitutions.substitute('--native.Dllvm.home=<path:SULONG_LIBS>')
366+
367+
# tests root directory
368+
tests_folder = "graalpython/com.oracle.graal.python.test/src/tests/"
369+
370+
# list of excluded tests
371+
excluded = ["test_interop.py"]
372+
373+
def is_included(path):
374+
if path.endswith(".py"):
375+
basename = path.rpartition("/")[2]
376+
return basename.startswith("test_") and basename not in excluded
377+
return False
378+
379+
# list all 1st-level tests and exclude the SVM-incompatible ones
380+
testfiles = []
381+
paths = [tests_folder]
382+
while paths:
383+
path = paths.pop()
384+
if is_included(path):
385+
testfiles.append(path)
386+
else:
387+
try:
388+
paths += [(path + f if path.endswith("/") else "%s/%s" % (path, f)) for f in
389+
os.listdir(path)]
390+
except OSError:
391+
pass
392+
393+
test_args = ["graalpython/com.oracle.graal.python.test/src/graalpytest.py", "-v"] + testfiles
394+
mx.run(["./graalpython-svm", "--python.CoreHome=graalpython/lib-graalpython", "--python.StdLibHome=graalpython/lib-python/3", langhome] + test_args, nonZeroIsFatal=True)
395+
359396
with Task('GraalPython downstream R tests', tasks, tags=[GraalPythonTags.downstream, GraalPythonTags.R]) as task:
360397
script_r2p = os.path.join(_suite.dir, "graalpython", "benchmarks", "src", "benchmarks", "interop", "r_python_image_demo.r")
361398
script_p2r = os.path.join(_suite.dir, "graalpython", "benchmarks", "src", "benchmarks", "interop", "python_r_image_demo.py")

0 commit comments

Comments
 (0)