Teresa Johnson | 7943fec | 2016-10-13 17:43:20 +0000 | [diff] [blame^] | 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 for |
| 35 | // x86_64 Linux. |
| 36 | SupportedArchAndOSs.push_back(std::make_pair(Triple::x86_64, Triple::Linux)); |
| 37 | } |
| 38 | }; |
| 39 | |
| 40 | TEST_F(HostTest, NumPhysicalCores) { |
| 41 | int Num = sys::getHostNumPhysicalCores(); |
| 42 | |
| 43 | if (isSupportedArchAndOS()) |
| 44 | ASSERT_GT(Num, 0); |
| 45 | else |
| 46 | ASSERT_EQ(Num, -1); |
| 47 | } |