diff options
author | Guang Zhu <guangzhu@google.com> | 2024-03-15 17:27:06 +0000 |
---|---|---|
committer | Guang Zhu <guangzhu@google.com> | 2024-03-15 14:06:26 -0700 |
commit | 3a5faeb64f3a3ad7b5e17a0de9e8c50426d9d072 (patch) | |
tree | cdbd539f175be5807dfa77d04e257e702d33da6f | |
parent | b69f892cc7338c56258cd8dfa2142b11aa0b5eba (diff) | |
download | loganalysis-master.tar.gz |
- Removed SmartMonkey because the test driver has already been
deleted
- Removed regular Monkey because it's meant to work with inspect
bug related backend which has been deprecated
Bug: 329542554
Test: go/abtd-run/L99500030002548885
Change-Id: Id3bd455d78e568cd738c35fc45d3239a9e2fb9b1
9 files changed, 3 insertions, 2362 deletions
diff --git a/javatests/com/android/loganalysis/item/MonkeyLogItemTest.java b/javatests/com/android/loganalysis/item/MonkeyLogItemTest.java deleted file mode 100644 index cc2867c..0000000 --- a/javatests/com/android/loganalysis/item/MonkeyLogItemTest.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (C) 2013 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.android.loganalysis.item; - -import junit.framework.TestCase; - -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - -/** - * Unit test for {@link MonkeyLogItem}. - */ -public class MonkeyLogItemTest extends TestCase { - /** - * Test that {@link MonkeyLogItem#toJson()} returns correctly. - */ - public void testToJson() throws JSONException { - MonkeyLogItem item = new MonkeyLogItem(); - item.addCategory("category1"); - item.addCategory("category2"); - item.addPackage("package1"); - item.addPackage("package2"); - item.addPackage("package3"); - - // Convert to JSON string and back again - JSONObject output = new JSONObject(item.toJson().toString()); - - assertTrue(output.has(MonkeyLogItem.CATEGORIES)); - assertTrue(output.get(MonkeyLogItem.CATEGORIES) instanceof JSONArray); - - JSONArray categories = output.getJSONArray(MonkeyLogItem.CATEGORIES); - - assertEquals(2, categories.length()); - assertTrue(in("category1", categories)); - assertTrue(in("category2", categories)); - - JSONArray packages = output.getJSONArray(MonkeyLogItem.PACKAGES); - - assertEquals(3, packages.length()); - assertTrue(in("package1", packages)); - assertTrue(in("package2", packages)); - assertTrue(in("package3", packages)); - } - - private boolean in(String value, JSONArray array) throws JSONException { - for (int i = 0; i < array.length(); i++) { - if (value.equals(array.get(i))) { - return true; - } - } - return false; - } -} diff --git a/javatests/com/android/loganalysis/item/SmartMonkeyLogItemTest.java b/javatests/com/android/loganalysis/item/SmartMonkeyLogItemTest.java deleted file mode 100644 index 4dd5597..0000000 --- a/javatests/com/android/loganalysis/item/SmartMonkeyLogItemTest.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (C) 2013 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.android.loganalysis.item; - -import junit.framework.TestCase; - -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - -import java.util.Date; - -/** - * Unit test for {@link SmartMonkeyLogItem}. - */ -public class SmartMonkeyLogItemTest extends TestCase { - /** - * Test that {@link SmartMonkeyLogItem#toJson()} returns correctly. - */ - public void testToJson() throws JSONException { - SmartMonkeyLogItem item = new SmartMonkeyLogItem(); - item.addApplication("application1"); - item.addPackage("package1"); - item.addAnrTime(new Date()); - item.addCrashTime(new Date()); - - // Convert to JSON string and back again - JSONObject output = new JSONObject(item.toJson().toString()); - - assertTrue(output.has(SmartMonkeyLogItem.APPLICATIONS)); - assertTrue(output.get(SmartMonkeyLogItem.APPLICATIONS) instanceof JSONArray); - assertTrue(output.has(SmartMonkeyLogItem.PACKAGES)); - assertTrue(output.get(SmartMonkeyLogItem.PACKAGES) instanceof JSONArray); - assertTrue(output.has(SmartMonkeyLogItem.ANR_TIMES)); - assertTrue(output.get(SmartMonkeyLogItem.ANR_TIMES) instanceof JSONArray); - assertTrue(output.has(SmartMonkeyLogItem.CRASH_TIMES)); - assertTrue(output.get(SmartMonkeyLogItem.CRASH_TIMES) instanceof JSONArray); - } -} diff --git a/javatests/com/android/loganalysis/parser/MonkeyLogParserTest.java b/javatests/com/android/loganalysis/parser/MonkeyLogParserTest.java deleted file mode 100644 index b7e867d..0000000 --- a/javatests/com/android/loganalysis/parser/MonkeyLogParserTest.java +++ /dev/null @@ -1,786 +0,0 @@ -/* - * Copyright (C) 2012 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.android.loganalysis.parser; - -import com.android.loganalysis.item.AnrItem; -import com.android.loganalysis.item.JavaCrashItem; -import com.android.loganalysis.item.MonkeyLogItem; -import com.android.loganalysis.item.MonkeyLogItem.DroppedCategory; -import com.android.loganalysis.item.NativeCrashItem; -import com.android.loganalysis.util.ArrayUtil; - -import junit.framework.TestCase; - -import java.text.DateFormat; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Arrays; -import java.util.Date; -import java.util.List; - -/** - * Unit tests for {@link MonkeyLogParser} - */ -public class MonkeyLogParserTest extends TestCase { - - /** - * Test that a monkey can be parsed if there are no crashes. - */ - public void testParse_success() { - List<String> lines = Arrays.asList( - "# Wednesday, 04/25/2012 01:37:12 AM - device uptime = 242.13: Monkey command used for this test:", - "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 ", - "", - ":Monkey: seed=528 count=10000", - ":AllowPackage: com.google.android.browser", - ":IncludeCategory: android.intent.category.LAUNCHER", - ":Switch: #Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10200000;component=com.google.android.browser/com.android.browser.BrowserActivity;end", - " // 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", - "Sleeping for 100 milliseconds", - ":Sending Key (ACTION_DOWN): 23 // KEYCODE_DPAD_CENTER", - ":Sending Key (ACTION_UP): 23 // KEYCODE_DPAD_CENTER", - "Sleeping for 100 milliseconds", - ":Sending Trackball (ACTION_MOVE): 0:(-5.0,3.0)", - ":Sending Trackball (ACTION_MOVE): 0:(3.0,3.0)", - ":Sending Trackball (ACTION_MOVE): 0:(-1.0,3.0)", - ":Sending Trackball (ACTION_MOVE): 0:(4.0,-2.0)", - ":Sending Trackball (ACTION_MOVE): 0:(1.0,4.0)", - ":Sending Trackball (ACTION_MOVE): 0:(-4.0,2.0)", - " //[calendar_time:2012-04-25 01:42:20.140 system_uptime:535179]", - " // Sending event #9900", - ":Sending Trackball (ACTION_MOVE): 0:(2.0,-4.0)", - ":Sending Trackball (ACTION_MOVE): 0:(-2.0,0.0)", - ":Sending Trackball (ACTION_MOVE): 0:(2.0,2.0)", - ":Sending Trackball (ACTION_MOVE): 0:(-5.0,4.0)", - "Events injected: 10000", - ":Dropped: keys=5 pointers=6 trackballs=7 flips=8 rotations=9", - "// Monkey finished", - "", - "# Wednesday, 04/25/2012 01:42:09 AM - device uptime = 539.21: Monkey command ran for: 04:57 (mm:ss)", - "", - "----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------"); - - MonkeyLogItem monkeyLog = new MonkeyLogParser().parse(lines); - assertNotNull(monkeyLog); - // FIXME: Add test back once time situation has been worked out. - // assertEquals(parseTime("2012-04-25 01:37:12"), monkeyLog.getStartTime()); - // assertEquals(parseTime("2012-04-25 01:42:09"), monkeyLog.getStopTime()); - assertEquals(1, monkeyLog.getPackages().size()); - assertTrue(monkeyLog.getPackages().contains("com.google.android.browser")); - assertEquals(1, monkeyLog.getCategories().size()); - assertTrue(monkeyLog.getCategories().contains("android.intent.category.LAUNCHER")); - assertEquals(100, monkeyLog.getThrottle()); - assertEquals(528, monkeyLog.getSeed().intValue()); - assertEquals(10000, monkeyLog.getTargetCount().intValue()); - assertTrue(monkeyLog.getIgnoreSecurityExceptions()); - assertEquals(4 * 60 * 1000 + 57 * 1000, monkeyLog.getTotalDuration().longValue()); - assertEquals(242130, monkeyLog.getStartUptimeDuration().longValue()); - assertEquals(539210, monkeyLog.getStopUptimeDuration().longValue()); - assertTrue(monkeyLog.getIsFinished()); - assertFalse(monkeyLog.getNoActivities()); - assertEquals(9900, monkeyLog.getIntermediateCount()); - assertEquals(10000, monkeyLog.getFinalCount().intValue()); - assertEquals(5, monkeyLog.getDroppedCount(DroppedCategory.KEYS).intValue()); - assertEquals(6, monkeyLog.getDroppedCount(DroppedCategory.POINTERS).intValue()); - assertEquals(7, monkeyLog.getDroppedCount(DroppedCategory.TRACKBALLS).intValue()); - assertEquals(8, monkeyLog.getDroppedCount(DroppedCategory.FLIPS).intValue()); - assertEquals(9, monkeyLog.getDroppedCount(DroppedCategory.ROTATIONS).intValue()); - assertNull(monkeyLog.getCrash()); - } - - /** - * Test that a monkey can be parsed if there is an ANR. - */ - public void testParse_anr() { - List<String> lines = Arrays.asList( - "# Tuesday, 04/24/2012 05:23:30 PM - device uptime = 216.48: Monkey command used for this test:", - "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 ", - "", - ":Monkey: seed=993 count=10000", - ":AllowPackage: com.google.android.youtube", - ":IncludeCategory: android.intent.category.LAUNCHER", - ":Switch: #Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10200000;component=com.google.android.youtube/.app.honeycomb.Shell%24HomeActivity;end", - " // 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", - "Sleeping for 100 milliseconds", - ":Sending Key (ACTION_UP): 21 // KEYCODE_DPAD_LEFT", - "Sleeping for 100 milliseconds", - ":Sending Key (ACTION_DOWN): 22 // KEYCODE_DPAD_RIGHT", - ":Sending Key (ACTION_UP): 22 // KEYCODE_DPAD_RIGHT", - " //[calendar_time:2012-04-25 00:27:27.155 system_uptime:454996]", - " // Sending event #5300", - ":Sending Key (ACTION_UP): 19 // KEYCODE_DPAD_UP", - "Sleeping for 100 milliseconds", - ":Sending Trackball (ACTION_MOVE): 0:(4.0,3.0)", - ":Sending Key (ACTION_DOWN): 20 // KEYCODE_DPAD_DOWN", - ":Sending Key (ACTION_UP): 20 // KEYCODE_DPAD_DOWN", - "// NOT RESPONDING: com.google.android.youtube (pid 3301)", - "ANR in com.google.android.youtube (com.google.android.youtube/.app.honeycomb.phone.WatchActivity)", - "Reason: keyDispatchingTimedOut", - "Load: 1.0 / 1.05 / 0.6", - "CPU usage from 4794ms to -1502ms ago with 99% awake:", - " 18% 3301/com.google.android.youtube: 16% user + 2.3% kernel / faults: 268 minor 9 major", - " 13% 313/system_server: 9.2% user + 4.4% kernel / faults: 906 minor 3 major", - " 10% 117/surfaceflinger: 4.9% user + 5.5% kernel / faults: 1 minor", - " 10% 120/mediaserver: 6.8% user + 3.6% kernel / faults: 1189 minor", - "34% TOTAL: 19% user + 13% kernel + 0.2% iowait + 1% softirq", - "", - "procrank:", - "// procrank status was 0", - "anr traces:", - "", - "", - "----- pid 2887 at 2012-04-25 17:17:08 -----", - "Cmd line: com.google.android.youtube", - "", - "DALVIK THREADS:", - "(mutexes: tll=0 tsl=0 tscl=0 ghl=0)", - "", - "\"main\" prio=5 tid=1 SUSPENDED", - " | group=\"main\" sCount=1 dsCount=0 obj=0x00000001 self=0x00000001", - " | sysTid=2887 nice=0 sched=0/0 cgrp=foreground handle=0000000001", - " | schedstat=( 0 0 0 ) utm=5954 stm=1017 core=0", - " at class.method1(Class.java:1)", - " at class.method2(Class.java:2)", - " at class.method2(Class.java:2)", - "", - "----- end 2887 -----", - "// anr traces status was 0", - "** Monkey aborted due to error.", - "Events injected: 5322", - ":Sending rotation degree=0, persist=false", - ":Dropped: keys=1 pointers=0 trackballs=0 flips=0 rotations=0", - "## Network stats: elapsed time=252942ms (0ms mobile, 252942ms wifi, 0ms not connected)", - "** System appears to have crashed at event 5322 of 10000 using seed 993", - "", - "# Tuesday, 04/24/2012 05:27:44 PM - device uptime = 471.37: Monkey command ran for: 04:14 (mm:ss)", - "", - "----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------", - ""); - - List<String> expectedStack = Arrays.asList( - "\"main\" prio=5 tid=1 SUSPENDED", - " | group=\"main\" sCount=1 dsCount=0 obj=0x00000001 self=0x00000001", - " | sysTid=2887 nice=0 sched=0/0 cgrp=foreground handle=0000000001", - " | schedstat=( 0 0 0 ) utm=5954 stm=1017 core=0", - " at class.method1(Class.java:1)", - " at class.method2(Class.java:2)", - " at class.method2(Class.java:2)"); - - MonkeyLogItem monkeyLog = new MonkeyLogParser().parse(lines); - assertNotNull(monkeyLog); - // FIXME: Add test back once time situation has been worked out. - // assertEquals(parseTime("2012-04-24 17:23:30"), monkeyLog.getStartTime()); - // assertEquals(parseTime("2012-04-24 17:27:44"), monkeyLog.getStopTime()); - assertEquals(1, monkeyLog.getPackages().size()); - assertTrue(monkeyLog.getPackages().contains("com.google.android.youtube")); - assertEquals(1, monkeyLog.getCategories().size()); - assertTrue(monkeyLog.getCategories().contains("android.intent.category.LAUNCHER")); - assertEquals(100, monkeyLog.getThrottle()); - assertEquals(993, monkeyLog.getSeed().intValue()); - assertEquals(10000, monkeyLog.getTargetCount().intValue()); - assertTrue(monkeyLog.getIgnoreSecurityExceptions()); - assertEquals(4 * 60 * 1000 + 14 * 1000, monkeyLog.getTotalDuration().longValue()); - assertEquals(216480, monkeyLog.getStartUptimeDuration().longValue()); - assertEquals(471370, monkeyLog.getStopUptimeDuration().longValue()); - assertFalse(monkeyLog.getIsFinished()); - assertFalse(monkeyLog.getNoActivities()); - assertEquals(5300, monkeyLog.getIntermediateCount()); - assertEquals(5322, monkeyLog.getFinalCount().intValue()); - assertNotNull(monkeyLog.getCrash()); - assertTrue(monkeyLog.getCrash() instanceof AnrItem); - assertEquals("com.google.android.youtube", monkeyLog.getCrash().getApp()); - assertEquals(3301, monkeyLog.getCrash().getPid().intValue()); - assertEquals("keyDispatchingTimedOut", ((AnrItem) monkeyLog.getCrash()).getReason()); - assertEquals(ArrayUtil.join("\n", expectedStack), - ((AnrItem) monkeyLog.getCrash()).getTrace()); - } - - /** - * Test that a monkey can be parsed if there is a Java crash. - */ - public void testParse_java_crash() { - List<String> lines = Arrays.asList( - "# Tuesday, 04/24/2012 05:05:50 PM - device uptime = 232.65: Monkey command used for this test:", - "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 ", - "", - ":Monkey: seed=501 count=10000", - ":AllowPackage: com.google.android.apps.maps", - ":IncludeCategory: android.intent.category.LAUNCHER", - ":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", - " // 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", - "Sleeping for 100 milliseconds", - ":Sending Touch (ACTION_DOWN): 0:(332.0,70.0)", - ":Sending Touch (ACTION_UP): 0:(332.55292,76.54678)", - " //[calendar_time:2012-04-25 00:06:38.419 system_uptime:280799]", - " // Sending event #1600", - ":Sending Touch (ACTION_MOVE): 0:(1052.2666,677.64594)", - ":Sending Touch (ACTION_UP): 0:(1054.7593,687.3757)", - "Sleeping for 100 milliseconds", - "// CRASH: com.google.android.apps.maps (pid 3161)", - "// Short Msg: java.lang.Exception", - "// Long Msg: java.lang.Exception: This is the message", - "// Build Label: google/yakju/maguro:JellyBean/JRN24B/338896:userdebug/dev-keys", - "// Build Changelist: 338896", - "// Build Time: 1335309051000", - "// java.lang.Exception: This is the message", - "// \tat class.method1(Class.java:1)", - "// \tat class.method2(Class.java:2)", - "// \tat class.method3(Class.java:3)", - "// ", - "** Monkey aborted due to error.", - "Events injected: 1649", - ":Sending rotation degree=0, persist=false", - ":Dropped: keys=0 pointers=0 trackballs=0 flips=0 rotations=0", - "## Network stats: elapsed time=48897ms (0ms mobile, 48897ms wifi, 0ms not connected)", - "** System appears to have crashed at event 1649 of 10000 using seed 501", - "", - "# Tuesday, 04/24/2012 05:06:40 PM - device uptime = 282.53: Monkey command ran for: 00:49 (mm:ss)", - "", - "----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------", - ""); - - MonkeyLogItem monkeyLog = new MonkeyLogParser().parse(lines); - assertNotNull(monkeyLog); - // FIXME: Add test back once time situation has been worked out. - // assertEquals(parseTime("2012-04-24 17:05:50"), monkeyLog.getStartTime()); - // assertEquals(parseTime("2012-04-24 17:06:40"), monkeyLog.getStopTime()); - assertEquals(1, monkeyLog.getPackages().size()); - assertTrue(monkeyLog.getPackages().contains("com.google.android.apps.maps")); - assertEquals(1, monkeyLog.getCategories().size()); - assertTrue(monkeyLog.getCategories().contains("android.intent.category.LAUNCHER")); - assertEquals(100, monkeyLog.getThrottle()); - assertEquals(501, monkeyLog.getSeed().intValue()); - assertEquals(10000, monkeyLog.getTargetCount().intValue()); - assertTrue(monkeyLog.getIgnoreSecurityExceptions()); - assertEquals(49 * 1000, monkeyLog.getTotalDuration().longValue()); - assertEquals(232650, monkeyLog.getStartUptimeDuration().longValue()); - assertEquals(282530, monkeyLog.getStopUptimeDuration().longValue()); - assertFalse(monkeyLog.getIsFinished()); - assertFalse(monkeyLog.getNoActivities()); - assertEquals(1600, monkeyLog.getIntermediateCount()); - assertEquals(1649, monkeyLog.getFinalCount().intValue()); - assertNotNull(monkeyLog.getCrash()); - assertTrue(monkeyLog.getCrash() instanceof JavaCrashItem); - assertEquals("com.google.android.apps.maps", monkeyLog.getCrash().getApp()); - assertEquals(3161, monkeyLog.getCrash().getPid().intValue()); - assertEquals("java.lang.Exception", ((JavaCrashItem) monkeyLog.getCrash()).getException()); - } - - /** - * Test that a monkey can be parsed if there is a Java crash even if monkey lines are mixed in - * the crash. - */ - public void testParse_java_crash_mixed() { - List<String> lines = Arrays.asList( - "# Tuesday, 04/24/2012 05:05:50 PM - device uptime = 232.65: Monkey command used for this test:", - "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 ", - "", - ":Monkey: seed=501 count=10000", - ":AllowPackage: com.google.android.apps.maps", - ":IncludeCategory: android.intent.category.LAUNCHER", - ":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", - " // 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", - "Sleeping for 100 milliseconds", - ":Sending Touch (ACTION_DOWN): 0:(332.0,70.0)", - ":Sending Touch (ACTION_UP): 0:(332.55292,76.54678)", - " //[calendar_time:2012-04-25 00:06:38.419 system_uptime:280799]", - " // Sending event #1600", - ":Sending Touch (ACTION_MOVE): 0:(1052.2666,677.64594)", - "// CRASH: com.google.android.apps.maps (pid 3161)", - "// Short Msg: java.lang.Exception", - ":Sending Touch (ACTION_UP): 0:(1054.7593,687.3757)", - "// Long Msg: java.lang.Exception: This is the message", - "// Build Label: google/yakju/maguro:JellyBean/JRN24B/338896:userdebug/dev-keys", - "// Build Changelist: 338896", - "Sleeping for 100 milliseconds", - "// Build Time: 1335309051000", - "// java.lang.Exception: This is the message", - "// \tat class.method1(Class.java:1)", - "// \tat class.method2(Class.java:2)", - "// \tat class.method3(Class.java:3)", - "// ", - "** Monkey aborted due to error.", - "Events injected: 1649", - ":Sending rotation degree=0, persist=false", - ":Dropped: keys=0 pointers=0 trackballs=0 flips=0 rotations=0", - "## Network stats: elapsed time=48897ms (0ms mobile, 48897ms wifi, 0ms not connected)", - "** System appears to have crashed at event 1649 of 10000 using seed 501", - "", - "# Tuesday, 04/24/2012 05:06:40 PM - device uptime = 282.53: Monkey command ran for: 00:49 (mm:ss)", - "", - "----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------", - ""); - - MonkeyLogItem monkeyLog = new MonkeyLogParser().parse(lines); - assertNotNull(monkeyLog); - // FIXME: Add test back once time situation has been worked out. - // assertEquals(parseTime("2012-04-24 17:05:50"), monkeyLog.getStartTime()); - // assertEquals(parseTime("2012-04-24 17:06:40"), monkeyLog.getStopTime()); - assertEquals(1, monkeyLog.getPackages().size()); - assertTrue(monkeyLog.getPackages().contains("com.google.android.apps.maps")); - assertEquals(1, monkeyLog.getCategories().size()); - assertTrue(monkeyLog.getCategories().contains("android.intent.category.LAUNCHER")); - assertEquals(100, monkeyLog.getThrottle()); - assertEquals(501, monkeyLog.getSeed().intValue()); - assertEquals(10000, monkeyLog.getTargetCount().intValue()); - assertTrue(monkeyLog.getIgnoreSecurityExceptions()); - assertEquals(49 * 1000, monkeyLog.getTotalDuration().longValue()); - assertEquals(232650, monkeyLog.getStartUptimeDuration().longValue()); - assertEquals(282530, monkeyLog.getStopUptimeDuration().longValue()); - assertFalse(monkeyLog.getIsFinished()); - assertFalse(monkeyLog.getNoActivities()); - assertEquals(1600, monkeyLog.getIntermediateCount()); - assertEquals(1649, monkeyLog.getFinalCount().intValue()); - assertNotNull(monkeyLog.getCrash()); - assertTrue(monkeyLog.getCrash() instanceof JavaCrashItem); - assertEquals("com.google.android.apps.maps", monkeyLog.getCrash().getApp()); - assertEquals(3161, monkeyLog.getCrash().getPid().intValue()); - assertEquals("java.lang.Exception", ((JavaCrashItem) monkeyLog.getCrash()).getException()); - } - - - /** - * Test that a monkey can be parsed if there is a native crash. - */ - public void testParse_native_crash() { - List<String> lines = Arrays.asList( - "# Tuesday, 04/24/2012 05:05:50 PM - device uptime = 232.65: Monkey command used for this test:", - "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 ", - "", - ":Monkey: seed=501 count=10000", - ":AllowPackage: com.google.android.apps.maps", - ":IncludeCategory: android.intent.category.LAUNCHER", - ":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", - " // 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", - "Sleeping for 100 milliseconds", - ":Sending Touch (ACTION_DOWN): 0:(332.0,70.0)", - ":Sending Touch (ACTION_UP): 0:(332.55292,76.54678)", - " //[calendar_time:2012-04-25 00:06:38.419 system_uptime:280799]", - " // Sending event #1600", - ":Sending Touch (ACTION_MOVE): 0:(1052.2666,677.64594)", - ":Sending Touch (ACTION_UP): 0:(1054.7593,687.3757)", - "Sleeping for 100 milliseconds", - "// CRASH: com.android.chrome (pid 2162)", - "// Short Msg: Native crash", - "// Long Msg: Native crash: Segmentation fault", - "// Build Label: google/mantaray/manta:JellyBeanMR2/JWR02/624470:userdebug/dev-keys", - "// Build Changelist: 624470", - "// Build Time: 1364920502000", - "// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***", - "// Build fingerprint: 'google/mantaray/manta:4.1/JRO01/12345:userdebug/dev-keys'", - "// Revision: '7'", - "// pid: 2162, tid: 2216, name: .android.chrome >>> com.android.chrome <<<", - "// signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr deadbaad", - "// r0 00000027 r1 00001000 r2 00000008 r3 deadbaad", - "// r4 00000000 r5 7af65e64 r6 00000000 r7 7af65ea4", - "// r8 401291f4 r9 00200000 sl 7784badc fp 00001401", - "// ip 7af65ea4 sp 7af65e60 lr 400fed6b pc 400fc2d4 cpsr 600f0030", - "// d0 3332303033312034 d1 6361707320737332", - "// d2 632e6c6f6f705f34 d3 205d29383231280a", - "// scr 60000010", - "// ", - "// backtrace:", - "// #00 pc 0001e2d4 /system/lib/libc.so", - "// #01 pc 0001c4bc /system/lib/libc.so (abort+4)", - "// #02 pc 0023a515 /system/lib/libchromeview.so", - "// #03 pc 006f8a27 /system/lib/libchromeview.so", - "// ", - "// stack:", - "// 7af65e20 77856cf8 ", - "// 7af65e24 7af65e64 [stack:2216]", - "// 7af65e28 00000014 ", - "// 7af65e2c 76a88e6c /system/lib/libchromeview.so", - "** Monkey aborted due to error.", - "Events injected: 1649", - ":Sending rotation degree=0, persist=false", - ":Dropped: keys=0 pointers=0 trackballs=0 flips=0 rotations=0", - "## Network stats: elapsed time=48897ms (0ms mobile, 48897ms wifi, 0ms not connected)", - "** System appears to have crashed at event 1649 of 10000 using seed 501", - "", - "# Tuesday, 04/24/2012 05:06:40 PM - device uptime = 282.53: Monkey command ran for: 00:49 (mm:ss)", - "", - "----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------", - ""); - - MonkeyLogItem monkeyLog = new MonkeyLogParser().parse(lines); - assertNotNull(monkeyLog); - // FIXME: Add test back once time situation has been worked out. - // assertEquals(parseTime("2012-04-24 17:05:50"), monkeyLog.getStartTime()); - // assertEquals(parseTime("2012-04-24 17:06:40"), monkeyLog.getStopTime()); - assertEquals(1, monkeyLog.getPackages().size()); - assertTrue(monkeyLog.getPackages().contains("com.google.android.apps.maps")); - assertEquals(1, monkeyLog.getCategories().size()); - assertTrue(monkeyLog.getCategories().contains("android.intent.category.LAUNCHER")); - assertEquals(100, monkeyLog.getThrottle()); - assertEquals(501, monkeyLog.getSeed().intValue()); - assertEquals(10000, monkeyLog.getTargetCount().intValue()); - assertTrue(monkeyLog.getIgnoreSecurityExceptions()); - assertEquals(49 * 1000, monkeyLog.getTotalDuration().longValue()); - assertEquals(232650, monkeyLog.getStartUptimeDuration().longValue()); - assertEquals(282530, monkeyLog.getStopUptimeDuration().longValue()); - assertFalse(monkeyLog.getIsFinished()); - assertFalse(monkeyLog.getNoActivities()); - assertEquals(1600, monkeyLog.getIntermediateCount()); - assertEquals(1649, monkeyLog.getFinalCount().intValue()); - assertNotNull(monkeyLog.getCrash()); - assertTrue(monkeyLog.getCrash() instanceof NativeCrashItem); - assertEquals("com.android.chrome", monkeyLog.getCrash().getApp()); - assertEquals(2162, monkeyLog.getCrash().getPid().intValue()); - assertEquals("google/mantaray/manta:4.1/JRO01/12345:userdebug/dev-keys", - ((NativeCrashItem) monkeyLog.getCrash()).getFingerprint()); - // Make sure that the entire stack is included. - assertEquals(23, ((NativeCrashItem) monkeyLog.getCrash()).getStack().split("\n").length); - } - - /** - * Test that a monkey can be parsed if there is a native crash with extra info at the end. - */ - public void testParse_native_crash_strip_extra() { - List<String> lines = Arrays.asList( - "# Tuesday, 04/24/2012 05:05:50 PM - device uptime = 232.65: Monkey command used for this test:", - "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 ", - "", - ":Monkey: seed=501 count=10000", - ":AllowPackage: com.google.android.apps.maps", - ":IncludeCategory: android.intent.category.LAUNCHER", - ":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", - " // 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", - "Sleeping for 100 milliseconds", - ":Sending Touch (ACTION_DOWN): 0:(332.0,70.0)", - ":Sending Touch (ACTION_UP): 0:(332.55292,76.54678)", - " //[calendar_time:2012-04-25 00:06:38.419 system_uptime:280799]", - " // Sending event #1600", - ":Sending Touch (ACTION_MOVE): 0:(1052.2666,677.64594)", - ":Sending Touch (ACTION_UP): 0:(1054.7593,687.3757)", - "Sleeping for 100 milliseconds", - "// CRASH: com.android.chrome (pid 2162)", - "// Short Msg: Native crash", - "// Long Msg: Native crash: Segmentation fault", - "// Build Label: google/mantaray/manta:JellyBeanMR2/JWR02/624470:userdebug/dev-keys", - "// Build Changelist: 624470", - "// Build Time: 1364920502000", - "// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***", - "// Build fingerprint: 'google/mantaray/manta:4.1/JRO01/12345:userdebug/dev-keys'", - "// Revision: '7'", - "// pid: 2162, tid: 2216, name: .android.chrome >>> com.android.chrome <<<", - "// signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr deadbaad", - "// r0 00000027 r1 00001000 r2 00000008 r3 deadbaad", - "// r4 00000000 r5 7af65e64 r6 00000000 r7 7af65ea4", - "// r8 401291f4 r9 00200000 sl 7784badc fp 00001401", - "// ip 7af65ea4 sp 7af65e60 lr 400fed6b pc 400fc2d4 cpsr 600f0030", - "// d0 3332303033312034 d1 6361707320737332", - "// d2 632e6c6f6f705f34 d3 205d29383231280a", - "// scr 60000010", - "// ", - "// backtrace:", - "// #00 pc 0001e2d4 /system/lib/libc.so", - "// #01 pc 0001c4bc /system/lib/libc.so (abort+4)", - "// #02 pc 0023a515 /system/lib/libchromeview.so", - "// #03 pc 006f8a27 /system/lib/libchromeview.so", - "// ", - "// stack:", - "// 7af65e20 77856cf8 ", - "// 7af65e24 7af65e64 [stack:2216]", - "// 7af65e28 00000014 ", - "// 7af65e2c 76a88e6c /system/lib/libchromeview.so", - "// ** New native crash detected.", - "** Monkey aborted due to error.", - "Events injected: 1649", - ":Sending rotation degree=0, persist=false", - ":Dropped: keys=0 pointers=0 trackballs=0 flips=0 rotations=0", - "## Network stats: elapsed time=48897ms (0ms mobile, 48897ms wifi, 0ms not connected)", - "** System appears to have crashed at event 1649 of 10000 using seed 501", - "", - "# Tuesday, 04/24/2012 05:06:40 PM - device uptime = 282.53: Monkey command ran for: 00:49 (mm:ss)", - "", - "----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------", - ""); - - MonkeyLogItem monkeyLog = new MonkeyLogParser().parse(lines); - assertNotNull(monkeyLog); - // FIXME: Add test back once time situation has been worked out. - // assertEquals(parseTime("2012-04-24 17:05:50"), monkeyLog.getStartTime()); - // assertEquals(parseTime("2012-04-24 17:06:40"), monkeyLog.getStopTime()); - assertEquals(1, monkeyLog.getPackages().size()); - assertTrue(monkeyLog.getPackages().contains("com.google.android.apps.maps")); - assertEquals(1, monkeyLog.getCategories().size()); - assertTrue(monkeyLog.getCategories().contains("android.intent.category.LAUNCHER")); - assertEquals(100, monkeyLog.getThrottle()); - assertEquals(501, monkeyLog.getSeed().intValue()); - assertEquals(10000, monkeyLog.getTargetCount().intValue()); - assertTrue(monkeyLog.getIgnoreSecurityExceptions()); - assertEquals(49 * 1000, monkeyLog.getTotalDuration().longValue()); - assertEquals(232650, monkeyLog.getStartUptimeDuration().longValue()); - assertEquals(282530, monkeyLog.getStopUptimeDuration().longValue()); - assertFalse(monkeyLog.getIsFinished()); - assertFalse(monkeyLog.getNoActivities()); - assertEquals(1600, monkeyLog.getIntermediateCount()); - assertEquals(1649, monkeyLog.getFinalCount().intValue()); - assertNotNull(monkeyLog.getCrash()); - assertTrue(monkeyLog.getCrash() instanceof NativeCrashItem); - assertEquals("com.android.chrome", monkeyLog.getCrash().getApp()); - assertEquals(2162, monkeyLog.getCrash().getPid().intValue()); - NativeCrashItem nc = (NativeCrashItem) monkeyLog.getCrash(); - assertEquals("google/mantaray/manta:4.1/JRO01/12345:userdebug/dev-keys", - nc.getFingerprint()); - // Make sure that the stack with the last line stripped is included. - assertEquals(23, nc.getStack().split("\n").length); - assertFalse(nc.getStack().contains("New native crash detected")); - } - - /** - * Test that a monkey can be parsed if there is an empty native crash. - */ - public void testParse_native_crash_empty() { - List<String> lines = Arrays.asList( - "# Tuesday, 04/24/2012 05:05:50 PM - device uptime = 232.65: Monkey command used for this test:", - "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 ", - "", - ":Monkey: seed=501 count=10000", - ":AllowPackage: com.google.android.apps.maps", - ":IncludeCategory: android.intent.category.LAUNCHER", - ":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", - " // 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", - "Sleeping for 100 milliseconds", - ":Sending Touch (ACTION_DOWN): 0:(332.0,70.0)", - ":Sending Touch (ACTION_UP): 0:(332.55292,76.54678)", - " //[calendar_time:2012-04-25 00:06:38.419 system_uptime:280799]", - " // Sending event #1600", - ":Sending Touch (ACTION_MOVE): 0:(1052.2666,677.64594)", - ":Sending Touch (ACTION_UP): 0:(1054.7593,687.3757)", - "Sleeping for 100 milliseconds", - "** New native crash detected.", - "** Monkey aborted due to error.", - "Events injected: 1649", - ":Sending rotation degree=0, persist=false", - ":Dropped: keys=0 pointers=0 trackballs=0 flips=0 rotations=0", - "## Network stats: elapsed time=48897ms (0ms mobile, 48897ms wifi, 0ms not connected)", - "** System appears to have crashed at event 1649 of 10000 using seed 501", - "", - "# Tuesday, 04/24/2012 05:06:40 PM - device uptime = 282.53: Monkey command ran for: 00:49 (mm:ss)", - "", - "----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------", - ""); - - MonkeyLogItem monkeyLog = new MonkeyLogParser().parse(lines); - assertNotNull(monkeyLog); - // FIXME: Add test back once time situation has been worked out. - // assertEquals(parseTime("2012-04-24 17:05:50"), monkeyLog.getStartTime()); - // assertEquals(parseTime("2012-04-24 17:06:40"), monkeyLog.getStopTime()); - assertEquals(1, monkeyLog.getPackages().size()); - assertTrue(monkeyLog.getPackages().contains("com.google.android.apps.maps")); - assertEquals(1, monkeyLog.getCategories().size()); - assertTrue(monkeyLog.getCategories().contains("android.intent.category.LAUNCHER")); - assertEquals(100, monkeyLog.getThrottle()); - assertEquals(501, monkeyLog.getSeed().intValue()); - assertEquals(10000, monkeyLog.getTargetCount().intValue()); - assertTrue(monkeyLog.getIgnoreSecurityExceptions()); - assertEquals(49 * 1000, monkeyLog.getTotalDuration().longValue()); - assertEquals(232650, monkeyLog.getStartUptimeDuration().longValue()); - assertEquals(282530, monkeyLog.getStopUptimeDuration().longValue()); - assertFalse(monkeyLog.getIsFinished()); - assertFalse(monkeyLog.getNoActivities()); - assertEquals(1600, monkeyLog.getIntermediateCount()); - assertEquals(1649, monkeyLog.getFinalCount().intValue()); - assertNotNull(monkeyLog.getCrash()); - assertTrue(monkeyLog.getCrash() instanceof NativeCrashItem); - assertNull(monkeyLog.getCrash().getApp()); - assertNull(monkeyLog.getCrash().getPid()); - NativeCrashItem nc = (NativeCrashItem) monkeyLog.getCrash(); - assertNull(nc.getFingerprint()); - assertEquals("", nc.getStack()); - } - - /** - * Test that a monkey can be parsed if there are no activities to run. - */ - public void testParse_no_activities() { - List<String> lines = Arrays.asList( - "# Wednesday, 04/25/2012 01:37:12 AM - device uptime = 242.13: Monkey command used for this test:", - "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 ", - "", - ":Monkey: seed=528 count=10000", - ":AllowPackage: com.google.android.browser", - ":IncludeCategory: android.intent.category.LAUNCHER", - "** No activities found to run, monkey aborted.", - "", - "# Wednesday, 04/25/2012 01:42:09 AM - device uptime = 539.21: Monkey command ran for: 04:57 (mm:ss)", - "", - "----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------"); - - MonkeyLogItem monkeyLog = new MonkeyLogParser().parse(lines); - assertNotNull(monkeyLog); - // FIXME: Add test back once time situation has been worked out. - // assertEquals(parseTime("2012-04-25 01:37:12"), monkeyLog.getStartTime()); - // assertEquals(parseTime("2012-04-25 01:42:09"), monkeyLog.getStopTime()); - assertEquals(1, monkeyLog.getPackages().size()); - assertTrue(monkeyLog.getPackages().contains("com.google.android.browser")); - assertEquals(1, monkeyLog.getCategories().size()); - assertTrue(monkeyLog.getCategories().contains("android.intent.category.LAUNCHER")); - assertEquals(100, monkeyLog.getThrottle()); - assertEquals(528, monkeyLog.getSeed().intValue()); - assertEquals(10000, monkeyLog.getTargetCount().intValue()); - assertTrue(monkeyLog.getIgnoreSecurityExceptions()); - assertEquals(4 * 60 * 1000 + 57 * 1000, monkeyLog.getTotalDuration().longValue()); - assertEquals(242130, monkeyLog.getStartUptimeDuration().longValue()); - assertEquals(539210, monkeyLog.getStopUptimeDuration().longValue()); - assertFalse(monkeyLog.getIsFinished()); - assertTrue(monkeyLog.getNoActivities()); - assertEquals(0, monkeyLog.getIntermediateCount()); - assertNull(monkeyLog.getFinalCount()); - assertNull(monkeyLog.getDroppedCount(DroppedCategory.KEYS)); - assertNull(monkeyLog.getDroppedCount(DroppedCategory.POINTERS)); - assertNull(monkeyLog.getDroppedCount(DroppedCategory.TRACKBALLS)); - assertNull(monkeyLog.getDroppedCount(DroppedCategory.FLIPS)); - assertNull(monkeyLog.getDroppedCount(DroppedCategory.ROTATIONS)); - assertNull(monkeyLog.getCrash()); - } - - /** - * Test that a monkey can be parsed if there is an ANR in the middle of the traces. - */ - public void testParse_malformed_anr() { - List<String> lines = Arrays.asList( - "# Tuesday, 04/24/2012 05:23:30 PM - device uptime = 216.48: Monkey command used for this test:", - "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 ", - "", - ":Monkey: seed=993 count=10000", - ":AllowPackage: com.google.android.youtube", - ":IncludeCategory: android.intent.category.LAUNCHER", - ":Switch: #Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10200000;component=com.google.android.youtube/.app.honeycomb.Shell%24HomeActivity;end", - " // 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", - "Sleeping for 100 milliseconds", - ":Sending Key (ACTION_UP): 21 // KEYCODE_DPAD_LEFT", - "Sleeping for 100 milliseconds", - ":Sending Key (ACTION_DOWN): 22 // KEYCODE_DPAD_RIGHT", - ":Sending Key (ACTION_UP): 22 // KEYCODE_DPAD_RIGHT", - " //[calendar_time:2012-04-25 00:27:27.155 system_uptime:454996]", - " // Sending event #5300", - ":Sending Key (ACTION_UP): 19 // KEYCODE_DPAD_UP", - "Sleeping for 100 milliseconds", - ":Sending Trackball (ACTION_MOVE): 0:(4.0,3.0)", - ":Sending Key (ACTION_DOWN): 20 // KEYCODE_DPAD_DOWN", - ":Sending Key (ACTION_UP): 20 // KEYCODE_DPAD_DOWN", - "// NOT RESPONDING: com.google.android.youtube (pid 0)", - "ANR in com.google.android.youtube (com.google.android.youtube/.app.honeycomb.phone.WatchActivity)", - "PID: 3301", - "Reason: keyDispatchingTimedOut", - "Load: 1.0 / 1.05 / 0.6", - "CPU usage from 4794ms to -1502ms ago with 99% awake:", - " 18% 3301/com.google.android.youtube: 16% user + 2.3% kernel / faults: 268 minor 9 major", - " 13% 313/system_server: 9.2% user + 4.4% kernel / faults: 906 minor 3 major", - " 10% 117/surfaceflinger: 4.9% user + 5.5% kernel / faults: 1 minor", - " 10% 120/mediaserver: 6.8% user + 3.6% kernel / faults: 1189 minor", - "34% TOTAL: 19% user + 13% kernel + 0.2% iowait + 1% softirq", - "", - "procrank:", - "// procrank status was 0", - "anr traces:", - "", - "", - "----- pid 3301 at 2012-04-25 17:17:08 -----", - "Cmd line: com.google.android.youtube", - "", - "DALVIK THREADS:", - "(mutexes: tll=0 tsl=0 tscl=0 ghl=0)", - "", - "\"main\" prio=5 tid=1 SUSPENDED", - " | group=\"main\" sCount=1 dsCount=0 obj=0x00000001 self=0x00000001", - " | sysTid=2887 nice=0 sched=0/0 cgrp=foreground handle=0000000001", - " | schedstat=( 0 0 0 ) utm=5954 stm=1017 core=0", - " at class.method1(Class.java:1)", - "// NOT RESPONDING: com.google.android.youtube (pid 3302)", - "ANR in com.google.android.youtube (com.google.android.youtube/.app.honeycomb.phone.WatchActivity)", - "Reason: keyDispatchingTimedOut", - "Load: 1.0 / 1.05 / 0.6", - "CPU usage from 4794ms to -1502ms ago with 99% awake:", - " 18% 3301/com.google.android.youtube: 16% user + 2.3% kernel / faults: 268 minor 9 major", - " 13% 313/system_server: 9.2% user + 4.4% kernel / faults: 906 minor 3 major", - " 10% 117/surfaceflinger: 4.9% user + 5.5% kernel / faults: 1 minor", - " 10% 120/mediaserver: 6.8% user + 3.6% kernel / faults: 1189 minor", - "34% TOTAL: 19% user + 13% kernel + 0.2% iowait + 1% softirq", - "", - " at class.method2(Class.java:2)", - " at class.method2(Class.java:2)", - "", - "----- end 3301 -----", - "// anr traces status was 0", - "** Monkey aborted due to error.", - "Events injected: 5322", - ":Sending rotation degree=0, persist=false", - ":Dropped: keys=1 pointers=0 trackballs=0 flips=0 rotations=0", - "## Network stats: elapsed time=252942ms (0ms mobile, 252942ms wifi, 0ms not connected)", - "** System appears to have crashed at event 5322 of 10000 using seed 993", - "", - "# Tuesday, 04/24/2012 05:27:44 PM - device uptime = 471.37: Monkey command ran for: 04:14 (mm:ss)", - "", - "----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------", - ""); - - MonkeyLogItem monkeyLog = new MonkeyLogParser().parse(lines); - assertNotNull(monkeyLog); - // FIXME: Add test back once time situation has been worked out. - // assertEquals(parseTime("2012-04-24 17:23:30"), monkeyLog.getStartTime()); - // assertEquals(parseTime("2012-04-24 17:27:44"), monkeyLog.getStopTime()); - assertEquals(1, monkeyLog.getPackages().size()); - assertTrue(monkeyLog.getPackages().contains("com.google.android.youtube")); - assertEquals(1, monkeyLog.getCategories().size()); - assertTrue(monkeyLog.getCategories().contains("android.intent.category.LAUNCHER")); - assertEquals(100, monkeyLog.getThrottle()); - assertEquals(993, monkeyLog.getSeed().intValue()); - assertEquals(10000, monkeyLog.getTargetCount().intValue()); - assertTrue(monkeyLog.getIgnoreSecurityExceptions()); - assertEquals(4 * 60 * 1000 + 14 * 1000, monkeyLog.getTotalDuration().longValue()); - assertEquals(216480, monkeyLog.getStartUptimeDuration().longValue()); - assertEquals(471370, monkeyLog.getStopUptimeDuration().longValue()); - assertFalse(monkeyLog.getIsFinished()); - assertFalse(monkeyLog.getNoActivities()); - assertEquals(5300, monkeyLog.getIntermediateCount()); - assertEquals(5322, monkeyLog.getFinalCount().intValue()); - assertNotNull(monkeyLog.getCrash()); - assertTrue(monkeyLog.getCrash() instanceof AnrItem); - assertEquals("com.google.android.youtube", monkeyLog.getCrash().getApp()); - assertEquals(3301, monkeyLog.getCrash().getPid().intValue()); - assertEquals("keyDispatchingTimedOut", ((AnrItem) monkeyLog.getCrash()).getReason()); - } - - /** - * Test that the other date format can be parsed. - */ - public void testAlternateDateFormat() { - List<String> lines = Arrays.asList( - "# Tue Apr 24 17:05:50 PST 2012 - device uptime = 232.65: Monkey command used for this test:", - "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 ", - "", - "# Tue Apr 24 17:06:40 PST 2012 - device uptime = 282.53: Monkey command ran for: 00:49 (mm:ss)", - "", - "----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------", - ""); - - MonkeyLogItem monkeyLog = new MonkeyLogParser().parse(lines); - assertNotNull(monkeyLog); - // FIXME: Add test back once time situation has been worked out. - // assertEquals(parseTime("2012-04-24 17:05:50"), monkeyLog.getStartTime()); - // assertEquals(parseTime("2012-04-24 17:06:40"), monkeyLog.getStopTime()); - } - - @SuppressWarnings("unused") - private Date parseTime(String timeStr) throws ParseException { - DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - return formatter.parse(timeStr); - } -} - diff --git a/javatests/com/android/loganalysis/parser/SmartMonkeyLogParserTest.java b/javatests/com/android/loganalysis/parser/SmartMonkeyLogParserTest.java deleted file mode 100644 index 1249f7c..0000000 --- a/javatests/com/android/loganalysis/parser/SmartMonkeyLogParserTest.java +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Copyright (C) 2013 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.android.loganalysis.parser; - -import com.android.loganalysis.item.SmartMonkeyLogItem; -import com.android.loganalysis.parser.SmartMonkeyLogParser; - -import java.text.ParseException; -import java.util.Arrays; -import java.util.List; -import junit.framework.TestCase; - -/** - * Unit tests for {@link SmartMonkeyLogParser} and {@link SmartMonkeyLogItem} - */ -public class SmartMonkeyLogParserTest extends TestCase { - - /** - * Test for detecting UI exceptions - * @throws ParseException - */ - public void testExceptions() throws ParseException { - List<String> lines = Arrays.asList( - "2013-03-04 12:33:18.789: Starting [UiAutomator Tests][com.android.cts.uiautomator]", - "2013-03-04 12:33:18.792: Target invocation count: 1000", - "2013-03-04 12:33:18.793: Throttle: 0 ms", - "2013-03-04 12:33:19.795: [ 0](Seq: -1)-Launching UiAutomator Tests", - "2013-03-04 12:33:37.211: [ 0](Seq: 0)-Found 6 candidates. Using index: 1", - "2013-03-04 12:33:37.336: [ 0](Seq: 0)-Clicking: CheckBox (760,194)", - "2013-03-04 12:33:38.443: [ 1](Seq: 0)-Found 6 candidates. Using index: 5", - "2013-03-04 12:33:38.533: [ 1](Seq: 0)-Clicking: Button~Description for Button (723,874)", - "2013-03-04 12:33:39.510: [ 2](Seq: 0)-UI Exception: CRASH: Unfortunately, UiAutomator Test App has stopped.", - "2013-03-04 12:43:39.510: [ 2](Seq: 0)-UI Exception: ANR: UiAutomator is not responding.", - "2013-03-04 12:53:39.513: Invocations requested: 1000", - "2013-03-04 12:53:39.518: Invocations completed: 2", - "2013-03-04 12:53:39.520: Device uptime: 608193 sec, Monkey run duration: 20 sec"); - - SmartMonkeyLogItem monkeyLog = new SmartMonkeyLogParser().parse(lines); - assertNotNull(monkeyLog); - assertEquals(1, monkeyLog.getCrashTimes().size()); - assertEquals(1, monkeyLog.getAnrTimes().size()); - assertEquals(SmartMonkeyLogParser.parseTime("2013-03-04 12:33:39.510"), - monkeyLog.getCrashTimes().toArray()[0]); - assertEquals(SmartMonkeyLogParser.parseTime("2013-03-04 12:43:39.510"), - monkeyLog.getAnrTimes().toArray()[0]); - } - - /** - * Tests for parsing smart monkey log header - * @throws ParseException - */ - public void testHeader() throws ParseException { - List<String> lines = Arrays.asList( - "2013-03-04 12:33:18.789: Starting [UiAutomator Tests|YouTube][com.android.cts.uiautomator|com.google.android.youtube]", - "2013-03-04 12:33:18.792: Target invocation count: 1000", - "2013-03-04 12:33:18.793: Throttle: 1500 ms", - "2013-03-04 12:33:18.793: Device uptime: 608173 sec", - "2013-03-04 12:33:19.795: [ 0](Seq: -1)-Launching UiAutomator Tests", - "2013-03-04 12:33:37.211: [ 0](Seq: 0)-Found 6 candidates. Using index: 1", - "2013-03-04 12:33:37.336: [ 0](Seq: 0)-Clicking: CheckBox (760,194)", - "2013-03-04 12:33:38.443: [ 1](Seq: 0)-Found 6 candidates. Using index: 5", - "2013-03-04 12:33:38.533: [ 1](Seq: 0)-Clicking: Button~Description for Button (723,874)", - "2013-03-04 12:33:39.510: [ 2](Seq: 0)-UI Exception: CRASH: Unfortunately, UiAutomator Test App has stopped.", - "2013-03-04 12:43:39.510: [ 2](Seq: 0)-UI Exception: ANR: UiAutomator is not responding.", - "2013-03-04 12:53:39.513: Invocations requested: 1000", - "2013-03-04 12:53:39.518: Invocations completed: 2", - "2013-03-04 12:53:39.520: Device uptime: 608193 sec, Monkey run duration: 20 sec"); - SmartMonkeyLogItem monkeyLog = new SmartMonkeyLogParser().parse(lines); - assertNotNull(monkeyLog); - assertEquals(2, monkeyLog.getApplications().size()); - assertEquals("UiAutomator Tests", monkeyLog.getApplications().get(0)); - assertEquals("YouTube", monkeyLog.getApplications().get(1)); - assertEquals(2, monkeyLog.getPackages().size()); - assertEquals("com.android.cts.uiautomator", monkeyLog.getPackages().get(0)); - assertEquals("com.google.android.youtube", monkeyLog.getPackages().get(1)); - assertEquals(SmartMonkeyLogParser.parseTime("2013-03-04 12:33:18.789"), - monkeyLog.getStartTime()); - assertEquals(608173, monkeyLog.getStartUptimeDuration()); - assertEquals(1000, monkeyLog.getTargetInvocations()); - assertEquals(1500, monkeyLog.getThrottle()); - } - - /** - * Test for parsing log in flight - * @throws ParseException - */ - public void testIntermidiateStop() throws ParseException { - List<String> lines = Arrays.asList( - "2013-03-04 12:33:18.789: Starting [UiAutomator Tests|YouTube][com.android.cts.uiautomator|com.google.android.youtube]", - "2013-03-04 12:33:18.792: Target invocation count: 1000", - "2013-03-04 12:33:18.793: Throttle: 1500 ms", - "2013-03-04 12:33:19.795: [ 0](Seq: -1)-Launching UiAutomator Tests", - "2013-03-04 12:33:37.211: [ 0](Seq: 0)-Found 6 candidates. Using index: 1", - "2013-03-04 12:33:37.336: [ 0](Seq: 0)-Clicking: CheckBox (760,194)", - "2013-03-04 12:33:38.443: [ 1](Seq: 0)-Found 6 candidates. Using index: 5", - "2013-03-04 12:33:38.533: [ 12](Seq: 3)-Clicking: Button~Description for Button (723,874)", - "2013-03-04 12:33:39.510: [ 12](Seq: 3)-UI Exception: CRASH: Unfortunately, UiAutomator Test App has stopped."); - - SmartMonkeyLogItem monkeyLog = new SmartMonkeyLogParser().parse(lines); - assertNotNull(monkeyLog); - assertEquals(12, monkeyLog.getIntermediateCount()); - assertEquals(SmartMonkeyLogParser.parseTime("2013-03-04 12:33:39.510"), - monkeyLog.getIntermediateTime()); - } - - /** - * Tests for parsing smart monkey log footer - * @throws ParseException - */ - public void testFooter() throws ParseException { - List<String> lines = Arrays.asList( - "2013-03-04 12:33:18.789: Starting [UiAutomator Tests|YouTube][com.android.cts.uiautomator|com.google.android.youtube]", - "2013-03-04 12:33:18.792: Target invocation count: 1000", - "2013-03-04 12:33:18.793: Throttle: 1500 ms", - "2013-03-04 12:33:19.795: [ 0](Seq: -1)-Launching UiAutomator Tests", - "2013-03-04 12:33:37.211: [ 0](Seq: 0)-Found 6 candidates. Using index: 1", - "2013-03-04 12:33:37.336: [ 0](Seq: 0)-Clicking: CheckBox (760,194)", - "2013-03-04 12:33:38.443: [ 1](Seq: 0)-Found 6 candidates. Using index: 5", - "2013-03-04 12:33:38.533: [ 1](Seq: 0)-Clicking: Button~Description for Button (723,874)", - "2013-03-04 12:33:38.443: [ 2](Seq: 0)-Found 6 candidates. Using index: 5", - "2013-03-04 12:33:38.533: [ 2](Seq: 0)-Clicking: Button~Description for Button (723,874)", - "2013-03-04 12:53:39.513: Monkey aborted.", - "2013-03-04 12:53:39.513: Invocations requested: 1000", - "2013-03-04 12:53:39.518: Invocations completed: 999", - "2013-03-04 12:53:39.520: Device uptime: 608193 sec, Monkey run duration: 20 sec"); - - SmartMonkeyLogItem monkeyLog = new SmartMonkeyLogParser().parse(lines); - assertNotNull(monkeyLog); - assertEquals(999, monkeyLog.getFinalCount()); - assertEquals(20, monkeyLog.getTotalDuration()); - assertEquals(608193, monkeyLog.getStopUptimeDuration()); - assertEquals(true, monkeyLog.getIsAborted()); - } -} diff --git a/src/com/android/loganalysis/LogAnalyzer.java b/src/com/android/loganalysis/LogAnalyzer.java index 5a16c23..df7d63f 100644 --- a/src/com/android/loganalysis/LogAnalyzer.java +++ b/src/com/android/loganalysis/LogAnalyzer.java @@ -21,13 +21,11 @@ import com.android.loganalysis.item.IItem; import com.android.loganalysis.item.KernelLogItem; import com.android.loganalysis.item.LogcatItem; import com.android.loganalysis.item.MemoryHealthItem; -import com.android.loganalysis.item.MonkeyLogItem; import com.android.loganalysis.parser.BugreportParser; import com.android.loganalysis.parser.DvmLockSampleParser; import com.android.loganalysis.parser.KernelLogParser; import com.android.loganalysis.parser.LogcatParser; import com.android.loganalysis.parser.MemoryHealthParser; -import com.android.loganalysis.parser.MonkeyLogParser; import com.android.loganalysis.rule.RuleEngine; import com.android.loganalysis.rule.RuleEngine.RuleType; import com.android.loganalysis.util.config.ArgsOptionParser; @@ -71,9 +69,6 @@ public class LogAnalyzer { @Option(name="kernel-log", description="The path to the kernel log") private String mKernelLogPath = null; - @Option(name="monkey-log", description="The path to the monkey log") - private String mMonkeyLogPath = null; - @Option(name="memory-health", description="The path to the memory health log") private String mMemoryHealthLogPath = null; @@ -133,13 +128,6 @@ public class LogAnalyzer { return; } - if (mMonkeyLogPath != null) { - reader = getBufferedReader(mMonkeyLogPath); - MonkeyLogItem monkeyLog = new MonkeyLogParser().parse(reader); - printMonkeyLog(monkeyLog); - return; - } - if (mMemoryHealthLogPath != null) { reader = getBufferedReader(mMemoryHealthLogPath); MemoryHealthItem item = new MemoryHealthParser().parse(reader); @@ -255,16 +243,6 @@ public class LogAnalyzer { } /** - * Print the monkey log to stdout. - */ - private void printMonkeyLog(MonkeyLogItem monkeyLog) { - if (OutputFormat.JSON.equals(mOutputFormat)) { - printJson(monkeyLog); - } - // TODO: Print monkey log in human readable form. - } - - /** * Print a DVM log entry to stdout. */ private void printDVMLog(DvmLockSampleItem dvmLog) { @@ -338,7 +316,6 @@ public class LogAnalyzer { if (mBugreportPath != null) logCount++; if (mLogcatPath != null) logCount++; if (mKernelLogPath != null) logCount++; - if (mMonkeyLogPath != null) logCount++; if (mMemoryHealthLogPath != null) logCount++; return (logCount == 1); } @@ -347,8 +324,9 @@ public class LogAnalyzer { * Print the usage for the command. */ private void printUsage() { - System.err.println("Usage: loganalysis [--bugreport FILE | --events-log FILE | --logcat FILE | " + - "--kernel-log FILE | --monkey-log FILE]"); + System.err.println( + "Usage: loganalysis [--bugreport FILE | --events-log FILE | --logcat FILE | " + + "--kernel-log FILE]"); } /** diff --git a/src/com/android/loganalysis/item/MonkeyLogItem.java b/src/com/android/loganalysis/item/MonkeyLogItem.java deleted file mode 100644 index ef8d9e3..0000000 --- a/src/com/android/loganalysis/item/MonkeyLogItem.java +++ /dev/null @@ -1,373 +0,0 @@ -/* - * Copyright (C) 2012 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.android.loganalysis.item; - -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - -import java.util.Arrays; -import java.util.Date; -import java.util.HashSet; -import java.util.Set; - -/** - * An {@link IItem} used to store monkey log info. - */ -public class MonkeyLogItem extends GenericItem { - @SuppressWarnings("serial") - private class StringSet extends HashSet<String> {} - - public enum DroppedCategory { - KEYS, - POINTERS, - TRACKBALLS, - FLIPS, - ROTATIONS - } - - /** Constant for JSON output */ - public static final String START_TIME = "START_TIME"; - /** Constant for JSON output */ - public static final String STOP_TIME = "STOP_TIME"; - /** Constant for JSON output */ - public static final String PACKAGES = "PACKAGES"; - /** Constant for JSON output */ - public static final String CATEGORIES = "CATEGORIES"; - /** Constant for JSON output */ - public static final String THROTTLE = "THROTTLE"; - /** Constant for JSON output */ - public static final String SEED = "SEED"; - /** Constant for JSON output */ - public static final String TARGET_COUNT = "TARGET_COUNT"; - /** Constant for JSON output */ - public static final String IGNORE_SECURITY_EXCEPTIONS = "IGNORE_SECURITY_EXCEPTIONS"; - /** Constant for JSON output */ - public static final String TOTAL_DURATION = "TOTAL_TIME"; - /** Constant for JSON output */ - public static final String START_UPTIME_DURATION = "START_UPTIME"; - /** Constant for JSON output */ - public static final String STOP_UPTIME_DURATION = "STOP_UPTIME"; - /** Constant for JSON output */ - public static final String IS_FINISHED = "IS_FINISHED"; - /** Constant for JSON output */ - public static final String NO_ACTIVITIES = "NO_ACTIVITIES"; - /** Constant for JSON output */ - public static final String INTERMEDIATE_COUNT = "INTERMEDIATE_COUNT"; - /** Constant for JSON output */ - public static final String FINAL_COUNT = "FINAL_COUNT"; - /** Constant for JSON output */ - public static final String CRASH = "CRASH"; - - private static final Set<String> ATTRIBUTES = new HashSet<String>(Arrays.asList( - START_TIME, STOP_TIME, PACKAGES, CATEGORIES, THROTTLE, SEED, TARGET_COUNT, - IGNORE_SECURITY_EXCEPTIONS, TOTAL_DURATION, START_UPTIME_DURATION, STOP_UPTIME_DURATION, - IS_FINISHED, NO_ACTIVITIES, INTERMEDIATE_COUNT, FINAL_COUNT, CRASH, - DroppedCategory.KEYS.toString(), - DroppedCategory.POINTERS.toString(), - DroppedCategory.TRACKBALLS.toString(), - DroppedCategory.FLIPS.toString(), - DroppedCategory.ROTATIONS.toString())); - - /** - * The constructor for {@link MonkeyLogItem}. - */ - public MonkeyLogItem() { - super(ATTRIBUTES); - - setAttribute(PACKAGES, new StringSet()); - setAttribute(CATEGORIES, new StringSet()); - setAttribute(THROTTLE, 0); - setAttribute(IGNORE_SECURITY_EXCEPTIONS, false); - setAttribute(IS_FINISHED, false); - setAttribute(NO_ACTIVITIES, false); - setAttribute(INTERMEDIATE_COUNT, 0); - } - - /** - * Get the start time of the monkey log. - */ - public Date getStartTime() { - return (Date) getAttribute(START_TIME); - } - - /** - * Set the start time of the monkey log. - */ - public void setStartTime(Date time) { - setAttribute(START_TIME, time); - } - - /** - * Get the stop time of the monkey log. - */ - public Date getStopTime() { - return (Date) getAttribute(STOP_TIME); - } - - /** - * Set the stop time of the monkey log. - */ - public void setStopTime(Date time) { - setAttribute(STOP_TIME, time); - } - - /** - * Get the set of packages that the monkey is run on. - */ - public Set<String> getPackages() { - return (StringSet) getAttribute(PACKAGES); - } - - /** - * Add a package to the set that the monkey is run on. - */ - public void addPackage(String thePackage) { - ((StringSet) getAttribute(PACKAGES)).add(thePackage); - } - - /** - * Get the set of categories that the monkey is run on. - */ - public Set<String> getCategories() { - return (StringSet) getAttribute(CATEGORIES); - } - - /** - * Add a category to the set that the monkey is run on. - */ - public void addCategory(String category) { - ((StringSet) getAttribute(CATEGORIES)).add(category); - } - - /** - * Get the throttle for the monkey run. - */ - public int getThrottle() { - return (Integer) getAttribute(THROTTLE); - } - - /** - * Set the throttle for the monkey run. - */ - public void setThrottle(int throttle) { - setAttribute(THROTTLE, throttle); - } - - /** - * Get the seed for the monkey run. - */ - public Long getSeed() { - return (Long) getAttribute(SEED); - } - - /** - * Set the seed for the monkey run. - */ - public void setSeed(long seed) { - setAttribute(SEED, seed); - } - - /** - * Get the target count for the monkey run. - */ - public Integer getTargetCount() { - return (Integer) getAttribute(TARGET_COUNT); - } - - /** - * Set the target count for the monkey run. - */ - public void setTargetCount(int count) { - setAttribute(TARGET_COUNT, count); - } - - /** - * Get if the ignore security exceptions flag is set for the monkey run. - */ - public boolean getIgnoreSecurityExceptions() { - return (Boolean) getAttribute(IGNORE_SECURITY_EXCEPTIONS); - } - - /** - * Set if the ignore security exceptions flag is set for the monkey run. - */ - public void setIgnoreSecurityExceptions(boolean ignore) { - setAttribute(IGNORE_SECURITY_EXCEPTIONS, ignore); - } - - /** - * Get the total duration of the monkey run in milliseconds. - */ - public Long getTotalDuration() { - return (Long) getAttribute(TOTAL_DURATION); - } - - /** - * Set the total duration of the monkey run in milliseconds. - */ - public void setTotalDuration(long time) { - setAttribute(TOTAL_DURATION, time); - } - - /** - * Get the start uptime duration of the monkey run in milliseconds. - */ - public Long getStartUptimeDuration() { - return (Long) getAttribute(START_UPTIME_DURATION); - } - - /** - * Set the start uptime duration of the monkey run in milliseconds. - */ - public void setStartUptimeDuration(long uptime) { - setAttribute(START_UPTIME_DURATION, uptime); - } - - /** - * Get the stop uptime duration of the monkey run in milliseconds. - */ - public Long getStopUptimeDuration() { - return (Long) getAttribute(STOP_UPTIME_DURATION); - } - - /** - * Set the stop uptime duration of the monkey run in milliseconds. - */ - public void setStopUptimeDuration(long uptime) { - setAttribute(STOP_UPTIME_DURATION, uptime); - } - - /** - * Get if the monkey run finished without crashing. - */ - public boolean getIsFinished() { - return (Boolean) getAttribute(IS_FINISHED); - } - - /** - * Set if the monkey run finished without crashing. - */ - public void setIsFinished(boolean finished) { - setAttribute(IS_FINISHED, finished); - } - - /** - * Get if the monkey run aborted due to no activies to run. - */ - public boolean getNoActivities() { - return (Boolean) getAttribute(NO_ACTIVITIES); - } - - /** - * Set if the monkey run aborted due to no activies to run. - */ - public void setNoActivities(boolean noActivities) { - setAttribute(NO_ACTIVITIES, noActivities); - } - - - /** - * Get the intermediate count for the monkey run. - * <p> - * This count starts at 0 and increments every 100 events. This number should be within 100 of - * the final count. - * </p> - */ - public int getIntermediateCount() { - return (Integer) getAttribute(INTERMEDIATE_COUNT); - } - - /** - * Set the intermediate count for the monkey run. - * <p> - * This count starts at 0 and increments every 100 events. This number should be within 100 of - * the final count. - * </p> - */ - public void setIntermediateCount(int count) { - setAttribute(INTERMEDIATE_COUNT, count); - } - - /** - * Get the final count for the monkey run. - */ - public Integer getFinalCount() { - return (Integer) getAttribute(FINAL_COUNT); - } - - /** - * Set the final count for the monkey run. - */ - public void setFinalCount(int count) { - setAttribute(FINAL_COUNT, count); - } - - /** - * Get the dropped events count for a {@link DroppedCategory} for the monkey run. - */ - public Integer getDroppedCount(DroppedCategory category) { - return (Integer) getAttribute(category.toString()); - } - - /** - * Set the dropped events count for a {@link DroppedCategory} for the monkey run. - */ - public void setDroppedCount(DroppedCategory category, int count) { - setAttribute(category.toString(), count); - } - - /** - * Get the {@link AnrItem}, {@link JavaCrashItem}, or {@link NativeCrashItem} for the monkey run - * or null if there was no crash. - */ - public MiscLogcatItem getCrash() { - return (MiscLogcatItem) getAttribute(CRASH); - } - - /** - * Set the {@link AnrItem}, {@link JavaCrashItem}, or {@link NativeCrashItem} for the monkey - * run. - */ - public void setCrash(MiscLogcatItem crash) { - setAttribute(CRASH, crash); - } - - /** - * {@inheritDoc} - */ - @Override - public JSONObject toJson() { - JSONObject object = super.toJson(); - - // Override packages and categories - put(object, PACKAGES, new JSONArray(getPackages())); - put(object, CATEGORIES, new JSONArray(getCategories())); - - return object; - } - - /** - * Try to put an {@link Object} in a {@link JSONObject} and remove the existing key if it fails. - */ - private static void put(JSONObject object, String key, Object value) { - try { - object.put(key, value); - } catch (JSONException e) { - object.remove(key); - } - } -} diff --git a/src/com/android/loganalysis/item/SmartMonkeyLogItem.java b/src/com/android/loganalysis/item/SmartMonkeyLogItem.java deleted file mode 100644 index a8645e1..0000000 --- a/src/com/android/loganalysis/item/SmartMonkeyLogItem.java +++ /dev/null @@ -1,366 +0,0 @@ -/* - * Copyright (C) 2013 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.android.loganalysis.item; - -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Date; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -/** - * An {@link IItem} used to store monkey log info. - */ -public class SmartMonkeyLogItem extends GenericItem { - - @SuppressWarnings("serial") - private class DateSet extends HashSet<Date> {} - - /** Constant for JSON output */ - public static final String START_TIME = "START_TIME"; - /** Constant for JSON output */ - public static final String STOP_TIME = "STOP_TIME"; - /** Constant for JSON output */ - public static final String APPLICATIONS = "APPS"; - /** Constant for JSON output */ - public static final String PACKAGES = "PACKAGES"; - /** Constant for JSON output */ - public static final String THROTTLE = "THROTTLE"; - /** Constant for JSON output */ - public static final String TARGET_INVOCATIONS = "TARGET_INVOCATIONS"; - /** Constant for JSON output */ - public static final String TOTAL_DURATION = "TOTAL_TIME"; - /** Constant for JSON output */ - public static final String START_UPTIME_DURATION = "START_UPTIME"; - /** Constant for JSON output */ - public static final String STOP_UPTIME_DURATION = "STOP_UPTIME"; - /** Constant for JSON output */ - public static final String IS_FINISHED = "IS_FINISHED"; - /** Constant for JSON output */ - public static final String ABORTED = "ABORTED"; - /** Constant for JSON output */ - public static final String INTERMEDIATE_COUNT = "INTERMEDIATE_COUNT"; - /** Constant for JSON output */ - public static final String FINAL_COUNT = "FINAL_COUNT"; - /** Constant for JSON output */ - public static final String ANR_TIMES = "ANR_TIMES"; - /** Constant for JSON output */ - public static final String CRASH_TIMES = "CRASH_TIMES"; - /** Constant for JSON output */ - public static final String INTERMEDIATE_TIME = "INTERMEDIATE_TIME"; - - private static final Set<String> ATTRIBUTES = new HashSet<String>(Arrays.asList( - START_TIME, STOP_TIME, PACKAGES, THROTTLE, TARGET_INVOCATIONS, ABORTED, - TOTAL_DURATION, START_UPTIME_DURATION, STOP_UPTIME_DURATION, APPLICATIONS, - IS_FINISHED, INTERMEDIATE_COUNT, FINAL_COUNT, ANR_TIMES, CRASH_TIMES, - INTERMEDIATE_TIME)); - - /** - * The constructor for {@link MonkeyLogItem}. - */ - public SmartMonkeyLogItem() { - super(ATTRIBUTES); - - setAttribute(APPLICATIONS, new ArrayList<String>()); - setAttribute(PACKAGES, new ArrayList<String>()); - setAttribute(CRASH_TIMES, new DateSet()); - setAttribute(ANR_TIMES, new DateSet()); - setAttribute(INTERMEDIATE_TIME, new DateSet()); - setAttribute(THROTTLE, 0); - setAttribute(FINAL_COUNT, 0); - setAttribute(IS_FINISHED, false); - setAttribute(ABORTED, false); - setAttribute(INTERMEDIATE_COUNT, 0); - setAttribute(START_UPTIME_DURATION, 0L); - setAttribute(STOP_UPTIME_DURATION, 0L); - } - - /** - * Get the start time of the monkey log. - */ - public Date getStartTime() { - return (Date) getAttribute(START_TIME); - } - - /** - * Set the start time of the monkey log. - */ - public void setStartTime(Date time) { - setAttribute(START_TIME, time); - } - - /** - * Set the last time reported for a monkey event - */ - public void setIntermediateTime(Date time) { - setAttribute(INTERMEDIATE_TIME, time); - } - - /** - * Get the last time reported for a monkey event - */ - public Date getIntermediateTime() { - return (Date) getAttribute(INTERMEDIATE_TIME); - } - - /** - * Get the stop time of the monkey log. - */ - public Date getStopTime() { - return (Date) getAttribute(STOP_TIME); - } - - /** - * Set the stop time of the monkey log. - */ - public void setStopTime(Date time) { - setAttribute(STOP_TIME, time); - } - - /** - * Get the set of packages that the monkey is run on. - */ - @SuppressWarnings("unchecked") - public List<String> getPackages() { - return (List<String>) getAttribute(PACKAGES); - } - - /** - * Add a package to the set that the monkey is run on. - */ - @SuppressWarnings("unchecked") - public void addPackage(String thePackage) { - ((List<String>) getAttribute(PACKAGES)).add(thePackage); - } - - /** - * Get the set of packages that the monkey is run on. - */ - @SuppressWarnings("unchecked") - public List<String> getApplications() { - return (List<String>) getAttribute(APPLICATIONS); - } - - /** - * Add a package to the set that the monkey is run on. - */ - @SuppressWarnings("unchecked") - public void addApplication(String theApp) { - ((List<String>) getAttribute(APPLICATIONS)).add(theApp); - } - - /** - * Get the throttle for the monkey run. - */ - public int getThrottle() { - return (Integer) getAttribute(THROTTLE); - } - - /** - * Set the throttle for the monkey run. - */ - public void setThrottle(int throttle) { - setAttribute(THROTTLE, throttle); - } - - /** - * Get the target sequence invocations for the monkey run. - */ - public int getTargetInvocations() { - return (Integer) getAttribute(TARGET_INVOCATIONS); - } - - /** - * Set the target sequence invocations for the monkey run. - */ - public void setTargetInvocations(int count) { - setAttribute(TARGET_INVOCATIONS, count); - } - - /** - * Get the total duration of the monkey run in milliseconds. - */ - public long getTotalDuration() { - if (getIsFinished() || getIsAborted()) - return (Long) getAttribute(TOTAL_DURATION); - // else it crashed - Date startTime = getStartTime(); - Date endTime = getIntermediateTime(); - return endTime.getTime() - startTime.getTime() / 1000; - } - - /** - * Set the total duration of the monkey run in milliseconds. - */ - public void setTotalDuration(long time) { - setAttribute(TOTAL_DURATION, time); - } - - /** - * Get the start uptime duration of the monkey run in milliseconds. - */ - public long getStartUptimeDuration() { - return (Long) getAttribute(START_UPTIME_DURATION); - } - - /** - * Set the start uptime duration of the monkey run in milliseconds. - */ - public void setStartUptimeDuration(long uptime) { - setAttribute(START_UPTIME_DURATION, uptime); - } - - /** - * Get the stop uptime duration of the monkey run in milliseconds. - */ - public long getStopUptimeDuration() { - return (Long) getAttribute(STOP_UPTIME_DURATION); - } - - /** - * Set the stop uptime duration of the monkey run in milliseconds. - */ - public void setStopUptimeDuration(long uptime) { - setAttribute(STOP_UPTIME_DURATION, uptime); - } - - /** - * Get if the monkey run finished without crashing. - */ - public boolean getIsFinished() { - return (Boolean) getAttribute(IS_FINISHED); - } - - /** - * Set if the monkey run finished without crashing. - */ - public void setIsFinished(boolean finished) { - setAttribute(IS_FINISHED, finished); - } - - /** - * Get the intermediate count for the monkey run. - * <p> - * This count starts at 0 and increments every 100 events. This number should be within 100 of - * the final count. - * </p> - */ - public int getIntermediateCount() { - return (Integer) getAttribute(INTERMEDIATE_COUNT); - } - - /** - * Set the intermediate count for the monkey run. - * <p> - * This count starts at 0 and increments every 100 events. This number should be within 100 of - * the final count. - * </p> - */ - public void setIntermediateCount(int count) { - setAttribute(INTERMEDIATE_COUNT, count); - } - - /** - * Get the final count for the monkey run. - */ - public int getFinalCount() { - if (getIsFinished()) - return (Integer) getAttribute(FINAL_COUNT); - return getIntermediateCount(); - } - - /** - * Set the final count for the monkey run. - */ - public void setFinalCount(int count) { - setAttribute(FINAL_COUNT, count); - } - - /** - * Get ANR times - */ - public Set<Date> getAnrTimes() { - return (DateSet) getAttribute(ANR_TIMES); - } - - /** - * Add ANR time - */ - public void addAnrTime(Date time) { - ((DateSet) getAttribute(ANR_TIMES)).add(time); - } - - /** - * Get Crash times - */ - public Set<Date> getCrashTimes() { - return (DateSet) getAttribute(CRASH_TIMES); - } - - /** - * Add Crash time - */ - public void addCrashTime(Date time) { - ((DateSet) getAttribute(CRASH_TIMES)).add(time); - } - - /** - * Get the status of no sequences abort - */ - public boolean getIsAborted() { - return (Boolean) getAttribute(ABORTED); - } - - /** - * Set the status of no sequences abort - * @param noSeq - */ - public void setIsAborted(boolean noSeq) { - setAttribute(ABORTED, noSeq); - } - - /** - * {@inheritDoc} - */ - @Override - public JSONObject toJson() { - JSONObject object = super.toJson(); - - // Override application, packages, and ANR and crash times. - put(object, APPLICATIONS, new JSONArray(getApplications())); - put(object, PACKAGES, new JSONArray(getPackages())); - put(object, ANR_TIMES, new JSONArray(getAnrTimes())); - put(object, CRASH_TIMES, new JSONArray(getCrashTimes())); - - return object; - } - - /** - * Try to put an {@link Object} in a {@link JSONObject} and remove the existing key if it fails. - */ - private static void put(JSONObject object, String key, Object value) { - try { - object.put(key, value); - } catch (JSONException e) { - object.remove(key); - } - } -} diff --git a/src/com/android/loganalysis/parser/MonkeyLogParser.java b/src/com/android/loganalysis/parser/MonkeyLogParser.java deleted file mode 100644 index 0fbb3f8..0000000 --- a/src/com/android/loganalysis/parser/MonkeyLogParser.java +++ /dev/null @@ -1,347 +0,0 @@ -/* - * Copyright (C) 2012 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.android.loganalysis.parser; - -import com.android.loganalysis.item.AnrItem; -import com.android.loganalysis.item.MiscLogcatItem; -import com.android.loganalysis.item.MonkeyLogItem; -import com.android.loganalysis.item.MonkeyLogItem.DroppedCategory; -import com.android.loganalysis.item.NativeCrashItem; -import com.android.loganalysis.item.TracesItem; - -import java.io.BufferedReader; -import java.io.IOException; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.LinkedList; -import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * A {@link IParser} to parse monkey logs. - */ -public class MonkeyLogParser implements IParser { - private static final Pattern THROTTLE = Pattern.compile( - "adb shell monkey.* --throttle (\\d+).*"); - private static final Pattern SEED_AND_TARGET_COUNT = Pattern.compile( - ":Monkey: seed=(\\d+) count=(\\d+)"); - private static final Pattern SECURITY_EXCEPTIONS = Pattern.compile( - "adb shell monkey.* --ignore-security-exceptions.*"); - - private static final Pattern PACKAGES = Pattern.compile(":AllowPackage: (\\S+)"); - private static final Pattern CATEGORIES = Pattern.compile(":IncludeCategory: (\\S+)"); - - private static final Pattern START_UPTIME = Pattern.compile( - "# (.*) - device uptime = (\\d+\\.\\d+): Monkey command used for this test:"); - private static final Pattern STOP_UPTIME = Pattern.compile( - "# (.*) - device uptime = (\\d+\\.\\d+): Monkey command ran for: " + - "(\\d+):(\\d+) \\(mm:ss\\)"); - - private static final Pattern INTERMEDIATE_COUNT = Pattern.compile( - "\\s+// Sending event #(\\d+)"); - private static final Pattern FINISHED = Pattern.compile("// Monkey finished"); - private static final Pattern FINAL_COUNT = Pattern.compile("Events injected: (\\d+)"); - private static final Pattern NO_ACTIVITIES = Pattern.compile( - "\\*\\* No activities found to run, monkey aborted."); - - private static final Pattern DROPPED_KEYS = Pattern.compile(":Dropped: .*keys=(\\d+).*"); - private static final Pattern DROPPED_POINTERS = Pattern.compile( - ":Dropped: .*pointers=(\\d+).*"); - private static final Pattern DROPPED_TRACKBALLS = Pattern.compile( - ":Dropped: .*trackballs=(\\d+).*"); - private static final Pattern DROPPED_FLIPS = Pattern.compile(":Dropped: .*flips=(\\d+).*"); - private static final Pattern DROPPED_ROTATIONS = Pattern.compile( - ":Dropped: .*rotations=(\\d+).*"); - - // Log messages can get intermixed in crash message, ignore those in the crash context. - private static final Pattern MONKEY_LOG_MESSAGE = Pattern.compile("$(:|Sleeping| //)"); - - private static final Pattern ANR = Pattern.compile( - "// NOT RESPONDING: (\\S+) \\(pid (\\d+)\\)"); - private static final Pattern CRASH = Pattern.compile( - "// CRASH: (\\S+) \\(pid (\\d+)\\)"); - private static final Pattern EMPTY_NATIVE_CRASH = Pattern.compile("" + - "\\*\\* New native crash detected."); - private static final Pattern ABORTED = Pattern.compile("\\*\\* Monkey aborted due to error."); - - private static final Pattern TRACES_START = Pattern.compile("anr traces:"); - private static final Pattern TRACES_STOP = Pattern.compile("// anr traces status was \\d+"); - - private boolean mMatchingAnr = false; - private boolean mMatchingCrash = false; - private boolean mMatchingJavaCrash = false; - private boolean mMatchingNativeCrash = false; - private boolean mMatchingTraces = false; - private boolean mMatchedTrace = false; - private List<String> mBlock = null; - private String mApp = null; - private Integer mPid = null; - - private MonkeyLogItem mMonkeyLog = new MonkeyLogItem(); - - /** - * Parse a monkey log from a {@link BufferedReader} into an {@link MonkeyLogItem} object. - * - * @param input a {@link BufferedReader}. - * @return The {@link MonkeyLogItem}. - * @see #parse(List) - */ - public MonkeyLogItem parse(BufferedReader input) throws IOException { - String line; - while ((line = input.readLine()) != null) { - parseLine(line); - } - - return mMonkeyLog; - } - - /** - * {@inheritDoc} - * - * @return The {@link MonkeyLogItem}. - */ - @Override - public MonkeyLogItem parse(List<String> lines) { - for (String line : lines) { - parseLine(line); - } - - return mMonkeyLog; - } - - /** - * Parse a line of input. - */ - private void parseLine(String line) { - Matcher m; - - if (mMatchingAnr) { - if ("".equals(line)) { - AnrItem crash = new AnrParser().parse(mBlock); - addCrashAndReset(crash); - } else { - m = MONKEY_LOG_MESSAGE.matcher(line); - if (!m.matches()) { - mBlock.add(line); - } - return; - } - } - - if (mMatchingCrash) { - if (!mMatchingJavaCrash && !mMatchingNativeCrash && line.startsWith("// Short Msg: ")) { - if (line.contains("Native crash")) { - mMatchingNativeCrash = true; - } else { - mMatchingJavaCrash = true; - } - } - m = ABORTED.matcher(line); - if (m.matches()) { - MiscLogcatItem crash = null; - if (mMatchingJavaCrash) { - crash = new JavaCrashParser().parse(mBlock); - } else if (mMatchingNativeCrash) { - crash = new NativeCrashParser().parse(mBlock); - } - addCrashAndReset(crash); - } else { - m = MONKEY_LOG_MESSAGE.matcher(line); - if (!m.matches() && line.startsWith("// ") && !line.startsWith("// ** ")) { - line = line.replace("// ", ""); - mBlock.add(line); - } - return; - } - } - - if (mMatchingTraces) { - m = TRACES_STOP.matcher(line); - if (m.matches()) { - TracesItem traces = new TracesParser().parse(mBlock); - - // Set the trace if the crash is an ANR and if the app for the crash and trace match - if (traces != null && traces.getApp() != null && traces.getStack() != null && - mMonkeyLog.getCrash() instanceof AnrItem && - traces.getApp().equals(mMonkeyLog.getCrash().getApp())) { - ((AnrItem) mMonkeyLog.getCrash()).setTrace(traces.getStack()); - } - - reset(); - mMatchedTrace = true; - } else { - m = MONKEY_LOG_MESSAGE.matcher(line); - if (!m.matches()) { - mBlock.add(line); - } - return; - } - } - - m = THROTTLE.matcher(line); - if (m.matches()) { - mMonkeyLog.setThrottle(Integer.parseInt(m.group(1))); - } - m = SEED_AND_TARGET_COUNT.matcher(line); - if (m.matches()) { - mMonkeyLog.setSeed(Long.parseLong(m.group(1))); - mMonkeyLog.setTargetCount(Integer.parseInt(m.group(2))); - } - m = SECURITY_EXCEPTIONS.matcher(line); - if (m.matches()) { - mMonkeyLog.setIgnoreSecurityExceptions(true); - } - m = PACKAGES.matcher(line); - if (m.matches()) { - mMonkeyLog.addPackage(m.group(1)); - } - m = CATEGORIES.matcher(line); - if (m.matches()) { - mMonkeyLog.addCategory(m.group(1)); - } - m = START_UPTIME.matcher(line); - if (m.matches()) { - mMonkeyLog.setStartTime(parseTime(m.group(1))); - mMonkeyLog.setStartUptimeDuration((long) (Double.parseDouble(m.group(2)) * 1000)); - } - m = STOP_UPTIME.matcher(line); - if (m.matches()) { - mMonkeyLog.setStopTime(parseTime(m.group(1))); - mMonkeyLog.setStopUptimeDuration((long) (Double.parseDouble(m.group(2)) * 1000)); - mMonkeyLog.setTotalDuration(60 * 1000 * Integer.parseInt(m.group(3)) + - 1000 *Integer.parseInt(m.group(4))); - } - m = INTERMEDIATE_COUNT.matcher(line); - if (m.matches()) { - mMonkeyLog.setIntermediateCount(Integer.parseInt(m.group(1))); - } - m = FINAL_COUNT.matcher(line); - if (m.matches()) { - mMonkeyLog.setFinalCount(Integer.parseInt(m.group(1))); - } - m = FINISHED.matcher(line); - if (m.matches()) { - mMonkeyLog.setIsFinished(true); - } - m = NO_ACTIVITIES.matcher(line); - if (m.matches()) { - mMonkeyLog.setNoActivities(true); - } - m = DROPPED_KEYS.matcher(line); - if (m.matches()) { - mMonkeyLog.setDroppedCount(DroppedCategory.KEYS, Integer.parseInt(m.group(1))); - } - m = DROPPED_POINTERS.matcher(line); - if (m.matches()) { - mMonkeyLog.setDroppedCount(DroppedCategory.POINTERS, Integer.parseInt(m.group(1))); - } - m = DROPPED_TRACKBALLS.matcher(line); - if (m.matches()) { - mMonkeyLog.setDroppedCount(DroppedCategory.TRACKBALLS, Integer.parseInt(m.group(1))); - } - m = DROPPED_FLIPS.matcher(line); - if (m.matches()) { - mMonkeyLog.setDroppedCount(DroppedCategory.FLIPS, Integer.parseInt(m.group(1))); - } - m = DROPPED_ROTATIONS.matcher(line); - if (m.matches()) { - mMonkeyLog.setDroppedCount(DroppedCategory.ROTATIONS, Integer.parseInt(m.group(1))); - } - m = ANR.matcher(line); - if (mMonkeyLog.getCrash() == null && m.matches()) { - mApp = m.group(1); - mPid = Integer.parseInt(m.group(2)); - mBlock = new LinkedList<String>(); - mMatchingAnr = true; - } - m = CRASH.matcher(line); - if (mMonkeyLog.getCrash() == null && m.matches()) { - mApp = m.group(1); - mPid = Integer.parseInt(m.group(2)); - mBlock = new LinkedList<String>(); - mMatchingCrash = true; - } - m = EMPTY_NATIVE_CRASH.matcher(line); - if (mMonkeyLog.getCrash() == null && m.matches()) { - MiscLogcatItem crash = new NativeCrashItem(); - crash.setStack(""); - addCrashAndReset(crash); - } - m = TRACES_START.matcher(line); - if (!mMatchedTrace && m.matches()) { - mBlock = new LinkedList<String>(); - mMatchingTraces = true; - } - } - - /** - * Add a crash to the monkey log item and reset the parser state for crashes. - */ - private void addCrashAndReset(MiscLogcatItem crash) { - if (crash != null) { - if (crash.getPid() == null) { - crash.setPid(mPid); - } - if (crash.getApp() == null) { - crash.setApp(mApp); - } - mMonkeyLog.setCrash(crash); - } - - reset(); - } - - /** - * Reset the parser state for crashes. - */ - private void reset() { - mApp = null; - mPid = null; - mMatchingAnr = false; - mMatchingCrash = false; - mMatchingJavaCrash = false; - mMatchingNativeCrash = false; - mMatchingTraces = false; - mBlock = null; - } - - /** - * Parse the timestamp and return a date. - * - * @param timeStr The timestamp in the format {@code E, MM/dd/yyyy hh:mm:ss a} or - * {@code EEE MMM dd HH:mm:ss zzz yyyy}. - * @return The {@link Date}. - */ - private Date parseTime(String timeStr) { - try { - return new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy").parse(timeStr); - } catch (ParseException e) { - // CLog.v("Could not parse date %s with format EEE MMM dd HH:mm:ss zzz yyyy", timeStr); - } - - try { - return new SimpleDateFormat("E, MM/dd/yyyy hh:mm:ss a").parse(timeStr); - } catch (ParseException e) { - // CLog.v("Could not parse date %s with format E, MM/dd/yyyy hh:mm:ss a", timeStr); - } - - // CLog.e("Could not parse date %s", timeStr); - return null; - } - -} diff --git a/src/com/android/loganalysis/parser/SmartMonkeyLogParser.java b/src/com/android/loganalysis/parser/SmartMonkeyLogParser.java deleted file mode 100644 index c35325c..0000000 --- a/src/com/android/loganalysis/parser/SmartMonkeyLogParser.java +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Copyright (C) 2013 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.android.loganalysis.parser; - -import com.android.loganalysis.item.SmartMonkeyLogItem; - -import java.io.BufferedReader; -import java.io.IOException; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * A {@link IParser} to parse monkey logs. - */ -public class SmartMonkeyLogParser implements IParser { - - private static final String TIME_STAMP_GROUP = - "^(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}.\\d{3}): "; - private static final String INVOKE_NUM_GROUP = "\\[.*?(\\d+)\\]"; - private static final String SEQ_NUM_GROUP = "\\(Seq:.*?(\\d+)\\)"; - - private static final Pattern START_TIME = Pattern.compile( - TIME_STAMP_GROUP + "Starting.*"); - - private static final Pattern START_UPTIME = Pattern.compile( - TIME_STAMP_GROUP + "Device uptime: (\\d+) sec$"); - - private static final Pattern STOP_UPTIME = Pattern.compile( - TIME_STAMP_GROUP + "Device uptime: (\\d+) sec, Monkey run duration: (\\d+) sec$"); - - private static final Pattern THROTTLE = Pattern.compile( - TIME_STAMP_GROUP + "Throttle: (\\d+).*"); - - private static final Pattern TARGET_INVOCATIONS = Pattern.compile( - TIME_STAMP_GROUP + "Target invocation count: (\\d+)"); - - private static final Pattern INTERMEDIATE_COUNT = Pattern.compile( - TIME_STAMP_GROUP + INVOKE_NUM_GROUP + SEQ_NUM_GROUP + ".*"); - - private static final Pattern INTERMEDIATE_TIME = Pattern.compile(TIME_STAMP_GROUP + ".*"); - - private static final Pattern FINISHED = Pattern.compile( - TIME_STAMP_GROUP + "Monkey finished"); - - private static final Pattern FINAL_COUNT = Pattern.compile( - TIME_STAMP_GROUP + "Invocations completed: (\\d+)"); - - private static final Pattern APPS_PACKAGES = Pattern.compile( - TIME_STAMP_GROUP + "Starting \\[(.*)\\]\\[(.*)\\]"); - - private static final Pattern ABORTED = Pattern.compile( - TIME_STAMP_GROUP + "Monkey aborted."); - - private static final Pattern UI_ANR = Pattern.compile( - TIME_STAMP_GROUP + INVOKE_NUM_GROUP + SEQ_NUM_GROUP + "-UI Exception: ANR: (.*)"); - - private static final Pattern UI_CRASH = Pattern.compile( - TIME_STAMP_GROUP + INVOKE_NUM_GROUP + SEQ_NUM_GROUP + "-UI Exception: CRASH: (.*)"); - - private final SmartMonkeyLogItem mSmartMonkeyLog = new SmartMonkeyLogItem(); - - /** - * Parse a monkey log from a {@link BufferedReader} into an {@link SmartMonkeyLogItem} - * object. - * - * @param input a {@link BufferedReader}. - * @return The {@link SmartMonkeyLogItem}. - * @see #parse(List) - */ - public SmartMonkeyLogItem parse(BufferedReader input) throws IOException { - String line; - while ((line = input.readLine()) != null) { - parseLine(line); - } - return mSmartMonkeyLog; - } - - /** - * {@inheritDoc} - * - * @return The {@link SmartMonkeyLogItem}. - */ - @Override - public SmartMonkeyLogItem parse(List<String> lines) { - for (String line : lines) { - parseLine(line); - } - - if (mSmartMonkeyLog.getStopUptimeDuration() == 0) - mSmartMonkeyLog.setIsFinished(false); - else - mSmartMonkeyLog.setIsFinished(true); - - return mSmartMonkeyLog; - } - - /** - * Parse a line of input. - */ - private void parseLine(String line) { - Matcher m = THROTTLE.matcher(line); - if (m.matches()) { - mSmartMonkeyLog.setThrottle(Integer.parseInt(m.group(2))); - } - m = TARGET_INVOCATIONS.matcher(line); - if (m.matches()) { - mSmartMonkeyLog.setTargetInvocations(Integer.parseInt(m.group(2))); - } - m = APPS_PACKAGES.matcher(line); - if (m.matches()) { - String apps = m.group(2); - String packages = m.group(3); - - String[] appsArray = apps.split("\\|"); - for (String a : appsArray) { - mSmartMonkeyLog.addApplication(a); - } - - String[] pkgsArray = packages.split("\\|"); - for (String p : pkgsArray) { - mSmartMonkeyLog.addPackage(p); - } - } - m = INTERMEDIATE_COUNT.matcher(line); - if (m.matches()) { - mSmartMonkeyLog.setIntermediateCount(Integer.parseInt(m.group(2))); - } - m = START_TIME.matcher(line); - if (m.matches()) { - mSmartMonkeyLog.setStartTime(parseTime(m.group(1))); - } - m = START_UPTIME.matcher(line); - if (m.matches()) { - mSmartMonkeyLog.setStartUptimeDuration(Long.parseLong(m.group(2))); - } - m = STOP_UPTIME.matcher(line); - if (m.matches()) { - mSmartMonkeyLog.setStopTime(parseTime(m.group(1))); - mSmartMonkeyLog.setStopUptimeDuration(Long.parseLong(m.group(2))); - mSmartMonkeyLog.setTotalDuration(Long.parseLong(m.group(3))); - } - m = INTERMEDIATE_TIME.matcher(line); - if (m.matches()) { - mSmartMonkeyLog.setIntermediateTime(parseTime(m.group(1))); - } - m = FINAL_COUNT.matcher(line); - if (m.matches()) { - mSmartMonkeyLog.setFinalCount(Integer.parseInt(m.group(2))); - } - m = FINISHED.matcher(line); - if (m.matches()) { - mSmartMonkeyLog.setIsFinished(true); - } - m = ABORTED.matcher(line); - if (m.matches()) { - mSmartMonkeyLog.setIsAborted(true); - } - m = UI_CRASH.matcher(line); - if (m.matches()) { - mSmartMonkeyLog.addCrashTime(parseTime(m.group(1))); - } - m = UI_ANR.matcher(line); - if (m.matches()) { - mSmartMonkeyLog.addAnrTime(parseTime(m.group(1))); - } - } - - /** - * Parse the timestamp and return a date. - * - * @param timeStr The timestamp in the format {@code yyyy-MM-dd HH:mm:ss.SSS} - * @return The {@link Date}. - */ - public static Date parseTime(String timeStr) { - try { - return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").parse(timeStr); - } catch (ParseException e) { - } - return null; - } - -} |