diff options
| author | Devtools Arcadia <[email protected]> | 2022-02-07 18:08:42 +0300 |
|---|---|---|
| committer | Devtools Arcadia <[email protected]> | 2022-02-07 18:08:42 +0300 |
| commit | 1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch) | |
| tree | e26c9fed0de5d9873cce7e00bc214573dc2195b7 /util/system/valgrind.h | |
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'util/system/valgrind.h')
| -rw-r--r-- | util/system/valgrind.h | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/util/system/valgrind.h b/util/system/valgrind.h new file mode 100644 index 00000000000..2ec4ed927ca --- /dev/null +++ b/util/system/valgrind.h @@ -0,0 +1,48 @@ +#pragma once + +#if defined(WITH_VALGRIND) && defined(HAVE_VALGRIND) + #include <valgrind/valgrind.h> + #include <valgrind/memcheck.h> + + #if !defined(VALGRIND_CHECK_READABLE) + #define VALGRIND_CHECK_READABLE(s, l) VALGRIND_CHECK_MEM_IS_DEFINED(s, l) + #endif + + #if !defined(VALGRIND_MAKE_READABLE) + #define VALGRIND_MAKE_READABLE(a, b) VALGRIND_MAKE_MEM_DEFINED(a, b) + #endif +#else + #define RUNNING_ON_VALGRIND 0 + #define VALGRIND_CHECK_READABLE(s, l) + #define VALGRIND_MAKE_READABLE(a, b) 0 + #define VALGRIND_STACK_REGISTER(start, end) 0 + #define VALGRIND_STACK_DEREGISTER(id) + #define VALGRIND_DISCARD(v) ((void)v) +static inline int VALGRIND_PRINTF(...) { + return 0; +} + #define VALGRIND_DO_LEAK_CHECK +#endif + +namespace NValgrind { + inline constexpr static bool ValgrindIsOn() noexcept { +#if defined(WITH_VALGRIND) + return true; +#else + return false; +#endif + } + + // Returns valgrinded if running under Valgrind and plain otherwise + // Ment to be used in test code for constants (timeouts, etc) + template <typename T> + inline constexpr static T PlainOrUnderValgrind(T plain, T valgrinded) noexcept { +#if defined(WITH_VALGRIND) + Y_UNUSED(plain); + return valgrinded; +#else + Y_UNUSED(valgrinded); + return plain; +#endif + } +} |
