Merge "Improve test and fix doulbe-close fd problem for async DNS API cts" am: 277181d9d3
am: af31d7737c
Change-Id: Ifda2107b18e1dad6cef227f440bb3cf10a401e15
This commit is contained in:
@@ -245,13 +245,12 @@ JNIEXPORT jint Java_android_net_cts_MultinetworkApiTest_runResNcancelCheck(
|
|||||||
net_handle_t handle = (net_handle_t) nethandle;
|
net_handle_t handle = (net_handle_t) nethandle;
|
||||||
|
|
||||||
int fd = android_res_nquery(handle, kGoogleName, ns_c_in, ns_t_a, 0);
|
int fd = android_res_nquery(handle, kGoogleName, ns_c_in, ns_t_a, 0);
|
||||||
int rcode = -1;
|
errno = 0;
|
||||||
uint8_t buf[MAXPACKET] = {};
|
|
||||||
android_res_cancel(fd);
|
android_res_cancel(fd);
|
||||||
EXPECT_EQ(env, -EBADF, android_res_nresult(fd, &rcode, buf, MAXPACKET), "res_cancel");
|
int err = errno;
|
||||||
|
EXPECT_EQ(env, 0, err, "res_cancel");
|
||||||
android_res_cancel(fd);
|
// DO NOT call cancel or result with the same fd more than once,
|
||||||
EXPECT_EQ(env, -EBADF, android_res_nresult(fd, &rcode, buf, MAXPACKET), "res_cancel");
|
// otherwise it will hit fdsan double-close fd.
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -288,10 +287,10 @@ JNIEXPORT jint Java_android_net_cts_MultinetworkApiTest_runResNapiMalformedCheck
|
|||||||
fd = android_res_nsend(handle, largeBuf, sizeof(largeBuf), 0);
|
fd = android_res_nsend(handle, largeBuf, sizeof(largeBuf), 0);
|
||||||
EXPECT_EQ(env, -EMSGSIZE, fd, "res_nsend buffer larger than 8KB");
|
EXPECT_EQ(env, -EMSGSIZE, fd, "res_nsend buffer larger than 8KB");
|
||||||
|
|
||||||
// 1000 bytes filled with 0. This returns EMSGSIZE because FrameworkListener limits the size of
|
// 5000 bytes filled with 0. This returns EMSGSIZE because FrameworkListener limits the size of
|
||||||
// commands to 1024 bytes. TODO: b/126307309
|
// commands to 4096 bytes.
|
||||||
fd = android_res_nsend(handle, largeBuf, 1000, 0);
|
fd = android_res_nsend(handle, largeBuf, 5000, 0);
|
||||||
EXPECT_EQ(env, -EMSGSIZE, fd, "res_nsend 1000 bytes filled with 0");
|
EXPECT_EQ(env, -EMSGSIZE, fd, "res_nsend 5000 bytes filled with 0");
|
||||||
|
|
||||||
// 500 bytes filled with 0
|
// 500 bytes filled with 0
|
||||||
fd = android_res_nsend(handle, largeBuf, 500, 0);
|
fd = android_res_nsend(handle, largeBuf, 500, 0);
|
||||||
@@ -299,16 +298,16 @@ JNIEXPORT jint Java_android_net_cts_MultinetworkApiTest_runResNapiMalformedCheck
|
|||||||
EXPECT_EQ(env, 0, expectAnswersNotValid(env, fd, -EINVAL),
|
EXPECT_EQ(env, 0, expectAnswersNotValid(env, fd, -EINVAL),
|
||||||
"res_nsend 500 bytes filled with 0 check answers");
|
"res_nsend 500 bytes filled with 0 check answers");
|
||||||
|
|
||||||
// 1000 bytes filled with 0xFF
|
// 5000 bytes filled with 0xFF
|
||||||
uint8_t ffBuf[1001] = {};
|
uint8_t ffBuf[5001] = {};
|
||||||
memset(ffBuf, 0xFF, sizeof(ffBuf));
|
memset(ffBuf, 0xFF, sizeof(ffBuf));
|
||||||
ffBuf[1000] = '\0';
|
ffBuf[5000] = '\0';
|
||||||
fd = android_res_nsend(handle, ffBuf, sizeof(ffBuf), 0);
|
fd = android_res_nsend(handle, ffBuf, sizeof(ffBuf), 0);
|
||||||
EXPECT_EQ(env, -EMSGSIZE, fd, "res_nsend 1000 bytes filled with 0xFF");
|
EXPECT_EQ(env, -EMSGSIZE, fd, "res_nsend 5000 bytes filled with 0xFF");
|
||||||
|
|
||||||
// 500 bytes filled with 0xFF
|
// 500 bytes filled with 0xFF
|
||||||
ffBuf[501] = '\0';
|
ffBuf[500] = '\0';
|
||||||
fd = android_res_nsend(handle, ffBuf, 500, 0);
|
fd = android_res_nsend(handle, ffBuf, 501, 0);
|
||||||
EXPECT_GE(env, fd, 0, "res_nsend 500 bytes filled with 0xFF");
|
EXPECT_GE(env, fd, 0, "res_nsend 500 bytes filled with 0xFF");
|
||||||
EXPECT_EQ(env, 0, expectAnswersNotValid(env, fd, -EINVAL),
|
EXPECT_EQ(env, 0, expectAnswersNotValid(env, fd, -EINVAL),
|
||||||
"res_nsend 500 bytes filled with 0xFF check answers");
|
"res_nsend 500 bytes filled with 0xFF check answers");
|
||||||
|
|||||||
@@ -194,13 +194,12 @@ TEST (NativeDnsAsyncTest, Async_NXDOMAIN) {
|
|||||||
TEST (NativeDnsAsyncTest, Async_Cancel) {
|
TEST (NativeDnsAsyncTest, Async_Cancel) {
|
||||||
int fd = android_res_nquery(
|
int fd = android_res_nquery(
|
||||||
NETWORK_UNSPECIFIED, "www.google.com", ns_c_in, ns_t_a, 0);
|
NETWORK_UNSPECIFIED, "www.google.com", ns_c_in, ns_t_a, 0);
|
||||||
int rcode = -1;
|
errno = 0;
|
||||||
uint8_t buf[MAXPACKET] = {};
|
|
||||||
android_res_cancel(fd);
|
android_res_cancel(fd);
|
||||||
android_res_cancel(fd);
|
int err = errno;
|
||||||
|
EXPECT_EQ(err, 0);
|
||||||
int res = android_res_nresult(fd, &rcode, buf, MAXPACKET);
|
// DO NOT call cancel or result with the same fd more than once,
|
||||||
EXPECT_EQ(-EBADF, res);
|
// otherwise it will hit fdsan double-close fd.
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST (NativeDnsAsyncTest, Async_Query_MALFORMED) {
|
TEST (NativeDnsAsyncTest, Async_Query_MALFORMED) {
|
||||||
@@ -235,9 +234,9 @@ TEST (NativeDnsAsyncTest, Async_Send_MALFORMED) {
|
|||||||
NETWORK_UNSPECIFIED, largeBuf.data(), largeBuf.size(), 0);
|
NETWORK_UNSPECIFIED, largeBuf.data(), largeBuf.size(), 0);
|
||||||
EXPECT_EQ(-EMSGSIZE, fd);
|
EXPECT_EQ(-EMSGSIZE, fd);
|
||||||
|
|
||||||
// 1000 bytes filled with 0. This returns EMSGSIZE because FrameworkListener limits the size of
|
// 5000 bytes filled with 0. This returns EMSGSIZE because FrameworkListener limits the size of
|
||||||
// commands to 1024 bytes. TODO: fix this.
|
// commands to 4096 bytes.
|
||||||
fd = android_res_nsend(NETWORK_UNSPECIFIED, largeBuf.data(), 1000, 0);
|
fd = android_res_nsend(NETWORK_UNSPECIFIED, largeBuf.data(), 5000, 0);
|
||||||
EXPECT_EQ(-EMSGSIZE, fd);
|
EXPECT_EQ(-EMSGSIZE, fd);
|
||||||
|
|
||||||
// 500 bytes filled with 0
|
// 500 bytes filled with 0
|
||||||
@@ -245,8 +244,8 @@ TEST (NativeDnsAsyncTest, Async_Send_MALFORMED) {
|
|||||||
EXPECT_GE(fd, 0);
|
EXPECT_GE(fd, 0);
|
||||||
expectAnswersNotValid(fd, -EINVAL);
|
expectAnswersNotValid(fd, -EINVAL);
|
||||||
|
|
||||||
// 1000 bytes filled with 0xFF
|
// 5000 bytes filled with 0xFF
|
||||||
std::vector<uint8_t> ffBuf(1000, 0xFF);
|
std::vector<uint8_t> ffBuf(5000, 0xFF);
|
||||||
fd = android_res_nsend(
|
fd = android_res_nsend(
|
||||||
NETWORK_UNSPECIFIED, ffBuf.data(), ffBuf.size(), 0);
|
NETWORK_UNSPECIFIED, ffBuf.data(), ffBuf.size(), 0);
|
||||||
EXPECT_EQ(-EMSGSIZE, fd);
|
EXPECT_EQ(-EMSGSIZE, fd);
|
||||||
|
|||||||
Reference in New Issue
Block a user