blob: eb46b22f06c1f2939cfcc04b89f5d57f02938fed [file] [log] [blame]
Reid Kleckner0e6e9b92016-02-03 21:41:24 +00001//===- unittests/MC/TargetRegistry.cpp ------------------------------------===//
Douglas Katzmand7e20e72015-05-08 15:34:12 +00002//
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
Reid Kleckner0e6e9b92016-02-03 21:41:24 +000010// The target registry code lives in Support, but it relies on linking in all
11// LLVM targets. We keep this test with the MC tests, which already do that, to
12// keep the SupportTests target small.
13
Douglas Katzmand7e20e72015-05-08 15:34:12 +000014#include "llvm/Support/TargetRegistry.h"
15#include "llvm/Support/TargetSelect.h"
16#include "gtest/gtest.h"
17
18using namespace llvm;
19
20namespace {
21
22TEST(TargetRegistry, TargetHasArchType) {
23 // Presence of at least one target will be asserted when done with the loop,
24 // else this would pass by accident if InitializeAllTargetInfos were omitted.
25 int Count = 0;
26
27 llvm::InitializeAllTargetInfos();
28
David Blaikiebbd301d2015-05-11 22:20:48 +000029 for (const Target &T : TargetRegistry::targets()) {
30 StringRef Name = T.getName();
Douglas Katzmand7e20e72015-05-08 15:34:12 +000031 // There is really no way (at present) to ask a Target whether it targets
32 // a specific architecture, because the logic for that is buried in a
33 // predicate.
34 // We can't ask the predicate "Are you a function that always returns
35 // false?"
36 // So given that the cpp backend truly has no target arch, it is skipped.
37 if (Name != "cpp") {
38 Triple::ArchType Arch = Triple::getArchTypeForLLVMName(Name);
39 EXPECT_NE(Arch, Triple::UnknownArch);
40 ++Count;
41 }
42 }
43 ASSERT_NE(Count, 0);
44}
45
46} // end namespace