Omari Stephens | 7ddc62b | 2012-02-27 21:18:58 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 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.continuous; |
| 18 | |
Omari Stephens | cb76e3a | 2012-03-19 20:12:41 -0700 | [diff] [blame^] | 19 | import com.android.ddmlib.testrunner.TestIdentifier; |
Omari Stephens | 7ddc62b | 2012-02-27 21:18:58 -0800 | [diff] [blame] | 20 | import com.android.tradefed.config.Option; |
| 21 | import com.android.tradefed.config.Option.Importance; |
| 22 | import com.android.tradefed.config.OptionClass; |
| 23 | import com.android.tradefed.device.DeviceNotAvailableException; |
| 24 | import com.android.tradefed.result.BugreportCollector; |
| 25 | import com.android.tradefed.result.BugreportCollector.Freq; |
| 26 | import com.android.tradefed.result.BugreportCollector.Noun; |
| 27 | import com.android.tradefed.result.BugreportCollector.Predicate; |
| 28 | import com.android.tradefed.result.BugreportCollector.Relation; |
| 29 | import com.android.tradefed.result.DeviceFileReporter; |
| 30 | import com.android.tradefed.result.ITestInvocationListener; |
| 31 | import com.android.tradefed.result.LogDataType; |
Omari Stephens | cb76e3a | 2012-03-19 20:12:41 -0700 | [diff] [blame^] | 32 | import com.android.tradefed.result.NameMangleListener; |
Omari Stephens | 7ddc62b | 2012-02-27 21:18:58 -0800 | [diff] [blame] | 33 | import com.android.tradefed.testtype.InstrumentationTest; |
| 34 | |
| 35 | import java.util.LinkedHashMap; |
| 36 | import java.util.Map; |
| 37 | |
| 38 | /** |
| 39 | * A test that runs the smoke tests |
| 40 | * <p /> |
| 41 | * Simply {@link InstrumentationTest} with extra reporting. Should be re-integrated with |
| 42 | * {@link InstrumentationTest} after it's clear that it works as expected. |
| 43 | */ |
| 44 | @OptionClass(alias = "smoke") |
| 45 | public class SmokeTest extends InstrumentationTest { |
| 46 | @Option(name = "capture-file-pattern", description = "File glob of on-device files to log " + |
| 47 | "if found. Takes two arguments: the glob, and the file type " + |
| 48 | "(text/xml/zip/gzip/png/unknown). May be repeated.", importance = Importance.IF_UNSET) |
| 49 | private Map<String, LogDataType> mUploadFilePatterns = new LinkedHashMap<String, LogDataType>(); |
| 50 | |
| 51 | /** |
| 52 | * {@inheritDoc} |
| 53 | */ |
| 54 | @Override |
| 55 | public void run(final ITestInvocationListener listener) throws DeviceNotAvailableException { |
Omari Stephens | cb76e3a | 2012-03-19 20:12:41 -0700 | [diff] [blame^] | 56 | // trimListener should be the first thing to receive any results. It will pass the results |
| 57 | // through to the bugListener, which will forward them (after collecting any necessary |
| 58 | // bugreports) to the real Listener(s). |
Omari Stephens | 7ddc62b | 2012-02-27 21:18:58 -0800 | [diff] [blame] | 59 | final BugreportCollector bugListener = new BugreportCollector(listener, getDevice()); |
| 60 | bugListener.addPredicate(BugreportCollector.AFTER_FAILED_TESTCASES); |
Omari Stephens | cb76e3a | 2012-03-19 20:12:41 -0700 | [diff] [blame^] | 61 | final ITestInvocationListener trimListener = new TrimListener(bugListener); |
Omari Stephens | 7ddc62b | 2012-02-27 21:18:58 -0800 | [diff] [blame] | 62 | |
Omari Stephens | cb76e3a | 2012-03-19 20:12:41 -0700 | [diff] [blame^] | 63 | super.run(trimListener); |
Omari Stephens | 7ddc62b | 2012-02-27 21:18:58 -0800 | [diff] [blame] | 64 | |
Omari Stephens | cb76e3a | 2012-03-19 20:12:41 -0700 | [diff] [blame^] | 65 | final DeviceFileReporter dfr = new DeviceFileReporter(getDevice(), trimListener); |
Omari Stephens | 7ddc62b | 2012-02-27 21:18:58 -0800 | [diff] [blame] | 66 | dfr.addPatterns(mUploadFilePatterns); |
| 67 | dfr.run(); |
| 68 | } |
| 69 | |
Omari Stephens | cb76e3a | 2012-03-19 20:12:41 -0700 | [diff] [blame^] | 70 | /** |
| 71 | * A class to adjust the test identifiers from something like this: |
| 72 | * com.android.smoketest.SmokeTestRunner$3#com.android.voicedialer.VoiceDialerActivity |
| 73 | * To this: |
| 74 | * SmokeFAST#com.android.voicedialer.VoiceDialerActivity |
| 75 | */ |
| 76 | static class TrimListener extends NameMangleListener { |
| 77 | public TrimListener(ITestInvocationListener listener) { |
| 78 | super(listener); |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * {@inheritDoc} |
| 83 | */ |
| 84 | @Override |
| 85 | protected TestIdentifier mangleTestId(TestIdentifier test) { |
| 86 | final String method = test.getTestName(); |
| 87 | final String klass = test.getClassName().replaceFirst( |
| 88 | "com.android.smoketest.SmokeTestRunner(?:\\$\\d+)?", "SmokeFAST"); |
| 89 | return new TestIdentifier(klass, method); |
| 90 | } |
| 91 | } |
Omari Stephens | 7ddc62b | 2012-02-27 21:18:58 -0800 | [diff] [blame] | 92 | } |
| 93 | |