2 * Copyright (C) 2008 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.smoketest;
19 import com.android.internal.os.RuntimeInit;
21 import android.app.ActivityManager;
22 import android.content.Context;
23 import android.test.AndroidTestCase;
24 import android.util.Log;
26 import java.util.Iterator;
27 import java.util.List;
30 * This smoke test is designed to quickly sniff for any error conditions
31 * encountered after initial startup.
33 public class ProcessErrorsTest extends AndroidTestCase {
35 private final String TAG = "ProcessErrorsTest";
37 protected ActivityManager mActivityManager;
40 public void setUp() throws Exception {
42 mActivityManager = (ActivityManager)
43 getContext().getSystemService(Context.ACTIVITY_SERVICE);
46 public void testSetUpConditions() throws Exception {
47 assertNotNull(mActivityManager);
50 public void testNoProcessErrors() throws Exception {
51 List<ActivityManager.ProcessErrorStateInfo> errList;
52 errList = mActivityManager.getProcessesInErrorState();
54 // note: this contains information about each process that is currently in an error
55 // condition. if the list is empty (null) then "we're good".
57 // if the list is non-empty, then it's useful to report the contents of the list
58 // we'll put a copy in the log, and we'll report it back to the framework via the assert.
59 final String reportMsg = reportListContents(errList);
60 if (reportMsg != null) {
61 Log.w(TAG, reportMsg);
64 // report a non-empty list back to the test framework
65 assertNull(reportMsg, errList);
69 * This helper function will dump the actual error reports.
71 * @param errList The error report containing one or more error records.
72 * @return Returns a string containing all of the errors.
74 private String reportListContents(List<ActivityManager.ProcessErrorStateInfo> errList) {
75 if (errList == null) return null;
77 StringBuilder builder = new StringBuilder();
79 Iterator<ActivityManager.ProcessErrorStateInfo> iter = errList.iterator();
80 while (iter.hasNext()) {
81 ActivityManager.ProcessErrorStateInfo entry = iter.next();
84 switch (entry.condition) {
85 case ActivityManager.ProcessErrorStateInfo.CRASHED:
86 condition = "CRASHED";
88 case ActivityManager.ProcessErrorStateInfo.NOT_RESPONDING:
92 condition = "<unknown>";
96 builder.append("Process error ").append(condition).append(" ");
97 builder.append(" ").append(entry.shortMsg);
98 builder.append(" detected in ").append(entry.processName).append(" ").append(entry.tag);
100 return builder.toString();