Move Interface stats map dump to NetworkStatsService

Bug: 217624062
Test: dumpsys netstats, atest NetworkStatsServiceTest
Change-Id: Ie0357a79925c0bbb34aa05442f727c776f434f88
This commit is contained in:
Motomu Utsumi
2022-08-16 08:50:46 +00:00
parent 388787b8fd
commit 809a316035
4 changed files with 61 additions and 22 deletions

View File

@@ -263,7 +263,8 @@ public class NetworkStatsServiceTest extends NetworkStatsBaseTest {
StatsMapValue.class);
private TestBpfMap<UidStatsMapKey, StatsMapValue> mAppUidStatsMap = new TestBpfMap<>(
UidStatsMapKey.class, StatsMapValue.class);
private TestBpfMap<S32, StatsMapValue> mIfaceStatsMap = new TestBpfMap<>(
S32.class, StatsMapValue.class);
private NetworkStatsService mService;
private INetworkStatsSession mSession;
private AlertObserver mAlertObserver;
@@ -502,6 +503,11 @@ public class NetworkStatsServiceTest extends NetworkStatsBaseTest {
return mAppUidStatsMap;
}
@Override
public IBpfMap<S32, StatsMapValue> getIfaceStatsMap() {
return mIfaceStatsMap;
}
@Override
public boolean isDebuggable() {
return mIsDebuggable == Boolean.TRUE;
@@ -2552,4 +2558,25 @@ public class NetworkStatsServiceTest extends NetworkStatsBaseTest {
doReturn(null).when(mBpfInterfaceMapUpdater).getIfNameByIndex(10 /* index */);
doTestDumpStatsMap("unknown");
}
void doTestDumpIfaceStatsMap(final String expectedIfaceName) throws Exception {
mIfaceStatsMap.insertEntry(new S32(10), new StatsMapValue(3, 3000, 3, 3000));
final String dump = getDump();
assertDumpContains(dump, "mIfaceStatsMap: OK");
assertDumpContains(dump, "ifaceIndex ifaceName rxBytes rxPackets txBytes txPackets");
assertDumpContains(dump, "10 " + expectedIfaceName + " 3000 3 3000 3");
}
@Test
public void testDumpIfaceStatsMap() throws Exception {
doReturn("wlan0").when(mBpfInterfaceMapUpdater).getIfNameByIndex(10 /* index */);
doTestDumpIfaceStatsMap("wlan0");
}
@Test
public void testDumpIfaceStatsMapUnknownInterface() throws Exception {
doReturn(null).when(mBpfInterfaceMapUpdater).getIfNameByIndex(10 /* index */);
doTestDumpIfaceStatsMap("unknown");
}
}