[cast_core] Add Cast Core gRPC stub\handler generator build.
This change introduces a Cast Core gRPC stub and handler generator tool and a build rule, cast_core_grpc_library in cast_core_grpc.gni, to automatically generate those files from protos. Bug: b:210127896 Test: unit tests Change-Id: I8dbfd06e85b2793ae0498ecbed28f6faade3aa53 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3387542 Reviewed-by: Ryan Keane <rwkeane@google.com> Reviewed-by: John Abd-El-Malek <jam@chromium.org> Commit-Queue: Vigen Issahhanjan <vigeni@google.com> Cr-Commit-Position: refs/heads/main@{#961699}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
56498537fc
commit
cfe41e619e
2
DEPS
2
DEPS
@ -1020,7 +1020,7 @@ deps = {
|
||||
},
|
||||
|
||||
'src/third_party/cast_core/public/src':
|
||||
Var('chromium_git') + '/cast_core/public' + '@' + '2c1308094df97d5fcc84d6c40405c6ecb807301b',
|
||||
Var('chromium_git') + '/cast_core/public' + '@' + '1c3981386ac760d99f38e25f8cc0ee6c68c47f4d',
|
||||
|
||||
'src/third_party/catapult':
|
||||
Var('chromium_git') + '/catapult.git' + '@' + Var('catapult_revision'),
|
||||
|
@ -3,27 +3,15 @@
|
||||
# found in the LICENSE file.
|
||||
|
||||
import("//chromecast/chromecast.gni")
|
||||
import("//third_party/grpc/grpc_library.gni")
|
||||
import("//third_party/cast_core/public/src/proto/proto.gni")
|
||||
|
||||
cast_source_set("calls") {
|
||||
cast_source_set("grpc") {
|
||||
sources = [
|
||||
"grpc_call.h",
|
||||
"grpc_client_reactor.h",
|
||||
"grpc_server_streaming_call.h",
|
||||
"grpc_stub.h",
|
||||
"grpc_unary_call.h",
|
||||
]
|
||||
|
||||
public_deps = [
|
||||
":grpc_call_options",
|
||||
":grpc_status_or",
|
||||
"//base",
|
||||
"//third_party/grpc:grpc++",
|
||||
]
|
||||
}
|
||||
|
||||
cast_source_set("handlers") {
|
||||
sources = [
|
||||
"cancellable_reactor.h",
|
||||
"grpc_handler.cc",
|
||||
"grpc_handler.h",
|
||||
@ -35,39 +23,16 @@ cast_source_set("handlers") {
|
||||
"server_reactor_tracker.cc",
|
||||
"server_reactor_tracker.h",
|
||||
"trackable_reactor.h",
|
||||
]
|
||||
|
||||
public_deps = [
|
||||
":grpc_call_options",
|
||||
":grpc_status_or",
|
||||
"//base",
|
||||
"//third_party/abseil-cpp:absl",
|
||||
"//third_party/grpc:grpc++",
|
||||
]
|
||||
}
|
||||
|
||||
cast_source_set("grpc_call_options") {
|
||||
sources = [
|
||||
"grpc_call_options.cc",
|
||||
"grpc_call_options.h",
|
||||
]
|
||||
|
||||
public_deps = [
|
||||
"//base",
|
||||
"//third_party/grpc:grpc++",
|
||||
]
|
||||
}
|
||||
|
||||
cast_source_set("grpc_status_or") {
|
||||
sources = [
|
||||
"grpc_status_or.cc",
|
||||
"grpc_status_or.h",
|
||||
]
|
||||
|
||||
public_deps = [
|
||||
"//base",
|
||||
"//third_party/abseil-cpp:absl",
|
||||
"//third_party/grpc:grpc++",
|
||||
"//third_party/abseil-cpp:absl",
|
||||
]
|
||||
}
|
||||
|
||||
@ -82,31 +47,19 @@ cast_source_set("status_matchers") {
|
||||
deps = [ "//testing/gmock" ]
|
||||
}
|
||||
|
||||
grpc_library("test_service_proto") {
|
||||
sources = [ "test_service.proto" ]
|
||||
cast_core_proto_library("test_service_messages_proto") {
|
||||
sources = [ "test_service_messages.proto" ]
|
||||
}
|
||||
|
||||
cast_source_set("test_service_handlers") {
|
||||
testonly = true
|
||||
|
||||
cast_core_grpc_library("test_service_proto") {
|
||||
sources = [
|
||||
"test_service_handlers.cc",
|
||||
"test_service_handlers.h",
|
||||
"test_service.proto",
|
||||
"test_service_extra.proto",
|
||||
]
|
||||
|
||||
deps = [
|
||||
":handlers",
|
||||
":test_service_proto",
|
||||
]
|
||||
}
|
||||
deps = [ ":test_service_messages_proto" ]
|
||||
|
||||
cast_source_set("test_service_stubs") {
|
||||
sources = [ "test_service_stubs.h" ]
|
||||
|
||||
deps = [
|
||||
":calls",
|
||||
":test_service_proto",
|
||||
]
|
||||
generate_castcore_stubs = true
|
||||
}
|
||||
|
||||
cast_source_set("unit_tests") {
|
||||
@ -119,12 +72,9 @@ cast_source_set("unit_tests") {
|
||||
]
|
||||
|
||||
deps = [
|
||||
":calls",
|
||||
":handlers",
|
||||
":grpc",
|
||||
":status_matchers",
|
||||
":test_service_handlers",
|
||||
":test_service_proto",
|
||||
":test_service_stubs",
|
||||
":test_service_proto_castcore",
|
||||
"//base",
|
||||
"//base/test:test_support",
|
||||
"//testing/gmock",
|
||||
|
@ -14,9 +14,7 @@
|
||||
#include "base/time/time.h"
|
||||
#include "chromecast/cast_core/grpc/grpc_server.h"
|
||||
#include "chromecast/cast_core/grpc/status_matchers.h"
|
||||
#include "chromecast/cast_core/grpc/test_service.grpc.pb.h"
|
||||
#include "chromecast/cast_core/grpc/test_service_handlers.h"
|
||||
#include "chromecast/cast_core/grpc/test_service_stubs.h"
|
||||
#include "chromecast/cast_core/grpc/test_service.castcore.pb.h"
|
||||
#include "testing/gmock/include/gmock/gmock.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
|
||||
|
@ -17,9 +17,14 @@
|
||||
#include "base/time/time.h"
|
||||
#include "chromecast/cast_core/grpc/grpc_server.h"
|
||||
#include "chromecast/cast_core/grpc/status_matchers.h"
|
||||
// Include all various protobuf headers generated by Cast Core rules.
|
||||
#include "chromecast/cast_core/grpc/test_service.castcore.pb.h"
|
||||
#include "chromecast/cast_core/grpc/test_service.grpc.pb.h"
|
||||
#include "chromecast/cast_core/grpc/test_service_handlers.h"
|
||||
#include "chromecast/cast_core/grpc/test_service_stubs.h"
|
||||
#include "chromecast/cast_core/grpc/test_service.pb.h"
|
||||
// Include all various protobuf headers generated by Cast Core rules.
|
||||
#include "chromecast/cast_core/grpc/test_service_extra.castcore.pb.h"
|
||||
#include "chromecast/cast_core/grpc/test_service_extra.grpc.pb.h"
|
||||
#include "chromecast/cast_core/grpc/test_service_extra.pb.h"
|
||||
#include "testing/gmock/include/gmock/gmock.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
|
||||
@ -117,10 +122,7 @@ TEST_F(GrpcUnaryTest, SyncUnaryCallCancelledIfServerIsStopped) {
|
||||
ASSERT_THAT(response, StatusIs(grpc::StatusCode::UNAVAILABLE));
|
||||
|
||||
// Need to wait for server to fully stop.
|
||||
{
|
||||
base::ScopedAllowBaseSyncPrimitivesForTesting allow_base_sync_primitives;
|
||||
ASSERT_TRUE(server_stopped_event.TimedWait(kEventTimeout));
|
||||
}
|
||||
ASSERT_TRUE(server_stopped_event.TimedWait(kEventTimeout));
|
||||
}
|
||||
|
||||
TEST_F(GrpcUnaryTest, AsyncUnaryCallSucceeds) {
|
||||
@ -221,6 +223,29 @@ TEST_F(GrpcUnaryTest, AsyncUnaryCallCancelledIfServerIsStopped) {
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(GrpcUnaryTest, SyncUnaryCallSucceedsExtra) {
|
||||
GrpcServer server;
|
||||
server.SetHandler<SimpleServiceExtraHandler::SimpleCall>(
|
||||
base::BindLambdaForTesting(
|
||||
[](TestExtraRequest request,
|
||||
SimpleServiceExtraHandler::SimpleCall::Reactor* reactor) {
|
||||
EXPECT_EQ(request.extra(), "test_extra");
|
||||
TestResponse response;
|
||||
response.set_bar("test_bar");
|
||||
reactor->Write(std::move(response));
|
||||
}));
|
||||
server.Start(endpoint_);
|
||||
|
||||
SimpleServiceExtraStub stub(endpoint_);
|
||||
auto call = stub.CreateCall<SimpleServiceExtraStub::SimpleCall>();
|
||||
call.request().set_extra("test_extra");
|
||||
auto response = std::move(call).Invoke();
|
||||
CU_ASSERT_OK(response);
|
||||
EXPECT_EQ(response->bar(), "test_bar");
|
||||
|
||||
server.StopForTesting(kServerStopTimeout);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace utils
|
||||
} // namespace cast
|
||||
|
@ -8,6 +8,8 @@ package cast.utils;
|
||||
|
||||
option optimize_for = LITE_RUNTIME;
|
||||
|
||||
import "chromecast/cast_core/grpc/test_service_messages.proto";
|
||||
|
||||
// An unary test service.
|
||||
service SimpleService {
|
||||
// Makes an unary test call.
|
||||
@ -20,12 +22,7 @@ service ServerStreamingService {
|
||||
rpc StreamingCall(TestRequest) returns (stream TestResponse);
|
||||
}
|
||||
|
||||
// Test request.
|
||||
message TestRequest {
|
||||
string foo = 1;
|
||||
}
|
||||
|
||||
// Test response.
|
||||
message TestResponse {
|
||||
string bar = 1;
|
||||
}
|
||||
// The request is added here to verify the build rules.
|
||||
message TestExtraRequest {
|
||||
string extra = 1;
|
||||
};
|
||||
|
18
chromecast/cast_core/grpc/test_service_extra.proto
Normal file
18
chromecast/cast_core/grpc/test_service_extra.proto
Normal file
@ -0,0 +1,18 @@
|
||||
// Copyright 2021 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
syntax = "proto3";
|
||||
|
||||
package cast.utils;
|
||||
|
||||
import "chromecast/cast_core/grpc/test_service.proto";
|
||||
import "chromecast/cast_core/grpc/test_service_messages.proto";
|
||||
|
||||
option optimize_for = LITE_RUNTIME;
|
||||
|
||||
// An unary test service.
|
||||
service SimpleServiceExtra {
|
||||
// Makes an unary test call.
|
||||
rpc SimpleCall(TestExtraRequest) returns (TestResponse);
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
// Copyright 2021 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "chromecast/cast_core/grpc/test_service_handlers.h"
|
||||
|
||||
namespace cast {
|
||||
namespace utils {
|
||||
|
||||
const char SimpleServiceHandler::kSimpleCall[] = "SimpleCall";
|
||||
|
||||
const char ServerStreamingServiceHandler::kStreamingCall[] = "StreamingCall";
|
||||
|
||||
} // namespace utils
|
||||
} // namespace cast
|
@ -1,40 +0,0 @@
|
||||
// Copyright 2021 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef CHROMECAST_CAST_CORE_GRPC_TEST_SERVICE_HANDLERS_H_
|
||||
#define CHROMECAST_CAST_CORE_GRPC_TEST_SERVICE_HANDLERS_H_
|
||||
|
||||
#include "chromecast/cast_core/grpc/grpc_server_streaming_handler.h"
|
||||
#include "chromecast/cast_core/grpc/grpc_unary_handler.h"
|
||||
#include "chromecast/cast_core/grpc/test_service.grpc.pb.h"
|
||||
#include "chromecast/cast_core/grpc/test_service.pb.h"
|
||||
|
||||
namespace cast {
|
||||
namespace utils {
|
||||
|
||||
class SimpleServiceHandler {
|
||||
private:
|
||||
static const char kSimpleCall[];
|
||||
|
||||
public:
|
||||
using SimpleCall = utils::
|
||||
GrpcUnaryHandler<SimpleService, TestRequest, TestResponse, kSimpleCall>;
|
||||
};
|
||||
|
||||
class ServerStreamingServiceHandler {
|
||||
private:
|
||||
static const char kStreamingCall[];
|
||||
|
||||
public:
|
||||
using StreamingCall =
|
||||
utils::GrpcServerStreamingHandler<ServerStreamingService,
|
||||
TestRequest,
|
||||
TestResponse,
|
||||
kStreamingCall>;
|
||||
};
|
||||
|
||||
} // namespace utils
|
||||
} // namespace cast
|
||||
|
||||
#endif // CHROMECAST_CAST_CORE_GRPC_TEST_SERVICE_HANDLERS_H_
|
19
chromecast/cast_core/grpc/test_service_messages.proto
Normal file
19
chromecast/cast_core/grpc/test_service_messages.proto
Normal file
@ -0,0 +1,19 @@
|
||||
// Copyright 2021 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
syntax = "proto3";
|
||||
|
||||
package cast.utils;
|
||||
|
||||
option optimize_for = LITE_RUNTIME;
|
||||
|
||||
// Test request.
|
||||
message TestRequest {
|
||||
string foo = 1;
|
||||
}
|
||||
|
||||
// Test response.
|
||||
message TestResponse {
|
||||
string bar = 1;
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
// Copyright 2021 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef CHROMECAST_CAST_CORE_GRPC_TEST_SERVICE_STUBS_H_
|
||||
#define CHROMECAST_CAST_CORE_GRPC_TEST_SERVICE_STUBS_H_
|
||||
|
||||
#include "chromecast/cast_core/grpc/grpc_server_streaming_call.h"
|
||||
#include "chromecast/cast_core/grpc/grpc_stub.h"
|
||||
#include "chromecast/cast_core/grpc/grpc_unary_call.h"
|
||||
#include "chromecast/cast_core/grpc/test_service.grpc.pb.h"
|
||||
#include "chromecast/cast_core/grpc/test_service.pb.h"
|
||||
|
||||
namespace cast {
|
||||
namespace utils {
|
||||
|
||||
class SimpleServiceStub final : public utils::GrpcStub<SimpleService> {
|
||||
public:
|
||||
using GrpcStub::GrpcStub;
|
||||
using GrpcStub::operator=;
|
||||
using GrpcStub::AsyncInterface;
|
||||
using GrpcStub::CreateCall;
|
||||
using GrpcStub::SyncInterface;
|
||||
|
||||
using SimpleCall = utils::GrpcUnaryCall<SimpleServiceStub,
|
||||
TestRequest,
|
||||
TestResponse,
|
||||
&AsyncInterface::SimpleCall,
|
||||
&SyncInterface::SimpleCall>;
|
||||
};
|
||||
|
||||
class ServerStreamingServiceStub
|
||||
: public utils::GrpcStub<ServerStreamingService> {
|
||||
public:
|
||||
using GrpcStub::GrpcStub;
|
||||
using GrpcStub::operator=;
|
||||
using GrpcStub::AsyncInterface;
|
||||
using GrpcStub::CreateCall;
|
||||
using GrpcStub::SyncInterface;
|
||||
|
||||
using StreamingCall =
|
||||
utils::GrpcServerStreamingCall<ServerStreamingServiceStub,
|
||||
TestRequest,
|
||||
TestResponse,
|
||||
&AsyncInterface::StreamingCall>;
|
||||
};
|
||||
|
||||
} // namespace utils
|
||||
} // namespace cast
|
||||
|
||||
#endif // CHROMECAST_CAST_CORE_GRPC_TEST_SERVICE_STUBS_H_
|
3
third_party/protobuf/BUILD.gn
vendored
3
third_party/protobuf/BUILD.gn
vendored
@ -265,6 +265,9 @@ static_library("protobuf_full") {
|
||||
"//third_party/dawn/third_party/tint/fuzzers/tint_ast_fuzzer:tint_ast_fuzzer",
|
||||
"//third_party/dawn/third_party/tint/fuzzers/tint_ast_fuzzer:tint_ast_fuzzer_proto",
|
||||
"//third_party/dawn/third_party/tint/fuzzers/tint_spirv_tools_fuzzer:tint_spirv_tools_fuzzer",
|
||||
|
||||
# The Cast Core gRPC generator tool.
|
||||
"//third_party/cast_core/public/src/build/chromium:cast_core_grpc_generator",
|
||||
]
|
||||
|
||||
sources = protobuf_lite_sources + [
|
||||
|
Reference in New Issue
Block a user