Debian Codegraph @

test/core/end2end/invalid_call_argument_test.cc

raw
1 /*
2 *
3 * Copyright 2015 gRPC authors.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 */
18
19 #include <grpc/impl/codegen/port_platform.h>
20
21 #include <limits.h>
22 #include <stdint.h>
23 #include <string.h>
24
25 #include <initializer_list>
26 #include <memory>
27 #include <string>
28
29 #include <grpc/byte_buffer.h>
30 #include <grpc/grpc.h>
31 #include <grpc/grpc_security.h>
32 #include <grpc/impl/codegen/propagation_bits.h>
33 #include <grpc/slice.h>
34 #include <grpc/status.h>
35 #include <grpc/support/log.h>
36 #include <grpc/support/time.h>
37
38 #include "src/core/lib/gprpp/host_port.h"
39 #include "test/core/end2end/cq_verifier.h"
40 #include "test/core/util/port.h"
41 #include "test/core/util/test_config.h"
42
43 static void* tag(intptr_t t) { return reinterpret_cast<void*>(t); }
44
45 struct test_state {
46 int is_client;
47 grpc_channel* chan;
48 grpc_call* call;
49 gpr_timespec deadline;
50 grpc_completion_queue* cq;
51 std::unique_ptr<grpc_core::CqVerifier> cqv;
52 grpc_op ops[6];
53 grpc_metadata_array initial_metadata_recv;
54 grpc_metadata_array trailing_metadata_recv;
55 grpc_status_code status;
56 grpc_slice details;
57 grpc_call* server_call;
58 grpc_server* server;
59 grpc_metadata_array server_initial_metadata_recv;
60 grpc_call_details call_details;
61 };
62
63 static struct test_state g_state;
64
65 static void prepare_test(int is_client) {
66 int port = grpc_pick_unused_port_or_die();
67 grpc_op* op;
68 g_state.is_client = is_client;
69 grpc_metadata_array_init(&g_state.initial_metadata_recv);
70 grpc_metadata_array_init(&g_state.trailing_metadata_recv);
71 g_state.deadline = grpc_timeout_seconds_to_deadline(5);
72 g_state.cq = grpc_completion_queue_create_for_next(nullptr);
73 g_state.cqv = std::make_unique<grpc_core::CqVerifier>(g_state.cq);
74 g_state.details = grpc_empty_slice();
75 memset(g_state.ops, 0, sizeof(g_state.ops));
76
77 if (is_client) {
78 /* create a call, channel to a non existant server */
79 grpc_channel_credentials* creds = grpc_insecure_credentials_create();
80 g_state.chan = grpc_channel_create("nonexistant:54321", creds, nullptr);
81 grpc_channel_credentials_release(creds);
82 grpc_slice host = grpc_slice_from_static_string("nonexistant");
83 g_state.call = grpc_channel_create_call(
84 g_state.chan, nullptr, GRPC_PROPAGATE_DEFAULTS, g_state.cq,
85 grpc_slice_from_static_string("/Foo"), &host, g_state.deadline,
86 nullptr);
87 } else {
88 g_state.server = grpc_server_create(nullptr, nullptr);
89 grpc_server_register_completion_queue(g_state.server, g_state.cq, nullptr);
90 std::string server_hostport = grpc_core::JoinHostPort("0.0.0.0", port);
91 grpc_server_credentials* server_creds =
92 grpc_insecure_server_credentials_create();
93 grpc_server_add_http2_port(g_state.server, server_hostport.c_str(),
94 server_creds);
95 grpc_server_credentials_release(server_creds);
96 grpc_server_start(g_state.server);
97 server_hostport = grpc_core::JoinHostPort("localhost", port);
98 grpc_channel_credentials* creds = grpc_insecure_credentials_create();
99 g_state.chan = grpc_channel_create(server_hostport.c_str(), creds, nullptr);
100 grpc_channel_credentials_release(creds);
101 grpc_slice host = grpc_slice_from_static_string("bar");
102 g_state.call = grpc_channel_create_call(
103 g_state.chan, nullptr, GRPC_PROPAGATE_DEFAULTS, g_state.cq,
104 grpc_slice_from_static_string("/Foo"), &host, g_state.deadline,
105 nullptr);
106 grpc_metadata_array_init(&g_state.server_initial_metadata_recv);
107 grpc_call_details_init(&g_state.call_details);
108 op = g_state.ops;
109 op->op = GRPC_OP_SEND_INITIAL_METADATA;
110 op->data.send_initial_metadata.count = 0;
111 op->flags = GRPC_INITIAL_METADATA_WAIT_FOR_READY;
112 op->reserved = nullptr;
113 op++;
114 GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(g_state.call, g_state.ops,
115 (size_t)(op - g_state.ops),
116 tag(1), nullptr));
117 GPR_ASSERT(GRPC_CALL_OK ==
118 grpc_server_request_call(g_state.server, &g_state.server_call,
119 &g_state.call_details,
120 &g_state.server_initial_metadata_recv,
121 g_state.cq, g_state.cq, tag(101)));
122 g_state.cqv->Expect(tag(101), true);
123 g_state.cqv->Expect(tag(1), true);
124 g_state.cqv->Verify();
125 }
126 }
127
128 static void cleanup_test() {
129 grpc_call_unref(g_state.call);
130 grpc_channel_destroy(g_state.chan);
131 grpc_slice_unref(g_state.details);
132 grpc_metadata_array_destroy(&g_state.initial_metadata_recv);
133 grpc_metadata_array_destroy(&g_state.trailing_metadata_recv);
134
135 if (!g_state.is_client) {
136 grpc_call_unref(g_state.server_call);
137 grpc_server_shutdown_and_notify(g_state.server, g_state.cq, tag(1000));
138 grpc_event ev;
139 do {
140 ev = grpc_completion_queue_next(
141 g_state.cq, grpc_timeout_seconds_to_deadline(5), nullptr);
142 } while (ev.type != GRPC_OP_COMPLETE || ev.tag != tag(1000));
143 grpc_server_destroy(g_state.server);
144 grpc_call_details_destroy(&g_state.call_details);
145 grpc_metadata_array_destroy(&g_state.server_initial_metadata_recv);
146 }
147 grpc_completion_queue_shutdown(g_state.cq);
148 while (grpc_completion_queue_next(g_state.cq,
149 gpr_inf_future(GPR_CLOCK_REALTIME), nullptr)
150 .type != GRPC_QUEUE_SHUTDOWN) {
151 }
152 grpc_completion_queue_destroy(g_state.cq);
153 }
154
155 static void test_non_null_reserved_on_start_batch() {
156 gpr_log(GPR_INFO, "test_non_null_reserved_on_start_batch");
157
158 prepare_test(1);
159 GPR_ASSERT(GRPC_CALL_ERROR ==
160 grpc_call_start_batch(g_state.call, nullptr, 0, nullptr, tag(1)));
161 cleanup_test();
162 }
163
164 static void test_non_null_reserved_on_op() {
165 gpr_log(GPR_INFO, "test_non_null_reserved_on_op");
166
167 grpc_op* op;
168 prepare_test(1);
169
170 op = g_state.ops;
171 op->op = GRPC_OP_SEND_INITIAL_METADATA;
172 op->data.send_initial_metadata.count = 0;
173 op->flags = 0;
174 op->reserved = tag(2);
175 op++;
176 GPR_ASSERT(GRPC_CALL_ERROR ==
177 grpc_call_start_batch(g_state.call, g_state.ops,
178 (size_t)(op - g_state.ops), tag(1),
179 nullptr));
180 cleanup_test();
181 }
182
183 static void test_send_initial_metadata_more_than_once() {
184 gpr_log(GPR_INFO, "test_send_initial_metadata_more_than_once");
185
186 grpc_op* op;
187 prepare_test(1);
188
189 op = g_state.ops;
190 op->op = GRPC_OP_SEND_INITIAL_METADATA;
191 op->data.send_initial_metadata.count = 0;
192 op->flags = 0;
193 op->reserved = nullptr;
194 op++;
195 GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(g_state.call, g_state.ops,
196 (size_t)(op - g_state.ops),
197 tag(1), nullptr));
198 g_state.cqv->Expect(tag(1), false);
199 g_state.cqv->Verify();
200
201 op = g_state.ops;
202 op->op = GRPC_OP_SEND_INITIAL_METADATA;
203 op->data.send_initial_metadata.count = 0;
204 op->flags = 0;
205 op->reserved = nullptr;
206 op++;
207 GPR_ASSERT(GRPC_CALL_ERROR_TOO_MANY_OPERATIONS ==
208 grpc_call_start_batch(g_state.call, g_state.ops,
209 (size_t)(op - g_state.ops), tag(1),
210 nullptr));
211 cleanup_test();
212 }
213
214 static void test_too_many_metadata() {
215 gpr_log(GPR_INFO, "test_too_many_metadata");
216
217 grpc_op* op;
218 prepare_test(1);
219
220 op = g_state.ops;
221 op->op = GRPC_OP_SEND_INITIAL_METADATA;
222 op->data.send_initial_metadata.count = static_cast<size_t>(INT_MAX) + 1;
223 op->flags = 0;
224 op->reserved = nullptr;
225 op++;
226 GPR_ASSERT(GRPC_CALL_ERROR_INVALID_METADATA ==
227 grpc_call_start_batch(g_state.call, g_state.ops,
228 (size_t)(op - g_state.ops), tag(1),
229 nullptr));
230 cleanup_test();
231 }
232
233 static void test_send_null_message() {
234 gpr_log(GPR_INFO, "test_send_null_message");
235
236 grpc_op* op;
237 prepare_test(1);
238
239 op = g_state.ops;
240 op->op = GRPC_OP_SEND_INITIAL_METADATA;
241 op->data.send_initial_metadata.count = 0;
242 op->flags = 0;
243 op->reserved = nullptr;
244 op++;
245 op->op = GRPC_OP_SEND_MESSAGE;
246 op->data.send_message.send_message = nullptr;
247 op->flags = 0;
248 op->reserved = nullptr;
249 op++;
250 GPR_ASSERT(GRPC_CALL_ERROR_INVALID_MESSAGE ==
251 grpc_call_start_batch(g_state.call, g_state.ops,
252 (size_t)(op - g_state.ops), tag(1),
253 nullptr));
254 cleanup_test();
255 }
256
257 static void test_send_messages_at_the_same_time() {
258 gpr_log(GPR_INFO, "test_send_messages_at_the_same_time");
259
260 grpc_op* op;
261 grpc_slice request_payload_slice =
262 grpc_slice_from_copied_string("hello world");
263 grpc_byte_buffer* request_payload =
264 grpc_raw_byte_buffer_create(&request_payload_slice, 1);
265 prepare_test(1);
266 op = g_state.ops;
267 op->op = GRPC_OP_SEND_INITIAL_METADATA;
268 op->data.send_initial_metadata.count = 0;
269 op->flags = 0;
270 op->reserved = nullptr;
271 op++;
272 op->op = GRPC_OP_SEND_MESSAGE;
273 op->data.send_message.send_message = request_payload;
274 op->flags = 0;
275 op->reserved = nullptr;
276 op++;
277 op->op = GRPC_OP_SEND_MESSAGE;
278 op->data.send_message.send_message = static_cast<grpc_byte_buffer*>(tag(2));
279 op->flags = 0;
280 op->reserved = nullptr;
281 op++;
282 GPR_ASSERT(GRPC_CALL_ERROR_TOO_MANY_OPERATIONS ==
283 grpc_call_start_batch(g_state.call, g_state.ops,
284 (size_t)(op - g_state.ops), tag(1),
285 nullptr));
286 grpc_byte_buffer_destroy(request_payload);
287 cleanup_test();
288 }
289
290 static void test_send_server_status_from_client() {
291 gpr_log(GPR_INFO, "test_send_server_status_from_client");
292
293 grpc_op* op;
294 prepare_test(1);
295
296 op = g_state.ops;
297 op->op = GRPC_OP_SEND_STATUS_FROM_SERVER;
298 op->data.send_status_from_server.trailing_metadata_count = 0;
299 op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED;
300 grpc_slice status_details = grpc_slice_from_static_string("xyz");
301 op->data.send_status_from_server.status_details = &status_details;
302 op->flags = 0;
303 op->reserved = nullptr;
304 op++;
305 GPR_ASSERT(GRPC_CALL_ERROR_NOT_ON_CLIENT ==
306 grpc_call_start_batch(g_state.call, g_state.ops,
307 (size_t)(op - g_state.ops), tag(1),
308 nullptr));
309 cleanup_test();
310 }
311
312 static void test_receive_initial_metadata_twice_at_client() {
313 gpr_log(GPR_INFO, "test_receive_initial_metadata_twice_at_client");
314
315 grpc_op* op;
316 prepare_test(1);
317 op = g_state.ops;
318 op->op = GRPC_OP_RECV_INITIAL_METADATA;
319 op->data.recv_initial_metadata.recv_initial_metadata =
320 &g_state.initial_metadata_recv;
321 op->flags = 0;
322 op->reserved = nullptr;
323 op++;
324 GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(g_state.call, g_state.ops,
325 (size_t)(op - g_state.ops),
326 tag(1), nullptr));
327 g_state.cqv->Expect(tag(1), false);
328 g_state.cqv->Verify();
329 op = g_state.ops;
330 op->op = GRPC_OP_RECV_INITIAL_METADATA;
331 op->data.recv_initial_metadata.recv_initial_metadata =
332 &g_state.initial_metadata_recv;
333 op->flags = 0;
334 op->reserved = nullptr;
335 op++;
336 GPR_ASSERT(GRPC_CALL_ERROR_TOO_MANY_OPERATIONS ==
337 grpc_call_start_batch(g_state.call, g_state.ops,
338 (size_t)(op - g_state.ops), tag(1),
339 nullptr));
340 cleanup_test();
341 }
342
343 static void test_receive_message_with_invalid_flags() {
344 gpr_log(GPR_INFO, "test_receive_message_with_invalid_flags");
345
346 grpc_op* op;
347 grpc_byte_buffer* payload = nullptr;
348 prepare_test(1);
349 op = g_state.ops;
350 op->op = GRPC_OP_RECV_MESSAGE;
351 op->data.recv_message.recv_message = &payload;
352 op->flags = 1;
353 op->reserved = nullptr;
354 op++;
355 GPR_ASSERT(GRPC_CALL_ERROR_INVALID_FLAGS ==
356 grpc_call_start_batch(g_state.call, g_state.ops,
357 (size_t)(op - g_state.ops), tag(1),
358 nullptr));
359 cleanup_test();
360 }
361
362 static void test_receive_two_messages_at_the_same_time() {
363 gpr_log(GPR_INFO, "test_receive_two_messages_at_the_same_time");
364
365 grpc_op* op;
366 grpc_byte_buffer* payload = nullptr;
367 prepare_test(1);
368 op = g_state.ops;
369 op->op = GRPC_OP_RECV_MESSAGE;
370 op->data.recv_message.recv_message = &payload;
371 op->flags = 0;
372 op->reserved = nullptr;
373 op++;
374 op->op = GRPC_OP_RECV_MESSAGE;
375 op->data.recv_message.recv_message = &payload;
376 op->flags = 0;
377 op->reserved = nullptr;
378 op++;
379 GPR_ASSERT(GRPC_CALL_ERROR_TOO_MANY_OPERATIONS ==
380 grpc_call_start_batch(g_state.call, g_state.ops,
381 (size_t)(op - g_state.ops), tag(1),
382 nullptr));
383 cleanup_test();
384 }
385
386 static void test_recv_close_on_server_from_client() {
387 gpr_log(GPR_INFO, "test_recv_close_on_server_from_client");
388
389 grpc_op* op;
390 prepare_test(1);
391
392 op = g_state.ops;
393 op->op = GRPC_OP_RECV_CLOSE_ON_SERVER;
394 op->data.recv_close_on_server.cancelled = nullptr;
395 op->flags = 0;
396 op->reserved = nullptr;
397 op++;
398 GPR_ASSERT(GRPC_CALL_ERROR_NOT_ON_CLIENT ==
399 grpc_call_start_batch(g_state.call, g_state.ops,
400 (size_t)(op - g_state.ops), tag(1),
401 nullptr));
402 cleanup_test();
403 }
404
405 static void test_recv_status_on_client_twice() {
406 gpr_log(GPR_INFO, "test_recv_status_on_client_twice");
407
408 grpc_op* op;
409 prepare_test(1);
410
411 op = g_state.ops;
412 op->op = GRPC_OP_RECV_STATUS_ON_CLIENT;
413 op->data.recv_status_on_client.trailing_metadata =
414 &g_state.trailing_metadata_recv;
415 op->data.recv_status_on_client.status = &g_state.status;
416 op->data.recv_status_on_client.status_details = &g_state.details;
417 op->flags = 0;
418 op->reserved = nullptr;
419 op++;
420 GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(g_state.call, g_state.ops,
421 (size_t)(op - g_state.ops),
422 tag(1), nullptr));
423 g_state.cqv->Expect(tag(1), true);
424 g_state.cqv->Verify();
425
426 op = g_state.ops;
427 op->op = GRPC_OP_RECV_STATUS_ON_CLIENT;
428 op->data.recv_status_on_client.trailing_metadata = nullptr;
429 op->data.recv_status_on_client.status = nullptr;
430 op->data.recv_status_on_client.status_details = nullptr;
431 op->flags = 0;
432 op->reserved = nullptr;
433 op++;
434 GPR_ASSERT(GRPC_CALL_ERROR_TOO_MANY_OPERATIONS ==
435 grpc_call_start_batch(g_state.call, g_state.ops,
436 (size_t)(op - g_state.ops), tag(1),
437 nullptr));
438 cleanup_test();
439 }
440
441 static void test_send_close_from_client_on_server() {
442 gpr_log(GPR_INFO, "test_send_close_from_client_on_server");
443
444 grpc_op* op;
445 prepare_test(0);
446
447 op = g_state.ops;
448 op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT;
449 op->flags = 0;
450 op->reserved = nullptr;
451 op++;
452 GPR_ASSERT(GRPC_CALL_ERROR_NOT_ON_SERVER ==
453 grpc_call_start_batch(g_state.server_call, g_state.ops,
454 (size_t)(op - g_state.ops), tag(2),
455 nullptr));
456 cleanup_test();
457 }
458
459 static void test_recv_status_on_client_from_server() {
460 gpr_log(GPR_INFO, "test_recv_status_on_client_from_server");
461
462 grpc_op* op;
463 prepare_test(0);
464
465 op = g_state.ops;
466 op->op = GRPC_OP_RECV_STATUS_ON_CLIENT;
467 op->data.recv_status_on_client.trailing_metadata =
468 &g_state.trailing_metadata_recv;
469 op->data.recv_status_on_client.status = &g_state.status;
470 op->data.recv_status_on_client.status_details = &g_state.details;
471 op->flags = 0;
472 op->reserved = nullptr;
473 op++;
474 GPR_ASSERT(GRPC_CALL_ERROR_NOT_ON_SERVER ==
475 grpc_call_start_batch(g_state.server_call, g_state.ops,
476 (size_t)(op - g_state.ops), tag(2),
477 nullptr));
478 cleanup_test();
479 }
480
481 static void test_send_status_from_server_with_invalid_flags() {
482 gpr_log(GPR_INFO, "test_send_status_from_server_with_invalid_flags");
483
484 grpc_op* op;
485 prepare_test(0);
486
487 op = g_state.ops;
488 op->op = GRPC_OP_SEND_STATUS_FROM_SERVER;
489 op->data.send_status_from_server.trailing_metadata_count = 0;
490 op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED;
491 grpc_slice status_details = grpc_slice_from_static_string("xyz");
492 op->data.send_status_from_server.status_details = &status_details;
493 op->flags = 1;
494 op->reserved = nullptr;
495 op++;
496 GPR_ASSERT(GRPC_CALL_ERROR_INVALID_FLAGS ==
497 grpc_call_start_batch(g_state.server_call, g_state.ops,
498 (size_t)(op - g_state.ops), tag(2),
499 nullptr));
500 cleanup_test();
501 }
502
503 static void test_too_many_trailing_metadata() {
504 gpr_log(GPR_INFO, "test_too_many_trailing_metadata");
505
506 grpc_op* op;
507 prepare_test(0);
508
509 op = g_state.ops;
510 op->op = GRPC_OP_SEND_STATUS_FROM_SERVER;
511 op->data.send_status_from_server.trailing_metadata_count =
512 static_cast<size_t>(INT_MAX) + 1;
513 op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED;
514 grpc_slice status_details = grpc_slice_from_static_string("xyz");
515 op->data.send_status_from_server.status_details = &status_details;
516 op->flags = 0;
517 op->reserved = nullptr;
518 op++;
519 GPR_ASSERT(GRPC_CALL_ERROR_INVALID_METADATA ==
520 grpc_call_start_batch(g_state.server_call, g_state.ops,
521 (size_t)(op - g_state.ops), tag(2),
522 nullptr));
523 cleanup_test();
524 }
525
526 static void test_send_server_status_twice() {
527 gpr_log(GPR_INFO, "test_send_server_status_twice");
528
529 grpc_op* op;
530 prepare_test(0);
531
532 op = g_state.ops;
533 op->op = GRPC_OP_SEND_STATUS_FROM_SERVER;
534 op->data.send_status_from_server.trailing_metadata_count = 0;
535 op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED;
536 grpc_slice status_details = grpc_slice_from_static_string("xyz");
537 op->data.send_status_from_server.status_details = &status_details;
538 op->flags = 0;
539 op->reserved = nullptr;
540 op++;
541 op->op = GRPC_OP_SEND_STATUS_FROM_SERVER;
542 op->data.send_status_from_server.trailing_metadata_count = 0;
543 op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED;
544 op->data.send_status_from_server.status_details = &status_details;
545 op->flags = 0;
546 op->reserved = nullptr;
547 op++;
548 GPR_ASSERT(GRPC_CALL_ERROR_TOO_MANY_OPERATIONS ==
549 grpc_call_start_batch(g_state.server_call, g_state.ops,
550 (size_t)(op - g_state.ops), tag(2),
551 nullptr));
552 cleanup_test();
553 }
554
555 static void test_recv_close_on_server_with_invalid_flags() {
556 gpr_log(GPR_INFO, "test_recv_close_on_server_with_invalid_flags");
557
558 grpc_op* op;
559 prepare_test(0);
560
561 op = g_state.ops;
562 op->op = GRPC_OP_RECV_CLOSE_ON_SERVER;
563 op->data.recv_close_on_server.cancelled = nullptr;
564 op->flags = 1;
565 op->reserved = nullptr;
566 op++;
567 GPR_ASSERT(GRPC_CALL_ERROR_INVALID_FLAGS ==
568 grpc_call_start_batch(g_state.server_call, g_state.ops,
569 (size_t)(op - g_state.ops), tag(2),
570 nullptr));
571 cleanup_test();
572 }
573
574 static void test_recv_close_on_server_twice() {
575 gpr_log(GPR_INFO, "test_recv_close_on_server_twice");
576
577 grpc_op* op;
578 prepare_test(0);
579
580 op = g_state.ops;
581 op->op = GRPC_OP_RECV_CLOSE_ON_SERVER;
582 op->data.recv_close_on_server.cancelled = nullptr;
583 op->flags = 0;
584 op->reserved = nullptr;
585 op++;
586 op->op = GRPC_OP_RECV_CLOSE_ON_SERVER;
587 op->data.recv_close_on_server.cancelled = nullptr;
588 op->flags = 0;
589 op->reserved = nullptr;
590 op++;
591 GPR_ASSERT(GRPC_CALL_ERROR_TOO_MANY_OPERATIONS ==
592 grpc_call_start_batch(g_state.server_call, g_state.ops,
593 (size_t)(op - g_state.ops), tag(2),
594 nullptr));
595 cleanup_test();
596 }
597
598 static void test_invalid_initial_metadata_reserved_key() {
599 gpr_log(GPR_INFO, "test_invalid_initial_metadata_reserved_key");
600
601 grpc_metadata metadata;
602 metadata.key = grpc_slice_from_static_string(":start_with_colon");
603 metadata.value = grpc_slice_from_static_string("value");
604
605 grpc_op* op;
606 prepare_test(1);
607 op = g_state.ops;
608 op->op = GRPC_OP_SEND_INITIAL_METADATA;
609 op->data.send_initial_metadata.count = 1;
610 op->data.send_initial_metadata.metadata = &metadata;
611 op->flags = 0;
612 op->reserved = nullptr;
613 op++;
614 GPR_ASSERT(GRPC_CALL_ERROR_INVALID_METADATA ==
615 grpc_call_start_batch(g_state.call, g_state.ops,
616 (size_t)(op - g_state.ops), tag(1),
617 nullptr));
618 cleanup_test();
619 }
620
621 static void test_multiple_ops_in_a_single_batch() {
622 gpr_log(GPR_INFO, "test_multiple_ops_in_a_single_batch");
623
624 grpc_op* op;
625 prepare_test(1);
626
627 for (auto which :
628 {GRPC_OP_SEND_INITIAL_METADATA, GRPC_OP_RECV_INITIAL_METADATA,
629 GRPC_OP_SEND_MESSAGE, GRPC_OP_RECV_MESSAGE,
630 GRPC_OP_RECV_STATUS_ON_CLIENT, GRPC_OP_RECV_CLOSE_ON_SERVER,
631 GRPC_OP_SEND_STATUS_FROM_SERVER, GRPC_OP_RECV_CLOSE_ON_SERVER}) {
632 op = g_state.ops;
633 op->op = which;
634 op++;
635 op->op = which;
636 op++;
637 GPR_ASSERT(GRPC_CALL_ERROR_TOO_MANY_OPERATIONS ==
638 grpc_call_start_batch(g_state.call, g_state.ops,
639 (size_t)(op - g_state.ops), tag(1),
640 nullptr));
641 }
642
643 cleanup_test();
644 }
645
646 int main(int argc, char** argv) {
647 grpc::testing::TestEnvironment env(&argc, argv);
648 grpc_init();
649 test_invalid_initial_metadata_reserved_key();
650 test_non_null_reserved_on_start_batch();
651 test_non_null_reserved_on_op();
652 test_send_initial_metadata_more_than_once();
653 test_too_many_metadata();
654 test_send_null_message();
655 test_send_messages_at_the_same_time();
656 test_send_server_status_from_client();
657 test_receive_initial_metadata_twice_at_client();
658 test_receive_message_with_invalid_flags();
659 test_receive_two_messages_at_the_same_time();
660 test_recv_close_on_server_from_client();
661 test_recv_status_on_client_twice();
662 test_send_close_from_client_on_server();
663 test_recv_status_on_client_from_server();
664 test_send_status_from_server_with_invalid_flags();
665 test_too_many_trailing_metadata();
666 test_send_server_status_twice();
667 test_recv_close_on_server_with_invalid_flags();
668 test_recv_close_on_server_twice();
669 test_multiple_ops_in_a_single_batch();
670 grpc_shutdown();
671
672 return 0;
673 }