aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/core
diff options
context:
space:
mode:
authorGravatar Bill Feng <yfen@google.com>2018-11-26 10:15:47 -0800
committerGravatar Bill Feng <yfen@google.com>2018-11-26 10:15:47 -0800
commit5810b53df3e4ef338f610a71d4a8443f665a2bc6 (patch)
tree042d29b30e427615928c6fb3e4118112ea626276 /test/core
parent70f9992d77e67f90234b079eabaa33210d866c87 (diff)
parent5ee0cdc4222a137024598579107f51767062efc2 (diff)
merge conflict fix
Diffstat (limited to 'test/core')
-rw-r--r--test/core/end2end/fuzzers/hpack.dictionary1
-rw-r--r--test/core/gprpp/ref_counted_test.cc47
-rw-r--r--test/core/iomgr/buffer_list_test.cc4
-rw-r--r--test/core/transport/chttp2/BUILD16
-rw-r--r--test/core/transport/chttp2/context_list_test.cc98
-rw-r--r--test/core/util/mock_endpoint.cc25
-rw-r--r--test/core/util/passthru_endpoint.cc3
-rw-r--r--test/core/util/trickle_endpoint.cc5
8 files changed, 183 insertions, 16 deletions
diff --git a/test/core/end2end/fuzzers/hpack.dictionary b/test/core/end2end/fuzzers/hpack.dictionary
index a79fe5ad95..0469421c97 100644
--- a/test/core/end2end/fuzzers/hpack.dictionary
+++ b/test/core/end2end/fuzzers/hpack.dictionary
@@ -35,6 +35,7 @@
"\x1Fgrpc.max_response_message_bytes"
"$/grpc.lb.v1.LoadBalancer/BalanceLoad"
"\x1C/grpc.health.v1.Health/Watch"
+"P/envoy.service.discovery.v2.AggregatedDiscoveryService/StreamAggregatedResources"
"\x07deflate"
"\x04gzip"
"\x0Bstream/gzip"
diff --git a/test/core/gprpp/ref_counted_test.cc b/test/core/gprpp/ref_counted_test.cc
index f85a2e4675..62a3ea4d53 100644
--- a/test/core/gprpp/ref_counted_test.cc
+++ b/test/core/gprpp/ref_counted_test.cc
@@ -29,7 +29,10 @@ namespace {
class Foo : public RefCounted<Foo> {
public:
- Foo() {}
+ Foo() {
+ static_assert(std::has_virtual_destructor<Foo>::value,
+ "PolymorphicRefCount doesn't have a virtual dtor");
+ }
};
TEST(RefCounted, Basic) {
@@ -45,6 +48,28 @@ TEST(RefCounted, ExtraRef) {
foo->Unref();
}
+class FooNonPolymorphic
+ : public RefCounted<FooNonPolymorphic, NonPolymorphicRefCount> {
+ public:
+ FooNonPolymorphic() {
+ static_assert(!std::has_virtual_destructor<FooNonPolymorphic>::value,
+ "NonPolymorphicRefCount has a virtual dtor");
+ }
+};
+
+TEST(RefCountedNonPolymorphic, Basic) {
+ FooNonPolymorphic* foo = New<FooNonPolymorphic>();
+ foo->Unref();
+}
+
+TEST(RefCountedNonPolymorphic, ExtraRef) {
+ FooNonPolymorphic* foo = New<FooNonPolymorphic>();
+ RefCountedPtr<FooNonPolymorphic> foop = foo->Ref();
+ foop.release();
+ foo->Unref();
+ foo->Unref();
+}
+
// Note: We use DebugOnlyTraceFlag instead of TraceFlag to ensure that
// things build properly in both debug and non-debug cases.
DebugOnlyTraceFlag foo_tracer(true, "foo");
@@ -66,6 +91,26 @@ TEST(RefCountedWithTracing, Basic) {
foo->Unref(DEBUG_LOCATION, "original_ref");
}
+class FooNonPolymorphicWithTracing
+ : public RefCountedWithTracing<FooNonPolymorphicWithTracing,
+ NonPolymorphicRefCount> {
+ public:
+ FooNonPolymorphicWithTracing() : RefCountedWithTracing(&foo_tracer) {}
+};
+
+TEST(RefCountedNonPolymorphicWithTracing, Basic) {
+ FooNonPolymorphicWithTracing* foo = New<FooNonPolymorphicWithTracing>();
+ RefCountedPtr<FooNonPolymorphicWithTracing> foop =
+ foo->Ref(DEBUG_LOCATION, "extra_ref");
+ foop.release();
+ foo->Unref(DEBUG_LOCATION, "extra_ref");
+ // Can use the no-argument methods, too.
+ foop = foo->Ref();
+ foop.release();
+ foo->Unref();
+ foo->Unref(DEBUG_LOCATION, "original_ref");
+}
+
} // namespace
} // namespace testing
} // namespace grpc_core
diff --git a/test/core/iomgr/buffer_list_test.cc b/test/core/iomgr/buffer_list_test.cc
index c7f30fa092..e104e8e91a 100644
--- a/test/core/iomgr/buffer_list_test.cc
+++ b/test/core/iomgr/buffer_list_test.cc
@@ -50,7 +50,7 @@ static void TestShutdownFlushesList() {
grpc_core::TracedBuffer::AddNewEntry(
&list, i, static_cast<void*>(&verifier_called[i]));
}
- grpc_core::TracedBuffer::Shutdown(&list, GRPC_ERROR_NONE);
+ grpc_core::TracedBuffer::Shutdown(&list, nullptr, GRPC_ERROR_NONE);
GPR_ASSERT(list == nullptr);
for (auto i = 0; i < NUM_ELEM; i++) {
GPR_ASSERT(gpr_atm_acq_load(&verifier_called[i]) ==
@@ -88,7 +88,7 @@ static void TestVerifierCalledOnAck() {
grpc_core::TracedBuffer::ProcessTimestamp(&list, &serr, &tss);
GPR_ASSERT(gpr_atm_acq_load(&verifier_called) == static_cast<gpr_atm>(1));
GPR_ASSERT(list == nullptr);
- grpc_core::TracedBuffer::Shutdown(&list, GRPC_ERROR_NONE);
+ grpc_core::TracedBuffer::Shutdown(&list, nullptr, GRPC_ERROR_NONE);
}
static void TestTcpBufferList() {
diff --git a/test/core/transport/chttp2/BUILD b/test/core/transport/chttp2/BUILD
index 6eff716b01..33437373e4 100644
--- a/test/core/transport/chttp2/BUILD
+++ b/test/core/transport/chttp2/BUILD
@@ -67,6 +67,22 @@ grpc_cc_test(
)
grpc_cc_test(
+ name = "context_list_test",
+ srcs = ["context_list_test.cc"],
+ external_deps = [
+ "gtest",
+ ],
+ language = "C++",
+ deps = [
+ "//:gpr",
+ "//:grpc",
+ "//test/core/util:gpr_test_util",
+ "//test/core/util:grpc_test_util",
+ ],
+)
+
+
+grpc_cc_test(
name = "hpack_encoder_test",
srcs = ["hpack_encoder_test.cc"],
language = "C++",
diff --git a/test/core/transport/chttp2/context_list_test.cc b/test/core/transport/chttp2/context_list_test.cc
new file mode 100644
index 0000000000..e2100899d3
--- /dev/null
+++ b/test/core/transport/chttp2/context_list_test.cc
@@ -0,0 +1,98 @@
+/*
+ *
+ * Copyright 2018 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.
+ *
+ */
+
+#include "src/core/lib/iomgr/port.h"
+
+#include <gtest/gtest.h>
+#include <new>
+#include <vector>
+
+#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
+#include "src/core/ext/transport/chttp2/transport/context_list.h"
+#include "src/core/lib/transport/transport.h"
+#include "test/core/util/mock_endpoint.h"
+#include "test/core/util/test_config.h"
+
+#include <grpc/grpc.h>
+
+namespace grpc_core {
+namespace testing {
+namespace {
+void TestExecuteFlushesListVerifier(void* arg, grpc_core::Timestamps* ts) {
+ GPR_ASSERT(arg != nullptr);
+ gpr_atm* done = reinterpret_cast<gpr_atm*>(arg);
+ gpr_atm_rel_store(done, static_cast<gpr_atm>(1));
+}
+
+void discard_write(grpc_slice slice) {}
+
+/** Tests that all ContextList elements in the list are flushed out on
+ * execute.
+ * Also tests that arg is passed correctly.
+ */
+TEST(ContextList, ExecuteFlushesList) {
+ grpc_core::ContextList* list = nullptr;
+ grpc_http2_set_write_timestamps_callback(TestExecuteFlushesListVerifier);
+ const int kNumElems = 5;
+ grpc_core::ExecCtx exec_ctx;
+ grpc_stream_refcount ref;
+ GRPC_STREAM_REF_INIT(&ref, 1, nullptr, nullptr, "dummy ref");
+ grpc_resource_quota* resource_quota =
+ grpc_resource_quota_create("context_list_test");
+ grpc_endpoint* mock_endpoint =
+ grpc_mock_endpoint_create(discard_write, resource_quota);
+ grpc_transport* t =
+ grpc_create_chttp2_transport(nullptr, mock_endpoint, true);
+ std::vector<grpc_chttp2_stream*> s;
+ s.reserve(kNumElems);
+ gpr_atm verifier_called[kNumElems];
+ for (auto i = 0; i < kNumElems; i++) {
+ s.push_back(static_cast<grpc_chttp2_stream*>(
+ gpr_malloc(grpc_transport_stream_size(t))));
+ grpc_transport_init_stream(reinterpret_cast<grpc_transport*>(t),
+ reinterpret_cast<grpc_stream*>(s[i]), &ref,
+ nullptr, nullptr);
+ s[i]->context = &verifier_called[i];
+ gpr_atm_rel_store(&verifier_called[i], static_cast<gpr_atm>(0));
+ grpc_core::ContextList::Append(&list, s[i]);
+ }
+ grpc_core::Timestamps ts;
+ grpc_core::ContextList::Execute(list, &ts, GRPC_ERROR_NONE);
+ for (auto i = 0; i < kNumElems; i++) {
+ GPR_ASSERT(gpr_atm_acq_load(&verifier_called[i]) ==
+ static_cast<gpr_atm>(1));
+ grpc_transport_destroy_stream(reinterpret_cast<grpc_transport*>(t),
+ reinterpret_cast<grpc_stream*>(s[i]),
+ nullptr);
+ exec_ctx.Flush();
+ gpr_free(s[i]);
+ }
+ grpc_transport_destroy(t);
+ grpc_resource_quota_unref(resource_quota);
+ exec_ctx.Flush();
+}
+} // namespace
+} // namespace testing
+} // namespace grpc_core
+
+int main(int argc, char** argv) {
+ grpc_test_init(argc, argv);
+ grpc_init();
+ ::testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+}
diff --git a/test/core/util/mock_endpoint.cc b/test/core/util/mock_endpoint.cc
index ef6fd62b51..e5867cd526 100644
--- a/test/core/util/mock_endpoint.cc
+++ b/test/core/util/mock_endpoint.cc
@@ -103,18 +103,19 @@ static grpc_resource_user* me_get_resource_user(grpc_endpoint* ep) {
static int me_get_fd(grpc_endpoint* ep) { return -1; }
-static const grpc_endpoint_vtable vtable = {
- me_read,
- me_write,
- me_add_to_pollset,
- me_add_to_pollset_set,
- me_delete_from_pollset_set,
- me_shutdown,
- me_destroy,
- me_get_resource_user,
- me_get_peer,
- me_get_fd,
-};
+static bool me_can_track_err(grpc_endpoint* ep) { return false; }
+
+static const grpc_endpoint_vtable vtable = {me_read,
+ me_write,
+ me_add_to_pollset,
+ me_add_to_pollset_set,
+ me_delete_from_pollset_set,
+ me_shutdown,
+ me_destroy,
+ me_get_resource_user,
+ me_get_peer,
+ me_get_fd,
+ me_can_track_err};
grpc_endpoint* grpc_mock_endpoint_create(void (*on_write)(grpc_slice slice),
grpc_resource_quota* resource_quota) {
diff --git a/test/core/util/passthru_endpoint.cc b/test/core/util/passthru_endpoint.cc
index 3cc8ad6fe1..51b6de4695 100644
--- a/test/core/util/passthru_endpoint.cc
+++ b/test/core/util/passthru_endpoint.cc
@@ -155,6 +155,8 @@ static char* me_get_peer(grpc_endpoint* ep) {
static int me_get_fd(grpc_endpoint* ep) { return -1; }
+static bool me_can_track_err(grpc_endpoint* ep) { return false; }
+
static grpc_resource_user* me_get_resource_user(grpc_endpoint* ep) {
half* m = reinterpret_cast<half*>(ep);
return m->resource_user;
@@ -171,6 +173,7 @@ static const grpc_endpoint_vtable vtable = {
me_get_resource_user,
me_get_peer,
me_get_fd,
+ me_can_track_err,
};
static void half_init(half* m, passthru_endpoint* parent,
diff --git a/test/core/util/trickle_endpoint.cc b/test/core/util/trickle_endpoint.cc
index 62ed72a629..b0da735e57 100644
--- a/test/core/util/trickle_endpoint.cc
+++ b/test/core/util/trickle_endpoint.cc
@@ -131,6 +131,8 @@ static int te_get_fd(grpc_endpoint* ep) {
return grpc_endpoint_get_fd(te->wrapped);
}
+static bool te_can_track_err(grpc_endpoint* ep) { return false; }
+
static void te_finish_write(void* arg, grpc_error* error) {
trickle_endpoint* te = static_cast<trickle_endpoint*>(arg);
gpr_mu_lock(&te->mu);
@@ -148,7 +150,8 @@ static const grpc_endpoint_vtable vtable = {te_read,
te_destroy,
te_get_resource_user,
te_get_peer,
- te_get_fd};
+ te_get_fd,
+ te_can_track_err};
grpc_endpoint* grpc_trickle_endpoint_create(grpc_endpoint* wrap,
double bytes_per_second) {