Added Bazel BUILD for tests/

A few test failures to resolve
pull/19855/head
Tony Lu 5 years ago
parent 9e9f47a090
commit 8171981592
  1. 40
      src/objective-c/BUILD
  2. 1
      src/objective-c/GRPCClient/private/GRPCOpBatchLog.h
  3. 174
      src/objective-c/grpc_objc_internal_library.bzl
  4. 202
      src/objective-c/tests/BUILD
  5. 6
      src/objective-c/tests/InteropTests/InteropTests.h
  6. 8
      src/objective-c/tests/InteropTests/InteropTests.m
  7. 3
      src/objective-c/tests/InteropTests/InteropTestsMultipleChannels.m
  8. 6
      src/objective-c/tests/MacTests/StressTests.h
  9. 8
      src/objective-c/tests/MacTests/StressTests.m

@ -87,10 +87,48 @@ grpc_objc_library(
# Different from Cocoapods, do not import as if @com_google_protobuf//:protobuf_objc is a framework,
# use the real paths of @com_google_protobuf//:protobuf_objc instead
defines = ["GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS=0"],
includes = ["src/objective-c"],
deps = [
":grpc_objc_client",
":rx_library",
"@com_google_protobuf//:protobuf_objc",
],
)
grpc_objc_library(
name = "grpc_objc_client_internal_testing",
srcs = glob(
[
"GRPCClient/*.m",
"GRPCClient/private/*.m",
"GRPCClient/internal_testing/*.m",
"ProtoRPC/*.m",
],
exclude = ["GRPCClient/GRPCCall+GID.m"],
),
hdrs = glob(
[
"GRPCClient/*.h",
"GRPCClient/internal/*.h",
"GRPCClient/internal_testing/*.h",
"ProtoRPC/*.h",
],
exclude = ["GRPCClient/GRPCCall+GID.h"],
),
includes = ["."],
data = ["//:gRPCCertificates"],
defines = [
"GRPC_TEST_OBJC=1",
"GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS=0",
],
textual_hdrs = glob(
[
"GRPCClient/private/*.h",
],
),
deps = [
":rx_library",
"//:grpc_objc",
"@com_google_protobuf//:protobuf_objc",
],
visibility = ["//visibility:public"],
)

