xref: /aosp_15_r20/external/grpc-grpc/test/core/bad_client/bad_client.h (revision cc02d7e222339f7a4f6ba5f422e6413f4bd931f2)
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 <stddef.h>
23 #include <stdint.h>
24 
25 #include <grpc/grpc.h>
26 #include <grpc/slice.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 #define GRPC_BAD_CLIENT_MAX_CONCURRENT_REQUESTS_OF_ONE 4
51 
52 // Test runner.
53 //
54 // Create a server, and for each arg in \a args send client_payload. For each
55 // payload, run client_validator to make sure that the response is as expected.
56 // Also execute \a server_validator in a separate thread to assert that the
57 // bytes are handled as expected.
58 //
59 // The flags are only applicable to the last validator in the array. (This can
60 // be changed in the future if necessary)
61 //
62 void grpc_run_bad_client_test(
63     grpc_bad_client_server_side_validator server_validator,
64     grpc_bad_client_arg args[], int num_args, uint32_t flags);
65 
66 // A hack to let old tests work as before. In these tests, instead of an array,
67 // the tests provide a single client_validator and payload
68 //
69 #define COMBINE1(X, Y) X##Y
70 #define COMBINE(X, Y) COMBINE1(X, Y)
71 
72 #define GRPC_RUN_BAD_CLIENT_TEST(server_validator, client_validator, payload,  \
73                                  flags)                                        \
74   grpc_bad_client_arg COMBINE(bca, __LINE__) = {client_validator, nullptr,     \
75                                                 payload, sizeof(payload) - 1}; \
76   grpc_run_bad_client_test(server_validator, &COMBINE(bca, __LINE__), 1, flags)
77 
78 // Helper validator functions
79 // Client side validator for connection preface from server. \a arg is unused
80 bool client_connection_preface_validator(grpc_slice_buffer* incoming,
81                                          void* arg);
82 
83 // Client side validator for checking if reset stream is present at the end
84 // of the buffer. \a arg is unused.
85 //
86 bool rst_stream_client_validator(grpc_slice_buffer* incoming, void* arg);
87 
88 // Helper grpc_bad_client_arg arguments for direct use
89 // Sends a connection preface from the client with an empty settings frame
90 extern grpc_bad_client_arg connection_preface_arg;
91 
92 // Server side verifier function that performs a
93 //  single grpc_server_request_call
94 void server_verifier_request_call(grpc_server* server,
95                                   grpc_completion_queue* cq,
96                                   void* registered_method);
97 #endif  // GRPC_TEST_CORE_BAD_CLIENT_BAD_CLIENT_H
98