summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Light <allight@google.com>2017-12-01 21:33:41 +0000
committerandroid-build-merger <android-build-merger@google.com>2017-12-01 21:33:41 +0000
commitac9752232883e8957489b1bdc34556b0fcc390e0 (patch)
tree92f5ee71d377486b81a72447d19cae19297c170b
parent86c34cb89426a5b9b65d72ceee9a68ca05d93a13 (diff)
parent2c8474929f3305464ff3da4b5a5da1faee2b42fe (diff)
downloadapache-harmony-ac9752232883e8957489b1bdc34556b0fcc390e0.tar.gz
Merge "Add jdwp tests for VMDebug debugger functions" am: 523cf0c72a
am: 2c8474929f Change-Id: Ia0c3569b4b65847b36fd616e1892c6b41bebad70
-rw-r--r--jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/VMDebug/VMDebugDebuggee.java119
-rw-r--r--jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/VMDebug/VMDebugTest.java73
-rw-r--r--jdwp/src/test/java/org/apache/harmony/jpda/tests/share/AllTests.java1
3 files changed, 193 insertions, 0 deletions
diff --git a/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/VMDebug/VMDebugDebuggee.java b/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/VMDebug/VMDebugDebuggee.java
new file mode 100644
index 0000000..36ded06
--- /dev/null
+++ b/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/VMDebug/VMDebugDebuggee.java
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+package org.apache.harmony.jpda.tests.jdwp.VMDebug;
+
+import java.lang.reflect.Method;
+import java.io.*;
+import java.util.*;
+import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
+import org.apache.harmony.jpda.tests.share.SyncDebuggee;
+
+/**
+ * This class provides a test for VMDebug functions.
+ */
+public class VMDebugDebuggee extends SyncDebuggee {
+
+ public static final class DebugResult implements Serializable {
+ public boolean error_occured = false;
+ public boolean is_debugger_connected = false;
+ public boolean is_debugging_enabled = false;
+ public long last_debugger_activity = -1;
+
+ public DebugResult(boolean is_error, boolean is_debugger_connected, boolean is_debugger_enabled, long last_debugger_activity) {
+ this.error_occured = is_error;
+ this.is_debugger_connected = is_debugger_connected;
+ this.is_debugging_enabled = is_debugger_enabled;
+ this.last_debugger_activity = last_debugger_activity;
+ }
+
+ @Override
+ public String toString() {
+ return "DebugResult { error: " + error_occured
+ + ", connected: " + is_debugger_connected
+ + ", enabled: " + is_debugging_enabled
+ + ", last_activity: " + last_debugger_activity + " }";
+ }
+ }
+
+ private void SendResult(boolean is_error, boolean is_debugger_connected, boolean is_debugger_enabled, long last_debugger_activity) {
+ ByteArrayOutputStream bs = new ByteArrayOutputStream();
+ try {
+ ObjectOutputStream st = new ObjectOutputStream(bs);
+ st.writeObject(new DebugResult(is_error, is_debugger_connected, is_debugger_enabled, last_debugger_activity));
+ st.flush();
+ } catch (Exception e) {
+ logWriter.println("Failed to serialize debug result!");
+ }
+ synchronizer.sendMessage(Base64.getEncoder().encodeToString(bs.toByteArray()));
+ }
+
+ public static DebugResult ReadResult(String args) throws IllegalArgumentException {
+ try {
+ ByteArrayInputStream bs = new ByteArrayInputStream(Base64.getDecoder().decode(args));
+ ObjectInputStream ois = new ObjectInputStream(bs);
+ return (DebugResult) ois.readObject();
+ } catch (Exception e) {
+ return null;
+ }
+ }
+
+ @Override
+ public void run() {
+ // Tell the test we have started.
+ synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_READY);
+ // The debugger will have done something before sending this so the last activity is reset.
+ synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
+
+ boolean error_occured = false;
+ boolean is_debugger_connected = false;
+ boolean is_debugging_enabled = false;
+ long last_debugger_activity = -1;
+ try {
+ // Wait 100 milliseconds so that last_debugger_activity will be non-zero and definitely
+ // more than 10.
+ Thread.sleep(100);
+
+ Class<?> vmdebug = Class.forName("dalvik.system.VMDebug");
+ Method isDebuggerConnectedMethod = vmdebug.getDeclaredMethod("isDebuggerConnected");
+ Method isDebuggingEnabledMethod = vmdebug.getDeclaredMethod("isDebuggingEnabled");
+ Method lastDebuggerActivityMethod = vmdebug.getDeclaredMethod("lastDebuggerActivity");
+
+ is_debugger_connected = (boolean)isDebuggerConnectedMethod.invoke(null);
+ is_debugging_enabled = (boolean)isDebuggingEnabledMethod.invoke(null);
+ last_debugger_activity = (long)lastDebuggerActivityMethod.invoke(null);
+ } catch (NoSuchMethodException e) {
+ error_occured = true;
+ logWriter.println("Unable to find one of the VMDebug methods!" + e);
+ } catch (ClassNotFoundException e) {
+ error_occured = true;
+ logWriter.println("Could not find VMDebug");
+ } catch (Exception e) {
+ error_occured = true;
+ logWriter.println("Other exception occured " + e);
+ }
+ SendResult(
+ error_occured, is_debugger_connected, is_debugging_enabled, last_debugger_activity);
+ synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
+ }
+
+ public static void main(String [] args) {
+ runDebuggee(VMDebugDebuggee.class);
+ }
+}
+
diff --git a/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/VMDebug/VMDebugTest.java b/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/VMDebug/VMDebugTest.java
new file mode 100644
index 0000000..de10beb
--- /dev/null
+++ b/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/VMDebug/VMDebugTest.java
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+package org.apache.harmony.jpda.tests.jdwp.VMDebug;
+
+import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket;
+import org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands;
+import org.apache.harmony.jpda.tests.framework.jdwp.JDWPConstants;
+import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket;
+import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase;
+import org.apache.harmony.jpda.tests.jdwp.share.JDWPTestConstants;
+import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
+
+/**
+ * JDWP Unit test for VMDebug functions command
+ */
+public class VMDebugTest extends JDWPSyncTestCase {
+ @Override
+ protected String getDebuggeeClassName() {
+ return "org.apache.harmony.jpda.tests.jdwp.VMDebug.VMDebugDebuggee";
+ }
+
+ private void SendDebuggerActivity() {
+ logWriter.println("Sending invalid command to ensure there is recent debugger activity!");
+ long stringID = JDWPTestConstants.INVALID_OBJECT_ID;
+ int expectedError = JDWPConstants.Error.INVALID_OBJECT;
+ logWriter.println("Send StringReference.Value command with id " + stringID);
+
+ CommandPacket packet = new CommandPacket(
+ JDWPCommands.StringReferenceCommandSet.CommandSetID,
+ JDWPCommands.StringReferenceCommandSet.ValueCommand);
+ packet.setNextValueAsObjectID(stringID);
+ ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(packet);
+
+ checkReplyPacket(reply, "StringReference::Value command", expectedError);
+ }
+
+ public void testVMDebug() {
+ synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
+ // Do something that resets the debugger activity count.
+ SendDebuggerActivity();
+ synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
+ // Get the results.
+ VMDebugDebuggee.DebugResult res = VMDebugDebuggee.ReadResult(synchronizer.receiveMessage());
+ if (res == null) {
+ fail("unable to deserialize result data");
+ } else {
+ logWriter.println("Recieved results: " + res);
+ assertFalse("no error expected", res.error_occured);
+ assertTrue("expected active debugger!", res.is_debugging_enabled);
+ assertTrue("expected active debugger connection!", res.is_debugger_connected);
+ if (10 > res.last_debugger_activity) {
+ fail("Expected last debugger activity to be greater then 10, was " + res.last_debugger_activity);
+ }
+ }
+ synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
+ }
+}
diff --git a/jdwp/src/test/java/org/apache/harmony/jpda/tests/share/AllTests.java b/jdwp/src/test/java/org/apache/harmony/jpda/tests/share/AllTests.java
index 1cae40f..7cbb1c1 100644
--- a/jdwp/src/test/java/org/apache/harmony/jpda/tests/share/AllTests.java
+++ b/jdwp/src/test/java/org/apache/harmony/jpda/tests/share/AllTests.java
@@ -244,6 +244,7 @@ public class AllTests {
suite.addTestSuite(org.apache.harmony.jpda.tests.jdwp.VirtualMachine.TopLevelThreadGroupsTest.class);
suite.addTestSuite(org.apache.harmony.jpda.tests.jdwp.VirtualMachine.VersionTest.class);
addOptionalTestSuite(suite, "org.apache.harmony.jpda.tests.jdwp.DDM.DDMTest");
+ suite.addTestSuite(org.apache.harmony.jpda.tests.jdwp.VMDebug.VMDebugTest.class);
return suite;
}
}