Example #1
0
static void put_metadata(gpr_strvec *b, grpc_mdelem *md) {
  gpr_strvec_add(b, gpr_strdup("key="));
  gpr_strvec_add(
      b, gpr_hexdump((char *)GPR_SLICE_START_PTR(md->key->slice),
                     GPR_SLICE_LENGTH(md->key->slice), GPR_HEXDUMP_PLAINTEXT));

  gpr_strvec_add(b, gpr_strdup(" value="));
  gpr_strvec_add(b, gpr_hexdump((char *)GPR_SLICE_START_PTR(md->value->slice),
                                GPR_SLICE_LENGTH(md->value->slice),
                                GPR_HEXDUMP_PLAINTEXT));
}
Example #2
0
static void expect_slice_eq(gpr_slice expected, gpr_slice slice, char *debug,
                            int line) {
  if (0 != gpr_slice_cmp(slice, expected)) {
    char *hs = gpr_hexdump((const char *)GPR_SLICE_START_PTR(slice),
                           GPR_SLICE_LENGTH(slice), GPR_HEXDUMP_PLAINTEXT);
    char *he = gpr_hexdump((const char *)GPR_SLICE_START_PTR(expected),
                           GPR_SLICE_LENGTH(expected), GPR_HEXDUMP_PLAINTEXT);
    gpr_log(GPR_ERROR, "FAILED:%d: %s\ngot:  %s\nwant: %s", line, debug, hs,
            he);
    gpr_free(hs);
    gpr_free(he);
    all_ok = 0;
  }
  gpr_slice_unref(expected);
  gpr_slice_unref(slice);
}
Example #3
0
static void add_metadata(gpr_strvec *b, const grpc_metadata *md, size_t count) {
  size_t i;
  for(i = 0; i < count; i++) {
    gpr_strvec_add(b, gpr_strdup("\nkey="));
    gpr_strvec_add(b, gpr_strdup(md[i].key));

    gpr_strvec_add(b, gpr_strdup(" value="));
    gpr_strvec_add(b, gpr_hexdump(md[i].value, md[i].value_length,
                                  GPR_HEXDUMP_PLAINTEXT));
  }
}
Example #4
0
void grpc_chttp2_add_incoming_goaway(
    grpc_chttp2_transport_global *transport_global, gpr_uint32 goaway_error,
    gpr_slice goaway_text) {
  char *msg = gpr_hexdump((char*)GPR_SLICE_START_PTR(goaway_text), GPR_SLICE_LENGTH(goaway_text), GPR_HEXDUMP_PLAINTEXT);
  gpr_free(msg);
  if (transport_global->goaway_state == GRPC_CHTTP2_ERROR_STATE_NONE) {
    transport_global->goaway_state = GRPC_CHTTP2_ERROR_STATE_SEEN;
    transport_global->goaway_text = goaway_text;
    transport_global->goaway_error = goaway_error;
  } else {
    gpr_slice_unref(goaway_text);
  }
}
Example #5
0
static void expect_combined_equiv(const char *s, size_t len, int line) {
  gpr_slice input = gpr_slice_from_copied_buffer(s, len);
  gpr_slice base64 = grpc_chttp2_base64_encode(input);
  gpr_slice expect = grpc_chttp2_huffman_compress(base64);
  gpr_slice got = grpc_chttp2_base64_encode_and_huffman_compress(input);
  if (0 != gpr_slice_cmp(expect, got)) {
    char *t = gpr_hexdump((const char *)GPR_SLICE_START_PTR(input),
                          GPR_SLICE_LENGTH(input), GPR_HEXDUMP_PLAINTEXT);
    char *e = gpr_hexdump((const char *)GPR_SLICE_START_PTR(expect),
                          GPR_SLICE_LENGTH(expect), GPR_HEXDUMP_PLAINTEXT);
    char *g = gpr_hexdump((const char *)GPR_SLICE_START_PTR(got),
                          GPR_SLICE_LENGTH(got), GPR_HEXDUMP_PLAINTEXT);
    gpr_log(GPR_ERROR, "FAILED:%d:\ntest: %s\ngot:  %s\nwant: %s", t, g, e);
    gpr_free(t);
    gpr_free(e);
    gpr_free(g);
    all_ok = 0;
  }
  gpr_slice_unref(input);
  gpr_slice_unref(base64);
  gpr_slice_unref(expect);
  gpr_slice_unref(got);
}
Example #6
0
/* verify that the output generated by encoding the stream matches the
   hexstring passed in */
