Add helper function for rst_stream
diff --git a/test/core/bad_client/bad_client.cc b/test/core/bad_client/bad_client.cc
index 0c4deaf..7db7788 100644
--- a/test/core/bad_client/bad_client.cc
+++ b/test/core/bad_client/bad_client.cc
@@ -38,15 +38,6 @@
#define MIN_HTTP2_FRAME_SIZE 9
-/* connection preface and settings frame to be sent by the client */
-#define CONNECTION_PREFACE_FROM_CLIENT \
- "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" \
- "\x00\x00\x00\x04\x00\x00\x00\x00\x00"
-
-grpc_bad_client_arg connection_preface_arg = {
- client_connection_preface_validator, CONNECTION_PREFACE_FROM_CLIENT,
- sizeof(CONNECTION_PREFACE_FROM_CLIENT) - 1};
-
/* Args to provide to thread running server side validator */
typedef struct {
grpc_server* server;
@@ -67,8 +58,9 @@
/* Sets the done_write event */
static void set_done_write(void* arg, grpc_error* error) {
- gpr_event* set_done = (gpr_event*)arg;
- gpr_event_set(set_done, (void*)1);
+ gpr_log(GPR_INFO, "done writing");
+ gpr_event* done_write = (gpr_event*)arg;
+ gpr_event_set(done_write, (void*)1);
}
static void server_setup_transport(void* ts, grpc_transport* transport) {
@@ -84,10 +76,10 @@
gpr_event_set(read_done, (void*)1);
}
-/* Runs client side validators */
-void grpc_run_client_side_validators(grpc_bad_client_arg* arg, uint32_t flags,
- grpc_endpoint_pair* sfd,
- grpc_completion_queue* client_cq) {
+/* Runs client side validator */
+void grpc_run_client_side_validator(grpc_bad_client_arg* arg, uint32_t flags,
+ grpc_endpoint_pair* sfd,
+ grpc_completion_queue* client_cq) {
char* hex;
gpr_event done_write;
if (arg->client_payload_length < 4 * 1024) {
@@ -156,7 +148,7 @@
nullptr)
.type == GRPC_QUEUE_TIMEOUT);
} while (!gpr_event_get(&read_done_event));
- if (arg->client_validator(&incoming)) break;
+ if (arg->client_validator(&incoming, arg->client_validator_arg)) break;
gpr_log(GPR_INFO,
"client validator failed; trying additional read "
"in case we didn't get all the data");
@@ -214,7 +206,7 @@
/* Start validator */
gpr_thd_new(&id, "grpc_bad_client", thd_func, &a, nullptr);
for (int i = 0; i < num_args; i++) {
- grpc_run_client_side_validators(&args[i], flags, &sfd, client_cq);
+ grpc_run_client_side_validator(&args[i], flags, &sfd, client_cq);
}
/* Wait for server thread to finish */
GPR_ASSERT(gpr_event_wait(&a.done_thd, grpc_timeout_seconds_to_deadline(1)));
@@ -240,7 +232,8 @@
grpc_shutdown();
}
-bool client_connection_preface_validator(grpc_slice_buffer* incoming) {
+bool client_connection_preface_validator(grpc_slice_buffer* incoming,
+ void* arg) {
if (incoming->count < 1) {
return false;
}
@@ -257,6 +250,44 @@
return true;
}
+/* connection preface and settings frame to be sent by the client */
+#define CONNECTION_PREFACE_FROM_CLIENT \
+ "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" \
+ "\x00\x00\x00\x04\x00\x00\x00\x00\x00"
+
+grpc_bad_client_arg connection_preface_arg = {
+ client_connection_preface_validator, nullptr,
+ CONNECTION_PREFACE_FROM_CLIENT, sizeof(CONNECTION_PREFACE_FROM_CLIENT) - 1};
+
+bool rst_stream_client_validator(grpc_slice_buffer* incoming, void* arg) {
+ // Get last frame from incoming slice buffer.
+ grpc_slice_buffer last_frame_buffer;
+ grpc_slice_buffer_init(&last_frame_buffer);
+ grpc_slice_buffer_trim_end(incoming, 13, &last_frame_buffer);
+ GPR_ASSERT(last_frame_buffer.count == 1);
+ grpc_slice last_frame = last_frame_buffer.slices[0];
+
+ const uint8_t* p = GRPC_SLICE_START_PTR(last_frame);
+ bool success =
+ // Length == 4
+ *p++ != 0 || *p++ != 0 || *p++ != 4 ||
+ // Frame type (RST_STREAM)
+ *p++ != 3 ||
+ // Flags
+ *p++ != 0 ||
+ // Stream ID.
+ *p++ != 0 || *p++ != 0 || *p++ != 0 || *p++ != 1 ||
+ // Payload (error code)
+ *p++ == 0 || *p++ == 0 || *p++ == 0 || *p == 0 || *p == 11;
+
+ if (!success) {
+ gpr_log(GPR_INFO, "client expected RST_STREAM frame, not found");
+ }
+
+ grpc_slice_buffer_destroy(&last_frame_buffer);
+ return success;
+}
+
static void* tag(intptr_t t) { return (void*)t; }
void server_verifier_request_call(grpc_server* server,
diff --git a/test/core/bad_client/bad_client.h b/test/core/bad_client/bad_client.h
index 54bf022..bf73a78 100644
--- a/test/core/bad_client/bad_client.h
+++ b/test/core/bad_client/bad_client.h
@@ -35,10 +35,11 @@
/* Returns false if we need to read more data. */
typedef bool (*grpc_bad_client_client_stream_validator)(
- grpc_slice_buffer* incoming);
+ grpc_slice_buffer* incoming, void* arg);
struct grpc_bad_client_arg {
grpc_bad_client_client_stream_validator client_validator;
+ void* client_validator_arg;
const char* client_payload;
size_t client_payload_length;
};
@@ -47,11 +48,12 @@
#define GRPC_BAD_CLIENT_LARGE_REQUEST 2
/* Test runner.
-
- Create a server, and for each arg in args send client_payload. For each
- payload, run client_validator to make sure that the response is as expected.
- Also execute server_validator in a separate thread to assert that the bytes
- are handled as expected. */
+ *
+ * Create a server, and for each arg in \a args send client_payload. For each
+ * payload, run client_validator to make sure that the response is as expected.
+ * Also execute \a server_validator in a separate thread to assert that the
+ * bytes are handled as expected.
+ */
void grpc_run_bad_client_test(
grpc_bad_client_server_side_validator server_validator,
grpc_bad_client_arg args[], int num_args, uint32_t flags);
@@ -59,20 +61,28 @@
#define COMBINE1(X, Y) X##Y
#define COMBINE(X, Y) COMBINE1(X, Y)
-#define GRPC_RUN_BAD_CLIENT_TEST(server_validator, client_validator, payload, \
- flags) \
- grpc_bad_client_arg COMBINE(bca, __LINE__) = {client_validator, payload, \
- sizeof(payload) - 1}; \
+#define GRPC_RUN_BAD_CLIENT_TEST(server_validator, client_validator, payload, \
+ flags) \
+ grpc_bad_client_arg COMBINE(bca, __LINE__) = {client_validator, nullptr, \
+ payload, sizeof(payload) - 1}; \
grpc_run_bad_client_test(server_validator, &COMBINE(bca, __LINE__), 1, flags)
-/* Client side validator for connection preface from server */
-bool client_connection_preface_validator(grpc_slice_buffer* incoming);
+/* Helper validator functions */
+/* Client side validator for connection preface from server. \a arg is unused */
+bool client_connection_preface_validator(grpc_slice_buffer* incoming,
+ void* arg);
+/* Client side validator for checking if reset stream is present at the end
+ * of the buffer. \a arg is unused.
+ */
+bool rst_stream_client_validator(grpc_slice_buffer* incoming, void* arg);
+
+/* Helper grpc_bad_client_arg arguments for direct use */
/* Sends a connection preface from the client with an empty settings frame */
extern grpc_bad_client_arg connection_preface_arg;
/* Server side verifier function that performs a
- * single grpc_server_request_call */
+ * single grpc_server_request_call */
void server_verifier_request_call(grpc_server* server,
grpc_completion_queue* cq,
void* registered_method);
diff --git a/test/core/bad_client/tests/head_of_line_blocking.cc b/test/core/bad_client/tests/head_of_line_blocking.cc
index 7b1940d..8668e09 100644
--- a/test/core/bad_client/tests/head_of_line_blocking.cc
+++ b/test/core/bad_client/tests/head_of_line_blocking.cc
@@ -131,7 +131,7 @@
addbuf(hdr, sizeof(hdr));
addbuf(msg, FRAME_SIZE);
}
- grpc_bad_client_arg bca = {nullptr, g_buffer, g_count};
+ grpc_bad_client_arg bca = {nullptr, nullptr, g_buffer, g_count};
grpc_run_bad_client_test(verifier, &bca, 1, 0);
gpr_free(g_buffer);
grpc_shutdown();
diff --git a/test/core/bad_client/tests/large_metadata.cc b/test/core/bad_client/tests/large_metadata.cc
index 600d000..429af8c 100644
--- a/test/core/bad_client/tests/large_metadata.cc
+++ b/test/core/bad_client/tests/large_metadata.cc
@@ -138,43 +138,6 @@
cq_verifier_destroy(cqv);
}
-static bool client_validator(grpc_slice_buffer* incoming) {
- for (size_t i = 0; i < incoming->count; ++i) {
- const char* s = (const char*)GRPC_SLICE_START_PTR(incoming->slices[i]);
- char* hex = gpr_dump(s, GRPC_SLICE_LENGTH(incoming->slices[i]),
- GPR_DUMP_HEX | GPR_DUMP_ASCII);
- gpr_log(GPR_INFO, "RESPONSE SLICE %" PRIdPTR ": %s", i, hex);
- gpr_free(hex);
- }
-
- // Get last frame from incoming slice buffer.
- grpc_slice_buffer last_frame_buffer;
- grpc_slice_buffer_init(&last_frame_buffer);
- grpc_slice_buffer_trim_end(incoming, 13, &last_frame_buffer);
- GPR_ASSERT(last_frame_buffer.count == 1);
- grpc_slice last_frame = last_frame_buffer.slices[0];
-
- const uint8_t* p = GRPC_SLICE_START_PTR(last_frame);
- bool success =
- // Length == 4
- *p++ != 0 || *p++ != 0 || *p++ != 4 ||
- // Frame type (RST_STREAM)
- *p++ != 3 ||
- // Flags
- *p++ != 0 ||
- // Stream ID.
- *p++ != 0 || *p++ != 0 || *p++ != 0 || *p++ != 1 ||
- // Payload (error code)
- *p++ == 0 || *p++ == 0 || *p++ == 0 || *p == 0 || *p == 11;
-
- if (!success) {
- gpr_log(GPR_INFO, "client expected RST_STREAM frame, not found");
- }
-
- grpc_slice_buffer_destroy(&last_frame_buffer);
- return success;
-}
-
int main(int argc, char** argv) {
int i;
@@ -199,7 +162,7 @@
client_headers, headers_len);
grpc_bad_client_arg args[2];
args[0] = connection_preface_arg;
- args[1].client_validator = client_validator;
+ args[1].client_validator = rst_stream_client_validator;
args[1].client_payload = client_payload;
args[1].client_payload_length = sizeof(client_payload) - 1;
@@ -208,7 +171,7 @@
// Test sending more metadata than the client will accept.
GRPC_RUN_BAD_CLIENT_TEST(server_verifier_sends_too_much_metadata,
- client_validator,
+ rst_stream_client_validator,
PFX_TOO_MUCH_METADATA_FROM_SERVER_STR, 0);
return 0;
}
diff --git a/test/core/bad_client/tests/window_overflow.cc b/test/core/bad_client/tests/window_overflow.cc
index 3c3b733..3fda2e2 100644
--- a/test/core/bad_client/tests/window_overflow.cc
+++ b/test/core/bad_client/tests/window_overflow.cc
@@ -26,8 +26,7 @@
#include "src/core/lib/surface/server.h"
#define PFX_STR \
- "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" \
- "\x00\x00\x00\x04\x00\x00\x00\x00\x00" /* settings frame */ \
+ "\x00\x00\x00\x04\x01\x00\x00\x00\x00" \
"\x00\x00\xc9\x01\x04\x00\x00\x00\x01" /* headers: generated from \
simple_request.headers in this \
directory */ \
@@ -92,8 +91,10 @@
addbuf(message, sizeof(message));
}
}
- grpc_bad_client_arg bca = {nullptr, g_buffer, g_count};
- grpc_run_bad_client_test(verifier, &bca, 1, GRPC_BAD_CLIENT_LARGE_REQUEST);
+ grpc_bad_client_arg bca[2];
+ bca[0] = connection_preface_arg;
+ bca[1] = {rst_stream_client_validator, nullptr, g_buffer, g_count};
+ grpc_run_bad_client_test(verifier, bca, 2, GRPC_BAD_CLIENT_LARGE_REQUEST);
gpr_free(g_buffer);
grpc_shutdown();