Skip to content

Commit 2effa64

Browse files
author
Maxim Siniavine
committed
Fixed MemoryUsage issue with reporting results.
When the memory of the application did not stabilize within the time limit, the test would report that using the application name, instead of the result key. Fixed the test to always use the result key. Change-Id: Ie16969e831bd3d89ee0496b992568f52bf1989cb
1 parent 0c9278d commit 2effa64

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

tests/MemoryUsage/src/com/android/tests/memoryusage/MemoryUsageTest.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ public class MemoryUsageTest extends InstrumentationTestCase {
5454
private static final String TAG = "MemoryUsageInstrumentation";
5555
private static final String KEY_APPS = "apps";
5656

57-
private Map<String, Intent> nameToIntent;
58-
private Map<String, String> nameToProcess;
59-
private Map<String, String> nameToResultKey;
57+
private Map<String, Intent> mNameToIntent;
58+
private Map<String, String> mNameToProcess;
59+
private Map<String, String> mNameToResultKey;
6060

6161
public void testMemory() {
6262
MemoryUsageInstrumentation instrumentation =
@@ -67,7 +67,7 @@ public void testMemory() {
6767
parseArgs(args);
6868

6969
Bundle results = new Bundle();
70-
for (String app : nameToResultKey.keySet()) {
70+
for (String app : mNameToResultKey.keySet()) {
7171
String processName;
7272
try {
7373
processName = startApp(app);
@@ -81,7 +81,7 @@ public void testMemory() {
8181
}
8282

8383
private void parseArgs(Bundle args) {
84-
nameToResultKey = new HashMap<String, String>();
84+
mNameToResultKey = new HashMap<String, String>();
8585
String appList = args.getString(KEY_APPS);
8686

8787
if (appList == null)
@@ -95,13 +95,13 @@ private void parseArgs(Bundle args) {
9595
fail();
9696
}
9797

98-
nameToResultKey.put(parts[0], parts[1]);
98+
mNameToResultKey.put(parts[0], parts[1]);
9999
}
100100
}
101101

102102
private void createMappings() {
103-
nameToIntent = new HashMap<String, Intent>();
104-
nameToProcess = new HashMap<String, String>();
103+
mNameToIntent = new HashMap<String, Intent>();
104+
mNameToProcess = new HashMap<String, String>();
105105

106106
PackageManager pm = getInstrumentation().getContext()
107107
.getPackageManager();
@@ -120,8 +120,8 @@ private void createMappings() {
120120
| Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
121121
startIntent.setClassName(ri.activityInfo.packageName,
122122
ri.activityInfo.name);
123-
nameToIntent.put(ri.loadLabel(pm).toString(), startIntent);
124-
nameToProcess.put(ri.loadLabel(pm).toString(),
123+
mNameToIntent.put(ri.loadLabel(pm).toString(), startIntent);
124+
mNameToProcess.put(ri.loadLabel(pm).toString(),
125125
ri.activityInfo.processName);
126126
}
127127
}
@@ -130,11 +130,11 @@ private void createMappings() {
130130
private String startApp(String appName) throws NameNotFoundException {
131131
Log.i(TAG, "Starting " + appName);
132132

133-
if (!nameToProcess.containsKey(appName))
133+
if (!mNameToProcess.containsKey(appName))
134134
throw new NameNotFoundException("Could not find: " + appName);
135135

136-
String process = nameToProcess.get(appName);
137-
Intent startIntent = nameToIntent.get(appName);
136+
String process = mNameToProcess.get(appName);
137+
Intent startIntent = mNameToIntent.get(appName);
138138
getInstrumentation().getContext().startActivity(startIntent);
139139
return process;
140140
}
@@ -154,14 +154,14 @@ private void measureMemory(String appName, String processName,
154154
}
155155
pssData.add(pss);
156156
if (iteration >= MIN_ITERATIONS && stabilized(pssData)) {
157-
results.putInt(nameToResultKey.get(appName), pss);
157+
results.putInt(mNameToResultKey.get(appName), pss);
158158
return;
159159
}
160160
iteration++;
161161
}
162162

163163
Log.w(TAG, appName + " memory usage did not stabilize");
164-
results.putInt(appName, average(pssData));
164+
results.putInt(mNameToResultKey.get(appName), average(pssData));
165165
}
166166

167167
private int average(List<Integer> pssData) {
@@ -202,12 +202,12 @@ private void reportError(String appName, String processName, Bundle results) {
202202
continue;
203203

204204
Log.w(TAG, appName + " crashed: " + crash.shortMsg);
205-
results.putString(nameToResultKey.get(appName), crash.shortMsg);
205+
results.putString(mNameToResultKey.get(appName), crash.shortMsg);
206206
return;
207207
}
208208
}
209209

210-
results.putString(nameToResultKey.get(appName),
210+
results.putString(mNameToResultKey.get(appName),
211211
"Crashed for unknown reason");
212212
Log.w(TAG, appName
213213
+ " not found in process list, most likely it is crashed");

0 commit comments

Comments
 (0)