Move error count BPF map initialization into class Dependencies
The preparation for testing BpfCoordinator#dump(). Used to wrap error count BPF map access to avoid SYS_SECCOMP on some test device. Ex: cuttlefish. https://android-build.googleplex.com/builds/tests/view?invocationId=I01200010101524265&testResultId=TR03228338750686157 Bug: 255466740 Test: atest BpfCoordinatorTest Change-Id: Id4405b70bc6d500b35943b4f81b88e7515fff3b0
This commit is contained in:
@@ -403,6 +403,18 @@ public class BpfCoordinator {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/** Get error BPF map. */
|
||||
@Nullable public IBpfMap<S32, S32> getBpfErrorMap() {
|
||||
if (!isAtLeastS()) return null;
|
||||
try {
|
||||
return new BpfMap<>(TETHER_ERROR_MAP_PATH,
|
||||
BpfMap.BPF_F_RDONLY, S32.class, S32.class);
|
||||
} catch (ErrnoException e) {
|
||||
Log.e(TAG, "Cannot create error map: " + e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
@@ -1287,13 +1299,15 @@ public class BpfCoordinator {
|
||||
}
|
||||
|
||||
private void dumpCounters(@NonNull IndentingPrintWriter pw) {
|
||||
if (!mDeps.isAtLeastS()) {
|
||||
pw.println("No counter support");
|
||||
try (IBpfMap<S32, S32> map = mDeps.getBpfErrorMap()) {
|
||||
if (map == null) {
|
||||
pw.println("No error counter support");
|
||||
return;
|
||||
}
|
||||
if (map.isEmpty()) {
|
||||
pw.println("<empty>");
|
||||
return;
|
||||
}
|
||||
try (IBpfMap<S32, S32> map = new BpfMap<>(TETHER_ERROR_MAP_PATH, BpfMap.BPF_F_RDONLY,
|
||||
S32.class, S32.class)) {
|
||||
|
||||
map.forEach((k, v) -> {
|
||||
String counterName;
|
||||
try {
|
||||
@@ -1307,7 +1321,7 @@ public class BpfCoordinator {
|
||||
if (v.val > 0) pw.println(String.format("%s: %d", counterName, v.val));
|
||||
});
|
||||
} catch (ErrnoException | IOException e) {
|
||||
pw.println("Error dumping counter map: " + e);
|
||||
pw.println("Error dumping error counter map: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -99,6 +99,7 @@ import com.android.net.module.util.BpfMap;
|
||||
import com.android.net.module.util.InterfaceParams;
|
||||
import com.android.net.module.util.NetworkStackConstants;
|
||||
import com.android.net.module.util.SharedLog;
|
||||
import com.android.net.module.util.Struct.S32;
|
||||
import com.android.net.module.util.bpf.Tether4Key;
|
||||
import com.android.net.module.util.bpf.Tether4Value;
|
||||
import com.android.net.module.util.bpf.TetherStatsKey;
|
||||
@@ -197,6 +198,7 @@ public class IpServerTest {
|
||||
@Mock private BpfMap<TetherStatsKey, TetherStatsValue> mBpfStatsMap;
|
||||
@Mock private BpfMap<TetherLimitKey, TetherLimitValue> mBpfLimitMap;
|
||||
@Mock private BpfMap<TetherDevKey, TetherDevValue> mBpfDevMap;
|
||||
@Mock private BpfMap<S32, S32> mBpfErrorMap;
|
||||
|
||||
@Captor private ArgumentCaptor<DhcpServingParamsParcel> mDhcpParamsCaptor;
|
||||
|
||||
@@ -360,6 +362,11 @@ public class IpServerTest {
|
||||
public BpfMap<TetherDevKey, TetherDevValue> getBpfDevMap() {
|
||||
return mBpfDevMap;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public BpfMap<S32, S32> getBpfErrorMap() {
|
||||
return mBpfErrorMap;
|
||||
}
|
||||
};
|
||||
mBpfCoordinator = spy(new BpfCoordinator(mBpfDeps));
|
||||
|
||||
|
||||
@@ -99,6 +99,7 @@ import com.android.net.module.util.IBpfMap;
|
||||
import com.android.net.module.util.InterfaceParams;
|
||||
import com.android.net.module.util.NetworkStackConstants;
|
||||
import com.android.net.module.util.SharedLog;
|
||||
import com.android.net.module.util.Struct.S32;
|
||||
import com.android.net.module.util.bpf.Tether4Key;
|
||||
import com.android.net.module.util.bpf.Tether4Value;
|
||||
import com.android.net.module.util.bpf.TetherStatsKey;
|
||||
@@ -365,6 +366,7 @@ public class BpfCoordinatorTest {
|
||||
@Mock private IBpfMap<TetherDownstream6Key, Tether6Value> mBpfDownstream6Map;
|
||||
@Mock private IBpfMap<TetherUpstream6Key, Tether6Value> mBpfUpstream6Map;
|
||||
@Mock private IBpfMap<TetherDevKey, TetherDevValue> mBpfDevMap;
|
||||
@Mock private IBpfMap<S32, S32> mBpfErrorMap;
|
||||
|
||||
// Late init since methods must be called by the thread that created this object.
|
||||
private TestableNetworkStatsProviderCbBinder mTetherStatsProviderCb;
|
||||
@@ -457,6 +459,11 @@ public class BpfCoordinatorTest {
|
||||
public IBpfMap<TetherDevKey, TetherDevValue> getBpfDevMap() {
|
||||
return mBpfDevMap;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public IBpfMap<S32, S32> getBpfErrorMap() {
|
||||
return mBpfErrorMap;
|
||||
}
|
||||
});
|
||||
|
||||
@Before public void setUp() {
|
||||
|
||||
Reference in New Issue
Block a user