@ -17,6 +17,7 @@
*/
#ifdef GRPC_TEST_OBJC
#import <Foundation/Foundation.h>
/**
* Logs the op batches of a client. Used for testing.

@ -0,0 +1,174 @@
# Copyright 2019 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.
#
# This is for the gRPC build system. This isn't intended to be used outsite of
# the BUILD file for gRPC. It contains the mapping for the template system we
# use to generate other platform's build system files.
#
# Please consider that there should be a high bar for additions and changes to
# this file.
# Each rule listed must be re-written for Google's internal build system, and
# each change must be ported from one to the other.
#
load(
"//bazel:generate_objc.bzl",
"generate_objc",
"generate_objc_hdrs",
"generate_objc_srcs",
"generate_objc_non_arc_srcs"
)
load("//bazel:protobuf.bzl", "well_known_proto_libs")
def grpc_objc_testing_library(
name,
srcs = [],
hdrs = [],
textual_hdrs = [],
data = [],
deps = [],
defines = [],
includes = []):
"""objc_library for testing, only works in //src/objective-c/tests
Args:
name: name of target
hdrs: public headers
srcs: all source files (.m)
textual_hdrs: private headers
data: any other bundle resources
defines: preprocessors
includes: added to search path, always [the path to objc directory]
deps: dependencies
"""
additional_deps = [
":RemoteTest",
"//src/objective-c:grpc_objc_client_internal_testing",
]
if not name == "TestConfigs":
additional_deps += [":TestConfigs"]
native.objc_library(
name = name,
hdrs = hdrs,
srcs = srcs,
textual_hdrs = textual_hdrs,
data = data,
defines = defines,
includes = includes,
deps = deps + additional_deps,
)
def local_objc_grpc_library(name, deps, srcs = [], use_well_known_protos = False, **kwargs):
"""!!For local targets within the gRPC repository only!! Will not work outside of the repo
"""
objc_grpc_library_name = "_" + name + "_objc_grpc_library"
generate_objc(
name = objc_grpc_library_name,
srcs = srcs,
deps = deps,
use_well_known_protos = use_well_known_protos,
**kwargs
)
generate_objc_hdrs(
name = objc_grpc_library_name + "_hdrs",
src = ":" + objc_grpc_library_name,
)
generate_objc_non_arc_srcs(
name = objc_grpc_library_name + "_non_arc_srcs",
src = ":" + objc_grpc_library_name,
)
arc_srcs = None
if len(srcs) > 0:
generate_objc_srcs(
name = objc_grpc_library_name + "_srcs",
src = ":" + objc_grpc_library_name,
)
arc_srcs = [":" + objc_grpc_library_name + "_srcs"]
native.objc_library(
name = name,
hdrs = [":" + objc_grpc_library_name + "_hdrs"],
non_arc_srcs = [":" + objc_grpc_library_name + "_non_arc_srcs"],
srcs = arc_srcs,
defines = [
"GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS=0",
"GPB_GRPC_FORWARD_DECLARE_MESSAGE_PROTO=0",
],
includes = [
"_generated_protos",
"src/objective-c",
],
deps = [
"//src/objective-c:proto_objc_rpc",
"@com_google_protobuf//:protobuf_objc",
],
)
def testing_objc_grpc_library(name, deps, srcs = [], use_well_known_protos = False, **kwargs):
"""!!For testing within the gRPC repository only!! Will not work outside of the repo
"""
objc_grpc_library_name = "_" + name + "_objc_grpc_library"
generate_objc(
name = objc_grpc_library_name,
srcs = srcs,
deps = deps,
use_well_known_protos = use_well_known_protos,
**kwargs
)
generate_objc_hdrs(
name = objc_grpc_library_name + "_hdrs",
src = ":" + objc_grpc_library_name,
)
generate_objc_non_arc_srcs(
name = objc_grpc_library_name + "_non_arc_srcs",
src = ":" + objc_grpc_library_name,
)
arc_srcs = None
if len(srcs) > 0:
generate_objc_srcs(
name = objc_grpc_library_name + "_srcs",
src = ":" + objc_grpc_library_name,
)
arc_srcs = [":" + objc_grpc_library_name + "_srcs"]
native.objc_library(
name = name,
hdrs = [":" + objc_grpc_library_name + "_hdrs"],
non_arc_srcs = [":" + objc_grpc_library_name + "_non_arc_srcs"],
srcs = arc_srcs,
defines = [
"GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS=0",
"GPB_GRPC_FORWARD_DECLARE_MESSAGE_PROTO=0",
],
includes = [
"_generated_protos",
"src/objective-c",
],
deps = [
"//src/objective-c:grpc_objc_client_internal_testing",
"@com_google_protobuf//:protobuf_objc",
],
)

@ -0,0 +1,202 @@
# gRPC Bazel BUILD file.
#
# Copyright 2019 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.
licenses(["notice"]) # Apache v2
package(default_visibility = ["//visibility:private"])
load(
"//src/objective-c:grpc_objc_internal_library.bzl",
"grpc_objc_testing_library",
"testing_objc_grpc_library"
)
load("@build_bazel_rules_apple//apple:resources.bzl", "apple_resource_bundle")
load("@build_bazel_rules_apple//apple:ios.bzl", "ios_unit_test")
load("@build_bazel_rules_apple//apple:macos.bzl", "macos_unit_test")
load("@build_bazel_rules_apple//apple:tvos.bzl", "tvos_unit_test")
exports_files(["LICENSE"])
proto_library(
name = "messages_proto",
srcs = ["RemoteTestClient/messages.proto"],
)
proto_library(
name = "test_proto",
srcs = ["RemoteTestClient/test.proto"],
deps = [":messages_proto"],
)
testing_objc_grpc_library(
name = "RemoteTest",
srcs = ["RemoteTestClient/test.proto"],
use_well_known_protos = True,
deps = [":test_proto"],
)
apple_resource_bundle(
name = "TestCertificates",
resources = ["TestCertificates.bundle/test-certificates.pem"],
)
# TestConfigs is added to each grpc_objc_testing_library's deps
grpc_objc_testing_library(
name = "TestConfigs",
hdrs = ["version.h"],
data = [":TestCertificates"],
defines = [
"HOST_PORT_LOCALSSL=localhost:5051",
"HOST_PORT_LOCAL=localhost:5050",
"HOST_PORT_REMOTE=grpc-test.sandbox.googleapis.com",
],
)
grpc_objc_testing_library(
name = "CronetConfig",
srcs = ["ConfigureCronet.m"],
hdrs = ["ConfigureCronet.h"],
)
grpc_objc_testing_library(
name = "InteropTests-lib",
hdrs = ["InteropTests/InteropTests.h"],
srcs = ["InteropTests/InteropTests.m"],
deps = [
":InteropTestsBlockCallbacks-lib",
":CronetConfig",
],
)
grpc_objc_testing_library(
name = "InteropTestsRemote-lib",
srcs = ["InteropTests/InteropTestsRemote.m"],
deps = [":InteropTests-lib"],
)
grpc_objc_testing_library(
name = "InteropTestsBlockCallbacks-lib",
hdrs = ["InteropTests/InteropTestsBlockCallbacks.h"],
srcs = ["InteropTests/InteropTestsBlockCallbacks.m"],
)
grpc_objc_testing_library(
name = "InteropTestsLocalSSL-lib",
srcs = ["InteropTests/InteropTestsLocalSSL.m"],
deps = [":InteropTests-lib"],
)
grpc_objc_testing_library(
name = "InteropTestsLocalCleartext-lib",
srcs = ["InteropTests/InteropTestsLocalCleartext.m"],
deps = [":InteropTests-lib"],
)
grpc_objc_testing_library(
name = "InteropTestsMultipleChannels-lib",
srcs = ["InteropTests/InteropTestsMultipleChannels.m"],
deps = [":InteropTests-lib"],
)
grpc_objc_testing_library(
name = "RxLibraryUnitTests-lib",
srcs = ["UnitTests/RxLibraryUnitTests.m"],
)
grpc_objc_testing_library(
name = "GRPCClientTests-lib",
srcs = ["UnitTests/GRPCClientTests.m"],
)
grpc_objc_testing_library(
name = "APIv2Tests-lib",
srcs = ["UnitTests/APIv2Tests.m"],
)
grpc_objc_testing_library(
name = "ChannelPoolTest-lib",
srcs = ["UnitTests/ChannelPoolTest.m"],
)
grpc_objc_testing_library(
name = "ChannelTests-lib",
srcs = ["UnitTests/ChannelTests.m"],
)
grpc_objc_testing_library(
name = "NSErrorUnitTests-lib",
srcs = ["UnitTests/NSErrorUnitTests.m"],
)
grpc_objc_testing_library(
name = "MacStressTests-lib",
srcs = glob([
"MacTests/*.m",
]),
hdrs = ["MacTests/StressTests.h"],
)
ios_unit_test(
name = "UnitTests",
minimum_os_version = "8.0",
deps = [
":RxLibraryUnitTests-lib",
":GRPCClientTests-lib",
":APIv2Tests-lib",
":ChannelPoolTest-lib",
":ChannelTests-lib",
":NSErrorUnitTests-lib",
]
)
ios_unit_test(
name = "InteropTests",
minimum_os_version = "8.0",
deps = [
":InteropTestsRemote-lib",
":InteropTestsLocalSSL-lib",
":InteropTestsLocalCleartext-lib",
# ":InteropTestsMultipleChannels-lib", #??????? Cronet must be used?
],
)
macos_unit_test(
name = "MacTests",
minimum_os_version = "10.9",
deps = [
":APIv2Tests-lib",
":RxLibraryUnitTests-lib",
":NSErrorUnitTests-lib",
":InteropTestsRemote-lib",
":InteropTestsLocalSSL-lib",
":InteropTestsLocalCleartext-lib",
":MacStressTests-lib",
]
)
# cares does not support tvOS CPU architecture with Bazel yet
tvos_unit_test(
name = "TvTests",
minimum_os_version = "10.0",
deps = [
":APIv2Tests-lib",
":RxLibraryUnitTests-lib",
":NSErrorUnitTests-lib",
":InteropTestsRemote-lib",
":InteropTestsLocalSSL-lib",
":InteropTestsLocalCleartext-lib",
]
)

@ -27,6 +27,12 @@
* This is an abstract class that needs to be subclassed. See |+host|.
*/
@interface InteropTests : XCTestCase
/**
* The test suite to run, checking if the current XCTestCase instance is the base class.
* If so, run no tests (disabled). Otherwise, proceed to normal execution.
*/
@property(class, readonly) XCTestSuite *defaultTestSuite;
/**
* Host to send the RPCs to. The base implementation returns nil, which would make all tests to
* fail.

@ -406,6 +406,14 @@ static dispatch_once_t initGlobalInterceptorFactory;
RMTTestService *_service;
}
+ (XCTestSuite *)defaultTestSuite {
if (self == [InteropTests class]) {
return [XCTestSuite testSuiteWithName:@"InteropTestsEmptySuite"];
} else {
return super.defaultTestSuite;
}
}
+ (NSString *)host {
return nil;
}

@ -86,8 +86,9 @@ dispatch_once_t initCronet;
self.continueAfterFailure = NO;
_remoteService = [RMTTestService serviceWithHost:kRemoteSSLHost callOptions:nil];
#ifdef GRPC_COMPILE_WITH_CRONET
configureCronet();
#endif
// Default stack with remote host
GRPCMutableCallOptions *options = [[GRPCMutableCallOptions alloc] init];

@ -21,6 +21,12 @@
#import <GRPCClient/GRPCCallOptions.h>
@interface StressTests : XCTestCase
/**
* The test suite to run, checking if the current XCTestCase instance is the base class.
* If so, run no tests (disabled). Otherwise, proceed to normal execution.
*/
@property(class, readonly) XCTestSuite *defaultTestSuite;
/**
* Host to send the RPCs to. The base implementation returns nil, which would make all tests to
* fail.

@ -89,6 +89,14 @@ extern const char *kCFStreamVarName;
RMTTestService *_service;
}
+ (XCTestSuite *)defaultTestSuite {
if (self == [StressTests class]) {
return [XCTestSuite testSuiteWithName:@"StressTestsEmptySuite"];
} else {
return super.defaultTestSuite;
}
}
+ (NSString *)host {
return nil;
}

Loading…
Cancel
Save