added debugging support and integrated with Eclipse debugger
This commit is contained in:
@@ -1,57 +0,0 @@
|
||||
package lua.debug;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import lua.io.Closure;
|
||||
import lua.io.LoadState;
|
||||
import lua.io.Proto;
|
||||
import lua.value.LValue;
|
||||
|
||||
public class DebugStackStateTest extends TestCase {
|
||||
|
||||
public void testDebugStackState() throws InterruptedException, IOException {
|
||||
String script = "/test6.luac";
|
||||
|
||||
// set up the vm
|
||||
final DebugStackState state = new DebugStackState();
|
||||
InputStream is = getClass().getResourceAsStream( script );
|
||||
Proto p = LoadState.undump(state, is, script);
|
||||
|
||||
// create closure and execute
|
||||
final Closure c = new Closure( state, p );
|
||||
|
||||
// suspend the vm right away
|
||||
state.suspend();
|
||||
state.set( 14 );
|
||||
|
||||
// start the call processing in its own thread
|
||||
new Thread() {
|
||||
public void run() {
|
||||
try {
|
||||
state.doCall( c, new LValue[0] );
|
||||
} catch ( Exception e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
|
||||
// step for 5 steps
|
||||
for ( int i=0; i<5; i++ ) {
|
||||
state.step();
|
||||
Thread.sleep(500);
|
||||
System.out.println("--- callgraph="+state.callgraph() );
|
||||
System.out.println("--- stack="+state.stack() );
|
||||
System.out.println("--- variable(1,0)="+state.variable(1,0) );
|
||||
}
|
||||
|
||||
// resume the vm
|
||||
state.resume();
|
||||
Thread.sleep(500);
|
||||
System.out.println("--- callgraph="+state.callgraph() );
|
||||
state.resume();
|
||||
Thread.sleep(500);
|
||||
System.out.println("--- callgraph="+state.callgraph() );
|
||||
}
|
||||
}
|
||||
81
src/test/java/lua/debug/LuaJVMTest.java
Normal file
81
src/test/java/lua/debug/LuaJVMTest.java
Normal file
@@ -0,0 +1,81 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2007 LuaJ. All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
******************************************************************************/
|
||||
package lua.debug;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import lua.LuaJVM;
|
||||
|
||||
/**
|
||||
* Sanity test for LuaJVM.
|
||||
*/
|
||||
public class LuaJVMTest extends TestCase {
|
||||
protected void doTestRun(String testName) {
|
||||
String[] args = new String[2];
|
||||
args[0] = "-file";
|
||||
URL filePath = getClass().getResource("/"+ testName);
|
||||
if (filePath != null) {
|
||||
args[1] = filePath.getPath();
|
||||
try {
|
||||
LuaJVM.main(args);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail("Test " + testName + " failed due to " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void testRun() {
|
||||
String[] tests = new String[] {
|
||||
"autoload",
|
||||
"boolean",
|
||||
"calls",
|
||||
"coercions",
|
||||
"compare",
|
||||
"math",
|
||||
"mathlib",
|
||||
"metatables",
|
||||
"select",
|
||||
"setlist",
|
||||
"swingapp",
|
||||
"test1",
|
||||
"test2",
|
||||
"test3",
|
||||
"test4",
|
||||
"test5",
|
||||
"test6",
|
||||
"test7",
|
||||
"type",
|
||||
"upvalues",
|
||||
//"strlib"
|
||||
};
|
||||
|
||||
for (String test : tests) {
|
||||
System.out.println("==> running test: " + test + ".lua");
|
||||
doTestRun(test + ".lua");
|
||||
System.out.println("==> running test: " + test + ".luac");
|
||||
doTestRun(test + ".luac");
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
}
|
||||
39
src/test/java/lua/debug/TypeTest.java
Normal file
39
src/test/java/lua/debug/TypeTest.java
Normal file
@@ -0,0 +1,39 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2007 LuaJ. All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
******************************************************************************/
|
||||
package lua.debug;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import lua.value.Type;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class TypeTest extends TestCase {
|
||||
public void testEnumToString() {
|
||||
assertEquals("boolean", Type.bool.toString());
|
||||
}
|
||||
|
||||
public void testStringToEnum() {
|
||||
String boolStr = "boolean";
|
||||
assertEquals(Type.bool, Type.valueOf(boolStr));
|
||||
}
|
||||
}
|
||||
@@ -1,92 +0,0 @@
|
||||
package lua.io;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import lua.value.LDouble;
|
||||
import lua.value.LInteger;
|
||||
import lua.value.LNumber;
|
||||
|
||||
public class LoadStateTest extends TestCase {
|
||||
double[] DOUBLE_VALUES = {
|
||||
0.0,
|
||||
1.0,
|
||||
2.5,
|
||||
10.0,
|
||||
16.0,
|
||||
16.125,
|
||||
-1.0,
|
||||
2.0,
|
||||
-2.0,
|
||||
-10.0,
|
||||
-0.25,
|
||||
-25,
|
||||
Integer.MAX_VALUE,
|
||||
Integer.MAX_VALUE - 1,
|
||||
(double)Integer.MAX_VALUE + 1.0,
|
||||
Integer.MIN_VALUE,
|
||||
Integer.MIN_VALUE + 1,
|
||||
(double)Integer.MIN_VALUE - 1.0,
|
||||
Double.NEGATIVE_INFINITY,
|
||||
Double.POSITIVE_INFINITY,
|
||||
Double.MAX_VALUE,
|
||||
Double.MAX_VALUE
|
||||
};
|
||||
|
||||
public void testLongBitsToLuaNumber() {
|
||||
for ( int i = 0; i < DOUBLE_VALUES.length; ++i ) {
|
||||
double v = DOUBLE_VALUES[i];
|
||||
long bits = Double.doubleToLongBits( v );
|
||||
LNumber luaNumber = LoadState.longBitsToLuaNumber( bits );
|
||||
|
||||
assertEquals( v, luaNumber.luaAsDouble() );
|
||||
|
||||
if ( v != Integer.MIN_VALUE ) {
|
||||
// Special case of MIN_VALUE is probably not worth dealing with.
|
||||
// (Unlike zero, which is also a special case but much more common.)
|
||||
assertEquals( "Value "+v+" (at index "+i+") can be represented as integer but was not",
|
||||
luaNumber instanceof LInteger, v == (double)( (int) v ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private LNumber simpleBitsToLuaNumber( long bits ) {
|
||||
double value = Double.longBitsToDouble( bits );
|
||||
int valueAsInt = (int) value;
|
||||
|
||||
if ( value == (double) valueAsInt ) {
|
||||
return new LInteger( valueAsInt );
|
||||
} else {
|
||||
return new LDouble( value );
|
||||
}
|
||||
}
|
||||
|
||||
public void testLongBitsToLuaNumberSpeed() {
|
||||
long[] BITS = new long[ 500000 ];
|
||||
Random r = new Random();
|
||||
|
||||
for ( int i = 0; i < DOUBLE_VALUES.length; ++i ) {
|
||||
BITS[i] = Double.doubleToLongBits( DOUBLE_VALUES[i] );
|
||||
}
|
||||
for ( int i = DOUBLE_VALUES.length; i < BITS.length; i += 2 ) {
|
||||
BITS[i ] = r.nextLong();
|
||||
BITS[i+1] = Double.doubleToLongBits( r.nextDouble() );
|
||||
}
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
for ( int j = 0; j < BITS.length; ++j ) {
|
||||
LoadState.longBitsToLuaNumber( BITS[j] );
|
||||
}
|
||||
long endTime = System.currentTimeMillis();
|
||||
long complexConversionTime = endTime - startTime;
|
||||
|
||||
startTime = System.currentTimeMillis();
|
||||
for ( int j = 0; j < BITS.length; ++j ) {
|
||||
simpleBitsToLuaNumber( BITS[j] );
|
||||
}
|
||||
endTime = System.currentTimeMillis();
|
||||
long simpleConversionTime = endTime - startTime;
|
||||
|
||||
assertTrue( complexConversionTime < simpleConversionTime );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user