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