diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/core/handshake/client_ssl.c | 4 | ||||
-rw-r--r-- | test/core/iomgr/ev_epoll_linux_test.c | 128 | ||||
-rw-r--r-- | test/cpp/interop/stress_test.cc | 66 |
3 files changed, 112 insertions, 86 deletions
diff --git a/test/core/handshake/client_ssl.c b/test/core/handshake/client_ssl.c index 24281e0b41..613251b835 100644 --- a/test/core/handshake/client_ssl.c +++ b/test/core/handshake/client_ssl.c @@ -104,7 +104,8 @@ static int alpn_select_cb(SSL *ssl, const uint8_t **out, uint8_t *out_len, bool grpc_exp_seen = false; bool h2_seen = false; const char *inp = (const char *)in; - for (int i = 0; i < (int)in_len; ++i) { + const char *in_end = inp + in_len; + while (inp < in_end) { const size_t length = (size_t)*inp++; if (length == strlen("grpc-exp") && strncmp(inp, "grpc-exp", length) == 0) { grpc_exp_seen = true; @@ -117,6 +118,7 @@ static int alpn_select_cb(SSL *ssl, const uint8_t **out, uint8_t *out_len, inp += length; } + GPR_ASSERT(inp == in_end); GPR_ASSERT(grpc_exp_seen); GPR_ASSERT(h2_seen); diff --git a/test/core/iomgr/ev_epoll_linux_test.c b/test/core/iomgr/ev_epoll_linux_test.c index 40ae91bc6d..d95d552773 100644 --- a/test/core/iomgr/ev_epoll_linux_test.c +++ b/test/core/iomgr/ev_epoll_linux_test.c @@ -45,6 +45,7 @@ #include <grpc/support/log.h> #include "src/core/lib/iomgr/iomgr.h" +#include "src/core/lib/iomgr/workqueue.h" #include "test/core/util/test_config.h" typedef struct test_pollset { @@ -60,6 +61,22 @@ typedef struct test_fd { /* num_fds should be an even number */ static void test_fd_init(test_fd *tfds, int *fds, int num_fds) { int i; + int r; + + /* Create some dummy file descriptors. Currently using pipe file descriptors + * for this test but we could use any other type of file descriptors. Also, + * since pipe() used in this test creates two fds in each call, num_fds should + * be an even number */ + GPR_ASSERT((num_fds % 2) == 0); + for (i = 0; i < num_fds; i = i + 2) { + r = pipe(fds + i); + if (r != 0) { + gpr_log(GPR_ERROR, "Error in creating pipe. %d (%s)", errno, + strerror(errno)); + return; + } + } + for (i = 0; i < num_fds; i++) { tfds[i].inner_fd = fds[i]; tfds[i].fd = grpc_fd_create(fds[i], "test_fd"); @@ -111,8 +128,80 @@ static void test_pollset_cleanup(grpc_exec_ctx *exec_ctx, } } -#define NUM_FDS 8 -#define NUM_POLLSETS 4 +static void increment(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) { + ++*(int *)arg; +} + +/* + * Validate that merging two workqueues preserves the closures in each queue. + * This is a regression test for a bug in + * polling_island_merge()[ev_epoll_linux.c], where the parent relationship was + * inverted. + */ +static void test_pollset_queue_merge_items() { + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + const int num_fds = 2; + const int num_pollsets = 2; + const int num_closures = 4; + test_fd tfds[num_fds]; + int fds[num_fds]; + test_pollset pollsets[num_pollsets]; + grpc_closure closures[num_closures]; + int i; + int result = 0; + + test_fd_init(tfds, fds, num_fds); + test_pollset_init(pollsets, num_pollsets); + + /* Two distinct polling islands, each with their own FD and pollset. */ + for (i = 0; i < num_fds; i++) { + grpc_pollset_add_fd(&exec_ctx, pollsets[i].pollset, tfds[i].fd); + grpc_exec_ctx_flush(&exec_ctx); + } + + /* Enqeue the closures, 3 to polling island 0 and 1 to polling island 1. */ + grpc_closure_init( + closures, increment, &result, + grpc_workqueue_scheduler(grpc_fd_get_polling_island(tfds[0].fd))); + grpc_closure_init( + closures + 1, increment, &result, + grpc_workqueue_scheduler(grpc_fd_get_polling_island(tfds[0].fd))); + grpc_closure_init( + closures + 2, increment, &result, + grpc_workqueue_scheduler(grpc_fd_get_polling_island(tfds[0].fd))); + grpc_closure_init( + closures + 3, increment, &result, + grpc_workqueue_scheduler(grpc_fd_get_polling_island(tfds[1].fd))); + for (i = 0; i < num_closures; ++i) { + grpc_closure_sched(&exec_ctx, closures + i, GRPC_ERROR_NONE); + } + + /* Merge the two polling islands. */ + grpc_pollset_add_fd(&exec_ctx, pollsets[0].pollset, tfds[1].fd); + grpc_exec_ctx_flush(&exec_ctx); + + /* + * Execute the closures, verify we see each one execute when executing work on + * the merged polling island. + */ + grpc_pollset_worker *worker = NULL; + for (i = 0; i < num_closures; ++i) { + const gpr_timespec deadline = gpr_time_add( + gpr_now(GPR_CLOCK_MONOTONIC), gpr_time_from_seconds(2, GPR_TIMESPAN)); + gpr_mu_lock(pollsets[1].mu); + GRPC_LOG_IF_ERROR( + "grpc_pollset_work", + grpc_pollset_work(&exec_ctx, pollsets[1].pollset, &worker, + gpr_now(GPR_CLOCK_MONOTONIC), deadline)); + gpr_mu_unlock(pollsets[1].mu); + } + GPR_ASSERT(result == num_closures); + + test_fd_cleanup(&exec_ctx, tfds, num_fds); + test_pollset_cleanup(&exec_ctx, pollsets, num_pollsets); + grpc_exec_ctx_finish(&exec_ctx); +} + /* * Cases to test: * case 1) Polling islands of both fd and pollset are NULL @@ -125,28 +214,16 @@ static void test_pollset_cleanup(grpc_exec_ctx *exec_ctx, * */ static void test_add_fd_to_pollset() { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - test_fd tfds[NUM_FDS]; - int fds[NUM_FDS]; - test_pollset pollsets[NUM_POLLSETS]; + const int num_fds = 8; + const int num_pollsets = 4; + test_fd tfds[num_fds]; + int fds[num_fds]; + test_pollset pollsets[num_pollsets]; void *expected_pi = NULL; int i; - int r; - /* Create some dummy file descriptors. Currently using pipe file descriptors - * for this test but we could use any other type of file descriptors. Also, - * since pipe() used in this test creates two fds in each call, NUM_FDS should - * be an even number */ - for (i = 0; i < NUM_FDS; i = i + 2) { - r = pipe(fds + i); - if (r != 0) { - gpr_log(GPR_ERROR, "Error in creating pipe. %d (%s)", errno, - strerror(errno)); - return; - } - } - - test_fd_init(tfds, fds, NUM_FDS); - test_pollset_init(pollsets, NUM_POLLSETS); + test_fd_init(tfds, fds, num_fds); + test_pollset_init(pollsets, num_pollsets); /*Step 1. * Create three polling islands (This will exercise test case 1 and 2) with @@ -207,19 +284,19 @@ static void test_add_fd_to_pollset() { /* Compare Fd:0's polling island with that of all other Fds */ expected_pi = grpc_fd_get_polling_island(tfds[0].fd); - for (i = 1; i < NUM_FDS; i++) { + for (i = 1; i < num_fds; i++) { GPR_ASSERT(grpc_are_polling_islands_equal( expected_pi, grpc_fd_get_polling_island(tfds[i].fd))); } /* Compare Fd:0's polling island with that of all other pollsets */ - for (i = 0; i < NUM_POLLSETS; i++) { + for (i = 0; i < num_pollsets; i++) { GPR_ASSERT(grpc_are_polling_islands_equal( expected_pi, grpc_pollset_get_polling_island(pollsets[i].pollset))); } - test_fd_cleanup(&exec_ctx, tfds, NUM_FDS); - test_pollset_cleanup(&exec_ctx, pollsets, NUM_POLLSETS); + test_fd_cleanup(&exec_ctx, tfds, num_fds); + test_pollset_cleanup(&exec_ctx, pollsets, num_pollsets); grpc_exec_ctx_finish(&exec_ctx); } @@ -231,6 +308,7 @@ int main(int argc, char **argv) { poll_strategy = grpc_get_poll_strategy_name(); if (poll_strategy != NULL && strcmp(poll_strategy, "epoll") == 0) { test_add_fd_to_pollset(); + test_pollset_queue_merge_items(); } else { gpr_log(GPR_INFO, "Skipping the test. The test is only relevant for 'epoll' " diff --git a/test/cpp/interop/stress_test.cc b/test/cpp/interop/stress_test.cc index 562522de77..fdc0a613f3 100644 --- a/test/cpp/interop/stress_test.cc +++ b/test/cpp/interop/stress_test.cc @@ -45,9 +45,9 @@ #include "src/proto/grpc/testing/metrics.grpc.pb.h" #include "src/proto/grpc/testing/metrics.pb.h" -#include "test/cpp/interop/client_helper.h" #include "test/cpp/interop/interop_client.h" #include "test/cpp/interop/stress_interop_client.h" +#include "test/cpp/util/create_test_channel.h" #include "test/cpp/util/metrics_server.h" #include "test/cpp/util/test_config.h" @@ -67,9 +67,7 @@ DEFINE_int32(test_duration_secs, -1, " forcefully terminated."); DEFINE_string(server_addresses, "localhost:8080", - "The list of server" - "addresses. This option is ignored if either\n" - "server_port or server_host is specified. The format is: \n" + "The list of server addresses. The format is: \n" " \"<name_1>:<port_1>,<name_2>:<port_1>...<name_N>:<port_N>\"\n" " Note: <name> can be servername or IP address."); @@ -80,34 +78,6 @@ DEFINE_int32(num_stubs_per_channel, 1, "indicates the max number of parallel RPC calls on each channel " "at any given time."); -DEFINE_string(test_case, "", - "Configure different test cases. Valid options are:\n\n" - "all : all test cases;\n" - "cancel_after_begin : cancel stream after starting it;\n" - "cancel_after_first_response: cancel on first response;\n" - "client_compressed_streaming : compressed request streaming with " - "client_compressed_unary : single compressed request;\n" - "client_streaming : request streaming with single response;\n" - "compute_engine_creds: large_unary with compute engine auth;\n" - "custom_metadata: server will echo custom metadata;\n" - "empty_stream : bi-di stream with no request/response;\n" - "empty_unary : empty (zero bytes) request and response;\n" - "half_duplex : half-duplex streaming;\n" - "jwt_token_creds: large_unary with JWT token auth;\n" - "large_unary : single request and (large) response;\n" - "oauth2_auth_token: raw oauth2 access token auth;\n" - "per_rpc_creds: raw oauth2 access token on a single rpc;\n" - "ping_pong : full-duplex streaming;\n" - "response streaming;\n" - "server_compressed_streaming : single request with compressed " - "server_compressed_unary : single compressed response;\n" - "server_streaming : single request with response streaming;\n" - "slow_consumer : single request with response streaming with " - "slow client consumer;\n" - "status_code_and_message: verify status code & message;\n" - "timeout_on_sleeping_server: deadline exceeds on stream;\n" - "unimplemented_method: client calls an unimplemented_method;\n"); - // TODO(sreek): Add more test cases here in future DEFINE_string(test_cases, "", "List of test cases to call along with the" @@ -147,14 +117,9 @@ DEFINE_bool(do_not_abort_on_transient_failures, true, // Options from client.cc (for compatibility with interop test). // TODO(sreek): Consolidate overlapping options DEFINE_bool(use_tls, false, "Whether to use tls."); -DEFINE_string(custom_credentials_type, "", "User provided credentials type."); DEFINE_bool(use_test_ca, false, "False to use SSL roots for google"); -DEFINE_int32(server_port, 0, "Server port."); -DEFINE_string(server_host, "127.0.0.1", "Server host to connect to"); DEFINE_string(server_host_override, "foo.test.google.fr", "Override the server host which is sent in HTTP header"); -DEFINE_string(service_account_key_file, "", - "Path to service account json key file."); using grpc::testing::kTestCaseList; using grpc::testing::MetricsService; @@ -241,8 +206,6 @@ bool ParseTestCasesString(const grpc::string& test_cases, void LogParameterInfo(const std::vector<grpc::string>& addresses, const std::vector<std::pair<TestCaseType, int>>& tests) { gpr_log(GPR_INFO, "server_addresses: %s", FLAGS_server_addresses.c_str()); - gpr_log(GPR_INFO, "server_host: %s", FLAGS_server_host.c_str()); - gpr_log(GPR_INFO, "server_port: %d", FLAGS_server_port); gpr_log(GPR_INFO, "test_cases : %s", FLAGS_test_cases.c_str()); gpr_log(GPR_INFO, "sleep_duration_ms: %d", FLAGS_sleep_duration_ms); gpr_log(GPR_INFO, "test_duration_secs: %d", FLAGS_test_duration_secs); @@ -286,24 +249,11 @@ int main(int argc, char** argv) { // Parse the server addresses std::vector<grpc::string> server_addresses; - if (FLAGS_server_port != 0) { - // We are using interop_client style cmdline options. - const int host_port_buf_size = 1024; - char host_port[host_port_buf_size]; - snprintf(host_port, host_port_buf_size, "%s:%d", FLAGS_server_host.c_str(), - FLAGS_server_port); - std::string host_port_str(host_port); - ParseCommaDelimitedString(host_port_str, server_addresses); - } else { - ParseCommaDelimitedString(FLAGS_server_addresses, server_addresses); - } + ParseCommaDelimitedString(FLAGS_server_addresses, server_addresses); // Parse test cases and weights if (FLAGS_test_cases.length() == 0) { - // We are using interop_client style test_case option - FLAGS_test_cases = FLAGS_test_case + ":100"; - } else if (FLAGS_test_case != "") { - gpr_log(GPR_ERROR, "specify --test_case or --test_cases but not both."); + gpr_log(GPR_ERROR, "No test cases supplied"); return 1; } @@ -341,12 +291,8 @@ int main(int argc, char** argv) { channel_idx++) { gpr_log(GPR_INFO, "Starting test with %s channel_idx=%d..", it->c_str(), channel_idx); - std::shared_ptr<grpc::Channel> channel; - if (FLAGS_use_tls) { - channel = grpc::testing::CreateChannelForTestCase(FLAGS_test_case); - } else { - channel = grpc::CreateChannel(*it, grpc::InsecureChannelCredentials()); - } + std::shared_ptr<grpc::Channel> channel = grpc::CreateTestChannel( + *it, FLAGS_server_host_override, FLAGS_use_tls, !FLAGS_use_test_ca); // Create stub(s) for each channel for (int stub_idx = 0; stub_idx < FLAGS_num_stubs_per_channel; |