1 //===-- HostInfoTest.cpp --------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "lldb/Host/HostInfo.h" 10 #include "TestingSupport/SubsystemRAII.h" 11 #include "TestingSupport/TestUtilities.h" 12 #include "lldb/Host/FileSystem.h" 13 #include "lldb/lldb-defines.h" 14 #include "gtest/gtest.h" 15 16 using namespace lldb_private; 17 using namespace llvm; 18 19 namespace { 20 class HostInfoTest : public ::testing::Test { 21 SubsystemRAII<FileSystem, HostInfo> subsystems; 22 }; 23 } // namespace 24 25 TEST_F(HostInfoTest, GetAugmentedArchSpec) { 26 // Fully specified triple should not be changed. 27 ArchSpec spec = HostInfo::GetAugmentedArchSpec("x86_64-pc-linux-gnu"); 28 EXPECT_EQ(spec.GetTriple().getTriple(), "x86_64-pc-linux-gnu"); 29 30 // Same goes if we specify at least one of (os, vendor, env). 31 spec = HostInfo::GetAugmentedArchSpec("x86_64-pc"); 32 EXPECT_EQ(spec.GetTriple().getTriple(), "x86_64-pc"); 33 34 // But if we specify only an arch, we should fill in the rest from the host. 35 spec = HostInfo::GetAugmentedArchSpec("x86_64"); 36 Triple triple(sys::getDefaultTargetTriple()); 37 EXPECT_EQ(spec.GetTriple().getArch(), Triple::x86_64); 38 EXPECT_EQ(spec.GetTriple().getOS(), triple.getOS()); 39 EXPECT_EQ(spec.GetTriple().getVendor(), triple.getVendor()); 40 EXPECT_EQ(spec.GetTriple().getEnvironment(), triple.getEnvironment()); 41 42 // Test LLDB_ARCH_DEFAULT 43 EXPECT_EQ(HostInfo::GetAugmentedArchSpec(LLDB_ARCH_DEFAULT).GetTriple(), 44 HostInfo::GetArchitecture(HostInfo::eArchKindDefault).GetTriple()); 45 } 46 47 TEST_F(HostInfoTest, GetHostname) { 48 // Check non-empty string input works correctly. 49 std::string s("abc"); 50 EXPECT_TRUE(HostInfo::GetHostname(s)); 51 } 52