split POC into real test

pull/13288/head
ncteisen 7 years ago
parent 8d224c1c28
commit 4d9c98b146
  1. 29
      CMakeLists.txt
  2. 36
      Makefile
  3. 10
      build.yaml
  4. 2
      src/core/ext/transport/chttp2/transport/chttp2_transport.cc
  5. 17
      src/core/ext/transport/chttp2/transport/internal.h
  6. 2
      src/core/lib/support/manual_constructor.h
  7. 97
      test/core/support/manual_constructor_test.cc
  8. 15
      tools/run_tests/generated/sources_and_headers.json
  9. 24
      tools/run_tests/generated/tests.json

@ -430,6 +430,7 @@ add_dependencies(buildtests_c gpr_env_test)
add_dependencies(buildtests_c gpr_histogram_test)
add_dependencies(buildtests_c gpr_host_port_test)
add_dependencies(buildtests_c gpr_log_test)
add_dependencies(buildtests_c gpr_manual_constructor_test)
add_dependencies(buildtests_c gpr_mpscq_test)
add_dependencies(buildtests_c gpr_spinlock_test)
add_dependencies(buildtests_c gpr_stack_lockfree_test)
@ -6390,6 +6391,34 @@ target_link_libraries(gpr_log_test
endif (gRPC_BUILD_TESTS)
if (gRPC_BUILD_TESTS)
add_executable(gpr_manual_constructor_test
test/core/support/manual_constructor_test.cc
)
target_include_directories(gpr_manual_constructor_test
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include
PRIVATE ${BORINGSSL_ROOT_DIR}/include
PRIVATE ${PROTOBUF_ROOT_DIR}/src
PRIVATE ${BENCHMARK_ROOT_DIR}/include
PRIVATE ${ZLIB_ROOT_DIR}
PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib
PRIVATE ${CARES_INCLUDE_DIR}
PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/cares/cares
PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/third_party/abseil-cpp
)
target_link_libraries(gpr_manual_constructor_test
${_gRPC_ALLTARGETS_LIBRARIES}
gpr_test_util
gpr
)
endif (gRPC_BUILD_TESTS)
if (gRPC_BUILD_TESTS)
add_executable(gpr_mpscq_test
test/core/support/mpscq_test.cc
)

@ -991,6 +991,7 @@ gpr_env_test: $(BINDIR)/$(CONFIG)/gpr_env_test
gpr_histogram_test: $(BINDIR)/$(CONFIG)/gpr_histogram_test
gpr_host_port_test: $(BINDIR)/$(CONFIG)/gpr_host_port_test
gpr_log_test: $(BINDIR)/$(CONFIG)/gpr_log_test
gpr_manual_constructor_test: $(BINDIR)/$(CONFIG)/gpr_manual_constructor_test
gpr_mpscq_test: $(BINDIR)/$(CONFIG)/gpr_mpscq_test
gpr_spinlock_test: $(BINDIR)/$(CONFIG)/gpr_spinlock_test
gpr_stack_lockfree_test: $(BINDIR)/$(CONFIG)/gpr_stack_lockfree_test
@ -1383,6 +1384,7 @@ buildtests_c: privatelibs_c \
$(BINDIR)/$(CONFIG)/gpr_histogram_test \
$(BINDIR)/$(CONFIG)/gpr_host_port_test \
$(BINDIR)/$(CONFIG)/gpr_log_test \
$(BINDIR)/$(CONFIG)/gpr_manual_constructor_test \
$(BINDIR)/$(CONFIG)/gpr_mpscq_test \
$(BINDIR)/$(CONFIG)/gpr_spinlock_test \
$(BINDIR)/$(CONFIG)/gpr_stack_lockfree_test \
@ -1827,6 +1829,8 @@ test_c: buildtests_c
$(Q) $(BINDIR)/$(CONFIG)/gpr_host_port_test || ( echo test gpr_host_port_test failed ; exit 1 )
$(E) "[RUN] Testing gpr_log_test"
$(Q) $(BINDIR)/$(CONFIG)/gpr_log_test || ( echo test gpr_log_test failed ; exit 1 )
$(E) "[RUN] Testing gpr_manual_constructor_test"
$(Q) $(BINDIR)/$(CONFIG)/gpr_manual_constructor_test || ( echo test gpr_manual_constructor_test failed ; exit 1 )
$(E) "[RUN] Testing gpr_mpscq_test"
$(Q) $(BINDIR)/$(CONFIG)/gpr_mpscq_test || ( echo test gpr_mpscq_test failed ; exit 1 )
$(E) "[RUN] Testing gpr_spinlock_test"
@ -10153,6 +10157,38 @@ endif
endif
GPR_MANUAL_CONSTRUCTOR_TEST_SRC = \
test/core/support/manual_constructor_test.cc \
GPR_MANUAL_CONSTRUCTOR_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(GPR_MANUAL_CONSTRUCTOR_TEST_SRC))))
ifeq ($(NO_SECURE),true)
# You can't build secure targets if you don't have OpenSSL.
$(BINDIR)/$(CONFIG)/gpr_manual_constructor_test: openssl_dep_error
else
$(BINDIR)/$(CONFIG)/gpr_manual_constructor_test: $(GPR_MANUAL_CONSTRUCTOR_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a
$(E) "[LD] Linking $@"
$(Q) mkdir -p `dirname $@`
$(Q) $(LD) $(LDFLAGS) $(GPR_MANUAL_CONSTRUCTOR_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBS) $(LDLIBS_SECURE) -o $(BINDIR)/$(CONFIG)/gpr_manual_constructor_test
endif
$(OBJDIR)/$(CONFIG)/test/core/support/manual_constructor_test.o: $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a
deps_gpr_manual_constructor_test: $(GPR_MANUAL_CONSTRUCTOR_TEST_OBJS:.o=.dep)
ifneq ($(NO_SECURE),true)
ifneq ($(NO_DEPS),true)
-include $(GPR_MANUAL_CONSTRUCTOR_TEST_OBJS:.o=.dep)
endif
endif
GPR_MPSCQ_TEST_SRC = \
test/core/support/mpscq_test.cc \

@ -2215,6 +2215,16 @@ targets:
- gpr_test_util
- gpr
uses_polling: false
- name: gpr_manual_constructor_test
cpu_cost: 3
build: test
language: c
src:
- test/core/support/manual_constructor_test.cc
deps:
- gpr_test_util
- gpr
uses_polling: false
- name: gpr_mpscq_test
cpu_cost: 30
build: test

@ -274,8 +274,6 @@ static void init_transport(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t,
GPR_ASSERT(strlen(GRPC_CHTTP2_CLIENT_CONNECT_STRING) ==
GRPC_CHTTP2_CLIENT_CONNECT_STRLEN);
t->abstract.Init<Derived>();
t->base.vtable = get_vtable();
t->ep = ep;
/* one ref is for destroy */

@ -38,7 +38,6 @@
#include "src/core/lib/iomgr/combiner.h"
#include "src/core/lib/iomgr/endpoint.h"
#include "src/core/lib/iomgr/timer.h"
#include "src/core/lib/support/abstract.h"
#include "src/core/lib/support/manual_constructor.h"
#include "src/core/lib/transport/connectivity_state.h"
#include "src/core/lib/transport/transport_impl.h"
@ -238,20 +237,6 @@ typedef enum {
GRPC_CHTTP2_KEEPALIVE_STATE_DISABLED,
} grpc_chttp2_keepalive_state;
class AbstractBase {
public:
AbstractBase() {}
virtual ~AbstractBase() { gpr_log(GPR_ERROR, "base dtor"); }
virtual void foo() { gpr_log(GPR_ERROR, "base"); }
GRPC_ABSTRACT_BASE_CLASS
};
class Derived : public AbstractBase {
public:
Derived() {}
virtual ~Derived() { gpr_log(GPR_ERROR, "derived dtor"); }
void foo() override { gpr_log(GPR_ERROR, "derived"); }
};
struct grpc_chttp2_transport {
grpc_transport base; /* must be first */
@ -259,8 +244,6 @@ struct grpc_chttp2_transport {
grpc_endpoint* ep;
char* peer_string;
grpc_core::PolymorphicManualConstructor<AbstractBase, Derived> abstract;
grpc_combiner* combiner;
/** write execution state of the transport */

@ -27,6 +27,8 @@
#include <type_traits>
#include <utility>
#include <grpc/support/log.h>
namespace grpc_core {
// this contains templated helpers needed to implement the ManualConstructors

@ -0,0 +1,97 @@
/*
*
* Copyright 2017 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.
*
*/
/* Test of gpr synchronization support. */
#include "src/core/lib/support/abstract.h"
#include "src/core/lib/support/manual_constructor.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/sync.h>
#include <grpc/support/thd.h>
#include <stdio.h>
#include <stdlib.h>
#include <cstring>
#include "test/core/util/test_config.h"
class A {
public:
A() {}
virtual ~A() {}
virtual const char* foo() { return "A_foo"; }
virtual const char* bar() { return "A_bar"; }
GRPC_ABSTRACT_BASE_CLASS
};
class B : public A {
public:
B() {}
~B() {}
const char* foo() override { return "B_foo"; }
char get_junk() { return junk[0]; }
private:
char junk[1000];
};
class C : public B {
public:
C() {}
~C() {}
virtual const char* bar() { return "C_bar"; }
char get_more_junk() { return more_junk[0]; }
private:
char more_junk[1000];
};
class D : public A {
public:
virtual const char* bar() { return "D_bar"; }
};
static void basic_test() {
grpc_core::PolymorphicManualConstructor<A, B> poly;
poly.Init<B>();
GPR_ASSERT(!strcmp(poly->foo(), "B_foo"));
GPR_ASSERT(!strcmp(poly->bar(), "A_bar"));
}
static void complex_test() {
grpc_core::PolymorphicManualConstructor<A, B, C, D> polyB;
polyB.Init<B>();
GPR_ASSERT(!strcmp(polyB->foo(), "B_foo"));
GPR_ASSERT(!strcmp(polyB->bar(), "A_bar"));
grpc_core::PolymorphicManualConstructor<A, B, C, D> polyC;
polyC.Init<C>();
GPR_ASSERT(!strcmp(polyC->foo(), "B_foo"));
GPR_ASSERT(!strcmp(polyC->bar(), "C_bar"));
grpc_core::PolymorphicManualConstructor<A, B, C, D> polyD;
polyD.Init<D>();
GPR_ASSERT(!strcmp(polyD->foo(), "A_foo"));
GPR_ASSERT(!strcmp(polyD->bar(), "D_bar"));
}
/* ------------------------------------------------- */
int main(int argc, char* argv[]) {
grpc_test_init(argc, argv);
basic_test();
complex_test();
return 0;
}

@ -748,6 +748,21 @@
"third_party": false,
"type": "target"
},
{
"deps": [
"gpr",
"gpr_test_util"
],
"headers": [],
"is_filegroup": false,
"language": "c",
"name": "gpr_manual_constructor_test",
"src": [
"test/core/support/manual_constructor_test.cc"
],
"third_party": false,
"type": "target"
},
{
"deps": [
"gpr",

@ -911,6 +911,30 @@
],
"uses_polling": false
},
{
"args": [],
"benchmark": false,
"ci_platforms": [
"linux",
"mac",
"posix",
"windows"
],
"cpu_cost": 3,
"exclude_configs": [],
"exclude_iomgrs": [],
"flaky": false,
"gtest": false,
"language": "c",
"name": "gpr_manual_constructor_test",
"platforms": [
"linux",
"mac",
"posix",
"windows"
],
"uses_polling": false
},
{
"args": [],
"benchmark": false,

Loading…
Cancel
Save