Home | History | Annotate | Download | only in bad_client
      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 #ifndef GRPC_TEST_CORE_BAD_CLIENT_BAD_CLIENT_H
     20 #define GRPC_TEST_CORE_BAD_CLIENT_BAD_CLIENT_H
     21 
     22 #include <grpc/grpc.h>
     23 
     24 #include <stdbool.h>
     25 
     26 #include "test/core/util/test_config.h"
     27 
     28 #define GRPC_BAD_CLIENT_REGISTERED_METHOD "/registered/bar"
     29 #define GRPC_BAD_CLIENT_REGISTERED_HOST "localhost"
     30 
     31 /* The server side validator function to run */
     32 typedef void (*grpc_bad_client_server_side_validator)(grpc_server* server,
     33                                                       grpc_completion_queue* cq,
     34                                                       void* registered_method);
     35 
     36 /* Returns false if we need to read more data. */
     37 typedef bool (*grpc_bad_client_client_stream_validator)(
     38     grpc_slice_buffer* incoming, void* arg);
     39 
     40 struct grpc_bad_client_arg {
     41   grpc_bad_client_client_stream_validator client_validator;
     42   void* client_validator_arg;
     43   const char* client_payload;
     44   size_t client_payload_length;
     45 };
     46 
     47 /* Flags for grpc_run_bad_client_test */
     48 #define GRPC_BAD_CLIENT_DISCONNECT 1
     49 #define GRPC_BAD_CLIENT_LARGE_REQUEST 2
     50 
     51 /* Test runner.
     52  *
     53  * Create a server, and for each arg in \a args send client_payload. For each
     54  * payload, run client_validator to make sure that the response is as expected.
     55  * Also execute \a server_validator in a separate thread to assert that the
     56  * bytes are handled as expected.
     57  *
     58  * The flags are only applicable to the last validator in the array. (This can
     59  * be changed in the future if necessary)
     60  */
     61 void grpc_run_bad_client_test(
     62     grpc_bad_client_server_side_validator server_validator,
     63     grpc_bad_client_arg args[], int num_args, uint32_t flags);
     64 
     65 /* A hack to let old tests work as before. In these tests, instead of an array,
     66  * the tests provide a single client_validator and payload
     67  */
     68 #define COMBINE1(X, Y) X##Y
     69 #define COMBINE(X, Y) COMBINE1(X, Y)
     70 
     71 #define GRPC_RUN_BAD_CLIENT_TEST(server_validator, client_validator, payload,  \
     72                                  flags)                                        \
     73   grpc_bad_client_arg COMBINE(bca, __LINE__) = {client_validator, nullptr,     \
     74                                                 payload, sizeof(payload) - 1}; \
     75   grpc_run_bad_client_test(server_validator, &COMBINE(bca, __LINE__), 1, flags)
     76 
     77 /* Helper validator functions */
     78 /* Client side validator for connection preface from server. \a arg is unused */
     79 bool client_connection_preface_validator(grpc_slice_buffer* incoming,
     80                                          void* arg);
     81 
     82 /* Client side validator for checking if reset stream is present at the end
     83  * of the buffer. \a arg is unused.
     84  */
     85 bool rst_stream_client_validator(grpc_slice_buffer* incoming, void* arg);
     86 
     87 /* Helper grpc_bad_client_arg arguments for direct use */
     88 /* Sends a connection preface from the client with an empty settings frame */
     89 extern grpc_bad_client_arg connection_preface_arg;
     90 
     91 /* Server side verifier function that performs a
     92  *  single grpc_server_request_call */
     93 void server_verifier_request_call(grpc_server* server,
     94                                   grpc_completion_queue* cq,
     95                                   void* registered_method);
     96 #endif /* GRPC_TEST_CORE_BAD_CLIENT_BAD_CLIENT_H */
     97