Move Interface index name map dump to NetworkStatsService
Map status dump will do access check if map is null.
This could show different message from the current dump output.
Information in map content dump does not change
$ dumpsys connectivity trafficcontroller
....
mIfaceIndexNameMap:
ifaceIndex=5 ifaceName=ip6_vti0
ifaceIndex=19 ifaceName=r_rmnet_data3
ifaceIndex=17 ifaceName=r_rmnet_data1
ifaceIndex=18 ifaceName=r_rmnet_data2
ifaceIndex=23 ifaceName=wifi-aware0
....
$ dumpsys netstats
....
BPF map content:
ifaceIndex=5 ifaceName=ip6_vti0
ifaceIndex=19 ifaceName=r_rmnet_data3
ifaceIndex=17 ifaceName=r_rmnet_data1
ifaceIndex=18 ifaceName=r_rmnet_data2
ifaceIndex=8 ifaceName=rmnet_ipa0
....
Bug: 217624062
Test: dumpsys netstats, atest
com.android.server.net.BpfInterfaceMapUpdaterTest
Change-Id: If182bd97f72713b6347028668cf7bd4676b8aea4
This commit is contained in:
@@ -20,6 +20,7 @@ import static android.system.OsConstants.EPERM;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.spy;
|
||||
@@ -34,6 +35,7 @@ import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.os.test.TestLooper;
|
||||
import android.system.ErrnoException;
|
||||
import android.util.IndentingPrintWriter;
|
||||
|
||||
import androidx.test.filters.SmallTest;
|
||||
|
||||
@@ -52,6 +54,9 @@ import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
|
||||
@SmallTest
|
||||
@RunWith(DevSdkIgnoreRunner.class)
|
||||
@DevSdkIgnoreRule.IgnoreUpTo(Build.VERSION_CODES.S_V2)
|
||||
@@ -144,4 +149,26 @@ public final class BpfInterfaceMapUpdaterTest {
|
||||
doThrow(new ErrnoException("", EPERM)).when(mBpfMap).getValue(new U32(TEST_INDEX));
|
||||
assertNull(mUpdater.getIfNameByIndex(TEST_INDEX));
|
||||
}
|
||||
|
||||
private void assertDumpContains(final String dump, final String message) {
|
||||
assertTrue(String.format("dump(%s) does not contain '%s'", dump, message),
|
||||
dump.contains(message));
|
||||
}
|
||||
|
||||
private String getDump() {
|
||||
final StringWriter sw = new StringWriter();
|
||||
mUpdater.dump(new IndentingPrintWriter(new PrintWriter(sw), " "));
|
||||
return sw.toString();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDump() throws ErrnoException {
|
||||
mBpfMap.updateEntry(new U32(TEST_INDEX), new InterfaceMapValue(TEST_INTERFACE_NAME));
|
||||
mBpfMap.updateEntry(new U32(TEST_INDEX2), new InterfaceMapValue(TEST_INTERFACE_NAME2));
|
||||
|
||||
final String dump = getDump();
|
||||
assertDumpContains(dump, "IfaceIndexNameMap: OK");
|
||||
assertDumpContains(dump, "ifaceIndex=1 ifaceName=test1");
|
||||
assertDumpContains(dump, "ifaceIndex=2 ifaceName=test2");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user