aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/core/util
diff options
context:
space:
mode:
authorGravatar Robbie Shade <rjshade@google.com>2017-01-17 09:14:29 -0500
committerGravatar Robbie Shade <rjshade@google.com>2017-01-31 15:40:20 -0500
commitca7effcdff69baba8e52e4c83fe808491df60f36 (patch)
tree7e04f13f655f44c5930233381b615e1d54e5386e /test/core/util
parentc88834ba996084db5f530706a09892bdd900e7dc (diff)
Replace timeout/scaling macros with functions.
Diffstat (limited to 'test/core/util')
-rw-r--r--test/core/util/port_server_client.c10
-rw-r--r--test/core/util/test_config.c104
-rw-r--r--test/core/util/test_config.h31
3 files changed, 110 insertions, 35 deletions
diff --git a/test/core/util/port_server_client.c b/test/core/util/port_server_client.c
index 118708d419..6d722ffc88 100644
--- a/test/core/util/port_server_client.c
+++ b/test/core/util/port_server_client.c
@@ -103,7 +103,7 @@ void grpc_free_port_using_server(char *server, int port) {
grpc_resource_quota *resource_quota =
grpc_resource_quota_create("port_server_client/free");
grpc_httpcli_get(&exec_ctx, &context, &pr.pops, resource_quota, &req,
- GRPC_TIMEOUT_SECONDS_TO_DEADLINE(10),
+ grpc_timeout_seconds_to_deadline(10),
grpc_closure_create(freed_port_from_server, &pr,
grpc_schedule_on_exec_ctx),
&rsp);
@@ -115,7 +115,7 @@ void grpc_free_port_using_server(char *server, int port) {
"pollset_work",
grpc_pollset_work(&exec_ctx, grpc_polling_entity_pollset(&pr.pops),
&worker, gpr_now(GPR_CLOCK_MONOTONIC),
- GRPC_TIMEOUT_SECONDS_TO_DEADLINE(1)))) {
+ grpc_timeout_seconds_to_deadline(1)))) {
pr.done = 1;
}
}
@@ -176,7 +176,7 @@ static void got_port_from_server(grpc_exec_ctx *exec_ctx, void *arg,
grpc_resource_quota *resource_quota =
grpc_resource_quota_create("port_server_client/pick_retry");
grpc_httpcli_get(exec_ctx, pr->ctx, &pr->pops, resource_quota, &req,
- GRPC_TIMEOUT_SECONDS_TO_DEADLINE(10),
+ grpc_timeout_seconds_to_deadline(10),
grpc_closure_create(got_port_from_server, pr,
grpc_schedule_on_exec_ctx),
&pr->response);
@@ -226,7 +226,7 @@ int grpc_pick_port_using_server(char *server) {
grpc_resource_quota_create("port_server_client/pick");
grpc_httpcli_get(
&exec_ctx, &context, &pr.pops, resource_quota, &req,
- GRPC_TIMEOUT_SECONDS_TO_DEADLINE(10),
+ grpc_timeout_seconds_to_deadline(10),
grpc_closure_create(got_port_from_server, &pr, grpc_schedule_on_exec_ctx),
&pr.response);
grpc_resource_quota_unref_internal(&exec_ctx, resource_quota);
@@ -238,7 +238,7 @@ int grpc_pick_port_using_server(char *server) {
"pollset_work",
grpc_pollset_work(&exec_ctx, grpc_polling_entity_pollset(&pr.pops),
&worker, gpr_now(GPR_CLOCK_MONOTONIC),
- GRPC_TIMEOUT_SECONDS_TO_DEADLINE(1)))) {
+ grpc_timeout_seconds_to_deadline(1)))) {
pr.port = 0;
}
}
diff --git a/test/core/util/test_config.c b/test/core/util/test_config.c
index d86ed94637..94aab27253 100644
--- a/test/core/util/test_config.c
+++ b/test/core/util/test_config.c
@@ -45,8 +45,8 @@
#include "src/core/lib/support/env.h"
#include "src/core/lib/support/string.h"
-double g_fixture_slowdown_factor = 1.0;
-double g_poller_slowdown_factor = 1.0;
+int64_t g_fixture_slowdown_factor = 1;
+int64_t g_poller_slowdown_factor = 1;
#if GPR_GETPID_IN_UNISTD_H
#include <unistd.h>
@@ -278,19 +278,109 @@ static void install_crash_handler() {
static void install_crash_handler() {}
#endif
+bool BuiltUnderValgrind() {
+#ifdef RUNNING_ON_VALGRIND
+ return true;
+#else
+ return false;
+#endif
+}
+
+bool BuiltUnderTsan() {
+#if defined(__has_feature)
+#if __has_feature(thread_sanitizer)
+ return true;
+#else
+ return false;
+#endif
+#else
+#ifdef THREAD_SANITIZER
+ return true;
+#else
+ return false;
+#endif
+#endif
+}
+
+bool BuiltUnderAsan() {
+#if defined(__has_feature)
+#if __has_feature(address_sanitizer)
+ return true;
+#else
+ return false;
+#endif
+#else
+#ifdef ADDRESS_SANITIZER
+ return true;
+#else
+ return false;
+#endif
+#endif
+}
+
+bool BuiltUnderMsan() {
+#if defined(__has_feature)
+#if __has_feature(memory_sanitizer)
+ return true;
+#else
+ return false;
+#endif
+#else
+#ifdef MEMORY_SANITIZER
+ return true;
+#else
+ return false;
+#endif
+#endif
+}
+
+int64_t grpc_test_sanitizer_slowdown_factor() {
+ int64_t sanitizer_multiplier = 1;
+ if (BuiltUnderValgrind()) {
+ sanitizer_multiplier = 20;
+ } else if (BuiltUnderTsan()) {
+ sanitizer_multiplier = 5;
+ } else if (BuiltUnderAsan()) {
+ sanitizer_multiplier = 3;
+ } else if (BuiltUnderMsan()) {
+ sanitizer_multiplier = 4;
+ }
+ return sanitizer_multiplier;
+}
+
+int64_t grpc_test_slowdown_factor() {
+ return grpc_test_sanitizer_slowdown_factor() * g_fixture_slowdown_factor *
+ g_poller_slowdown_factor;
+}
+
+gpr_timespec grpc_timeout_seconds_to_deadline(int64_t time_s) {
+ return gpr_time_add(
+ gpr_now(GPR_CLOCK_MONOTONIC),
+ gpr_time_from_millis(grpc_test_slowdown_factor() * (int64_t)1e3 * time_s,
+ GPR_TIMESPAN));
+}
+
+gpr_timespec grpc_timeout_milliseconds_to_deadline(int64_t time_ms) {
+ return gpr_time_add(
+ gpr_now(GPR_CLOCK_MONOTONIC),
+ gpr_time_from_micros(grpc_test_slowdown_factor() * (int64_t)1e3 * time_ms,
+ GPR_TIMESPAN));
+}
+
void grpc_test_init(int argc, char **argv) {
install_crash_handler();
{ /* poll-cv poll strategy runs much more slowly than anything else */
char *s = gpr_getenv("GRPC_POLL_STRATEGY");
if (s != NULL && 0 == strcmp(s, "poll-cv")) {
- g_poller_slowdown_factor = 5.0;
+ g_poller_slowdown_factor = 5;
}
gpr_free(s);
}
- gpr_log(GPR_DEBUG, "test slowdown: machine=%f build=%f poll=%f total=%f",
- (double)GRPC_TEST_SLOWDOWN_MACHINE_FACTOR,
- (double)GRPC_TEST_SLOWDOWN_BUILD_FACTOR, g_poller_slowdown_factor,
- (double)GRPC_TEST_SLOWDOWN_FACTOR);
+ gpr_log(GPR_DEBUG,
+ "test slowdown factor: sanitizer=%" PRId64 ", fixture=%" PRId64
+ ", poller=%" PRId64 ", total=%" PRId64,
+ grpc_test_sanitizer_slowdown_factor(), g_fixture_slowdown_factor,
+ g_poller_slowdown_factor, grpc_test_slowdown_factor());
/* seed rng with pid, so we don't end up with the same random numbers as a
concurrently running test binary */
srand(seed());
diff --git a/test/core/util/test_config.h b/test/core/util/test_config.h
index c13fe86a64..491f011fc8 100644
--- a/test/core/util/test_config.h
+++ b/test/core/util/test_config.h
@@ -40,32 +40,17 @@
extern "C" {
#endif /* __cplusplus */
-#ifndef GRPC_TEST_SLOWDOWN_BUILD_FACTOR
-#define GRPC_TEST_SLOWDOWN_BUILD_FACTOR 1.0
-#endif
-
-#ifndef GRPC_TEST_SLOWDOWN_MACHINE_FACTOR
-#define GRPC_TEST_SLOWDOWN_MACHINE_FACTOR 1.0
-#endif
-
-extern double g_fixture_slowdown_factor;
-extern double g_poller_slowdown_factor;
+extern int64_t g_fixture_slowdown_factor;
+extern int64_t g_poller_slowdown_factor;
-#define GRPC_TEST_SLOWDOWN_FACTOR \
- (GRPC_TEST_SLOWDOWN_BUILD_FACTOR * GRPC_TEST_SLOWDOWN_MACHINE_FACTOR * \
- g_fixture_slowdown_factor * g_poller_slowdown_factor)
+/* Returns an appropriate scaling factor for timeouts. */
+int64_t grpc_test_slowdown_factor();
-#define GRPC_TIMEOUT_SECONDS_TO_DEADLINE(x) \
- gpr_time_add( \
- gpr_now(GPR_CLOCK_MONOTONIC), \
- gpr_time_from_millis((int64_t)(GRPC_TEST_SLOWDOWN_FACTOR * 1e3 * (x)), \
- GPR_TIMESPAN))
+/* Converts a given timeout (in seconds) to a deadline. */
+gpr_timespec grpc_timeout_seconds_to_deadline(int64_t time_s);
-#define GRPC_TIMEOUT_MILLIS_TO_DEADLINE(x) \
- gpr_time_add( \
- gpr_now(GPR_CLOCK_MONOTONIC), \
- gpr_time_from_micros((int64_t)(GRPC_TEST_SLOWDOWN_FACTOR * 1e3 * (x)), \
- GPR_TIMESPAN))
+/* Converts a given timeout (in milliseconds) to a deadline. */
+gpr_timespec grpc_timeout_milliseconds_to_deadline(int64_t time_ms);
#ifndef GRPC_TEST_CUSTOM_PICK_PORT
#define GRPC_TEST_PICK_PORT