From 898bfbd865496855c3a6c792f9e0da011ae34854 Mon Sep 17 00:00:00 2001 From: Steve Block Date: Tue, 28 Sep 2010 13:48:44 +0100 Subject: Prevent DumpRenderTree2 from crashing when the host server is not running Bug: 3010758 Change-Id: I04a01634544d223d225b264827d3cf18be74e1e0 --- .../dumprendertree2/forwarder/AdbUtils.java | 15 ++++-------- .../forwarder/ConnectionHandler.java | 13 +++++------ .../dumprendertree2/forwarder/Forwarder.java | 27 ++++++++++++---------- 3 files changed, 26 insertions(+), 29 deletions(-) (limited to 'tests/DumpRenderTree2') diff --git a/tests/DumpRenderTree2/src/com/android/dumprendertree2/forwarder/AdbUtils.java b/tests/DumpRenderTree2/src/com/android/dumprendertree2/forwarder/AdbUtils.java index 086ff59..224509d 100644 --- a/tests/DumpRenderTree2/src/com/android/dumprendertree2/forwarder/AdbUtils.java +++ b/tests/DumpRenderTree2/src/com/android/dumprendertree2/forwarder/AdbUtils.java @@ -40,15 +40,10 @@ public class AdbUtils { * remote machine. This can be achieved by calling configureSocket() * * @return a socket that can be configured to link to remote machine + * @throws IOException */ - public static Socket createSocket() { - Socket socket = null; - try { - socket = new Socket(ADB_HOST, ADB_PORT); - } catch (IOException e) { - Log.e(LOG_TAG, "Creation failed.", e); - } - return socket; + public static Socket createSocket() throws IOException{ + return new Socket(ADB_HOST, ADB_PORT); } /** @@ -72,9 +67,9 @@ public class AdbUtils { outputStream.write(cmd.getBytes()); int read = inputStream.read(buf); if (read != ADB_RESPONSE_SIZE || !ADB_OK.equals(new String(buf))) { - Log.w(LOG_TAG, "adb cmd faild."); + Log.w(LOG_TAG, "adb cmd failed."); return false; } return true; } -} \ No newline at end of file +} diff --git a/tests/DumpRenderTree2/src/com/android/dumprendertree2/forwarder/ConnectionHandler.java b/tests/DumpRenderTree2/src/com/android/dumprendertree2/forwarder/ConnectionHandler.java index 4f01dae..f19cd41 100644 --- a/tests/DumpRenderTree2/src/com/android/dumprendertree2/forwarder/ConnectionHandler.java +++ b/tests/DumpRenderTree2/src/com/android/dumprendertree2/forwarder/ConnectionHandler.java @@ -93,7 +93,8 @@ public class ConnectionHandler { private OnFinishedCallback mOnFinishedCallback; - public ConnectionHandler(String remoteMachineIp, int port, Socket fromSocket, Socket toSocket) { + public ConnectionHandler(String remoteMachineIp, int port, Socket fromSocket, Socket toSocket) + throws IOException { mRemoteMachineIpAddress = remoteMachineIp; mPort = port; @@ -105,14 +106,12 @@ public class ConnectionHandler { mToSocketInputStream = mToSocket.getInputStream(); mFromSocketOutputStream = mFromSocket.getOutputStream(); mToSocketOutputStream = mToSocket.getOutputStream(); - if (!AdbUtils.configureConnection(mToSocketInputStream, mToSocketOutputStream, - mRemoteMachineIpAddress, mPort)) { - throw new IOException("Configuring socket failed!"); - } + AdbUtils.configureConnection(mToSocketInputStream, mToSocketOutputStream, + mRemoteMachineIpAddress, mPort); } catch (IOException e) { Log.e(LOG_TAG, "Unable to start ConnectionHandler", e); closeStreams(); - return; + throw e; } mFromToPipe = new SocketPipeThread(mFromSocketInputStream, mToSocketOutputStream); @@ -170,4 +169,4 @@ public class ConnectionHandler { } } } -} \ No newline at end of file +} diff --git a/tests/DumpRenderTree2/src/com/android/dumprendertree2/forwarder/Forwarder.java b/tests/DumpRenderTree2/src/com/android/dumprendertree2/forwarder/Forwarder.java index b361a89..ce22fa0 100644 --- a/tests/DumpRenderTree2/src/com/android/dumprendertree2/forwarder/Forwarder.java +++ b/tests/DumpRenderTree2/src/com/android/dumprendertree2/forwarder/Forwarder.java @@ -61,7 +61,6 @@ public class Forwarder extends Thread { public void run() { while (true) { Socket localSocket; - Socket remoteSocket; try { localSocket = mServerSocket.accept(); } catch (IOException e) { @@ -70,24 +69,28 @@ public class Forwarder extends Thread { break; } - remoteSocket = AdbUtils.createSocket(); - - if (remoteSocket == null) { + Socket remoteSocket = null; + final ConnectionHandler connectionHandler; + try { + remoteSocket = AdbUtils.createSocket(); + connectionHandler = new ConnectionHandler( + mRemoteMachineIpAddress, mPort, localSocket, remoteSocket); + } catch (IOException exception) { try { localSocket.close(); } catch (IOException e) { Log.e(LOG_TAG, "mPort=" + mPort, e); } - - Log.e(LOG_TAG, "run(): mPort= " + mPort + " Failed to start forwarding from " + - localSocket); + if (remoteSocket != null) { + try { + remoteSocket.close(); + } catch (IOException e) { + Log.e(LOG_TAG, "mPort=" + mPort, e); + } + } continue; } - final ConnectionHandler connectionHandler = - new ConnectionHandler(mRemoteMachineIpAddress, mPort, localSocket, - remoteSocket); - /** * We have to close the sockets after the ConnectionHandler finishes, so we * don't get "Too may open files" exception. We also remove the ConnectionHandler @@ -126,4 +129,4 @@ public class Forwarder extends Thread { Log.e(LOG_TAG, "mPort=" + mPort, e); } } -} \ No newline at end of file +} -- cgit v1.1 From cb98a3e621b7c56d1367a1bf77cd91dae3feb6da Mon Sep 17 00:00:00 2001 From: Steve Block Date: Tue, 28 Sep 2010 12:13:40 +0100 Subject: Provide a useful message in DumpRenderTree2 GUI when the host server is not running Bug: 3010758 Change-Id: Ic62f60d96055e7ad1e475215ca384306cdfa859c --- .../src/com/android/dumprendertree2/FsUtils.java | 7 ++- .../dumprendertree2/TestsListPreloaderThread.java | 53 ++++++++++++---------- .../dumprendertree2/ui/DirListActivity.java | 29 +++++++++--- 3 files changed, 54 insertions(+), 35 deletions(-) (limited to 'tests/DumpRenderTree2') diff --git a/tests/DumpRenderTree2/src/com/android/dumprendertree2/FsUtils.java b/tests/DumpRenderTree2/src/com/android/dumprendertree2/FsUtils.java index 4438811..4f9a737 100644 --- a/tests/DumpRenderTree2/src/com/android/dumprendertree2/FsUtils.java +++ b/tests/DumpRenderTree2/src/com/android/dumprendertree2/FsUtils.java @@ -223,10 +223,9 @@ public class FsUtils { try { return getHttpClient().execute(httpRequest, handler); } catch (IOException e) { - Log.e(LOG_TAG, "url=" + url, e); + Log.e(LOG_TAG, "getLayoutTestsDirContents(): HTTP GET failed for URL " + url); + return null; } - - return new LinkedList(); } public static void closeInputStream(InputStream inputStream) { @@ -248,4 +247,4 @@ public class FsUtils { Log.e(LOG_TAG, "Couldn't close stream!", e); } } -} \ No newline at end of file +} diff --git a/tests/DumpRenderTree2/src/com/android/dumprendertree2/TestsListPreloaderThread.java b/tests/DumpRenderTree2/src/com/android/dumprendertree2/TestsListPreloaderThread.java index e0f1450..0e7d47a 100644 --- a/tests/DumpRenderTree2/src/com/android/dumprendertree2/TestsListPreloaderThread.java +++ b/tests/DumpRenderTree2/src/com/android/dumprendertree2/TestsListPreloaderThread.java @@ -21,6 +21,7 @@ import android.os.Message; import java.io.File; import java.util.ArrayList; import java.util.LinkedList; +import java.util.List; /** * A Thread that is responsible for generating a lists of tests to run. @@ -35,7 +36,7 @@ public class TestsListPreloaderThread extends Thread { private FileFilter mFileFilter; /** - * A relative path to the folder with the tests we want to run or particular test. + * A relative path to the directory with the tests we want to run or particular test. * Used up to and including preloadTests(). */ private String mRelativePath; @@ -67,40 +68,44 @@ public class TestsListPreloaderThread extends Thread { } /** - * Loads all the tests from the given folders and all the subfolders + * Loads all the tests from the given directories and all the subdirectories * into mTestsList. * * @param dirRelativePath */ - private void loadTestsFromUrl(String dirRelativePath) { - LinkedList foldersList = new LinkedList(); - foldersList.add(dirRelativePath); + private void loadTestsFromUrl(String rootRelativePath) { + LinkedList directoriesList = new LinkedList(); + directoriesList.add(rootRelativePath); String relativePath; String itemName; - while (!foldersList.isEmpty()) { - relativePath = foldersList.removeFirst(); + while (!directoriesList.isEmpty()) { + relativePath = directoriesList.removeFirst(); - for (String folderRelativePath : FsUtils.getLayoutTestsDirContents(relativePath, - false, true)) { - itemName = new File(folderRelativePath).getName(); - if (FileFilter.isTestDir(itemName)) { - foldersList.add(folderRelativePath); + List dirRelativePaths = FsUtils.getLayoutTestsDirContents(relativePath, false, true); + if (dirRelativePaths != null) { + for (String dirRelativePath : dirRelativePaths) { + itemName = new File(dirRelativePath).getName(); + if (FileFilter.isTestDir(itemName)) { + directoriesList.add(dirRelativePath); + } } } - for (String testRelativePath : FsUtils.getLayoutTestsDirContents(relativePath, - false, false)) { - itemName = new File(testRelativePath).getName(); - if (FileFilter.isTestFile(itemName)) { - /** We chose to skip all the tests that are expected to crash. */ - if (!mFileFilter.isCrash(testRelativePath)) { - mTestsList.add(testRelativePath); - } else { - /** - * TODO: Summarizer is now in service - figure out how to send the info. - * Previously: mSummarizer.addSkippedTest(relativePath); - */ + List testRelativePaths = FsUtils.getLayoutTestsDirContents(relativePath, false, false); + if (testRelativePaths != null) { + for (String testRelativePath : testRelativePaths) { + itemName = new File(testRelativePath).getName(); + if (FileFilter.isTestFile(itemName)) { + /** We choose to skip all the tests that are expected to crash. */ + if (!mFileFilter.isCrash(testRelativePath)) { + mTestsList.add(testRelativePath); + } else { + /** + * TODO: Summarizer is now in service - figure out how to send the info. + * Previously: mSummarizer.addSkippedTest(relativePath); + */ + } } } } diff --git a/tests/DumpRenderTree2/src/com/android/dumprendertree2/ui/DirListActivity.java b/tests/DumpRenderTree2/src/com/android/dumprendertree2/ui/DirListActivity.java index 35de88a..5de69a7 100644 --- a/tests/DumpRenderTree2/src/com/android/dumprendertree2/ui/DirListActivity.java +++ b/tests/DumpRenderTree2/src/com/android/dumprendertree2/ui/DirListActivity.java @@ -45,6 +45,7 @@ import android.widget.ArrayAdapter; import android.widget.ImageView; import android.widget.ListView; import android.widget.TextView; +import android.widget.Toast; import java.io.File; import java.util.ArrayList; @@ -69,6 +70,9 @@ public class DirListActivity extends ListActivity { private static final int MSG_LOADED_ITEMS = 0; private static final int MSG_SHOW_PROGRESS_DIALOG = 1; + private static final CharSequence NO_RESPONSE_MESSAGE = + "No response from host when getting directory contents. Is the host server running?"; + /** Initialized lazily before first sProgressDialog.show() */ private static ProgressDialog sProgressDialog; @@ -349,13 +353,18 @@ public class DirListActivity extends ListActivity { @Override public void handleMessage(Message msg) { if (msg.what == MSG_LOADED_ITEMS) { - setListAdapter(new DirListAdapter(DirListActivity.this, - (ListItem[])msg.obj)); - delayedDialogHandler.removeMessages(MSG_SHOW_PROGRESS_DIALOG); setTitle(shortenTitle(mCurrentDirPath)); + delayedDialogHandler.removeMessages(MSG_SHOW_PROGRESS_DIALOG); if (sProgressDialog != null) { sProgressDialog.dismiss(); } + if (msg.obj == null) { + Toast.makeText(DirListActivity.this, NO_RESPONSE_MESSAGE, + Toast.LENGTH_LONG).show(); + } else { + setListAdapter(new DirListAdapter(DirListActivity.this, + (ListItem[])msg.obj)); + } } } }).start(); @@ -389,15 +398,21 @@ public class DirListActivity extends ListActivity { List subDirs = new ArrayList(); List subFiles = new ArrayList(); - for (String dirRelativePath : FsUtils.getLayoutTestsDirContents(dirPath, false, - true)) { + List dirRelativePaths = FsUtils.getLayoutTestsDirContents(dirPath, false, true); + if (dirRelativePaths == null) { + return null; + } + for (String dirRelativePath : dirRelativePaths) { if (FileFilter.isTestDir(new File(dirRelativePath).getName())) { subDirs.add(new ListItem(dirRelativePath, true)); } } - for (String testRelativePath : FsUtils.getLayoutTestsDirContents(dirPath, false, - false)) { + List testRelativePaths = FsUtils.getLayoutTestsDirContents(dirPath, false, false); + if (testRelativePaths == null) { + return null; + } + for (String testRelativePath : testRelativePaths) { if (FileFilter.isTestFile(new File(testRelativePath).getName())) { subFiles.add(new ListItem(testRelativePath, false)); } -- cgit v1.1