1. updated DebugSupport to use one port for two-way communication
2. added a command line debug option to pause the VM on start 3. minor code clean up - replaced tabs with 4 white spaces
This commit is contained in:
@@ -2,92 +2,86 @@ package org.luaj.debug;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.luaj.debug.event.DebugEventType;
|
||||
import org.luaj.debug.response.DebugResponseCallgraph;
|
||||
import org.luaj.debug.response.DebugResponseSimple;
|
||||
import org.luaj.debug.response.DebugResponseStack;
|
||||
import org.luaj.debug.response.DebugResponseVariables;
|
||||
import org.luaj.vm.Lua;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class DebugResponseTest extends TestCase {
|
||||
public void testDebugResponseSimpleSerialization() {
|
||||
try {
|
||||
DebugResponseSimple responseIn = DebugResponseSimple.SUCCESS;
|
||||
byte[] data = SerializationHelper.serialize(responseIn);
|
||||
DebugResponseSimple responseOut
|
||||
= (DebugResponseSimple)SerializationHelper.deserialize(data);
|
||||
assertEquals(responseIn, responseOut);
|
||||
} catch (IOException e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void testDebugResponseStackSerialization() {
|
||||
try {
|
||||
doTestDebugResponseStackSerialization(null);
|
||||
|
||||
doTestDebugResponseStackSerialization(new Variable[0]);
|
||||
|
||||
Variable[] variables = new Variable[5];
|
||||
variables[0] = new Variable(0, "variable1", Lua.LUA_TSTRING, "value1");
|
||||
variables[1] = new Variable(1, "variable2", Lua.LUA_TNIL, "nil");
|
||||
variables[2] = new Variable(2, "variable3", Lua.LUA_TBOOLEAN, "false");
|
||||
|
||||
TableVariable childTable = new TableVariable(0, "child", Lua.LUA_TTABLE, new String[0], new Object[0]);
|
||||
String[] keys = new String[] {"key1", "key2"};
|
||||
Object[] values = new Object[] {"value1", childTable};
|
||||
variables[3] = new TableVariable(2, "variable4", Lua.LUA_TTABLE, keys, values);
|
||||
|
||||
variables[4] = new Variable(2, "variable3", Lua.LUA_TNUMBER, "10");
|
||||
doTestDebugResponseStackSerialization(variables);
|
||||
} catch (IOException e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
public void testDebugResponseStackSerialization() {
|
||||
try {
|
||||
doTestDebugResponseStackSerialization(0, null);
|
||||
|
||||
private void doTestDebugResponseStackSerialization(Variable[] variables)
|
||||
throws IOException {
|
||||
DebugResponseVariables stackIn = new DebugResponseVariables(variables);
|
||||
byte[] data = SerializationHelper.serialize(stackIn);
|
||||
DebugResponseVariables stackOut
|
||||
= (DebugResponseVariables) SerializationHelper.deserialize(data);
|
||||
Variable[] variablesIn = stackIn.getVariables();
|
||||
Variable[] variablesOut = stackOut.getVariables();
|
||||
assertNotNull(variablesIn);
|
||||
assertNotNull(variablesOut);
|
||||
assertEquals(variablesIn.length, variablesOut.length);
|
||||
for (int i = 0; i < variablesIn.length; i++) {
|
||||
assertEquals(variablesIn[i], variablesOut[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public void testDebugResponseCallgraphSerialization() {
|
||||
try {
|
||||
doTestDebugResponseCallgraphSerialization(null);
|
||||
doTestDebugResponseCallgraphSerialization(new StackFrame[0]);
|
||||
|
||||
StackFrame[] frames = new StackFrame[1];
|
||||
frames[0] = new StackFrame(100, "test.lua");
|
||||
doTestDebugResponseCallgraphSerialization(frames);
|
||||
} catch (IOException e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void doTestDebugResponseCallgraphSerialization(StackFrame[] frames)
|
||||
throws IOException {
|
||||
DebugResponseCallgraph responseIn = new DebugResponseCallgraph(frames);
|
||||
byte[] data = SerializationHelper.serialize(responseIn);
|
||||
DebugResponseCallgraph responseOut =
|
||||
(DebugResponseCallgraph) SerializationHelper.deserialize(data);
|
||||
assertNotNull(responseOut);
|
||||
StackFrame[] inFrames = responseIn.getCallgraph();
|
||||
StackFrame[] outFrames = responseOut.getCallgraph();
|
||||
assertNotNull(outFrames);
|
||||
assertEquals(inFrames.length, outFrames.length);
|
||||
for (int i = 0; i < inFrames.length; i++) {
|
||||
assertEquals(inFrames[i], outFrames[i]);
|
||||
}
|
||||
}
|
||||
doTestDebugResponseStackSerialization(1, new Variable[0]);
|
||||
|
||||
Variable[] variables = new Variable[5];
|
||||
variables[0] = new Variable(0, "variable1", Lua.LUA_TSTRING,
|
||||
"value1");
|
||||
variables[1] = new Variable(1, "variable2", Lua.LUA_TNIL, "nil");
|
||||
variables[2] = new Variable(2, "variable3", Lua.LUA_TBOOLEAN,
|
||||
"false");
|
||||
|
||||
TableVariable childTable = new TableVariable(0, "child",
|
||||
Lua.LUA_TTABLE, new String[0], new Object[0]);
|
||||
String[] keys = new String[] { "key1", "key2" };
|
||||
Object[] values = new Object[] { "value1", childTable };
|
||||
variables[3] = new TableVariable(2, "variable4", Lua.LUA_TTABLE,
|
||||
keys, values);
|
||||
|
||||
variables[4] = new Variable(2, "variable3", Lua.LUA_TNUMBER, "10");
|
||||
doTestDebugResponseStackSerialization(2, variables);
|
||||
} catch (IOException e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void doTestDebugResponseStackSerialization(int index, Variable[] variables)
|
||||
throws IOException {
|
||||
DebugResponseStack stackIn = new DebugResponseStack(index, variables);
|
||||
byte[] data = SerializationHelper.serialize(stackIn);
|
||||
DebugResponseStack stackOut = (DebugResponseStack) SerializationHelper
|
||||
.deserialize(data);
|
||||
Variable[] variablesIn = stackIn.getVariables();
|
||||
Variable[] variablesOut = stackOut.getVariables();
|
||||
assertNotNull(variablesIn);
|
||||
assertNotNull(variablesOut);
|
||||
assertEquals(stackIn.getIndex(), stackOut.getIndex());
|
||||
assertEquals(variablesIn.length, variablesOut.length);
|
||||
for (int i = 0; i < variablesIn.length; i++) {
|
||||
assertEquals(variablesIn[i], variablesOut[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public void testDebugResponseCallgraphSerialization() {
|
||||
try {
|
||||
doTestDebugResponseCallgraphSerialization(null);
|
||||
doTestDebugResponseCallgraphSerialization(new StackFrame[0]);
|
||||
|
||||
StackFrame[] frames = new StackFrame[1];
|
||||
frames[0] = new StackFrame(100, "test.lua");
|
||||
doTestDebugResponseCallgraphSerialization(frames);
|
||||
} catch (IOException e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void doTestDebugResponseCallgraphSerialization(StackFrame[] frames)
|
||||
throws IOException {
|
||||
DebugResponseCallgraph responseIn = new DebugResponseCallgraph(frames);
|
||||
byte[] data = SerializationHelper.serialize(responseIn);
|
||||
DebugResponseCallgraph responseOut = (DebugResponseCallgraph) SerializationHelper
|
||||
.deserialize(data);
|
||||
assertNotNull(responseOut);
|
||||
StackFrame[] inFrames = responseIn.getCallgraph();
|
||||
StackFrame[] outFrames = responseOut.getCallgraph();
|
||||
assertNotNull(outFrames);
|
||||
assertEquals(inFrames.length, outFrames.length);
|
||||
for (int i = 0; i < inFrames.length; i++) {
|
||||
assertEquals(inFrames[i], outFrames[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
/*******************************************************************************
|
||||
* 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.
|
||||
******************************************************************************/
|
||||
* 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 org.luaj.debug.j2se;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -33,135 +33,172 @@ import junit.framework.TestCase;
|
||||
* Sanity test for StandardLuaJVM.
|
||||
*/
|
||||
public class LuaJVMTest extends TestCase {
|
||||
public void testCommandLineParse() {
|
||||
// null arguments
|
||||
String[] args = null;
|
||||
StandardLuaJVM vm = new StandardLuaJVM();
|
||||
try {
|
||||
vm.parse(args);
|
||||
fail("Bad parsing program. Should never reach this line.");
|
||||
} catch (ParseException e) {}
|
||||
|
||||
// empty arguments
|
||||
args = new String[] {};
|
||||
try {
|
||||
vm.parse(args);
|
||||
fail("Bad parsing program. Should never reach this line.");
|
||||
} catch (ParseException e) {}
|
||||
public void testCommandLineParse() {
|
||||
// null arguments
|
||||
String[] args = null;
|
||||
StandardLuaJVM vm = new StandardLuaJVM();
|
||||
try {
|
||||
vm.parse(args);
|
||||
fail("Bad parsing program. Should never reach this line.");
|
||||
} catch (ParseException e) {}
|
||||
|
||||
// incomplete arguments
|
||||
args = new String[] { "-debug" };
|
||||
try {
|
||||
vm.parse(args);
|
||||
fail("Bad parsing program. Should never reach this line.");
|
||||
} catch (ParseException e) {}
|
||||
|
||||
// incomplete arguments
|
||||
args = new String[] { "-debug", "1046" };
|
||||
try {
|
||||
vm.parse(args);
|
||||
fail("Bad parsing program. Should never reach this line.");
|
||||
} catch (ParseException e) {}
|
||||
|
||||
// missing script name
|
||||
args = new String[] { "-debug", "1046", "1047"};
|
||||
try {
|
||||
vm.parse(args);
|
||||
fail("Bad parsing program. Should never reach this line.");
|
||||
} catch (ParseException e) {}
|
||||
// empty arguments
|
||||
args = new String[] {};
|
||||
vm = new StandardLuaJVM();
|
||||
try {
|
||||
vm.parse(args);
|
||||
fail("Bad parsing program. Should never reach this line.");
|
||||
} catch (ParseException e) {}
|
||||
|
||||
// malformed request port
|
||||
args = new String[] { "-debug", "104x", "1046", "dummy.lua"};
|
||||
try {
|
||||
vm.parse(args);
|
||||
fail("Bad parsing program. Should never reach this line.");
|
||||
} catch (ParseException e) {}
|
||||
// incomplete arguments
|
||||
args = new String[] { "-D" };
|
||||
vm = new StandardLuaJVM();
|
||||
try {
|
||||
vm.parse(args);
|
||||
fail("Bad parsing program. Should never reach this line.");
|
||||
} catch (ParseException e) {}
|
||||
|
||||
// malformed event port
|
||||
args = new String[] { "-debug", "1046", "104x", "dummy.lua"};
|
||||
try {
|
||||
vm.parse(args);
|
||||
fail("Bad parsing program. Should never reach this line.");
|
||||
} catch (ParseException e) {}
|
||||
|
||||
// event port == request port
|
||||
args = new String[] { "-debug", "1046", "1046", "dummy.lua"};
|
||||
try {
|
||||
vm.parse(args);
|
||||
fail("Bad parsing program. Should never reach this line.");
|
||||
} catch (ParseException e) {}
|
||||
args = new String[] { "-D1046" };
|
||||
vm = new StandardLuaJVM();
|
||||
try {
|
||||
vm.parse(args);
|
||||
fail("Bad parsing program. Should never reach this line.");
|
||||
} catch (ParseException e) {}
|
||||
|
||||
// lua script cannot be found
|
||||
args = new String[] { "-debug", "1046", "1047", "dummy.lua"};
|
||||
try {
|
||||
vm.parse(args);
|
||||
vm.run();
|
||||
fail("Should never reach this line.");
|
||||
} catch (ParseException e) {
|
||||
fail("Should never reach this line.");
|
||||
} catch (IOException e) {
|
||||
//expected
|
||||
}
|
||||
|
||||
// lua script cannot be found
|
||||
args = new String[] {"dummy.lua"};
|
||||
try {
|
||||
vm.parse(args);
|
||||
vm.run();
|
||||
fail("Bad parsing program. Should never reach this line.");
|
||||
} catch (ParseException e) {
|
||||
fail("Should never reach this line.");
|
||||
} catch (IOException e) {
|
||||
//expected
|
||||
}
|
||||
}
|
||||
|
||||
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"
|
||||
};
|
||||
args = new String[] { "-DsuspendOnStart=true" };
|
||||
vm = new StandardLuaJVM();
|
||||
try {
|
||||
vm.parse(args);
|
||||
fail("Bad parsing program. Should never reach this line.");
|
||||
} catch (ParseException e) {}
|
||||
|
||||
// invalid debug option format
|
||||
args = new String[] { "-Dport=1044:suspendOnStart=true", "dummy.lua" };
|
||||
vm = new StandardLuaJVM();
|
||||
try {
|
||||
vm.parse(args);
|
||||
assertFalse(1044 == vm.getDebugPort());
|
||||
assertFalse(true == vm.getSuspendOnStart());
|
||||
assertEquals("dummy.lua", vm.getScript());
|
||||
} catch (ParseException e) {
|
||||
//expected
|
||||
}
|
||||
|
||||
args = new String[] { "-Dport=1044,suspendOnStart=xyz", "dummy.lua" };
|
||||
vm = new StandardLuaJVM();
|
||||
try {
|
||||
vm.parse(args);
|
||||
assertFalse(1044 == vm.getDebugPort());
|
||||
assertFalse(true == vm.getSuspendOnStart());
|
||||
assertEquals("dummy.lua", vm.getScript());
|
||||
} catch (ParseException e) {
|
||||
//expected
|
||||
}
|
||||
|
||||
// missing script name
|
||||
args = new String[] { "-Dport=1047,suspendOnStart=true"};
|
||||
vm = new StandardLuaJVM();
|
||||
try {
|
||||
vm.parse(args);
|
||||
fail("Bad parsing program. Should never reach this line.");
|
||||
} catch (ParseException e) {}
|
||||
|
||||
// lua script cannot be found
|
||||
args = new String[] { "-Dport=1046,suspendOnStart", "dummy.lua" };
|
||||
vm = new StandardLuaJVM();
|
||||
try {
|
||||
vm.parse(args);
|
||||
vm.run();
|
||||
fail("Should never reach this line.");
|
||||
} catch (ParseException e) {}
|
||||
catch (IOException e) {}
|
||||
|
||||
// lua script cannot be found
|
||||
args = new String[] { "dummy.lua" };
|
||||
vm = new StandardLuaJVM();
|
||||
try {
|
||||
vm.parse(args);
|
||||
vm.run();
|
||||
fail("Bad parsing program. Should never reach this line.");
|
||||
} catch (ParseException e) {
|
||||
fail("Should never reach this line.");
|
||||
} catch (IOException e) {}
|
||||
|
||||
// valid command line
|
||||
args = new String[] { "-Dport=1044,suspendOnStart=true", "dummy.lua" };
|
||||
vm = new StandardLuaJVM();
|
||||
try {
|
||||
vm.parse(args);
|
||||
assertEquals(1044, vm.getDebugPort());
|
||||
assertEquals(true, vm.getSuspendOnStart());
|
||||
assertEquals("dummy.lua", vm.getScript());
|
||||
} catch (ParseException e) {
|
||||
fail("Should never reach this line.");
|
||||
}
|
||||
|
||||
args = new String[] { "-DsuspendOnStart=true,port=1044", "dummy.lua" };
|
||||
vm = new StandardLuaJVM();
|
||||
try {
|
||||
vm.parse(args);
|
||||
assertEquals(1044, vm.getDebugPort());
|
||||
assertEquals(true, vm.getSuspendOnStart());
|
||||
assertEquals("dummy.lua", vm.getScript());
|
||||
} catch (ParseException e) {
|
||||
fail("Should never reach this line.");
|
||||
}
|
||||
|
||||
args = new String[] { "-DsuspendOnStart=TRUE,port=1044", "dummy.lua" };
|
||||
vm = new StandardLuaJVM();
|
||||
try {
|
||||
vm.parse(args);
|
||||
assertEquals(1044, vm.getDebugPort());
|
||||
assertEquals(true, vm.getSuspendOnStart());
|
||||
assertEquals("dummy.lua", vm.getScript());
|
||||
} catch (ParseException e) {
|
||||
fail("Should never reach this line.");
|
||||
}
|
||||
|
||||
args = new String[] { "-Dport=1044", "dummy.lua" };
|
||||
vm = new StandardLuaJVM();
|
||||
try {
|
||||
vm.parse(args);
|
||||
assertEquals(1044, vm.getDebugPort());
|
||||
assertEquals(false, vm.getSuspendOnStart());
|
||||
assertEquals("dummy.lua", vm.getScript());
|
||||
} catch (ParseException e) {
|
||||
fail("Should never reach this line.");
|
||||
}
|
||||
}
|
||||
|
||||
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 (int i = 0; i < tests.length; i++) {
|
||||
String test = tests[i];
|
||||
String test = tests[i];
|
||||
System.out.println("==> running test: " + test + ".lua");
|
||||
doTestRun(test + ".lua");
|
||||
doTestRun(test + ".lua");
|
||||
System.out.println("==> running test: " + test + ".luac");
|
||||
doTestRun(test + ".luac");
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void doTestRun(String testName) {
|
||||
String[] args = new String[1];
|
||||
URL filePath = getClass().getResource("/"+ testName);
|
||||
URL filePath = getClass().getResource("/" + testName);
|
||||
if (filePath != null) {
|
||||
args[0] = filePath.getPath();
|
||||
args[0] = filePath.getPath();
|
||||
try {
|
||||
StandardLuaJVM.main(args);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail("Test " + testName + " failed due to " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user