From 6952683692aca9e2b4109882c1a2bb589bd844f2 Mon Sep 17 00:00:00 2001 From: David CARLIER Date: Wed, 18 Dec 2024 12:42:26 +0000 Subject: [PATCH] memcpy test fix build warning on openbsd. (#714) * memcpy test fix build warning on openbsd. * enabling TEST_LIMITED for openbsd too. --- src/test/func/memory/memory.cc | 14 +++++++++++--- src/test/perf/memcpy/memcpy.cc | 7 +++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/test/func/memory/memory.cc b/src/test/func/memory/memory.cc index 7d176f43d..c85659eab 100644 --- a/src/test/func/memory/memory.cc +++ b/src/test/func/memory/memory.cc @@ -5,8 +5,8 @@ #include #include #include -#if ((defined(__linux__) && !defined(__ANDROID__)) || defined(__sun)) && \ - !defined(SNMALLOC_QEMU_WORKAROUND) +#if ((defined(__linux__) && !defined(__ANDROID__)) || defined(__sun)) || \ + defined(__OpenBSD__) && !defined(SNMALLOC_QEMU_WORKAROUND) /* * We only test allocations with limited AS on linux and Solaris for now. * It should be a good representative for POSIX systems. @@ -14,13 +14,19 @@ * so we need to exclude it from such tests. */ # include -# include +# ifndef __OpenBSD__ +# include +# endif # include # include # define TEST_LIMITED # define KiB (1024ull) # define MiB (KiB * KiB) # define GiB (KiB * MiB) + +# ifdef __OpenBSD__ +using rlim64_t = rlim_t; +# endif #else using rlim64_t = size_t; #endif @@ -45,6 +51,7 @@ void test_limited(rlim64_t as_limit, size_t& count) } std::cout << "limiting memory to " << limit.rlim_cur / KiB << " KiB" << std::endl; +# ifndef __OpenBSD__ struct sysinfo info {}; if (sysinfo(&info)) @@ -59,6 +66,7 @@ void test_limited(rlim64_t as_limit, size_t& count) upper_bound = std::min( upper_bound, static_cast(info.freeram >> 3u)); std::cout << "trying to alloc " << upper_bound / KiB << " KiB" << std::endl; +# endif auto& alloc = ThreadAlloc::get(); std::cout << "allocator initialised" << std::endl; auto chunk = alloc.alloc(upper_bound); diff --git a/src/test/perf/memcpy/memcpy.cc b/src/test/perf/memcpy/memcpy.cc index 763dcd72e..d726ea429 100644 --- a/src/test/perf/memcpy/memcpy.cc +++ b/src/test/perf/memcpy/memcpy.cc @@ -13,7 +13,14 @@ struct Shape size_t my_random() { +#ifndef __OpenBSD__ return (size_t)rand(); +#else + // OpenBSD complains on rand() usage + // we let it know we purposely want + // deterministic randomness here + return (size_t)lrand48(); +#endif } std::vector allocs;