Skip to content

Commit

Permalink
run ios CronetTest from bazel (#30439)
Browse files Browse the repository at this point in the history
  • Loading branch information
HannahShiSFB committed Sep 27, 2022
1 parent 6d249c0 commit 96d2763
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 10 deletions.
7 changes: 7 additions & 0 deletions BUILD
Expand Up @@ -706,6 +706,13 @@ grpc_cc_library(
],
)

grpc_cc_library(
name = "grpc_cronet_hdrs",
hdrs = [
"include/grpc/grpc_cronet.h",
],
)

grpc_cc_library(
name = "tchar",
srcs = [
Expand Down
29 changes: 29 additions & 0 deletions WORKSPACE
Expand Up @@ -88,3 +88,32 @@ pip_install(
name = "grpc_python_dependencies",
requirements = "@com_github_grpc_grpc//:requirements.bazel.txt",
)

http_archive(
name = "build_bazel_rules_swift",
sha256 = "12057b7aa904467284eee640de5e33853e51d8e31aae50b3fb25d2823d51c6b8",
url = "https://github.com/bazelbuild/rules_swift/releases/download/1.0.0/rules_swift.1.0.0.tar.gz",
)

http_archive(
name = "rules_pods",
urls = ["https://github.com/pinterest/PodToBUILD/releases/download/4.1.0-412495/PodToBUILD.zip"],
)

load(
"@build_bazel_rules_swift//swift:repositories.bzl",
"swift_rules_dependencies",
)
load(
"@rules_pods//BazelExtensions:workspace.bzl",
"new_pod_repository",
)

swift_rules_dependencies()

new_pod_repository(
name = "CronetFramework",
is_dynamic_framework = True,
podspec_url = "https://raw.githubusercontent.com/CocoaPods/Specs/master/Specs/2/e/1/CronetFramework/0.0.5/CronetFramework.podspec.json",
url = "https://storage.googleapis.com/grpc-precompiled-binaries/cronet/Cronet.framework-v0.0.5.zip",
)
12 changes: 12 additions & 0 deletions src/objective-c/BUILD
Expand Up @@ -239,6 +239,18 @@ grpc_objc_library(
],
)

grpc_objc_library(
name = "grpc_objc_client_core_cronet_testing",
srcs = glob(["GRPCClient/private/GRPCCore/GRPCCoreCronet/*.m"]),
hdrs = glob(["GRPCClient/private/GRPCCore/GRPCCoreCronet/*.h"]),
deps = [
":grpc_objc_client_core_internal_testing",
"//:grpc_cronet_hdrs",
"//src/core/ext/transport/cronet:grpc_transport_cronet_client_secure",
"@CronetFramework",
],
)

grpc_objc_library(
name = "proto_objc_rpc_internal_testing",
srcs = [
Expand Down
1 change: 1 addition & 0 deletions src/objective-c/grpc_objc_internal_library.bzl
Expand Up @@ -163,6 +163,7 @@ def grpc_objc_testing_library(
defines = defines,
includes = includes,
deps = deps + additional_deps,
testonly = 1,
)

def local_objc_grpc_library(name, deps, testing = True, srcs = [], use_well_known_protos = False, **kwargs):
Expand Down
31 changes: 30 additions & 1 deletion src/objective-c/tests/BUILD
Expand Up @@ -22,6 +22,7 @@ load(
"local_objc_grpc_library",
"proto_library_objc_wrapper",
)
load("//test/core/end2end:generate_tests.bzl", "grpc_end2end_tests")
load("@build_bazel_rules_apple//apple:resources.bzl", "apple_resource_bundle")
load("@build_bazel_rules_apple//apple:macos.bzl", "macos_unit_test")
load("@build_bazel_rules_apple//apple:tvos.bzl", "tvos_application", "tvos_unit_test")
Expand All @@ -32,6 +33,8 @@ package(default_visibility = ["//visibility:public"])

exports_files(["LICENSE"])

grpc_end2end_tests()

proto_library_objc_wrapper(
name = "messages_proto",
srcs = ["RemoteTestClient/messages.proto"],
Expand Down Expand Up @@ -171,7 +174,26 @@ grpc_objc_testing_library(
hdrs = ["MacTests/StressTests.h"],
)

grpc_objc_ios_unit_test(
grpc_objc_testing_library(
name = "CronetTests-lib",
srcs = [
"ConfigureCronet.m",
] + glob([
"CronetTests/*.m",
"CronetTests/*.mm",
]),
hdrs = [
"ConfigureCronet.h",
],
deps = [
"InteropTests-lib",
"//src/objective-c:grpc_objc_client_core_cronet_testing",
"//test/core/end2end:end2end_tests",
"//third_party/objective_c/Cronet:cronet_c_for_grpc",
],
)

grpc_objc_testing_library(
name = "UnitTests",
deps = [
":APIv2Tests-lib",
Expand Down Expand Up @@ -205,6 +227,13 @@ grpc_objc_ios_unit_test(
],
)

grpc_objc_ios_unit_test(
name = "CronetTests",
deps = [
"CronetTests-lib",
],
)

macos_unit_test(
name = "MacTests",
minimum_os_version = "10.10",
Expand Down
4 changes: 4 additions & 0 deletions src/objective-c/tests/CronetTests/CronetUnitTests.mm
Expand Up @@ -39,7 +39,11 @@
#import "test/core/end2end/data/ssl_test_data.h"
#import "test/core/util/test_config.h"

#if COCOAPODS
#import <openssl_grpc/ssl.h>
#else
#import <openssl/ssl.h>
#endif

static void drain_cq(grpc_completion_queue *cq) {
grpc_event ev;
Expand Down
Expand Up @@ -23,7 +23,7 @@
#import <GRPCClient/GRPCCall+Cronet.h>

#import "../ConfigureCronet.h"
#import "InteropTests.h"
#import "../InteropTests/InteropTests.h"

// The server address is derived from preprocessor macro, which is
// in turn derived from environment variable of the same name.
Expand Down
3 changes: 3 additions & 0 deletions test/core/end2end/generate_tests.bzl
Expand Up @@ -441,6 +441,9 @@ def grpc_end2end_tests():
"//:grpc_http_filters",
"//:event_log",
],
visibility = [
"//src/objective-c/tests:__subpackages__",
],
)
for f, fopt in END2END_FIXTURES.items():
bin_name = "%s_test" % f
Expand Down
1 change: 1 addition & 0 deletions tools/internal_ci/macos/grpc_objc_bazel_test.sh
Expand Up @@ -57,6 +57,7 @@ TEST_TARGETS=(
//src/objective-c/tests:InteropTestsRemote
//src/objective-c/tests:MacTests
//src/objective-c/tests:UnitTests
//src/objective-c/tests:CronetTests
# codegen plugin tests
//src/objective-c/tests:objc_codegen_plugin_test
//src/objective-c/tests:objc_codegen_plugin_option_test
Expand Down
8 changes: 0 additions & 8 deletions tools/run_tests/run_tests.py
Expand Up @@ -1013,14 +1013,6 @@ def test_specs(self):
shortname='ios-test-cfstream-tests',
cpu_cost=1e6,
environ=_FORCE_ENVIRON_FOR_WRAPPERS))
# TODO(jtattermusch): Create bazel target for the test and remove the test from here
# (how does one add the cronet dependency in bazel?)
out.append(
self.config.job_spec(['src/objective-c/tests/run_one_test.sh'],
timeout_seconds=60 * 60,
shortname='ios-test-cronettests',
cpu_cost=1e6,
environ={'SCHEME': 'CronetTests'}))
# TODO(jtattermusch): Create bazel target for the test and remove the test from here.
out.append(
self.config.job_spec(['src/objective-c/tests/run_one_test.sh'],
Expand Down

0 comments on commit 96d2763

Please sign in to comment.