Permalink
Browse files

Run OSH unit and spec tests under byterun with OPy-compiled bytecode.

We were using the CPython-compiled bytecode in $REPO_ROOT, rather than
the OPy-compiled bytecode under $REPO_ROOT/opy/_tmp/oil-opy.

This is because of the __import__ issue.

All unit test and spec tests still pass.
  • Loading branch information...
Andy Chu
Andy Chu committed Apr 9, 2018
1 parent 8ee5271 commit 35eb2e638be5df2004741dd6e2e00ee06c2f9591
Showing with 32 additions and 6 deletions.
  1. +3 −1 bin/osh-byterun
  2. +6 −1 opy/byterun/pyvm2.py
  3. +21 −4 opy/test.sh
  4. +1 −0 opy/testdata/speed.py
  5. +1 −0 opy/testdata/speed_main.py
View
@@ -1,6 +1,8 @@
#!/bin/bash
#
# OSH running on OPyPy. OPyPy is the OPy front end with byterun.
# OSH running under byterun.
# Because of the $PYTHONPATH setting, this will import from the Oil repo.
# See opy/test.sh for a different invocation.
readonly THIS_DIR=$(cd $(dirname $0) && pwd)
readonly OIL_DIR=$THIS_DIR/..
View
@@ -989,9 +989,14 @@ def byte_IMPORT_NAME(self, name):
frame = self.frame
# NOTE: This can read .pyc files not compiled with OPy!
# TODO: Respect OPY_PATH
#debug1('IMPORT name=%s fromlist=%s level=%s', name, fromlist, level)
mod = __import__(name, frame.f_globals, frame.f_locals, fromlist, level)
#print('-- IMPORTED %s -> %s' % (name, mod))
#debug1('IMPORTED %s -> %s' % (name, mod))
self.push(mod)
def byte_IMPORT_STAR(self):
View
@@ -8,10 +8,16 @@ set -o pipefail
set -o errexit
readonly THIS_DIR=$(cd $(dirname $0) && pwd)
readonly OPYC=$THIS_DIR/../bin/opyc
source $THIS_DIR/common.sh
# We have to invoke opyc like this because byterun uses __import__, which
# respects PYTHONPATH. If we use ../bin/opyc, it will use the CPython-compiled
# bytecode in the repo, rather than the OPy-compiled bytecode in _tmp/oil-opy.
opyc() {
python bin/opy_.pyc opyc "$@"
}
oil-opy() {
_tmp/oil-opy/bin/oil "$@"
}
@@ -47,7 +53,7 @@ oil-unit() {
# Note: adding PYTHONPATH screws things up, I guess because it's the HOST
# interpreter pythonpath.
$OPYC run $t
opyc run $t
status=$?
if test $status -ne 0; then
@@ -99,7 +105,7 @@ oil-byterun-failed() {
echo ---
pushd _tmp/oil-opy
$OPYC run $t
opyc run $t
popd
done
}
@@ -171,7 +177,18 @@ spec() {
# TODO: Should be OSH_ALT instead of OSH_OVM?
# Usually it is dev build vs. release build, but here it is CPython vs.
# byterun.
OSH_OVM=bin/osh-byterun test/spec.sh $action "$@"
# HACK to get around __import__ problem with byterun.
local stub=opy/_tmp/oil-opy/bin/osh-byterun
cat >$stub <<'EOF'
#!/bin/bash
readonly THIS_DIR=$(cd $(dirname $0) && pwd)
exec python $THIS_DIR/opy_.pyc opyc run $THIS_DIR/oil.pyc osh "$@"
EOF
chmod +x $stub
OSH_OVM=$stub test/spec.sh $action "$@"
popd
}
View
1 opy/testdata/speed.py 100644 → 100755
@@ -1,3 +1,4 @@
#!/usr/bin/python
def do_sum(n):
sum = 0
for i in xrange(n):
View
1 opy/testdata/speed_main.py 100644 → 100755
@@ -1,3 +1,4 @@
#!/usr/bin/python
import sys
import speed

0 comments on commit 35eb2e6

Please sign in to comment.