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