OSDN Git Service

unitests: add some ARM TargetParser tests
authorSaleem Abdulrasool <compnerd@compnerd.org>
Sun, 6 Mar 2016 04:50:55 +0000 (04:50 +0000)
committerSaleem Abdulrasool <compnerd@compnerd.org>
Sun, 6 Mar 2016 04:50:55 +0000 (04:50 +0000)
The ARM TargetParser would construct invalid StringRefs.  This would cause
asserts to trigger.  Add some tests in LLVM to ensure that we dont regress on
this in the future.  Although there is a test for this in clang, this ensures
that the changes would get caught in the same repository.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@262790 91177308-0d34-0410-b5e6-96231b3b80d8

unittests/Support/CMakeLists.txt
unittests/Support/TargetParserTest.cpp [new file with mode: 0644]

index 690a2e3..e4e053f 100644 (file)
@@ -38,6 +38,7 @@ add_llvm_unittest(SupportTests
   StreamingMemoryObject.cpp
   StringPool.cpp
   SwapByteOrderTest.cpp
+  TargetParserTest.cpp
   ThreadLocalTest.cpp
   ThreadPool.cpp
   TimerTest.cpp
diff --git a/unittests/Support/TargetParserTest.cpp b/unittests/Support/TargetParserTest.cpp
new file mode 100644 (file)
index 0000000..4bdf03a
--- /dev/null
@@ -0,0 +1,51 @@
+//===----------- TargetParser.cpp - Target Parser -------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "gtest/gtest.h"
+#include "llvm/Support/TargetParser.h"
+
+using namespace llvm;
+
+namespace {
+TEST(TargetParserTest, ARMArchName) {
+  for (ARM::ArchKind AK = static_cast<ARM::ArchKind>(0);
+       AK <= ARM::ArchKind::AK_LAST;
+       AK = static_cast<ARM::ArchKind>(static_cast<unsigned>(AK) + 1))
+    EXPECT_TRUE(AK == ARM::AK_LAST ? ARM::getArchName(AK).empty()
+                                   : !ARM::getArchName(AK).empty());
+}
+
+TEST(TargetParserTest, ARMCPUAttr) {
+  for (ARM::ArchKind AK = static_cast<ARM::ArchKind>(0);
+       AK <= ARM::ArchKind::AK_LAST;
+       AK = static_cast<ARM::ArchKind>(static_cast<unsigned>(AK) + 1))
+    EXPECT_TRUE((AK == ARM::AK_INVALID || AK == ARM::AK_LAST)
+                    ? ARM::getCPUAttr(AK).empty()
+                    : !ARM::getCPUAttr(AK).empty());
+}
+
+TEST(TargetParserTest, ARMSubArch) {
+  for (ARM::ArchKind AK = static_cast<ARM::ArchKind>(0);
+       AK <= ARM::ArchKind::AK_LAST;
+       AK = static_cast<ARM::ArchKind>(static_cast<unsigned>(AK) + 1))
+    EXPECT_TRUE((AK == ARM::AK_INVALID || AK == ARM::AK_IWMMXT ||
+                 AK == ARM::AK_IWMMXT2 || AK == ARM::AK_LAST)
+                    ? ARM::getSubArch(AK).empty()
+                    : !ARM::getSubArch(AK).empty());
+}
+
+TEST(TargetParserTest, ARMFPUName) {
+  for (ARM::FPUKind FK = static_cast<ARM::FPUKind>(0);
+       FK <= ARM::FPUKind::FK_LAST;
+       FK = static_cast<ARM::FPUKind>(static_cast<unsigned>(FK) + 1))
+    EXPECT_TRUE(FK == ARM::FK_LAST ? ARM::getFPUName(FK).empty()
+                                   : !ARM::getFPUName(FK).empty());
+}
+}
+