Skip to content
Commit a81f1251 authored by Hungming Chen's avatar Hungming Chen Committed by Nucca Chen
Browse files

BpfMapTest: add fd leak test

Test that there is no fd leak with persistent fd cache.

Bug: 236320567
Test: atest BpfMapTest#testNoFdLeaks (cached fd) [PASSED]
Test: atest BpfMapTest#testNoFdLeaks (noncached fd) [FAILED] (as expected)
[8/14] com.android.networkstack.tethering.BpfMapTest#testNoFdLeaks: FAILED (241ms)

STACKTRACE:
java.lang.AssertionError: Fd leak after 1000 iterations:  expected:<89> but was:<1089>
	at org.junit.Assert.fail(Assert.java:89)
	at org.junit.Assert.failNotEquals(Assert.java:835)
	at org.junit.Assert.assertEquals(Assert.java:647)
	at com.android.networkstack.tethering.BpfMapTest.testNoFdLeaks(BpfMapTest.java:420)

Test Code:
fd noncached BpfMap
frameworks/libs/net/common/device/com/android/net/module/util/BpfMap.java
@@ -97,7 +97,7 @@ public class BpfMap<K extends Struct, V extends Struct> implements IBpfMap<K, V>
      */
     public BpfMap(@NonNull final String path, final int flag, final Class<K> key,
             final Class<V> value) throws ErrnoException, NullPointerException {
-        mMapFd = cachedBpfFdGet(path, flag);
+        mMapFd = ParcelFileDescriptor.adoptFd(nativeBpfFdGet(path, flag));

Change-Id: I66f477fd1c291c56bccc97d385b2a554c2367b5a
parent 944f9e3d
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment