summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorEric Rowe <erowe@google.com>2013-12-10 16:28:36 -0800
committerEric Rowe <erowe@google.com>2013-12-12 11:43:57 -0800
commit874b8efb76e4eeec42454162ad56f9561cad8dbf (patch)
tree6085f4138b4fbbc061415c3bb108da67c0de714e /tests
parentb9a677c06570dbfdf0adf984c21f5a3da4abb954 (diff)
downloadloganalysis-874b8efb76e4eeec42454162ad56f9561cad8dbf.tar.gz
Add last charged wake locks
Bug: 12083761 Change-Id: I658253eaf8dd1cff52dd3f54ee2431b0b7f1c708
Diffstat (limited to 'tests')
-rw-r--r--tests/src/com/android/loganalysis/item/DumpsysBatteryInfoItemTest.java54
-rw-r--r--tests/src/com/android/loganalysis/parser/DumpsysBatteryInfoParserTest.java39
-rw-r--r--tests/src/com/android/loganalysis/parser/DumpsysParserTest.java9
3 files changed, 55 insertions, 47 deletions
diff --git a/tests/src/com/android/loganalysis/item/DumpsysBatteryInfoItemTest.java b/tests/src/com/android/loganalysis/item/DumpsysBatteryInfoItemTest.java
index e2c1d20..bb48da7 100644
--- a/tests/src/com/android/loganalysis/item/DumpsysBatteryInfoItemTest.java
+++ b/tests/src/com/android/loganalysis/item/DumpsysBatteryInfoItemTest.java
@@ -15,6 +15,8 @@
*/
package com.android.loganalysis.item;
+import com.android.loganalysis.item.DumpsysBatteryInfoItem.WakeLockCategory;
+
import junit.framework.TestCase;
import org.json.JSONArray;
@@ -25,46 +27,42 @@ import org.json.JSONObject;
* Unit test for {@link DumpsysBatteryInfoItem}.
*/
public class DumpsysBatteryInfoItemTest extends TestCase {
+ private static final String WAKELOCKS = "WAKELOCKS";
+ private static final String LAST_CHARGE_KERNEL_WAKELOCKS = "LAST_CHARGE_KERNEL_WAKELOCKS";
+ private static final String LAST_UNPLUGGED_WAKELOCKS = "LAST_UNPLUGGED_WAKELOCKS";
+ private static final String LAST_UNPLUGGED_KERNEL_WAKELOCKS = "LAST_UNPLUGGED_KERNEL_WAKELOCKS";
/**
* Test that {@link DumpsysBatteryInfoItem#toJson()} returns correctly.
*/
public void testToJson() throws JSONException {
DumpsysBatteryInfoItem item = new DumpsysBatteryInfoItem();
- item.addLastUnpluggedKernelWakeLock("a", 0, 1);
- item.addLastUnpluggedKernelWakeLock("b", 2, 3);
- item.addLastUnpluggedWakeLock("x", 4, 5, 6);
- item.addLastUnpluggedWakeLock("y", 7, 8, 9);
- item.addLastUnpluggedWakeLock("z", 10, 11, 12);
+ item.addWakeLock("a", 0, 1, WakeLockCategory.LAST_UNPLUGGED_KERNEL_WAKELOCK);
+ item.addWakeLock("b", 2, 3, WakeLockCategory.LAST_UNPLUGGED_KERNEL_WAKELOCK);
+ item.addWakeLock("c", 4, 5, 6, WakeLockCategory.LAST_UNPLUGGED_WAKELOCK);
+ item.addWakeLock("d", 7, 8, 9, WakeLockCategory.LAST_UNPLUGGED_WAKELOCK);
+ item.addWakeLock("e", 10, 11, 12, WakeLockCategory.LAST_UNPLUGGED_WAKELOCK);
+ item.addWakeLock("w", 0, 1, WakeLockCategory.LAST_CHARGE_KERNEL_WAKELOCK);
+ item.addWakeLock("v", 2, 3, WakeLockCategory.LAST_CHARGE_KERNEL_WAKELOCK);
+ item.addWakeLock("x", 4, 5, 6, WakeLockCategory.LAST_CHARGE_WAKELOCK);
+ item.addWakeLock("y", 7, 8, 9, WakeLockCategory.LAST_CHARGE_WAKELOCK);
+ item.addWakeLock("z", 10, 11, 12, WakeLockCategory.LAST_CHARGE_WAKELOCK);
// Convert to JSON string and back again
JSONObject output = new JSONObject(item.toJson().toString());
- assertTrue(output.has(DumpsysBatteryInfoItem.KERNEL_WAKELOCKS));
- assertTrue(output.get(DumpsysBatteryInfoItem.KERNEL_WAKELOCKS) instanceof JSONArray);
- assertTrue(output.has(DumpsysBatteryInfoItem.WAKELOCKS));
- assertTrue(output.get(DumpsysBatteryInfoItem.WAKELOCKS) instanceof JSONArray);
-
- JSONArray kernelWakeLocks = output.getJSONArray(DumpsysBatteryInfoItem.KERNEL_WAKELOCKS);
-
- assertEquals(2, kernelWakeLocks.length());
- assertTrue(kernelWakeLocks.get(0) instanceof JSONObject);
+ assertTrue(output.has(WAKELOCKS));
+ assertTrue(output.get(WAKELOCKS) instanceof JSONArray);
- JSONObject kernelWakeLock = kernelWakeLocks.getJSONObject(0);
-
- assertEquals("a", kernelWakeLock.get(DumpsysBatteryInfoItem.WakeLock.NAME));
- assertFalse(kernelWakeLock.has(DumpsysBatteryInfoItem.WakeLock.NUMBER));
- assertEquals(0, kernelWakeLock.get(DumpsysBatteryInfoItem.WakeLock.HELD_TIME));
- assertEquals(1, kernelWakeLock.get(DumpsysBatteryInfoItem.WakeLock.LOCKED_COUNT));
-
- JSONArray wakeLocks = output.getJSONArray(DumpsysBatteryInfoItem.WAKELOCKS);
- assertEquals(3, wakeLocks.length());
+ JSONArray wakeLocks = output.getJSONArray(WAKELOCKS);
+ assertEquals(10, wakeLocks.length());
assertTrue(wakeLocks.get(0) instanceof JSONObject);
JSONObject wakeLock = wakeLocks.getJSONObject(0);
-
- assertEquals("x", wakeLock.get(DumpsysBatteryInfoItem.WakeLock.NAME));
- assertEquals(4, wakeLock.get(DumpsysBatteryInfoItem.WakeLock.NUMBER));
- assertEquals(5, wakeLock.get(DumpsysBatteryInfoItem.WakeLock.HELD_TIME));
- assertEquals(6, wakeLock.get(DumpsysBatteryInfoItem.WakeLock.LOCKED_COUNT));
+ assertEquals("a", wakeLock.get(DumpsysBatteryInfoItem.WakeLock.NAME));
+ assertFalse(wakeLock.has(DumpsysBatteryInfoItem.WakeLock.NUMBER));
+ assertEquals(0, wakeLock.get(DumpsysBatteryInfoItem.WakeLock.HELD_TIME));
+ assertEquals(1, wakeLock.get(DumpsysBatteryInfoItem.WakeLock.LOCKED_COUNT));
+ assertEquals(WakeLockCategory.LAST_UNPLUGGED_KERNEL_WAKELOCK.toString(),
+ wakeLock.get(DumpsysBatteryInfoItem.WakeLock.CATEGORY));
}
}
diff --git a/tests/src/com/android/loganalysis/parser/DumpsysBatteryInfoParserTest.java b/tests/src/com/android/loganalysis/parser/DumpsysBatteryInfoParserTest.java
index 55af599..66c7796 100644
--- a/tests/src/com/android/loganalysis/parser/DumpsysBatteryInfoParserTest.java
+++ b/tests/src/com/android/loganalysis/parser/DumpsysBatteryInfoParserTest.java
@@ -17,6 +17,7 @@ package com.android.loganalysis.parser;
import com.android.loganalysis.item.DumpsysBatteryInfoItem;
import com.android.loganalysis.item.DumpsysBatteryInfoItem.WakeLock;
+import com.android.loganalysis.item.DumpsysBatteryInfoItem.WakeLockCategory;
import junit.framework.TestCase;
@@ -96,13 +97,19 @@ public class DumpsysBatteryInfoParserTest extends TestCase {
DumpsysBatteryInfoParser parser = new DumpsysBatteryInfoParser();
DumpsysBatteryInfoItem item = parser.parse(inputBlock);
- assertEquals(5, item.getLastUnpluggedWakeLocks().size());
- assertEquals(3, item.getLastUnpluggedKernelWakeLocks().size());
+ assertEquals(2, item.getWakeLocks(WakeLockCategory.LAST_CHARGE_WAKELOCK).size());
+ assertEquals(2, item.getWakeLocks(WakeLockCategory.LAST_CHARGE_KERNEL_WAKELOCK).size());
+ assertEquals(5, item.getWakeLocks(WakeLockCategory.LAST_UNPLUGGED_WAKELOCK).size());
+ assertEquals(3, item.getWakeLocks(WakeLockCategory.LAST_UNPLUGGED_KERNEL_WAKELOCK).size());
assertEquals("partialWakelock",
- item.getLastUnpluggedWakeLocks().get(0).getName());
+ item.getWakeLocks(WakeLockCategory.LAST_CHARGE_WAKELOCK).get(0).getName());
assertEquals("PowerManagerService.WakeLocks",
- item.getLastUnpluggedKernelWakeLocks().get(0).getName());
+ item.getWakeLocks(WakeLockCategory.LAST_CHARGE_KERNEL_WAKELOCK).get(0).getName());
+ assertEquals("partialWakelock",
+ item.getWakeLocks(WakeLockCategory.LAST_UNPLUGGED_WAKELOCK).get(0).getName());
+ assertEquals("PowerManagerService.WakeLocks",
+ item.getWakeLocks(WakeLockCategory.LAST_UNPLUGGED_KERNEL_WAKELOCK).get(0).getName());
}
/**
@@ -112,11 +119,11 @@ public class DumpsysBatteryInfoParserTest extends TestCase {
String inputLine = " Kernel Wake lock \"Process\": 1d 2h 3m 4s 5ms (6 times) realtime";
DumpsysBatteryInfoParser parser = new DumpsysBatteryInfoParser();
- parser.parseLastUnpluggedKernelWakeLock(inputLine);
+ parser.parseKernelWakeLock(inputLine, WakeLockCategory.LAST_CHARGE_KERNEL_WAKELOCK);
DumpsysBatteryInfoItem item = parser.getItem();
- assertEquals(1, item.getLastUnpluggedKernelWakeLocks().size());
- WakeLock wakeLock = item.getLastUnpluggedKernelWakeLocks().get(0);
+ assertEquals(1, item.getWakeLocks(WakeLockCategory.LAST_CHARGE_KERNEL_WAKELOCK).size());
+ WakeLock wakeLock = item.getWakeLocks(WakeLockCategory.LAST_CHARGE_KERNEL_WAKELOCK).get(0);
assertEquals("Process", wakeLock.getName());
assertNull(wakeLock.getNumber());
assertEquals(DumpsysBatteryInfoParser.getMs(1, 2, 3, 4, 5), wakeLock.getHeldTime());
@@ -125,11 +132,11 @@ public class DumpsysBatteryInfoParserTest extends TestCase {
inputLine = " Kernel Wake lock \"Process\": 5m 7ms (2 times) realtime";
parser = new DumpsysBatteryInfoParser();
- parser.parseLastUnpluggedKernelWakeLock(inputLine);
+ parser.parseKernelWakeLock(inputLine, WakeLockCategory.LAST_CHARGE_KERNEL_WAKELOCK);
item = parser.getItem();
- assertEquals(1, item.getLastUnpluggedKernelWakeLocks().size());
- wakeLock = item.getLastUnpluggedKernelWakeLocks().get(0);
+ assertEquals(1, item.getWakeLocks(WakeLockCategory.LAST_CHARGE_KERNEL_WAKELOCK).size());
+ wakeLock = item.getWakeLocks(WakeLockCategory.LAST_CHARGE_KERNEL_WAKELOCK).get(0);
assertEquals("Process", wakeLock.getName());
assertNull(wakeLock.getNumber());
assertEquals(5 * 60 * 1000 + 7, wakeLock.getHeldTime());
@@ -143,11 +150,11 @@ public class DumpsysBatteryInfoParserTest extends TestCase {
String inputLine = " Wake lock #1234 Process: 1d 2h 3m 4s 5ms (6 times) realtime";
DumpsysBatteryInfoParser parser = new DumpsysBatteryInfoParser();
- parser.parseLastUnpluggedWakeLock(inputLine);
+ parser.parseWakeLock(inputLine, WakeLockCategory.LAST_CHARGE_WAKELOCK);
DumpsysBatteryInfoItem item = parser.getItem();
- assertEquals(1, item.getLastUnpluggedWakeLocks().size());
- WakeLock wakeLock = item.getLastUnpluggedWakeLocks().get(0);
+ assertEquals(1, item.getWakeLocks(WakeLockCategory.LAST_CHARGE_WAKELOCK).size());
+ WakeLock wakeLock = item.getWakeLocks(WakeLockCategory.LAST_CHARGE_WAKELOCK).get(0);
assertEquals("Process", wakeLock.getName());
assertEquals((Integer) 1234, wakeLock.getNumber());
assertEquals(DumpsysBatteryInfoParser.getMs(1, 2, 3, 4, 5), wakeLock.getHeldTime());
@@ -156,11 +163,11 @@ public class DumpsysBatteryInfoParserTest extends TestCase {
inputLine = " Wake lock #1234 Process:with:colons: 5m 7ms (2 times) realtime";
parser = new DumpsysBatteryInfoParser();
- parser.parseLastUnpluggedWakeLock(inputLine);
+ parser.parseWakeLock(inputLine, WakeLockCategory.LAST_CHARGE_WAKELOCK);
item = parser.getItem();
- assertEquals(1, item.getLastUnpluggedWakeLocks().size());
- wakeLock = item.getLastUnpluggedWakeLocks().get(0);
+ assertEquals(1, item.getWakeLocks(WakeLockCategory.LAST_CHARGE_WAKELOCK).size());
+ wakeLock = item.getWakeLocks(WakeLockCategory.LAST_CHARGE_WAKELOCK).get(0);
assertEquals("Process:with:colons", wakeLock.getName());
assertEquals((Integer) 1234, wakeLock.getNumber());
assertEquals(5 * 60 * 1000 + 7, wakeLock.getHeldTime());
diff --git a/tests/src/com/android/loganalysis/parser/DumpsysParserTest.java b/tests/src/com/android/loganalysis/parser/DumpsysParserTest.java
index df0d95e..423ec06 100644
--- a/tests/src/com/android/loganalysis/parser/DumpsysParserTest.java
+++ b/tests/src/com/android/loganalysis/parser/DumpsysParserTest.java
@@ -15,6 +15,7 @@
*/
package com.android.loganalysis.parser;
+import com.android.loganalysis.item.DumpsysBatteryInfoItem.WakeLockCategory;
import com.android.loganalysis.item.DumpsysItem;
import junit.framework.TestCase;
@@ -36,7 +37,7 @@ public class DumpsysParserTest extends TestCase {
"DUMP OF SERVICE process1:",
"-------------------------------------------------------------------------------",
"DUMP OF SERVICE batteryinfo:",
- "Statistics since last unplugged:",
+ "Statistics since last charge:",
" Kernel Wake lock \"PowerManagerService.WakeLocks\": 5m 10s 61ms (2 times) realtime",
" Kernel Wake lock \"pm8921_eoc\": 9s 660ms (0 times) realtime",
"",
@@ -51,8 +52,10 @@ public class DumpsysParserTest extends TestCase {
DumpsysItem item = new DumpsysParser().parse(inputBlock);
assertNotNull(item.getBatteryInfo());
- assertEquals(2, item.getBatteryInfo().getLastUnpluggedWakeLocks().size());
- assertEquals(2, item.getBatteryInfo().getLastUnpluggedKernelWakeLocks().size());
+ assertEquals(2, item.getBatteryInfo().getWakeLocks(
+ WakeLockCategory.LAST_CHARGE_WAKELOCK).size());
+ assertEquals(2, item.getBatteryInfo().getWakeLocks(
+ WakeLockCategory.LAST_CHARGE_KERNEL_WAKELOCK).size());
}
/**