summaryrefslogtreecommitdiff
path: root/unittests/Support
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2017-07-13 19:25:18 +0000
committerDimitry Andric <dim@FreeBSD.org>2017-07-13 19:25:18 +0000
commitca089b24d48ef6fa8da2d0bb8c25bb802c4a95c0 (patch)
tree3a28a772df9b17aef34f49e3c727965ad28c0c93 /unittests/Support
parent9df3605dea17e84f8183581f6103bd0c79e2a606 (diff)
Notes
Diffstat (limited to 'unittests/Support')
-rw-r--r--unittests/Support/DynamicLibrary/DynamicLibraryTest.cpp10
-rw-r--r--unittests/Support/ErrorTest.cpp2
-rw-r--r--unittests/Support/Host.cpp61
-rw-r--r--unittests/Support/MathExtrasTest.cpp2
4 files changed, 74 insertions, 1 deletions
diff --git a/unittests/Support/DynamicLibrary/DynamicLibraryTest.cpp b/unittests/Support/DynamicLibrary/DynamicLibraryTest.cpp
index c54e1b7eed24..370e1c5ed5e8 100644
--- a/unittests/Support/DynamicLibrary/DynamicLibraryTest.cpp
+++ b/unittests/Support/DynamicLibrary/DynamicLibraryTest.cpp
@@ -77,6 +77,7 @@ TEST(DynamicLibrary, Overload) {
EXPECT_TRUE(DL.isValid());
EXPECT_TRUE(Err.empty());
+ // Test overloading local symbols does not occur by default
GS = FuncPtr<GetString>(DynamicLibrary::SearchForAddressOfSymbol("TestA"));
EXPECT_TRUE(GS != nullptr && GS == &TestA);
EXPECT_EQ(StdString(GS()), "ProcessCall");
@@ -85,6 +86,12 @@ TEST(DynamicLibrary, Overload) {
EXPECT_TRUE(GS != nullptr && GS == &TestA);
EXPECT_EQ(StdString(GS()), "ProcessCall");
+ // Test overloading by forcing library priority when searching for a symbol
+ DynamicLibrary::SearchOrder = DynamicLibrary::SO_LoadedFirst;
+ GS = FuncPtr<GetString>(DynamicLibrary::SearchForAddressOfSymbol("TestA"));
+ EXPECT_TRUE(GS != nullptr && GS != &TestA);
+ EXPECT_EQ(StdString(GS()), "LibCall");
+
DynamicLibrary::AddSymbol("TestA", PtrFunc(&OverloadTestA));
GS = FuncPtr<GetString>(DL.getAddressOfSymbol("TestA"));
EXPECT_TRUE(GS != nullptr && GS != &OverloadTestA);
@@ -95,6 +102,9 @@ TEST(DynamicLibrary, Overload) {
}
EXPECT_TRUE(FuncPtr<GetString>(DynamicLibrary::SearchForAddressOfSymbol(
"TestA")) == nullptr);
+
+ // Check serach ordering is reset to default after call to llvm_shutdown
+ EXPECT_TRUE(DynamicLibrary::SearchOrder == DynamicLibrary::SO_Linker);
}
TEST(DynamicLibrary, Shutdown) {
diff --git a/unittests/Support/ErrorTest.cpp b/unittests/Support/ErrorTest.cpp
index 299fc50b4697..a762cf023f9c 100644
--- a/unittests/Support/ErrorTest.cpp
+++ b/unittests/Support/ErrorTest.cpp
@@ -360,7 +360,7 @@ TEST(Error, CheckJoinErrors) {
[&](const CustomError &CE) {
Sum += CE.getInfo();
});
- EXPECT_EQ(Sum, 28) << "Failed to correctly concatenate erorr lists.";
+ EXPECT_EQ(Sum, 28) << "Failed to correctly concatenate error lists.";
}
}
diff --git a/unittests/Support/Host.cpp b/unittests/Support/Host.cpp
index fd53697793c7..4f895e7163c5 100644
--- a/unittests/Support/Host.cpp
+++ b/unittests/Support/Host.cpp
@@ -10,9 +10,23 @@
#include "llvm/Support/Host.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Triple.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/Program.h"
#include "gtest/gtest.h"
+#define ASSERT_NO_ERROR(x) \
+ if (std::error_code ASSERT_NO_ERROR_ec = x) { \
+ SmallString<128> MessageStorage; \
+ raw_svector_ostream Message(MessageStorage); \
+ Message << #x ": did not return errc::success.\n" \
+ << "error number: " << ASSERT_NO_ERROR_ec.value() << "\n" \
+ << "error message: " << ASSERT_NO_ERROR_ec.message() << "\n"; \
+ GTEST_FATAL_FAILURE_(MessageStorage.c_str()); \
+ } else { \
+ }
+
using namespace llvm;
class HostTest : public testing::Test {
@@ -114,3 +128,50 @@ Hardware : Qualcomm Technologies, Inc MSM8992
EXPECT_EQ(sys::detail::getHostCPUNameForARM(MSM8992ProcCpuInfo),
"cortex-a53");
}
+
+#if defined(__APPLE__)
+TEST_F(HostTest, getMacOSHostVersion) {
+ using namespace llvm::sys;
+ llvm::Triple HostTriple(getProcessTriple());
+ if (!HostTriple.isMacOSX())
+ return;
+
+ SmallString<128> TestDirectory;
+ ASSERT_NO_ERROR(fs::createUniqueDirectory("host_test", TestDirectory));
+ SmallString<128> OutputFile(TestDirectory);
+ path::append(OutputFile, "out");
+
+ const char *SwVersPath = "/usr/bin/sw_vers";
+ const char *argv[] = {SwVersPath, "-productVersion", nullptr};
+ StringRef OutputPath = OutputFile.str();
+ const StringRef *Redirects[] = {/*STDIN=*/nullptr, /*STDOUT=*/&OutputPath,
+ /*STDERR=*/nullptr};
+ int RetCode = ExecuteAndWait(SwVersPath, argv, /*env=*/nullptr, Redirects);
+ ASSERT_EQ(0, RetCode);
+
+ int FD = 0;
+ ASSERT_NO_ERROR(fs::openFileForRead(OutputPath, FD));
+ off_t Size = ::lseek(FD, 0, SEEK_END);
+ ASSERT_NE(-1, Size);
+ ::lseek(FD, 0, SEEK_SET);
+ std::unique_ptr<char[]> Buffer = llvm::make_unique<char[]>(Size);
+ ASSERT_EQ(::read(FD, Buffer.get(), Size), Size);
+ ::close(FD);
+
+ // Ensure that the two versions match.
+ StringRef SystemVersion(Buffer.get(), Size);
+ unsigned SystemMajor, SystemMinor, SystemMicro;
+ ASSERT_EQ(llvm::Triple((Twine("x86_64-apple-macos") + SystemVersion))
+ .getMacOSXVersion(SystemMajor, SystemMinor, SystemMicro),
+ true);
+ unsigned HostMajor, HostMinor, HostMicro;
+ ASSERT_EQ(HostTriple.getMacOSXVersion(HostMajor, HostMinor, HostMicro), true);
+
+ // Don't compare the 'Micro' version, as it's always '0' for the 'Darwin'
+ // triples.
+ ASSERT_EQ(std::tie(SystemMajor, SystemMinor), std::tie(HostMajor, HostMinor));
+
+ ASSERT_NO_ERROR(fs::remove(OutputPath));
+ ASSERT_NO_ERROR(fs::remove(TestDirectory.str()));
+}
+#endif
diff --git a/unittests/Support/MathExtrasTest.cpp b/unittests/Support/MathExtrasTest.cpp
index e26653b8a656..694a1f24d032 100644
--- a/unittests/Support/MathExtrasTest.cpp
+++ b/unittests/Support/MathExtrasTest.cpp
@@ -177,6 +177,7 @@ TEST(MathExtras, reverseBits) {
}
TEST(MathExtras, isPowerOf2_32) {
+ EXPECT_FALSE(isPowerOf2_32(0));
EXPECT_TRUE(isPowerOf2_32(1 << 6));
EXPECT_TRUE(isPowerOf2_32(1 << 12));
EXPECT_FALSE(isPowerOf2_32((1 << 19) + 3));
@@ -184,6 +185,7 @@ TEST(MathExtras, isPowerOf2_32) {
}
TEST(MathExtras, isPowerOf2_64) {
+ EXPECT_FALSE(isPowerOf2_64(0));
EXPECT_TRUE(isPowerOf2_64(1LL << 46));
EXPECT_TRUE(isPowerOf2_64(1LL << 12));
EXPECT_FALSE(isPowerOf2_64((1LL << 53) + 3));