Skip to content

Commit

Permalink
memcpy test fix build warning on openbsd. (#714)
Browse files Browse the repository at this point in the history
* memcpy test fix build warning on openbsd.

* enabling TEST_LIMITED for openbsd too.
  • Loading branch information
devnexen authored Dec 18, 2024
1 parent 57c88ef commit 6952683
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/test/func/memory/memory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,28 @@
#include <test/xoroshiro.h>
#include <unordered_set>
#include <vector>
#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.
* QEMU `setrlimit64` does not behave as the same as native linux,
* so we need to exclude it from such tests.
*/
# include <sys/resource.h>
# include <sys/sysinfo.h>
# ifndef __OpenBSD__
# include <sys/sysinfo.h>
# endif
# include <sys/wait.h>
# include <unistd.h>
# 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
Expand All @@ -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))
Expand All @@ -59,6 +66,7 @@ void test_limited(rlim64_t as_limit, size_t& count)
upper_bound = std::min(
upper_bound, static_cast<unsigned long long>(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);
Expand Down
7 changes: 7 additions & 0 deletions src/test/perf/memcpy/memcpy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<Shape> allocs;
Expand Down

0 comments on commit 6952683

Please sign in to comment.