• 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 "test/core/end2end/end2end_tests.h"
20 
21 #include <stdio.h>
22 #include <string.h>
23 
24 #include <grpc/byte_buffer.h>
25 #include <grpc/byte_buffer_reader.h>
26 #include <grpc/compression.h>
27 #include <grpc/support/alloc.h>
28 #include <grpc/support/log.h>
29 #include <grpc/support/string_util.h>
30 #include <grpc/support/time.h>
31 
32 #include "src/core/lib/channel/channel_args.h"
33 #include "src/core/lib/surface/call.h"
34 #include "src/core/lib/surface/call_test_only.h"
35 #include "src/core/lib/transport/static_metadata.h"
36 #include "test/core/end2end/cq_verifier.h"
37 
tag(intptr_t t)38 static void* tag(intptr_t t) { return (void*)t; }
39 
begin_test(grpc_end2end_test_config config,const char * test_name,grpc_channel_args * client_args,grpc_channel_args * server_args)40 static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config,
41                                             const char* test_name,
42                                             grpc_channel_args* client_args,
43                                             grpc_channel_args* server_args) {
44   grpc_end2end_test_fixture f;
45   gpr_log(GPR_INFO, "Running test: %s/%s", test_name, config.name);
46   f = config.create_fixture(client_args, server_args);
47   config.init_server(&f, server_args);
48   config.init_client(&f, client_args);
49   return f;
50 }
51 
n_seconds_from_now(int n)52 static gpr_timespec n_seconds_from_now(int n) {
53   return grpc_timeout_seconds_to_deadline(n);
54 }
55 
five_seconds_from_now(void)56 static gpr_timespec five_seconds_from_now(void) {
57   return n_seconds_from_now(5);
58 }
59 
drain_cq(grpc_completion_queue * cq)60 static void drain_cq(grpc_completion_queue* cq) {
61   grpc_event ev;
62   do {
63     ev = grpc_completion_queue_next(cq, five_seconds_from_now(), nullptr);
64   } while (ev.type != GRPC_QUEUE_SHUTDOWN);
65 }
66 
shutdown_server(grpc_end2end_test_fixture * f)67 static void shutdown_server(grpc_end2end_test_fixture* f) {
68   if (!f->server) return;
69   grpc_server_shutdown_and_notify(f->server, f->shutdown_cq, tag(1000));
70   GPR_ASSERT(grpc_completion_queue_pluck(f->shutdown_cq, tag(1000),
71                                          grpc_timeout_seconds_to_deadline(5),
72                                          nullptr)
73                  .type == GRPC_OP_COMPLETE);
74   grpc_server_destroy(f->server);
75   f->server = nullptr;
76 }
77 
shutdown_client(grpc_end2end_test_fixture * f)78 static void shutdown_client(grpc_end2end_test_fixture* f) {
79   if (!f->client) return;
80   grpc_channel_destroy(f->client);
81   f->client = nullptr;
82 }
83 
end_test(grpc_end2end_test_fixture * f)84 static void end_test(grpc_end2end_test_fixture* f) {
85   shutdown_server(f);
86   shutdown_client(f);
87 
88   grpc_completion_queue_shutdown(f->cq);
89   drain_cq(f->cq);
90   grpc_completion_queue_destroy(f->cq);
91   grpc_completion_queue_destroy(f->shutdown_cq);
92 }
93 
request_for_disabled_algorithm(grpc_end2end_test_config config,const char * test_name,uint32_t send_flags_bitmask,grpc_compression_algorithm algorithm_to_disable,grpc_compression_algorithm requested_client_compression_algorithm,grpc_status_code expected_error,grpc_metadata * client_metadata)94 static void request_for_disabled_algorithm(
95     grpc_end2end_test_config config, const char* test_name,
96     uint32_t send_flags_bitmask,
97     grpc_compression_algorithm algorithm_to_disable,
98     grpc_compression_algorithm requested_client_compression_algorithm,
99     grpc_status_code expected_error, grpc_metadata* client_metadata) {
100   grpc_call* c;
101   grpc_call* s;
102   grpc_slice request_payload_slice;
103   grpc_byte_buffer* request_payload;
104   grpc_channel_args* client_args;
105   grpc_channel_args* server_args;
106   grpc_end2end_test_fixture f;
107   grpc_op ops[6];
108   grpc_op* op;
109   grpc_metadata_array initial_metadata_recv;
110   grpc_metadata_array trailing_metadata_recv;
111   grpc_metadata_array request_metadata_recv;
112   grpc_byte_buffer* request_payload_recv = nullptr;
113   grpc_call_details call_details;
114   grpc_status_code status;
115   grpc_call_error error;
116   grpc_slice details;
117   int was_cancelled = 2;
118   cq_verifier* cqv;
119   char str[1024];
120 
121   memset(str, 'x', 1023);
122   str[1023] = '\0';
123   request_payload_slice = grpc_slice_from_copied_string(str);
124   request_payload = grpc_raw_byte_buffer_create(&request_payload_slice, 1);
125 
126   client_args = grpc_channel_args_set_compression_algorithm(
127       nullptr, requested_client_compression_algorithm);
128   server_args =
129       grpc_channel_args_set_compression_algorithm(nullptr, GRPC_COMPRESS_NONE);
130   {
131     grpc_core::ExecCtx exec_ctx;
132     server_args = grpc_channel_args_compression_algorithm_set_state(
133         &server_args, algorithm_to_disable, false);
134   }
135 
136   f = begin_test(config, test_name, client_args, server_args);
137   cqv = cq_verifier_create(f.cq);
138 
139   gpr_timespec deadline = five_seconds_from_now();
140   c = grpc_channel_create_call(f.client, nullptr, GRPC_PROPAGATE_DEFAULTS, f.cq,
141                                grpc_slice_from_static_string("/foo"), nullptr,
142                                deadline, nullptr);
143   GPR_ASSERT(c);
144 
145   grpc_metadata_array_init(&initial_metadata_recv);
146   grpc_metadata_array_init(&trailing_metadata_recv);
147   grpc_metadata_array_init(&request_metadata_recv);
148   grpc_call_details_init(&call_details);
149 
150   error =
151       grpc_server_request_call(f.server, &s, &call_details,
152                                &request_metadata_recv, f.cq, f.cq, tag(101));
153   GPR_ASSERT(GRPC_CALL_OK == error);
154 
155   memset(ops, 0, sizeof(ops));
156   op = ops;
157   op->op = GRPC_OP_SEND_INITIAL_METADATA;
158   if (client_metadata != nullptr) {
159     op->data.send_initial_metadata.count = 1;
160     op->data.send_initial_metadata.metadata = client_metadata;
161   } else {
162     op->data.send_initial_metadata.count = 0;
163   }
164   op->flags = 0;
165   op->reserved = nullptr;
166   op++;
167   op->op = GRPC_OP_SEND_MESSAGE;
168   op->data.send_message.send_message = request_payload;
169   op->flags = send_flags_bitmask;
170   op->reserved = nullptr;
171   op++;
172   op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT;
173   op->flags = 0;
174   op->reserved = nullptr;
175   op++;
176   op->op = GRPC_OP_RECV_INITIAL_METADATA;
177   op->data.recv_initial_metadata.recv_initial_metadata = &initial_metadata_recv;
178   op->flags = 0;
179   op->reserved = nullptr;
180   op++;
181   op->op = GRPC_OP_RECV_STATUS_ON_CLIENT;
182   op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv;
183   op->data.recv_status_on_client.status = &status;
184   op->data.recv_status_on_client.status_details = &details;
185   op->flags = 0;
186   op->reserved = nullptr;
187   op++;
188   error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops), tag(1),
189                                 nullptr);
190   GPR_ASSERT(GRPC_CALL_OK == error);
191 
192   CQ_EXPECT_COMPLETION(cqv, tag(101), true);
193   CQ_EXPECT_COMPLETION(cqv, tag(1), true);
194   cq_verify(cqv);
195 
196   op = ops;
197   op->op = GRPC_OP_SEND_INITIAL_METADATA;
198   op->data.send_initial_metadata.count = 0;
199   op->flags = 0;
200   op->reserved = nullptr;
201   op++;
202   op->op = GRPC_OP_RECV_MESSAGE;
203   op->data.recv_message.recv_message = &request_payload_recv;
204   op->flags = 0;
205   op->reserved = nullptr;
206   op++;
207   error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops), tag(102),
208                                 nullptr);
209   GPR_ASSERT(GRPC_CALL_OK == error);
210 
211   CQ_EXPECT_COMPLETION(cqv, tag(102), false);
212 
213   op = ops;
214   op->op = GRPC_OP_RECV_CLOSE_ON_SERVER;
215   op->data.recv_close_on_server.cancelled = &was_cancelled;
216   op->flags = 0;
217   op->reserved = nullptr;
218   op++;
219   error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops), tag(103),
220                                 nullptr);
221   GPR_ASSERT(GRPC_CALL_OK == error);
222 
223   CQ_EXPECT_COMPLETION(cqv, tag(103), true);
224   cq_verify(cqv);
225 
226   /* call was cancelled (closed) ... */
227   GPR_ASSERT(was_cancelled != 0);
228   /* with a certain error */
229   GPR_ASSERT(status == expected_error);
230 
231   const char* algo_name = nullptr;
232   GPR_ASSERT(grpc_compression_algorithm_name(algorithm_to_disable, &algo_name));
233   char* expected_details = nullptr;
234   gpr_asprintf(&expected_details, "Compression algorithm '%s' is disabled.",
235                algo_name);
236   /* and we expect a specific reason for it */
237   GPR_ASSERT(0 == grpc_slice_str_cmp(details, expected_details));
238   gpr_free(expected_details);
239   GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo"));
240 
241   grpc_slice_unref(details);
242   grpc_metadata_array_destroy(&initial_metadata_recv);
243   grpc_metadata_array_destroy(&trailing_metadata_recv);
244   grpc_metadata_array_destroy(&request_metadata_recv);
245   grpc_call_details_destroy(&call_details);
246 
247   grpc_call_unref(c);
248   grpc_call_unref(s);
249 
250   cq_verifier_destroy(cqv);
251 
252   grpc_slice_unref(request_payload_slice);
253   grpc_byte_buffer_destroy(request_payload);
254   grpc_byte_buffer_destroy(request_payload_recv);
255 
256   {
257     grpc_core::ExecCtx exec_ctx;
258     grpc_channel_args_destroy(client_args);
259     grpc_channel_args_destroy(server_args);
260   }
261 
262   end_test(&f);
263   config.tear_down_data(&f);
264 }
265 
request_with_payload_template(grpc_end2end_test_config config,const char * test_name,uint32_t client_send_flags_bitmask,grpc_compression_algorithm default_client_channel_compression_algorithm,grpc_compression_algorithm default_server_channel_compression_algorithm,grpc_compression_algorithm expected_algorithm_from_client,grpc_compression_algorithm expected_algorithm_from_server,grpc_metadata * client_init_metadata,bool set_server_level,grpc_compression_level server_compression_level,bool send_message_before_initial_metadata)266 static void request_with_payload_template(
267     grpc_end2end_test_config config, const char* test_name,
268     uint32_t client_send_flags_bitmask,
269     grpc_compression_algorithm default_client_channel_compression_algorithm,
270     grpc_compression_algorithm default_server_channel_compression_algorithm,
271     grpc_compression_algorithm expected_algorithm_from_client,
272     grpc_compression_algorithm expected_algorithm_from_server,
273     grpc_metadata* client_init_metadata, bool set_server_level,
274     grpc_compression_level server_compression_level,
275     bool send_message_before_initial_metadata) {
276   grpc_call* c;
277   grpc_call* s;
278   grpc_slice request_payload_slice;
279   grpc_byte_buffer* request_payload = nullptr;
280   grpc_channel_args* client_args;
281   grpc_channel_args* server_args;
282   grpc_end2end_test_fixture f;
283   grpc_op ops[6];
284   grpc_op* op;
285   grpc_metadata_array initial_metadata_recv;
286   grpc_metadata_array trailing_metadata_recv;
287   grpc_metadata_array request_metadata_recv;
288   grpc_byte_buffer* request_payload_recv = nullptr;
289   grpc_byte_buffer* response_payload;
290   grpc_byte_buffer* response_payload_recv;
291   grpc_call_details call_details;
292   grpc_status_code status;
293   grpc_call_error error;
294   grpc_slice details;
295   int was_cancelled = 2;
296   cq_verifier* cqv;
297   char request_str[1024];
298   char response_str[1024];
299 
300   memset(request_str, 'x', 1023);
301   request_str[1023] = '\0';
302 
303   memset(response_str, 'y', 1023);
304   response_str[1023] = '\0';
305 
306   request_payload_slice = grpc_slice_from_copied_string(request_str);
307   grpc_slice response_payload_slice =
308       grpc_slice_from_copied_string(response_str);
309 
310   client_args = grpc_channel_args_set_compression_algorithm(
311       nullptr, default_client_channel_compression_algorithm);
312   server_args = grpc_channel_args_set_compression_algorithm(
313       nullptr, default_server_channel_compression_algorithm);
314 
315   f = begin_test(config, test_name, client_args, server_args);
316   cqv = cq_verifier_create(f.cq);
317 
318   gpr_timespec deadline = five_seconds_from_now();
319   c = grpc_channel_create_call(f.client, nullptr, GRPC_PROPAGATE_DEFAULTS, f.cq,
320                                grpc_slice_from_static_string("/foo"), nullptr,
321                                deadline, nullptr);
322   GPR_ASSERT(c);
323 
324   grpc_metadata_array_init(&initial_metadata_recv);
325   grpc_metadata_array_init(&trailing_metadata_recv);
326   grpc_metadata_array_init(&request_metadata_recv);
327   grpc_call_details_init(&call_details);
328 
329   if (send_message_before_initial_metadata) {
330     request_payload = grpc_raw_byte_buffer_create(&request_payload_slice, 1);
331     memset(ops, 0, sizeof(ops));
332     op = ops;
333     op->op = GRPC_OP_SEND_MESSAGE;
334     op->data.send_message.send_message = request_payload;
335     op->flags = client_send_flags_bitmask;
336     op->reserved = nullptr;
337     op++;
338     error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops), tag(2),
339                                   nullptr);
340     GPR_ASSERT(GRPC_CALL_OK == error);
341     CQ_EXPECT_COMPLETION(cqv, tag(2), true);
342   }
343 
344   memset(ops, 0, sizeof(ops));
345   op = ops;
346   op->op = GRPC_OP_SEND_INITIAL_METADATA;
347   if (client_init_metadata != nullptr) {
348     op->data.send_initial_metadata.count = 1;
349     op->data.send_initial_metadata.metadata = client_init_metadata;
350   } else {
351     op->data.send_initial_metadata.count = 0;
352   }
353   op->flags = 0;
354   op->reserved = nullptr;
355   op++;
356   op->op = GRPC_OP_RECV_INITIAL_METADATA;
357   op->data.recv_initial_metadata.recv_initial_metadata = &initial_metadata_recv;
358   op->flags = 0;
359   op->reserved = nullptr;
360   op++;
361   op->op = GRPC_OP_RECV_STATUS_ON_CLIENT;
362   op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv;
363   op->data.recv_status_on_client.status = &status;
364   op->data.recv_status_on_client.status_details = &details;
365   op->flags = 0;
366   op->reserved = nullptr;
367   op++;
368   error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops), tag(1),
369                                 nullptr);
370   GPR_ASSERT(GRPC_CALL_OK == error);
371 
372   error =
373       grpc_server_request_call(f.server, &s, &call_details,
374                                &request_metadata_recv, f.cq, f.cq, tag(100));
375   GPR_ASSERT(GRPC_CALL_OK == error);
376   CQ_EXPECT_COMPLETION(cqv, tag(100), true);
377   cq_verify(cqv);
378 
379   GPR_ASSERT(GPR_BITCOUNT(grpc_call_test_only_get_encodings_accepted_by_peer(
380                  s)) == GRPC_COMPRESS_ALGORITHMS_COUNT);
381   GPR_ASSERT(GPR_BITGET(grpc_call_test_only_get_encodings_accepted_by_peer(s),
382                         GRPC_COMPRESS_NONE) != 0);
383   GPR_ASSERT(GPR_BITGET(grpc_call_test_only_get_encodings_accepted_by_peer(s),
384                         GRPC_COMPRESS_DEFLATE) != 0);
385   GPR_ASSERT(GPR_BITGET(grpc_call_test_only_get_encodings_accepted_by_peer(s),
386                         GRPC_COMPRESS_GZIP) != 0);
387 
388   memset(ops, 0, sizeof(ops));
389   op = ops;
390   op->op = GRPC_OP_SEND_INITIAL_METADATA;
391   op->data.send_initial_metadata.count = 0;
392   if (set_server_level) {
393     op->data.send_initial_metadata.maybe_compression_level.is_set = true;
394     op->data.send_initial_metadata.maybe_compression_level.level =
395         server_compression_level;
396   }
397   op->flags = 0;
398   op->reserved = nullptr;
399   op++;
400   op->op = GRPC_OP_RECV_CLOSE_ON_SERVER;
401   op->data.recv_close_on_server.cancelled = &was_cancelled;
402   op->flags = 0;
403   op->reserved = nullptr;
404   op++;
405   error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops), tag(101),
406                                 nullptr);
407   GPR_ASSERT(GRPC_CALL_OK == error);
408 
409   for (int i = 0; i < 2; i++) {
410     response_payload = grpc_raw_byte_buffer_create(&response_payload_slice, 1);
411 
412     if (i > 0 || !send_message_before_initial_metadata) {
413       request_payload = grpc_raw_byte_buffer_create(&request_payload_slice, 1);
414       memset(ops, 0, sizeof(ops));
415       op = ops;
416       op->op = GRPC_OP_SEND_MESSAGE;
417       op->data.send_message.send_message = request_payload;
418       op->flags = client_send_flags_bitmask;
419       op->reserved = nullptr;
420       op++;
421       error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops),
422                                     tag(2), nullptr);
423       GPR_ASSERT(GRPC_CALL_OK == error);
424       CQ_EXPECT_COMPLETION(cqv, tag(2), 1);
425     }
426 
427     memset(ops, 0, sizeof(ops));
428     op = ops;
429     op->op = GRPC_OP_RECV_MESSAGE;
430     op->data.recv_message.recv_message = &request_payload_recv;
431     op->flags = 0;
432     op->reserved = nullptr;
433     op++;
434     error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops),
435                                   tag(102), nullptr);
436     GPR_ASSERT(GRPC_CALL_OK == error);
437 
438     CQ_EXPECT_COMPLETION(cqv, tag(102), 1);
439     cq_verify(cqv);
440 
441     GPR_ASSERT(request_payload_recv->type == GRPC_BB_RAW);
442     GPR_ASSERT(byte_buffer_eq_string(request_payload_recv, request_str));
443     GPR_ASSERT(request_payload_recv->data.raw.compression ==
444                expected_algorithm_from_client);
445 
446     memset(ops, 0, sizeof(ops));
447     op = ops;
448     op->op = GRPC_OP_SEND_MESSAGE;
449     op->data.send_message.send_message = response_payload;
450     op->flags = 0;
451     op->reserved = nullptr;
452     op++;
453     error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops),
454                                   tag(103), nullptr);
455     GPR_ASSERT(GRPC_CALL_OK == error);
456 
457     memset(ops, 0, sizeof(ops));
458     op = ops;
459     op->op = GRPC_OP_RECV_MESSAGE;
460     op->data.recv_message.recv_message = &response_payload_recv;
461     op->flags = 0;
462     op->reserved = nullptr;
463     op++;
464     error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops), tag(3),
465                                   nullptr);
466     GPR_ASSERT(GRPC_CALL_OK == error);
467 
468     CQ_EXPECT_COMPLETION(cqv, tag(103), 1);
469     CQ_EXPECT_COMPLETION(cqv, tag(3), 1);
470     cq_verify(cqv);
471 
472     GPR_ASSERT(response_payload_recv->type == GRPC_BB_RAW);
473     GPR_ASSERT(byte_buffer_eq_string(response_payload_recv, response_str));
474     if (server_compression_level > GRPC_COMPRESS_LEVEL_NONE) {
475       const grpc_compression_algorithm algo_for_server_level =
476           grpc_call_compression_for_level(s, server_compression_level);
477       GPR_ASSERT(response_payload_recv->data.raw.compression ==
478                  algo_for_server_level);
479     } else {
480       GPR_ASSERT(response_payload_recv->data.raw.compression ==
481                  expected_algorithm_from_server);
482     }
483 
484     grpc_byte_buffer_destroy(request_payload);
485     grpc_byte_buffer_destroy(response_payload);
486     grpc_byte_buffer_destroy(request_payload_recv);
487     grpc_byte_buffer_destroy(response_payload_recv);
488   }
489 
490   grpc_slice_unref(request_payload_slice);
491   grpc_slice_unref(response_payload_slice);
492 
493   memset(ops, 0, sizeof(ops));
494   op = ops;
495   op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT;
496   op->flags = 0;
497   op->reserved = nullptr;
498   op++;
499   error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops), tag(4),
500                                 nullptr);
501   GPR_ASSERT(GRPC_CALL_OK == error);
502 
503   memset(ops, 0, sizeof(ops));
504   op = ops;
505   op->op = GRPC_OP_SEND_STATUS_FROM_SERVER;
506   op->data.send_status_from_server.trailing_metadata_count = 0;
507   op->data.send_status_from_server.status = GRPC_STATUS_OK;
508   grpc_slice status_details = grpc_slice_from_static_string("xyz");
509   op->data.send_status_from_server.status_details = &status_details;
510   op->flags = 0;
511   op->reserved = nullptr;
512   op++;
513   error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops), tag(104),
514                                 nullptr);
515   GPR_ASSERT(GRPC_CALL_OK == error);
516 
517   CQ_EXPECT_COMPLETION(cqv, tag(1), 1);
518   CQ_EXPECT_COMPLETION(cqv, tag(4), 1);
519   CQ_EXPECT_COMPLETION(cqv, tag(101), 1);
520   CQ_EXPECT_COMPLETION(cqv, tag(104), 1);
521   cq_verify(cqv);
522 
523   GPR_ASSERT(status == GRPC_STATUS_OK);
524   GPR_ASSERT(0 == grpc_slice_str_cmp(details, "xyz"));
525   GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo"));
526   GPR_ASSERT(was_cancelled == 0);
527 
528   grpc_slice_unref(details);
529   grpc_metadata_array_destroy(&initial_metadata_recv);
530   grpc_metadata_array_destroy(&trailing_metadata_recv);
531   grpc_metadata_array_destroy(&request_metadata_recv);
532   grpc_call_details_destroy(&call_details);
533 
534   grpc_call_unref(c);
535   grpc_call_unref(s);
536 
537   cq_verifier_destroy(cqv);
538 
539   {
540     grpc_core::ExecCtx exec_ctx;
541     grpc_channel_args_destroy(client_args);
542     grpc_channel_args_destroy(server_args);
543   }
544 
545   end_test(&f);
546   config.tear_down_data(&f);
547 }
548 
test_invoke_request_with_exceptionally_uncompressed_payload(grpc_end2end_test_config config)549 static void test_invoke_request_with_exceptionally_uncompressed_payload(
550     grpc_end2end_test_config config) {
551   request_with_payload_template(
552       config, "test_invoke_request_with_exceptionally_uncompressed_payload",
553       GRPC_WRITE_NO_COMPRESS, GRPC_COMPRESS_GZIP, GRPC_COMPRESS_GZIP,
554       GRPC_COMPRESS_NONE, GRPC_COMPRESS_GZIP, nullptr, false,
555       /* ignored */ GRPC_COMPRESS_LEVEL_NONE, false);
556 }
557 
test_invoke_request_with_uncompressed_payload(grpc_end2end_test_config config)558 static void test_invoke_request_with_uncompressed_payload(
559     grpc_end2end_test_config config) {
560   request_with_payload_template(
561       config, "test_invoke_request_with_uncompressed_payload", 0,
562       GRPC_COMPRESS_NONE, GRPC_COMPRESS_NONE, GRPC_COMPRESS_NONE,
563       GRPC_COMPRESS_NONE, nullptr, false,
564       /* ignored */ GRPC_COMPRESS_LEVEL_NONE, false);
565 }
566 
test_invoke_request_with_compressed_payload(grpc_end2end_test_config config)567 static void test_invoke_request_with_compressed_payload(
568     grpc_end2end_test_config config) {
569   request_with_payload_template(
570       config, "test_invoke_request_with_compressed_payload", 0,
571       GRPC_COMPRESS_GZIP, GRPC_COMPRESS_GZIP, GRPC_COMPRESS_GZIP,
572       GRPC_COMPRESS_GZIP, nullptr, false,
573       /* ignored */ GRPC_COMPRESS_LEVEL_NONE, false);
574 }
575 
test_invoke_request_with_send_message_before_initial_metadata(grpc_end2end_test_config config)576 static void test_invoke_request_with_send_message_before_initial_metadata(
577     grpc_end2end_test_config config) {
578   request_with_payload_template(
579       config, "test_invoke_request_with_compressed_payload", 0,
580       GRPC_COMPRESS_GZIP, GRPC_COMPRESS_GZIP, GRPC_COMPRESS_GZIP,
581       GRPC_COMPRESS_GZIP, nullptr, false,
582       /* ignored */ GRPC_COMPRESS_LEVEL_NONE, true);
583 }
584 
test_invoke_request_with_server_level(grpc_end2end_test_config config)585 static void test_invoke_request_with_server_level(
586     grpc_end2end_test_config config) {
587   request_with_payload_template(
588       config, "test_invoke_request_with_server_level", 0, GRPC_COMPRESS_NONE,
589       GRPC_COMPRESS_NONE, GRPC_COMPRESS_NONE, GRPC_COMPRESS_NONE /* ignored */,
590       nullptr, true, GRPC_COMPRESS_LEVEL_HIGH, false);
591 }
592 
test_invoke_request_with_compressed_payload_md_override(grpc_end2end_test_config config)593 static void test_invoke_request_with_compressed_payload_md_override(
594     grpc_end2end_test_config config) {
595   grpc_metadata gzip_compression_override;
596   grpc_metadata identity_compression_override;
597 
598   gzip_compression_override.key = GRPC_MDSTR_GRPC_INTERNAL_ENCODING_REQUEST;
599   gzip_compression_override.value = grpc_slice_from_static_string("gzip");
600   memset(&gzip_compression_override.internal_data, 0,
601          sizeof(gzip_compression_override.internal_data));
602 
603   identity_compression_override.key = GRPC_MDSTR_GRPC_INTERNAL_ENCODING_REQUEST;
604   identity_compression_override.value =
605       grpc_slice_from_static_string("identity");
606   memset(&identity_compression_override.internal_data, 0,
607          sizeof(identity_compression_override.internal_data));
608 
609   /* Channel default NONE (aka IDENTITY), call override to GZIP */
610   request_with_payload_template(
611       config, "test_invoke_request_with_compressed_payload_md_override_1", 0,
612       GRPC_COMPRESS_NONE, GRPC_COMPRESS_NONE, GRPC_COMPRESS_GZIP,
613       GRPC_COMPRESS_NONE, &gzip_compression_override, false,
614       /*ignored*/ GRPC_COMPRESS_LEVEL_NONE, false);
615 
616   /* Channel default DEFLATE, call override to GZIP */
617   request_with_payload_template(
618       config, "test_invoke_request_with_compressed_payload_md_override_2", 0,
619       GRPC_COMPRESS_DEFLATE, GRPC_COMPRESS_NONE, GRPC_COMPRESS_GZIP,
620       GRPC_COMPRESS_NONE, &gzip_compression_override, false,
621       /*ignored*/ GRPC_COMPRESS_LEVEL_NONE, false);
622 
623   /* Channel default DEFLATE, call override to NONE (aka IDENTITY) */
624   request_with_payload_template(
625       config, "test_invoke_request_with_compressed_payload_md_override_3", 0,
626       GRPC_COMPRESS_DEFLATE, GRPC_COMPRESS_NONE, GRPC_COMPRESS_NONE,
627       GRPC_COMPRESS_NONE, &identity_compression_override, false,
628       /*ignored*/ GRPC_COMPRESS_LEVEL_NONE, false);
629 }
630 
test_invoke_request_with_disabled_algorithm(grpc_end2end_test_config config)631 static void test_invoke_request_with_disabled_algorithm(
632     grpc_end2end_test_config config) {
633   request_for_disabled_algorithm(config,
634                                  "test_invoke_request_with_disabled_algorithm",
635                                  0, GRPC_COMPRESS_GZIP, GRPC_COMPRESS_GZIP,
636                                  GRPC_STATUS_UNIMPLEMENTED, nullptr);
637 }
638 
compressed_payload(grpc_end2end_test_config config)639 void compressed_payload(grpc_end2end_test_config config) {
640   test_invoke_request_with_exceptionally_uncompressed_payload(config);
641   test_invoke_request_with_uncompressed_payload(config);
642   test_invoke_request_with_compressed_payload(config);
643   test_invoke_request_with_send_message_before_initial_metadata(config);
644   test_invoke_request_with_server_level(config);
645   test_invoke_request_with_compressed_payload_md_override(config);
646   test_invoke_request_with_disabled_algorithm(config);
647 }
648 
compressed_payload_pre_init(void)649 void compressed_payload_pre_init(void) {}
650