bad_client.h 3.7 KB

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