Reid Kleckner | 0e6e9b9 | 2016-02-03 21:41:24 +0000 | [diff] [blame] | 1 | //===- unittests/MC/TargetRegistry.cpp ------------------------------------===// |
Douglas Katzman | d7e20e7 | 2015-05-08 15:34:12 +0000 | [diff] [blame] | 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 | |
Reid Kleckner | 0e6e9b9 | 2016-02-03 21:41:24 +0000 | [diff] [blame] | 10 | // 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 Katzman | d7e20e7 | 2015-05-08 15:34:12 +0000 | [diff] [blame] | 14 | #include "llvm/Support/TargetRegistry.h" |
| 15 | #include "llvm/Support/TargetSelect.h" |
| 16 | #include "gtest/gtest.h" |
| 17 | |
| 18 | using namespace llvm; |
| 19 | |
| 20 | namespace { |
| 21 | |
| 22 | TEST(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 Blaikie | bbd301d | 2015-05-11 22:20:48 +0000 | [diff] [blame] | 29 | for (const Target &T : TargetRegistry::targets()) { |
| 30 | StringRef Name = T.getName(); |
Douglas Katzman | d7e20e7 | 2015-05-08 15:34:12 +0000 | [diff] [blame] | 31 | // 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 |