[Objc] iOS ThirdPartyTest suite for libuv dns test, add additional dns test (#28573)

* add ios libuv additional dns test

* rewrite LibuvGetAddrInfoTests.m

* comment address

* clang format
pull/29435/head
Hannah Shi 3 years ago committed by GitHub
parent 93a90e3c55
commit bf4ab9654b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 134
      src/objective-c/tests/ThirdPartyTests/Libuv/LibuvGetAddrInfoTests.m
  2. 46
      src/objective-c/tests/ThirdPartyTests/Libuv/LibuvGetHostnameTests.m
  3. 50
      src/objective-c/tests/ThirdPartyTests/Libuv/LibuvGetNameInfo.m
  4. 48
      src/objective-c/tests/ThirdPartyTests/Libuv/LibuvGetSockNameTests.m
  5. 12
      src/objective-c/tests/ThirdPartyTests/Libuv/LibuvTimerTests.m
  6. 4
      third_party/libuv.BUILD

@ -18,55 +18,26 @@
#import <XCTest/XCTest.h>
#import <stdlib.h>
#import <uv.h>
#define ASSERT(x) XCTAssertTrue(x)
#define ASSERT_NULL(x) XCTAssertTrue(x == NULL)
#define ASSERT_NOT_NULL(x) XCTAssertFalse(x == NULL)
#define CONCURRENT_COUNT 10
static const char* name = "localhost";
static int getaddrinfo_cbs = 0;
/* data used for running multiple calls concurrently */
static uv_getaddrinfo_t* getaddrinfo_handle;
static uv_getaddrinfo_t getaddrinfo_handles[CONCURRENT_COUNT];
static int callback_counts[CONCURRENT_COUNT];
static int fail_cb_called;
static void getaddrinfo_fail_cb(uv_getaddrinfo_t* req, int status, struct addrinfo* res) {
ASSERT(fail_cb_called == 0);
ASSERT(status < 0);
ASSERT_NULL(res);
uv_freeaddrinfo(res); /* Should not crash. */
fail_cb_called++;
}
static void getaddrinfo_basic_cb(uv_getaddrinfo_t* handle, int status, struct addrinfo* res) {
ASSERT(handle == getaddrinfo_handle);
getaddrinfo_cbs++;
free(handle);
uv_freeaddrinfo(res);
}
static void getaddrinfo_cuncurrent_cb(uv_getaddrinfo_t* handle, int status, struct addrinfo* res) {
int i;
int* data = (int*)handle->data;
for (i = 0; i < CONCURRENT_COUNT; i++) {
if (&getaddrinfo_handles[i] == handle) {
ASSERT(i == *data);
callback_counts[i]++;
break;
}
}
ASSERT(i < CONCURRENT_COUNT);
free(data);
uv_freeaddrinfo(res);
getaddrinfo_cbs++;
}
#import "test/runner.h"
#import "test/task.h"
// Tests in:
// libuv/test/test-getaddrinfo.c
TEST_DECLARE(getaddrinfo_fail)
TEST_DECLARE(getaddrinfo_fail_sync)
TEST_DECLARE(getaddrinfo_basic)
TEST_DECLARE(getaddrinfo_basic_sync)
TEST_DECLARE(getaddrinfo_concurrent)
#define TASK_LIST_START_LOCAL static task_entry_t TEST_TASKS[] = {
TASK_LIST_START_LOCAL
TEST_ENTRY(getaddrinfo_fail)
TEST_ENTRY(getaddrinfo_fail_sync)
TEST_ENTRY(getaddrinfo_basic)
TEST_ENTRY(getaddrinfo_basic_sync)
TEST_ENTRY(getaddrinfo_concurrent)
TASK_LIST_END
@interface LibuvGetAddrInfoTests : XCTestCase
@ -74,68 +45,9 @@ static void getaddrinfo_cuncurrent_cb(uv_getaddrinfo_t* handle, int status, stru
@implementation LibuvGetAddrInfoTests
- (void)testGetAddrInfoFail {
uv_getaddrinfo_t req;
ASSERT(UV_EINVAL ==
uv_getaddrinfo(uv_default_loop(), &req, (uv_getaddrinfo_cb)abort, NULL, NULL, NULL));
/* Use a FQDN by ending in a period */
ASSERT(0 == uv_getaddrinfo(uv_default_loop(), &req, getaddrinfo_fail_cb, "example.invalid.", NULL,
NULL));
ASSERT(0 == uv_run(uv_default_loop(), UV_RUN_DEFAULT));
ASSERT(fail_cb_called == 1);
}
- (void)testGetAddrInfoFailSync {
uv_getaddrinfo_t req;
/* Use a FQDN by ending in a period */
ASSERT(0 > uv_getaddrinfo(uv_default_loop(), &req, NULL, "example.invalid.", NULL, NULL));
uv_freeaddrinfo(req.addrinfo);
}
- (void)testGetAddrInfoBasic {
int r;
getaddrinfo_handle = (uv_getaddrinfo_t*)malloc(sizeof(uv_getaddrinfo_t));
r = uv_getaddrinfo(uv_default_loop(), getaddrinfo_handle, &getaddrinfo_basic_cb, name, NULL,
NULL);
ASSERT(r == 0);
uv_run(uv_default_loop(), UV_RUN_DEFAULT);
ASSERT(getaddrinfo_cbs == 1);
}
- (void)testGetAddrInfoBasicSync {
uv_getaddrinfo_t req;
ASSERT(0 == uv_getaddrinfo(uv_default_loop(), &req, NULL, name, NULL, NULL));
uv_freeaddrinfo(req.addrinfo);
}
- (void)testGetAddrInfoConcurrent {
int i, r;
int* data;
for (i = 0; i < CONCURRENT_COUNT; i++) {
callback_counts[i] = 0;
data = (int*)malloc(sizeof(int));
ASSERT_NOT_NULL(data);
*data = i;
getaddrinfo_handles[i].data = data;
r = uv_getaddrinfo(uv_default_loop(), &getaddrinfo_handles[i], &getaddrinfo_cuncurrent_cb, name,
NULL, NULL);
ASSERT(r == 0);
}
uv_run(uv_default_loop(), UV_RUN_DEFAULT);
for (i = 0; i < CONCURRENT_COUNT; i++) {
ASSERT(callback_counts[i] == 1);
- (void)testGetAddrInfoAll {
for (task_entry_t* task = TEST_TASKS; task->main; task++) {
task->main();
}
}

@ -0,0 +1,46 @@
/*
*
* Copyright 2021 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#import <XCTest/XCTest.h>
#import "test/runner.h"
#import "test/task.h"
// Tests in:
// libuv/test/test-gethostname.c
TEST_DECLARE(gethostname)
#define TASK_LIST_START_LOCAL static task_entry_t TEST_TASKS[] = {
TASK_LIST_START_LOCAL
TEST_ENTRY(gethostname)
TASK_LIST_END
@interface LibuvGetHostNameTests : XCTestCase
@end
@implementation LibuvGetHostNameTests
- (void)testGetHostNameAll {
for (task_entry_t* task = TEST_TASKS; task->main; task++) {
task->main();
}
}
@end

@ -0,0 +1,50 @@
/*
*
* Copyright 2021 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#import <XCTest/XCTest.h>
#import "test/runner.h"
#import "test/task.h"
// Tests in:
// libuv/test/test-getnameinfo.c
TEST_DECLARE(getnameinfo_basic_ip4)
TEST_DECLARE(getnameinfo_basic_ip4_sync)
TEST_DECLARE(getnameinfo_basic_ip6)
#define TASK_LIST_START_LOCAL static task_entry_t TEST_TASKS[] = {
TASK_LIST_START_LOCAL
TEST_ENTRY(getnameinfo_basic_ip4)
TEST_ENTRY(getnameinfo_basic_ip4_sync)
TEST_ENTRY(getnameinfo_basic_ip6)
TASK_LIST_END
@interface LibuvGetNameInfoTests : XCTestCase
@end
@implementation LibuvGetNameInfoTests
- (void)testGetHostNameAll {
for (task_entry_t* task = TEST_TASKS; task->main; task++) {
task->main();
}
}
@end

@ -0,0 +1,48 @@
/*
*
* Copyright 2021 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#import <XCTest/XCTest.h>
#import "test/runner.h"
#import "test/task.h"
// Tests in:
// libuv/test/test-getsockname.c
TEST_DECLARE(getsockname_tcp)
TEST_DECLARE(getsockname_udp)
#define TASK_LIST_START_LOCAL static task_entry_t TEST_TASKS[] = {
TASK_LIST_START_LOCAL
TEST_ENTRY(getsockname_tcp)
// TEST_ENTRY(getsockname_udp)
TASK_LIST_END
@interface LibuvGetSockNameTests : XCTestCase
@end
@implementation LibuvGetSockNameTests
- (void)testGetSockNameAll {
for (task_entry_t* task = TEST_TASKS; task->main; task++) {
task->main();
}
}
@end

@ -21,6 +21,11 @@
#import "test/runner.h"
#import "test/task.h"
// Tests in:
// libuv/test/test-timer.c
// libuv/test/test-timer-again.c
// libuv/test/test-timer-from-check.c
TEST_DECLARE(timer)
TEST_DECLARE(timer_init)
TEST_DECLARE(timer_again)
@ -34,7 +39,8 @@ TEST_DECLARE(timer_is_closing)
TEST_DECLARE(timer_null_callback)
TEST_DECLARE(timer_early_check)
TASK_LIST_START
#define TASK_LIST_START_LOCAL static task_entry_t TEST_TASKS[] = {
TASK_LIST_START_LOCAL
TEST_ENTRY(timer)
TEST_ENTRY(timer_init)
TEST_ENTRY(timer_again)
@ -56,9 +62,9 @@ TASK_LIST_END
@implementation LibuvTimerTests
- (void)testTimerAll {
for (task_entry_t* task = TASKS; task->main; task++) {
for (task_entry_t* task = TEST_TASKS; task->main; task++) {
task->main();
}
}
@end
@end

@ -331,6 +331,10 @@ cc_library(
"test/test-timer.c",
"test/test-timer-again.c",
"test/test-timer-from-check.c",
"test/test-getaddrinfo.c",
"test/test-gethostname.c",
"test/test-getnameinfo.c",
"test/test-getsockname.c",
],
hdrs = [
"test/runner.h",

Loading…
Cancel
Save