forked from OSchip/llvm-project
[Support][NFC] Add an explicit unit test for Process::getPageSize()
It turns out that it was only tested indirectly. For now test only on Linux X86-64 and aarch64.
This commit is contained in:
parent
460cbabe17
commit
002be6cfa2
|
@ -6,6 +6,9 @@
|
|||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/ADT/Triple.h"
|
||||
#include "llvm/Support/Error.h"
|
||||
#include "llvm/Support/Host.h"
|
||||
#include "llvm/Support/Process.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
|
@ -61,4 +64,39 @@ TEST(ProcessTest, Wchar) {
|
|||
}
|
||||
#endif
|
||||
|
||||
class PageSizeTest : public testing::Test {
|
||||
Triple Host;
|
||||
|
||||
protected:
|
||||
PageSizeTest() : Host(Triple::normalize(sys::getProcessTriple())) {}
|
||||
|
||||
bool isSupported() const {
|
||||
// For now just on X86-64 and Aarch64. This can be expanded in the future.
|
||||
return (Host.getArch() == Triple::x86_64 ||
|
||||
Host.getArch() == Triple::aarch64) &&
|
||||
Host.getOS() == Triple::Linux;
|
||||
}
|
||||
|
||||
bool pageSizeAsExpected(unsigned PageSize) const {
|
||||
switch (Host.getArch()) {
|
||||
case Triple::x86_64:
|
||||
return PageSize == 4096;
|
||||
case Triple::aarch64:
|
||||
// supported granule sizes are 4k, 16k and 64k
|
||||
return PageSize == 4096 || PageSize == 16384 || PageSize == 65536;
|
||||
default:
|
||||
llvm_unreachable("unexpected arch!");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(PageSizeTest, PageSize) {
|
||||
if (!isSupported())
|
||||
return;
|
||||
|
||||
llvm::Expected<unsigned> Result = llvm::sys::Process::getPageSize();
|
||||
ASSERT_FALSE(!Result);
|
||||
ASSERT_TRUE(pageSizeAsExpected(*Result));
|
||||
}
|
||||
|
||||
} // end anonymous namespace
|
||||
|
|
Loading…
Reference in New Issue