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_TEST_UTIL_TEST_CONFIG_H 20 #define GRPC_TEST_CORE_TEST_UTIL_TEST_CONFIG_H 21 22 #include <grpc/support/time.h> 23 #include <stdint.h> 24 25 extern int64_t g_fixture_slowdown_factor; 26 extern int64_t g_poller_slowdown_factor; 27 28 // Returns an appropriate scaling factor for timeouts. 29 int64_t grpc_test_slowdown_factor(); 30 31 // Converts a given timeout (in seconds) to a deadline. 32 gpr_timespec grpc_timeout_seconds_to_deadline(int64_t time_s); 33 34 // Converts a given timeout (in milliseconds) to a deadline. 35 gpr_timespec grpc_timeout_milliseconds_to_deadline(int64_t time_ms); 36 37 #if !defined(GRPC_TEST_CUSTOM_PICK_PORT) && !defined(GRPC_PORT_ISOLATED_RUNTIME) 38 #define GRPC_TEST_PICK_PORT 39 #endif 40 41 // Prefer TestEnvironment below. 42 void grpc_test_init(int* argc, char** argv); 43 44 // Disable all absl logs via SetMinLogLevel and SetVLogLevel 45 void grpc_disable_all_absl_logs(void); 46 47 // Wait until gRPC is fully shut down. 48 // Returns if grpc is shutdown 49 bool grpc_wait_until_shutdown(int64_t time_s); 50 51 // Sets absl verbosity via SetMinLogLevel and SetVLogLevel 52 void grpc_set_absl_verbosity_debug(void); 53 54 // Hacks to reduce the effect of OS on test results. 55 void grpc_prewarm_os_for_tests(void); 56 57 namespace grpc { 58 namespace testing { 59 60 // A TestEnvironment object should be alive in the main function of a test. It 61 // provides test init and shutdown inside. 62 class TestEnvironment { 63 public: 64 TestEnvironment(int* argc, char** argv); 65 ~TestEnvironment(); 66 }; 67 68 // A TestGrpcScope makes sure that 69 // - when it's created, gRPC will be initialized 70 // - when it's destroyed, gRPC will shutdown and it waits until shutdown 71 class TestGrpcScope { 72 public: 73 TestGrpcScope(); 74 ~TestGrpcScope(); 75 }; 76 77 } // namespace testing 78 } // namespace grpc 79 80 #endif // GRPC_TEST_CORE_TEST_UTIL_TEST_CONFIG_H 81