llvm.org GIT mirror llvm / 8fb520e
Original patch by Talin. * Added the first LLVM unittest -- DenseMap. * Updated mkpatch utility to include llvm/unittests dir * Added top-level target "unittests" to run all unittests git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@61541 91177308-0d34-0410-b5e6-96231b3b80d8 Misha Brukman 10 years ago
7 changed file(s) with 261 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
2727 OPTIONAL_DIRS := examples projects bindings
2828 endif
2929
30 EXTRA_DIST := test llvm.spec include win32 Xcode
30 EXTRA_DIST := test unittests llvm.spec include win32 Xcode
3131
3232 include $(LEVEL)/Makefile.config
3333
5050
5151 ifeq ($(MAKECMDGOALS),tools-only)
5252 DIRS := $(filter-out runtime docs, $(DIRS))
53 OPTIONAL_DIRS :=
54 endif
55
56 ifeq ($(MAKECMDGOALS),unittests)
57 DIRS := $(filter-out tools runtime docs, $(DIRS)) utils unittests
5358 OPTIONAL_DIRS :=
5459 endif
5560
110115 tools-only: all
111116 libs-only: all
112117 install-libs: install
118 unittests: all
113119
114120 #------------------------------------------------------------------------
115121 # Make sure the generated headers are up-to-date. This must be kept in
0 //===- llvm/unittest/ADT/DenseMapMap.cpp - DenseMap unit tests --*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "gtest/gtest.h"
10 #include "llvm/ADT/DenseMap.h"
11
12 using namespace llvm;
13
14 namespace {
15
16 // Test fixture
17 class DenseMapTest : public testing::Test {
18 protected:
19 DenseMap uintMap;
20 DenseMap uintPtrMap;
21 uint32_t dummyInt;
22 };
23
24 // Empty map tests
25 TEST_F(DenseMapTest, EmptyIntMapTest) {
26 // Size tests
27 EXPECT_EQ(0u, uintMap.size());
28 EXPECT_TRUE(uintMap.empty());
29
30 // Iterator tests
31 EXPECT_TRUE(uintMap.begin() == uintMap.end());
32
33 // Lookup tests
34 EXPECT_FALSE(uintMap.count(0u));
35 EXPECT_TRUE(uintMap.find(0u) == uintMap.end());
36 EXPECT_EQ(0u, uintMap.lookup(0u));
37 }
38
39 // Empty map tests for pointer map
40 TEST_F(DenseMapTest, EmptyPtrMapTest) {
41 // Size tests
42 EXPECT_EQ(0u, uintPtrMap.size());
43 EXPECT_TRUE(uintPtrMap.empty());
44
45 // Iterator tests
46 EXPECT_TRUE(uintPtrMap.begin() == uintPtrMap.end());
47
48 // Lookup tests
49 EXPECT_FALSE(uintPtrMap.count(&dummyInt));
50 EXPECT_TRUE(uintPtrMap.find(&dummyInt) == uintPtrMap.begin());
51 EXPECT_EQ(0, uintPtrMap.lookup(&dummyInt));
52 }
53
54 // Constant map tests
55 TEST_F(DenseMapTest, ConstEmptyMapTest) {
56 const DenseMap & constUintMap = uintMap;
57 const DenseMap & constUintPtrMap = uintPtrMap;
58 EXPECT_EQ(0u, constUintMap.size());
59 EXPECT_EQ(0u, constUintPtrMap.size());
60 EXPECT_TRUE(constUintMap.empty());
61 EXPECT_TRUE(constUintPtrMap.empty());
62 EXPECT_TRUE(constUintMap.begin() == constUintMap.end());
63 EXPECT_TRUE(constUintPtrMap.begin() == constUintPtrMap.end());
64 }
65
66 // A map with a single entry
67 TEST_F(DenseMapTest, SingleEntryMapTest) {
68 uintMap[0] = 1;
69
70 // Size tests
71 EXPECT_EQ(1u, uintMap.size());
72 EXPECT_FALSE(uintMap.begin() == uintMap.end());
73 EXPECT_FALSE(uintMap.empty());
74
75 // Iterator tests
76 DenseMap::iterator it = uintMap.begin();
77 EXPECT_EQ(0u, it->first);
78 EXPECT_EQ(1u, it->second);
79 ++it;
80 EXPECT_TRUE(it == uintMap.end());
81
82 // Lookup tests
83 EXPECT_TRUE(uintMap.count(0u));
84 EXPECT_TRUE(uintMap.find(0u) == uintMap.begin());
85 EXPECT_EQ(1u, uintMap.lookup(0u));
86 EXPECT_EQ(1u, uintMap[0]);
87 }
88
89 // Test clear() method
90 TEST_F(DenseMapTest, ClearTest) {
91 uintMap[0] = 1;
92 uintMap.clear();
93
94 EXPECT_EQ(0u, uintMap.size());
95 EXPECT_TRUE(uintMap.empty());
96 EXPECT_TRUE(uintMap.begin() == uintMap.end());
97 }
98
99 // Test erase(iterator) method
100 TEST_F(DenseMapTest, EraseTest) {
101 uintMap[0] = 1;
102 uintMap.erase(uintMap.begin());
103
104 EXPECT_EQ(0u, uintMap.size());
105 EXPECT_TRUE(uintMap.empty());
106 EXPECT_TRUE(uintMap.begin() == uintMap.end());
107 }
108
109 // Test erase(value) method
110 TEST_F(DenseMapTest, EraseTest2) {
111 uintMap[0] = 1;
112 uintMap.erase(0);
113
114 EXPECT_EQ(0u, uintMap.size());
115 EXPECT_TRUE(uintMap.empty());
116 EXPECT_TRUE(uintMap.begin() == uintMap.end());
117 }
118
119 // Test insert() method
120 TEST_F(DenseMapTest, InsertTest) {
121 uintMap.insert(std::make_pair(0u, 1u));
122 EXPECT_EQ(1u, uintMap.size());
123 EXPECT_EQ(1u, uintMap[0]);
124 }
125
126 // Test copy constructor method
127 TEST_F(DenseMapTest, AssignmentTest) {
128 uintMap[0] = 1;
129 DenseMap copyMap(uintMap);
130
131 EXPECT_EQ(1u, copyMap.size());
132 EXPECT_EQ(1u, copyMap[0]);
133 }
134
135 // Test assignment operator method
136 TEST_F(DenseMapTest, CopyConstructorTest) {
137 uintMap[0] = 1;
138 DenseMap copyMap = uintMap;
139
140 EXPECT_EQ(1u, copyMap.size());
141 EXPECT_EQ(1u, copyMap[0]);
142 }
143
144 // A more complex iteration test
145 TEST_F(DenseMapTest, IterationTest) {
146 bool visited[100];
147
148 // Insert 100 numbers into the map
149 for (int i = 0; i < 100; ++i) {
150 visited[i] = false;
151 uintMap[i] = 3;
152 }
153
154 // Iterate over all numbers and mark each one found.
155 for (DenseMap::iterator it = uintMap.begin();
156 it != uintMap.end(); ++it) {
157 visited[it->first] = true;
158 }
159
160 // Ensure every number was visited.
161 for (int i = 0; i < 100; ++i) {
162 EXPECT_EQ(true, visited[i]);
163 }
164 }
165
166 }
0 ##===- unittests/ADT/Makefile ------------------------------*- Makefile -*-===##
1 #
2 # The LLVM Compiler Infrastructure
3 #
4 # This file is distributed under the University of Illinois Open Source
5 # License. See LICENSE.TXT for details.
6 #
7 ##===----------------------------------------------------------------------===##
8
9 LEVEL = ../..
10 TESTNAME = ADT
11 LINK_COMPONENTS := core support
12
13 include $(LEVEL)/Makefile.config
14 include $(LLVM_SRC_ROOT)/unittests/Makefile.unittest
0 ##===- unittests/Makefile ----------------------------------*- Makefile -*-===##
1 #
2 # The LLVM Compiler Infrastructure
3 #
4 # This file is distributed under the University of Illinois Open Source
5 # License. See LICENSE.TXT for details.
6 #
7 ##===----------------------------------------------------------------------===##
8
9 LEVEL = ..
10 include $(LEVEL)/Makefile.config
11
12 LIBRARYNAME = UnitTestMain
13 BUILD_ARCHIVE = 1
14 CPP.Flags += -I$(LLVM_SRC_ROOT)/utils/unittest/googletest/include/
15 CPP.Flags += -Wno-variadic-macros
16
17 PARALLEL_DIRS = ADT
18
19 include $(LEVEL)/Makefile.common
0 ##===- unittests/Makefile.unittest -------------------------*- Makefile -*-===##
1 #
2 # The LLVM Compiler Infrastructure
3 #
4 # This file is distributed under the University of Illinois Open Source
5 # License. See LICENSE.TXT for details.
6 #
7 ##===----------------------------------------------------------------------===##
8 #
9 # This file is included by all of the unit test makefiles.
10 #
11 ##===----------------------------------------------------------------------===##
12
13 # Set up variables for building a unit test.
14 ifdef TESTNAME
15
16 LLVMUnitTestDir := $(LLVM_OBJ_ROOT)/$(BuildMode)/unittests
17 LLVMUnitTestExe := $(LLVMUnitTestDir)/$(TESTNAME)Tests$(EXEEXT)
18
19 include $(LEVEL)/Makefile.common
20
21 CPP.Flags += -I$(LLVM_SRC_ROOT)/utils/unittest/googletest/include/
22 CPP.Flags += -Wno-variadic-macros
23 LD.Flags += -lGoogleTest -lUnitTestMain
24
25 $(LLVMUnitTestExe): $(ObjectsO) $(ProjLibsPaths) $(LLVMLibsPaths)
26 $(Echo) Linking $(BuildMode) unit test $(TESTNAME) $(StripWarnMsg)
27 $(Verb) $(LTLink) -o $@ $(TOOLLINKOPTS) $(ObjectsO) $(ProjLibsOptions) \
28 $(LLVMLibsOptions) $(ExtraLibs) $(TOOLLINKOPTSB) $(LIBS)
29 $(Echo) ======= Finished Linking $(BuildMode) Unit test $(TESTNAME) \
30 $(StripWarnMsg)
31
32 all:: $(LLVMUnitTestExe)
33 $(LLVMUnitTestExe)
34
35 endif
0 //===--- unittests/TestMain.cpp - unittest driver -------------------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "gtest/gtest.h"
10
11 int main(int argc, char **argv) {
12 testing::InitGoogleTest(&argc, argv);
13 return RUN_ALL_TESTS();
14 }
2323 autoconf docs utils include lib/System lib/Support lib/VMCore lib/AsmParser \
2424 lib/Bitcode lib/Analysis lib/Transforms lib/CodeGen lib/Target \
2525 lib/ExecutionEngine lib/Debugger lib/Linker \
26 tools test runtime projects examples win32 Xcode
26 tools test unittests runtime projects examples win32 Xcode
2727
2828 echo "mkpatch: Removing cruft from the patch file"
2929 sed -e '/^[?] .*/d' -e '/^cvs diff: Diffing/d' "$NAME".patch.raw | awk '\