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_END2END_END2END_TESTS_H
20 #define GRPC_TEST_CORE_END2END_END2END_TESTS_H
21 
22 #include <grpc/grpc.h>
23 
24 typedef struct grpc_end2end_test_fixture grpc_end2end_test_fixture;
25 typedef struct grpc_end2end_test_config grpc_end2end_test_config;
26 
27 /* Test feature flags. */
28 #define FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION 1
29 #define FEATURE_MASK_SUPPORTS_HOSTNAME_VERIFICATION 2
30 #define FEATURE_MASK_SUPPORTS_PER_CALL_CREDENTIALS 4
31 #define FEATURE_MASK_SUPPORTS_REQUEST_PROXYING 8
32 #define FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL 16
33 #define FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER 32
34 #define FEATURE_MASK_DOES_NOT_SUPPORT_RESOURCE_QUOTA_SERVER 64
35 #define FEATURE_MASK_DOES_NOT_SUPPORT_NETWORK_STATUS_CHANGE 128
36 #define FEATURE_MASK_SUPPORTS_WORKAROUNDS 256
37 
38 #define FAIL_AUTH_CHECK_SERVER_ARG_NAME "fail_auth_check"
39 
40 struct grpc_end2end_test_fixture {
41   grpc_completion_queue* cq;
42   grpc_completion_queue* shutdown_cq;
43   grpc_server* server;
44   grpc_channel* client;
45   void* fixture_data;
46 };
47 
48 struct grpc_end2end_test_config {
49   /* A descriptive name for this test fixture. */
50   const char* name;
51 
52   /* Which features are supported by this fixture. See feature flags above. */
53   uint32_t feature_mask;
54 
55   /* If the call host is setup by the fixture (for example, via the
56    * GRPC_SSL_TARGET_NAME_OVERRIDE_ARG channel arg), which value should the test
57    * expect to find in call_details.host */
58   const char* overridden_call_host;
59 
60   grpc_end2end_test_fixture (*create_fixture)(grpc_channel_args* client_args,
61                                               grpc_channel_args* server_args);
62   void (*init_client)(grpc_end2end_test_fixture* f,
63                       grpc_channel_args* client_args);
64   void (*init_server)(grpc_end2end_test_fixture* f,
65                       grpc_channel_args* server_args);
66   void (*tear_down_data)(grpc_end2end_test_fixture* f);
67 };
68 
69 void grpc_end2end_tests_pre_init(void);
70 void grpc_end2end_tests(int argc, char** argv, grpc_end2end_test_config config);
71 
72 const char* get_host_override_string(const char* str,
73                                      grpc_end2end_test_config config);
74 /* Returns a pointer to a statically allocated slice: future invocations
75    overwrite past invocations, not threadsafe, etc... */
76 const grpc_slice* get_host_override_slice(const char* str,
77                                           grpc_end2end_test_config config);
78 
79 void validate_host_override_string(const char* pattern, grpc_slice str,
80                                    grpc_end2end_test_config config);
81 
82 #endif /* GRPC_TEST_CORE_END2END_END2END_TESTS_H */
83