diff options
Diffstat (limited to 'tests/utils.h')
-rw-r--r-- | tests/utils.h | 53 |
1 files changed, 8 insertions, 45 deletions
diff --git a/tests/utils.h b/tests/utils.h index 592ac0e56..5014ef743 100644 --- a/tests/utils.h +++ b/tests/utils.h @@ -21,21 +21,10 @@ #include <fcntl.h> #include <inttypes.h> #include <sys/mman.h> -#include <sys/prctl.h> #include <sys/types.h> #include <sys/wait.h> #include <unistd.h> -#if defined(__BIONIC__) -#include <sys/system_properties.h> -#endif - -#if defined(__BIONIC__) -#include <bionic/macros.h> -#else -#define untag_address(p) p -#endif - #include <atomic> #include <string> #include <regex> @@ -77,16 +66,14 @@ static inline bool running_with_hwasan() { #define SKIP_WITH_HWASAN if (running_with_hwasan()) GTEST_SKIP() -static inline bool running_with_native_bridge() { -#if defined(__BIONIC__) - static const prop_info* pi = __system_property_find("ro.dalvik.vm.isa." ABI_STRING); - return pi != nullptr; +static inline void* untag_address(void* addr) { +#if defined(__LP64__) + constexpr uintptr_t mask = (static_cast<uintptr_t>(1) << 56) - 1; + addr = reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(addr) & mask); #endif - return false; + return addr; } -#define SKIP_WITH_NATIVE_BRIDGE if (running_with_native_bridge()) GTEST_SKIP() - #if defined(__linux__) #include <sys/sysmacros.h> @@ -186,14 +173,10 @@ static inline void AssertChildExited(int pid, int expected_exit_status, } } -static inline bool CloseOnExec(int fd) { +static inline void AssertCloseOnExec(int fd, bool close_on_exec) { int flags = fcntl(fd, F_GETFD); - // This isn't ideal, but the alternatives are worse: - // * If we return void and use ASSERT_NE here, we get failures at utils.h:191 - // rather than in the relevant test. - // * If we ignore failures of fcntl(), well, that's obviously a bad idea. - if (flags == -1) abort(); - return flags & FD_CLOEXEC; + ASSERT_NE(flags, -1); + ASSERT_EQ(close_on_exec ? FD_CLOEXEC : 0, flags & FD_CLOEXEC); } // The absolute path to the executable @@ -295,23 +278,3 @@ class FdLeakChecker { size_t start_count_ = CountOpenFds(); }; - -// From <benchmark/benchmark.h>. -template <class Tp> -static inline void DoNotOptimize(Tp const& value) { - asm volatile("" : : "r,m"(value) : "memory"); -} -template <class Tp> -static inline void DoNotOptimize(Tp& value) { - asm volatile("" : "+r,m"(value) : : "memory"); -} - -static inline bool running_with_mte() { -#ifdef __aarch64__ - int level = prctl(PR_GET_TAGGED_ADDR_CTRL, 0, 0, 0, 0); - return level >= 0 && (level & PR_TAGGED_ADDR_ENABLE) && - (level & PR_MTE_TCF_MASK) != PR_MTE_TCF_NONE; -#else - return false; -#endif -} |