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