The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.dumprendertree; |
| 18 | |
Guang Zhu | f3d924c | 2009-09-01 11:57:16 -0700 | [diff] [blame] | 19 | import com.android.dumprendertree.TestShellActivity.DumpDataType; |
Guang Zhu | f4bf552 | 2009-07-23 14:19:35 -0700 | [diff] [blame] | 20 | import com.android.dumprendertree.forwarder.AdbUtils; |
Guang Zhu | 6bf18ba | 2009-09-15 23:47:20 -0700 | [diff] [blame] | 21 | import com.android.dumprendertree.forwarder.ForwardService; |
Guang Zhu | f4bf552 | 2009-07-23 14:19:35 -0700 | [diff] [blame] | 22 | |
Guang Zhu | 0006952 | 2010-12-06 11:17:38 -0800 | [diff] [blame] | 23 | import android.content.Context; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | import android.content.Intent; |
Christian Mehlmauer | 8b85dce | 2010-07-19 20:11:27 +0200 | [diff] [blame] | 25 | import android.os.Environment; |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 26 | import android.test.ActivityInstrumentationTestCase2; |
Guang Zhu | b933f669 | 2009-05-05 01:02:14 -0700 | [diff] [blame] | 27 | import android.util.Log; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | |
| 29 | import java.io.BufferedOutputStream; |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 30 | import java.io.BufferedReader; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | import java.io.File; |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 32 | import java.io.FileNotFoundException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | import java.io.FileOutputStream; |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 34 | import java.io.FileReader; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | import java.io.IOException; |
Sridhar Gurivireddy | 36fd6d2 | 2009-03-31 14:47:19 -0700 | [diff] [blame] | 36 | import java.io.InputStream; |
| 37 | import java.io.OutputStream; |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 38 | import java.util.Vector; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | |
Steve Block | cf0fd78 | 2010-03-09 13:54:09 +0000 | [diff] [blame] | 40 | // TestRecorder creates four files ... |
Steve Block | 5ac2a3b | 2010-03-09 14:36:00 +0000 | [diff] [blame] | 41 | // - passing tests |
| 42 | // - failing tests |
Steve Block | cf0fd78 | 2010-03-09 13:54:09 +0000 | [diff] [blame] | 43 | // - tests for which results are ignored |
Steve Block | 5ac2a3b | 2010-03-09 14:36:00 +0000 | [diff] [blame] | 44 | // - tests with no text results available |
| 45 | // TestRecorder does not have the ability to clear the results. |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 46 | class MyTestRecorder { |
| 47 | private BufferedOutputStream mBufferedOutputPassedStream; |
| 48 | private BufferedOutputStream mBufferedOutputFailedStream; |
Steve Block | cf0fd78 | 2010-03-09 13:54:09 +0000 | [diff] [blame] | 49 | private BufferedOutputStream mBufferedOutputIgnoreResultStream; |
Steve Block | 5ac2a3b | 2010-03-09 14:36:00 +0000 | [diff] [blame] | 50 | private BufferedOutputStream mBufferedOutputNoResultStream; |
Guang Zhu | f4bf552 | 2009-07-23 14:19:35 -0700 | [diff] [blame] | 51 | |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 52 | public void passed(String layout_file) { |
| 53 | try { |
| 54 | mBufferedOutputPassedStream.write(layout_file.getBytes()); |
| 55 | mBufferedOutputPassedStream.write('\n'); |
| 56 | mBufferedOutputPassedStream.flush(); |
| 57 | } catch(Exception e) { |
| 58 | e.printStackTrace(); |
| 59 | } |
| 60 | } |
Guang Zhu | f4bf552 | 2009-07-23 14:19:35 -0700 | [diff] [blame] | 61 | |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 62 | public void failed(String layout_file) { |
| 63 | try { |
| 64 | mBufferedOutputFailedStream.write(layout_file.getBytes()); |
| 65 | mBufferedOutputFailedStream.write('\n'); |
| 66 | mBufferedOutputFailedStream.flush(); |
| 67 | } catch(Exception e) { |
| 68 | e.printStackTrace(); |
| 69 | } |
| 70 | } |
Guang Zhu | f4bf552 | 2009-07-23 14:19:35 -0700 | [diff] [blame] | 71 | |
Steve Block | cf0fd78 | 2010-03-09 13:54:09 +0000 | [diff] [blame] | 72 | public void ignoreResult(String layout_file) { |
| 73 | try { |
| 74 | mBufferedOutputIgnoreResultStream.write(layout_file.getBytes()); |
| 75 | mBufferedOutputIgnoreResultStream.write('\n'); |
| 76 | mBufferedOutputIgnoreResultStream.flush(); |
| 77 | } catch(Exception e) { |
| 78 | e.printStackTrace(); |
| 79 | } |
| 80 | } |
| 81 | |
Steve Block | 5ac2a3b | 2010-03-09 14:36:00 +0000 | [diff] [blame] | 82 | public void noResult(String layout_file) { |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 83 | try { |
Steve Block | 5ac2a3b | 2010-03-09 14:36:00 +0000 | [diff] [blame] | 84 | mBufferedOutputNoResultStream.write(layout_file.getBytes()); |
| 85 | mBufferedOutputNoResultStream.write('\n'); |
| 86 | mBufferedOutputNoResultStream.flush(); |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 87 | } catch(Exception e) { |
| 88 | e.printStackTrace(); |
| 89 | } |
| 90 | } |
Guang Zhu | f4bf552 | 2009-07-23 14:19:35 -0700 | [diff] [blame] | 91 | |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 92 | public MyTestRecorder(boolean resume) { |
| 93 | try { |
Christian Mehlmauer | 8b85dce | 2010-07-19 20:11:27 +0200 | [diff] [blame] | 94 | File externalDir = Environment.getExternalStorageDirectory(); |
| 95 | File resultsPassedFile = new File(externalDir, "layout_tests_passed.txt"); |
| 96 | File resultsFailedFile = new File(externalDir, "layout_tests_failed.txt"); |
| 97 | File resultsIgnoreResultFile = new File(externalDir, "layout_tests_ignored.txt"); |
| 98 | File noExpectedResultFile = new File(externalDir, "layout_tests_nontext.txt"); |
Guang Zhu | f4bf552 | 2009-07-23 14:19:35 -0700 | [diff] [blame] | 99 | |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 100 | mBufferedOutputPassedStream = |
| 101 | new BufferedOutputStream(new FileOutputStream(resultsPassedFile, resume)); |
| 102 | mBufferedOutputFailedStream = |
| 103 | new BufferedOutputStream(new FileOutputStream(resultsFailedFile, resume)); |
Steve Block | cf0fd78 | 2010-03-09 13:54:09 +0000 | [diff] [blame] | 104 | mBufferedOutputIgnoreResultStream = |
| 105 | new BufferedOutputStream(new FileOutputStream(resultsIgnoreResultFile, resume)); |
Steve Block | 5ac2a3b | 2010-03-09 14:36:00 +0000 | [diff] [blame] | 106 | mBufferedOutputNoResultStream = |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 107 | new BufferedOutputStream(new FileOutputStream(noExpectedResultFile, resume)); |
| 108 | } catch (Exception e) { |
| 109 | e.printStackTrace(); |
| 110 | } |
| 111 | } |
Guang Zhu | f4bf552 | 2009-07-23 14:19:35 -0700 | [diff] [blame] | 112 | |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 113 | public void close() { |
| 114 | try { |
| 115 | mBufferedOutputPassedStream.close(); |
| 116 | mBufferedOutputFailedStream.close(); |
Steve Block | cf0fd78 | 2010-03-09 13:54:09 +0000 | [diff] [blame] | 117 | mBufferedOutputIgnoreResultStream.close(); |
Steve Block | 5ac2a3b | 2010-03-09 14:36:00 +0000 | [diff] [blame] | 118 | mBufferedOutputNoResultStream.close(); |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 119 | } catch (Exception e) { |
| 120 | e.printStackTrace(); |
| 121 | } |
| 122 | } |
| 123 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 124 | |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 125 | |
| 126 | public class LayoutTestsAutoTest extends ActivityInstrumentationTestCase2<TestShellActivity> { |
| 127 | |
| 128 | private static final String LOGTAG = "LayoutTests"; |
| 129 | static final int DEFAULT_TIMEOUT_IN_MILLIS = 5000; |
Guang Zhu | f4bf552 | 2009-07-23 14:19:35 -0700 | [diff] [blame] | 130 | |
Christian Mehlmauer | 8b85dce | 2010-07-19 20:11:27 +0200 | [diff] [blame] | 131 | static final String EXTERNAL_DIR = Environment.getExternalStorageDirectory().toString(); |
Guang Zhu | 7171622 | 2011-01-12 22:57:41 -0800 | [diff] [blame] | 132 | static final String LAYOUT_TESTS_ROOT = EXTERNAL_DIR + "/webkit/layout_tests/"; |
| 133 | static final String LAYOUT_TESTS_RESULT_DIR = EXTERNAL_DIR + "/webkit/layout_tests_results/"; |
| 134 | static final String ANDROID_EXPECTED_RESULT_DIR = EXTERNAL_DIR + "/webkit/expected_results/"; |
| 135 | static final String LAYOUT_TESTS_LIST_FILE = EXTERNAL_DIR + "/webkit/layout_tests_list.txt"; |
| 136 | static final String TEST_STATUS_FILE = EXTERNAL_DIR + "/webkit/running_test.txt"; |
Sridhar Gurivireddy | 36fd6d2 | 2009-03-31 14:47:19 -0700 | [diff] [blame] | 137 | static final String LAYOUT_TESTS_RESULTS_REFERENCE_FILES[] = { |
| 138 | "results/layout_tests_passed.txt", |
| 139 | "results/layout_tests_failed.txt", |
| 140 | "results/layout_tests_nontext.txt", |
| 141 | "results/layout_tests_crashed.txt", |
| 142 | "run_layout_tests.py" |
| 143 | }; |
| 144 | |
| 145 | static final String LAYOUT_RESULTS_FAILED_RESULT_FILE = "results/layout_tests_failed.txt"; |
| 146 | static final String LAYOUT_RESULTS_NONTEXT_RESULT_FILE = "results/layout_tests_nontext.txt"; |
| 147 | static final String LAYOUT_RESULTS_CRASHED_RESULT_FILE = "results/layout_tests_crashed.txt"; |
| 148 | static final String LAYOUT_TESTS_RUNNER = "run_layout_tests.py"; |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 149 | |
| 150 | private MyTestRecorder mResultRecorder; |
| 151 | private Vector<String> mTestList; |
Steve Block | cf0fd78 | 2010-03-09 13:54:09 +0000 | [diff] [blame] | 152 | // Whether we should ignore the result for the corresponding test. Ordered same as mTestList. |
| 153 | private Vector<Boolean> mTestListIgnoreResult; |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 154 | private boolean mRebaselineResults; |
Steve Block | 12077e1 | 2010-02-25 12:50:33 +0000 | [diff] [blame] | 155 | // The JavaScript engine currently in use. This determines which set of Android-specific |
| 156 | // expected test results we use. |
| 157 | private String mJsEngine; |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 158 | private String mTestPathPrefix; |
Guang Zhu | b933f669 | 2009-05-05 01:02:14 -0700 | [diff] [blame] | 159 | private boolean mFinished; |
Kristian Monsen | 521d9a7 | 2010-05-25 20:12:47 +0100 | [diff] [blame] | 160 | private int mTestCount; |
Kristian Monsen | fb4b88f | 2010-05-26 18:21:39 +0100 | [diff] [blame] | 161 | private int mResumeIndex; |
Guang Zhu | f4bf552 | 2009-07-23 14:19:35 -0700 | [diff] [blame] | 162 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 163 | public LayoutTestsAutoTest() { |
Guang Zhu | 6c15f60 | 2010-05-03 11:49:04 -0700 | [diff] [blame] | 164 | super(TestShellActivity.class); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 165 | } |
Guang Zhu | f4bf552 | 2009-07-23 14:19:35 -0700 | [diff] [blame] | 166 | |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 167 | private void getTestList() { |
| 168 | // Read test list. |
| 169 | try { |
| 170 | BufferedReader inReader = new BufferedReader(new FileReader(LAYOUT_TESTS_LIST_FILE)); |
| 171 | String line = inReader.readLine(); |
| 172 | while (line != null) { |
Steve Block | cf0fd78 | 2010-03-09 13:54:09 +0000 | [diff] [blame] | 173 | if (line.startsWith(mTestPathPrefix)) { |
| 174 | String[] components = line.split(" "); |
| 175 | mTestList.add(components[0]); |
| 176 | mTestListIgnoreResult.add(components.length > 1 && components[1].equals("IGNORE_RESULT")); |
| 177 | } |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 178 | line = inReader.readLine(); |
| 179 | } |
| 180 | inReader.close(); |
| 181 | Log.v(LOGTAG, "Test list has " + mTestList.size() + " test(s)."); |
| 182 | } catch (Exception e) { |
| 183 | Log.e(LOGTAG, "Error while reading test list : " + e.getMessage()); |
| 184 | } |
Kristian Monsen | 521d9a7 | 2010-05-25 20:12:47 +0100 | [diff] [blame] | 185 | mTestCount = mTestList.size(); |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 186 | } |
Guang Zhu | f4bf552 | 2009-07-23 14:19:35 -0700 | [diff] [blame] | 187 | |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 188 | private void resumeTestList() { |
| 189 | // read out the test name it stoped last time. |
| 190 | try { |
Guang Zhu | f92bd42 | 2009-06-29 10:40:55 -0700 | [diff] [blame] | 191 | String line = FsUtils.readTestStatus(TEST_STATUS_FILE); |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 192 | for (int i = 0; i < mTestList.size(); i++) { |
| 193 | if (mTestList.elementAt(i).equals(line)) { |
| 194 | mTestList = new Vector<String>(mTestList.subList(i+1, mTestList.size())); |
Steve Block | cf0fd78 | 2010-03-09 13:54:09 +0000 | [diff] [blame] | 195 | mTestListIgnoreResult = new Vector<Boolean>(mTestListIgnoreResult.subList(i+1, mTestListIgnoreResult.size())); |
Kristian Monsen | fb4b88f | 2010-05-26 18:21:39 +0100 | [diff] [blame] | 196 | mResumeIndex = i + 1; |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 197 | break; |
| 198 | } |
| 199 | } |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 200 | } catch (Exception e) { |
| 201 | Log.e(LOGTAG, "Error reading " + TEST_STATUS_FILE); |
| 202 | } |
| 203 | } |
Guang Zhu | f4bf552 | 2009-07-23 14:19:35 -0700 | [diff] [blame] | 204 | |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 205 | private void clearTestStatus() { |
| 206 | // Delete TEST_STATUS_FILE |
| 207 | try { |
| 208 | File f = new File(TEST_STATUS_FILE); |
| 209 | if (f.delete()) |
| 210 | Log.v(LOGTAG, "Deleted " + TEST_STATUS_FILE); |
| 211 | else |
| 212 | Log.e(LOGTAG, "Fail to delete " + TEST_STATUS_FILE); |
| 213 | } catch (Exception e) { |
| 214 | Log.e(LOGTAG, "Fail to delete " + TEST_STATUS_FILE + " : " + e.getMessage()); |
| 215 | } |
| 216 | } |
Guang Zhu | f92bd42 | 2009-06-29 10:40:55 -0700 | [diff] [blame] | 217 | |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 218 | private String getResultFile(String test) { |
| 219 | String shortName = test.substring(0, test.lastIndexOf('.')); |
| 220 | // Write actual results to result directory. |
| 221 | return shortName.replaceFirst(LAYOUT_TESTS_ROOT, LAYOUT_TESTS_RESULT_DIR) + "-result.txt"; |
| 222 | } |
Guang Zhu | f4bf552 | 2009-07-23 14:19:35 -0700 | [diff] [blame] | 223 | |
Steve Block | 12077e1 | 2010-02-25 12:50:33 +0000 | [diff] [blame] | 224 | // Gets the file which contains WebKit's expected results for this test. |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 225 | private String getExpectedResultFile(String test) { |
Steve Block | 12077e1 | 2010-02-25 12:50:33 +0000 | [diff] [blame] | 226 | // The generic result is at <path>/<name>-expected.txt |
| 227 | // First try the Android-specific result at |
| 228 | // platform/android-<js-engine>/<path>/<name>-expected.txt |
Steve Block | a888375 | 2010-07-12 17:50:06 +0100 | [diff] [blame] | 229 | // then |
| 230 | // platform/android/<path>/<name>-expected.txt |
Guang Zhu | 2a197b1 | 2009-05-18 14:37:23 -0700 | [diff] [blame] | 231 | int pos = test.lastIndexOf('.'); |
Steve Block | 12077e1 | 2010-02-25 12:50:33 +0000 | [diff] [blame] | 232 | if (pos == -1) |
Guang Zhu | 2a197b1 | 2009-05-18 14:37:23 -0700 | [diff] [blame] | 233 | return null; |
Steve Block | 12077e1 | 2010-02-25 12:50:33 +0000 | [diff] [blame] | 234 | String genericExpectedResult = test.substring(0, pos) + "-expected.txt"; |
| 235 | String androidExpectedResultsDir = "platform/android-" + mJsEngine + "/"; |
Steve Block | a888375 | 2010-07-12 17:50:06 +0100 | [diff] [blame] | 236 | String androidExpectedResult = genericExpectedResult.replaceFirst(LAYOUT_TESTS_ROOT, |
| 237 | LAYOUT_TESTS_ROOT + androidExpectedResultsDir); |
Steve Block | 12077e1 | 2010-02-25 12:50:33 +0000 | [diff] [blame] | 238 | File f = new File(androidExpectedResult); |
Steve Block | a888375 | 2010-07-12 17:50:06 +0100 | [diff] [blame] | 239 | if (f.exists()) |
| 240 | return androidExpectedResult; |
| 241 | androidExpectedResultsDir = "platform/android/"; |
| 242 | androidExpectedResult = genericExpectedResult.replaceFirst(LAYOUT_TESTS_ROOT, |
| 243 | LAYOUT_TESTS_ROOT + androidExpectedResultsDir); |
| 244 | f = new File(androidExpectedResult); |
Steve Block | 12077e1 | 2010-02-25 12:50:33 +0000 | [diff] [blame] | 245 | return f.exists() ? androidExpectedResult : genericExpectedResult; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 246 | } |
| 247 | |
Steve Block | 12077e1 | 2010-02-25 12:50:33 +0000 | [diff] [blame] | 248 | // Gets the file which contains the actual results of running the test on |
| 249 | // Android, generated by a previous run which set a new baseline. |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 250 | private String getAndroidExpectedResultFile(String expectedResultFile) { |
| 251 | return expectedResultFile.replaceFirst(LAYOUT_TESTS_ROOT, ANDROID_EXPECTED_RESULT_DIR); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 252 | } |
| 253 | |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 254 | // Wrap up |
| 255 | private void failedCase(String file) { |
| 256 | Log.w("Layout test: ", file + " failed"); |
Guang Zhu | f4bf552 | 2009-07-23 14:19:35 -0700 | [diff] [blame] | 257 | mResultRecorder.failed(file); |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | private void passedCase(String file) { |
| 261 | Log.v("Layout test:", file + " passed"); |
| 262 | mResultRecorder.passed(file); |
| 263 | } |
| 264 | |
Steve Block | cf0fd78 | 2010-03-09 13:54:09 +0000 | [diff] [blame] | 265 | private void ignoreResultCase(String file) { |
| 266 | Log.v("Layout test:", file + " ignore result"); |
| 267 | mResultRecorder.ignoreResult(file); |
| 268 | } |
| 269 | |
Steve Block | 5ac2a3b | 2010-03-09 14:36:00 +0000 | [diff] [blame] | 270 | private void noResultCase(String file) { |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 271 | Log.v("Layout test:", file + " no expected result"); |
Steve Block | 5ac2a3b | 2010-03-09 14:36:00 +0000 | [diff] [blame] | 272 | mResultRecorder.noResult(file); |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 273 | } |
Guang Zhu | f4bf552 | 2009-07-23 14:19:35 -0700 | [diff] [blame] | 274 | |
Steve Block | cf0fd78 | 2010-03-09 13:54:09 +0000 | [diff] [blame] | 275 | private void processResult(String testFile, String actualResultFile, String expectedResultFile, boolean ignoreResult) { |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 276 | Log.v(LOGTAG, " Processing result: " + testFile); |
| 277 | |
Steve Block | cf0fd78 | 2010-03-09 13:54:09 +0000 | [diff] [blame] | 278 | if (ignoreResult) { |
| 279 | ignoreResultCase(testFile); |
| 280 | return; |
| 281 | } |
| 282 | |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 283 | File actual = new File(actualResultFile); |
| 284 | File expected = new File(expectedResultFile); |
| 285 | if (actual.exists() && expected.exists()) { |
| 286 | try { |
Guang Zhu | ea48cd6 | 2009-11-12 10:18:14 -0800 | [diff] [blame] | 287 | if (FsUtils.diffIgnoreSpaces(actualResultFile, expectedResultFile)) { |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 288 | passedCase(testFile); |
| 289 | } else { |
| 290 | failedCase(testFile); |
| 291 | } |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 292 | } catch (FileNotFoundException ex) { |
| 293 | Log.e(LOGTAG, "File not found : " + ex.getMessage()); |
| 294 | } catch (IOException ex) { |
| 295 | Log.e(LOGTAG, "IO Error : " + ex.getMessage()); |
| 296 | } |
| 297 | return; |
| 298 | } |
| 299 | |
| 300 | if (!expected.exists()) { |
Steve Block | 5ac2a3b | 2010-03-09 14:36:00 +0000 | [diff] [blame] | 301 | noResultCase(testFile); |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 302 | } |
| 303 | } |
Guang Zhu | f4bf552 | 2009-07-23 14:19:35 -0700 | [diff] [blame] | 304 | |
Ben Murdoch | 9b815d0 | 2010-06-01 18:45:10 +0100 | [diff] [blame] | 305 | private void runTestAndWaitUntilDone(TestShellActivity activity, String test, int timeout, boolean ignoreResult, int testNumber) { |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 306 | activity.setCallback(new TestShellCallback() { |
| 307 | public void finished() { |
| 308 | synchronized (LayoutTestsAutoTest.this) { |
Guang Zhu | b933f669 | 2009-05-05 01:02:14 -0700 | [diff] [blame] | 309 | mFinished = true; |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 310 | LayoutTestsAutoTest.this.notifyAll(); |
| 311 | } |
Guang Zhu | 4010ac3 | 2009-04-29 14:49:03 -0700 | [diff] [blame] | 312 | } |
Guang Zhu | f4bf552 | 2009-07-23 14:19:35 -0700 | [diff] [blame] | 313 | |
Guang Zhu | 4010ac3 | 2009-04-29 14:49:03 -0700 | [diff] [blame] | 314 | public void timedOut(String url) { |
Guang Zhu | 4a40a03 | 2009-09-01 10:23:24 -0700 | [diff] [blame] | 315 | Log.v(LOGTAG, "layout timeout: " + url); |
Guang Zhu | 4010ac3 | 2009-04-29 14:49:03 -0700 | [diff] [blame] | 316 | } |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 317 | }); |
| 318 | |
| 319 | String resultFile = getResultFile(test); |
Steve Block | 12077e1 | 2010-02-25 12:50:33 +0000 | [diff] [blame] | 320 | if (resultFile == null) { |
| 321 | // Simply ignore this test. |
Guang Zhu | 2a197b1 | 2009-05-18 14:37:23 -0700 | [diff] [blame] | 322 | return; |
| 323 | } |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 324 | if (mRebaselineResults) { |
| 325 | String expectedResultFile = getExpectedResultFile(test); |
| 326 | File f = new File(expectedResultFile); |
| 327 | if (f.exists()) { |
| 328 | return; // don't run test and don't overwrite default tests. |
| 329 | } |
| 330 | |
| 331 | resultFile = getAndroidExpectedResultFile(expectedResultFile); |
| 332 | } |
Guang Zhu | f4bf552 | 2009-07-23 14:19:35 -0700 | [diff] [blame] | 333 | |
Guang Zhu | b933f669 | 2009-05-05 01:02:14 -0700 | [diff] [blame] | 334 | mFinished = false; |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 335 | Intent intent = new Intent(Intent.ACTION_VIEW); |
| 336 | intent.setClass(activity, TestShellActivity.class); |
| 337 | intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); |
Guang Zhu | 6bf18ba | 2009-09-15 23:47:20 -0700 | [diff] [blame] | 338 | intent.putExtra(TestShellActivity.TEST_URL, FsUtils.getTestUrl(test)); |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 339 | intent.putExtra(TestShellActivity.RESULT_FILE, resultFile); |
| 340 | intent.putExtra(TestShellActivity.TIMEOUT_IN_MILLIS, timeout); |
Ben Murdoch | 9b815d0 | 2010-06-01 18:45:10 +0100 | [diff] [blame] | 341 | intent.putExtra(TestShellActivity.TOTAL_TEST_COUNT, mTestCount); |
| 342 | intent.putExtra(TestShellActivity.CURRENT_TEST_NUMBER, testNumber); |
Guang Zhu | 5d53c19 | 2010-07-14 17:17:54 -0700 | [diff] [blame] | 343 | intent.putExtra(TestShellActivity.STOP_ON_REF_ERROR, true); |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 344 | activity.startActivity(intent); |
Guang Zhu | f4bf552 | 2009-07-23 14:19:35 -0700 | [diff] [blame] | 345 | |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 346 | // Wait until done. |
| 347 | synchronized (this) { |
Guang Zhu | b933f669 | 2009-05-05 01:02:14 -0700 | [diff] [blame] | 348 | while(!mFinished){ |
| 349 | try { |
| 350 | this.wait(); |
| 351 | } catch (InterruptedException e) { } |
| 352 | } |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 353 | } |
Guang Zhu | f4bf552 | 2009-07-23 14:19:35 -0700 | [diff] [blame] | 354 | |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 355 | if (!mRebaselineResults) { |
| 356 | String expectedResultFile = getExpectedResultFile(test); |
| 357 | File f = new File(expectedResultFile); |
| 358 | if (!f.exists()) { |
| 359 | expectedResultFile = getAndroidExpectedResultFile(expectedResultFile); |
| 360 | } |
Guang Zhu | f4bf552 | 2009-07-23 14:19:35 -0700 | [diff] [blame] | 361 | |
Steve Block | cf0fd78 | 2010-03-09 13:54:09 +0000 | [diff] [blame] | 362 | processResult(test, resultFile, expectedResultFile, ignoreResult); |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 363 | } |
Guang Zhu | f4bf552 | 2009-07-23 14:19:35 -0700 | [diff] [blame] | 364 | } |
| 365 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 366 | // Invokes running of layout tests |
| 367 | // and waits till it has finished running. |
| 368 | public void executeLayoutTests(boolean resume) { |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 369 | LayoutTestsAutoRunner runner = (LayoutTestsAutoRunner) getInstrumentation(); |
| 370 | // A convenient method to be called by another activity. |
| 371 | |
| 372 | if (runner.mTestPath == null) { |
| 373 | Log.e(LOGTAG, "No test specified"); |
| 374 | return; |
| 375 | } |
| 376 | |
| 377 | this.mTestList = new Vector<String>(); |
Steve Block | cf0fd78 | 2010-03-09 13:54:09 +0000 | [diff] [blame] | 378 | this.mTestListIgnoreResult = new Vector<Boolean>(); |
Guang Zhu | f4bf552 | 2009-07-23 14:19:35 -0700 | [diff] [blame] | 379 | |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 380 | // Read settings |
Steve Block | 12077e1 | 2010-02-25 12:50:33 +0000 | [diff] [blame] | 381 | mTestPathPrefix = (new File(LAYOUT_TESTS_ROOT + runner.mTestPath)).getAbsolutePath(); |
| 382 | mRebaselineResults = runner.mRebaseline; |
Steve Block | c1d8651 | 2010-05-13 10:59:59 +0100 | [diff] [blame] | 383 | // V8 is the default JavaScript engine. |
| 384 | mJsEngine = runner.mJsEngine == null ? "v8" : runner.mJsEngine; |
Guang Zhu | f4bf552 | 2009-07-23 14:19:35 -0700 | [diff] [blame] | 385 | |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 386 | int timeout = runner.mTimeoutInMillis; |
| 387 | if (timeout <= 0) { |
| 388 | timeout = DEFAULT_TIMEOUT_IN_MILLIS; |
| 389 | } |
Guang Zhu | f4bf552 | 2009-07-23 14:19:35 -0700 | [diff] [blame] | 390 | |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 391 | this.mResultRecorder = new MyTestRecorder(resume); |
Guang Zhu | f4bf552 | 2009-07-23 14:19:35 -0700 | [diff] [blame] | 392 | |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 393 | if (!resume) |
| 394 | clearTestStatus(); |
Guang Zhu | f4bf552 | 2009-07-23 14:19:35 -0700 | [diff] [blame] | 395 | |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 396 | getTestList(); |
| 397 | if (resume) |
| 398 | resumeTestList(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 399 | |
Guang Zhu | f3d924c | 2009-09-01 11:57:16 -0700 | [diff] [blame] | 400 | TestShellActivity activity = getActivity(); |
Guang Zhu | 6c15f60 | 2010-05-03 11:49:04 -0700 | [diff] [blame] | 401 | activity.setDefaultDumpDataType(DumpDataType.EXT_REPR); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 402 | |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 403 | // Run tests. |
| 404 | for (int i = 0; i < mTestList.size(); i++) { |
| 405 | String s = mTestList.elementAt(i); |
Steve Block | cf0fd78 | 2010-03-09 13:54:09 +0000 | [diff] [blame] | 406 | boolean ignoreResult = mTestListIgnoreResult.elementAt(i); |
Guang Zhu | f92bd42 | 2009-06-29 10:40:55 -0700 | [diff] [blame] | 407 | FsUtils.updateTestStatus(TEST_STATUS_FILE, s); |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 408 | // Run tests |
Ben Murdoch | 9b815d0 | 2010-06-01 18:45:10 +0100 | [diff] [blame] | 409 | // i is 0 based, but test count is 1 based so add 1 to i here. |
| 410 | runTestAndWaitUntilDone(activity, s, runner.mTimeoutInMillis, ignoreResult, |
| 411 | i + 1 + mResumeIndex); |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 412 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 413 | |
Guang Zhu | f92bd42 | 2009-06-29 10:40:55 -0700 | [diff] [blame] | 414 | FsUtils.updateTestStatus(TEST_STATUS_FILE, "#DONE"); |
Guang Zhu | 6bf18ba | 2009-09-15 23:47:20 -0700 | [diff] [blame] | 415 | ForwardService.getForwardService().stopForwardService(); |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 416 | activity.finish(); |
| 417 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 418 | |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 419 | private String getTestPath() { |
| 420 | LayoutTestsAutoRunner runner = (LayoutTestsAutoRunner) getInstrumentation(); |
| 421 | |
| 422 | String test_path = LAYOUT_TESTS_ROOT; |
| 423 | if (runner.mTestPath != null) { |
| 424 | test_path += runner.mTestPath; |
| 425 | } |
Guang Zhu | 8cd303a | 2010-02-22 16:16:24 -0800 | [diff] [blame] | 426 | test_path = new File(test_path).getAbsolutePath(); |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 427 | Log.v("LayoutTestsAutoTest", " Test path : " + test_path); |
Guang Zhu | f4bf552 | 2009-07-23 14:19:35 -0700 | [diff] [blame] | 428 | |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 429 | return test_path; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 430 | } |
Guang Zhu | f4bf552 | 2009-07-23 14:19:35 -0700 | [diff] [blame] | 431 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 432 | public void generateTestList() { |
| 433 | try { |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 434 | File tests_list = new File(LAYOUT_TESTS_LIST_FILE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 435 | BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(tests_list, false)); |
Ben Murdoch | 9b815d0 | 2010-06-01 18:45:10 +0100 | [diff] [blame] | 436 | FsUtils.writeLayoutTestListRecursively(bos, getTestPath(), false); // Don't ignore results |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 437 | bos.flush(); |
| 438 | bos.close(); |
| 439 | } catch (Exception e) { |
| 440 | Log.e(LOGTAG, "Error when creating test list: " + e.getMessage()); |
| 441 | } |
| 442 | } |
| 443 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 444 | // Running all the layout tests at once sometimes |
| 445 | // causes the dumprendertree to run out of memory. |
| 446 | // So, additional tests are added to run the tests |
| 447 | // in chunks. |
| 448 | public void startLayoutTests() { |
| 449 | try { |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 450 | File tests_list = new File(LAYOUT_TESTS_LIST_FILE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 451 | if (!tests_list.exists()) |
| 452 | generateTestList(); |
| 453 | } catch (Exception e) { |
| 454 | e.printStackTrace(); |
| 455 | } |
Guang Zhu | f4bf552 | 2009-07-23 14:19:35 -0700 | [diff] [blame] | 456 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 457 | executeLayoutTests(false); |
| 458 | } |
| 459 | |
| 460 | public void resumeLayoutTests() { |
| 461 | executeLayoutTests(true); |
| 462 | } |
Sridhar Gurivireddy | 36fd6d2 | 2009-03-31 14:47:19 -0700 | [diff] [blame] | 463 | |
| 464 | public void copyResultsAndRunnerAssetsToCache() { |
| 465 | try { |
Guang Zhu | 0006952 | 2010-12-06 11:17:38 -0800 | [diff] [blame] | 466 | Context targetContext = getInstrumentation().getTargetContext(); |
| 467 | File cacheDir = targetContext.getCacheDir(); |
Sridhar Gurivireddy | 36fd6d2 | 2009-03-31 14:47:19 -0700 | [diff] [blame] | 468 | |
| 469 | for( int i=0; i< LAYOUT_TESTS_RESULTS_REFERENCE_FILES.length; i++) { |
Guang Zhu | 0006952 | 2010-12-06 11:17:38 -0800 | [diff] [blame] | 470 | InputStream in = targetContext.getAssets().open( |
| 471 | LAYOUT_TESTS_RESULTS_REFERENCE_FILES[i]); |
| 472 | OutputStream out = new FileOutputStream(new File(cacheDir, |
| 473 | LAYOUT_TESTS_RESULTS_REFERENCE_FILES[i])); |
Sridhar Gurivireddy | 36fd6d2 | 2009-03-31 14:47:19 -0700 | [diff] [blame] | 474 | |
| 475 | byte[] buf = new byte[2048]; |
| 476 | int len; |
| 477 | |
Guang Zhu | b933f669 | 2009-05-05 01:02:14 -0700 | [diff] [blame] | 478 | while ((len = in.read(buf)) >= 0 ) { |
Sridhar Gurivireddy | 36fd6d2 | 2009-03-31 14:47:19 -0700 | [diff] [blame] | 479 | out.write(buf, 0, len); |
| 480 | } |
| 481 | out.close(); |
| 482 | in.close(); |
| 483 | } |
| 484 | }catch (IOException e) { |
| 485 | e.printStackTrace(); |
| 486 | } |
| 487 | |
| 488 | } |
| 489 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 490 | } |