Merge "Fix test initialization errors on Q" into rvc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
203e783ccd
@@ -16,6 +16,7 @@ cc_library_shared {
|
||||
name: "libnativedns_jni",
|
||||
|
||||
srcs: ["NativeDnsJni.c"],
|
||||
sdk_version: "current",
|
||||
|
||||
shared_libs: [
|
||||
"libnativehelper_compat_libc++",
|
||||
@@ -35,6 +36,7 @@ cc_library_shared {
|
||||
name: "libnativemultinetwork_jni",
|
||||
|
||||
srcs: ["NativeMultinetworkJni.cpp"],
|
||||
sdk_version: "current",
|
||||
cflags: [
|
||||
"-Wall",
|
||||
"-Werror",
|
||||
|
||||
@@ -19,7 +19,12 @@
|
||||
#include <netdb.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <utils/Log.h>
|
||||
|
||||
#include <android/log.h>
|
||||
|
||||
#define LOG_TAG "NativeDns-JNI"
|
||||
#define LOGD(fmt, ...) \
|
||||
__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, fmt, ##__VA_ARGS__)
|
||||
|
||||
const char *GoogleDNSIpV4Address="8.8.8.8";
|
||||
const char *GoogleDNSIpV4Address2="8.8.4.4";
|
||||
@@ -33,7 +38,7 @@ JNIEXPORT jboolean Java_android_net_cts_DnsTest_testNativeDns(JNIEnv* env, jclas
|
||||
struct addrinfo *answer;
|
||||
|
||||
int res = getaddrinfo(node, service, NULL, &answer);
|
||||
ALOGD("getaddrinfo(www.google.com) gave res=%d (%s)", res, gai_strerror(res));
|
||||
LOGD("getaddrinfo(www.google.com) gave res=%d (%s)", res, gai_strerror(res));
|
||||
if (res != 0) return JNI_FALSE;
|
||||
|
||||
// check for v4 & v6
|
||||
@@ -47,12 +52,12 @@ JNIEXPORT jboolean Java_android_net_cts_DnsTest_testNativeDns(JNIEnv* env, jclas
|
||||
inet_ntop(current->ai_family, &((struct sockaddr_in *)current->ai_addr)->sin_addr,
|
||||
buf, sizeof(buf));
|
||||
foundv4 = 1;
|
||||
ALOGD(" %s", buf);
|
||||
LOGD(" %s", buf);
|
||||
} else if (current->ai_addr->sa_family == AF_INET6) {
|
||||
inet_ntop(current->ai_family, &((struct sockaddr_in6 *)current->ai_addr)->sin6_addr,
|
||||
buf, sizeof(buf));
|
||||
foundv6 = 1;
|
||||
ALOGD(" %s", buf);
|
||||
LOGD(" %s", buf);
|
||||
}
|
||||
current = current->ai_next;
|
||||
}
|
||||
@@ -60,14 +65,14 @@ JNIEXPORT jboolean Java_android_net_cts_DnsTest_testNativeDns(JNIEnv* env, jclas
|
||||
freeaddrinfo(answer);
|
||||
answer = NULL;
|
||||
if (foundv4 != 1 && foundv6 != 1) {
|
||||
ALOGD("getaddrinfo(www.google.com) didn't find either v4 or v6 address");
|
||||
LOGD("getaddrinfo(www.google.com) didn't find either v4 or v6 address");
|
||||
return JNI_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
node = "ipv6.google.com";
|
||||
res = getaddrinfo(node, service, NULL, &answer);
|
||||
ALOGD("getaddrinfo(ipv6.google.com) gave res=%d", res);
|
||||
LOGD("getaddrinfo(ipv6.google.com) gave res=%d", res);
|
||||
if (res != 0) return JNI_FALSE;
|
||||
|
||||
{
|
||||
@@ -79,12 +84,12 @@ JNIEXPORT jboolean Java_android_net_cts_DnsTest_testNativeDns(JNIEnv* env, jclas
|
||||
if (current->ai_addr->sa_family == AF_INET) {
|
||||
inet_ntop(current->ai_family, &((struct sockaddr_in *)current->ai_addr)->sin_addr,
|
||||
buf, sizeof(buf));
|
||||
ALOGD(" %s", buf);
|
||||
LOGD(" %s", buf);
|
||||
foundv4 = 1;
|
||||
} else if (current->ai_addr->sa_family == AF_INET6) {
|
||||
inet_ntop(current->ai_family, &((struct sockaddr_in6 *)current->ai_addr)->sin6_addr,
|
||||
buf, sizeof(buf));
|
||||
ALOGD(" %s", buf);
|
||||
LOGD(" %s", buf);
|
||||
foundv6 = 1;
|
||||
}
|
||||
current = current->ai_next;
|
||||
@@ -93,7 +98,7 @@ JNIEXPORT jboolean Java_android_net_cts_DnsTest_testNativeDns(JNIEnv* env, jclas
|
||||
freeaddrinfo(answer);
|
||||
answer = NULL;
|
||||
if (foundv4 == 1 || foundv6 != 1) {
|
||||
ALOGD("getaddrinfo(ipv6.google.com) didn't find only v6");
|
||||
LOGD("getaddrinfo(ipv6.google.com) didn't find only v6");
|
||||
return JNI_FALSE;
|
||||
}
|
||||
}
|
||||
@@ -116,12 +121,12 @@ JNIEXPORT jboolean Java_android_net_cts_DnsTest_testNativeDns(JNIEnv* env, jclas
|
||||
|
||||
res = getnameinfo((const struct sockaddr*)&sa4, sizeof(sa4), buf, sizeof(buf), NULL, 0, flags);
|
||||
if (res != 0) {
|
||||
ALOGD("getnameinfo(%s (GoogleDNS) ) gave error %d (%s)", GoogleDNSIpV4Address, res,
|
||||
LOGD("getnameinfo(%s (GoogleDNS) ) gave error %d (%s)", GoogleDNSIpV4Address, res,
|
||||
gai_strerror(res));
|
||||
return JNI_FALSE;
|
||||
}
|
||||
if (strstr(buf, "google.com") == NULL && strstr(buf, "dns.google") == NULL) {
|
||||
ALOGD("getnameinfo(%s (GoogleDNS) ) didn't return google.com or dns.google: %s",
|
||||
LOGD("getnameinfo(%s (GoogleDNS) ) didn't return google.com or dns.google: %s",
|
||||
GoogleDNSIpV4Address, buf);
|
||||
return JNI_FALSE;
|
||||
}
|
||||
@@ -129,12 +134,12 @@ JNIEXPORT jboolean Java_android_net_cts_DnsTest_testNativeDns(JNIEnv* env, jclas
|
||||
memset(buf, 0, sizeof(buf));
|
||||
res = getnameinfo((const struct sockaddr*)&sa6, sizeof(sa6), buf, sizeof(buf), NULL, 0, flags);
|
||||
if (res != 0) {
|
||||
ALOGD("getnameinfo(%s (GoogleDNS) ) gave error %d (%s)", GoogleDNSIpV6Address2,
|
||||
LOGD("getnameinfo(%s (GoogleDNS) ) gave error %d (%s)", GoogleDNSIpV6Address2,
|
||||
res, gai_strerror(res));
|
||||
return JNI_FALSE;
|
||||
}
|
||||
if (strstr(buf, "google.com") == NULL && strstr(buf, "dns.google") == NULL) {
|
||||
ALOGD("getnameinfo(%s (GoogleDNS) ) didn't return google.com or dns.google: %s",
|
||||
LOGD("getnameinfo(%s (GoogleDNS) ) didn't return google.com or dns.google: %s",
|
||||
GoogleDNSIpV6Address2, buf);
|
||||
return JNI_FALSE;
|
||||
}
|
||||
@@ -142,11 +147,11 @@ JNIEXPORT jboolean Java_android_net_cts_DnsTest_testNativeDns(JNIEnv* env, jclas
|
||||
// gethostbyname
|
||||
struct hostent *my_hostent = gethostbyname("www.youtube.com");
|
||||
if (my_hostent == NULL) {
|
||||
ALOGD("gethostbyname(www.youtube.com) gave null response");
|
||||
LOGD("gethostbyname(www.youtube.com) gave null response");
|
||||
return JNI_FALSE;
|
||||
}
|
||||
if ((my_hostent->h_addr_list == NULL) || (*my_hostent->h_addr_list == NULL)) {
|
||||
ALOGD("gethostbyname(www.youtube.com) gave 0 addresses");
|
||||
LOGD("gethostbyname(www.youtube.com) gave 0 addresses");
|
||||
return JNI_FALSE;
|
||||
}
|
||||
{
|
||||
@@ -154,7 +159,7 @@ JNIEXPORT jboolean Java_android_net_cts_DnsTest_testNativeDns(JNIEnv* env, jclas
|
||||
while (*current != NULL) {
|
||||
char buf[256];
|
||||
inet_ntop(my_hostent->h_addrtype, *current, buf, sizeof(buf));
|
||||
ALOGD("gethostbyname(www.youtube.com) gave %s", buf);
|
||||
LOGD("gethostbyname(www.youtube.com) gave %s", buf);
|
||||
current++;
|
||||
}
|
||||
}
|
||||
@@ -164,11 +169,11 @@ JNIEXPORT jboolean Java_android_net_cts_DnsTest_testNativeDns(JNIEnv* env, jclas
|
||||
inet_pton(AF_INET6, GoogleDNSIpV6Address, addr6);
|
||||
my_hostent = gethostbyaddr(addr6, sizeof(addr6), AF_INET6);
|
||||
if (my_hostent == NULL) {
|
||||
ALOGD("gethostbyaddr(%s (GoogleDNS) ) gave null response", GoogleDNSIpV6Address);
|
||||
LOGD("gethostbyaddr(%s (GoogleDNS) ) gave null response", GoogleDNSIpV6Address);
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
ALOGD("gethostbyaddr(%s (GoogleDNS) ) gave %s for name", GoogleDNSIpV6Address,
|
||||
LOGD("gethostbyaddr(%s (GoogleDNS) ) gave %s for name", GoogleDNSIpV6Address,
|
||||
my_hostent->h_name ? my_hostent->h_name : "null");
|
||||
|
||||
if (my_hostent->h_name == NULL) return JNI_FALSE;
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
|
||||
#define LOG_TAG "MultinetworkApiTest"
|
||||
#include <utils/Log.h>
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <arpa/nameser.h>
|
||||
@@ -34,9 +33,13 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <android/log.h>
|
||||
#include <android/multinetwork.h>
|
||||
#include <nativehelper/JNIHelp.h>
|
||||
|
||||
#define LOGD(fmt, ...) \
|
||||
__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, fmt, ##__VA_ARGS__)
|
||||
|
||||
#define EXPECT_GE(env, actual, expected, msg) \
|
||||
do { \
|
||||
if (actual < expected) { \
|
||||
@@ -138,7 +141,7 @@ int expectAnswersNotValid(JNIEnv* env, int fd, int expectedErrno) {
|
||||
uint8_t buf[MAXPACKET] = {};
|
||||
int res = getAsyncResponse(env, fd, TIMEOUT_MS, &rcode, buf, MAXPACKET);
|
||||
if (res != expectedErrno) {
|
||||
ALOGD("res:%d, expectedErrno = %d", res, expectedErrno);
|
||||
LOGD("res:%d, expectedErrno = %d", res, expectedErrno);
|
||||
return (res > 0) ? -EREMOTEIO : res;
|
||||
}
|
||||
return 0;
|
||||
@@ -326,7 +329,7 @@ JNIEXPORT jint Java_android_net_cts_MultinetworkApiTest_runGetaddrinfoCheck(
|
||||
const int saved_errno = errno;
|
||||
freeaddrinfo(res);
|
||||
|
||||
ALOGD("android_getaddrinfofornetwork(%" PRIu64 ", %s) returned rval=%d errno=%d",
|
||||
LOGD("android_getaddrinfofornetwork(%" PRIu64 ", %s) returned rval=%d errno=%d",
|
||||
handle, kHostname, rval, saved_errno);
|
||||
return rval == 0 ? 0 : -saved_errno;
|
||||
}
|
||||
@@ -339,7 +342,7 @@ JNIEXPORT jint Java_android_net_cts_MultinetworkApiTest_runSetprocnetwork(
|
||||
errno = 0;
|
||||
int rval = android_setprocnetwork(handle);
|
||||
const int saved_errno = errno;
|
||||
ALOGD("android_setprocnetwork(%" PRIu64 ") returned rval=%d errno=%d",
|
||||
LOGD("android_setprocnetwork(%" PRIu64 ") returned rval=%d errno=%d",
|
||||
handle, rval, saved_errno);
|
||||
return rval == 0 ? 0 : -saved_errno;
|
||||
}
|
||||
@@ -352,14 +355,14 @@ JNIEXPORT jint Java_android_net_cts_MultinetworkApiTest_runSetsocknetwork(
|
||||
errno = 0;
|
||||
int fd = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
|
||||
if (fd < 0) {
|
||||
ALOGD("socket() failed, errno=%d", errno);
|
||||
LOGD("socket() failed, errno=%d", errno);
|
||||
return -errno;
|
||||
}
|
||||
|
||||
errno = 0;
|
||||
int rval = android_setsocknetwork(handle, fd);
|
||||
const int saved_errno = errno;
|
||||
ALOGD("android_setprocnetwork(%" PRIu64 ", %d) returned rval=%d errno=%d",
|
||||
LOGD("android_setprocnetwork(%" PRIu64 ", %d) returned rval=%d errno=%d",
|
||||
handle, fd, rval, saved_errno);
|
||||
close(fd);
|
||||
return rval == 0 ? 0 : -saved_errno;
|
||||
@@ -404,7 +407,7 @@ JNIEXPORT jint Java_android_net_cts_MultinetworkApiTest_runDatagramCheck(
|
||||
static const char kPort[] = "443";
|
||||
int rval = android_getaddrinfofornetwork(handle, kHostname, kPort, &kHints, &res);
|
||||
if (rval != 0) {
|
||||
ALOGD("android_getaddrinfofornetwork(%llu, %s) returned rval=%d errno=%d",
|
||||
LOGD("android_getaddrinfofornetwork(%llu, %s) returned rval=%d errno=%d",
|
||||
handle, kHostname, rval, errno);
|
||||
freeaddrinfo(res);
|
||||
return -errno;
|
||||
@@ -413,14 +416,14 @@ JNIEXPORT jint Java_android_net_cts_MultinetworkApiTest_runDatagramCheck(
|
||||
// Rely upon getaddrinfo sorting the best destination to the front.
|
||||
int fd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
|
||||
if (fd < 0) {
|
||||
ALOGD("socket(%d, %d, %d) failed, errno=%d",
|
||||
LOGD("socket(%d, %d, %d) failed, errno=%d",
|
||||
res->ai_family, res->ai_socktype, res->ai_protocol, errno);
|
||||
freeaddrinfo(res);
|
||||
return -errno;
|
||||
}
|
||||
|
||||
rval = android_setsocknetwork(handle, fd);
|
||||
ALOGD("android_setprocnetwork(%llu, %d) returned rval=%d errno=%d",
|
||||
LOGD("android_setprocnetwork(%llu, %d) returned rval=%d errno=%d",
|
||||
handle, fd, rval, errno);
|
||||
if (rval != 0) {
|
||||
close(fd);
|
||||
@@ -430,7 +433,7 @@ JNIEXPORT jint Java_android_net_cts_MultinetworkApiTest_runDatagramCheck(
|
||||
|
||||
char addrstr[kSockaddrStrLen+1];
|
||||
sockaddr_ntop(res->ai_addr, res->ai_addrlen, addrstr, sizeof(addrstr));
|
||||
ALOGD("Attempting connect() to %s ...", addrstr);
|
||||
LOGD("Attempting connect() to %s ...", addrstr);
|
||||
|
||||
rval = connect(fd, res->ai_addr, res->ai_addrlen);
|
||||
if (rval != 0) {
|
||||
@@ -447,7 +450,7 @@ JNIEXPORT jint Java_android_net_cts_MultinetworkApiTest_runDatagramCheck(
|
||||
return -errno;
|
||||
}
|
||||
sockaddr_ntop((const struct sockaddr *)&src_addr, sizeof(src_addr), addrstr, sizeof(addrstr));
|
||||
ALOGD("... from %s", addrstr);
|
||||
LOGD("... from %s", addrstr);
|
||||
|
||||
// Don't let reads or writes block indefinitely.
|
||||
const struct timeval timeo = { 2, 0 }; // 2 seconds
|
||||
@@ -479,7 +482,7 @@ JNIEXPORT jint Java_android_net_cts_MultinetworkApiTest_runDatagramCheck(
|
||||
sent = send(fd, quic_packet, sizeof(quic_packet), 0);
|
||||
if (sent < (ssize_t)sizeof(quic_packet)) {
|
||||
errnum = errno;
|
||||
ALOGD("send(QUIC packet) returned sent=%zd, errno=%d", sent, errnum);
|
||||
LOGD("send(QUIC packet) returned sent=%zd, errno=%d", sent, errnum);
|
||||
close(fd);
|
||||
return -errnum;
|
||||
}
|
||||
@@ -489,14 +492,14 @@ JNIEXPORT jint Java_android_net_cts_MultinetworkApiTest_runDatagramCheck(
|
||||
break;
|
||||
} else {
|
||||
errnum = errno;
|
||||
ALOGD("[%d/%d] recv(QUIC response) returned rcvd=%zd, errno=%d",
|
||||
LOGD("[%d/%d] recv(QUIC response) returned rcvd=%zd, errno=%d",
|
||||
i + 1, MAX_RETRIES, rcvd, errnum);
|
||||
}
|
||||
}
|
||||
if (rcvd < 9) {
|
||||
ALOGD("QUIC UDP %s: sent=%zd but rcvd=%zd, errno=%d", kPort, sent, rcvd, errnum);
|
||||
LOGD("QUIC UDP %s: sent=%zd but rcvd=%zd, errno=%d", kPort, sent, rcvd, errnum);
|
||||
if (rcvd <= 0) {
|
||||
ALOGD("Does this network block UDP port %s?", kPort);
|
||||
LOGD("Does this network block UDP port %s?", kPort);
|
||||
}
|
||||
close(fd);
|
||||
return -EPROTO;
|
||||
@@ -504,7 +507,7 @@ JNIEXPORT jint Java_android_net_cts_MultinetworkApiTest_runDatagramCheck(
|
||||
|
||||
int conn_id_cmp = memcmp(quic_packet + 1, response + 1, 8);
|
||||
if (conn_id_cmp != 0) {
|
||||
ALOGD("sent and received connection IDs do not match");
|
||||
LOGD("sent and received connection IDs do not match");
|
||||
close(fd);
|
||||
return -EPROTO;
|
||||
}
|
||||
|
||||
@@ -18,15 +18,17 @@ package android.net.cts;
|
||||
|
||||
import static android.net.ConnectivityDiagnosticsManager.ConnectivityDiagnosticsCallback;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.ConnectivityDiagnosticsManager;
|
||||
import android.net.NetworkRequest;
|
||||
import android.os.Build;
|
||||
|
||||
import androidx.test.InstrumentationRegistry;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import com.android.testutils.DevSdkIgnoreRule.IgnoreUpTo;
|
||||
import com.android.testutils.DevSdkIgnoreRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -34,7 +36,8 @@ import org.junit.runner.RunWith;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@RunWith(DevSdkIgnoreRunner.class)
|
||||
@IgnoreUpTo(Build.VERSION_CODES.Q) // ConnectivityDiagnosticsManager did not exist in Q
|
||||
public class ConnectivityDiagnosticsManagerTest {
|
||||
private static final Executor INLINE_EXECUTOR = x -> x.run();
|
||||
private static final NetworkRequest DEFAULT_REQUEST = new NetworkRequest.Builder().build();
|
||||
|
||||
@@ -180,7 +180,7 @@ class NetworkAgentTest {
|
||||
}
|
||||
|
||||
private open class TestableNetworkAgent(
|
||||
val looper: Looper,
|
||||
looper: Looper,
|
||||
val nc: NetworkCapabilities,
|
||||
val lp: LinkProperties,
|
||||
conf: NetworkAgentConfig
|
||||
|
||||
Reference in New Issue
Block a user