Files
acceptance-tests
data
debian
docs
external
Newtonsoft.Json
api-doc-tools
api-snapshot
aspnetwebstack
binary-reference-assemblies
bockbuild
boringssl
cecil
cecil-legacy
corefx
corert
helix-binaries
ikdasm
ikvm
illinker-test-assets
linker
llvm
bindings
cmake
docs
examples
include
lib
projects
resources
runtimes
scripts
test
tools
unittests
ADT
Analysis
AsmParser
BinaryFormat
Bitcode
CodeGen
DebugInfo
ExecutionEngine
FuzzMutate
IR
LineEditor
Linker
MC
MI
Object
ObjectYAML
Option
ProfileData
Support
DynamicLibrary
ARMAttributeParser.cpp
AlignOfTest.cpp
AllocatorTest.cpp
ArrayRecyclerTest.cpp
BinaryStreamTest.cpp
BlockFrequencyTest.cpp
BranchProbabilityTest.cpp
CMakeLists.txt
CachePruningTest.cpp
Casting.cpp
Chrono.cpp
CommandLineTest.cpp
CompressionTest.cpp
ConvertUTFTest.cpp
CrashRecoveryTest.cpp
DataExtractorTest.cpp
DebugTest.cpp
EndianStreamTest.cpp
EndianTest.cpp
ErrnoTest.cpp
ErrorOrTest.cpp
ErrorTest.cpp
FileOutputBufferTest.cpp
FormatVariadicTest.cpp
GlobPatternTest.cpp
Host.cpp
LEB128Test.cpp
LineIteratorTest.cpp
LockFileManagerTest.cpp
MD5Test.cpp
ManagedStatic.cpp
MathExtrasTest.cpp
MemoryBufferTest.cpp
MemoryTest.cpp
NativeFormatTests.cpp
ParallelTest.cpp
Path.cpp
ProcessTest.cpp
ProgramTest.cpp
RegexTest.cpp
ReplaceFileTest.cpp
ReverseIterationTest.cpp
ScaledNumberTest.cpp
SourceMgrTest.cpp
SpecialCaseListTest.cpp
StringPool.cpp
SwapByteOrderTest.cpp
TarWriterTest.cpp
TargetParserTest.cpp
ThreadLocalTest.cpp
ThreadPool.cpp
Threading.cpp
TimerTest.cpp
TrailingObjectsTest.cpp
TrigramIndexTest.cpp
TypeNameTest.cpp
UnicodeTest.cpp
YAMLIOTest.cpp
YAMLParserTest.cpp
formatted_raw_ostream_test.cpp
raw_ostream_test.cpp
raw_pwrite_stream_test.cpp
raw_sha1_ostream_test.cpp
xxhashTest.cpp
Target
Transforms
XRay
tools
CMakeLists.txt
utils
.arcconfig
.clang-format
.clang-tidy
.gitattributes
.gitignore
CMakeLists.txt
CODE_OWNERS.TXT
CREDITS.TXT
LICENSE.TXT
LLVMBuild.txt
README.txt
RELEASE_TESTERS.TXT
configure
llvm.spec.in
nuget-buildtasks
nunit-lite
roslyn-binaries
rx
xunit-binaries
ikvm-native
libgc
llvm
m4
man
mcs
mk
mono
msvc
po
runtime
samples
scripts
support
tools
COPYING.LIB
LICENSE
Makefile.am
Makefile.in
NEWS
README.md
acinclude.m4
aclocal.m4
autogen.sh
code_of_conduct.md
compile
config.guess
config.h.in
config.rpath
config.sub
configure.REMOVED.git-id
configure.ac.REMOVED.git-id
depcomp
install-sh
ltmain.sh.REMOVED.git-id
missing
mkinstalldirs
mono-uninstalled.pc.in
test-driver
winconfig.h
linux-packaging-mono/external/llvm/unittests/Support/CachePruningTest.cpp

98 lines
3.7 KiB
C++
Raw Normal View History

