• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 package com.android.loganalysis.parser;
17 
18 import com.android.loganalysis.item.AnrItem;
19 import com.android.loganalysis.item.JavaCrashItem;
20 import com.android.loganalysis.item.MonkeyLogItem;
21 import com.android.loganalysis.item.MonkeyLogItem.DroppedCategory;
22 import com.android.loganalysis.item.NativeCrashItem;
23 import com.android.loganalysis.util.ArrayUtil;
24 
25 import junit.framework.TestCase;
26 
27 import java.text.DateFormat;
28 import java.text.ParseException;
29 import java.text.SimpleDateFormat;
30 import java.util.Arrays;
31 import java.util.Date;
32 import java.util.List;
33 
34 /**
35  * Unit tests for {@link MonkeyLogParser}
36  */
37 public class MonkeyLogParserTest extends TestCase {
38 
39     /**
40      * Test that a monkey can be parsed if there are no crashes.
41      */
testParse_success()42     public void testParse_success() {
43         List<String> lines = Arrays.asList(
44                 "# Wednesday, 04/25/2012 01:37:12 AM - device uptime = 242.13: Monkey command used for this test:",
45                 "adb shell monkey -p com.google.android.browser  -c android.intent.category.SAMPLE_CODE -c android.intent.category.CAR_DOCK -c android.intent.category.LAUNCHER -c android.intent.category.MONKEY -c android.intent.category.INFO  --ignore-security-exceptions --throttle 100  -s 528 -v -v -v 10000 ",
46                 "",
47                 ":Monkey: seed=528 count=10000",
48                 ":AllowPackage: com.google.android.browser",
49                 ":IncludeCategory: android.intent.category.LAUNCHER",
50                 ":Switch: #Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10200000;component=com.google.android.browser/com.android.browser.BrowserActivity;end",
51                 "    // Allowing start of Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.google.android.browser/com.android.browser.BrowserActivity } in package com.google.android.browser",
52                 "Sleeping for 100 milliseconds",
53                 ":Sending Key (ACTION_DOWN): 23    // KEYCODE_DPAD_CENTER",
54                 ":Sending Key (ACTION_UP): 23    // KEYCODE_DPAD_CENTER",
55                 "Sleeping for 100 milliseconds",
56                 ":Sending Trackball (ACTION_MOVE): 0:(-5.0,3.0)",
57                 ":Sending Trackball (ACTION_MOVE): 0:(3.0,3.0)",
58                 ":Sending Trackball (ACTION_MOVE): 0:(-1.0,3.0)",
59                 ":Sending Trackball (ACTION_MOVE): 0:(4.0,-2.0)",
60                 ":Sending Trackball (ACTION_MOVE): 0:(1.0,4.0)",
61                 ":Sending Trackball (ACTION_MOVE): 0:(-4.0,2.0)",
62                 "    //[calendar_time:2012-04-25 01:42:20.140  system_uptime:535179]",
63                 "    // Sending event #9900",
64                 ":Sending Trackball (ACTION_MOVE): 0:(2.0,-4.0)",
65                 ":Sending Trackball (ACTION_MOVE): 0:(-2.0,0.0)",
66                 ":Sending Trackball (ACTION_MOVE): 0:(2.0,2.0)",
67                 ":Sending Trackball (ACTION_MOVE): 0:(-5.0,4.0)",
68                 "Events injected: 10000",
69                 ":Dropped: keys=5 pointers=6 trackballs=7 flips=8 rotations=9",
70                 "// Monkey finished",
71                 "",
72                 "# Wednesday, 04/25/2012 01:42:09 AM - device uptime = 539.21: Monkey command ran for: 04:57 (mm:ss)",
73                 "",
74                 "----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------");
75 
76         MonkeyLogItem monkeyLog = new MonkeyLogParser().parse(lines);
77         assertNotNull(monkeyLog);
78         // FIXME: Add test back once time situation has been worked out.
79         // assertEquals(parseTime("2012-04-25 01:37:12"), monkeyLog.getStartTime());
80         // assertEquals(parseTime("2012-04-25 01:42:09"), monkeyLog.getStopTime());
81         assertEquals(1, monkeyLog.getPackages().size());
82         assertTrue(monkeyLog.getPackages().contains("com.google.android.browser"));
83         assertEquals(1, monkeyLog.getCategories().size());
84         assertTrue(monkeyLog.getCategories().contains("android.intent.category.LAUNCHER"));
85         assertEquals(100, monkeyLog.getThrottle());
86         assertEquals(528, monkeyLog.getSeed().intValue());
87         assertEquals(10000, monkeyLog.getTargetCount().intValue());
88         assertTrue(monkeyLog.getIgnoreSecurityExceptions());
89         assertEquals(4 * 60 * 1000 + 57 * 1000, monkeyLog.getTotalDuration().longValue());
90         assertEquals(242130, monkeyLog.getStartUptimeDuration().longValue());
91         assertEquals(539210, monkeyLog.getStopUptimeDuration().longValue());
92         assertTrue(monkeyLog.getIsFinished());
93         assertFalse(monkeyLog.getNoActivities());
94         assertEquals(9900, monkeyLog.getIntermediateCount());
95         assertEquals(10000, monkeyLog.getFinalCount().intValue());
96         assertEquals(5, monkeyLog.getDroppedCount(DroppedCategory.KEYS).intValue());
97         assertEquals(6, monkeyLog.getDroppedCount(DroppedCategory.POINTERS).intValue());
98         assertEquals(7, monkeyLog.getDroppedCount(DroppedCategory.TRACKBALLS).intValue());
99         assertEquals(8, monkeyLog.getDroppedCount(DroppedCategory.FLIPS).intValue());
100         assertEquals(9, monkeyLog.getDroppedCount(DroppedCategory.ROTATIONS).intValue());
101         assertNull(monkeyLog.getCrash());
102     }
103 
104     /**
105      * Test that a monkey can be parsed if there is an ANR.
106      */
testParse_anr()107     public void testParse_anr() {
108         List<String> lines = Arrays.asList(
109                 "# Tuesday, 04/24/2012 05:23:30 PM - device uptime = 216.48: Monkey command used for this test:",
110                 "adb shell monkey -p com.google.android.youtube  -c android.intent.category.SAMPLE_CODE -c android.intent.category.CAR_DOCK -c android.intent.category.LAUNCHER -c android.intent.category.MONKEY -c android.intent.category.INFO  --ignore-security-exceptions --throttle 100  -s 993 -v -v -v 10000 ",
111                 "",
112                 ":Monkey: seed=993 count=10000",
113                 ":AllowPackage: com.google.android.youtube",
114                 ":IncludeCategory: android.intent.category.LAUNCHER",
115                 ":Switch: #Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10200000;component=com.google.android.youtube/.app.honeycomb.Shell%24HomeActivity;end",
116                 "    // Allowing start of Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.google.android.youtube/.app.honeycomb.Shell$HomeActivity } in package com.google.android.youtube",
117                 "Sleeping for 100 milliseconds",
118                 ":Sending Key (ACTION_UP): 21    // KEYCODE_DPAD_LEFT",
119                 "Sleeping for 100 milliseconds",
120                 ":Sending Key (ACTION_DOWN): 22    // KEYCODE_DPAD_RIGHT",
121                 ":Sending Key (ACTION_UP): 22    // KEYCODE_DPAD_RIGHT",
122                 "    //[calendar_time:2012-04-25 00:27:27.155  system_uptime:454996]",
123                 "    // Sending event #5300",
124                 ":Sending Key (ACTION_UP): 19    // KEYCODE_DPAD_UP",
125                 "Sleeping for 100 milliseconds",
126                 ":Sending Trackball (ACTION_MOVE): 0:(4.0,3.0)",
127                 ":Sending Key (ACTION_DOWN): 20    // KEYCODE_DPAD_DOWN",
128                 ":Sending Key (ACTION_UP): 20    // KEYCODE_DPAD_DOWN",
129                 "// NOT RESPONDING: com.google.android.youtube (pid 3301)",
130                 "ANR in com.google.android.youtube (com.google.android.youtube/.app.honeycomb.phone.WatchActivity)",
131                 "Reason: keyDispatchingTimedOut",
132                 "Load: 1.0 / 1.05 / 0.6",
133                 "CPU usage from 4794ms to -1502ms ago with 99% awake:",
134                 "  18% 3301/com.google.android.youtube: 16% user + 2.3% kernel / faults: 268 minor 9 major",
135                 "  13% 313/system_server: 9.2% user + 4.4% kernel / faults: 906 minor 3 major",
136                 "  10% 117/surfaceflinger: 4.9% user + 5.5% kernel / faults: 1 minor",
137                 "  10% 120/mediaserver: 6.8% user + 3.6% kernel / faults: 1189 minor",
138                 "34% TOTAL: 19% user + 13% kernel + 0.2% iowait + 1% softirq",
139                 "",
140                 "procrank:",
141                 "// procrank status was 0",
142                 "anr traces:",
143                 "",
144                 "",
145                 "----- pid 2887 at 2012-04-25 17:17:08 -----",
146                 "Cmd line: com.google.android.youtube",
147                 "",
148                 "DALVIK THREADS:",
149                 "(mutexes: tll=0 tsl=0 tscl=0 ghl=0)",
150                 "",
151                 "\"main\" prio=5 tid=1 SUSPENDED",
152                 "  | group=\"main\" sCount=1 dsCount=0 obj=0x00000001 self=0x00000001",
153                 "  | sysTid=2887 nice=0 sched=0/0 cgrp=foreground handle=0000000001",
154                 "  | schedstat=( 0 0 0 ) utm=5954 stm=1017 core=0",
155                 "  at class.method1(Class.java:1)",
156                 "  at class.method2(Class.java:2)",
157                 "  at class.method2(Class.java:2)",
158                 "",
159                 "----- end 2887 -----",
160                 "// anr traces status was 0",
161                 "** Monkey aborted due to error.",
162                 "Events injected: 5322",
163                 ":Sending rotation degree=0, persist=false",
164                 ":Dropped: keys=1 pointers=0 trackballs=0 flips=0 rotations=0",
165                 "## Network stats: elapsed time=252942ms (0ms mobile, 252942ms wifi, 0ms not connected)",
166                 "** System appears to have crashed at event 5322 of 10000 using seed 993",
167                 "",
168                 "# Tuesday, 04/24/2012 05:27:44 PM - device uptime = 471.37: Monkey command ran for: 04:14 (mm:ss)",
169                 "",
170                 "----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------",
171                 "");
172 
173         List<String> expectedStack = Arrays.asList(
174                 "\"main\" prio=5 tid=1 SUSPENDED",
175                 "  | group=\"main\" sCount=1 dsCount=0 obj=0x00000001 self=0x00000001",
176                 "  | sysTid=2887 nice=0 sched=0/0 cgrp=foreground handle=0000000001",
177                 "  | schedstat=( 0 0 0 ) utm=5954 stm=1017 core=0",
178                 "  at class.method1(Class.java:1)",
179                 "  at class.method2(Class.java:2)",
180                 "  at class.method2(Class.java:2)");
181 
182         MonkeyLogItem monkeyLog = new MonkeyLogParser().parse(lines);
183         assertNotNull(monkeyLog);
184         // FIXME: Add test back once time situation has been worked out.
185         // assertEquals(parseTime("2012-04-24 17:23:30"), monkeyLog.getStartTime());
186         // assertEquals(parseTime("2012-04-24 17:27:44"), monkeyLog.getStopTime());
187         assertEquals(1, monkeyLog.getPackages().size());
188         assertTrue(monkeyLog.getPackages().contains("com.google.android.youtube"));
189         assertEquals(1, monkeyLog.getCategories().size());
190         assertTrue(monkeyLog.getCategories().contains("android.intent.category.LAUNCHER"));
191         assertEquals(100, monkeyLog.getThrottle());
192         assertEquals(993, monkeyLog.getSeed().intValue());
193         assertEquals(10000, monkeyLog.getTargetCount().intValue());
194         assertTrue(monkeyLog.getIgnoreSecurityExceptions());
195         assertEquals(4 * 60 * 1000 + 14 * 1000, monkeyLog.getTotalDuration().longValue());
196         assertEquals(216480, monkeyLog.getStartUptimeDuration().longValue());
197         assertEquals(471370, monkeyLog.getStopUptimeDuration().longValue());
198         assertFalse(monkeyLog.getIsFinished());
199         assertFalse(monkeyLog.getNoActivities());
200         assertEquals(5300, monkeyLog.getIntermediateCount());
201         assertEquals(5322, monkeyLog.getFinalCount().intValue());
202         assertNotNull(monkeyLog.getCrash());
203         assertTrue(monkeyLog.getCrash() instanceof AnrItem);
204         assertEquals("com.google.android.youtube", monkeyLog.getCrash().getApp());
205         assertEquals(3301, monkeyLog.getCrash().getPid().intValue());
206         assertEquals("keyDispatchingTimedOut", ((AnrItem) monkeyLog.getCrash()).getReason());
207         assertEquals(ArrayUtil.join("\n", expectedStack),
208                 ((AnrItem) monkeyLog.getCrash()).getTrace());
209     }
210 
211     /**
212      * Test that a monkey can be parsed if there is a Java crash.
213      */
testParse_java_crash()214     public void testParse_java_crash() {
215         List<String> lines = Arrays.asList(
216                 "# Tuesday, 04/24/2012 05:05:50 PM - device uptime = 232.65: Monkey command used for this test:",
217                 "adb shell monkey -p com.google.android.apps.maps  -c android.intent.category.SAMPLE_CODE -c android.intent.category.CAR_DOCK -c android.intent.category.LAUNCHER -c android.intent.category.MONKEY -c android.intent.category.INFO  --ignore-security-exceptions --throttle 100  -s 501 -v -v -v 10000 ",
218                 "",
219                 ":Monkey: seed=501 count=10000",
220                 ":AllowPackage: com.google.android.apps.maps",
221                 ":IncludeCategory: android.intent.category.LAUNCHER",
222                 ":Switch: #Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10200000;component=com.google.android.apps.maps/com.google.android.maps.LatitudeActivity;end",
223                 "    // Allowing start of Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.google.android.apps.maps/com.google.android.maps.LatitudeActivity } in package com.google.android.apps.maps",
224                 "Sleeping for 100 milliseconds",
225                 ":Sending Touch (ACTION_DOWN): 0:(332.0,70.0)",
226                 ":Sending Touch (ACTION_UP): 0:(332.55292,76.54678)",
227                 "    //[calendar_time:2012-04-25 00:06:38.419  system_uptime:280799]",
228                 "    // Sending event #1600",
229                 ":Sending Touch (ACTION_MOVE): 0:(1052.2666,677.64594)",
230                 ":Sending Touch (ACTION_UP): 0:(1054.7593,687.3757)",
231                 "Sleeping for 100 milliseconds",
232                 "// CRASH: com.google.android.apps.maps (pid 3161)",
233                 "// Short Msg: java.lang.Exception",
234                 "// Long Msg: java.lang.Exception: This is the message",
235                 "// Build Label: google/yakju/maguro:JellyBean/JRN24B/338896:userdebug/dev-keys",
236                 "// Build Changelist: 338896",
237                 "// Build Time: 1335309051000",
238                 "// java.lang.Exception: This is the message",
239                 "// \tat class.method1(Class.java:1)",
240                 "// \tat class.method2(Class.java:2)",
241                 "// \tat class.method3(Class.java:3)",
242                 "// ",
243                 "** Monkey aborted due to error.",
244                 "Events injected: 1649",
245                 ":Sending rotation degree=0, persist=false",
246                 ":Dropped: keys=0 pointers=0 trackballs=0 flips=0 rotations=0",
247                 "## Network stats: elapsed time=48897ms (0ms mobile, 48897ms wifi, 0ms not connected)",
248                 "** System appears to have crashed at event 1649 of 10000 using seed 501",
249                 "",
250                 "# Tuesday, 04/24/2012 05:06:40 PM - device uptime = 282.53: Monkey command ran for: 00:49 (mm:ss)",
251                 "",
252                 "----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------",
253                 "");
254 
255         MonkeyLogItem monkeyLog = new MonkeyLogParser().parse(lines);
256         assertNotNull(monkeyLog);
257         // FIXME: Add test back once time situation has been worked out.
258         // assertEquals(parseTime("2012-04-24 17:05:50"), monkeyLog.getStartTime());
259         // assertEquals(parseTime("2012-04-24 17:06:40"), monkeyLog.getStopTime());
260         assertEquals(1, monkeyLog.getPackages().size());
261         assertTrue(monkeyLog.getPackages().contains("com.google.android.apps.maps"));
262         assertEquals(1, monkeyLog.getCategories().size());
263         assertTrue(monkeyLog.getCategories().contains("android.intent.category.LAUNCHER"));
264         assertEquals(100, monkeyLog.getThrottle());
265         assertEquals(501, monkeyLog.getSeed().intValue());
266         assertEquals(10000, monkeyLog.getTargetCount().intValue());
267         assertTrue(monkeyLog.getIgnoreSecurityExceptions());
268         assertEquals(49 * 1000, monkeyLog.getTotalDuration().longValue());
269         assertEquals(232650, monkeyLog.getStartUptimeDuration().longValue());
270         assertEquals(282530, monkeyLog.getStopUptimeDuration().longValue());
271         assertFalse(monkeyLog.getIsFinished());
272         assertFalse(monkeyLog.getNoActivities());
273         assertEquals(1600, monkeyLog.getIntermediateCount());
274         assertEquals(1649, monkeyLog.getFinalCount().intValue());
275         assertNotNull(monkeyLog.getCrash());
276         assertTrue(monkeyLog.getCrash() instanceof JavaCrashItem);
277         assertEquals("com.google.android.apps.maps", monkeyLog.getCrash().getApp());
278         assertEquals(3161, monkeyLog.getCrash().getPid().intValue());
279         assertEquals("java.lang.Exception", ((JavaCrashItem) monkeyLog.getCrash()).getException());
280     }
281 
282     /**
283      * Test that a monkey can be parsed if there is a Java crash even if monkey lines are mixed in
284      * the crash.
285      */
testParse_java_crash_mixed()286     public void testParse_java_crash_mixed() {
287         List<String> lines = Arrays.asList(
288                 "# Tuesday, 04/24/2012 05:05:50 PM - device uptime = 232.65: Monkey command used for this test:",
289                 "adb shell monkey -p com.google.android.apps.maps  -c android.intent.category.SAMPLE_CODE -c android.intent.category.CAR_DOCK -c android.intent.category.LAUNCHER -c android.intent.category.MONKEY -c android.intent.category.INFO  --ignore-security-exceptions --throttle 100  -s 501 -v -v -v 10000 ",
290                 "",
291                 ":Monkey: seed=501 count=10000",
292                 ":AllowPackage: com.google.android.apps.maps",
293                 ":IncludeCategory: android.intent.category.LAUNCHER",
294                 ":Switch: #Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10200000;component=com.google.android.apps.maps/com.google.android.maps.LatitudeActivity;end",
295                 "    // Allowing start of Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.google.android.apps.maps/com.google.android.maps.LatitudeActivity } in package com.google.android.apps.maps",
296                 "Sleeping for 100 milliseconds",
297                 ":Sending Touch (ACTION_DOWN): 0:(332.0,70.0)",
298                 ":Sending Touch (ACTION_UP): 0:(332.55292,76.54678)",
299                 "    //[calendar_time:2012-04-25 00:06:38.419  system_uptime:280799]",
300                 "    // Sending event #1600",
301                 ":Sending Touch (ACTION_MOVE): 0:(1052.2666,677.64594)",
302                 "// CRASH: com.google.android.apps.maps (pid 3161)",
303                 "// Short Msg: java.lang.Exception",
304                 ":Sending Touch (ACTION_UP): 0:(1054.7593,687.3757)",
305                 "// Long Msg: java.lang.Exception: This is the message",
306                 "// Build Label: google/yakju/maguro:JellyBean/JRN24B/338896:userdebug/dev-keys",
307                 "// Build Changelist: 338896",
308                 "Sleeping for 100 milliseconds",
309                 "// Build Time: 1335309051000",
310                 "// java.lang.Exception: This is the message",
311                 "// \tat class.method1(Class.java:1)",
312                 "// \tat class.method2(Class.java:2)",
313                 "// \tat class.method3(Class.java:3)",
314                 "// ",
315                 "** Monkey aborted due to error.",
316                 "Events injected: 1649",
317                 ":Sending rotation degree=0, persist=false",
318                 ":Dropped: keys=0 pointers=0 trackballs=0 flips=0 rotations=0",
319                 "## Network stats: elapsed time=48897ms (0ms mobile, 48897ms wifi, 0ms not connected)",
320                 "** System appears to have crashed at event 1649 of 10000 using seed 501",
321                 "",
322                 "# Tuesday, 04/24/2012 05:06:40 PM - device uptime = 282.53: Monkey command ran for: 00:49 (mm:ss)",
323                 "",
324                 "----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------",
325                 "");
326 
327         MonkeyLogItem monkeyLog = new MonkeyLogParser().parse(lines);
328         assertNotNull(monkeyLog);
329         // FIXME: Add test back once time situation has been worked out.
330         // assertEquals(parseTime("2012-04-24 17:05:50"), monkeyLog.getStartTime());
331         // assertEquals(parseTime("2012-04-24 17:06:40"), monkeyLog.getStopTime());
332         assertEquals(1, monkeyLog.getPackages().size());
333         assertTrue(monkeyLog.getPackages().contains("com.google.android.apps.maps"));
334         assertEquals(1, monkeyLog.getCategories().size());
335         assertTrue(monkeyLog.getCategories().contains("android.intent.category.LAUNCHER"));
336         assertEquals(100, monkeyLog.getThrottle());
337         assertEquals(501, monkeyLog.getSeed().intValue());
338         assertEquals(10000, monkeyLog.getTargetCount().intValue());
339         assertTrue(monkeyLog.getIgnoreSecurityExceptions());
340         assertEquals(49 * 1000, monkeyLog.getTotalDuration().longValue());
341         assertEquals(232650, monkeyLog.getStartUptimeDuration().longValue());
342         assertEquals(282530, monkeyLog.getStopUptimeDuration().longValue());
343         assertFalse(monkeyLog.getIsFinished());
344         assertFalse(monkeyLog.getNoActivities());
345         assertEquals(1600, monkeyLog.getIntermediateCount());
346         assertEquals(1649, monkeyLog.getFinalCount().intValue());
347         assertNotNull(monkeyLog.getCrash());
348         assertTrue(monkeyLog.getCrash() instanceof JavaCrashItem);
349         assertEquals("com.google.android.apps.maps", monkeyLog.getCrash().getApp());
350         assertEquals(3161, monkeyLog.getCrash().getPid().intValue());
351         assertEquals("java.lang.Exception", ((JavaCrashItem) monkeyLog.getCrash()).getException());
352     }
353 
354 
355     /**
356      * Test that a monkey can be parsed if there is a native crash.
357      */
testParse_native_crash()358     public void testParse_native_crash() {
359         List<String> lines = Arrays.asList(
360                 "# Tuesday, 04/24/2012 05:05:50 PM - device uptime = 232.65: Monkey command used for this test:",
361                 "adb shell monkey -p com.google.android.apps.maps  -c android.intent.category.SAMPLE_CODE -c android.intent.category.CAR_DOCK -c android.intent.category.LAUNCHER -c android.intent.category.MONKEY -c android.intent.category.INFO  --ignore-security-exceptions --throttle 100  -s 501 -v -v -v 10000 ",
362                 "",
363                 ":Monkey: seed=501 count=10000",
364                 ":AllowPackage: com.google.android.apps.maps",
365                 ":IncludeCategory: android.intent.category.LAUNCHER",
366                 ":Switch: #Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10200000;component=com.google.android.apps.maps/com.google.android.maps.LatitudeActivity;end",
367                 "    // Allowing start of Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.google.android.apps.maps/com.google.android.maps.LatitudeActivity } in package com.google.android.apps.maps",
368                 "Sleeping for 100 milliseconds",
369                 ":Sending Touch (ACTION_DOWN): 0:(332.0,70.0)",
370                 ":Sending Touch (ACTION_UP): 0:(332.55292,76.54678)",
371                 "    //[calendar_time:2012-04-25 00:06:38.419  system_uptime:280799]",
372                 "    // Sending event #1600",
373                 ":Sending Touch (ACTION_MOVE): 0:(1052.2666,677.64594)",
374                 ":Sending Touch (ACTION_UP): 0:(1054.7593,687.3757)",
375                 "Sleeping for 100 milliseconds",
376                 "// CRASH: com.android.chrome (pid 2162)",
377                 "// Short Msg: Native crash",
378                 "// Long Msg: Native crash: Segmentation fault",
379                 "// Build Label: google/mantaray/manta:JellyBeanMR2/JWR02/624470:userdebug/dev-keys",
380                 "// Build Changelist: 624470",
381                 "// Build Time: 1364920502000",
382                 "// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***",
383                 "// Build fingerprint: 'google/mantaray/manta:4.1/JRO01/12345:userdebug/dev-keys'",
384                 "// Revision: '7'",
385                 "// pid: 2162, tid: 2216, name: .android.chrome  >>> com.android.chrome <<<",
386                 "// signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr deadbaad",
387                 "//     r0 00000027  r1 00001000  r2 00000008  r3 deadbaad",
388                 "//     r4 00000000  r5 7af65e64  r6 00000000  r7 7af65ea4",
389                 "//     r8 401291f4  r9 00200000  sl 7784badc  fp 00001401",
390                 "//     ip 7af65ea4  sp 7af65e60  lr 400fed6b  pc 400fc2d4  cpsr 600f0030",
391                 "//     d0  3332303033312034  d1  6361707320737332",
392                 "//     d2  632e6c6f6f705f34  d3  205d29383231280a",
393                 "//     scr 60000010",
394                 "// ",
395                 "// backtrace:",
396                 "//     #00  pc 0001e2d4  /system/lib/libc.so",
397                 "//     #01  pc 0001c4bc  /system/lib/libc.so (abort+4)",
398                 "//     #02  pc 0023a515  /system/lib/libchromeview.so",
399                 "//     #03  pc 006f8a27  /system/lib/libchromeview.so",
400                 "// ",
401                 "// stack:",
402                 "//     7af65e20  77856cf8  ",
403                 "//     7af65e24  7af65e64  [stack:2216]",
404                 "//     7af65e28  00000014  ",
405                 "//     7af65e2c  76a88e6c  /system/lib/libchromeview.so",
406                 "** Monkey aborted due to error.",
407                 "Events injected: 1649",
408                 ":Sending rotation degree=0, persist=false",
409                 ":Dropped: keys=0 pointers=0 trackballs=0 flips=0 rotations=0",
410                 "## Network stats: elapsed time=48897ms (0ms mobile, 48897ms wifi, 0ms not connected)",
411                 "** System appears to have crashed at event 1649 of 10000 using seed 501",
412                 "",
413                 "# Tuesday, 04/24/2012 05:06:40 PM - device uptime = 282.53: Monkey command ran for: 00:49 (mm:ss)",
414                 "",
415                 "----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------",
416                 "");
417 
418         MonkeyLogItem monkeyLog = new MonkeyLogParser().parse(lines);
419         assertNotNull(monkeyLog);
420         // FIXME: Add test back once time situation has been worked out.
421         // assertEquals(parseTime("2012-04-24 17:05:50"), monkeyLog.getStartTime());
422         // assertEquals(parseTime("2012-04-24 17:06:40"), monkeyLog.getStopTime());
423         assertEquals(1, monkeyLog.getPackages().size());
424         assertTrue(monkeyLog.getPackages().contains("com.google.android.apps.maps"));
425         assertEquals(1, monkeyLog.getCategories().size());
426         assertTrue(monkeyLog.getCategories().contains("android.intent.category.LAUNCHER"));
427         assertEquals(100, monkeyLog.getThrottle());
428         assertEquals(501, monkeyLog.getSeed().intValue());
429         assertEquals(10000, monkeyLog.getTargetCount().intValue());
430         assertTrue(monkeyLog.getIgnoreSecurityExceptions());
431         assertEquals(49 * 1000, monkeyLog.getTotalDuration().longValue());
432         assertEquals(232650, monkeyLog.getStartUptimeDuration().longValue());
433         assertEquals(282530, monkeyLog.getStopUptimeDuration().longValue());
434         assertFalse(monkeyLog.getIsFinished());
435         assertFalse(monkeyLog.getNoActivities());
436         assertEquals(1600, monkeyLog.getIntermediateCount());
437         assertEquals(1649, monkeyLog.getFinalCount().intValue());
438         assertNotNull(monkeyLog.getCrash());
439         assertTrue(monkeyLog.getCrash() instanceof NativeCrashItem);
440         assertEquals("com.android.chrome", monkeyLog.getCrash().getApp());
441         assertEquals(2162, monkeyLog.getCrash().getPid().intValue());
442         assertEquals("google/mantaray/manta:4.1/JRO01/12345:userdebug/dev-keys",
443                 ((NativeCrashItem) monkeyLog.getCrash()).getFingerprint());
444         // Make sure that the entire stack is included.
445         assertEquals(23, ((NativeCrashItem) monkeyLog.getCrash()).getStack().split("\n").length);
446     }
447 
448     /**
449      * Test that a monkey can be parsed if there is a native crash with extra info at the end.
450      */
testParse_native_crash_strip_extra()451     public void testParse_native_crash_strip_extra() {
452         List<String> lines = Arrays.asList(
453                 "# Tuesday, 04/24/2012 05:05:50 PM - device uptime = 232.65: Monkey command used for this test:",
454                 "adb shell monkey -p com.google.android.apps.maps  -c android.intent.category.SAMPLE_CODE -c android.intent.category.CAR_DOCK -c android.intent.category.LAUNCHER -c android.intent.category.MONKEY -c android.intent.category.INFO  --ignore-security-exceptions --throttle 100  -s 501 -v -v -v 10000 ",
455                 "",
456                 ":Monkey: seed=501 count=10000",
457                 ":AllowPackage: com.google.android.apps.maps",
458                 ":IncludeCategory: android.intent.category.LAUNCHER",
459                 ":Switch: #Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10200000;component=com.google.android.apps.maps/com.google.android.maps.LatitudeActivity;end",
460                 "    // Allowing start of Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.google.android.apps.maps/com.google.android.maps.LatitudeActivity } in package com.google.android.apps.maps",
461                 "Sleeping for 100 milliseconds",
462                 ":Sending Touch (ACTION_DOWN): 0:(332.0,70.0)",
463                 ":Sending Touch (ACTION_UP): 0:(332.55292,76.54678)",
464                 "    //[calendar_time:2012-04-25 00:06:38.419  system_uptime:280799]",
465                 "    // Sending event #1600",
466                 ":Sending Touch (ACTION_MOVE): 0:(1052.2666,677.64594)",
467                 ":Sending Touch (ACTION_UP): 0:(1054.7593,687.3757)",
468                 "Sleeping for 100 milliseconds",
469                 "// CRASH: com.android.chrome (pid 2162)",
470                 "// Short Msg: Native crash",
471                 "// Long Msg: Native crash: Segmentation fault",
472                 "// Build Label: google/mantaray/manta:JellyBeanMR2/JWR02/624470:userdebug/dev-keys",
473                 "// Build Changelist: 624470",
474                 "// Build Time: 1364920502000",
475                 "// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***",
476                 "// Build fingerprint: 'google/mantaray/manta:4.1/JRO01/12345:userdebug/dev-keys'",
477                 "// Revision: '7'",
478                 "// pid: 2162, tid: 2216, name: .android.chrome  >>> com.android.chrome <<<",
479                 "// signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr deadbaad",
480                 "//     r0 00000027  r1 00001000  r2 00000008  r3 deadbaad",
481                 "//     r4 00000000  r5 7af65e64  r6 00000000  r7 7af65ea4",
482                 "//     r8 401291f4  r9 00200000  sl 7784badc  fp 00001401",
483                 "//     ip 7af65ea4  sp 7af65e60  lr 400fed6b  pc 400fc2d4  cpsr 600f0030",
484                 "//     d0  3332303033312034  d1  6361707320737332",
485                 "//     d2  632e6c6f6f705f34  d3  205d29383231280a",
486                 "//     scr 60000010",
487                 "// ",
488                 "// backtrace:",
489                 "//     #00  pc 0001e2d4  /system/lib/libc.so",
490                 "//     #01  pc 0001c4bc  /system/lib/libc.so (abort+4)",
491                 "//     #02  pc 0023a515  /system/lib/libchromeview.so",
492                 "//     #03  pc 006f8a27  /system/lib/libchromeview.so",
493                 "// ",
494                 "// stack:",
495                 "//     7af65e20  77856cf8  ",
496                 "//     7af65e24  7af65e64  [stack:2216]",
497                 "//     7af65e28  00000014  ",
498                 "//     7af65e2c  76a88e6c  /system/lib/libchromeview.so",
499                 "// ** New native crash detected.",
500                 "** Monkey aborted due to error.",
501                 "Events injected: 1649",
502                 ":Sending rotation degree=0, persist=false",
503                 ":Dropped: keys=0 pointers=0 trackballs=0 flips=0 rotations=0",
504                 "## Network stats: elapsed time=48897ms (0ms mobile, 48897ms wifi, 0ms not connected)",
505                 "** System appears to have crashed at event 1649 of 10000 using seed 501",
506                 "",
507                 "# Tuesday, 04/24/2012 05:06:40 PM - device uptime = 282.53: Monkey command ran for: 00:49 (mm:ss)",
508                 "",
509                 "----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------",
510                 "");
511 
512         MonkeyLogItem monkeyLog = new MonkeyLogParser().parse(lines);
513         assertNotNull(monkeyLog);
514         // FIXME: Add test back once time situation has been worked out.
515         // assertEquals(parseTime("2012-04-24 17:05:50"), monkeyLog.getStartTime());
516         // assertEquals(parseTime("2012-04-24 17:06:40"), monkeyLog.getStopTime());
517         assertEquals(1, monkeyLog.getPackages().size());
518         assertTrue(monkeyLog.getPackages().contains("com.google.android.apps.maps"));
519         assertEquals(1, monkeyLog.getCategories().size());
520         assertTrue(monkeyLog.getCategories().contains("android.intent.category.LAUNCHER"));
521         assertEquals(100, monkeyLog.getThrottle());
522         assertEquals(501, monkeyLog.getSeed().intValue());
523         assertEquals(10000, monkeyLog.getTargetCount().intValue());
524         assertTrue(monkeyLog.getIgnoreSecurityExceptions());
525         assertEquals(49 * 1000, monkeyLog.getTotalDuration().longValue());
526         assertEquals(232650, monkeyLog.getStartUptimeDuration().longValue());
527         assertEquals(282530, monkeyLog.getStopUptimeDuration().longValue());
528         assertFalse(monkeyLog.getIsFinished());
529         assertFalse(monkeyLog.getNoActivities());
530         assertEquals(1600, monkeyLog.getIntermediateCount());
531         assertEquals(1649, monkeyLog.getFinalCount().intValue());
532         assertNotNull(monkeyLog.getCrash());
533         assertTrue(monkeyLog.getCrash() instanceof NativeCrashItem);
534         assertEquals("com.android.chrome", monkeyLog.getCrash().getApp());
535         assertEquals(2162, monkeyLog.getCrash().getPid().intValue());
536         NativeCrashItem nc = (NativeCrashItem) monkeyLog.getCrash();
537         assertEquals("google/mantaray/manta:4.1/JRO01/12345:userdebug/dev-keys",
538                 nc.getFingerprint());
539         // Make sure that the stack with the last line stripped is included.
540         assertEquals(23, nc.getStack().split("\n").length);
541         assertFalse(nc.getStack().contains("New native crash detected"));
542     }
543 
544     /**
545      * Test that a monkey can be parsed if there is an empty native crash.
546      */
testParse_native_crash_empty()547     public void testParse_native_crash_empty() {
548         List<String> lines = Arrays.asList(
549                 "# Tuesday, 04/24/2012 05:05:50 PM - device uptime = 232.65: Monkey command used for this test:",
550                 "adb shell monkey -p com.google.android.apps.maps  -c android.intent.category.SAMPLE_CODE -c android.intent.category.CAR_DOCK -c android.intent.category.LAUNCHER -c android.intent.category.MONKEY -c android.intent.category.INFO  --ignore-security-exceptions --throttle 100  -s 501 -v -v -v 10000 ",
551                 "",
552                 ":Monkey: seed=501 count=10000",
553                 ":AllowPackage: com.google.android.apps.maps",
554                 ":IncludeCategory: android.intent.category.LAUNCHER",
555                 ":Switch: #Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10200000;component=com.google.android.apps.maps/com.google.android.maps.LatitudeActivity;end",
556                 "    // Allowing start of Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.google.android.apps.maps/com.google.android.maps.LatitudeActivity } in package com.google.android.apps.maps",
557                 "Sleeping for 100 milliseconds",
558                 ":Sending Touch (ACTION_DOWN): 0:(332.0,70.0)",
559                 ":Sending Touch (ACTION_UP): 0:(332.55292,76.54678)",
560                 "    //[calendar_time:2012-04-25 00:06:38.419  system_uptime:280799]",
561                 "    // Sending event #1600",
562                 ":Sending Touch (ACTION_MOVE): 0:(1052.2666,677.64594)",
563                 ":Sending Touch (ACTION_UP): 0:(1054.7593,687.3757)",
564                 "Sleeping for 100 milliseconds",
565                 "** New native crash detected.",
566                 "** Monkey aborted due to error.",
567                 "Events injected: 1649",
568                 ":Sending rotation degree=0, persist=false",
569                 ":Dropped: keys=0 pointers=0 trackballs=0 flips=0 rotations=0",
570                 "## Network stats: elapsed time=48897ms (0ms mobile, 48897ms wifi, 0ms not connected)",
571                 "** System appears to have crashed at event 1649 of 10000 using seed 501",
572                 "",
573                 "# Tuesday, 04/24/2012 05:06:40 PM - device uptime = 282.53: Monkey command ran for: 00:49 (mm:ss)",
574                 "",
575                 "----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------",
576                 "");
577 
578         MonkeyLogItem monkeyLog = new MonkeyLogParser().parse(lines);
579         assertNotNull(monkeyLog);
580         // FIXME: Add test back once time situation has been worked out.
581         // assertEquals(parseTime("2012-04-24 17:05:50"), monkeyLog.getStartTime());
582         // assertEquals(parseTime("2012-04-24 17:06:40"), monkeyLog.getStopTime());
583         assertEquals(1, monkeyLog.getPackages().size());
584         assertTrue(monkeyLog.getPackages().contains("com.google.android.apps.maps"));
585         assertEquals(1, monkeyLog.getCategories().size());
586         assertTrue(monkeyLog.getCategories().contains("android.intent.category.LAUNCHER"));
587         assertEquals(100, monkeyLog.getThrottle());
588         assertEquals(501, monkeyLog.getSeed().intValue());
589         assertEquals(10000, monkeyLog.getTargetCount().intValue());
590         assertTrue(monkeyLog.getIgnoreSecurityExceptions());
591         assertEquals(49 * 1000, monkeyLog.getTotalDuration().longValue());
592         assertEquals(232650, monkeyLog.getStartUptimeDuration().longValue());
593         assertEquals(282530, monkeyLog.getStopUptimeDuration().longValue());
594         assertFalse(monkeyLog.getIsFinished());
595         assertFalse(monkeyLog.getNoActivities());
596         assertEquals(1600, monkeyLog.getIntermediateCount());
597         assertEquals(1649, monkeyLog.getFinalCount().intValue());
598         assertNotNull(monkeyLog.getCrash());
599         assertTrue(monkeyLog.getCrash() instanceof NativeCrashItem);
600         assertNull(monkeyLog.getCrash().getApp());
601         assertNull(monkeyLog.getCrash().getPid());
602         NativeCrashItem nc = (NativeCrashItem) monkeyLog.getCrash();
603         assertNull(nc.getFingerprint());
604         assertEquals("", nc.getStack());
605     }
606 
607     /**
608      * Test that a monkey can be parsed if there are no activities to run.
609      */
testParse_no_activities()610     public void testParse_no_activities() {
611         List<String> lines = Arrays.asList(
612                 "# Wednesday, 04/25/2012 01:37:12 AM - device uptime = 242.13: Monkey command used for this test:",
613                 "adb shell monkey -p com.google.android.browser  -c android.intent.category.SAMPLE_CODE -c android.intent.category.CAR_DOCK -c android.intent.category.LAUNCHER -c android.intent.category.MONKEY -c android.intent.category.INFO  --ignore-security-exceptions --throttle 100  -s 528 -v -v -v 10000 ",
614                 "",
615                 ":Monkey: seed=528 count=10000",
616                 ":AllowPackage: com.google.android.browser",
617                 ":IncludeCategory: android.intent.category.LAUNCHER",
618                 "** No activities found to run, monkey aborted.",
619                 "",
620                 "# Wednesday, 04/25/2012 01:42:09 AM - device uptime = 539.21: Monkey command ran for: 04:57 (mm:ss)",
621                 "",
622                 "----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------");
623 
624         MonkeyLogItem monkeyLog = new MonkeyLogParser().parse(lines);
625         assertNotNull(monkeyLog);
626         // FIXME: Add test back once time situation has been worked out.
627         // assertEquals(parseTime("2012-04-25 01:37:12"), monkeyLog.getStartTime());
628         // assertEquals(parseTime("2012-04-25 01:42:09"), monkeyLog.getStopTime());
629         assertEquals(1, monkeyLog.getPackages().size());
630         assertTrue(monkeyLog.getPackages().contains("com.google.android.browser"));
631         assertEquals(1, monkeyLog.getCategories().size());
632         assertTrue(monkeyLog.getCategories().contains("android.intent.category.LAUNCHER"));
633         assertEquals(100, monkeyLog.getThrottle());
634         assertEquals(528, monkeyLog.getSeed().intValue());
635         assertEquals(10000, monkeyLog.getTargetCount().intValue());
636         assertTrue(monkeyLog.getIgnoreSecurityExceptions());
637         assertEquals(4 * 60 * 1000 + 57 * 1000, monkeyLog.getTotalDuration().longValue());
638         assertEquals(242130, monkeyLog.getStartUptimeDuration().longValue());
639         assertEquals(539210, monkeyLog.getStopUptimeDuration().longValue());
640         assertFalse(monkeyLog.getIsFinished());
641         assertTrue(monkeyLog.getNoActivities());
642         assertEquals(0, monkeyLog.getIntermediateCount());
643         assertNull(monkeyLog.getFinalCount());
644         assertNull(monkeyLog.getDroppedCount(DroppedCategory.KEYS));
645         assertNull(monkeyLog.getDroppedCount(DroppedCategory.POINTERS));
646         assertNull(monkeyLog.getDroppedCount(DroppedCategory.TRACKBALLS));
647         assertNull(monkeyLog.getDroppedCount(DroppedCategory.FLIPS));
648         assertNull(monkeyLog.getDroppedCount(DroppedCategory.ROTATIONS));
649         assertNull(monkeyLog.getCrash());
650     }
651 
652     /**
653      * Test that a monkey can be parsed if there is an ANR in the middle of the traces.
654      */
testParse_malformed_anr()655     public void testParse_malformed_anr() {
656         List<String> lines = Arrays.asList(
657                 "# Tuesday, 04/24/2012 05:23:30 PM - device uptime = 216.48: Monkey command used for this test:",
658                 "adb shell monkey -p com.google.android.youtube  -c android.intent.category.SAMPLE_CODE -c android.intent.category.CAR_DOCK -c android.intent.category.LAUNCHER -c android.intent.category.MONKEY -c android.intent.category.INFO  --ignore-security-exceptions --throttle 100  -s 993 -v -v -v 10000 ",
659                 "",
660                 ":Monkey: seed=993 count=10000",
661                 ":AllowPackage: com.google.android.youtube",
662                 ":IncludeCategory: android.intent.category.LAUNCHER",
663                 ":Switch: #Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10200000;component=com.google.android.youtube/.app.honeycomb.Shell%24HomeActivity;end",
664                 "    // Allowing start of Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.google.android.youtube/.app.honeycomb.Shell$HomeActivity } in package com.google.android.youtube",
665                 "Sleeping for 100 milliseconds",
666                 ":Sending Key (ACTION_UP): 21    // KEYCODE_DPAD_LEFT",
667                 "Sleeping for 100 milliseconds",
668                 ":Sending Key (ACTION_DOWN): 22    // KEYCODE_DPAD_RIGHT",
669                 ":Sending Key (ACTION_UP): 22    // KEYCODE_DPAD_RIGHT",
670                 "    //[calendar_time:2012-04-25 00:27:27.155  system_uptime:454996]",
671                 "    // Sending event #5300",
672                 ":Sending Key (ACTION_UP): 19    // KEYCODE_DPAD_UP",
673                 "Sleeping for 100 milliseconds",
674                 ":Sending Trackball (ACTION_MOVE): 0:(4.0,3.0)",
675                 ":Sending Key (ACTION_DOWN): 20    // KEYCODE_DPAD_DOWN",
676                 ":Sending Key (ACTION_UP): 20    // KEYCODE_DPAD_DOWN",
677                 "// NOT RESPONDING: com.google.android.youtube (pid 0)",
678                 "ANR in com.google.android.youtube (com.google.android.youtube/.app.honeycomb.phone.WatchActivity)",
679                 "PID: 3301",
680                 "Reason: keyDispatchingTimedOut",
681                 "Load: 1.0 / 1.05 / 0.6",
682                 "CPU usage from 4794ms to -1502ms ago with 99% awake:",
683                 "  18% 3301/com.google.android.youtube: 16% user + 2.3% kernel / faults: 268 minor 9 major",
684                 "  13% 313/system_server: 9.2% user + 4.4% kernel / faults: 906 minor 3 major",
685                 "  10% 117/surfaceflinger: 4.9% user + 5.5% kernel / faults: 1 minor",
686                 "  10% 120/mediaserver: 6.8% user + 3.6% kernel / faults: 1189 minor",
687                 "34% TOTAL: 19% user + 13% kernel + 0.2% iowait + 1% softirq",
688                 "",
689                 "procrank:",
690                 "// procrank status was 0",
691                 "anr traces:",
692                 "",
693                 "",
694                 "----- pid 3301 at 2012-04-25 17:17:08 -----",
695                 "Cmd line: com.google.android.youtube",
696                 "",
697                 "DALVIK THREADS:",
698                 "(mutexes: tll=0 tsl=0 tscl=0 ghl=0)",
699                 "",
700                 "\"main\" prio=5 tid=1 SUSPENDED",
701                 "  | group=\"main\" sCount=1 dsCount=0 obj=0x00000001 self=0x00000001",
702                 "  | sysTid=2887 nice=0 sched=0/0 cgrp=foreground handle=0000000001",
703                 "  | schedstat=( 0 0 0 ) utm=5954 stm=1017 core=0",
704                 "  at class.method1(Class.java:1)",
705                 "// NOT RESPONDING: com.google.android.youtube (pid 3302)",
706                 "ANR in com.google.android.youtube (com.google.android.youtube/.app.honeycomb.phone.WatchActivity)",
707                 "Reason: keyDispatchingTimedOut",
708                 "Load: 1.0 / 1.05 / 0.6",
709                 "CPU usage from 4794ms to -1502ms ago with 99% awake:",
710                 "  18% 3301/com.google.android.youtube: 16% user + 2.3% kernel / faults: 268 minor 9 major",
711                 "  13% 313/system_server: 9.2% user + 4.4% kernel / faults: 906 minor 3 major",
712                 "  10% 117/surfaceflinger: 4.9% user + 5.5% kernel / faults: 1 minor",
713                 "  10% 120/mediaserver: 6.8% user + 3.6% kernel / faults: 1189 minor",
714                 "34% TOTAL: 19% user + 13% kernel + 0.2% iowait + 1% softirq",
715                 "",
716                 "  at class.method2(Class.java:2)",
717                 "  at class.method2(Class.java:2)",
718                 "",
719                 "----- end 3301 -----",
720                 "// anr traces status was 0",
721                 "** Monkey aborted due to error.",
722                 "Events injected: 5322",
723                 ":Sending rotation degree=0, persist=false",
724                 ":Dropped: keys=1 pointers=0 trackballs=0 flips=0 rotations=0",
725                 "## Network stats: elapsed time=252942ms (0ms mobile, 252942ms wifi, 0ms not connected)",
726                 "** System appears to have crashed at event 5322 of 10000 using seed 993",
727                 "",
728                 "# Tuesday, 04/24/2012 05:27:44 PM - device uptime = 471.37: Monkey command ran for: 04:14 (mm:ss)",
729                 "",
730                 "----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------",
731                 "");
732 
733         MonkeyLogItem monkeyLog = new MonkeyLogParser().parse(lines);
734         assertNotNull(monkeyLog);
735         // FIXME: Add test back once time situation has been worked out.
736         // assertEquals(parseTime("2012-04-24 17:23:30"), monkeyLog.getStartTime());
737         // assertEquals(parseTime("2012-04-24 17:27:44"), monkeyLog.getStopTime());
738         assertEquals(1, monkeyLog.getPackages().size());
739         assertTrue(monkeyLog.getPackages().contains("com.google.android.youtube"));
740         assertEquals(1, monkeyLog.getCategories().size());
741         assertTrue(monkeyLog.getCategories().contains("android.intent.category.LAUNCHER"));
742         assertEquals(100, monkeyLog.getThrottle());
743         assertEquals(993, monkeyLog.getSeed().intValue());
744         assertEquals(10000, monkeyLog.getTargetCount().intValue());
745         assertTrue(monkeyLog.getIgnoreSecurityExceptions());
746         assertEquals(4 * 60 * 1000 + 14 * 1000, monkeyLog.getTotalDuration().longValue());
747         assertEquals(216480, monkeyLog.getStartUptimeDuration().longValue());
748         assertEquals(471370, monkeyLog.getStopUptimeDuration().longValue());
749         assertFalse(monkeyLog.getIsFinished());
750         assertFalse(monkeyLog.getNoActivities());
751         assertEquals(5300, monkeyLog.getIntermediateCount());
752         assertEquals(5322, monkeyLog.getFinalCount().intValue());
753         assertNotNull(monkeyLog.getCrash());
754         assertTrue(monkeyLog.getCrash() instanceof AnrItem);
755         assertEquals("com.google.android.youtube", monkeyLog.getCrash().getApp());
756         assertEquals(3301, monkeyLog.getCrash().getPid().intValue());
757         assertEquals("keyDispatchingTimedOut", ((AnrItem) monkeyLog.getCrash()).getReason());
758     }
759 
760     /**
761      * Test that the other date format can be parsed.
762      */
testAlternateDateFormat()763     public void testAlternateDateFormat() {
764         List<String> lines = Arrays.asList(
765                 "# Tue Apr 24 17:05:50 PST 2012 - device uptime = 232.65: Monkey command used for this test:",
766                 "adb shell monkey -p com.google.android.apps.maps  -c android.intent.category.SAMPLE_CODE -c android.intent.category.CAR_DOCK -c android.intent.category.LAUNCHER -c android.intent.category.MONKEY -c android.intent.category.INFO  --ignore-security-exceptions --throttle 100  -s 501 -v -v -v 10000 ",
767                 "",
768                 "# Tue Apr 24 17:06:40 PST 2012 - device uptime = 282.53: Monkey command ran for: 00:49 (mm:ss)",
769                 "",
770                 "----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------",
771                 "");
772 
773         MonkeyLogItem monkeyLog = new MonkeyLogParser().parse(lines);
774         assertNotNull(monkeyLog);
775         // FIXME: Add test back once time situation has been worked out.
776         // assertEquals(parseTime("2012-04-24 17:05:50"), monkeyLog.getStartTime());
777         // assertEquals(parseTime("2012-04-24 17:06:40"), monkeyLog.getStopTime());
778     }
779 
780     @SuppressWarnings("unused")
parseTime(String timeStr)781     private Date parseTime(String timeStr) throws ParseException {
782         DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
783         return formatter.parse(timeStr);
784     }
785 }
786 
787