From 842ed8d4610461255f965ebee5cedd1793effc81 Mon Sep 17 00:00:00 2001 From: Hannah Shi Date: Wed, 16 Mar 2022 13:03:01 -0700 Subject: [PATCH] [Objc] add ios libuv timer test (#28570) * use libuv in third party * add ios libuv timer test * name changed correspondingly * format code * address comment * remove libuv patch --- bazel/grpc_deps.bzl | 13 ++-- .../tests/ThirdPartyTests/Libuv/BUILD | 3 +- .../ThirdPartyTests/Libuv/LibuvTimerTests.m | 64 +++++++++++++++++++ third_party/libuv.BUILD | 61 ++++++++++++++++++ .../run_tests/sanity/check_bazel_workspace.py | 9 +-- 5 files changed, 141 insertions(+), 9 deletions(-) create mode 100644 src/objective-c/tests/ThirdPartyTests/Libuv/LibuvTimerTests.m diff --git a/bazel/grpc_deps.bzl b/bazel/grpc_deps.bzl index 91791075977..d3b61552472 100644 --- a/bazel/grpc_deps.bzl +++ b/bazel/grpc_deps.bzl @@ -181,8 +181,13 @@ def grpc_deps(): ) native.bind( - name = "uv", - actual = "@libuv//:libuv", + name = "libuv", + actual = "@com_github_libuv_libuv//:libuv", + ) + + native.bind( + name = "libuv_test", + actual = "@com_github_libuv_libuv//:libuv_test", ) if "boringssl" not in native.existing_rules(): @@ -388,9 +393,9 @@ def grpc_deps(): ], ) - if "libuv" not in native.existing_rules(): + if "com_github_libuv_libuv" not in native.existing_rules(): http_archive( - name = "libuv", + name = "com_github_libuv_libuv", build_file = "@com_github_grpc_grpc//third_party:libuv.BUILD", sha256 = "5ca4e9091f3231d8ad8801862dc4e851c23af89c69141d27723157776f7291e7", strip_prefix = "libuv-02a9e1be252b623ee032a3137c0b0c94afbe6809", diff --git a/src/objective-c/tests/ThirdPartyTests/Libuv/BUILD b/src/objective-c/tests/ThirdPartyTests/Libuv/BUILD index a5643abd0e7..4822276e6fe 100644 --- a/src/objective-c/tests/ThirdPartyTests/Libuv/BUILD +++ b/src/objective-c/tests/ThirdPartyTests/Libuv/BUILD @@ -36,7 +36,8 @@ objc_library( testonly = True, srcs = glob(["*.m"]), deps = [ - "//external:uv", + "//external:libuv", + "//external:libuv_test", ], ) diff --git a/src/objective-c/tests/ThirdPartyTests/Libuv/LibuvTimerTests.m b/src/objective-c/tests/ThirdPartyTests/Libuv/LibuvTimerTests.m new file mode 100644 index 00000000000..5c378845b4b --- /dev/null +++ b/src/objective-c/tests/ThirdPartyTests/Libuv/LibuvTimerTests.m @@ -0,0 +1,64 @@ +/* + * + * 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 + +#import "test/runner.h" +#import "test/task.h" + +TEST_DECLARE(timer) +TEST_DECLARE(timer_init) +TEST_DECLARE(timer_again) +// TEST_DECLARE(timer_start_twice) //withhold until libuv patched +TEST_DECLARE(timer_order) +TEST_DECLARE(timer_huge_timeout) +TEST_DECLARE(timer_huge_repeat) +TEST_DECLARE(timer_run_once) +TEST_DECLARE(timer_from_check) +TEST_DECLARE(timer_is_closing) +TEST_DECLARE(timer_null_callback) +TEST_DECLARE(timer_early_check) + +TASK_LIST_START +TEST_ENTRY(timer) +TEST_ENTRY(timer_init) +TEST_ENTRY(timer_again) +// TEST_ENTRY(timer_start_twice) //withhold until libuv patched +TEST_ENTRY(timer_order) +TEST_ENTRY(timer_huge_timeout) +TEST_ENTRY(timer_huge_repeat) +TEST_ENTRY(timer_run_once) +TEST_ENTRY(timer_from_check) +TEST_ENTRY(timer_is_closing) +TEST_ENTRY(timer_null_callback) +TEST_ENTRY(timer_early_check) +TASK_LIST_END + +@interface LibuvTimerTests : XCTestCase + +@end + +@implementation LibuvTimerTests + +- (void)testTimerAll { + for (task_entry_t* task = TASKS; task->main; task++) { + task->main(); + } +} + +@end \ No newline at end of file diff --git a/third_party/libuv.BUILD b/third_party/libuv.BUILD index 84bfca89146..ebb8556fca3 100644 --- a/third_party/libuv.BUILD +++ b/third_party/libuv.BUILD @@ -324,3 +324,64 @@ cc_library( "//visibility:public", ], ) + +cc_library( + name = "libuv_test", + srcs = [ + "test/test-timer.c", + "test/test-timer-again.c", + "test/test-timer-from-check.c", + ], + hdrs = [ + "test/runner.h", + "test/runner-unix.h", + "test/task.h", + ], + includes = [ + "include", + "src", + ], + deps = [ + ":libuv" + ], + copts = [ + "-D_LARGEFILE_SOURCE", + "-D_FILE_OFFSET_BITS=64", + "-D_GNU_SOURCE", + "-pthread", + "--std=gnu89", + "-pedantic", + "-Wno-error", + "-Wno-strict-aliasing", + "-Wstrict-aliasing", + "-O2", + "-Wno-implicit-function-declaration", + "-Wno-unused-function", + "-Wno-unused-variable", + ] + select({ + ":apple": [], + ":windows": [ + "-DWIN32_LEAN_AND_MEAN", + "-D_WIN32_WINNT=0x0600", + ], + "//conditions:default": [ + "-Wno-tree-vrp", + "-Wno-omit-frame-pointer", + "-D_DARWIN_USE_64_BIT_INODE=1", + "-D_DARWIN_UNLIMITED_SELECT=1", + ], + }), + linkopts = select({ + ":windows": [ + "-Xcrosstool-compilation-mode=$(COMPILATION_MODE)", + "-Wl,Iphlpapi.lib", + "-Wl,Psapi.lib", + "-Wl,User32.lib", + "-Wl,Userenv.lib", + ], + "//conditions:default": [], + }), + visibility = [ + "//visibility:public", + ], +) diff --git a/tools/run_tests/sanity/check_bazel_workspace.py b/tools/run_tests/sanity/check_bazel_workspace.py index 257f2b4c330..4965a15e2e5 100755 --- a/tools/run_tests/sanity/check_bazel_workspace.py +++ b/tools/run_tests/sanity/check_bazel_workspace.py @@ -48,10 +48,11 @@ _GRPC_DEP_NAMES = [ _TWISTED_TWISTED_DEP_NAME, _YAML_PYYAML_DEP_NAME, _TWISTED_INCREMENTAL_DEP_NAME, _ZOPEFOUNDATION_ZOPE_INTERFACE_DEP_NAME, _TWISTED_CONSTANTLY_DEP_NAME, 'io_bazel_rules_go', - 'build_bazel_rules_apple', 'build_bazel_apple_support', 'libuv', - 'com_googlesource_code_re2', 'bazel_gazelle', 'opencensus_proto', - 'com_envoyproxy_protoc_gen_validate', 'com_google_googleapis', - 'com_google_libprotobuf_mutator', 'com_github_cncf_udpa' + 'build_bazel_rules_apple', 'build_bazel_apple_support', + 'com_github_libuv_libuv', 'com_googlesource_code_re2', 'bazel_gazelle', + 'opencensus_proto', 'com_envoyproxy_protoc_gen_validate', + 'com_google_googleapis', 'com_google_libprotobuf_mutator', + 'com_github_cncf_udpa' ] _GRPC_BAZEL_ONLY_DEPS = [