static void verify_sopb(size_t window_available, int eof,
                        size_t expect_window_used, const char *expected) {
  gpr_slice_buffer output;
  grpc_stream_op_buffer encops;
  gpr_slice merged;
  gpr_slice expect = parse_hexstring(expected);
  gpr_slice_buffer_init(&output);
  grpc_sopb_init(&encops);
  GPR_ASSERT(expect_window_used ==
             grpc_chttp2_preencode(g_sopb.ops, &g_sopb.nops, window_available,
                                   &encops));
  grpc_chttp2_encode(encops.ops, encops.nops, eof, 0xdeadbeef, &g_compressor,
                     &output);
  encops.nops = 0;
  merged = grpc_slice_merge(output.slices, output.count);
  gpr_slice_buffer_destroy(&output);
  grpc_sopb_destroy(&encops);

  if (0 != gpr_slice_cmp(merged, expect)) {
    char *expect_str =
        gpr_hexdump((char *)GPR_SLICE_START_PTR(expect),
                    GPR_SLICE_LENGTH(expect), GPR_HEXDUMP_PLAINTEXT);
    char *got_str =
        gpr_hexdump((char *)GPR_SLICE_START_PTR(merged),
                    GPR_SLICE_LENGTH(merged), GPR_HEXDUMP_PLAINTEXT);
    gpr_log(GPR_ERROR, "mismatched output for %s", expected);
    gpr_log(GPR_ERROR, "EXPECT: %s", expect_str);
    gpr_log(GPR_ERROR, "GOT:    %s", got_str);
    gpr_free(expect_str);
    gpr_free(got_str);
    g_failure = 1;
  }

  gpr_slice_unref(merged);
  gpr_slice_unref(expect);
}
Example #7
0
void grpc_run_bad_client_test(grpc_bad_client_server_side_validator validator,
                              const char *client_payload,
                              size_t client_payload_length, gpr_uint32 flags) {
  grpc_endpoint_pair sfd;
  thd_args a;
  gpr_thd_id id;
  char *hex;
  gpr_slice slice =
      gpr_slice_from_copied_buffer(client_payload, client_payload_length);

  hex =
      gpr_hexdump(client_payload, client_payload_length, GPR_HEXDUMP_PLAINTEXT);

  /* Add a debug log */
  gpr_log(GPR_INFO, "TEST: %s", hex);

  gpr_free(hex);

  /* Init grpc */
  grpc_init();

  /* Create endpoints */
  sfd = grpc_iomgr_create_endpoint_pair("fixture", 65536);

  /* Create server, completion events */
  a.server = grpc_server_create_from_filters(NULL, 0, NULL);
  a.cq = grpc_completion_queue_create();
  gpr_event_init(&a.done_thd);
  gpr_event_init(&a.done_write);
  a.validator = validator;
  grpc_server_register_completion_queue(a.server, a.cq);
  grpc_server_start(a.server);
  grpc_create_chttp2_transport(server_setup_transport, &a, NULL, sfd.server,
                               NULL, 0, grpc_mdctx_create(), 0);

  /* Bind everything into the same pollset */
  grpc_endpoint_add_to_pollset(sfd.client, grpc_cq_pollset(a.cq));
  grpc_endpoint_add_to_pollset(sfd.server, grpc_cq_pollset(a.cq));

  /* Check a ground truth */
  GPR_ASSERT(grpc_server_has_open_connections(a.server));

  /* Start validator */
  gpr_thd_new(&id, thd_func, &a, NULL);

  /* Write data */
  switch (grpc_endpoint_write(sfd.client, &slice, 1, done_write, &a)) {
    case GRPC_ENDPOINT_WRITE_DONE:
      done_write(&a, 1);
      break;
    case GRPC_ENDPOINT_WRITE_PENDING:
      break;
    case GRPC_ENDPOINT_WRITE_ERROR:
      done_write(&a, 0);
      break;
  }

  /* Await completion */
  GPR_ASSERT(
      gpr_event_wait(&a.done_write, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(5)));

  if (flags & GRPC_BAD_CLIENT_DISCONNECT) {
    grpc_endpoint_destroy(sfd.client);
    sfd.client = NULL;
  }

  GPR_ASSERT(gpr_event_wait(&a.done_thd, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(5)));

  /* Shutdown */
  if (sfd.client) {
    grpc_endpoint_destroy(sfd.client);
  }
  grpc_server_shutdown_and_notify(a.server, a.cq, NULL);
  GPR_ASSERT(grpc_completion_queue_pluck(a.cq, NULL,
                                         GRPC_TIMEOUT_SECONDS_TO_DEADLINE(1))
                 .type == GRPC_OP_COMPLETE);
  grpc_server_destroy(a.server);
  grpc_completion_queue_destroy(a.cq);

  grpc_shutdown();
}
Example #8
0
static void expect_hexdump(const char *buf, size_t len, gpr_uint32 flags,
                           const char *result) {
  char *got = gpr_hexdump(buf, len, flags);
  GPR_ASSERT(0 == strcmp(got, result));
  gpr_free(got);
}