diff options
author | Craig Tiller <ctiller@google.com> | 2017-03-31 15:21:04 -0700 |
---|---|---|
committer | Craig Tiller <ctiller@google.com> | 2017-03-31 15:21:04 -0700 |
commit | e431b52f0b6005786c5a3cca7f785931fe035056 (patch) | |
tree | 67062be879f1ea557cf6b43e026c325225a309f6 | |
parent | a911dbacd91aac75d4086f3bbd2d60b0cf27a4a4 (diff) |
Fix crashes
-rw-r--r-- | test/cpp/microbenchmarks/bm_chttp2_transport.cc | 42 |
1 files changed, 33 insertions, 9 deletions
diff --git a/test/cpp/microbenchmarks/bm_chttp2_transport.cc b/test/cpp/microbenchmarks/bm_chttp2_transport.cc index a084643c90..042d1cac21 100644 --- a/test/cpp/microbenchmarks/bm_chttp2_transport.cc +++ b/test/cpp/microbenchmarks/bm_chttp2_transport.cc @@ -306,9 +306,15 @@ static void BM_StreamCreateSendInitialMetadataDestroy(benchmark::State &state) { Fixture f(grpc::ChannelArguments(), true); Stream s(&f); grpc_transport_stream_op op; + grpc_transport_stream_op_payload op_payload; std::unique_ptr<Closure> start; std::unique_ptr<Closure> done; + auto reset_op = [&]() { + memset(&op, 0, sizeof(op)); + op.payload = &op_payload; + }; + grpc_metadata_batch b; grpc_metadata_batch_init(&b); b.deadline = gpr_inf_future(GPR_CLOCK_MONOTONIC); @@ -324,14 +330,14 @@ static void BM_StreamCreateSendInitialMetadataDestroy(benchmark::State &state) { start = MakeClosure([&](grpc_exec_ctx *exec_ctx, grpc_error *error) { if (!state.KeepRunning()) return; s.Init(state); - memset(&op, 0, sizeof(op)); + reset_op(); op.on_complete = done.get(); op.send_initial_metadata = true; op.payload->send_initial_metadata.send_initial_metadata = &b; s.Op(&op); }); done = MakeClosure([&](grpc_exec_ctx *exec_ctx, grpc_error *error) { - memset(&op, 0, sizeof(op)); + reset_op(); op.cancel_stream = true; op.payload->cancel_stream.cancel_error = GRPC_ERROR_CANCELLED; s.Op(&op); @@ -351,10 +357,15 @@ static void BM_TransportEmptyOp(benchmark::State &state) { Stream s(&f); s.Init(state); grpc_transport_stream_op op; + grpc_transport_stream_op_payload op_payload; + auto reset_op = [&]() { + memset(&op, 0, sizeof(op)); + op.payload = &op_payload; + }; std::unique_ptr<Closure> c = MakeClosure([&](grpc_exec_ctx *exec_ctx, grpc_error *error) { if (!state.KeepRunning()) return; - memset(&op, 0, sizeof(op)); + reset_op(); op.on_complete = c.get(); s.Op(&op); }); @@ -373,6 +384,11 @@ static void BM_TransportStreamSend(benchmark::State &state) { Stream s(&f); s.Init(state); grpc_transport_stream_op op; + grpc_transport_stream_op_payload op_payload; + auto reset_op = [&]() { + memset(&op, 0, sizeof(op)); + op.payload = &op_payload; + }; grpc_slice_buffer_stream send_stream; grpc_slice_buffer send_buffer; grpc_slice_buffer_init(&send_buffer); @@ -399,21 +415,21 @@ static void BM_TransportStreamSend(benchmark::State &state) { s.chttp2_stream()->outgoing_window_delta = 1024 * 1024 * 1024; f.chttp2_transport()->outgoing_window = 1024 * 1024 * 1024; grpc_slice_buffer_stream_init(&send_stream, &send_buffer, 0); - memset(&op, 0, sizeof(op)); + reset_op(); op.on_complete = c.get(); op.send_message = true; op.payload->send_message.send_message = &send_stream.base; s.Op(&op); }); - memset(&op, 0, sizeof(op)); + reset_op(); op.send_initial_metadata = true; op.payload->send_initial_metadata.send_initial_metadata = &b; op.on_complete = c.get(); s.Op(&op); f.FlushExecCtx(); - memset(&op, 0, sizeof(op)); + reset_op(); op.cancel_stream = true; op.payload->cancel_stream.cancel_error = GRPC_ERROR_CANCELLED; s.Op(&op); @@ -488,10 +504,16 @@ static void BM_TransportStreamRecv(benchmark::State &state) { Fixture f(grpc::ChannelArguments(), true); Stream s(&f); s.Init(state); + grpc_transport_stream_op_payload op_payload; grpc_transport_stream_op op; grpc_byte_stream *recv_stream; grpc_slice incoming_data = CreateIncomingDataSlice(state.range(0), 16384); + auto reset_op = [&]() { + memset(&op, 0, sizeof(op)); + op.payload = &op_payload; + }; + grpc_metadata_batch b; grpc_metadata_batch_init(&b); grpc_metadata_batch b_recv; @@ -523,7 +545,7 @@ static void BM_TransportStreamRecv(benchmark::State &state) { s.chttp2_stream()->incoming_window_delta = 1024 * 1024 * 1024; f.chttp2_transport()->incoming_window = 1024 * 1024 * 1024; received = 0; - memset(&op, 0, sizeof(op)); + reset_op(); op.on_complete = do_nothing.get(); op.recv_message = true; op.payload->recv_message.recv_message = &recv_stream; @@ -558,11 +580,13 @@ static void BM_TransportStreamRecv(benchmark::State &state) { grpc_closure_run(exec_ctx, drain.get(), GRPC_ERROR_NONE); }); - memset(&op, 0, sizeof(op)); + reset_op(); op.send_initial_metadata = true; op.payload->send_initial_metadata.send_initial_metadata = &b; op.recv_initial_metadata = true; op.payload->recv_initial_metadata.recv_initial_metadata = &b_recv; + op.payload->recv_initial_metadata.recv_initial_metadata_ready = + do_nothing.get(); op.on_complete = c.get(); s.Op(&op); f.PushInput(SLICE_FROM_BUFFER( @@ -579,7 +603,7 @@ static void BM_TransportStreamRecv(benchmark::State &state) { "\x10\x14grpc-accept-encoding\x15identity,deflate,gzip")); f.FlushExecCtx(); - memset(&op, 0, sizeof(op)); + reset_op(); op.cancel_stream = true; op.payload->cancel_stream.cancel_error = GRPC_ERROR_CANCELLED; s.Op(&op); |