| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.native_test; | 5 package org.chromium.native_test; |
| 6 | 6 |
| 7 import android.app.Activity; | 7 import android.app.Activity; |
| 8 import android.app.Instrumentation; | 8 import android.app.Instrumentation; |
| 9 import android.content.ComponentName; | 9 import android.content.ComponentName; |
| 10 import android.content.Intent; | 10 import android.content.Intent; |
| 11 import android.os.Bundle; | 11 import android.os.Bundle; |
| 12 import android.util.Log; | 12 import android.util.Log; |
| 13 | 13 |
| 14 import java.io.BufferedInputStream; | 14 import java.io.BufferedInputStream; |
| 15 import java.io.BufferedReader; | 15 import java.io.BufferedReader; |
| 16 import java.io.File; | 16 import java.io.File; |
| 17 import java.io.FileInputStream; | 17 import java.io.FileInputStream; |
| 18 import java.io.FileNotFoundException; | 18 import java.io.FileNotFoundException; |
| 19 import java.io.IOException; | 19 import java.io.IOException; |
| 20 import java.io.InputStreamReader; | 20 import java.io.InputStreamReader; |
| 21 import java.util.HashMap; | 21 import java.util.HashMap; |
| 22 import java.util.Map; | 22 import java.util.Map; |
| 23 import java.util.regex.Matcher; | 23 import java.util.regex.Matcher; |
| 24 import java.util.regex.Pattern; | 24 import java.util.regex.Pattern; |
| 25 | 25 |
| 26 /** | 26 /** |
| 27 * An Instrumentation that runs tests based on ChromeNativeTestActivity. | 27 * An Instrumentation that runs tests based on ChromeNativeTestActivity. |
| 28 */ | 28 */ |
| 29 public class ChromeNativeTestInstrumentationTestRunner extends Instrumentation { | 29 public class ChromeNativeTestInstrumentationTestRunner extends Instrumentation { |
| 30 // TODO(jbudorick): Remove this extra when b/18981674 is fixed. |
| 31 public static final String EXTRA_ONLY_OUTPUT_FAILURES = |
| 32 "org.chromium.native_test.ChromeNativeTestInstrumentationTestRunner.
" |
| 33 + "OnlyOutputFailures"; |
| 30 | 34 |
| 31 private static final String TAG = "ChromeNativeTestInstrumentationTestRunner
"; | 35 private static final String TAG = "ChromeNativeTestInstrumentationTestRunner
"; |
| 32 private static final Pattern RE_TEST_OUTPUT = Pattern.compile("\\[ *([^ ]*)
*\\] ?([^ ]*) .*"); | 36 private static final Pattern RE_TEST_OUTPUT = Pattern.compile("\\[ *([^ ]*)
*\\] ?([^ ]+) .*"); |
| 33 | 37 |
| 34 private static interface ResultsBundleGenerator { | 38 private static interface ResultsBundleGenerator { |
| 35 public Bundle generate(Map<String, TestResult> rawResults); | 39 public Bundle generate(Map<String, TestResult> rawResults); |
| 36 } | 40 } |
| 37 | 41 |
| 38 private String mCommandLineFile; | 42 private String mCommandLineFile; |
| 39 private String mCommandLineFlags; | 43 private String mCommandLineFlags; |
| 40 private Bundle mLogBundle; | 44 private Bundle mLogBundle; |
| 41 private ResultsBundleGenerator mBundleGenerator; | 45 private ResultsBundleGenerator mBundleGenerator; |
| 46 private boolean mOnlyOutputFailures; |
| 42 | 47 |
| 43 @Override | 48 @Override |
| 44 public void onCreate(Bundle arguments) { | 49 public void onCreate(Bundle arguments) { |
| 45 mCommandLineFile = arguments.getString(ChromeNativeTestActivity.EXTRA_CO
MMAND_LINE_FILE); | 50 mCommandLineFile = arguments.getString(ChromeNativeTestActivity.EXTRA_CO
MMAND_LINE_FILE); |
| 46 mCommandLineFlags = arguments.getString(ChromeNativeTestActivity.EXTRA_C
OMMAND_LINE_FLAGS); | 51 mCommandLineFlags = arguments.getString(ChromeNativeTestActivity.EXTRA_C
OMMAND_LINE_FLAGS); |
| 47 mLogBundle = new Bundle(); | 52 mLogBundle = new Bundle(); |
| 48 mBundleGenerator = new RobotiumBundleGenerator(); | 53 mBundleGenerator = new RobotiumBundleGenerator(); |
| 54 mOnlyOutputFailures = arguments.containsKey(EXTRA_ONLY_OUTPUT_FAILURES); |
| 49 start(); | 55 start(); |
| 50 } | 56 } |
| 51 | 57 |
| 52 @Override | 58 @Override |
| 53 public void onStart() { | 59 public void onStart() { |
| 54 super.onStart(); | 60 super.onStart(); |
| 55 Bundle results = runTests(); | 61 Bundle results = runTests(); |
| 56 finish(Activity.RESULT_OK, results); | 62 finish(Activity.RESULT_OK, results); |
| 57 } | 63 } |
| 58 | 64 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 while (!fifo.exists()) { | 116 while (!fifo.exists()) { |
| 111 Thread.sleep(1000); | 117 Thread.sleep(1000); |
| 112 } | 118 } |
| 113 | 119 |
| 114 r = new BufferedReader( | 120 r = new BufferedReader( |
| 115 new InputStreamReader(new BufferedInputStream(new FileInputS
tream(fifo)))); | 121 new InputStreamReader(new BufferedInputStream(new FileInputS
tream(fifo)))); |
| 116 | 122 |
| 117 for (String l = r.readLine(); l != null && !l.equals("<<ScopedMainEn
tryLogger"); | 123 for (String l = r.readLine(); l != null && !l.equals("<<ScopedMainEn
tryLogger"); |
| 118 l = r.readLine()) { | 124 l = r.readLine()) { |
| 119 Matcher m = RE_TEST_OUTPUT.matcher(l); | 125 Matcher m = RE_TEST_OUTPUT.matcher(l); |
| 126 boolean isFailure = false; |
| 120 if (m.matches()) { | 127 if (m.matches()) { |
| 121 if (m.group(1).equals("RUN")) { | 128 if (m.group(1).equals("RUN")) { |
| 122 results.put(m.group(2), TestResult.UNKNOWN); | 129 results.put(m.group(2), TestResult.UNKNOWN); |
| 123 } else if (m.group(1).equals("FAILED")) { | 130 } else if (m.group(1).equals("FAILED")) { |
| 124 results.put(m.group(2), TestResult.FAILED); | 131 results.put(m.group(2), TestResult.FAILED); |
| 132 isFailure = true; |
| 133 mLogBundle.putString(Instrumentation.REPORT_KEY_STREAMRE
SULT, l + "\n"); |
| 134 sendStatus(0, mLogBundle); |
| 125 } else if (m.group(1).equals("OK")) { | 135 } else if (m.group(1).equals("OK")) { |
| 126 results.put(m.group(2), TestResult.PASSED); | 136 results.put(m.group(2), TestResult.PASSED); |
| 127 } | 137 } |
| 128 } | 138 } |
| 129 mLogBundle.putString(Instrumentation.REPORT_KEY_STREAMRESULT, l
+ "\n"); | 139 |
| 130 sendStatus(0, mLogBundle); | 140 // TODO(jbudorick): mOnlyOutputFailures is a workaround for b/18
981674. Remove it |
| 141 // once that issue is fixed. |
| 142 if (!mOnlyOutputFailures || isFailure) { |
| 143 mLogBundle.putString(Instrumentation.REPORT_KEY_STREAMRESULT
, l + "\n"); |
| 144 sendStatus(0, mLogBundle); |
| 145 } |
| 146 Log.i(TAG, l); |
| 131 } | 147 } |
| 132 } catch (InterruptedException e) { | 148 } catch (InterruptedException e) { |
| 133 Log.e(TAG, "Interrupted while waiting for FIFO file creation: " + e.
toString()); | 149 Log.e(TAG, "Interrupted while waiting for FIFO file creation: " + e.
toString()); |
| 134 } catch (FileNotFoundException e) { | 150 } catch (FileNotFoundException e) { |
| 135 Log.e(TAG, "Couldn't find FIFO file: " + e.toString()); | 151 Log.e(TAG, "Couldn't find FIFO file: " + e.toString()); |
| 136 } catch (IOException e) { | 152 } catch (IOException e) { |
| 137 Log.e(TAG, "Error handling FIFO file: " + e.toString()); | 153 Log.e(TAG, "Error handling FIFO file: " + e.toString()); |
| 138 } finally { | 154 } finally { |
| 139 if (r != null) { | 155 if (r != null) { |
| 140 try { | 156 try { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 161 | 177 |
| 162 int testsPassed = 0; | 178 int testsPassed = 0; |
| 163 int testsFailed = 0; | 179 int testsFailed = 0; |
| 164 | 180 |
| 165 for (Map.Entry<String, TestResult> entry : rawResults.entrySet()) { | 181 for (Map.Entry<String, TestResult> entry : rawResults.entrySet()) { |
| 166 switch (entry.getValue()) { | 182 switch (entry.getValue()) { |
| 167 case PASSED: | 183 case PASSED: |
| 168 ++testsPassed; | 184 ++testsPassed; |
| 169 break; | 185 break; |
| 170 case FAILED: | 186 case FAILED: |
| 187 // TODO(jbudorick): Remove this log message once AMP exe
cution and |
| 188 // results handling has been stabilized. |
| 189 Log.d(TAG, "FAILED: " + entry.getKey()); |
| 171 ++testsFailed; | 190 ++testsFailed; |
| 172 break; | 191 break; |
| 173 default: | 192 default: |
| 174 Log.w(TAG, "Unhandled: " + entry.getKey() + ", " | 193 Log.w(TAG, "Unhandled: " + entry.getKey() + ", " |
| 175 + entry.getValue().toString()); | 194 + entry.getValue().toString()); |
| 176 break; | 195 break; |
| 177 } | 196 } |
| 178 } | 197 } |
| 179 | 198 |
| 180 StringBuilder resultBuilder = new StringBuilder(); | 199 StringBuilder resultBuilder = new StringBuilder(); |
| 181 resultBuilder.append("\nOK (" + Integer.toString(testsPassed) + " te
sts)"); | |
| 182 if (testsFailed > 0) { | 200 if (testsFailed > 0) { |
| 183 resultBuilder.append( | 201 resultBuilder.append( |
| 184 "\nFAILURES!!! Tests run: " + Integer.toString(rawResult
s.size()) | 202 "\nFAILURES!!! Tests run: " + Integer.toString(rawResult
s.size()) |
| 185 + ", Failures: " + Integer.toString(testsFailed) + ", Er
rors: 0"); | 203 + ", Failures: " + Integer.toString(testsFailed) + ", Er
rors: 0"); |
| 204 } else { |
| 205 resultBuilder.append("\nOK (" + Integer.toString(testsPassed) +
" tests)"); |
| 186 } | 206 } |
| 187 resultsBundle.putString(Instrumentation.REPORT_KEY_STREAMRESULT, | 207 resultsBundle.putString(Instrumentation.REPORT_KEY_STREAMRESULT, |
| 188 resultBuilder.toString()); | 208 resultBuilder.toString()); |
| 189 return resultsBundle; | 209 return resultsBundle; |
| 190 } | 210 } |
| 191 } | 211 } |
| 192 | 212 |
| 193 } | 213 } |
| OLD | NEW |