From 9c5bde5e4e2cc0c81c3c6411b3aa922d3e995a54 Mon Sep 17 00:00:00 2001 From: Yash Tibrewal Date: Sun, 26 Aug 2018 03:50:39 -0700 Subject: More commits --- test/core/transport/chttp2/BUILD | 13 +++++ test/core/transport/chttp2/context_list_test.cc | 64 +++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 test/core/transport/chttp2/context_list_test.cc (limited to 'test/core/transport') diff --git a/test/core/transport/chttp2/BUILD b/test/core/transport/chttp2/BUILD index 6eff716b01..c7bfa1ec09 100644 --- a/test/core/transport/chttp2/BUILD +++ b/test/core/transport/chttp2/BUILD @@ -66,6 +66,19 @@ grpc_cc_test( ], ) +grpc_cc_test( + name = "context_list_test", + srcs = ["context_list_test.cc"], + 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"], 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..1f7a38a107 --- /dev/null +++ b/test/core/transport/chttp2/context_list_test.cc @@ -0,0 +1,64 @@ +/* + * + * 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 "src/core/ext/transport/chttp2/transport/context_list.h" + +#include + +#include "test/core/util/test_config.h" + +static void TestExecuteFlushesListVerifier(void* arg, + grpc_core::Timestamps* ts) { + GPR_ASSERT(arg != nullptr); + gpr_atm* done = reinterpret_cast(arg); + gpr_atm_rel_store(done, static_cast(1)); +} + +/** Tests that all ContextList elements in the list are flushed out on + * execute. + * Also tests that arg is passed correctly. + */ +static void TestExecuteFlushesList() { + grpc_core::ContextList* list = nullptr; + grpc_http2_set_write_timestamps_callback(TestExecuteFlushesListVerifier); +#define NUM_ELEM 5 + grpc_chttp2_stream s[NUM_ELEM]; + gpr_atm verifier_called[NUM_ELEM]; + for (auto i = 0; i < NUM_ELEM; i++) { + s[i].context = &verifier_called[i]; + gpr_atm_rel_store(&verifier_called[i], static_cast(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 < NUM_ELEM; i++) { + GPR_ASSERT(gpr_atm_acq_load(&verifier_called[i]) == + static_cast(1)); + } +} + +static void TestContextList() { TestExecuteFlushesList(); } + +int main(int argc, char** argv) { + grpc_init(); + TestContextList(); + grpc_shutdown(); + return 0; +} -- cgit v1.2.3