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
17package com.android.smoketest;
18
19import android.app.ActivityManager;
20import android.app.ActivityManager.ProcessErrorStateInfo;
21import android.content.pm.PackageManager;
22import android.content.pm.ResolveInfo;
23import android.test.InstrumentationTestRunner;
24
25import junit.framework.TestCase;
26import junit.framework.TestSuite;
27
28import java.util.Collection;
29import java.util.HashSet;
30import java.util.List;
31import java.util.Set;
32
33/**
34 * A special test runner which does a test-start for each app in a separate testcase
35 */
36public class SmokeTestRunner extends InstrumentationTestRunner {
37
38    private static final String SUITE_NAME = "Smoke Test Suite";
39
40    /**
41     * Returns a single testcase for each app to launch
42     */
43    @Override
44    public TestSuite getAllTests() {
45        final TestSuite suite = new TestSuite(SUITE_NAME);
46
47        final PackageManager pm = getTargetContext().getPackageManager();
48        final List<ResolveInfo> apps = ProcessErrorsTest.getLauncherActivities(pm);
49
50        final TestCase setupTest = new ProcessErrorsTest() {
51            @Override
52            public void runTest() throws Exception {
53                testSetUpConditions();
54            }
55        };
56        setupTest.setName("testSetUpConditions");
57        suite.addTest(setupTest);
58
59        final TestCase postBootTest = new ProcessErrorsTest() {
60            @Override
61            public void runTest() throws Exception {
62                testNoProcessErrorsAfterBoot();
63            }
64        };
65        postBootTest.setName("testNoProcessErrorsAfterBoot");
66        suite.addTest(postBootTest);
67
68        for (final ResolveInfo app : apps) {
69            final TestCase appTest = new ProcessErrorsTest() {
70                @Override
71                public void runTest() throws Exception {
72                    final Set<ProcessError> errSet = new HashSet<ProcessError>();
73                    final Collection<ProcessError> errProcs = runOneActivity(app);
74                    if (errProcs != null) {
75                        errSet.addAll(errProcs);
76                    }
77
78                    if (!errSet.isEmpty()) {
79                        fail(String.format("Got %d errors:\n%s", errSet.size(),
80                                reportWrappedListContents(errSet)));
81                    }
82                }
83            };
84            appTest.setName(app.activityInfo.name);
85            suite.addTest(appTest);
86        }
87
88        final TestCase asyncErrorTest = new ProcessErrorsTest() {
89            @Override
90            public void runTest() throws Exception {
91                testZZReportAsyncErrors();
92            }
93        };
94        asyncErrorTest.setName("testAsynchronousErrors");
95        suite.addTest(asyncErrorTest);
96
97        return suite;
98    }
99}
100
101