blob: eaa3217023e9bbcedb14edbd31202ad85ebdda0b [file] [log] [blame]
Omari Stephens7ddc62b2012-02-27 21:18:58 -08001/*
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
17package com.android.continuous;
18
Omari Stephenscb76e3a2012-03-19 20:12:41 -070019import com.android.ddmlib.testrunner.TestIdentifier;
Omari Stephens7ddc62b2012-02-27 21:18:58 -080020import com.android.tradefed.config.Option;
21import com.android.tradefed.config.Option.Importance;
22import com.android.tradefed.config.OptionClass;
23import com.android.tradefed.device.DeviceNotAvailableException;
24import com.android.tradefed.result.BugreportCollector;
25import com.android.tradefed.result.BugreportCollector.Freq;
26import com.android.tradefed.result.BugreportCollector.Noun;
27import com.android.tradefed.result.BugreportCollector.Predicate;
28import com.android.tradefed.result.BugreportCollector.Relation;
29import com.android.tradefed.result.DeviceFileReporter;
30import com.android.tradefed.result.ITestInvocationListener;
31import com.android.tradefed.result.LogDataType;
Omari Stephenscb76e3a2012-03-19 20:12:41 -070032import com.android.tradefed.result.NameMangleListener;
Omari Stephens7ddc62b2012-02-27 21:18:58 -080033import com.android.tradefed.testtype.InstrumentationTest;
34
35import java.util.LinkedHashMap;
36import 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")
45public 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 Stephenscb76e3a2012-03-19 20:12:41 -070056 // 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 Stephens7ddc62b2012-02-27 21:18:58 -080059 final BugreportCollector bugListener = new BugreportCollector(listener, getDevice());
60 bugListener.addPredicate(BugreportCollector.AFTER_FAILED_TESTCASES);
Omari Stephenscb76e3a2012-03-19 20:12:41 -070061 final ITestInvocationListener trimListener = new TrimListener(bugListener);
Omari Stephens7ddc62b2012-02-27 21:18:58 -080062
Omari Stephenscb76e3a2012-03-19 20:12:41 -070063 super.run(trimListener);
Omari Stephens7ddc62b2012-02-27 21:18:58 -080064
Omari Stephenscb76e3a2012-03-19 20:12:41 -070065 final DeviceFileReporter dfr = new DeviceFileReporter(getDevice(), trimListener);
Omari Stephens7ddc62b2012-02-27 21:18:58 -080066 dfr.addPatterns(mUploadFilePatterns);
67 dfr.run();
68 }
69
Omari Stephenscb76e3a2012-03-19 20:12:41 -070070 /**
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 Stephens7ddc62b2012-02-27 21:18:58 -080092}
93