//===- CachePruningTest.cpp -----------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "llvm/Support/CachePruning.h"
#include "llvm/Support/Error.h"
#include "gtest/gtest.h"
using namespace llvm;
TEST(CachePruningPolicyParser, Empty) {
auto P = parseCachePruningPolicy("");
ASSERT_TRUE(bool(P));
EXPECT_EQ(std::chrono::seconds(1200), P->Interval);
EXPECT_EQ(std::chrono::hours(7 * 24), P->Expiration);
EXPECT_EQ(75u, P->MaxSizePercentageOfAvailableSpace);
}
TEST(CachePruningPolicyParser, Interval) {
auto P = parseCachePruningPolicy("prune_interval=1s");
ASSERT_TRUE(bool(P));
EXPECT_EQ(std::chrono::seconds(1), P->Interval);
P = parseCachePruningPolicy("prune_interval=2m");
ASSERT_TRUE(bool(P));
EXPECT_EQ(std::chrono::minutes(2), *P->Interval);
P = parseCachePruningPolicy("prune_interval=3h");
ASSERT_TRUE(bool(P));
EXPECT_EQ(std::chrono::hours(3), *P->Interval);
}
TEST(CachePruningPolicyParser, Expiration) {
auto P = parseCachePruningPolicy("prune_after=1s");
ASSERT_TRUE(bool(P));
EXPECT_EQ(std::chrono::seconds(1), P->Expiration);
}
TEST(CachePruningPolicyParser, MaxSizePercentageOfAvailableSpace) {
auto P = parseCachePruningPolicy("cache_size=100%");
ASSERT_TRUE(bool(P));
EXPECT_EQ(100u, P->MaxSizePercentageOfAvailableSpace);
EXPECT_EQ(0u, P->MaxSizeBytes);
}
TEST(CachePruningPolicyParser, MaxSizeBytes) {
auto P = parseCachePruningPolicy("cache_size_bytes=1");
ASSERT_TRUE(bool(P));
EXPECT_EQ(75u, P->MaxSizePercentageOfAvailableSpace);
EXPECT_EQ(1u, P->MaxSizeBytes);
P = parseCachePruningPolicy("cache_size_bytes=2k");
ASSERT_TRUE(bool(P));
EXPECT_EQ(75u, P->MaxSizePercentageOfAvailableSpace);
EXPECT_EQ(2u * 1024u, P->MaxSizeBytes);
P = parseCachePruningPolicy("cache_size_bytes=3m");
ASSERT_TRUE(bool(P));
EXPECT_EQ(75u, P->MaxSizePercentageOfAvailableSpace);
EXPECT_EQ(3u * 1024u * 1024u, P->MaxSizeBytes);
P = parseCachePruningPolicy("cache_size_bytes=4G");
ASSERT_TRUE(bool(P));
EXPECT_EQ(75u, P->MaxSizePercentageOfAvailableSpace);
EXPECT_EQ(4ull * 1024ull * 1024ull * 1024ull, P->MaxSizeBytes);
}
TEST(CachePruningPolicyParser, Multiple) {
auto P = parseCachePruningPolicy("prune_after=1s:cache_size=50%");
ASSERT_TRUE(bool(P));
EXPECT_EQ(std::chrono::seconds(1200), P->Interval);
EXPECT_EQ(std::chrono::seconds(1), P->Expiration);
EXPECT_EQ(50u, P->MaxSizePercentageOfAvailableSpace);
}
TEST(CachePruningPolicyParser, Errors) {
EXPECT_EQ("Duration must not be empty",
toString(parseCachePruningPolicy("prune_interval=").takeError()));
EXPECT_EQ("'foo' not an integer",
toString(parseCachePruningPolicy("prune_interval=foos").takeError()));
EXPECT_EQ("'24x' must end with one of 's', 'm' or 'h'",
toString(parseCachePruningPolicy("prune_interval=24x").takeError()));
EXPECT_EQ("'foo' must be a percentage",
toString(parseCachePruningPolicy("cache_size=foo").takeError()));
EXPECT_EQ("'foo' not an integer",
toString(parseCachePruningPolicy("cache_size=foo%").takeError()));
EXPECT_EQ("'101' must be between 0 and 100",
toString(parseCachePruningPolicy("cache_size=101%").takeError()));
EXPECT_EQ(
"'foo' not an integer",
toString(parseCachePruningPolicy("cache_size_bytes=foo").takeError()));
EXPECT_EQ(
"'foo' not an integer",
toString(parseCachePruningPolicy("cache_size_bytes=foom").takeError()));
EXPECT_EQ("Unknown key: 'foo'",
toString(parseCachePruningPolicy("foo=bar").takeError()));
}