int main(int argc, char **argv) { int i; struct rlimit rlim; grpc_endpoint_pair p; grpc_test_init(argc, argv); grpc_iomgr_init(); /* set max # of file descriptors to a low value, and verify we can create and destroy many more than this number of descriptors */ rlim.rlim_cur = rlim.rlim_max = 10; GPR_ASSERT(0 == setrlimit(RLIMIT_NOFILE, &rlim)); for (i = 0; i < 100; i++) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; p = grpc_iomgr_create_endpoint_pair("test", 1); grpc_endpoint_destroy(&exec_ctx, p.client); grpc_endpoint_destroy(&exec_ctx, p.server); grpc_exec_ctx_finish(&exec_ctx); } grpc_iomgr_shutdown(); return 0; }
void grpc_shutdown(void) { int i; GRPC_API_TRACE("grpc_shutdown(void)", 0, ()); grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INITIALIZER(0, grpc_never_ready_to_finish, NULL); gpr_mu_lock(&g_init_mu); if (--g_initializations == 0) { grpc_executor_shutdown(&exec_ctx); grpc_timer_manager_set_threading(false); // shutdown timer_manager thread for (i = g_number_of_plugins; i >= 0; i--) { if (g_all_of_the_plugins[i].destroy != NULL) { g_all_of_the_plugins[i].destroy(); } } grpc_iomgr_shutdown(&exec_ctx); gpr_timers_global_destroy(); grpc_tracer_shutdown(); grpc_mdctx_global_shutdown(&exec_ctx); grpc_handshaker_factory_registry_shutdown(&exec_ctx); grpc_slice_intern_shutdown(); grpc_stats_shutdown(); } gpr_mu_unlock(&g_init_mu); grpc_exec_ctx_finish(&exec_ctx); }
int main(int argc, char **argv) { grpc_test_init(argc, argv); grpc_iomgr_init(); test_grpc_fd(); test_grpc_fd_change(); grpc_iomgr_shutdown(); return 0; }
int main(int argc, char **argv) { grpc_test_init(argc, argv); grpc_iomgr_init(); test_succeeds(); gpr_log(GPR_ERROR, "End of first test"); test_fails(); test_times_out(); grpc_iomgr_shutdown(); return 0; }
void grpc_shutdown(void) { gpr_mu_lock(&g_init_mu); if (--g_initializations == 0) { grpc_iomgr_shutdown(); census_shutdown(); grpc_timers_global_destroy(); grpc_tracer_shutdown(); grpc_resolver_registry_shutdown(); } gpr_mu_unlock(&g_init_mu); }
int main(int argc, char **argv) { grpc_test_init(argc, argv); grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_iomgr_init(&exec_ctx); grpc_iomgr_start(&exec_ctx); test_unix_socket(); test_unix_socket_path_name_too_long(); grpc_executor_shutdown(&exec_ctx); grpc_iomgr_shutdown(&exec_ctx); grpc_exec_ctx_finish(&exec_ctx); return 0; }
int main(int argc, char** argv) { grpc_test_init(argc, argv); grpc_iomgr_init(); test_localhost(); test_default_port(); test_missing_default_port(); test_ipv6_with_port(); test_ipv6_without_port(); test_invalid_ip_addresses(); test_unparseable_hostports(); grpc_iomgr_shutdown(); return 0; }
int main(int argc, char **argv) { grpc_test_init(argc, argv); grpc_iomgr_init(); test_get(0); test_get(1); /* test_post(0); */ /* test_post(1); */ grpc_iomgr_shutdown(); return 0; }
int main(int argc, char **argv) { grpc_test_init(argc, argv); grpc_iomgr_init(); test_no_op(); test_wait_empty(); test_cq_end_op(); test_pluck(); test_threading(1, 1); test_threading(1, 10); test_threading(10, 1); test_threading(10, 10); grpc_iomgr_shutdown(); return 0; }
int main(int argc, char **argv) { grpc_test_init(argc, argv); grpc_iomgr_init(); grpc_pollset_init(&g_pollset); test_no_op(); test_no_op_with_start(); test_no_op_with_port(); test_no_op_with_port_and_start(); test_connect(1); test_connect(10); grpc_pollset_shutdown(&g_pollset, destroy_pollset, &g_pollset); grpc_iomgr_shutdown(); return 0; }
int main(int argc, char **argv) { grpc_test_init(argc, argv); grpc_iomgr_init(); test_no_op(); test_wait_empty(); test_cq_end_read(); test_cq_end_write_accepted(); test_cq_end_finish_accepted(); test_cq_end_client_metadata_read(); test_pluck(); test_threading(1, 1); test_threading(1, 10); test_threading(10, 1); test_threading(10, 10); grpc_iomgr_shutdown(); return 0; }
int main(int argc, char **argv) { grpc_test_init(argc, argv); grpc_iomgr_init(); gpr_mu_init(&mu); gpr_cv_init(&cv); test_no_op(); test_no_op_with_start(); test_no_op_with_port(); test_no_op_with_port_and_start(); test_connect(1); test_connect(10); grpc_iomgr_shutdown(); gpr_mu_destroy(&mu); gpr_cv_destroy(&cv); return 0; }
int main(int argc, char **argv) { grpc_closure destroyed; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_test_init(argc, argv); grpc_iomgr_init(&exec_ctx); grpc_iomgr_start(&exec_ctx); g_pollset = gpr_zalloc(grpc_pollset_size()); grpc_pollset_init(g_pollset, &g_mu); test_grpc_fd(); test_grpc_fd_change(); GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, g_pollset, grpc_schedule_on_exec_ctx); grpc_pollset_shutdown(&exec_ctx, g_pollset, &destroyed); grpc_exec_ctx_flush(&exec_ctx); gpr_free(g_pollset); grpc_iomgr_shutdown(&exec_ctx); grpc_exec_ctx_finish(&exec_ctx); return 0; }
void grpc_shutdown(void) { int i; GRPC_API_TRACE("grpc_shutdown(void)", 0, ()); gpr_mu_lock(&g_init_mu); if (--g_initializations == 0) { grpc_executor_shutdown(); grpc_cq_global_shutdown(); grpc_iomgr_shutdown(); gpr_timers_global_destroy(); grpc_tracer_shutdown(); for (i = g_number_of_plugins; i >= 0; i--) { if (g_all_of_the_plugins[i].destroy != NULL) { g_all_of_the_plugins[i].destroy(); } } grpc_mdctx_global_shutdown(); } gpr_mu_unlock(&g_init_mu); }
void grpc_shutdown(void) { int i; GRPC_API_TRACE("grpc_shutdown(void)", 0, ()); gpr_mu_lock(&g_init_mu); if (--g_initializations == 0) { grpc_iomgr_shutdown(); grpc_executor_shutdown(); census_shutdown(); gpr_timers_global_destroy(); grpc_tracer_shutdown(); grpc_resolver_registry_shutdown(); for (i = 0; i < g_number_of_plugins; i++) { if (g_all_of_the_plugins[i].destroy != NULL) { g_all_of_the_plugins[i].destroy(); } } } gpr_mu_unlock(&g_init_mu); }
int main(int argc, char **argv) { const char *poll_strategy = NULL; grpc_test_init(argc, argv); grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_iomgr_init(&exec_ctx); grpc_iomgr_start(&exec_ctx); poll_strategy = grpc_get_poll_strategy_name(); if (poll_strategy != NULL && strcmp(poll_strategy, "epollsig") == 0) { test_add_fd_to_pollset(); test_threading(); } else { gpr_log(GPR_INFO, "Skipping the test. The test is only relevant for 'epollsig' " "strategy. and the current strategy is: '%s'", poll_strategy); } grpc_iomgr_shutdown(&exec_ctx); grpc_exec_ctx_finish(&exec_ctx); return 0; }
int main(int argc, char **argv) { grpc_closure destroyed; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_test_init(argc, argv); grpc_init(); g_pollset = gpr_malloc(grpc_pollset_size()); grpc_pollset_init(g_pollset, &g_mu); test_no_op(); test_no_op_with_start(); test_no_op_with_port(); test_no_op_with_port_and_start(); test_receive(1); test_receive(10); grpc_closure_init(&destroyed, destroy_pollset, g_pollset); grpc_pollset_shutdown(&exec_ctx, g_pollset, &destroyed); grpc_exec_ctx_finish(&exec_ctx); gpr_free(g_pollset); grpc_iomgr_shutdown(); return 0; }
static void test_code(void) { /* iomgr.h */ grpc_iomgr_init(); grpc_iomgr_shutdown(); /* closure.h */ grpc_closure closure; closure.cb = NULL; closure.cb_arg = NULL; closure.next_data.scratch = 0; grpc_closure_list closure_list = GRPC_CLOSURE_LIST_INIT; closure_list.head = NULL; closure_list.tail = NULL; grpc_closure_init(&closure, NULL, NULL); grpc_closure_create(NULL, NULL); grpc_closure_list_move(NULL, NULL); grpc_closure_list_append(NULL, NULL, GRPC_ERROR_CREATE("Foo")); grpc_closure_list_empty(closure_list); /* exec_ctx.h */ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_exec_ctx_flush(&exec_ctx); grpc_exec_ctx_finish(&exec_ctx); grpc_exec_ctx_sched(&exec_ctx, &closure, GRPC_ERROR_CREATE("Foo"), NULL); grpc_exec_ctx_enqueue_list(&exec_ctx, &closure_list, NULL); /* endpoint.h */ grpc_endpoint endpoint; grpc_endpoint_vtable vtable = {grpc_endpoint_read, grpc_endpoint_write, grpc_endpoint_get_workqueue, grpc_endpoint_add_to_pollset, grpc_endpoint_add_to_pollset_set, grpc_endpoint_shutdown, grpc_endpoint_destroy, grpc_endpoint_get_resource_user, grpc_endpoint_get_peer}; endpoint.vtable = &vtable; grpc_endpoint_read(&exec_ctx, &endpoint, NULL, NULL); grpc_endpoint_get_peer(&endpoint); grpc_endpoint_write(&exec_ctx, &endpoint, NULL, NULL); grpc_endpoint_shutdown(&exec_ctx, &endpoint); grpc_endpoint_destroy(&exec_ctx, &endpoint); grpc_endpoint_add_to_pollset(&exec_ctx, &endpoint, NULL); grpc_endpoint_add_to_pollset_set(&exec_ctx, &endpoint, NULL); /* executor.h */ grpc_executor_init(); grpc_executor_push(&closure, GRPC_ERROR_CREATE("Phi")); grpc_executor_shutdown(); /* pollset.h */ grpc_pollset_size(); grpc_pollset_init(NULL, NULL); grpc_pollset_shutdown(NULL, NULL, NULL); grpc_pollset_reset(NULL); grpc_pollset_destroy(NULL); GRPC_ERROR_UNREF(grpc_pollset_work(NULL, NULL, NULL, gpr_now(GPR_CLOCK_REALTIME), gpr_now(GPR_CLOCK_MONOTONIC))); GRPC_ERROR_UNREF(grpc_pollset_kick(NULL, NULL)); }
/* Test grpc_alarm add and cancel. */ static void test_grpc_alarm(void) { grpc_alarm alarm; grpc_alarm alarm_to_cancel; /* Timeout on the alarm cond. var, so make big enough to absorb time deviations. Otherwise, operations after wait will not be properly ordered */ gpr_timespec alarm_deadline; gpr_timespec followup_deadline; alarm_arg arg; alarm_arg arg2; void *fdone; grpc_iomgr_init(); arg.counter = 0; arg.success = SUCCESS_NOT_SET; arg.done_success_ctr = 0; arg.done_cancel_ctr = 0; arg.done = 0; gpr_mu_init(&arg.mu); gpr_cv_init(&arg.cv); gpr_event_init(&arg.fcb_arg); grpc_alarm_init(&alarm, GRPC_TIMEOUT_MILLIS_TO_DEADLINE(100), alarm_cb, &arg, gpr_now()); alarm_deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(1); gpr_mu_lock(&arg.mu); while (arg.done == 0) { if (gpr_cv_wait(&arg.cv, &arg.mu, alarm_deadline)) { gpr_log(GPR_ERROR, "alarm deadline exceeded"); break; } } gpr_mu_unlock(&arg.mu); followup_deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(5); fdone = gpr_event_wait(&arg.fcb_arg, followup_deadline); if (arg.counter != 1) { gpr_log(GPR_ERROR, "Alarm callback not called"); GPR_ASSERT(0); } else if (arg.done_success_ctr != 1) { gpr_log(GPR_ERROR, "Alarm done callback not called with success"); GPR_ASSERT(0); } else if (arg.done_cancel_ctr != 0) { gpr_log(GPR_ERROR, "Alarm done callback called with cancel"); GPR_ASSERT(0); } else if (arg.success == SUCCESS_NOT_SET) { gpr_log(GPR_ERROR, "Alarm callback without status"); GPR_ASSERT(0); } else { gpr_log(GPR_INFO, "Alarm callback called successfully"); } if (fdone != (void *)&arg.fcb_arg) { gpr_log(GPR_ERROR, "Followup callback #1 not invoked properly %p %p", fdone, &arg.fcb_arg); GPR_ASSERT(0); } gpr_cv_destroy(&arg.cv); gpr_mu_destroy(&arg.mu); arg2.counter = 0; arg2.success = SUCCESS_NOT_SET; arg2.done_success_ctr = 0; arg2.done_cancel_ctr = 0; arg2.done = 0; gpr_mu_init(&arg2.mu); gpr_cv_init(&arg2.cv); gpr_event_init(&arg2.fcb_arg); grpc_alarm_init(&alarm_to_cancel, GRPC_TIMEOUT_MILLIS_TO_DEADLINE(100), alarm_cb, &arg2, gpr_now()); grpc_alarm_cancel(&alarm_to_cancel); alarm_deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(1); gpr_mu_lock(&arg2.mu); while (arg2.done == 0) { gpr_cv_wait(&arg2.cv, &arg2.mu, alarm_deadline); } gpr_mu_unlock(&arg2.mu); gpr_log(GPR_INFO, "alarm done = %d", arg2.done); followup_deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(5); fdone = gpr_event_wait(&arg2.fcb_arg, followup_deadline); if (arg2.counter != arg2.done_success_ctr) { gpr_log(GPR_ERROR, "Alarm callback called but didn't lead to done success"); GPR_ASSERT(0); } else if (arg2.done_success_ctr && arg2.done_cancel_ctr) { gpr_log(GPR_ERROR, "Alarm done callback called with success and cancel"); GPR_ASSERT(0); } else if (arg2.done_cancel_ctr + arg2.done_success_ctr != 1) { gpr_log(GPR_ERROR, "Alarm done callback called incorrect number of times"); GPR_ASSERT(0); } else if (arg2.success == SUCCESS_NOT_SET) { gpr_log(GPR_ERROR, "Alarm callback without status"); GPR_ASSERT(0); } else if (arg2.done_success_ctr) { gpr_log(GPR_INFO, "Alarm callback executed before cancel"); gpr_log(GPR_INFO, "Current value of triggered is %d\n", alarm_to_cancel.triggered); } else if (arg2.done_cancel_ctr) { gpr_log(GPR_INFO, "Alarm callback canceled"); gpr_log(GPR_INFO, "Current value of triggered is %d\n", alarm_to_cancel.triggered); } else { gpr_log(GPR_ERROR, "Alarm cancel test should not be here"); GPR_ASSERT(0); } if (fdone != (void *)&arg2.fcb_arg) { gpr_log(GPR_ERROR, "Followup callback #2 not invoked properly %p %p", fdone, &arg2.fcb_arg); GPR_ASSERT(0); } gpr_cv_destroy(&arg2.cv); gpr_mu_destroy(&arg2.mu); grpc_iomgr_shutdown(); }
static void test_code(void) { /* iomgr.h */ grpc_iomgr_init(); grpc_iomgr_shutdown(); /* closure.h */ grpc_closure closure; closure.cb = NULL; closure.cb_arg = NULL; closure.final_data = 0; grpc_closure_list closure_list = GRPC_CLOSURE_LIST_INIT; closure_list.head = NULL; closure_list.tail = NULL; grpc_closure_init(&closure, NULL, NULL); grpc_closure_create(NULL, NULL); grpc_closure_list_move(NULL, NULL); grpc_closure_list_add(NULL, NULL, true); bool x = grpc_closure_list_empty(closure_list); grpc_closure_next(&closure); /* exec_ctx.h */ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_exec_ctx_flush(&exec_ctx); grpc_exec_ctx_finish(&exec_ctx); grpc_exec_ctx_enqueue(&exec_ctx, &closure, x, NULL); grpc_exec_ctx_enqueue_list(&exec_ctx, &closure_list, NULL); /* endpoint.h */ grpc_endpoint endpoint; grpc_endpoint_vtable vtable = { grpc_endpoint_read, grpc_endpoint_write, grpc_endpoint_add_to_pollset, grpc_endpoint_add_to_pollset_set, grpc_endpoint_shutdown, grpc_endpoint_destroy, grpc_endpoint_get_peer}; endpoint.vtable = &vtable; grpc_endpoint_read(&exec_ctx, &endpoint, NULL, NULL); grpc_endpoint_get_peer(&endpoint); grpc_endpoint_write(&exec_ctx, &endpoint, NULL, NULL); grpc_endpoint_shutdown(&exec_ctx, &endpoint); grpc_endpoint_destroy(&exec_ctx, &endpoint); grpc_endpoint_add_to_pollset(&exec_ctx, &endpoint, NULL); grpc_endpoint_add_to_pollset_set(&exec_ctx, &endpoint, NULL); /* executor.h */ grpc_executor_init(); grpc_executor_enqueue(&closure, x); grpc_executor_shutdown(); /* pollset.h */ grpc_pollset_size(); grpc_pollset_init(NULL, NULL); grpc_pollset_shutdown(NULL, NULL, NULL); grpc_pollset_reset(NULL); grpc_pollset_destroy(NULL); grpc_pollset_work(NULL, NULL, NULL, gpr_now(GPR_CLOCK_REALTIME), gpr_now(GPR_CLOCK_MONOTONIC)); grpc_pollset_kick(NULL, NULL); }