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