1 /* 2 * Copyright (C) 2012 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.loganalysis.parser; 17 18 import com.android.loganalysis.item.NativeCrashItem; 19 import com.android.loganalysis.util.ArrayUtil; 20 21 import junit.framework.TestCase; 22 23 import java.util.Arrays; 24 import java.util.List; 25 26 /** 27 * Unit tests for {@link NativeCrashParser}. 28 */ 29 public class NativeCrashParserTest extends TestCase { 30 31 /** 32 * Test that native crashes are parsed. 33 */ testParseage()34 public void testParseage() { 35 List<String> lines = Arrays.asList( 36 "Build fingerprint: 'google/soju/crespo:4.0.4/IMM76D/299849:userdebug/test-keys'", 37 "pid: 2058, tid: 2523 >>> com.google.android.browser <<<", 38 "signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 00000000", 39 " r0 00000000 r1 007d9064 r2 007d9063 r3 00000004", 40 " r4 006bf518 r5 0091e3b0 r6 00000000 r7 9e3779b9", 41 " r8 000006c1 r9 000006c3 10 00000000 fp 67d246c1", 42 " ip d2363b58 sp 50ed71d8 lr 4edfc89b pc 4edfc6a0 cpsr 20000030", 43 " d0 00640065005f0065 d1 0072006f00740069", 44 " d2 00730075006e006b d3 0066006900670000", 45 " d4 00e6d48800e6d3b8 d5 02d517a000e6d518", 46 " d6 0000270f02d51860 d7 0000000002d51a80", 47 " d8 41d3dc5261e7893b d9 3fa999999999999a", 48 " d10 0000000000000000 d11 0000000000000000", 49 " d12 0000000000000000 d13 0000000000000000", 50 " d14 0000000000000000 d15 0000000000000000", 51 " d16 4070000000000000 d17 40c3878000000000", 52 " d18 412310f000000000 d19 3f91800dedacf040", 53 " d20 0000000000000000 d21 0000000000000000", 54 " d22 4010000000000000 d23 0000000000000000", 55 " d24 3ff0000000000000 d25 0000000000000000", 56 " d26 0000000000000000 d27 8000000000000000", 57 " d28 0000000000000000 d29 3ff0000000000000", 58 " d30 0000000000000000 d31 3ff0000000000000", 59 " scr 20000013", 60 "", 61 " #00 pc 001236a0 /system/lib/libwebcore.so", 62 " #01 pc 00123896 /system/lib/libwebcore.so", 63 " #02 pc 00123932 /system/lib/libwebcore.so", 64 " #03 pc 00123e3a /system/lib/libwebcore.so", 65 " #04 pc 00123e84 /system/lib/libwebcore.so", 66 " #05 pc 003db92a /system/lib/libwebcore.so", 67 " #06 pc 003dd01c /system/lib/libwebcore.so", 68 " #07 pc 002ffb92 /system/lib/libwebcore.so", 69 " #08 pc 0031c120 /system/lib/libwebcore.so", 70 " #09 pc 0031c134 /system/lib/libwebcore.so", 71 " #10 pc 0013fb98 /system/lib/libwebcore.so", 72 " #11 pc 0015b026 /system/lib/libwebcore.so", 73 " #12 pc 0015b164 /system/lib/libwebcore.so", 74 " #13 pc 0015f4cc /system/lib/libwebcore.so", 75 " #14 pc 00170472 /system/lib/libwebcore.so", 76 " #15 pc 0016ecb6 /system/lib/libwebcore.so", 77 " #16 pc 0027120e /system/lib/libwebcore.so", 78 " #17 pc 0026efec /system/lib/libwebcore.so", 79 " #18 pc 0026fcd8 /system/lib/libwebcore.so", 80 " #19 pc 00122efa /system/lib/libwebcore.so", 81 "", 82 "code around pc:", 83 "4edfc680 4a14b5f7 0601f001 23000849 3004f88d ...J....I..#...0", 84 "4edfc690 460a9200 3006f8ad e00e4603 3a019f00 ...F...0.F.....:", 85 "4edfc6a0 5c04f833 f83319ed 042c7c02 2cc7ea84 3..\\..3..|,....,", 86 "4edfc6b0 0405ea8c 24d4eb04 33049400 d1ed2a00 .......$...3.*..", 87 "4edfc6c0 f830b126 46681021 ff72f7ff f7ff4668 &.0.!.hF..r.hF..", 88 "", 89 "code around lr:", 90 "4edfc878 f9caf7ff 60209e03 9605e037 5b04f856 ...... `7...V..[", 91 "4edfc888 d0302d00 d13b1c6b 68a8e02d f7ff6869 .-0.k.;.-..hih..", 92 "4edfc898 6128fef3 b010f8d5 99022500 ea0146aa ..(a.....%...F..", 93 "4edfc8a8 9b01080b 0788eb03 3028f853 b9bdb90b ........S.(0....", 94 "4edfc8b8 3301e015 4638d005 f7ff9905 b970ff15 ...3..8F......p.", 95 "", 96 "stack:", 97 " 50ed7198 01d02c08 [heap]", 98 " 50ed719c 40045881 /system/lib/libc.so", 99 " 50ed71a0 400784c8", 100 " 50ed71a4 400784c8", 101 " 50ed71a8 02b40c68 [heap]", 102 " 50ed71ac 02b40c90 [heap]", 103 " 50ed71b0 50ed7290", 104 " 50ed71b4 006bf518 [heap]", 105 " 50ed71b8 00010000", 106 " 50ed71bc 50ed72a4", 107 " 50ed71c0 7da5a695", 108 " 50ed71c4 50ed7290", 109 " 50ed71c8 00000000", 110 " 50ed71cc 00000008", 111 " 50ed71d0 df0027ad", 112 " 50ed71d4 00000000", 113 "#00 50ed71d8 9e3779b9", 114 " 50ed71dc 00002000", 115 " 50ed71e0 00004000", 116 " 50ed71e4 006bf518 [heap]", 117 " 50ed71e8 0091e3b0 [heap]", 118 " 50ed71ec 01d72588 [heap]", 119 " 50ed71f0 00000000", 120 " 50ed71f4 4edfc89b /system/lib/libwebcore.so", 121 "#01 50ed71f8 01d70a78 [heap]", 122 " 50ed71fc 02b6afa8 [heap]", 123 " 50ed7200 00003fff", 124 " 50ed7204 01d70a78 [heap]", 125 " 50ed7208 00004000", 126 " 50ed720c 01d72584 [heap]", 127 " 50ed7210 00000000", 128 " 50ed7214 00000006", 129 " 50ed7218 006bf518 [heap]", 130 " 50ed721c 50ed72a4", 131 " 50ed7220 7da5a695", 132 " 50ed7224 50ed7290", 133 " 50ed7228 000016b8", 134 " 50ed722c 00000008", 135 " 50ed7230 01d70a78 [heap]", 136 " 50ed7234 4edfc937 /system/lib/libwebcore.so", 137 "debuggerd committing suicide to free the zombie!", 138 "debuggerd"); 139 140 NativeCrashItem nc = new NativeCrashParser().parse(lines); 141 assertNotNull(nc); 142 assertEquals(2058, nc.getPid().intValue()); 143 assertEquals(2523, nc.getTid().intValue()); 144 assertEquals("com.google.android.browser", nc.getApp()); 145 assertEquals("google/soju/crespo:4.0.4/IMM76D/299849:userdebug/test-keys", 146 nc.getFingerprint()); 147 assertEquals(ArrayUtil.join("\n", lines), nc.getStack()); 148 } 149 150 /** 151 * Test that both types of native crash app lines are parsed. 152 */ testParseApp()153 public void testParseApp() { 154 List<String> lines = Arrays.asList( 155 "*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***", 156 "Build fingerprint: 'google/soju/crespo:4.0.4/IMM76D/299849:userdebug/test-keys'", 157 "pid: 2058, tid: 2523 >>> com.google.android.browser <<<", 158 "signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 00000000"); 159 160 NativeCrashItem nc = new NativeCrashParser().parse(lines); 161 assertNotNull(nc); 162 assertEquals(2058, nc.getPid().intValue()); 163 assertEquals(2523, nc.getTid().intValue()); 164 assertEquals("com.google.android.browser", nc.getApp()); 165 166 lines = Arrays.asList( 167 "*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***", 168 "Build fingerprint: 'google/soju/crespo:4.0.4/IMM76D/299849:userdebug/test-keys'", 169 "pid: 2058, tid: 2523, name: com.google.android.browser >>> com.google.android.browser <<<", 170 "signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 00000000"); 171 172 nc = new NativeCrashParser().parse(lines); 173 assertNotNull(nc); 174 175 assertEquals(2058, nc.getPid().intValue()); 176 assertEquals(2523, nc.getTid().intValue()); 177 assertEquals("com.google.android.browser", nc.getApp()); 178 179 lines = Arrays.asList( 180 "*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***", 181 "Build fingerprint: 'google/soju/crespo:4.0.4/IMM76D/299849:userdebug/test-keys'", 182 "pid: 2058, tid: 2523, name: Atlas Worker #1 >>> com.google.android.browser <<<", 183 "signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 00000000"); 184 185 nc = new NativeCrashParser().parse(lines); 186 assertNotNull(nc); 187 188 assertEquals(2058, nc.getPid().intValue()); 189 assertEquals(2523, nc.getTid().intValue()); 190 assertEquals("com.google.android.browser", nc.getApp()); 191 } 192 } 193