|
7 | 7 | //===----------------------------------------------------------------------===//
|
8 | 8 |
|
9 | 9 | #include "llvm/TargetParser/Triple.h"
|
| 10 | +#include "llvm/Support/FormatVariadic.h" |
10 | 11 | #include "llvm/Support/VersionTuple.h"
|
11 | 12 | #include "gtest/gtest.h"
|
12 | 13 |
|
@@ -2737,4 +2738,41 @@ TEST(TripleTest, DXILNormaizeWithVersion) {
|
2737 | 2738 | EXPECT_EQ("dxilv1.0-pc-shadermodel5.0-compute",
|
2738 | 2739 | Triple::normalize("dxil-shadermodel5.0-pc-compute"));
|
2739 | 2740 | }
|
| 2741 | + |
| 2742 | +TEST(TripleTest, isCompatibleWith) { |
| 2743 | + struct { |
| 2744 | + const char *A; |
| 2745 | + const char *B; |
| 2746 | + bool Result; |
| 2747 | + } Cases[] = { |
| 2748 | + {"armv7-linux-gnueabihf", "thumbv7-linux-gnueabihf", true}, |
| 2749 | + {"armv4-none-unknown-eabi", "thumbv6-unknown-linux-gnueabihf", false}, |
| 2750 | + {"x86_64-apple-macosx10.9.0", "x86_64-apple-macosx10.10.0", true}, |
| 2751 | + {"x86_64-apple-macosx10.9.0", "i386-apple-macosx10.9.0", false}, |
| 2752 | + {"x86_64-apple-macosx10.9.0", "x86_64h-apple-macosx10.9.0", true}, |
| 2753 | + {"x86_64-unknown-linux-gnu", "x86_64-unknown-linux-gnu", true}, |
| 2754 | + {"x86_64-unknown-linux-gnu", "i386-unknown-linux-gnu", false}, |
| 2755 | + {"x86_64-unknown-linux-gnu", "x86_64h-unknown-linux-gnu", true}, |
| 2756 | + {"x86_64-pc-windows-gnu", "x86_64-pc-windows-msvc", false}, |
| 2757 | + {"x86_64-pc-windows-msvc", "x86_64-pc-windows-msvc-elf", false}, |
| 2758 | + {"i686-w64-windows-gnu", "i386-w64-windows-gnu", true}, |
| 2759 | + {"x86_64-w64-windows-gnu", "x86_64-pc-windows-gnu", true}, |
| 2760 | + {"armv7-w64-windows-gnu", "thumbv7-pc-windows-gnu", true}, |
| 2761 | + }; |
| 2762 | + |
| 2763 | + auto DoTest = [](const char *A, const char *B, |
| 2764 | + bool Result) -> testing::AssertionResult { |
| 2765 | + if (Triple(A).isCompatibleWith(Triple(B)) != Result) { |
| 2766 | + return testing::AssertionFailure() |
| 2767 | + << llvm::formatv("Triple {0} and {1} were expected to be {2}", A, |
| 2768 | + B, Result ? "compatible" : "incompatible"); |
| 2769 | + } |
| 2770 | + return testing::AssertionSuccess(); |
| 2771 | + }; |
| 2772 | + for (const auto &C : Cases) { |
| 2773 | + EXPECT_TRUE(DoTest(C.A, C.B, C.Result)); |
| 2774 | + // Test that the comparison is commutative. |
| 2775 | + EXPECT_TRUE(DoTest(C.B, C.A, C.Result)); |
| 2776 | + } |
| 2777 | +} |
2740 | 2778 | } // end anonymous namespace
|
0 commit comments