test_config.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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_UTIL_TEST_CONFIG_H
  19. #define GRPC_TEST_CORE_UTIL_TEST_CONFIG_H
  20. #include <grpc/support/time.h>
  21. #include "test/core/util/build.h"
  22. extern int64_t g_fixture_slowdown_factor;
  23. extern int64_t g_poller_slowdown_factor;
  24. /* Returns an appropriate scaling factor for timeouts. */
  25. int64_t grpc_test_slowdown_factor();
  26. /* Converts a given timeout (in seconds) to a deadline. */
  27. gpr_timespec grpc_timeout_seconds_to_deadline(int64_t time_s);
  28. /* Converts a given timeout (in milliseconds) to a deadline. */
  29. gpr_timespec grpc_timeout_milliseconds_to_deadline(int64_t time_ms);
  30. #if !defined(GRPC_TEST_CUSTOM_PICK_PORT) && !defined(GRPC_PORT_ISOLATED_RUNTIME)
  31. #define GRPC_TEST_PICK_PORT
  32. #endif
  33. // Prefer TestEnvironment below.
  34. void grpc_test_init(int argc, char** argv);
  35. // Wait until gRPC is fully shut down.
  36. // Returns if grpc is shutdown
  37. bool grpc_wait_until_shutdown(int64_t time_s);
  38. namespace grpc {
  39. namespace testing {
  40. // A TestEnvironment object should be alive in the main function of a test. It
  41. // provides test init and shutdown inside.
  42. class TestEnvironment {
  43. public:
  44. TestEnvironment(int argc, char** argv);
  45. ~TestEnvironment();
  46. };
  47. // A TestGrpcScope makes sure that
  48. // - when it's created, gRPC will be initialized
  49. // - when it's destroyed, gRPC will shutdown and it waits until shutdown
  50. class TestGrpcScope {
  51. public:
  52. TestGrpcScope();
  53. ~TestGrpcScope();
  54. };
  55. } // namespace testing
  56. } // namespace grpc
  57. #endif /* GRPC_TEST_CORE_UTIL_TEST_CONFIG_H */