Skip to content

Commit

Permalink
Merge pull request grpc#7858 from markdroth/cq_verifier_file_line
Browse files Browse the repository at this point in the history
Change cq_verifier to report file and line number for expectations.
  • Loading branch information
ctiller authored Aug 31, 2016
2 parents 79d7d99 + 661408c commit 581367a
Show file tree
Hide file tree
Showing 56 changed files with 217 additions and 216 deletions.
2 changes: 1 addition & 1 deletion test/core/bad_client/tests/head_of_line_blocking.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ static void verifier(grpc_server *server, grpc_completion_queue *cq,
&deadline, &request_metadata_recv,
&payload, cq, cq, tag(101));
GPR_ASSERT(GRPC_CALL_OK == error);
cq_expect_completion(cqv, tag(101), 1);
CQ_EXPECT_COMPLETION(cqv, tag(101), 1);
cq_verify(cqv);

GPR_ASSERT(payload != NULL);
Expand Down
6 changes: 3 additions & 3 deletions test/core/bad_client/tests/large_metadata.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ static void server_verifier(grpc_server *server, grpc_completion_queue *cq,
error = grpc_server_request_call(server, &s, &call_details,
&request_metadata_recv, cq, cq, tag(101));
GPR_ASSERT(GRPC_CALL_OK == error);
cq_expect_completion(cqv, tag(101), 1);
CQ_EXPECT_COMPLETION(cqv, tag(101), 1);
cq_verify(cqv);

GPR_ASSERT(0 == strcmp(call_details.host, "localhost"));
Expand All @@ -148,7 +148,7 @@ static void server_verifier_sends_too_much_metadata(grpc_server *server,
error = grpc_server_request_call(server, &s, &call_details,
&request_metadata_recv, cq, cq, tag(101));
GPR_ASSERT(GRPC_CALL_OK == error);
cq_expect_completion(cqv, tag(101), 1);
CQ_EXPECT_COMPLETION(cqv, tag(101), 1);
cq_verify(cqv);

GPR_ASSERT(0 == strcmp(call_details.host, "localhost"));
Expand All @@ -171,7 +171,7 @@ static void server_verifier_sends_too_much_metadata(grpc_server *server,
op.reserved = NULL;
error = grpc_call_start_batch(s, &op, 1, tag(102), NULL);
GPR_ASSERT(GRPC_CALL_OK == error);
cq_expect_completion(cqv, tag(102), 0); // Operation fails.
CQ_EXPECT_COMPLETION(cqv, tag(102), 0); // Operation fails.
cq_verify(cqv);

gpr_free((char *)meta.value);
Expand Down
4 changes: 2 additions & 2 deletions test/core/bad_client/tests/server_registered_method.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ static void verifier_succeeds(grpc_server *server, grpc_completion_queue *cq,
&deadline, &request_metadata_recv,
&payload, cq, cq, tag(101));
GPR_ASSERT(GRPC_CALL_OK == error);
cq_expect_completion(cqv, tag(101), 1);
CQ_EXPECT_COMPLETION(cqv, tag(101), 1);
cq_verify(cqv);

GPR_ASSERT(payload != NULL);
Expand All @@ -96,7 +96,7 @@ static void verifier_fails(grpc_server *server, grpc_completion_queue *cq,
&deadline, &request_metadata_recv,
&payload, cq, cq, tag(101));
GPR_ASSERT(GRPC_CALL_OK == error);
cq_expect_completion(cqv, tag(101), 1);
CQ_EXPECT_COMPLETION(cqv, tag(101), 1);
cq_verify(cqv);

GPR_ASSERT(payload == NULL);
Expand Down
2 changes: 1 addition & 1 deletion test/core/bad_client/tests/simple_request.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ static void verifier(grpc_server *server, grpc_completion_queue *cq,
error = grpc_server_request_call(server, &s, &call_details,
&request_metadata_recv, cq, cq, tag(101));
GPR_ASSERT(GRPC_CALL_OK == error);
cq_expect_completion(cqv, tag(101), 1);
CQ_EXPECT_COMPLETION(cqv, tag(101), 1);
cq_verify(cqv);

GPR_ASSERT(0 == strcmp(call_details.host, "localhost"));
Expand Down
2 changes: 1 addition & 1 deletion test/core/bad_ssl/bad_ssl_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ static void run_test(const char *target, size_t nops) {
error = grpc_call_start_batch(c, ops, nops, tag(1), NULL);
GPR_ASSERT(GRPC_CALL_OK == error);

cq_expect_completion(cqv, tag(1), 1);
CQ_EXPECT_COMPLETION(cqv, tag(1), 1);
cq_verify(cqv);

GPR_ASSERT(status != GRPC_STATUS_OK);
Expand Down
12 changes: 6 additions & 6 deletions test/core/client_config/lb_policies_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,9 +351,9 @@ static int *perform_request(servers_fixture *f, grpc_channel *client,
ops, (size_t)(op - ops),
tag(102), NULL));

cq_expect_completion(cqv, tag(102), 1);
CQ_EXPECT_COMPLETION(cqv, tag(102), 1);
if (!completed_client) {
cq_expect_completion(cqv, tag(1), 1);
CQ_EXPECT_COMPLETION(cqv, tag(1), 1);
}
cq_verify(cqv);

Expand All @@ -376,7 +376,7 @@ static int *perform_request(servers_fixture *f, grpc_channel *client,
} else { /* no response from server */
grpc_call_cancel(c, NULL);
if (!completed_client) {
cq_expect_completion(cqv, tag(1), 1);
CQ_EXPECT_COMPLETION(cqv, tag(1), 1);
cq_verify(cqv);
}
}
Expand Down Expand Up @@ -576,7 +576,7 @@ static void test_ping() {
client = create_client(f);

grpc_channel_ping(client, f->cq, tag(0), NULL);
cq_expect_completion(cqv, tag(0), 0);
CQ_EXPECT_COMPLETION(cqv, tag(0), 0);

/* check that we're still in idle, and start connecting */
GPR_ASSERT(grpc_channel_check_connectivity_state(client, 1) ==
Expand All @@ -586,7 +586,7 @@ static void test_ping() {
while (state != GRPC_CHANNEL_READY) {
grpc_channel_watch_connectivity_state(
client, state, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(3), f->cq, tag(99));
cq_expect_completion(cqv, tag(99), 1);
CQ_EXPECT_COMPLETION(cqv, tag(99), 1);
cq_verify(cqv);
state = grpc_channel_check_connectivity_state(client, 0);
GPR_ASSERT(state == GRPC_CHANNEL_READY ||
Expand All @@ -596,7 +596,7 @@ static void test_ping() {

for (i = 1; i <= 5; i++) {
grpc_channel_ping(client, f->cq, tag(i), NULL);
cq_expect_completion(cqv, tag(i), 1);
CQ_EXPECT_COMPLETION(cqv, tag(i), 1);
cq_verify(cqv);
}
gpr_free(rdata.call_details);
Expand Down
2 changes: 1 addition & 1 deletion test/core/end2end/bad_server_response_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ static void start_rpc(int target_port, grpc_status_code expected_status,

GPR_ASSERT(GRPC_CALL_OK == error);

cq_expect_completion(cqv, tag(1), 1);
CQ_EXPECT_COMPLETION(cqv, tag(1), 1);
cq_verify(cqv);

gpr_log(GPR_DEBUG, "Rpc status: %d, details: %s", status, details);
Expand Down
44 changes: 21 additions & 23 deletions test/core/end2end/cq_verifier.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ typedef struct metadata {
list to detail other expectations */
typedef struct expectation {
struct expectation *next;
const char *file;
int line;
grpc_completion_type type;
void *tag;
int success;
Expand Down Expand Up @@ -180,7 +182,8 @@ static void expectation_to_strvec(gpr_strvec *buf, expectation *e) {

switch (e->type) {
case GRPC_OP_COMPLETE:
gpr_asprintf(&tmp, "GRPC_OP_COMPLETE result=%d", e->success);
gpr_asprintf(&tmp, "GRPC_OP_COMPLETE result=%d %s:%d", e->success,
e->file, e->line);
gpr_strvec_add(buf, tmp);
break;
case GRPC_QUEUE_TIMEOUT:
Expand Down Expand Up @@ -214,25 +217,16 @@ static void fail_no_event_received(cq_verifier *v) {
}

void cq_verify(cq_verifier *v) {
gpr_timespec deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(10);
grpc_event ev;
expectation *e;
char *s;
gpr_strvec have_tags;

gpr_strvec_init(&have_tags);

const gpr_timespec deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(10);
while (v->first_expectation != NULL) {
ev = grpc_completion_queue_next(v->cq, deadline, NULL);
grpc_event ev = grpc_completion_queue_next(v->cq, deadline, NULL);
if (ev.type == GRPC_QUEUE_TIMEOUT) {
fail_no_event_received(v);
break;
}

expectation *e;
expectation *prev = NULL;
for (e = v->first_expectation; e != NULL; e = e->next) {
gpr_asprintf(&s, " %p", e->tag);
gpr_strvec_add(&have_tags, s);
if (e->tag == ev.tag) {
verify_matches(e, &ev);
if (e == v->first_expectation) v->first_expectation = e->next;
Expand All @@ -243,18 +237,19 @@ void cq_verify(cq_verifier *v) {
prev = e;
}
if (e == NULL) {
s = grpc_event_string(&ev);
char *s = grpc_event_string(&ev);
gpr_log(GPR_ERROR, "cq returned unexpected event: %s", s);
gpr_free(s);
s = gpr_strvec_flatten(&have_tags, NULL);
gpr_log(GPR_ERROR, "expected tags:%s", s);
gpr_strvec expectations;
gpr_strvec_init(&expectations);
expectations_to_strvec(&expectations, v);
s = gpr_strvec_flatten(&expectations, NULL);
gpr_strvec_destroy(&expectations);
gpr_log(GPR_ERROR, "expected tags:\n%s", s);
gpr_free(s);
gpr_strvec_destroy(&have_tags);
abort();
}
}

gpr_strvec_destroy(&have_tags);
}

void cq_verify_empty_timeout(cq_verifier *v, int timeout_sec) {
Expand All @@ -276,16 +271,19 @@ void cq_verify_empty_timeout(cq_verifier *v, int timeout_sec) {

void cq_verify_empty(cq_verifier *v) { cq_verify_empty_timeout(v, 1); }

static void add(cq_verifier *v, grpc_completion_type type, void *tag,
bool success) {
static void add(cq_verifier *v, const char *file, int line,
grpc_completion_type type, void *tag, bool success) {
expectation *e = gpr_malloc(sizeof(expectation));
e->type = type;
e->file = file;
e->line = line;
e->tag = tag;
e->success = success;
e->next = v->first_expectation;
v->first_expectation = e;
}

void cq_expect_completion(cq_verifier *v, void *tag, bool success) {
add(v, GRPC_OP_COMPLETE, tag, success);
void cq_expect_completion(cq_verifier *v, const char *file, int line, void *tag,
bool success) {
add(v, file, line, GRPC_OP_COMPLETE, tag, success);
}
5 changes: 4 additions & 1 deletion test/core/end2end/cq_verifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ void cq_verify_empty_timeout(cq_verifier *v, int timeout_sec);
Any functions taking ... expect a NULL terminated list of key/value pairs
(each pair using two parameter slots) of metadata that MUST be present in
the event. */
void cq_expect_completion(cq_verifier *v, void *tag, bool success);
void cq_expect_completion(cq_verifier *v, const char *file, int line, void *tag,
bool success);
#define CQ_EXPECT_COMPLETION(v, tag, success) \
cq_expect_completion(v, __FILE__, __LINE__, tag, success)

int byte_buffer_eq_string(grpc_byte_buffer *byte_buffer, const char *string);
int contains_metadata(grpc_metadata_array *array, const char *key,
Expand Down
8 changes: 4 additions & 4 deletions test/core/end2end/dualstack_socket_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ void test_connect(const char *server_host, const char *client_host, int port,
error = grpc_server_request_call(server, &s, &call_details,
&request_metadata_recv, cq, cq, tag(101));
GPR_ASSERT(GRPC_CALL_OK == error);
cq_expect_completion(cqv, tag(101), 1);
CQ_EXPECT_COMPLETION(cqv, tag(101), 1);
cq_verify(cqv);

memset(ops, 0, sizeof(ops));
Expand All @@ -221,8 +221,8 @@ void test_connect(const char *server_host, const char *client_host, int port,
error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), NULL);
GPR_ASSERT(GRPC_CALL_OK == error);

cq_expect_completion(cqv, tag(102), 1);
cq_expect_completion(cqv, tag(1), 1);
CQ_EXPECT_COMPLETION(cqv, tag(102), 1);
CQ_EXPECT_COMPLETION(cqv, tag(1), 1);
cq_verify(cqv);

peer = grpc_call_get_peer(c);
Expand All @@ -238,7 +238,7 @@ void test_connect(const char *server_host, const char *client_host, int port,
grpc_call_destroy(s);
} else {
/* Check for a failed connection. */
cq_expect_completion(cqv, tag(1), 1);
CQ_EXPECT_COMPLETION(cqv, tag(1), 1);
cq_verify(cqv);

GPR_ASSERT(status == GRPC_STATUS_UNAVAILABLE);
Expand Down
2 changes: 1 addition & 1 deletion test/core/end2end/fixtures/h2_ssl_cert.c
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ static void simple_request_body(grpc_end2end_test_fixture f,
error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL);
GPR_ASSERT(GRPC_CALL_OK == error);

cq_expect_completion(cqv, tag(1), expected_result == SUCCESS);
CQ_EXPECT_COMPLETION(cqv, tag(1), expected_result == SUCCESS);
cq_verify(cqv);

grpc_call_destroy(c);
Expand Down
22 changes: 11 additions & 11 deletions test/core/end2end/goaway_server_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ int main(int argc, char **argv) {
set_resolve_port(port1);

/* first call should now start */
cq_expect_completion(cqv, tag(0x101), 1);
cq_expect_completion(cqv, tag(0x301), 1);
CQ_EXPECT_COMPLETION(cqv, tag(0x101), 1);
CQ_EXPECT_COMPLETION(cqv, tag(0x301), 1);
cq_verify(cqv);

GPR_ASSERT(GRPC_CHANNEL_READY ==
Expand All @@ -200,7 +200,7 @@ int main(int argc, char **argv) {
* we should see a connectivity change and then nothing */
set_resolve_port(-1);
grpc_server_shutdown_and_notify(server1, cq, tag(0xdead1));
cq_expect_completion(cqv, tag(0x9999), 1);
CQ_EXPECT_COMPLETION(cqv, tag(0x9999), 1);
cq_verify(cqv);
cq_verify_empty(cqv);

Expand Down Expand Up @@ -250,8 +250,8 @@ int main(int argc, char **argv) {
&request_metadata2, cq, cq, tag(0x401)));

/* second call should now start */
cq_expect_completion(cqv, tag(0x201), 1);
cq_expect_completion(cqv, tag(0x401), 1);
CQ_EXPECT_COMPLETION(cqv, tag(0x201), 1);
CQ_EXPECT_COMPLETION(cqv, tag(0x401), 1);
cq_verify(cqv);

/* listen for close on the server call to probe for finishing */
Expand All @@ -273,12 +273,12 @@ int main(int argc, char **argv) {
grpc_call_cancel(call2, NULL);

/* now everything else should finish */
cq_expect_completion(cqv, tag(0x102), 1);
cq_expect_completion(cqv, tag(0x202), 1);
cq_expect_completion(cqv, tag(0x302), 1);
cq_expect_completion(cqv, tag(0x402), 1);
cq_expect_completion(cqv, tag(0xdead1), 1);
cq_expect_completion(cqv, tag(0xdead2), 1);
CQ_EXPECT_COMPLETION(cqv, tag(0x102), 1);
CQ_EXPECT_COMPLETION(cqv, tag(0x202), 1);
CQ_EXPECT_COMPLETION(cqv, tag(0x302), 1);
CQ_EXPECT_COMPLETION(cqv, tag(0x402), 1);
CQ_EXPECT_COMPLETION(cqv, tag(0xdead1), 1);
CQ_EXPECT_COMPLETION(cqv, tag(0xdead2), 1);
cq_verify(cqv);

grpc_call_destroy(call1);
Expand Down
10 changes: 5 additions & 5 deletions test/core/end2end/invalid_call_argument_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ static void prepare_test(int is_client) {
&g_state.call_details,
&g_state.server_initial_metadata_recv,
g_state.cq, g_state.cq, tag(101)));
cq_expect_completion(g_state.cqv, tag(101), 1);
cq_expect_completion(g_state.cqv, tag(1), 1);
CQ_EXPECT_COMPLETION(g_state.cqv, tag(101), 1);
CQ_EXPECT_COMPLETION(g_state.cqv, tag(1), 1);
cq_verify(g_state.cqv);
}
}
Expand Down Expand Up @@ -191,7 +191,7 @@ static void test_send_initial_metadata_more_than_once() {
GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(g_state.call, g_state.ops,
(size_t)(op - g_state.ops),
tag(1), NULL));
cq_expect_completion(g_state.cqv, tag(1), 0);
CQ_EXPECT_COMPLETION(g_state.cqv, tag(1), 0);
cq_verify(g_state.cqv);

op = g_state.ops;
Expand Down Expand Up @@ -312,7 +312,7 @@ static void test_receive_initial_metadata_twice_at_client() {
GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(g_state.call, g_state.ops,
(size_t)(op - g_state.ops),
tag(1), NULL));
cq_expect_completion(g_state.cqv, tag(1), 0);
CQ_EXPECT_COMPLETION(g_state.cqv, tag(1), 0);
cq_verify(g_state.cqv);
op = g_state.ops;
op->op = GRPC_OP_RECV_INITIAL_METADATA;
Expand Down Expand Up @@ -405,7 +405,7 @@ static void test_recv_status_on_client_twice() {
GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(g_state.call, g_state.ops,
(size_t)(op - g_state.ops),
tag(1), NULL));
cq_expect_completion(g_state.cqv, tag(1), 1);
CQ_EXPECT_COMPLETION(g_state.cqv, tag(1), 1);
cq_verify(g_state.cqv);

op = g_state.ops;
Expand Down
2 changes: 1 addition & 1 deletion test/core/end2end/no_server_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ int main(int argc, char **argv) {
GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(
call, ops, (size_t)(op - ops), tag(1), NULL));
/* verify that all tags get completed */
cq_expect_completion(cqv, tag(1), 1);
CQ_EXPECT_COMPLETION(cqv, tag(1), 1);
cq_verify(cqv);

GPR_ASSERT(status == GRPC_STATUS_DEADLINE_EXCEEDED);
Expand Down
2 changes: 1 addition & 1 deletion test/core/end2end/tests/bad_hostname.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ static void simple_request_body(grpc_end2end_test_fixture f) {
error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL);
GPR_ASSERT(GRPC_CALL_OK == error);

cq_expect_completion(cqv, tag(1), 1);
CQ_EXPECT_COMPLETION(cqv, tag(1), 1);
cq_verify(cqv);

GPR_ASSERT(status == GRPC_STATUS_INTERNAL);
Expand Down
Loading

0 comments on commit 581367a

Please sign in to comment.