1 //========- unittests/Support/Host.cpp - Host.cpp tests --------------========// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "llvm/Support/Host.h" 11 #include "llvm/ADT/SmallVector.h" 12 #include "llvm/ADT/Triple.h" 13 14 #include "gtest/gtest.h" 15 16 using namespace llvm; 17 18 class HostTest : public testing::Test { 19 Triple Host; 20 SmallVector<std::pair<Triple::ArchType, Triple::OSType>, 4> SupportedArchAndOSs; 21 22 protected: 23 bool isSupportedArchAndOS() { 24 if (is_contained(SupportedArchAndOSs, std::make_pair(Host.getArch(), Host.getOS()))) 25 return true; 26 27 return false; 28 } 29 30 HostTest() { 31 Host.setTriple(Triple::normalize(sys::getProcessTriple())); 32 33 // Initially this is only testing detection of the number of 34 // physical cores, which is currently only supported/tested for 35 // x86_64 Linux and Darwin. 36 SupportedArchAndOSs.push_back(std::make_pair(Triple::x86_64, Triple::Linux)); 37 SupportedArchAndOSs.push_back(std::make_pair(Triple::x86_64, Triple::Darwin)); 38 } 39 }; 40 41 TEST_F(HostTest, NumPhysicalCores) { 42 int Num = sys::getHostNumPhysicalCores(); 43 44 if (isSupportedArchAndOS()) 45 ASSERT_GT(Num, 0); 46 else 47 ASSERT_EQ(Num, -1); 48 } 49