Skip to content

Commit

Permalink
Skip Cronet tests that call GetTaggedBytes() on P+ devices.
Browse files Browse the repository at this point in the history
In Android P, /proc/net/xt_qtaguid/stats is no longer guaranteed to be
present, and has been replaced with eBPF Traffic Monitoring in netd. See:
https://source.android.com/devices/tech/datausage/ebpf-traffic-monitor

To read traffic statistics from netd, apps should use the API
NetworkStatsManager.queryDetailsForUidTag(). But this API does not provide
statistics for local traffic, only mobile and WiFi traffic, so it would not
work in tests that spin up a local server. So for now, GetTaggedBytes is
only supported on Android releases older than P.

Change-Id: Ida2b47624e1ac379799d00a21b8b41915579aece
Reviewed-on: https://chromium-review.googlesource.com/c/1470522
Commit-Queue: Paul Jensen <pauljensen@chromium.org>
Auto-Submit: Paul Jensen <pauljensen@chromium.org>
Reviewed-by: Peter Collingbourne <pcc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#631850}
  • Loading branch information
JensenPaul authored and Commit Bot committed Feb 13, 2019
1 parent 89770ac commit 47f40f9
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 0 deletions.
4 changes: 4 additions & 0 deletions components/cronet/android/test/cronet_test_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ void JNI_CronetTestUtil_CleanupNetworkThread(
jcontext_adapter, base::Bind(&CleanupNetworkThreadOnNetworkThread));
}

jboolean JNI_CronetTestUtil_CanGetTaggedBytes(JNIEnv* env) {
return net::CanGetTaggedBytes();
}

jlong JNI_CronetTestUtil_GetTaggedBytes(JNIEnv* env,
jint jexpected_tag) {
return net::GetTaggedBytes(jexpected_tag);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;

import org.chromium.base.Log;
import org.chromium.base.test.BaseJUnit4ClassRunner;
import org.chromium.base.test.util.DisabledTest;
import org.chromium.base.test.util.Feature;
Expand Down Expand Up @@ -55,6 +56,8 @@
*/
@RunWith(BaseJUnit4ClassRunner.class)
public class BidirectionalStreamTest {
private static final String TAG = BidirectionalStreamTest.class.getSimpleName();

@Rule
public final CronetTestRule mTestRule = new CronetTestRule();

Expand Down Expand Up @@ -1586,6 +1589,10 @@ private static void checkSpecificErrorCode(
@OnlyRunNativeCronet
@RequiresMinApi(10) // Tagging support added in API level 10: crrev.com/c/chromium/src/+/937583
public void testTagging() throws Exception {
if (!CronetTestUtil.nativeCanGetTaggedBytes()) {
Log.i(TAG, "Skipping test - GetTaggedBytes unsupported.");
return;
}
String url = Http2TestServer.getEchoStreamUrl();

// Test untagged requests are given tag 0.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
*/
@RunWith(BaseJUnit4ClassRunner.class)
public class CronetUrlRequestTest {
private static final String TAG = CronetUrlRequestTest.class.getSimpleName();

// URL used for base tests.
private static final String TEST_URL = "http://127.0.0.1:8000";

Expand Down Expand Up @@ -2327,6 +2329,10 @@ public void test404Head() throws Exception {
@Feature({"Cronet"})
@RequiresMinApi(9) // Tagging support added in API level 9: crrev.com/c/chromium/src/+/930086
public void testTagging() throws Exception {
if (!CronetTestUtil.nativeCanGetTaggedBytes()) {
Log.i(TAG, "Skipping test - GetTaggedBytes unsupported.");
return;
}
String url = NativeTestServer.getEchoMethodURL();

// Test untagged requests are given tag 0.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;

import org.chromium.base.Log;
import org.chromium.base.test.BaseJUnit4ClassRunner;
import org.chromium.base.test.util.Feature;
import org.chromium.net.CronetEngine;
Expand Down Expand Up @@ -67,6 +68,8 @@
*/
@RunWith(BaseJUnit4ClassRunner.class)
public class CronetHttpURLConnectionTest {
private static final String TAG = CronetHttpURLConnectionTest.class.getSimpleName();

@Rule
public final CronetTestRule mTestRule = new CronetTestRule();

Expand Down Expand Up @@ -1359,6 +1362,10 @@ private List<String> getRequestHeaderValues(String allHeaders,
@Feature({"Cronet"})
@RequiresMinApi(9) // Tagging support added in API level 9: crrev.com/c/chromium/src/+/930086
public void testTagging() throws Exception {
if (!CronetTestUtil.nativeCanGetTaggedBytes()) {
Log.i(TAG, "Skipping test - GetTaggedBytes unsupported.");
return;
}
URL url = new URL(NativeTestServer.getEchoMethodURL());

// Test untagged requests are given tag 0.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ public static CronetEngineBuilderImpl getCronetEngineBuilderImpl(
return (CronetEngineBuilderImpl) builder.getBuilderDelegate();
}

/**
* Returns whether the device supports calling nativeGetTaggedBytes().
*/
public static native boolean nativeCanGetTaggedBytes();

/**
* Query the system to find out how many bytes were received with tag
* {@code expectedTag} for our UID.
Expand Down

0 comments on commit 47f40f9

Please sign in to comment.