Skip to content
This repository has been archived by the owner on Sep 25, 2018. It is now read-only.

Commit

Permalink
Got all optimization tests to pass under node and rhino. Testing on s…
Browse files Browse the repository at this point in the history
…partan shells is not possible, due to the large stack size caused by excessive recursion. To test these interpreters, will use the distributed test framework.
  • Loading branch information
jbeard4 committed Jan 9, 2012
1 parent c799833 commit 66cc18f
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 132 deletions.
2 changes: 1 addition & 1 deletion bin/run-module-node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ moduleToRun=$1

shift

r.js $basedir/build/core/runner.js $basedir/build/core $moduleToRun $*
node $basedir/lib/js/r.js -lib $basedir/build/core/runner.js $basedir/build/core $moduleToRun $*
6 changes: 3 additions & 3 deletions bin/run-optimization-tests-node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ dn=`dirname $0`
abspath=`cd $dn; pwd`
basedir=`dirname $abspath`

if [ ! -e $basedir/build/spartanLoaderForAllTests.js ]; then
echo Please run \"make scion gen-requirejs-test-loader-module\" before running this file.
if [ ! -e $basedir/build/tests/loaders/spartan-loader-for-all-tests.js ]; then
echo Please run \"make interpreter tests test-loader\" before running this file.
exit 1
fi;

#these tests are highly recursive, so we increase the size of the nodejs stack.
#same thing is done with the rhino tests running under the JVM
node --stack_size=4096 $basedir/lib/js/r.js $basedir/src/main/javascript/runner.js $basedir/build/ scxml/test/node-optimization-harness
node --stack_size=4096 $basedir/lib/js/r.js -lib $basedir/build/core/runner.js $basedir/build/core scxml/test/node-optimization-harness
124 changes: 25 additions & 99 deletions bin/run-optimization-tests-rhino.sh
Original file line number Diff line number Diff line change
@@ -1,110 +1,36 @@
#!/bin/sh
# ----------------------------------------------------------------------------
# Copyright 2001-2006 The Apache Software Foundation.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ----------------------------------------------------------------------------

# Copyright (c) 2001-2002 The Apache Software Foundation. All rights
# reserved.
#this script is copied from /usr/bin/rhino on Ubuntu 11.10
#we need a special script here because the stack gets really big in the optimization tests, so we need to set JVM option Xss
#really, I should fix this the optimization test runner to be less recursive.

dn=`dirname $0`
abspath=`cd $dn; pwd`
basedir=`dirname $abspath`

BASEDIR=`dirname $abspath`/target/appassembler/
BASEDIR=`(cd "$BASEDIR"; pwd)`
root=`dirname $abspath`

# OS specific support. $var _must_ be set to either true or false.
cygwin=false;
darwin=false;
case "`uname`" in
CYGWIN*) cygwin=true ;;
Darwin*) darwin=true
if [ -z "$JAVA_VERSION" ] ; then
JAVA_VERSION="CurrentJDK"
else
echo "Using Java version: $JAVA_VERSION"
fi
if [ -z "$JAVA_HOME" ] ; then
JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/${JAVA_VERSION}/Home
fi
;;
esac

if [ -z "$JAVA_HOME" ] ; then
if [ -r /etc/gentoo-release ] ; then
JAVA_HOME=`java-config --jre-home`
fi
fi

# For Cygwin, ensure paths are in UNIX format before anything is touched
if $cygwin ; then
[ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
[ -n "$CLASSPATH" ] && CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
fi

# If a specific java binary isn't specified search for the standard 'java' binary
if [ -z "$JAVACMD" ] ; then
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
else
JAVACMD=`which java`
fi
fi

if [ ! -x "$JAVACMD" ] ; then
echo "Error: JAVA_HOME is not defined correctly."
echo " We cannot execute $JAVACMD"
exit 1
fi

if [ -z "$REPO" ]
then
REPO="$BASEDIR"/repo
fi
if [ ! -e $basedir/build/tests/loaders/spartan-loader-for-all-tests.js ]; then
echo Please run \"make interpreter tests test-loader\" before running this file.
exit 1
fi;

CLASSPATH=$CLASSPATH_PREFIX:"$REPO"/rhino/js/1.7R2/js-1.7R2.jar
JAVA_CMD="/usr/bin/java"
JAVA_OPTS=""
JAVA_CLASSPATH="/usr/share/java/js.jar:/usr/share/java/jline.jar"
JAVA_MAIN="org.mozilla.javascript.tools.shell.Main"
EXTRA_JVM_ARGUMENTS="-Xss10m" #increase max heap size so we don't stackoverflow

# For Cygwin, switch paths to Windows format before running java
if $cygwin; then
[ -n "$CLASSPATH" ] && CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
[ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
[ -n "$HOME" ] && HOME=`cygpath --path --windows "$HOME"`
[ -n "$BASEDIR" ] && BASEDIR=`cygpath --path --windows "$BASEDIR"`
[ -n "$REPO" ] && REPO=`cygpath --path --windows "$REPO"`
## Fix for #512498
## Change Bootclasspath when using OpenJDK because OpenJDK6
## bundle his own release of Rhino.
## References:
## <https://bugs.launchpad.net/ubuntu/+source/openjdk-6/+bug/255149>
## <http://icedtea.classpath.org/bugzilla/show_bug.cgi?id=179>
## <http://www.openoffice.org/issues/show_bug.cgi?id=91641>
isOpenJDK=`$JAVA_CMD -version 2>&1 | grep -i "OpenJDK" | wc -l`
if [ $isOpenJDK -gt 0 ]
then
JAVA_OPTS="-Xbootclasspath:/usr/lib/jvm/java-6-openjdk/jre/lib/rt.jar"
fi

exec "$JAVACMD" $JAVA_OPTS \
$EXTRA_JVM_ARGUMENTS \
-classpath "$CLASSPATH" \
-Dapp.name="JS-SCION" \
-Dapp.pid="$$" \
-Dapp.repo="$REPO" \
-Dbasedir="$BASEDIR" \
org.mozilla.javascript.tools.shell.Main \
-debug \
${root}/lib/js/r.js \
${root}/build/runner.js \
${root}/build \
scxml/test/rhino-optimization-harness \
"$*"



$JAVA_CMD $JAVA_OPTS $EXTRA_JVM_ARGUMENTS -classpath $JAVA_CLASSPATH $JAVA_MAIN \
-debug $basedir/lib/js/r.js -lib $basedir/build/core/runner.js $basedir/build/core scxml/test/rhino-optimization-harness
27 changes: 6 additions & 21 deletions bin/run-optimization-tests-spartan-shell.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,13 @@ dn=`dirname $0`
abspath=`cd $dn; pwd`
basedir=`dirname $abspath`

if [ ! -e $basedir/build/spartanLoaderForAllTests.js ]; then
echo Please run \"make scion gen-requirejs-test-loader-module\" before running this file.
if [ ! -e $basedir/build/tests/loaders/spartan-loader-for-all-tests.js ]; then
echo Please run \"make interpreter tests test-loader\" before running this file.
exit 1
fi;

defaultShell=spidermonkey-js
shell=${1-$defaultShell}
echo $shell

pushd $basedir/build
if [ -e main.js ]; then
mv main.js /tmp/
fi;

ln -s scxml/test/spartan-optimization-harness.js main.js

$shell $basedir/lib/js/r.js

#move original main.js back
rm main.js
if [ -e /tmp/main.js ]; then
mv /tmp/main.js .
fi;
interpreter=${1-spidermonkey}

popd
#these tests are highly recursive, so we increase the size of the nodejs stack.
#same thing is done with the rhino tests running under the JVM
$interpreter $basedir/lib/js/r.js -lib $basedir/build/core/runner.js $basedir/build/core scxml/test/spartan-optimization-harness
22 changes: 22 additions & 0 deletions lib/js/r.js
Original file line number Diff line number Diff line change
Expand Up @@ -3096,6 +3096,28 @@ define('spartan/print', function () {
return print;
});

}

if(env === 'node') {
define('node/quit', function(){
return process.exit;
});


}

if(env === 'rhino') {
define('rhino/quit', function(){
return quit;
});

}

if(env === 'spartan') {
define('spartan/quit', function(){
return quit;
});

}
/**
* @license RequireJS Copyright (c) 2010-2011, The Dojo Foundation All Rights Reserved.
Expand Down
4 changes: 2 additions & 2 deletions src/main/coffeescript/scxml/optimization/class.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ define ["scxml/optimization/initializer","lib/beautify"],(initializer,js_beautif
var transitions = #{initializer.arrayToIdentifierListString transitionsForEvent};
for(var i = 0,l=transitions.length; i < l; i++){
var transition = transitions[i];
if(!transition.cond || evaluator(transition.cond)){
if(!transition.cond || evaluator(transition)){
toReturn.push(transition);
}
}
Expand All @@ -39,7 +39,7 @@ define ["scxml/optimization/initializer","lib/beautify"],(initializer,js_beautif
var transitions = #{initializer.arrayToIdentifierListString defaultTransitionsForEvent };
for(var i = 0,l=transitions.length; i < l; i++){
var transition = transitions[i];
if(!transition.cond || evaluator(transition.cond)){
if(!transition.cond || evaluator(transition)){
toReturn.push(transition);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ define ->
var toReturn = [];
for(var i=0; i < transitions.length; i++){
var transition = transitions[i];
if(!transition.cond || evaluator(transition.cond)){
if(!transition.cond || evaluator(transition)){
toReturn.push(transition);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Copyright (C) 2011 Jacob Beard
# Released under GNU LGPL, read the file 'COPYING' for more information

define ["scxml/json2model","scxml/optimization/class","scxml/optimization/state-table","scxml/optimization/switch","lib/json2"],(json2model,classOpt,tableOpt,switchOpt,logger) ->
define ["scxml/json2model","scxml/optimization/class","scxml/optimization/state-table","scxml/optimization/switch","logger","env!env/file"],(json2model,classOpt,tableOpt,switchOpt,logger,file) ->

(pathToSCXMLJson,optimizerName="table",beautify,asyncModuleDef) ->
beautify = beautify is "true"
asyncModuleDef = asyncModuleDef is "true"

jsonDoc = JSON.parse(readFile(pathToSCXMLJson))
jsonDoc = JSON.parse(file.readFile(pathToSCXMLJson))
model = json2model jsonDoc
optimizer = switch optimizerName
when "table" then tableOpt
Expand Down
7 changes: 4 additions & 3 deletions src/main/coffeescript/scxml/test/optimization-harness.coffee
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Copyright (C) 2011 Jacob Beard
# Released under GNU LGPL, read the file 'COPYING' for more information

define ["scxml/json2model","scxml/json2extra-model", "scxml/test/harness", "scxml/async-for","util/set/ArraySet","util/set/BitVector","util/set/BooleanArray","util/set/ObjectSet", "spartanLoaderForAllTests", "class-transition-lookup-optimization-loader", "switch-transition-lookup-optimization-loader", "table-transition-lookup-optimization-loader","scxml/model","scxml/extra-model"],(json2model,json2ExtraModel,harness,asyncForEach,ArraySet,BitVectorInitializer,BooleanArrayInitializer,ObjectSetInitializer,testTuples,classTransitionOpts,switchTransitionOpts,tableTransitionOpts,m,extraModel) ->
define ["scxml/json2model","scxml/json2extra-model", "scxml/test/harness", "scxml/async-for","util/set/ArraySet","util/set/BitVector","util/set/BooleanArray","util/set/ObjectSet", "tests/loaders/spartan-loader-for-all-tests", "tests/loaders/class-transition-lookup-optimization-loader", "tests/loaders/switch-transition-lookup-optimization-loader", "tests/loaders/table-transition-lookup-optimization-loader","scxml/model","scxml/extra-model","scxml/default-transition-selector"],(json2model,json2ExtraModel,harness,asyncForEach,ArraySet,BitVectorInitializer,BooleanArrayInitializer,ObjectSetInitializer,testTuples,classTransitionOpts,switchTransitionOpts,tableTransitionOpts,m,extraModel,defaultTransitionSelector) ->



runTests = (setTimeout,clearTimeout,finish,mainloop) ->

Expand All @@ -14,15 +16,14 @@ define ["scxml/json2model","scxml/json2extra-model", "scxml/test/harness", "scxm

#parse scxmlJson model
model = json2model scxmlJson


#initialize opts
classTransOpt = classTransitionOpts[i] model.transitions,model.events
switchTransOpt = switchTransitionOpts[i] model.transitions,model.events
tableTransOpt = tableTransitionOpts[i] model.transitions,model.events

optArgs = {
"default transition lookup" : {}
"default transition lookup" : {transitionSelector:defaultTransitionSelector()}
"class-transition-lookup" : {transitionSelector:classTransOpt,onlySelectFromBasicStates:true}
"switch-transition-lookup" : {transitionSelector:switchTransOpt}
"table-transition-lookup" : {transitionSelector:tableTransOpt}
Expand Down

0 comments on commit 66cc18f

Please sign in to comment.