From 1995754bc3ab9777fe4773f1b583c09a1150e287 Mon Sep 17 00:00:00 2001 From: Leonid Yuriev Date: Tue, 13 Jul 2021 12:38:58 +0300 Subject: [PATCH] mdbx-test: add workarounds for QEMU (all 32-bit, Alpha, Sparc). --- GNUmakefile | 1 - test/main.cc | 52 +++++++++++++++++++++++++++++++++++++++++++++++++-- test/utils.cc | 2 +- 3 files changed, 51 insertions(+), 4 deletions(-) diff --git a/GNUmakefile b/GNUmakefile index 5cc2fd4a..35e560fe 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -618,7 +618,6 @@ cross-qemu: $(QUIET)for CC in $(CROSS_LIST); do \ echo "===================== $$CC + qemu"; \ $(MAKE) CXXSTD= clean && \ - MDBX_SMOKE_EXTRA="$(MDBX_SMOKE_EXTRA)$$(echo $$CC | grep -q -e alpha -e sparc && echo ' --size-upper=64M --size-lower=64M')" \ CC=$$CC CXX=$$(echo $$CC | sed 's/-gcc/-g++/') EXE_LDFLAGS=-static MDBX_BUILD_OPTIONS="-DMDBX_SAFE4QEMU $(MDBX_BUILD_OPTIONS)" \ $(MAKE) test-singleprocess || exit $$?; \ done diff --git a/test/main.cc b/test/main.cc index 94fd1166..4c700bff 100644 --- a/test/main.cc +++ b/test/main.cc @@ -222,6 +222,43 @@ void cleanup() { log_trace("<< cleanup"); } +static void fixup4qemu(actor_params ¶ms) { +#ifdef MDBX_SAFE4QEMU +#if MDBX_WORDBITS == 32 + intptr_t safe4qemu_limit = size_t(512) << 20 /* 512 megabytes */; +#if defined(__SANITIZE_ADDRESS__) + safe4qemu_limit >>= 1; +#else + if (RUNNING_ON_VALGRIND) + safe4qemu_limit >>= 1; +#endif /* __SANITIZE_ADDRESS__ */ + + if (params.size_lower > safe4qemu_limit || + params.size_now > safe4qemu_limit || + params.size_upper > safe4qemu_limit) { + params.size_upper = std::min(params.size_upper, safe4qemu_limit); + params.size_now = std::min(params.size_now, params.size_upper); + params.size_lower = std::min(params.size_lower, params.size_now); + log_notice("workaround: for conformance 32-bit build with " + "QEMU/ASAN/Valgrind database size reduced to %zu megabytes", + safe4qemu_limit >> 20); + } +#endif /* MDBX_WORDBITS == 32 */ + +#if defined(__alpha__) || defined(__alpha) || defined(__sparc__) || \ + defined(__sparc) || defined(__sparc64__) || defined(__sparc64) + if (params.size_lower != params.size_upper) { + log_notice( + "workaround: for conformance Alpha/Sparc build with QEMU/ASAN/Valgrind " + "enforce fixed database size %zu megabytes", + params.size_upper >> 20); + params.size_lower = params.size_now = params.size_upper; + } +#endif /* Alpha || Sparc */ +#endif /* MDBX_SAFE4QEMU */ + (void)params; +} + int main(int argc, char *const argv[]) { #ifdef _DEBUG @@ -254,6 +291,7 @@ int main(int argc, char *const argv[]) { const char *value = nullptr; if (config::parse_option(argc, argv, narg, "case", &value)) { + fixup4qemu(params); testcase_setup(value, params, last_space_id); continue; } @@ -486,38 +524,47 @@ int main(int argc, char *const argv[]) { continue; } if (config::parse_option(argc, argv, narg, "hill", &value, "auto")) { + fixup4qemu(params); configure_actor(last_space_id, ac_hill, value, params); continue; } if (config::parse_option(argc, argv, narg, "jitter", nullptr)) { + fixup4qemu(params); configure_actor(last_space_id, ac_jitter, value, params); continue; } if (config::parse_option(argc, argv, narg, "dead.reader", nullptr)) { + fixup4qemu(params); configure_actor(last_space_id, ac_deadread, value, params); continue; } if (config::parse_option(argc, argv, narg, "dead.writer", nullptr)) { + fixup4qemu(params); configure_actor(last_space_id, ac_deadwrite, value, params); continue; } if (config::parse_option(argc, argv, narg, "try", nullptr)) { + fixup4qemu(params); configure_actor(last_space_id, ac_try, value, params); continue; } if (config::parse_option(argc, argv, narg, "copy", nullptr)) { + fixup4qemu(params); configure_actor(last_space_id, ac_copy, value, params); continue; } if (config::parse_option(argc, argv, narg, "append", nullptr)) { + fixup4qemu(params); configure_actor(last_space_id, ac_append, value, params); continue; } if (config::parse_option(argc, argv, narg, "ttl", nullptr)) { + fixup4qemu(params); configure_actor(last_space_id, ac_ttl, value, params); continue; } if (config::parse_option(argc, argv, narg, "nested", nullptr)) { + fixup4qemu(params); configure_actor(last_space_id, ac_nested, value, params); continue; } @@ -531,9 +578,10 @@ int main(int argc, char *const argv[]) { global::config::console_mode)) continue; - if (*argv[narg] != '-') + if (*argv[narg] != '-') { + fixup4qemu(params); testcase_setup(argv[narg], params, last_space_id); - else + } else failure("Unknown option '%s'. Try --help\n", argv[narg]); } diff --git a/test/utils.cc b/test/utils.cc index 8e53465c..b628756d 100644 --- a/test/utils.cc +++ b/test/utils.cc @@ -129,7 +129,7 @@ uint64_t entropy_ticks(void) { uint64_t ticks; __asm __volatile("stck 0(%0)" : : "a"(&(ticks)) : "memory", "cc"); return ticks; -#elif defined(__alpha__) +#elif defined(__alpha__) || defined(__alpha) uint64_t ticks; __asm __volatile("rpcc %0" : "=r"(ticks)); return ticks;