Files
snmalloc/src/test/func/pagemap/pagemap.cc
David Chisnall 0007a53ef9 Move CI to GitHub Actions
A few highlights relative to our existing CI:

- Add a FreeBSD 12.2 and 13.0 runner so we have some FreeBSD CI.
- Windows builds use msbuild with the Visual-Studio-provided clang toolchain to test clang
 - The matrix builds describe the axes of the matrix, not all points.
 - The Arm builds now cross-compile with a native clang and run the tests with qemu, rather than running the compiler, linker, and ctest all with qemu.
 
This also includes a fix for one of the tests that was doing `static_cast<unsigned int>(1) << 36`, which is undefined behaviour and was sometimes causing qemu to hang.  There is now an assert to catch this in the future.
2021-08-03 17:10:56 +01:00

57 lines
1.4 KiB
C++

/**
* Unit tests for operations in pagemap operations.
*
* Currently this tests a very specific case where the pagemap
* requires multiple levels of index. This was incorrectly implemented,
* but no examples were using multiple levels of pagemap.
*/
#include <ds/bits.h>
#include <iostream>
#include <snmalloc.h>
#include <test/setup.h>
using namespace snmalloc;
using T = size_t;
static constexpr size_t GRANULARITY_BITS = 9;
static constexpr T PRIME = 251;
Pagemap<GRANULARITY_BITS, T, 0, DefaultPrimAlloc> pagemap_test;
int main(int argc, char** argv)
{
UNUSED(argc);
UNUSED(argv);
setup();
constexpr int bits_to_test = bits::is64() ? 36 : 31;
T value = 0;
for (uintptr_t ptr = 0; ptr < bits::one_at_bit(bits_to_test);
ptr += bits::one_at_bit(GRANULARITY_BITS + 3))
{
pagemap_test.set(ptr, value);
value++;
if (value == PRIME)
value = 0;
if ((ptr % (1ULL << 32)) == 0)
std::cout << "." << std::flush;
}
std::cout << std::endl;
value = 0;
for (uintptr_t ptr = 0; ptr < bits::one_at_bit(bits_to_test);
ptr += bits::one_at_bit(GRANULARITY_BITS + 3))
{
T result = pagemap_test.get(ptr);
if (value != result)
Pal::error("Pagemap corrupt!");
value++;
if (value == PRIME)
value = 0;
if ((ptr % (1ULL << 32)) == 0)
std::cout << "." << std::flush;
}
std::cout << std::endl;
}