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.CpuInfoItem; 19 20 import junit.framework.TestCase; 21 22 import java.util.Arrays; 23 import java.util.List; 24 25 public class CpuInfoParserTest extends TestCase { 26 testSingleLine()27 public void testSingleLine() { 28 List<String> input = Arrays.asList(" 0.1% 170/surfaceflinger: 0% user + 0% kernel"); 29 30 CpuInfoItem item = new CpuInfoParser().parse(input); 31 32 assertEquals(1, item.getPids().size()); 33 assertEquals("surfaceflinger", item.getName(170)); 34 assertEquals(0.1, item.getPercent(170), 0.0001); 35 } 36 testMultipleLines()37 public void testMultipleLines() { 38 List<String> input = Arrays.asList( 39 "CPU usage from 35935ms to 26370ms ago:", 40 " 57% 489/system_server: 37% user + 20% kernel / faults: 39754 minor 57 major", 41 " 34% 853/com.google.android.leanbacklauncher: 30% user + 4.6% kernel / faults: 7838 minor 14 major", 42 " 15% 19463/com.google.android.videos: 11% user + 3.3% kernel / faults: 21603 minor 141 major", 43 " 8.2% 170/surfaceflinger: 3.4% user + 4.8% kernel / faults: 1 minor"); 44 CpuInfoItem item = new CpuInfoParser().parse(input); 45 46 assertEquals(4, item.getPids().size()); 47 assertEquals("system_server", item.getName(489)); 48 assertEquals(57.0, item.getPercent(489), 0.0001); 49 assertEquals("surfaceflinger", item.getName(170)); 50 assertEquals(8.2, item.getPercent(170), 0.0001); 51 } 52 53 } 54 55