blob: 1fb0bc733149d1914590c6642f723f5bcf8d69e6 [file] [log] [blame]
Teresa Johnson7943fec2016-10-13 17:43:20 +00001//========- 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
16using namespace llvm;
17
18class HostTest : public testing::Test {
19 Triple Host;
20 SmallVector<std::pair<Triple::ArchType, Triple::OSType>, 4> SupportedArchAndOSs;
21
22protected:
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
40TEST_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}