You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by ge...@apache.org on 2006/11/28 18:49:31 UTC
svn commit: r480141 [38/38] - in
/harmony/enhanced/jdktools/trunk/modules/jpda: ./ doc/ doc/images/ make/
src/ src/common/ src/common/other/ src/common/other/jpda/
src/common/other/jpda/jdwp/ src/common/other/jpda/jdwp/agent/
src/common/other/jpda/jdwp...
Added: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/share/JDWPUnitDebuggeeWrapper.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/share/JDWPUnitDebuggeeWrapper.java?view=auto&rev=480141
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/share/JDWPUnitDebuggeeWrapper.java (added)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/share/JDWPUnitDebuggeeWrapper.java Tue Nov 28 09:49:08 2006
@@ -0,0 +1,279 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * 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.
+ */
+
+/**
+ * @author Vitaly A. Provodin
+ * @version $Revision: 1.4 $
+ */
+
+/**
+ * Created on 29.01.2005
+ */
+package org.apache.harmony.jpda.tests.jdwp.share;
+
+import java.io.IOException;
+
+import org.apache.harmony.jpda.tests.framework.LogWriter;
+import org.apache.harmony.jpda.tests.framework.StreamRedirector;
+import org.apache.harmony.jpda.tests.framework.TestErrorException;
+import org.apache.harmony.jpda.tests.framework.jdwp.JDWPDebuggeeWrapper;
+import org.apache.harmony.jpda.tests.framework.jdwp.TransportWrapper;
+import org.apache.harmony.jpda.tests.share.JPDATestOptions;
+
+/**
+ * This class provides DebuggeeWrapper implementation based on JUnit framework.
+ * Debuggee is always launched on local machine and attaches to debugger.
+ */
+public class JDWPUnitDebuggeeWrapper extends JDWPDebuggeeWrapper {
+
+ /**
+ * Target VM debuggee process.
+ */
+ public Process process;
+
+ /**
+ * Auxiliary options passed to the target VM on its launch.
+ */
+ public String savedVMOptions = null;
+
+ StreamRedirector errRedir;
+
+ StreamRedirector outRedir;
+
+ TransportWrapper transport;
+
+ /**
+ * Creates new instance with given data.
+ *
+ * @param settings
+ * test run options
+ * @param logWriter
+ * where to print log messages
+ */
+ public JDWPUnitDebuggeeWrapper(JPDATestOptions settings, LogWriter logWriter) {
+ super(settings, logWriter);
+ }
+
+ /**
+ * Launches new debuggee process according to test run options and
+ * establishes JDWP connection.
+ */
+ public void start() {
+ boolean isListenConnection = settings.isListenConnectorKind();
+ transport = createTransportWrapper();
+ String address = settings.getTransportAddress();
+
+ if (isListenConnection) {
+ try {
+ address = transport.startListening(address);
+ } catch (IOException e) {
+ throw new TestErrorException(e);
+ }
+ logWriter.println("Listening on: " + address);
+ } else {
+ logWriter.println("Attach to: " + address);
+ }
+
+ String cmdLine = settings.getDebuggeeJavaPath() + " -cp "
+ + settings.getDebuggeeClassPath() + " -agentlib:"
+ + settings.getDebuggeeAgentName() + "="
+ + settings.getDebuggeeAgentOptions(address, isListenConnection)
+ + " " + settings.getDebuggeeVMExtraOptions() + " "
+ + (savedVMOptions != null ? savedVMOptions : "") + " "
+ + settings.getDebuggeeClassName();
+
+ logWriter.println("Launch: " + cmdLine);
+
+ try {
+ process = launchProcess(cmdLine);
+ if (process != null) {
+ logWriter.println("Start redirectors");
+ errRedir = new StreamRedirector(process.getErrorStream(),
+ logWriter, "STDERR");
+ errRedir.start();
+ outRedir = new StreamRedirector(process.getInputStream(),
+ logWriter, "STDOUT");
+ outRedir.start();
+ }
+ openConnection();
+
+ logWriter.println("Established connection");
+
+ } catch (Exception e) {
+ throw new TestErrorException(e);
+ }
+ }
+
+ /**
+ * Closes all connections, stops redirectors, and waits for debuggee process
+ * exit for default timeout.
+ */
+ public void stop() {
+ disposeConnection();
+
+ if (process != null) {
+ logWriter.println("Waiting for debuggee exit");
+ try {
+ WaitForProcessExit(process);
+ } catch (IOException e) {
+ logWriter.println("IOException in stopping process: " + e);
+ }
+
+ logWriter.println("Waiting for redirectors");
+ if (outRedir != null) {
+ outRedir.exit();
+ try {
+ outRedir.join(settings.getTimeout());
+ } catch (InterruptedException e) {
+ logWriter
+ .println("InterruptedException in stopping outRedirector: "
+ + e);
+ }
+ }
+ if (errRedir != null) {
+ errRedir.exit();
+ try {
+ errRedir.join(settings.getTimeout());
+ } catch (InterruptedException e) {
+ logWriter
+ .println("InterruptedException in stopping errRedirector: "
+ + e);
+ }
+ }
+ }
+
+ closeConnection();
+ if (settings.isListenConnectorKind()) {
+ try {
+ transport.stopListening();
+ } catch (IOException e) {
+ logWriter
+ .println("IOException in stopping transport listening: "
+ + e);
+ }
+ }
+ }
+
+ /**
+ * Launches process with given command line.
+ *
+ * @param cmdLine
+ * command line
+ * @return associated Process object or null if not available
+ * @throws IOException
+ * if error occurred in launching process
+ */
+ protected Process launchProcess(String cmdLine) throws IOException {
+ process = Runtime.getRuntime().exec(cmdLine);
+ return process;
+ }
+
+ /**
+ * Waits for launched process to exit.
+ *
+ * @param process
+ * associated Process object or null if not available
+ * @throws IOException
+ * if any exception occurs in waiting
+ */
+ protected void WaitForProcessExit(Process process) throws IOException {
+ ProcessWaiter thrd = new ProcessWaiter();
+ thrd.start();
+ try {
+ thrd.join(settings.getTimeout());
+ } catch (InterruptedException e) {
+ throw new TestErrorException(e);
+ }
+
+ if (thrd.isAlive()) {
+ thrd.interrupt();
+ }
+
+ try {
+ int exitCode = process.exitValue();
+ logWriter.println("Finished debuggee with exit code: " + exitCode);
+ } catch (IllegalThreadStateException e) {
+ logWriter.printError("Enforced debuggee termination");
+ }
+ process.destroy();
+ }
+
+ /**
+ * Opens connection with debuggee.
+ */
+ protected void openConnection() {
+ try {
+ if (settings.isListenConnectorKind()) {
+ logWriter.println("Accepting JDWP connection");
+ transport.accept(settings.getTimeout(), settings.getTimeout());
+ } else {
+ String address = settings.getTransportAddress();
+ logWriter.println("Attaching for JDWP connection");
+ transport.attach(address, settings.getTimeout(), settings
+ .getTimeout());
+ }
+ setConnection(transport);
+ } catch (IOException e) {
+ logWriter.printError(e);
+ throw new TestErrorException(e);
+ }
+ }
+
+ /**
+ * Disposes JDWP connection stored in VmMirror.
+ */
+ protected void disposeConnection() {
+ if (vmMirror != null) {
+ try {
+ vmMirror.dispose();
+ } catch (Exception e) {
+ logWriter
+ .println("Ignoring exception in disposing debuggee VM: "
+ + e);
+ }
+ }
+ }
+
+ /**
+ * Closes JDWP connection stored in VmMirror.
+ */
+ protected void closeConnection() {
+ if (vmMirror != null) {
+ try {
+ vmMirror.closeConnection();
+ } catch (IOException e) {
+ logWriter.println("Ignoring exception in closing connection: "
+ + e);
+ }
+ }
+ }
+
+ /**
+ * Separate thread for waiting for process exit for specified timeout.
+ */
+ class ProcessWaiter extends Thread {
+ public void run() {
+ try {
+ process.waitFor();
+ } catch (InterruptedException e) {
+ logWriter
+ .println("Ignoring exception in ProcessWaiter thread interrupted: "
+ + e);
+ }
+ }
+ }
+}
Propchange: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/share/JDWPUnitDebuggeeWrapper.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/share/debuggee/HelloWorld.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/share/debuggee/HelloWorld.java?view=auto&rev=480141
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/share/debuggee/HelloWorld.java (added)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/share/debuggee/HelloWorld.java Tue Nov 28 09:49:08 2006
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * 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.
+ */
+
+/**
+ * @author Vitaly A. Provodin
+ * @version $Revision: 1.3 $
+ */
+
+/**
+ * Created on 31.01.2005
+ */
+package org.apache.harmony.jpda.tests.jdwp.share.debuggee;
+
+import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
+import org.apache.harmony.jpda.tests.share.SyncDebuggee;
+
+/**
+ * This class provides simple HelloWorld debuggee class used sync connection.
+ */
+public class HelloWorld extends SyncDebuggee {
+
+ public void run() {
+ synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_READY);
+ logWriter.println("Hello World");
+ synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
+ }
+
+ public static void main(String [] args) {
+ runDebuggee(HelloWorld.class);
+ }
+}
\ No newline at end of file
Propchange: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/share/debuggee/HelloWorld.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/share/debuggee/InvokeMethodDebuggee.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/share/debuggee/InvokeMethodDebuggee.java?view=auto&rev=480141
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/share/debuggee/InvokeMethodDebuggee.java (added)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/share/debuggee/InvokeMethodDebuggee.java Tue Nov 28 09:49:08 2006
@@ -0,0 +1,132 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * 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.
+ */
+
+/**
+ * @author Vitaly A. Provodin
+ * @version $Revision: 1.4 $
+ */
+
+/**
+ * Created on 10.03.2005
+ */
+package org.apache.harmony.jpda.tests.jdwp.share.debuggee;
+
+import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
+import org.apache.harmony.jpda.tests.share.SyncDebuggee;
+
+/**
+ * This class provides common debuggee class for InvokeMethod tests.
+ *
+ */
+public class InvokeMethodDebuggee extends SyncDebuggee {
+
+ public class testClass1 {
+ public testClass1() {
+ logWriter.println("constructor testClass1 invoked");
+ }
+ }
+
+ public int testMethod1(boolean needThrow) throws Throwable {
+ logWriter.println("method testClass1 invoked");
+ if (needThrow) {
+ throw new Throwable("test exception");
+ }
+ return 123;
+ }
+
+ public static int testMethod2(boolean needThrow) throws Throwable {
+ if (needThrow) {
+ throw new Throwable("test exception");
+ }
+ return 234;
+ }
+
+ static int checkInt = 1;
+ static int[] checkIntArray = {1, 2};
+ static int[][] checkIntArray2 = {{123}, {23, 34}, {2, 4, 6, 8}};
+ static String checkString = "text 1";
+ static String[] checkStringArray = {"text 2"};
+ static String[][] checkStringArray2 = {{"text 3"}, {"text 4"}};
+ static testClass checkClass = new testClass();
+ static testClass[] checkClassArray = {new testClass()};
+ static testClass[][] checkClassArray2 = {{new testClass()}, {new testClass()}};
+
+ public static String testMethod3(int i, int[] ai, int[][] aai,
+ String s, String[] as, String[][] aas,
+ testClass tc, testClass[] atc, testClass[][] aatc) {
+ return "qwerty";
+ }
+
+ void execMethod() {
+ logWriter.println("InvokeMethodDebuggee.execMethod()");
+ }
+
+ public void run() {
+ Class c = null;
+ try {
+ c = Class.forName("org.apache.harmony.jpda.tests.jdwp.share.debuggee.InvokeMethodDebuggee$testClass1");
+ c = Class.forName("org.apache.harmony.jpda.tests.jdwp.share.debuggee.testClass2");
+ c = Class.forName("org.apache.harmony.jpda.tests.jdwp.share.debuggee.testClass3");
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ }
+ synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_READY);
+ logWriter.println("InvokeMethodDebuggee");
+// synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
+ synchronizer.receiveMessageWithoutException("org.apache.harmony.jpda.tests.jdwp.share.debuggee.InvokeMethodDebuggee(#1)");
+ execMethod();
+// synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
+ synchronizer.receiveMessageWithoutException("org.apache.harmony.jpda.tests.jdwp.share.debuggee.InvokeMethodDebuggee(#2)");
+ logWriter.println("DUMP{" + c + "}");
+ }
+
+ public static void main(String[] args) {
+ runDebuggee(InvokeMethodDebuggee.class);
+ }
+}
+
+class testClass {
+}
+
+class testClass2 {
+ public testClass2(boolean needThrow) throws Throwable {
+ if (needThrow) {
+ throw new Throwable("test exception");
+ }
+ }
+
+ public int testMethod3(boolean needThrow) throws Throwable {
+ if (needThrow) {
+ throw new Throwable("test exception");
+ }
+ return 345;
+ }
+}
+
+class testClass3 extends testClass2 {
+ public testClass3() throws Throwable {
+ super(false);
+ }
+
+ public int testMethod3(boolean needThrow) throws Throwable {
+ if (needThrow) {
+ throw new Throwable("test exception");
+ }
+ return 456;
+ }
+}
+
Propchange: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/share/debuggee/InvokeMethodDebuggee.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/share/debuggee/SimpleHelloWorld.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/share/debuggee/SimpleHelloWorld.java?view=auto&rev=480141
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/share/debuggee/SimpleHelloWorld.java (added)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/share/debuggee/SimpleHelloWorld.java Tue Nov 28 09:49:08 2006
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * 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.
+ */
+
+/**
+ * @author Vitaly A. Provodin
+ * @version $Revision: 1.3 $
+ */
+
+/**
+ * Created on 31.01.2005
+ */
+package org.apache.harmony.jpda.tests.jdwp.share.debuggee;
+
+import org.apache.harmony.jpda.tests.share.Debuggee;
+
+/**
+ * This class provides simple HelloWorld debuggee class.
+ */
+public class SimpleHelloWorld extends Debuggee {
+
+ public void run() {
+ logWriter.println("Hello World");
+ }
+
+ public static void main(String [] args) {
+ runDebuggee(SimpleHelloWorld.class);
+ }
+}
Propchange: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/jdwp/share/debuggee/SimpleHelloWorld.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/share/Debuggee.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/share/Debuggee.java?view=auto&rev=480141
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/share/Debuggee.java (added)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/share/Debuggee.java Tue Nov 28 09:49:08 2006
@@ -0,0 +1,91 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * 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.
+ */
+
+/**
+ * @author Vitaly A. Provodin
+ * @version $Revision: 1.5 $
+ */
+
+/**
+ * Created on 31.01.2005
+ */
+package org.apache.harmony.jpda.tests.share;
+
+import org.apache.harmony.jpda.tests.framework.LogWriter;
+import org.apache.harmony.jpda.tests.framework.TestErrorException;
+
+/**
+ * All debuggee of unit tests must extend this class
+ */
+public abstract class Debuggee {
+
+ /**
+ * Instance of LogWriter implementation.
+ */
+ public LogWriter logWriter;
+
+ /**
+ * Instance of JPDA options used in all JPDA/JDWP tests.
+ */
+ public JPDATestOptions settings;
+
+ /**
+ * Executes main actions of debuggee. This method must be implemented by
+ * subclasses.
+ */
+ public abstract void run();
+
+ /**
+ * Initializes debuggee
+ */
+ public void onStart() {
+ settings = new JPDATestOptions();
+ logWriter = new JPDALogWriter(System.out, null, settings.isVerbose());
+ }
+
+ /**
+ * Executes final stage of debuggee.
+ */
+ public void onFinish() {
+ }
+
+ /**
+ * Starts debuggee specified by <code>debuggeeClass</code>.
+ *
+ * @param debuggeeClass
+ * debuggee's class
+ */
+ public static void runDebuggee(Class debuggeeClass) {
+ Debuggee debuggee = null;
+ try {
+ debuggee = (Debuggee) debuggeeClass.newInstance();
+ } catch (Exception e) {
+ throw new TestErrorException("Debuggee can not be started: "
+ + debuggeeClass.getName(), e);
+ }
+
+ debuggee.onStart();
+
+ try {
+ debuggee.run();
+ } catch (Throwable e) {
+ debuggee.logWriter.printError(e);
+ } finally {
+ debuggee.onFinish();
+ }
+ }
+}
Propchange: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/share/Debuggee.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/share/JPDADebuggeeSynchronizer.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/share/JPDADebuggeeSynchronizer.java?view=auto&rev=480141
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/share/JPDADebuggeeSynchronizer.java (added)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/share/JPDADebuggeeSynchronizer.java Tue Nov 28 09:49:08 2006
@@ -0,0 +1,243 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * 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.
+ */
+
+/**
+ * @author Vitaly A. Provodin
+ * @version $Revision: 1.5 $
+ */
+
+/**
+ * Created on 29.01.2005
+ */
+package org.apache.harmony.jpda.tests.share;
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.EOFException;
+import java.io.IOException;
+import java.net.Socket;
+import java.net.ServerSocket;
+
+import org.apache.harmony.jpda.tests.framework.DebuggeeSynchronizer;
+import org.apache.harmony.jpda.tests.framework.LogWriter;
+import org.apache.harmony.jpda.tests.framework.TestErrorException;
+import org.apache.harmony.jpda.tests.framework.TestOptions;
+
+/**
+ * This class implements <code>DebuggeeSynchronizer</code> interface using
+ * TCP/IP sockets. All operations can be timed out according to default timeout.
+ */
+public class JPDADebuggeeSynchronizer implements DebuggeeSynchronizer {
+
+ public final static String SGNL_READY = "ready";
+
+ public final static String SGNL_CONTINUE = "continue";
+
+ private Socket clientSocket = null;
+
+ private ServerSocket serverSocket = null;
+
+ private DataOutputStream out;
+
+ private DataInputStream in;
+
+ private TestOptions settings;
+
+ private LogWriter logWriter;
+
+ /**
+ * A constructor that initializes an instance of the class with specified
+ * <code>LogWriter</code> and <code>TestOptions</code>.
+ *
+ * @param logWriter
+ * The instance of implementation of LogWriter.
+ * @param settings
+ * Instance of test options.
+ */
+ public JPDADebuggeeSynchronizer(LogWriter logWriter, TestOptions settings) {
+ super();
+ this.logWriter = logWriter;
+ this.settings = settings;
+ }
+
+ /**
+ * Sends specified message to synchronization channel.
+ *
+ * @param message
+ * a message to be sent.
+ */
+ public synchronized void sendMessage(String message) {
+ try {
+ out.writeUTF(message);
+ out.flush();
+ logWriter.println("[SYNC] Message sent: " + message);
+ } catch (IOException e) {
+ throw new TestErrorException(e);
+ }
+ }
+
+ /**
+ * Receives message from synchronization channel and compares it with the
+ * expected <code>message</code>.
+ *
+ * @param message
+ * expected message.
+ * @return <code>true</code> if received string is equals to
+ * <code>message</code> otherwise - <code>false</code>.
+ *
+ */
+ public synchronized boolean receiveMessage(String message) {
+ String msg;
+ try {
+ logWriter.println("[SYNC] Waiting for message: " + message);
+ msg = in.readUTF();
+ logWriter.println("[SYNC] Received message: " + msg);
+ } catch (EOFException e) {
+ return false;
+ } catch (IOException e) {
+ logWriter.printError(e);
+ return false;
+ }
+ return message.equalsIgnoreCase(msg);
+ }
+
+ /**
+ * Receives message from synchronization channel.
+ *
+ * @return received string or null if connection was closed.
+ */
+ public synchronized String receiveMessage() {
+ String msg;
+ try {
+ logWriter.println("[SYNC] Waiting...");
+ msg = in.readUTF();
+ logWriter.println("[SYNC] received message: " + msg);
+ } catch (EOFException e) {
+ return null;
+ } catch (IOException e) {
+ throw new TestErrorException(e);
+ }
+ return msg;
+ }
+
+ /**
+ * Receives message from synchronization channel without Exception.
+ *
+ * @return received string
+ */
+ public synchronized String receiveMessageWithoutException(String invoker) {
+ String msg;
+ try {
+ logWriter.println("[SYNC] Waiting...");
+ msg = in.readUTF();
+ logWriter.println("[SYNC] Received message: " + msg);
+ } catch (Throwable thrown) {
+ if (invoker != null) {
+ logWriter
+ .println("#### receiveMessageWithoutException: Exception occurred:");
+ logWriter.println("#### " + thrown);
+ logWriter.println("#### Invoker = " + invoker);
+ }
+ msg = "" + thrown;
+ }
+ return msg;
+ }
+
+ /**
+ * Binds server to listen socket port.
+ *
+ * @return port number
+ */
+ public synchronized int bindServer() {
+ int port = settings.getSyncPortNumber();
+ try {
+ logWriter.println("[SYNC] Binding socket on port: " + port);
+ serverSocket = new ServerSocket(port);
+ port = serverSocket.getLocalPort();
+ logWriter.println("[SYNC] Bound socket on port: " + port);
+ return port;
+ } catch (IOException e) {
+ throw new TestErrorException(
+ "[SYNC] Exception in binding for socket sync connection", e);
+ }
+ }
+
+ /**
+ * Accepts sync connection form server side.
+ */
+ public synchronized void startServer() {
+ long timeout = settings.getTimeout();
+ try {
+ serverSocket.setSoTimeout((int) timeout);
+ logWriter.println("[SYNC] Accepting socket connection");
+ clientSocket = serverSocket.accept();
+ logWriter.println("[SYNC] Accepted socket connection");
+
+ clientSocket.setSoTimeout((int) timeout);
+ out = new DataOutputStream(clientSocket.getOutputStream());
+ in = new DataInputStream(clientSocket.getInputStream());
+ } catch (IOException e) {
+ throw new TestErrorException(
+ "[SYNC] Exception in accepting socket sync connection", e);
+ }
+ }
+
+ /**
+ * Attaches for sync connection from client side..
+ */
+ public synchronized void startClient() {
+ long timeout = settings.getTimeout();
+ String host = "localhost";
+ int port = settings.getSyncPortNumber();
+ try {
+ logWriter.println("[SYNC] Attaching socket to: " + host + ":"
+ + port);
+ clientSocket = new Socket(host, port);
+ logWriter.println("[SYNC] Attached socket");
+
+ clientSocket.setSoTimeout((int) timeout);
+ out = new DataOutputStream(clientSocket.getOutputStream());
+ in = new DataInputStream(clientSocket.getInputStream());
+ } catch (IOException e) {
+ throw new TestErrorException(
+ "[SYNC] Exception in attaching for socket sync connection",
+ e);
+ }
+ }
+
+ /**
+ * Stops synchronization work. It ignores <code>IOException</code> but
+ * prints a message.
+ */
+ public void stop() {
+ try {
+ if (out != null)
+ out.close();
+ if (in != null)
+ in.close();
+ if (clientSocket != null)
+ clientSocket.close();
+ if (serverSocket != null)
+ serverSocket.close();
+ } catch (IOException e) {
+ logWriter
+ .println("[SYNC] Ignoring exception in closing socket sync connection: "
+ + e);
+ }
+ logWriter.println("[SYNC] Closed socket");
+ }
+}
Propchange: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/share/JPDADebuggeeSynchronizer.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/share/JPDALogWriter.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/share/JPDALogWriter.java?view=auto&rev=480141
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/share/JPDALogWriter.java (added)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/share/JPDALogWriter.java Tue Nov 28 09:49:08 2006
@@ -0,0 +1,261 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * 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.
+ */
+
+/**
+ * @author Vitaly A. Provodin
+ * @version $Revision: 1.6 $
+ */
+
+/**
+ * Created on 28.03.2005
+ */
+package org.apache.harmony.jpda.tests.share;
+
+import java.io.PrintStream;
+
+import org.apache.harmony.jpda.tests.framework.LogWriter;
+
+/**
+ * This class provides logging messages to underlying output stream. There are
+ * can be several JPDALogWriter objects writing to the same underlying stream
+ * with different prefixes.
+ */
+public class JPDALogWriter extends LogWriter {
+
+ protected String printPrefix;
+
+ protected String errorMessage;
+
+ protected LogStream logStream;
+
+ public boolean enablePrint = true;
+
+ /**
+ * Constructs an instance of the class for given output stream.
+ *
+ * @param outputStream
+ * stream for output
+ * @param prefix
+ * prefix for messages or null
+ * @param enablePrint
+ * flag for enabling print to log
+ */
+ public JPDALogWriter(PrintStream outputStream, String prefix,
+ boolean enablePrint) {
+ super(prefix);
+ this.enablePrint = enablePrint;
+ logStream = new LogStream(outputStream);
+ }
+
+ /**
+ * Constructs an instance of the class for given output stream.
+ *
+ * @param outputStream
+ * stream for output
+ * @param prefix
+ * prefix for messages or null
+ */
+ public JPDALogWriter(PrintStream outputStream, String prefix) {
+ this(outputStream, prefix, true);
+ }
+
+ /**
+ * Constructs an instance of the class to log to the same output stream.
+ *
+ * @param logWriter
+ * log writer containing stream for output
+ * @param prefix
+ * prefix for messages or null
+ */
+ public JPDALogWriter(JPDALogWriter logWriter, String prefix) {
+ super(prefix);
+ logStream = logWriter.getLogStream();
+ }
+
+ /**
+ * Sets prefix for messages.
+ *
+ * @param prefix
+ * to be set
+ */
+ public void setPrefix(String prefix) {
+ super.setPrefix(prefix);
+ if (prefix == null || prefix.length() <= 0) {
+ printPrefix = "";
+ } else {
+ printPrefix = prefix + "> ";
+ }
+ }
+
+ /**
+ * Prints error message.
+ *
+ * @param message
+ * error message to be printed
+ */
+ public void printError(String message) {
+ if (null == errorMessage) {
+ errorMessage = message;
+ }
+ logStream.println(getErrorPrefix() + message);
+ }
+
+ /**
+ * Prints exception information with explaining message.
+ *
+ * @param message
+ * explaining message to be printed
+ * @param throwable
+ * exception to be printed
+ */
+ public void printError(String message, Throwable throwable) {
+ if (null == errorMessage) {
+ errorMessage = message;
+ }
+ logStream.printStackTrace(getErrorPrefix() + message, throwable);
+ }
+
+ /**
+ * Prints exception information w/o explaining message.
+ *
+ * @param throwable
+ * exception to be printed
+ */
+ public void printError(Throwable throwable) {
+ logStream.printStackTrace(null, throwable);
+ }
+
+ /**
+ * Prints message to the output stream w/o line feed.
+ *
+ * @param message
+ * to be printed
+ */
+ public void print(String message) {
+ if (enablePrint) {
+ logStream.print(printPrefix + message);
+ }
+ }
+
+ /**
+ * Prints message to the output stream with line feed.
+ *
+ * @param message
+ * to be printed
+ */
+ public void println(String message) {
+ if (enablePrint) {
+ logStream.println(printPrefix + message);
+ }
+ }
+
+ /**
+ * Returns saved error message.
+ *
+ * @return message string
+ */
+ public String getErrorMessage() {
+ return errorMessage;
+ }
+
+ // /////////////////////////////////////////////////////////////////////////////
+
+ /**
+ * Get prefix for error messages.
+ */
+ protected String getErrorPrefix() {
+ return "# ERROR: " + printPrefix;
+ }
+
+ /**
+ * Get underlying LogStream object.
+ */
+ protected LogStream getLogStream() {
+ return logStream;
+ }
+
+ /**
+ * Underlying stream with synchronous access.
+ */
+ protected static class LogStream {
+ protected PrintStream outputStream;
+
+ /**
+ * A constructor.
+ *
+ * @param outputStream
+ */
+ public LogStream(PrintStream outputStream) {
+ setOutputStream(outputStream);
+ }
+
+ /**
+ * @return The associated output stream.
+ */
+ public synchronized PrintStream getOutputStream() {
+ return outputStream;
+ }
+
+ /**
+ * Sets new output stream.
+ *
+ * @param outputStream
+ * new output stream
+ */
+ public synchronized void setOutputStream(PrintStream outputStream) {
+ this.outputStream = outputStream;
+ }
+
+ /**
+ * Prints the given message with the newline to the output stream.
+ *
+ * @param message
+ * log message
+ */
+ public synchronized void println(String message) {
+ outputStream.println(message);
+ }
+
+ /**
+ * Prints the given message to the output stream.
+ *
+ * @param message
+ * log message
+ */
+ public synchronized void print(String message) {
+ outputStream.print(message);
+ outputStream.flush();
+ }
+
+ /**
+ * Prints the given message and the call stack of the exception to the
+ * output stream.
+ *
+ * @param message
+ * log message
+ * @param throwable
+ * exception
+ */
+ public synchronized void printStackTrace(String message,
+ Throwable throwable) {
+ if (message != null) {
+ println(message);
+ }
+ throwable.printStackTrace(outputStream);
+ }
+ }
+}
Propchange: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/share/JPDALogWriter.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/share/JPDATestOptions.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/share/JPDATestOptions.java?view=auto&rev=480141
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/share/JPDATestOptions.java (added)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/share/JPDATestOptions.java Tue Nov 28 09:49:08 2006
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * 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.
+ */
+
+/**
+ * @author Vitaly A. Provodin
+ * @version $Revision: 1.2 $
+ */
+
+/**
+ * Created on 31.01.2005
+ */
+package org.apache.harmony.jpda.tests.share;
+
+import org.apache.harmony.jpda.tests.framework.TestOptions;
+
+/**
+ * This class provides additional options for unit tests.
+ * <p>
+ * Currently the following additional options are supported:
+ * <ul>
+ * <li><i>jpda.settings.debuggeeLaunchKind=auto|manual</i> - enables
+ * manual launching of debuggee VM for debugging purpose.
+ * </ul>
+ *
+ */
+public class JPDATestOptions extends TestOptions {
+
+ /**
+ * Returns kind of launching debuggee VM, which can be "auto" or "manual".
+ *
+ * @return option "jpda.settings.debuggeeLaunchKind" or "auto" by default.
+ */
+ public String getDebuggeeLaunchKind() {
+ return System.getProperty("jpda.settings.debuggeeLaunchKind", "auto");
+ }
+
+}
Propchange: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/share/JPDATestOptions.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/share/SyncDebuggee.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/share/SyncDebuggee.java?view=auto&rev=480141
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/share/SyncDebuggee.java (added)
+++ harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/share/SyncDebuggee.java Tue Nov 28 09:49:08 2006
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * 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.
+ */
+
+/**
+ * @author Vitaly A. Provodin
+ * @version $Revision: 1.4 $
+ */
+
+/**
+ * Created on 31.01.2005
+ */
+package org.apache.harmony.jpda.tests.share;
+
+/**
+ * The class extends <code>Debuggee</code> and adds usage of the
+ * synchronization channel implemented by <code>JPDADebuggeeSynchronizer</code>.
+ */
+public abstract class SyncDebuggee extends Debuggee {
+
+ /**
+ * An instance of JPDA debugger-debuggee synchronizer.
+ */
+ public JPDADebuggeeSynchronizer synchronizer;
+
+ /**
+ * Initializes the synchronization channel.
+ */
+ public void onStart() {
+ super.onStart();
+ synchronizer = new JPDADebuggeeSynchronizer(logWriter, settings);
+ synchronizer.startClient();
+ }
+
+ /**
+ * Terminates the synchronization channel.
+ */
+ public void onFinish() {
+ if (synchronizer != null) {
+ synchronizer.stop();
+ }
+ super.onFinish();
+ }
+}
Propchange: harmony/enhanced/jdktools/trunk/modules/jpda/test/common/unit/org/apache/harmony/jpda/tests/share/SyncDebuggee.java
------------------------------------------------------------------------------
svn:eol-style = native