1 /* 2 * Copyright (C) 2015 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.ProcessUsageItem; 19 import com.android.loganalysis.item.ProcessUsageItem.ProcessUsageInfoItem; 20 import com.android.loganalysis.item.ProcessUsageItem.SensorInfoItem; 21 22 import junit.framework.TestCase; 23 24 import java.util.Arrays; 25 import java.util.LinkedList; 26 import java.util.List; 27 28 /** 29 * Unit tests for {@link ProcessUsageParser} 30 */ 31 public class ProcessUsageParserTest extends TestCase { 32 33 /** 34 * Test that normal input is parsed. 35 */ testProcessUsageParser()36 public void testProcessUsageParser() { 37 List<String> inputBlock = Arrays.asList( 38 " 0:", 39 " Mobile network: 173.70KB received, 102.55KB sent (packets 129)", 40 " Mobile radio active: 6m 5s 80ms (14.9%) 80x @ 139 mspp", 41 " 1000:", 42 " Mobile network: 16.43KB received, 26.26KB sent", 43 " Mobile radio active: 1m 17s 489ms (3.2%) 61x @ 179 mspp", 44 " Sensor 44: 27m 18s 207ms realtime (22 times)", 45 " Sensor 36: 6s 483ms realtime (3 times)", 46 " Proc servicemanager:", 47 " CPU: 2s 20ms usr + 4s 60ms krn ; 0ms fg", 48 " Apk android:", 49 " 266 wakeup alarms", 50 " u0a2:", 51 " Mobile network: 16.43KB received, 26.26KB sent", 52 " Mobile radio active: 1m 17s 489ms (3.2%) 61x @ 179 mspp", 53 " Sensor 0: 5s 207ms realtime (2 times)", 54 " Proc servicemanager:", 55 " CPU: 2s 20ms usr + 4s 60ms krn ; 0ms fg", 56 " Apk android:", 57 " 2 wakeup alarms", 58 " "); 59 60 ProcessUsageItem processUsage = new ProcessUsageParser().parse(inputBlock); 61 62 assertEquals(3, processUsage.getProcessUsage().size()); 63 64 LinkedList<ProcessUsageInfoItem> processUsageInfo = 65 (LinkedList<ProcessUsageInfoItem>)processUsage.getProcessUsage(); 66 67 assertEquals("1000", processUsageInfo.get(1).getProcessUID()); 68 assertEquals(266, processUsageInfo.get(1).getAlarmWakeups()); 69 70 LinkedList<SensorInfoItem> sensor = processUsageInfo.get(1).getSensorUsage(); 71 assertEquals("44", sensor.get(0).getSensorName()); 72 assertEquals("36", sensor.get(1).getSensorName()); 73 74 sensor = processUsageInfo.get(2).getSensorUsage(); 75 assertEquals("0", sensor.get(0).getSensorName()); 76 } 77 } 78 79