diff options
author | David Garcia Quintas <dgq@google.com> | 2016-07-13 23:09:34 -0700 |
---|---|---|
committer | David Garcia Quintas <dgq@google.com> | 2016-07-13 23:48:20 -0700 |
commit | 824363dc2f521d0712ab7d6bc03f15939ea51aa5 (patch) | |
tree | 43b79398d90565b19082e3e177016bfb93f63d34 /test/core | |
parent | c0299df85decd3197c45550f19c874a8d96b8318 (diff) |
Simplified LR filter
Diffstat (limited to 'test/core')
-rw-r--r-- | test/core/end2end/fixtures/h2_load_reporting.c | 125 | ||||
-rwxr-xr-x | test/core/end2end/gen_build_yaml.py | 1 | ||||
-rw-r--r-- | test/core/end2end/tests/load_reporting_hook.c | 107 |
3 files changed, 171 insertions, 62 deletions
diff --git a/test/core/end2end/fixtures/h2_load_reporting.c b/test/core/end2end/fixtures/h2_load_reporting.c new file mode 100644 index 0000000000..f6d3923db9 --- /dev/null +++ b/test/core/end2end/fixtures/h2_load_reporting.c @@ -0,0 +1,125 @@ +/* + * + * Copyright 2016, 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 "test/core/end2end/end2end_tests.h" + +#include <string.h> + +#include <grpc/support/alloc.h> +#include <grpc/support/host_port.h> +#include <grpc/support/log.h> +#include <grpc/support/sync.h> +#include <grpc/support/thd.h> +#include <grpc/support/useful.h> +#include "src/core/ext/client_config/client_channel.h" +#include "src/core/ext/load_reporting/load_reporting.h" +#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h" +#include "src/core/lib/channel/channel_args.h" +#include "src/core/lib/channel/connected_channel.h" +#include "src/core/lib/channel/http_server_filter.h" +#include "src/core/lib/surface/channel.h" +#include "src/core/lib/surface/server.h" +#include "test/core/util/port.h" +#include "test/core/util/test_config.h" + +typedef struct load_reporting_fixture_data { + char *localaddr; +} load_reporting_fixture_data; + +static grpc_end2end_test_fixture chttp2_create_fixture_load_reporting( + grpc_channel_args *client_args, grpc_channel_args *server_args) { + grpc_end2end_test_fixture f; + int port = grpc_pick_unused_port_or_die(); + load_reporting_fixture_data *ffd = + gpr_malloc(sizeof(load_reporting_fixture_data)); + memset(&f, 0, sizeof(f)); + + gpr_join_host_port(&ffd->localaddr, "localhost", port); + + f.fixture_data = ffd; + f.cq = grpc_completion_queue_create(NULL); + + return f; +} + +void chttp2_init_client_load_reporting(grpc_end2end_test_fixture *f, + grpc_channel_args *client_args) { + load_reporting_fixture_data *ffd = f->fixture_data; + f->client = grpc_insecure_channel_create(ffd->localaddr, client_args, NULL); + GPR_ASSERT(f->client); +} + +void chttp2_init_server_load_reporting(grpc_end2end_test_fixture *f, + grpc_channel_args *server_args) { + load_reporting_fixture_data *ffd = f->fixture_data; + grpc_arg arg = grpc_load_reporting_enable_arg(); + if (f->server) { + grpc_server_destroy(f->server); + } + server_args = grpc_channel_args_copy_and_add(server_args, &arg, 1); + f->server = grpc_server_create(server_args, NULL); + grpc_channel_args_destroy(server_args); + grpc_server_register_completion_queue(f->server, f->cq, NULL); + GPR_ASSERT(grpc_server_add_insecure_http2_port(f->server, ffd->localaddr)); + grpc_server_start(f->server); +} + +void chttp2_tear_down_load_reporting(grpc_end2end_test_fixture *f) { + load_reporting_fixture_data *ffd = f->fixture_data; + gpr_free(ffd->localaddr); + gpr_free(ffd); +} + +/* All test configurations */ +static grpc_end2end_test_config configs[] = { + {"chttp2/fullstack+load_reporting", + FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION, + chttp2_create_fixture_load_reporting, chttp2_init_client_load_reporting, + chttp2_init_server_load_reporting, chttp2_tear_down_load_reporting}, +}; + +int main(int argc, char **argv) { + size_t i; + + grpc_test_init(argc, argv); + grpc_end2end_tests_pre_init(); + grpc_init(); + + for (i = 0; i < sizeof(configs) / sizeof(*configs); i++) { + grpc_end2end_tests(argc, argv, configs[i]); + } + + grpc_shutdown(); + + return 0; +} diff --git a/test/core/end2end/gen_build_yaml.py b/test/core/end2end/gen_build_yaml.py index 2bd028a45a..1c948ba24a 100755 --- a/test/core/end2end/gen_build_yaml.py +++ b/test/core/end2end/gen_build_yaml.py @@ -53,6 +53,7 @@ fd_unsecure_fixture_options = default_unsecure_fixture_options._replace( END2END_FIXTURES = { 'h2_compress': default_unsecure_fixture_options, 'h2_census': default_unsecure_fixture_options, + 'h2_load_reporting': default_unsecure_fixture_options, 'h2_fakesec': default_secure_fixture_options._replace(ci_mac=False), 'h2_fd': fd_unsecure_fixture_options, 'h2_full': default_unsecure_fixture_options, diff --git a/test/core/end2end/tests/load_reporting_hook.c b/test/core/end2end/tests/load_reporting_hook.c index b0f066e6f3..40ffa19c3f 100644 --- a/test/core/end2end/tests/load_reporting_hook.c +++ b/test/core/end2end/tests/load_reporting_hook.c @@ -44,6 +44,7 @@ #include "test/core/end2end/cq_verifier.h" #include "src/core/ext/load_reporting/load_reporting.h" +#include "src/core/ext/load_reporting/load_reporting_filter.h" #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/transport/static_metadata.h" @@ -56,64 +57,54 @@ typedef struct { intptr_t channel_id; intptr_t call_id; - uint32_t call_creation_token; /* expected 0xCAFED00D */ - uint32_t call_destruction_token; /* expected 0xDEADD00D */ - uint32_t channel_creation_token; /* expected 0xCAFEFACE */ - uint32_t channel_destruction_token; /* expected 0xDEADFACE */ - char *initial_md_str; char *trailing_md_str; char *method_name; uint64_t incoming_bytes; uint64_t outgoing_bytes; - bool fully_processed; -} aggregated_bw_stats; -static void sample_fn(const grpc_load_reporting_call_data *call_data, - void *user_data) { - GPR_ASSERT(user_data != NULL); + grpc_status_code call_final_status; + + bool fully_processed; +} load_reporting_data; - aggregated_bw_stats *custom_stats = (aggregated_bw_stats *)user_data; - gpr_mu_lock(&custom_stats->mu); +static load_reporting_data lr_data; +static void load_reporting_test_fn( + const grpc_load_reporting_call_data *call_data) { + gpr_mu_lock(&lr_data.mu); switch (call_data->source) { case GRPC_LR_POINT_CHANNEL_CREATION: - custom_stats->channel_creation_token = 0xCAFEFACE; - custom_stats->channel_id = call_data->channel_id; + lr_data.channel_id = call_data->channel_id; break; case GRPC_LR_POINT_CHANNEL_DESTRUCTION: - custom_stats->channel_destruction_token = 0xDEADFACE; break; case GRPC_LR_POINT_CALL_CREATION: - custom_stats->call_creation_token = 0xCAFED00D; - custom_stats->call_id = call_data->call_id; + lr_data.call_id = call_data->call_id; break; case GRPC_LR_POINT_CALL_DESTRUCTION: - if (custom_stats->initial_md_str == NULL) { - custom_stats->initial_md_str = gpr_strdup(call_data->initial_md_string); + if (lr_data.initial_md_str == NULL) { + lr_data.initial_md_str = gpr_strdup(call_data->initial_md_string); } - if (custom_stats->trailing_md_str == NULL) { - custom_stats->trailing_md_str = - gpr_strdup(call_data->trailing_md_string); + if (lr_data.trailing_md_str == NULL) { + lr_data.trailing_md_str = gpr_strdup(call_data->trailing_md_string); } - if (custom_stats->method_name == NULL) { - custom_stats->method_name = gpr_strdup(call_data->method_name); + if (lr_data.method_name == NULL) { + lr_data.method_name = gpr_strdup(call_data->method_name); } - custom_stats->call_destruction_token = 0xDEADD00D; - custom_stats->incoming_bytes = - call_data->final_info->stats.transport_stream_stats.incoming - .data_bytes; - custom_stats->outgoing_bytes = - call_data->final_info->stats.transport_stream_stats.outgoing - .data_bytes; - custom_stats->fully_processed = true; + lr_data.incoming_bytes = call_data->final_info->stats + .transport_stream_stats.incoming.data_bytes; + lr_data.outgoing_bytes = call_data->final_info->stats + .transport_stream_stats.outgoing.data_bytes; + lr_data.call_final_status = call_data->final_info->final_status; + lr_data.fully_processed = true; break; default: abort(); } - gpr_mu_unlock(&custom_stats->mu); + gpr_mu_unlock(&lr_data.mu); } static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, @@ -319,17 +310,16 @@ static void request_response_with_payload(grpc_end2end_test_fixture f, grpc_byte_buffer_destroy(response_payload_recv); } -static void test_load_reporting_hook(grpc_end2end_test_config config) { - aggregated_bw_stats *aggr_stats_server = - gpr_malloc(sizeof(aggregated_bw_stats)); - memset(aggr_stats_server, 0, sizeof(aggregated_bw_stats)); - gpr_mu_init(&aggr_stats_server->mu); +/* override the default for testing purposes */ +extern void (*g_load_reporting_fn)( + const grpc_load_reporting_call_data *call_data); - grpc_load_reporting_config *server_lrc = - grpc_load_reporting_config_create(sample_fn, aggr_stats_server); +static void test_load_reporting_hook(grpc_end2end_test_config config) { + gpr_mu_init(&lr_data.mu); + g_load_reporting_fn = load_reporting_test_fn; /* Introduce load reporting for the server through its arguments */ - grpc_arg arg = grpc_load_reporting_config_create_arg(server_lrc); + grpc_arg arg = grpc_load_reporting_enable_arg(); grpc_channel_args *lr_server_args = grpc_channel_args_copy_and_add(NULL, &arg, 1); @@ -361,32 +351,25 @@ static void test_load_reporting_hook(grpc_end2end_test_config config) { grpc_channel_args_destroy(lr_server_args); config.tear_down_data(&f); - GPR_ASSERT(aggr_stats_server->fully_processed); - GPR_ASSERT(aggr_stats_server->incoming_bytes == strlen(request_msg)); - GPR_ASSERT(aggr_stats_server->outgoing_bytes == strlen(response_msg)); - - GPR_ASSERT(aggr_stats_server->call_id > 0); - GPR_ASSERT(aggr_stats_server->channel_id > 0); + GPR_ASSERT(lr_data.fully_processed); + GPR_ASSERT(lr_data.incoming_bytes == strlen(request_msg)); + GPR_ASSERT(lr_data.outgoing_bytes == strlen(response_msg)); - GPR_ASSERT(aggr_stats_server->channel_creation_token == 0xCAFEFACE); - GPR_ASSERT(aggr_stats_server->channel_destruction_token == 0xDEADFACE); + GPR_ASSERT(lr_data.call_id > 0); + GPR_ASSERT(lr_data.channel_id > 0); - GPR_ASSERT(aggr_stats_server->call_creation_token == 0xCAFED00D); - GPR_ASSERT(aggr_stats_server->call_destruction_token == 0xDEADD00D); + GPR_ASSERT(strcmp(lr_data.method_name, "/gRPCFTW") == 0); - GPR_ASSERT(strcmp(aggr_stats_server->method_name, "/gRPCFTW") == 0); + GPR_ASSERT(lr_data.initial_md_str != NULL); + GPR_ASSERT(lr_data.trailing_md_str != NULL); + GPR_ASSERT(strcmp(lr_data.initial_md_str, "client-token") == 0); + GPR_ASSERT(strcmp(lr_data.trailing_md_str, "server-token") == 0); - GPR_ASSERT(aggr_stats_server->initial_md_str != NULL); - GPR_ASSERT(aggr_stats_server->trailing_md_str != NULL); - GPR_ASSERT(strcmp(aggr_stats_server->initial_md_str, "client-token") == 0); - GPR_ASSERT(strcmp(aggr_stats_server->trailing_md_str, "server-token") == 0); + GPR_ASSERT(lr_data.call_final_status == GRPC_STATUS_OK); - gpr_free(aggr_stats_server->initial_md_str); - gpr_free(aggr_stats_server->trailing_md_str); - gpr_free(aggr_stats_server->method_name); - gpr_mu_destroy(&aggr_stats_server->mu); - gpr_free(aggr_stats_server); - grpc_load_reporting_config_destroy(server_lrc); + gpr_free(lr_data.initial_md_str); + gpr_free(lr_data.trailing_md_str); + gpr_free(lr_data.method_name); } void load_reporting_hook(grpc_end2end_test_config config) { |