From e1523e95c102a3eec48fef34350bca206c0a6546 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Tue, 14 Mar 2017 21:10:42 -0700 Subject: Track calls to gpr_now() --- test/cpp/microbenchmarks/bm_call_create.cc | 2 ++ test/cpp/microbenchmarks/helpers.cc | 4 ++++ test/cpp/microbenchmarks/helpers.h | 3 +++ 3 files changed, 9 insertions(+) (limited to 'test') diff --git a/test/cpp/microbenchmarks/bm_call_create.cc b/test/cpp/microbenchmarks/bm_call_create.cc index 014e2b96b5..146f8e6bad 100644 --- a/test/cpp/microbenchmarks/bm_call_create.cc +++ b/test/cpp/microbenchmarks/bm_call_create.cc @@ -66,10 +66,12 @@ auto &force_library_initialization = Library::get(); void BM_Zalloc(benchmark::State &state) { // speed of light for call creation is zalloc, so benchmark a few interesting // sizes + TrackCounters track_counters; size_t sz = state.range(0); while (state.KeepRunning()) { gpr_free(gpr_zalloc(sz)); } + track_counters.Finish(state); } BENCHMARK(BM_Zalloc) ->Arg(64) diff --git a/test/cpp/microbenchmarks/helpers.cc b/test/cpp/microbenchmarks/helpers.cc index d277c5984c..6550742453 100644 --- a/test/cpp/microbenchmarks/helpers.cc +++ b/test/cpp/microbenchmarks/helpers.cc @@ -57,6 +57,10 @@ void TrackCounters::AddToLabel(std::ostream &out, benchmark::State &state) { << ((double)(gpr_atm_no_barrier_load(&gpr_counter_atm_add) - atm_add_at_start_) / (double)state.iterations()) + << " nows/iter:" + << ((double)(gpr_atm_no_barrier_load(&gpr_now_call_count) - + now_calls_at_start_) / + (double)state.iterations()) << " allocs/iter:" << ((double)(counters_at_end.total_allocs_absolute - counters_at_start_.total_allocs_absolute) / diff --git a/test/cpp/microbenchmarks/helpers.h b/test/cpp/microbenchmarks/helpers.h index f44b7cf83a..af401dd7bb 100644 --- a/test/cpp/microbenchmarks/helpers.h +++ b/test/cpp/microbenchmarks/helpers.h @@ -72,6 +72,7 @@ class Library { extern "C" gpr_atm gpr_mu_locks; extern "C" gpr_atm gpr_counter_atm_cas; extern "C" gpr_atm gpr_counter_atm_add; +extern "C" gpr_atm gpr_now_call_count; #endif class TrackCounters { @@ -86,6 +87,8 @@ class TrackCounters { gpr_atm_no_barrier_load(&gpr_counter_atm_cas); const size_t atm_add_at_start_ = gpr_atm_no_barrier_load(&gpr_counter_atm_add); + const size_t now_calls_at_start_ = + gpr_atm_no_barrier_load(&gpr_now_call_count); grpc_memory_counters counters_at_start_ = grpc_memory_counters_snapshot(); #endif }; -- cgit v1.2.3 From 0c0b89a88ba6544e42cca43913ed65dea64bff3a Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Wed, 19 Apr 2017 13:28:24 -0700 Subject: Change hash table to use linear probing and add unit test. Also add some missing rules in test/core/slice/BUILD. --- CMakeLists.txt | 32 ++++ Makefile | 36 ++++ build.yaml | 10 + src/core/lib/slice/slice_hash_table.c | 55 +++--- src/core/lib/slice/slice_hash_table.h | 4 +- test/core/slice/BUILD | 23 ++- test/core/slice/slice_hash_table_test.c | 202 +++++++++++++++++++++ tools/run_tests/generated/sources_and_headers.json | 17 ++ tools/run_tests/generated/tests.json | 22 +++ vsprojects/buildtests_c.sln | 27 +++ .../slice_hash_table_test.vcxproj | 199 ++++++++++++++++++++ .../slice_hash_table_test.vcxproj.filters | 21 +++ 12 files changed, 616 insertions(+), 32 deletions(-) create mode 100644 test/core/slice/slice_hash_table_test.c create mode 100644 vsprojects/vcxproj/test/slice_hash_table_test/slice_hash_table_test.vcxproj create mode 100644 vsprojects/vcxproj/test/slice_hash_table_test/slice_hash_table_test.vcxproj.filters (limited to 'test') diff --git a/CMakeLists.txt b/CMakeLists.txt index a6a2af65d5..230a3d1ac0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -493,6 +493,7 @@ add_dependencies(buildtests_c sequential_connectivity_test) add_dependencies(buildtests_c server_chttp2_test) add_dependencies(buildtests_c server_test) add_dependencies(buildtests_c slice_buffer_test) +add_dependencies(buildtests_c slice_hash_table_test) add_dependencies(buildtests_c slice_string_helpers_test) add_dependencies(buildtests_c slice_test) add_dependencies(buildtests_c sockaddr_resolver_test) @@ -8007,6 +8008,37 @@ target_link_libraries(slice_buffer_test endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) +add_executable(slice_hash_table_test + test/core/slice/slice_hash_table_test.c +) + + +target_include_directories(slice_hash_table_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_BUILD_INCLUDE_DIR} + PRIVATE ${CARES_INCLUDE_DIR} + PRIVATE ${CARES_PLATFORM_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/cares/cares + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(slice_hash_table_test + ${_gRPC_ALLTARGETS_LIBRARIES} + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + add_executable(slice_string_helpers_test test/core/slice/slice_string_helpers_test.c ) diff --git a/Makefile b/Makefile index 8898939af9..a233f712e4 100644 --- a/Makefile +++ b/Makefile @@ -1073,6 +1073,7 @@ server_chttp2_test: $(BINDIR)/$(CONFIG)/server_chttp2_test server_fuzzer: $(BINDIR)/$(CONFIG)/server_fuzzer server_test: $(BINDIR)/$(CONFIG)/server_test slice_buffer_test: $(BINDIR)/$(CONFIG)/slice_buffer_test +slice_hash_table_test: $(BINDIR)/$(CONFIG)/slice_hash_table_test slice_string_helpers_test: $(BINDIR)/$(CONFIG)/slice_string_helpers_test slice_test: $(BINDIR)/$(CONFIG)/slice_test sockaddr_resolver_test: $(BINDIR)/$(CONFIG)/sockaddr_resolver_test @@ -1443,6 +1444,7 @@ buildtests_c: privatelibs_c \ $(BINDIR)/$(CONFIG)/server_chttp2_test \ $(BINDIR)/$(CONFIG)/server_test \ $(BINDIR)/$(CONFIG)/slice_buffer_test \ + $(BINDIR)/$(CONFIG)/slice_hash_table_test \ $(BINDIR)/$(CONFIG)/slice_string_helpers_test \ $(BINDIR)/$(CONFIG)/slice_test \ $(BINDIR)/$(CONFIG)/sockaddr_resolver_test \ @@ -1915,6 +1917,8 @@ test_c: buildtests_c $(Q) $(BINDIR)/$(CONFIG)/server_test || ( echo test server_test failed ; exit 1 ) $(E) "[RUN] Testing slice_buffer_test" $(Q) $(BINDIR)/$(CONFIG)/slice_buffer_test || ( echo test slice_buffer_test failed ; exit 1 ) + $(E) "[RUN] Testing slice_hash_table_test" + $(Q) $(BINDIR)/$(CONFIG)/slice_hash_table_test || ( echo test slice_hash_table_test failed ; exit 1 ) $(E) "[RUN] Testing slice_string_helpers_test" $(Q) $(BINDIR)/$(CONFIG)/slice_string_helpers_test || ( echo test slice_string_helpers_test failed ; exit 1 ) $(E) "[RUN] Testing slice_test" @@ -12349,6 +12353,38 @@ endif endif +SLICE_HASH_TABLE_TEST_SRC = \ + test/core/slice/slice_hash_table_test.c \ + +SLICE_HASH_TABLE_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(SLICE_HASH_TABLE_TEST_SRC)))) +ifeq ($(NO_SECURE),true) + +# You can't build secure targets if you don't have OpenSSL. + +$(BINDIR)/$(CONFIG)/slice_hash_table_test: openssl_dep_error + +else + + + +$(BINDIR)/$(CONFIG)/slice_hash_table_test: $(SLICE_HASH_TABLE_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a + $(E) "[LD] Linking $@" + $(Q) mkdir -p `dirname $@` + $(Q) $(LD) $(LDFLAGS) $(SLICE_HASH_TABLE_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBS) $(LDLIBS_SECURE) -o $(BINDIR)/$(CONFIG)/slice_hash_table_test + +endif + +$(OBJDIR)/$(CONFIG)/test/core/slice/slice_hash_table_test.o: $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a + +deps_slice_hash_table_test: $(SLICE_HASH_TABLE_TEST_OBJS:.o=.dep) + +ifneq ($(NO_SECURE),true) +ifneq ($(NO_DEPS),true) +-include $(SLICE_HASH_TABLE_TEST_OBJS:.o=.dep) +endif +endif + + SLICE_STRING_HELPERS_TEST_SRC = \ test/core/slice/slice_string_helpers_test.c \ diff --git a/build.yaml b/build.yaml index f4461e40ef..b40834e16d 100644 --- a/build.yaml +++ b/build.yaml @@ -2807,6 +2807,16 @@ targets: - grpc - gpr_test_util - gpr +- name: slice_hash_table_test + build: test + language: c + src: + - test/core/slice/slice_hash_table_test.c + deps: + - grpc_test_util + - grpc + - gpr_test_util + - gpr - name: slice_string_helpers_test build: test language: c diff --git a/src/core/lib/slice/slice_hash_table.c b/src/core/lib/slice/slice_hash_table.c index 7a8b79cc33..a33f6069fd 100644 --- a/src/core/lib/slice/slice_hash_table.c +++ b/src/core/lib/slice/slice_hash_table.c @@ -44,6 +44,7 @@ struct grpc_slice_hash_table { gpr_refcount refs; void (*destroy_value)(grpc_exec_ctx *exec_ctx, void *value); size_t size; + size_t max_num_probes; grpc_slice_hash_table_entry* entries; }; @@ -51,32 +52,22 @@ static bool is_empty(grpc_slice_hash_table_entry* entry) { return entry->value == NULL; } -// Helper function for insert and get operations that performs quadratic -// probing (https://en.wikipedia.org/wiki/Quadratic_probing). -static size_t grpc_slice_hash_table_find_index( - const grpc_slice_hash_table* table, const grpc_slice key, bool find_empty) { - size_t hash = grpc_slice_hash(key); - for (size_t i = 0; i < table->size; ++i) { - const size_t idx = (hash + i * i) % table->size; - if (is_empty(&table->entries[idx])) { - return find_empty ? idx : table->size; - } - if (grpc_slice_eq(table->entries[idx].key, key)) { - return idx; - } - } - return table->size; // Not found. -} - static void grpc_slice_hash_table_add(grpc_slice_hash_table* table, grpc_slice key, void* value) { GPR_ASSERT(value != NULL); - const size_t idx = - grpc_slice_hash_table_find_index(table, key, true /* find_empty */); - GPR_ASSERT(idx != table->size); // Table should never be full. - grpc_slice_hash_table_entry* entry = &table->entries[idx]; - entry->key = key; - entry->value = value; + const size_t hash = grpc_slice_hash(key); + for (size_t offset = 0; offset < table->size; ++offset) { + const size_t idx = (hash + offset) % table->size; + if (is_empty(&table->entries[idx])) { + table->entries[idx].key = key; + table->entries[idx].value = value; + // Keep track of the maximum number of probes needed, since this + // provides an upper bound for lookups. + if (offset > table->max_num_probes) table->max_num_probes = offset; + return; + } + } + GPR_ASSERT(false); // Table should never be full. } grpc_slice_hash_table* grpc_slice_hash_table_create( @@ -85,8 +76,7 @@ grpc_slice_hash_table* grpc_slice_hash_table_create( grpc_slice_hash_table* table = gpr_zalloc(sizeof(*table)); gpr_ref_init(&table->refs, 1); table->destroy_value = destroy_value; - // Quadratic probing gets best performance when the table is no more - // than half full. + // Keep load factor low to improve performance of lookups. table->size = num_entries * 2; const size_t entry_size = sizeof(grpc_slice_hash_table_entry) * table->size; table->entries = gpr_zalloc(entry_size); @@ -119,8 +109,15 @@ void grpc_slice_hash_table_unref(grpc_exec_ctx* exec_ctx, void* grpc_slice_hash_table_get(const grpc_slice_hash_table* table, const grpc_slice key) { - const size_t idx = - grpc_slice_hash_table_find_index(table, key, false /* find_empty */); - if (idx == table->size) return NULL; // Not found. - return table->entries[idx].value; + const size_t hash = grpc_slice_hash(key); + // We cap the number of probes at the max number recorded when + // populating the table. + for (size_t offset = 0; offset <= table->max_num_probes; ++offset) { + const size_t idx = (hash + offset) % table->size; + if (is_empty(&table->entries[idx])) break; + if (grpc_slice_eq(table->entries[idx].key, key)) { + return table->entries[idx].value; + } + } + return NULL; // Not found. } diff --git a/src/core/lib/slice/slice_hash_table.h b/src/core/lib/slice/slice_hash_table.h index 81e92b6e21..1e61c5eb11 100644 --- a/src/core/lib/slice/slice_hash_table.h +++ b/src/core/lib/slice/slice_hash_table.h @@ -37,8 +37,8 @@ /** Hash table implementation. * * This implementation uses open addressing - * (https://en.wikipedia.org/wiki/Open_addressing) with quadratic - * probing (https://en.wikipedia.org/wiki/Quadratic_probing). + * (https://en.wikipedia.org/wiki/Open_addressing) with linear + * probing (https://en.wikipedia.org/wiki/Linear_probing). * * The keys are \a grpc_slice objects. The values are arbitrary pointers * with a common destroy function. diff --git a/test/core/slice/BUILD b/test/core/slice/BUILD index 4d64d0a818..18cf6f60af 100644 --- a/test/core/slice/BUILD +++ b/test/core/slice/BUILD @@ -47,12 +47,33 @@ cc_test( ) cc_test( - name = "slice_buffer_test", + name = "slice_test", + srcs = ["slice_test.c"], + deps = ["//:grpc", "//test/core/util:grpc_test_util", "//:gpr", "//test/core/util:gpr_test_util"], + copts = ['-std=c99'] +) + +cc_test( + name = "slice_string_helpers_test", srcs = ["slice_string_helpers_test.c"], deps = ["//:grpc", "//test/core/util:grpc_test_util", "//:gpr", "//test/core/util:gpr_test_util"], copts = ['-std=c99'] ) +cc_test( + name = "slice_buffer_test", + srcs = ["slice_buffer_test.c"], + deps = ["//:grpc", "//test/core/util:grpc_test_util", "//:gpr", "//test/core/util:gpr_test_util"], + copts = ['-std=c99'] +) + +cc_test( + name = "slice_hash_table_test", + srcs = ["slice_hash_table_test.c"], + deps = ["//:grpc", "//test/core/util:grpc_test_util", "//:gpr", "//test/core/util:gpr_test_util"], + copts = ['-std=c99'] +) + cc_test( name = "b64_test", srcs = ["b64_test.c"], diff --git a/test/core/slice/slice_hash_table_test.c b/test/core/slice/slice_hash_table_test.c new file mode 100644 index 0000000000..24a4354b8b --- /dev/null +++ b/test/core/slice/slice_hash_table_test.c @@ -0,0 +1,202 @@ +/* + * + * Copyright 2017, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include "src/core/lib/slice/slice_hash_table.h" + +#include + +#include +#include +#include + +#include "src/core/lib/slice/slice_internal.h" +#include "test/core/util/test_config.h" + +typedef struct { + char* key; + char* value; +} test_entry; + +static void populate_entries(const test_entry* input, size_t num_entries, + grpc_slice_hash_table_entry* output) { + for (size_t i = 0; i < num_entries; ++i) { + output[i].key = grpc_slice_from_copied_string(gpr_strdup(input[i].key)); + output[i].value = gpr_strdup(input[i].value); + } +} + +static void check_values(const test_entry* input, size_t num_entries, + grpc_slice_hash_table* table) { + for (size_t i = 0; i < num_entries; ++i) { + grpc_slice key = grpc_slice_from_static_string(input[i].key); + char* actual = grpc_slice_hash_table_get(table, key); + GPR_ASSERT(actual != NULL); + GPR_ASSERT(strcmp(actual, input[i].value) == 0); + grpc_slice_unref(key); + } +} + +static void check_non_existent_value(const char* key_string, + grpc_slice_hash_table* table) { + grpc_slice key = grpc_slice_from_static_string(key_string); + GPR_ASSERT(grpc_slice_hash_table_get(table, key) == NULL); + grpc_slice_unref(key); +} + +static void destroy_string(grpc_exec_ctx* exec_ctx, void* value) { + gpr_free(value); +} + +static void test_slice_hash_table() { + const test_entry test_entries[] = { + {"key_0", "value_0"}, + {"key_1", "value_1"}, + {"key_2", "value_2"}, + {"key_3", "value_3"}, + {"key_4", "value_4"}, + {"key_5", "value_5"}, + {"key_6", "value_6"}, + {"key_7", "value_7"}, + {"key_8", "value_8"}, + {"key_9", "value_9"}, + {"key_10", "value_10"}, + {"key_11", "value_11"}, + {"key_12", "value_12"}, + {"key_13", "value_13"}, + {"key_14", "value_14"}, + {"key_15", "value_15"}, + {"key_16", "value_16"}, + {"key_17", "value_17"}, + {"key_18", "value_18"}, + {"key_19", "value_19"}, + {"key_20", "value_20"}, + {"key_21", "value_21"}, + {"key_22", "value_22"}, + {"key_23", "value_23"}, + {"key_24", "value_24"}, + {"key_25", "value_25"}, + {"key_26", "value_26"}, + {"key_27", "value_27"}, + {"key_28", "value_28"}, + {"key_29", "value_29"}, + {"key_30", "value_30"}, + {"key_31", "value_31"}, + {"key_32", "value_32"}, + {"key_33", "value_33"}, + {"key_34", "value_34"}, + {"key_35", "value_35"}, + {"key_36", "value_36"}, + {"key_37", "value_37"}, + {"key_38", "value_38"}, + {"key_39", "value_39"}, + {"key_40", "value_40"}, + {"key_41", "value_41"}, + {"key_42", "value_42"}, + {"key_43", "value_43"}, + {"key_44", "value_44"}, + {"key_45", "value_45"}, + {"key_46", "value_46"}, + {"key_47", "value_47"}, + {"key_48", "value_48"}, + {"key_49", "value_49"}, + {"key_50", "value_50"}, + {"key_51", "value_51"}, + {"key_52", "value_52"}, + {"key_53", "value_53"}, + {"key_54", "value_54"}, + {"key_55", "value_55"}, + {"key_56", "value_56"}, + {"key_57", "value_57"}, + {"key_58", "value_58"}, + {"key_59", "value_59"}, + {"key_60", "value_60"}, + {"key_61", "value_61"}, + {"key_62", "value_62"}, + {"key_63", "value_63"}, + {"key_64", "value_64"}, + {"key_65", "value_65"}, + {"key_66", "value_66"}, + {"key_67", "value_67"}, + {"key_68", "value_68"}, + {"key_69", "value_69"}, + {"key_70", "value_70"}, + {"key_71", "value_71"}, + {"key_72", "value_72"}, + {"key_73", "value_73"}, + {"key_74", "value_74"}, + {"key_75", "value_75"}, + {"key_76", "value_76"}, + {"key_77", "value_77"}, + {"key_78", "value_78"}, + {"key_79", "value_79"}, + {"key_80", "value_80"}, + {"key_81", "value_81"}, + {"key_82", "value_82"}, + {"key_83", "value_83"}, + {"key_84", "value_84"}, + {"key_85", "value_85"}, + {"key_86", "value_86"}, + {"key_87", "value_87"}, + {"key_88", "value_88"}, + {"key_89", "value_89"}, + {"key_90", "value_90"}, + {"key_91", "value_91"}, + {"key_92", "value_92"}, + {"key_93", "value_93"}, + {"key_94", "value_94"}, + {"key_95", "value_95"}, + {"key_96", "value_96"}, + {"key_97", "value_97"}, + {"key_98", "value_98"}, + {"key_99", "value_99"}, + }; + const size_t num_entries = GPR_ARRAY_SIZE(test_entries); + // Construct table. + grpc_slice_hash_table_entry entries[num_entries]; + populate_entries(test_entries, num_entries, entries); + grpc_slice_hash_table* table = + grpc_slice_hash_table_create(num_entries, entries, destroy_string); + // Check contents of table. + check_values(test_entries, num_entries, table); + check_non_existent_value("XX", table); + // Clean up. + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_slice_hash_table_unref(&exec_ctx, table); + grpc_exec_ctx_finish(&exec_ctx); +} + +int main(int argc, char **argv) { + grpc_test_init(argc, argv); + test_slice_hash_table(); + return 0; +} diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json index aa4869e1c8..9635dbec83 100644 --- a/tools/run_tests/generated/sources_and_headers.json +++ b/tools/run_tests/generated/sources_and_headers.json @@ -1978,6 +1978,23 @@ "third_party": false, "type": "target" }, + { + "deps": [ + "gpr", + "gpr_test_util", + "grpc", + "grpc_test_util" + ], + "headers": [], + "is_filegroup": false, + "language": "c", + "name": "slice_hash_table_test", + "src": [ + "test/core/slice/slice_hash_table_test.c" + ], + "third_party": false, + "type": "target" + }, { "deps": [ "gpr", diff --git a/tools/run_tests/generated/tests.json b/tools/run_tests/generated/tests.json index 6338ea7012..eb8fb20d7d 100644 --- a/tools/run_tests/generated/tests.json +++ b/tools/run_tests/generated/tests.json @@ -2071,6 +2071,28 @@ "windows" ] }, + { + "args": [], + "ci_platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "gtest": false, + "language": "c", + "name": "slice_hash_table_test", + "platforms": [ + "linux", + "mac", + "posix", + "windows" + ] + }, { "args": [], "ci_platforms": [ diff --git a/vsprojects/buildtests_c.sln b/vsprojects/buildtests_c.sln index 6ae8bfa74d..539f474f9e 100644 --- a/vsprojects/buildtests_c.sln +++ b/vsprojects/buildtests_c.sln @@ -1440,6 +1440,17 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "slice_buffer_test", "vcxpro {B23D3D1A-9438-4EDA-BEB6-9A0A03D17792} = {B23D3D1A-9438-4EDA-BEB6-9A0A03D17792} EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "slice_hash_table_test", "vcxproj\test\slice_hash_table_test\slice_hash_table_test.vcxproj", "{B3BC3481-FCD3-BA52-C975-E65CDB1CE9A9}" + ProjectSection(myProperties) = preProject + lib = "False" + EndProjectSection + ProjectSection(ProjectDependencies) = postProject + {17BCAFC0-5FDC-4C94-AEB9-95F3E220614B} = {17BCAFC0-5FDC-4C94-AEB9-95F3E220614B} + {29D16885-7228-4C31-81ED-5F9187C7F2A9} = {29D16885-7228-4C31-81ED-5F9187C7F2A9} + {EAB0A629-17A9-44DB-B5FF-E91A721FE037} = {EAB0A629-17A9-44DB-B5FF-E91A721FE037} + {B23D3D1A-9438-4EDA-BEB6-9A0A03D17792} = {B23D3D1A-9438-4EDA-BEB6-9A0A03D17792} + EndProjectSection +EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "slice_string_helpers_test", "vcxproj\test\slice_string_helpers_test\slice_string_helpers_test.vcxproj", "{419167BB-C3F5-DDEA-403A-394D1902DE65}" ProjectSection(myProperties) = preProject lib = "False" @@ -3823,6 +3834,22 @@ Global {F0FA4A41-5695-580A-DCDA-EC719CB041B0}.Release-DLL|Win32.Build.0 = Release|Win32 {F0FA4A41-5695-580A-DCDA-EC719CB041B0}.Release-DLL|x64.ActiveCfg = Release|x64 {F0FA4A41-5695-580A-DCDA-EC719CB041B0}.Release-DLL|x64.Build.0 = Release|x64 + {B3BC3481-FCD3-BA52-C975-E65CDB1CE9A9}.Debug|Win32.ActiveCfg = Debug|Win32 + {B3BC3481-FCD3-BA52-C975-E65CDB1CE9A9}.Debug|x64.ActiveCfg = Debug|x64 + {B3BC3481-FCD3-BA52-C975-E65CDB1CE9A9}.Release|Win32.ActiveCfg = Release|Win32 + {B3BC3481-FCD3-BA52-C975-E65CDB1CE9A9}.Release|x64.ActiveCfg = Release|x64 + {B3BC3481-FCD3-BA52-C975-E65CDB1CE9A9}.Debug|Win32.Build.0 = Debug|Win32 + {B3BC3481-FCD3-BA52-C975-E65CDB1CE9A9}.Debug|x64.Build.0 = Debug|x64 + {B3BC3481-FCD3-BA52-C975-E65CDB1CE9A9}.Release|Win32.Build.0 = Release|Win32 + {B3BC3481-FCD3-BA52-C975-E65CDB1CE9A9}.Release|x64.Build.0 = Release|x64 + {B3BC3481-FCD3-BA52-C975-E65CDB1CE9A9}.Debug-DLL|Win32.ActiveCfg = Debug|Win32 + {B3BC3481-FCD3-BA52-C975-E65CDB1CE9A9}.Debug-DLL|Win32.Build.0 = Debug|Win32 + {B3BC3481-FCD3-BA52-C975-E65CDB1CE9A9}.Debug-DLL|x64.ActiveCfg = Debug|x64 + {B3BC3481-FCD3-BA52-C975-E65CDB1CE9A9}.Debug-DLL|x64.Build.0 = Debug|x64 + {B3BC3481-FCD3-BA52-C975-E65CDB1CE9A9}.Release-DLL|Win32.ActiveCfg = Release|Win32 + {B3BC3481-FCD3-BA52-C975-E65CDB1CE9A9}.Release-DLL|Win32.Build.0 = Release|Win32 + {B3BC3481-FCD3-BA52-C975-E65CDB1CE9A9}.Release-DLL|x64.ActiveCfg = Release|x64 + {B3BC3481-FCD3-BA52-C975-E65CDB1CE9A9}.Release-DLL|x64.Build.0 = Release|x64 {419167BB-C3F5-DDEA-403A-394D1902DE65}.Debug|Win32.ActiveCfg = Debug|Win32 {419167BB-C3F5-DDEA-403A-394D1902DE65}.Debug|x64.ActiveCfg = Debug|x64 {419167BB-C3F5-DDEA-403A-394D1902DE65}.Release|Win32.ActiveCfg = Release|Win32 diff --git a/vsprojects/vcxproj/test/slice_hash_table_test/slice_hash_table_test.vcxproj b/vsprojects/vcxproj/test/slice_hash_table_test/slice_hash_table_test.vcxproj new file mode 100644 index 0000000000..0fccfdcaa5 --- /dev/null +++ b/vsprojects/vcxproj/test/slice_hash_table_test/slice_hash_table_test.vcxproj @@ -0,0 +1,199 @@ + + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {B3BC3481-FCD3-BA52-C975-E65CDB1CE9A9} + true + $(SolutionDir)IntDir\$(MSBuildProjectName)\ + + + + v100 + + + v110 + + + v120 + + + v140 + + + Application + true + Unicode + + + Application + false + true + Unicode + + + + + + + + + + + + + + slice_hash_table_test + static + Debug + static + Debug + + + slice_hash_table_test + static + Release + static + Release + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + MultiThreadedDebug + true + None + false + + + Console + true + false + + + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + MultiThreadedDebug + true + None + false + + + Console + true + false + + + + + + NotUsing + Level3 + MaxSpeed + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + true + true + MultiThreaded + true + None + false + + + Console + true + false + true + true + + + + + + NotUsing + Level3 + MaxSpeed + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + true + true + MultiThreaded + true + None + false + + + Console + true + false + true + true + + + + + + + + + + {17BCAFC0-5FDC-4C94-AEB9-95F3E220614B} + + + {29D16885-7228-4C31-81ED-5F9187C7F2A9} + + + {EAB0A629-17A9-44DB-B5FF-E91A721FE037} + + + {B23D3D1A-9438-4EDA-BEB6-9A0A03D17792} + + + + + + + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + + + + diff --git a/vsprojects/vcxproj/test/slice_hash_table_test/slice_hash_table_test.vcxproj.filters b/vsprojects/vcxproj/test/slice_hash_table_test/slice_hash_table_test.vcxproj.filters new file mode 100644 index 0000000000..1973852678 --- /dev/null +++ b/vsprojects/vcxproj/test/slice_hash_table_test/slice_hash_table_test.vcxproj.filters @@ -0,0 +1,21 @@ + + + + + test\core\slice + + + + + + {e11f5007-84da-0229-9118-2a2bb17f956c} + + + {a11f4770-5e13-eb1a-a848-8667dde98812} + + + {fb1262a8-0a70-bc85-579a-6ebfffbf25b5} + + + + -- cgit v1.2.3 From ba390352c9d232d5e03e5821c06aecd2fd1f98d2 Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Thu, 20 Apr 2017 06:59:26 -0700 Subject: clang-format --- src/core/lib/slice/slice_hash_table.c | 4 +- test/core/slice/slice_hash_table_test.c | 136 ++++++++------------------------ 2 files changed, 37 insertions(+), 103 deletions(-) (limited to 'test') diff --git a/src/core/lib/slice/slice_hash_table.c b/src/core/lib/slice/slice_hash_table.c index a33f6069fd..444f22aa19 100644 --- a/src/core/lib/slice/slice_hash_table.c +++ b/src/core/lib/slice/slice_hash_table.c @@ -42,7 +42,7 @@ struct grpc_slice_hash_table { gpr_refcount refs; - void (*destroy_value)(grpc_exec_ctx *exec_ctx, void *value); + void (*destroy_value)(grpc_exec_ctx* exec_ctx, void* value); size_t size; size_t max_num_probes; grpc_slice_hash_table_entry* entries; @@ -72,7 +72,7 @@ static void grpc_slice_hash_table_add(grpc_slice_hash_table* table, grpc_slice_hash_table* grpc_slice_hash_table_create( size_t num_entries, grpc_slice_hash_table_entry* entries, - void (*destroy_value)(grpc_exec_ctx *exec_ctx, void *value)) { + void (*destroy_value)(grpc_exec_ctx* exec_ctx, void* value)) { grpc_slice_hash_table* table = gpr_zalloc(sizeof(*table)); gpr_ref_init(&table->refs, 1); table->destroy_value = destroy_value; diff --git a/test/core/slice/slice_hash_table_test.c b/test/core/slice/slice_hash_table_test.c index 24a4354b8b..9eba57e70a 100644 --- a/test/core/slice/slice_hash_table_test.c +++ b/test/core/slice/slice_hash_table_test.c @@ -79,106 +79,40 @@ static void destroy_string(grpc_exec_ctx* exec_ctx, void* value) { static void test_slice_hash_table() { const test_entry test_entries[] = { - {"key_0", "value_0"}, - {"key_1", "value_1"}, - {"key_2", "value_2"}, - {"key_3", "value_3"}, - {"key_4", "value_4"}, - {"key_5", "value_5"}, - {"key_6", "value_6"}, - {"key_7", "value_7"}, - {"key_8", "value_8"}, - {"key_9", "value_9"}, - {"key_10", "value_10"}, - {"key_11", "value_11"}, - {"key_12", "value_12"}, - {"key_13", "value_13"}, - {"key_14", "value_14"}, - {"key_15", "value_15"}, - {"key_16", "value_16"}, - {"key_17", "value_17"}, - {"key_18", "value_18"}, - {"key_19", "value_19"}, - {"key_20", "value_20"}, - {"key_21", "value_21"}, - {"key_22", "value_22"}, - {"key_23", "value_23"}, - {"key_24", "value_24"}, - {"key_25", "value_25"}, - {"key_26", "value_26"}, - {"key_27", "value_27"}, - {"key_28", "value_28"}, - {"key_29", "value_29"}, - {"key_30", "value_30"}, - {"key_31", "value_31"}, - {"key_32", "value_32"}, - {"key_33", "value_33"}, - {"key_34", "value_34"}, - {"key_35", "value_35"}, - {"key_36", "value_36"}, - {"key_37", "value_37"}, - {"key_38", "value_38"}, - {"key_39", "value_39"}, - {"key_40", "value_40"}, - {"key_41", "value_41"}, - {"key_42", "value_42"}, - {"key_43", "value_43"}, - {"key_44", "value_44"}, - {"key_45", "value_45"}, - {"key_46", "value_46"}, - {"key_47", "value_47"}, - {"key_48", "value_48"}, - {"key_49", "value_49"}, - {"key_50", "value_50"}, - {"key_51", "value_51"}, - {"key_52", "value_52"}, - {"key_53", "value_53"}, - {"key_54", "value_54"}, - {"key_55", "value_55"}, - {"key_56", "value_56"}, - {"key_57", "value_57"}, - {"key_58", "value_58"}, - {"key_59", "value_59"}, - {"key_60", "value_60"}, - {"key_61", "value_61"}, - {"key_62", "value_62"}, - {"key_63", "value_63"}, - {"key_64", "value_64"}, - {"key_65", "value_65"}, - {"key_66", "value_66"}, - {"key_67", "value_67"}, - {"key_68", "value_68"}, - {"key_69", "value_69"}, - {"key_70", "value_70"}, - {"key_71", "value_71"}, - {"key_72", "value_72"}, - {"key_73", "value_73"}, - {"key_74", "value_74"}, - {"key_75", "value_75"}, - {"key_76", "value_76"}, - {"key_77", "value_77"}, - {"key_78", "value_78"}, - {"key_79", "value_79"}, - {"key_80", "value_80"}, - {"key_81", "value_81"}, - {"key_82", "value_82"}, - {"key_83", "value_83"}, - {"key_84", "value_84"}, - {"key_85", "value_85"}, - {"key_86", "value_86"}, - {"key_87", "value_87"}, - {"key_88", "value_88"}, - {"key_89", "value_89"}, - {"key_90", "value_90"}, - {"key_91", "value_91"}, - {"key_92", "value_92"}, - {"key_93", "value_93"}, - {"key_94", "value_94"}, - {"key_95", "value_95"}, - {"key_96", "value_96"}, - {"key_97", "value_97"}, - {"key_98", "value_98"}, - {"key_99", "value_99"}, + {"key_0", "value_0"}, {"key_1", "value_1"}, {"key_2", "value_2"}, + {"key_3", "value_3"}, {"key_4", "value_4"}, {"key_5", "value_5"}, + {"key_6", "value_6"}, {"key_7", "value_7"}, {"key_8", "value_8"}, + {"key_9", "value_9"}, {"key_10", "value_10"}, {"key_11", "value_11"}, + {"key_12", "value_12"}, {"key_13", "value_13"}, {"key_14", "value_14"}, + {"key_15", "value_15"}, {"key_16", "value_16"}, {"key_17", "value_17"}, + {"key_18", "value_18"}, {"key_19", "value_19"}, {"key_20", "value_20"}, + {"key_21", "value_21"}, {"key_22", "value_22"}, {"key_23", "value_23"}, + {"key_24", "value_24"}, {"key_25", "value_25"}, {"key_26", "value_26"}, + {"key_27", "value_27"}, {"key_28", "value_28"}, {"key_29", "value_29"}, + {"key_30", "value_30"}, {"key_31", "value_31"}, {"key_32", "value_32"}, + {"key_33", "value_33"}, {"key_34", "value_34"}, {"key_35", "value_35"}, + {"key_36", "value_36"}, {"key_37", "value_37"}, {"key_38", "value_38"}, + {"key_39", "value_39"}, {"key_40", "value_40"}, {"key_41", "value_41"}, + {"key_42", "value_42"}, {"key_43", "value_43"}, {"key_44", "value_44"}, + {"key_45", "value_45"}, {"key_46", "value_46"}, {"key_47", "value_47"}, + {"key_48", "value_48"}, {"key_49", "value_49"}, {"key_50", "value_50"}, + {"key_51", "value_51"}, {"key_52", "value_52"}, {"key_53", "value_53"}, + {"key_54", "value_54"}, {"key_55", "value_55"}, {"key_56", "value_56"}, + {"key_57", "value_57"}, {"key_58", "value_58"}, {"key_59", "value_59"}, + {"key_60", "value_60"}, {"key_61", "value_61"}, {"key_62", "value_62"}, + {"key_63", "value_63"}, {"key_64", "value_64"}, {"key_65", "value_65"}, + {"key_66", "value_66"}, {"key_67", "value_67"}, {"key_68", "value_68"}, + {"key_69", "value_69"}, {"key_70", "value_70"}, {"key_71", "value_71"}, + {"key_72", "value_72"}, {"key_73", "value_73"}, {"key_74", "value_74"}, + {"key_75", "value_75"}, {"key_76", "value_76"}, {"key_77", "value_77"}, + {"key_78", "value_78"}, {"key_79", "value_79"}, {"key_80", "value_80"}, + {"key_81", "value_81"}, {"key_82", "value_82"}, {"key_83", "value_83"}, + {"key_84", "value_84"}, {"key_85", "value_85"}, {"key_86", "value_86"}, + {"key_87", "value_87"}, {"key_88", "value_88"}, {"key_89", "value_89"}, + {"key_90", "value_90"}, {"key_91", "value_91"}, {"key_92", "value_92"}, + {"key_93", "value_93"}, {"key_94", "value_94"}, {"key_95", "value_95"}, + {"key_96", "value_96"}, {"key_97", "value_97"}, {"key_98", "value_98"}, + {"key_99", "value_99"}, }; const size_t num_entries = GPR_ARRAY_SIZE(test_entries); // Construct table. @@ -195,7 +129,7 @@ static void test_slice_hash_table() { grpc_exec_ctx_finish(&exec_ctx); } -int main(int argc, char **argv) { +int main(int argc, char** argv) { grpc_test_init(argc, argv); test_slice_hash_table(); return 0; -- cgit v1.2.3 From f186d9d35b93bed6cb47e2902eb3caf4d43be55e Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Thu, 20 Apr 2017 07:05:34 -0700 Subject: Fix asan bug. --- test/core/slice/slice_hash_table_test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/core/slice/slice_hash_table_test.c b/test/core/slice/slice_hash_table_test.c index 9eba57e70a..055d7f448f 100644 --- a/test/core/slice/slice_hash_table_test.c +++ b/test/core/slice/slice_hash_table_test.c @@ -50,7 +50,7 @@ typedef struct { static void populate_entries(const test_entry* input, size_t num_entries, grpc_slice_hash_table_entry* output) { for (size_t i = 0; i < num_entries; ++i) { - output[i].key = grpc_slice_from_copied_string(gpr_strdup(input[i].key)); + output[i].key = grpc_slice_from_copied_string(input[i].key); output[i].value = gpr_strdup(input[i].value); } } -- cgit v1.2.3 From 493be1f1b98d3c238b9b87fc478c3f4ae25444af Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Thu, 20 Apr 2017 07:10:22 -0700 Subject: Fix windows build. --- test/core/slice/slice_hash_table_test.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/core/slice/slice_hash_table_test.c b/test/core/slice/slice_hash_table_test.c index 055d7f448f..67041b2d5c 100644 --- a/test/core/slice/slice_hash_table_test.c +++ b/test/core/slice/slice_hash_table_test.c @@ -116,10 +116,12 @@ static void test_slice_hash_table() { }; const size_t num_entries = GPR_ARRAY_SIZE(test_entries); // Construct table. - grpc_slice_hash_table_entry entries[num_entries]; + grpc_slice_hash_table_entry* entries = + gpr_zalloc(sizeof(*entries) * num_entries); populate_entries(test_entries, num_entries, entries); grpc_slice_hash_table* table = grpc_slice_hash_table_create(num_entries, entries, destroy_string); + gpr_free(entries); // Check contents of table. check_values(test_entries, num_entries, table); check_non_existent_value("XX", table); -- cgit v1.2.3 From 5e17e4430cebe6d1a1a96988a86eb6bd8c56fac5 Mon Sep 17 00:00:00 2001 From: Noah Eisen Date: Thu, 20 Apr 2017 12:35:27 -0700 Subject: Add fuzz test --- .../clusterfuzz-testcase-6462055064272896 | Bin 0 -> 51 bytes tools/run_tests/generated/tests.json | 23 +++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 test/core/end2end/fuzzers/api_fuzzer_corpus/clusterfuzz-testcase-6462055064272896 (limited to 'test') diff --git a/test/core/end2end/fuzzers/api_fuzzer_corpus/clusterfuzz-testcase-6462055064272896 b/test/core/end2end/fuzzers/api_fuzzer_corpus/clusterfuzz-testcase-6462055064272896 new file mode 100644 index 0000000000..c121283242 Binary files /dev/null and b/test/core/end2end/fuzzers/api_fuzzer_corpus/clusterfuzz-testcase-6462055064272896 differ diff --git a/tools/run_tests/generated/tests.json b/tools/run_tests/generated/tests.json index 6338ea7012..be8ee76b6d 100644 --- a/tools/run_tests/generated/tests.json +++ b/tools/run_tests/generated/tests.json @@ -85165,6 +85165,29 @@ ], "uses_polling": false }, + { + "args": [ + "test/core/end2end/fuzzers/api_fuzzer_corpus/clusterfuzz-testcase-6462055064272896" + ], + "ci_platforms": [ + "linux" + ], + "cpu_cost": 0.1, + "exclude_configs": [ + "tsan" + ], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "api_fuzzer_one_entry", + "platforms": [ + "mac", + "linux" + ], + "uses_polling": false + }, { "args": [ "test/core/end2end/fuzzers/api_fuzzer_corpus/clusterfuzz-testcase-6499902139924480" -- cgit v1.2.3 From 03876f66e17fc8a614407bb2aa317b21a2ef7319 Mon Sep 17 00:00:00 2001 From: yang-g Date: Thu, 20 Apr 2017 14:51:58 -0700 Subject: Fix http2_interop test for c++ and python --- src/python/grpcio_tests/tests/http2/negative_http2_client.py | 2 -- test/cpp/interop/http2_client.cc | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) (limited to 'test') diff --git a/src/python/grpcio_tests/tests/http2/negative_http2_client.py b/src/python/grpcio_tests/tests/http2/negative_http2_client.py index b184e62cfd..90f54e80bb 100644 --- a/src/python/grpcio_tests/tests/http2/negative_http2_client.py +++ b/src/python/grpcio_tests/tests/http2/negative_http2_client.py @@ -96,8 +96,6 @@ def _rst_during_data(stub): def _rst_after_data(stub): resp_future = stub.UnaryCall.future(_SIMPLE_REQUEST) - _validate_payload_type_and_length( - next(resp_future), messages_pb2.COMPRESSABLE, _RESPONSE_SIZE) _validate_status_code_and_details(resp_future, grpc.StatusCode.INTERNAL, "Received RST_STREAM with error code 0") diff --git a/test/cpp/interop/http2_client.cc b/test/cpp/interop/http2_client.cc index 38a437f39f..2109e34616 100644 --- a/test/cpp/interop/http2_client.cc +++ b/test/cpp/interop/http2_client.cc @@ -108,7 +108,7 @@ bool Http2Client::DoRstAfterData() { SimpleResponse response; AssertStatusCode(SendUnaryCall(&response), grpc::StatusCode::INTERNAL); - GPR_ASSERT(response.has_payload()); // data should be received + // There is no guarantee that data would be received. gpr_log(GPR_DEBUG, "Done testing reset stream after data"); return true; -- cgit v1.2.3 From a935ae1505c768ca0ce6ea981af1fb03c56052d7 Mon Sep 17 00:00:00 2001 From: Vijay Pai Date: Thu, 13 Apr 2017 21:07:45 +0000 Subject: Fix build rules for grpc++_unsecure, test that it builds properly --- BUILD | 5 ++++- WORKSPACE | 11 +++++------ test/cpp/util/BUILD | 9 +++++++++ 3 files changed, 18 insertions(+), 7 deletions(-) (limited to 'test') diff --git a/BUILD b/BUILD index 70bd4062a4..57709e4745 100644 --- a/BUILD +++ b/BUILD @@ -1277,6 +1277,9 @@ grpc_cc_library( "src/cpp/server/thread_pool_interface.h", "src/cpp/thread_manager/thread_manager.h", ], + external_deps = [ + "nanopb", + ], language = "c++", public_hdrs = [ "include/grpc++/alarm.h", @@ -1328,7 +1331,7 @@ grpc_cc_library( "include/grpc++/support/time.h", ], deps = [ - "grpc", + "grpc_base", "grpc++_codegen_base", ], ) diff --git a/WORKSPACE b/WORKSPACE index 5ba82f3127..a78a88979e 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -15,17 +15,17 @@ bind( bind( name = "protobuf", - actual = "@submodule_protobuf//:protobuf", + actual = "@com_google_protobuf//:protobuf", ) bind( name = "protobuf_clib", - actual = "@submodule_protobuf//:protoc_lib", + actual = "@com_google_protobuf//:protoc_lib", ) bind( name = "protocol_compiler", - actual = "@submodule_protobuf//:protoc", + actual = "@com_google_protobuf//:protoc", ) bind( @@ -48,9 +48,8 @@ bind( actual = "@com_github_gflags_gflags//:gflags", ) -new_local_repository( +local_repository( name = "submodule_boringssl", - build_file = "third_party/boringssl-with-bazel/BUILD", path = "third_party/boringssl-with-bazel", ) @@ -61,7 +60,7 @@ new_local_repository( ) new_local_repository( - name = "submodule_protobuf", + name = "com_google_protobuf", build_file = "third_party/protobuf/BUILD", path = "third_party/protobuf", ) diff --git a/test/cpp/util/BUILD b/test/cpp/util/BUILD index 38f804ffd4..c83f89eb90 100644 --- a/test/cpp/util/BUILD +++ b/test/cpp/util/BUILD @@ -29,6 +29,15 @@ licenses(["notice"]) # 3-clause BSD +# The following builds a shared-object to confirm that grpc++_unsecure +# builds properly. Build-only is sufficient here +cc_binary( + name = "testso.so", + srcs = [], + deps = ["//:grpc++_unsecure"], + linkshared = 1, +) + cc_library( name = "test_config", srcs = [ -- cgit v1.2.3 From 20cb627339c20e86814d64ba4837d7bdd6f35195 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 21 Apr 2017 15:07:13 -0700 Subject: Fix HTTP proxy tests - heap allocate the pollset shutdown closure (this may be called asynchronously) - ensure a poller remains until all endpoints are closed --- test/core/end2end/fixtures/http_proxy_fixture.c | 59 ++++++++++++++++++------- test/core/end2end/tests/cancel_after_invoke.c | 9 ++-- 2 files changed, 47 insertions(+), 21 deletions(-) (limited to 'test') diff --git a/test/core/end2end/fixtures/http_proxy_fixture.c b/test/core/end2end/fixtures/http_proxy_fixture.c index 451ed268d3..02235d96e7 100644 --- a/test/core/end2end/fixtures/http_proxy_fixture.c +++ b/test/core/end2end/fixtures/http_proxy_fixture.c @@ -59,6 +59,7 @@ #include "src/core/lib/iomgr/sockaddr_utils.h" #include "src/core/lib/iomgr/tcp_client.h" #include "src/core/lib/iomgr/tcp_server.h" +#include "src/core/lib/iomgr/timer.h" #include "src/core/lib/slice/slice_internal.h" #include "test/core/util/port.h" @@ -69,7 +70,7 @@ struct grpc_end2end_http_proxy { grpc_channel_args* channel_args; gpr_mu* mu; grpc_pollset* pollset; - gpr_atm shutdown; + gpr_refcount users; }; // @@ -77,6 +78,8 @@ struct grpc_end2end_http_proxy { // typedef struct proxy_connection { + grpc_end2end_http_proxy* proxy; + grpc_endpoint* client_endpoint; grpc_endpoint* server_endpoint; @@ -103,13 +106,26 @@ typedef struct proxy_connection { grpc_http_request http_request; } proxy_connection; +static void proxy_connection_ref(proxy_connection* conn, const char* reason) { + gpr_log(GPR_DEBUG, "proxy_connection_ref: %p %s %" PRIdPTR " --> %" PRIdPTR, + conn, reason, gpr_atm_no_barrier_load(&conn->refcount.count), + gpr_atm_no_barrier_load(&conn->refcount.count) - 1); + gpr_ref(&conn->refcount); +} + // Helper function to destroy the proxy connection. static void proxy_connection_unref(grpc_exec_ctx* exec_ctx, - proxy_connection* conn) { + proxy_connection* conn, const char* reason) { + gpr_log(GPR_DEBUG, "proxy_connection_unref: %p %s %" PRIdPTR " --> %" PRIdPTR, + conn, reason, gpr_atm_no_barrier_load(&conn->refcount.count), + gpr_atm_no_barrier_load(&conn->refcount.count) - 1); if (gpr_unref(&conn->refcount)) { + gpr_log(GPR_DEBUG, "endpoints: %p %p", conn->client_endpoint, + conn->server_endpoint); grpc_endpoint_destroy(exec_ctx, conn->client_endpoint); - if (conn->server_endpoint != NULL) + if (conn->server_endpoint != NULL) { grpc_endpoint_destroy(exec_ctx, conn->server_endpoint); + } grpc_pollset_set_destroy(exec_ctx, conn->pollset_set); grpc_slice_buffer_destroy_internal(exec_ctx, &conn->client_read_buffer); grpc_slice_buffer_destroy_internal(exec_ctx, @@ -121,6 +137,7 @@ static void proxy_connection_unref(grpc_exec_ctx* exec_ctx, grpc_slice_buffer_destroy_internal(exec_ctx, &conn->server_write_buffer); grpc_http_parser_destroy(&conn->http_parser); grpc_http_request_destroy(&conn->http_request); + gpr_unref(&conn->proxy->users); gpr_free(conn); } } @@ -139,7 +156,7 @@ static void proxy_connection_failed(grpc_exec_ctx* exec_ctx, grpc_endpoint_shutdown(exec_ctx, conn->server_endpoint, GRPC_ERROR_REF(error)); } - proxy_connection_unref(exec_ctx, conn); + proxy_connection_unref(exec_ctx, conn, "conn_failed"); } // Callback for writing proxy data to the client. @@ -163,7 +180,7 @@ static void on_client_write_done(grpc_exec_ctx* exec_ctx, void* arg, &conn->on_client_write_done); } else { // No more writes. Unref the connection. - proxy_connection_unref(exec_ctx, conn); + proxy_connection_unref(exec_ctx, conn, "write_done"); } } @@ -188,7 +205,7 @@ static void on_server_write_done(grpc_exec_ctx* exec_ctx, void* arg, &conn->on_server_write_done); } else { // No more writes. Unref the connection. - proxy_connection_unref(exec_ctx, conn); + proxy_connection_unref(exec_ctx, conn, "server_write"); } } @@ -214,7 +231,7 @@ static void on_client_read_done(grpc_exec_ctx* exec_ctx, void* arg, } else { grpc_slice_buffer_move_into(&conn->client_read_buffer, &conn->server_write_buffer); - gpr_ref(&conn->refcount); + proxy_connection_ref(conn, "client_read"); grpc_endpoint_write(exec_ctx, conn->server_endpoint, &conn->server_write_buffer, &conn->on_server_write_done); @@ -246,7 +263,7 @@ static void on_server_read_done(grpc_exec_ctx* exec_ctx, void* arg, } else { grpc_slice_buffer_move_into(&conn->server_read_buffer, &conn->client_write_buffer); - gpr_ref(&conn->refcount); + proxy_connection_ref(conn, "server_read"); grpc_endpoint_write(exec_ctx, conn->client_endpoint, &conn->client_write_buffer, &conn->on_client_write_done); @@ -270,7 +287,9 @@ static void on_write_response_done(grpc_exec_ctx* exec_ctx, void* arg, // Start reading from both client and server. One of the read // requests inherits our ref to conn, but we need to take a new ref // for the other one. - gpr_ref(&conn->refcount); + proxy_connection_ref(conn, "client_read"); + proxy_connection_ref(conn, "server_read"); + proxy_connection_unref(exec_ctx, conn, "write_response"); grpc_endpoint_read(exec_ctx, conn->client_endpoint, &conn->client_read_buffer, &conn->on_client_read_done); grpc_endpoint_read(exec_ctx, conn->server_endpoint, &conn->server_read_buffer, @@ -312,6 +331,8 @@ static void on_server_connect_done(grpc_exec_ctx* exec_ctx, void* arg, static void on_read_request_done(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { proxy_connection* conn = arg; + gpr_log(GPR_DEBUG, "on_read_request_done: %p %s", conn, + grpc_error_string(error)); if (error != GRPC_ERROR_NONE) { proxy_connection_failed(exec_ctx, conn, true /* is_client */, "HTTP proxy read request", error); @@ -376,12 +397,15 @@ static void on_accept(grpc_exec_ctx* exec_ctx, void* arg, gpr_free(acceptor); grpc_end2end_http_proxy* proxy = arg; // Instantiate proxy_connection. - proxy_connection* conn = gpr_malloc(sizeof(*conn)); - memset(conn, 0, sizeof(*conn)); + proxy_connection* conn = gpr_zalloc(sizeof(*conn)); + gpr_ref(&proxy->users); conn->client_endpoint = endpoint; + conn->proxy = proxy; gpr_ref_init(&conn->refcount, 1); conn->pollset_set = grpc_pollset_set_create(); + gpr_log(GPR_DEBUG, "on_accept: %p", conn); grpc_pollset_set_add_pollset(exec_ctx, conn->pollset_set, proxy->pollset); + grpc_endpoint_add_to_pollset_set(exec_ctx, endpoint, conn->pollset_set); grpc_closure_init(&conn->on_read_request_done, on_read_request_done, conn, grpc_schedule_on_exec_ctx); grpc_closure_init(&conn->on_server_connect_done, on_server_connect_done, conn, @@ -416,6 +440,7 @@ static void thread_main(void* arg) { grpc_end2end_http_proxy* proxy = arg; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; do { + gpr_ref(&proxy->users); const gpr_timespec now = gpr_now(GPR_CLOCK_MONOTONIC); const gpr_timespec deadline = gpr_time_add(now, gpr_time_from_seconds(1, GPR_TIMESPAN)); @@ -426,7 +451,7 @@ static void thread_main(void* arg) { grpc_pollset_work(&exec_ctx, proxy->pollset, &worker, now, deadline)); gpr_mu_unlock(proxy->mu); grpc_exec_ctx_flush(&exec_ctx); - } while (!gpr_atm_acq_load(&proxy->shutdown)); + } while (!gpr_unref(&proxy->users)); grpc_exec_ctx_finish(&exec_ctx); } @@ -434,6 +459,7 @@ grpc_end2end_http_proxy* grpc_end2end_http_proxy_create(void) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_end2end_http_proxy* proxy = gpr_malloc(sizeof(*proxy)); memset(proxy, 0, sizeof(*proxy)); + gpr_ref_init(&proxy->users, 1); // Construct proxy address. const int proxy_port = grpc_pick_unused_port_or_die(); gpr_join_host_port(&proxy->proxy_name, "localhost", proxy_port); @@ -474,17 +500,16 @@ static void destroy_pollset(grpc_exec_ctx* exec_ctx, void* arg, } void grpc_end2end_http_proxy_destroy(grpc_end2end_http_proxy* proxy) { - gpr_atm_rel_store(&proxy->shutdown, 1); // Signal proxy thread to shutdown. + gpr_unref(&proxy->users); // Signal proxy thread to shutdown. grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; gpr_thd_join(proxy->thd); grpc_tcp_server_shutdown_listeners(&exec_ctx, proxy->server); grpc_tcp_server_unref(&exec_ctx, proxy->server); gpr_free(proxy->proxy_name); grpc_channel_args_destroy(&exec_ctx, proxy->channel_args); - grpc_closure destroyed; - grpc_closure_init(&destroyed, destroy_pollset, proxy->pollset, - grpc_schedule_on_exec_ctx); - grpc_pollset_shutdown(&exec_ctx, proxy->pollset, &destroyed); + grpc_pollset_shutdown(&exec_ctx, proxy->pollset, + grpc_closure_create(destroy_pollset, proxy->pollset, + grpc_schedule_on_exec_ctx)); gpr_free(proxy); grpc_exec_ctx_finish(&exec_ctx); } diff --git a/test/core/end2end/tests/cancel_after_invoke.c b/test/core/end2end/tests/cancel_after_invoke.c index f2aca737ab..5bc9ed283b 100644 --- a/test/core/end2end/tests/cancel_after_invoke.c +++ b/test/core/end2end/tests/cancel_after_invoke.c @@ -49,11 +49,12 @@ static void *tag(intptr_t t) { return (void *)t; } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, const char *test_name, cancellation_mode mode, + size_t test_ops, grpc_channel_args *client_args, grpc_channel_args *server_args) { grpc_end2end_test_fixture f; - gpr_log(GPR_INFO, "Running test: %s/%s/%s", test_name, config.name, - mode.name); + gpr_log(GPR_INFO, "Running test: %s/%s/%s [%" PRIdPTR " ops]", test_name, + config.name, mode.name, test_ops); f = config.create_fixture(client_args, server_args); config.init_server(&f, server_args); config.init_client(&f, client_args); @@ -108,8 +109,8 @@ static void test_cancel_after_invoke(grpc_end2end_test_config config, grpc_op ops[6]; grpc_op *op; grpc_call *c; - grpc_end2end_test_fixture f = - begin_test(config, "test_cancel_after_invoke", mode, NULL, NULL); + grpc_end2end_test_fixture f = begin_test(config, "test_cancel_after_invoke", + mode, test_ops, NULL, NULL); cq_verifier *cqv = cq_verifier_create(f.cq); grpc_metadata_array initial_metadata_recv; grpc_metadata_array trailing_metadata_recv; -- cgit v1.2.3 From b2b4122c03271a16898c872b13986914ba424116 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 21 Apr 2017 19:05:59 -0700 Subject: Remove logging --- test/core/end2end/fixtures/http_proxy_fixture.c | 6 ------ 1 file changed, 6 deletions(-) (limited to 'test') diff --git a/test/core/end2end/fixtures/http_proxy_fixture.c b/test/core/end2end/fixtures/http_proxy_fixture.c index 02235d96e7..a9d71b5ba4 100644 --- a/test/core/end2end/fixtures/http_proxy_fixture.c +++ b/test/core/end2end/fixtures/http_proxy_fixture.c @@ -107,18 +107,12 @@ typedef struct proxy_connection { } proxy_connection; static void proxy_connection_ref(proxy_connection* conn, const char* reason) { - gpr_log(GPR_DEBUG, "proxy_connection_ref: %p %s %" PRIdPTR " --> %" PRIdPTR, - conn, reason, gpr_atm_no_barrier_load(&conn->refcount.count), - gpr_atm_no_barrier_load(&conn->refcount.count) - 1); gpr_ref(&conn->refcount); } // Helper function to destroy the proxy connection. static void proxy_connection_unref(grpc_exec_ctx* exec_ctx, proxy_connection* conn, const char* reason) { - gpr_log(GPR_DEBUG, "proxy_connection_unref: %p %s %" PRIdPTR " --> %" PRIdPTR, - conn, reason, gpr_atm_no_barrier_load(&conn->refcount.count), - gpr_atm_no_barrier_load(&conn->refcount.count) - 1); if (gpr_unref(&conn->refcount)) { gpr_log(GPR_DEBUG, "endpoints: %p %p", conn->client_endpoint, conn->server_endpoint); -- cgit v1.2.3 From 4a1925444d81ba09878c55d8576cf981d601990c Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 21 Apr 2017 19:07:00 -0700 Subject: Remove more spam --- test/core/end2end/fixtures/http_proxy_fixture.c | 1 - 1 file changed, 1 deletion(-) (limited to 'test') diff --git a/test/core/end2end/fixtures/http_proxy_fixture.c b/test/core/end2end/fixtures/http_proxy_fixture.c index a9d71b5ba4..f0d09487c6 100644 --- a/test/core/end2end/fixtures/http_proxy_fixture.c +++ b/test/core/end2end/fixtures/http_proxy_fixture.c @@ -397,7 +397,6 @@ static void on_accept(grpc_exec_ctx* exec_ctx, void* arg, conn->proxy = proxy; gpr_ref_init(&conn->refcount, 1); conn->pollset_set = grpc_pollset_set_create(); - gpr_log(GPR_DEBUG, "on_accept: %p", conn); grpc_pollset_set_add_pollset(exec_ctx, conn->pollset_set, proxy->pollset); grpc_endpoint_add_to_pollset_set(exec_ctx, endpoint, conn->pollset_set); grpc_closure_init(&conn->on_read_request_done, on_read_request_done, conn, -- cgit v1.2.3