Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 1 | //===- implTest.cpp -------------------------------------------------------===// |
| 2 | // |
| 3 | // The MCLinker Project |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 9 | #include "StaticResolverTest.h" |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 10 | #include "mcld/Support/TargetSelect.h" |
| 11 | #include "mcld/LD/StaticResolver.h" |
| 12 | #include "mcld/LD/ResolveInfo.h" |
| 13 | #include "mcld/LinkerConfig.h" |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 14 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 15 | #include "mcld/Support/FileSystem.h" |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 16 | |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 17 | using namespace mcld; |
| 18 | using namespace mcldtest; |
| 19 | |
Shih-wei Liao | 67e37f1 | 2012-07-27 03:50:34 -0700 | [diff] [blame] | 20 | //===----------------------------------------------------------------------===// |
| 21 | // StaticResolverTest |
| 22 | //===----------------------------------------------------------------------===// |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 23 | // Constructor can do set-up work for all test here. |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 24 | StaticResolverTest::StaticResolverTest() : m_pResolver(NULL), m_pConfig(NULL) { |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 25 | // create testee. modify it if need |
| 26 | m_pResolver = new StaticResolver(); |
Shih-wei Liao | 67e37f1 | 2012-07-27 03:50:34 -0700 | [diff] [blame] | 27 | |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 28 | m_pConfig = new LinkerConfig("arm-none-linux-gnueabi"); |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | // Destructor can do clean-up work that doesn't throw exceptions here. |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 32 | StaticResolverTest::~StaticResolverTest() { |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 33 | delete m_pResolver; |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 34 | delete m_pConfig; |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | // SetUp() will be called immediately before each test. |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 38 | void StaticResolverTest::SetUp() { |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | // TearDown() will be called immediately after each test. |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 42 | void StaticResolverTest::TearDown() { |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | //==========================================================================// |
| 46 | // Testcases |
| 47 | // |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 48 | TEST_F(StaticResolverTest, MDEF) { |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 49 | ResolveInfo* old_sym = ResolveInfo::Create("abc"); |
| 50 | ResolveInfo* new_sym = ResolveInfo::Create("abc"); |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 51 | new_sym->setDesc(ResolveInfo::Define); |
| 52 | old_sym->setDesc(ResolveInfo::Define); |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 53 | ASSERT_TRUE(mcld::ResolveInfo::Define == new_sym->desc()); |
| 54 | ASSERT_TRUE(mcld::ResolveInfo::Define == old_sym->desc()); |
| 55 | ASSERT_TRUE(mcld::ResolveInfo::define_flag == new_sym->info()); |
| 56 | ASSERT_TRUE(mcld::ResolveInfo::define_flag == old_sym->info()); |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 57 | bool override = true; |
Stephen Hines | 87f3465 | 2014-02-14 18:00:16 -0800 | [diff] [blame] | 58 | bool result = m_pResolver->resolve(*old_sym, *new_sym, override, 0x0); |
Zonr Chang | affc150 | 2012-07-16 14:28:23 +0800 | [diff] [blame] | 59 | ASSERT_TRUE(result); |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 60 | ASSERT_FALSE(override); |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 61 | } |
| 62 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 63 | TEST_F(StaticResolverTest, DynDefAfterDynUndef) { |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 64 | ResolveInfo* old_sym = ResolveInfo::Create("abc"); |
| 65 | ResolveInfo* new_sym = ResolveInfo::Create("abc"); |
Stephen Hines | 551ae4e | 2014-04-24 14:41:24 -0700 | [diff] [blame] | 66 | |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 67 | new_sym->setBinding(ResolveInfo::Global); |
| 68 | old_sym->setBinding(ResolveInfo::Global); |
| 69 | new_sym->setDesc(ResolveInfo::Undefined); |
| 70 | old_sym->setDesc(ResolveInfo::Define); |
| 71 | new_sym->setSource(true); |
| 72 | old_sym->setSource(true); |
| 73 | |
| 74 | new_sym->setSize(0); |
| 75 | |
| 76 | old_sym->setSize(1); |
| 77 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 78 | ASSERT_TRUE(mcld::ResolveInfo::Global == new_sym->binding()); |
| 79 | ASSERT_TRUE(mcld::ResolveInfo::Global == old_sym->binding()); |
| 80 | ASSERT_TRUE(mcld::ResolveInfo::Undefined == new_sym->desc()); |
| 81 | ASSERT_TRUE(mcld::ResolveInfo::Define == old_sym->desc()); |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 82 | |
| 83 | bool override = false; |
Stephen Hines | 87f3465 | 2014-02-14 18:00:16 -0800 | [diff] [blame] | 84 | bool result = m_pResolver->resolve(*old_sym, *new_sym, override, 0x0); |
Zonr Chang | affc150 | 2012-07-16 14:28:23 +0800 | [diff] [blame] | 85 | ASSERT_TRUE(result); |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 86 | ASSERT_FALSE(override); |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 87 | ASSERT_TRUE(1 == old_sym->size()); |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 88 | } |
| 89 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 90 | TEST_F(StaticResolverTest, DynDefAfterDynDef) { |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 91 | ResolveInfo* old_sym = ResolveInfo::Create("abc"); |
| 92 | ResolveInfo* new_sym = ResolveInfo::Create("abc"); |
Stephen Hines | 551ae4e | 2014-04-24 14:41:24 -0700 | [diff] [blame] | 93 | |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 94 | new_sym->setBinding(ResolveInfo::Global); |
| 95 | old_sym->setBinding(ResolveInfo::Global); |
| 96 | new_sym->setDesc(ResolveInfo::Define); |
| 97 | old_sym->setDesc(ResolveInfo::Define); |
| 98 | new_sym->setSource(true); |
| 99 | old_sym->setSource(true); |
| 100 | |
| 101 | new_sym->setSize(0); |
| 102 | |
| 103 | old_sym->setSize(1); |
| 104 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 105 | ASSERT_TRUE(mcld::ResolveInfo::Global == new_sym->binding()); |
| 106 | ASSERT_TRUE(mcld::ResolveInfo::Global == old_sym->binding()); |
| 107 | ASSERT_TRUE(mcld::ResolveInfo::Define == new_sym->desc()); |
| 108 | ASSERT_TRUE(mcld::ResolveInfo::Define == old_sym->desc()); |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 109 | |
| 110 | bool override = false; |
Stephen Hines | 87f3465 | 2014-02-14 18:00:16 -0800 | [diff] [blame] | 111 | bool result = m_pResolver->resolve(*old_sym, *new_sym, override, 0x0); |
Zonr Chang | affc150 | 2012-07-16 14:28:23 +0800 | [diff] [blame] | 112 | ASSERT_TRUE(result); |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 113 | ASSERT_FALSE(override); |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 114 | ASSERT_TRUE(1 == old_sym->size()); |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 115 | } |
| 116 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 117 | TEST_F(StaticResolverTest, DynUndefAfterDynUndef) { |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 118 | ResolveInfo* old_sym = ResolveInfo::Create("abc"); |
| 119 | ResolveInfo* new_sym = ResolveInfo::Create("abc"); |
Stephen Hines | 551ae4e | 2014-04-24 14:41:24 -0700 | [diff] [blame] | 120 | |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 121 | new_sym->setBinding(ResolveInfo::Global); |
| 122 | old_sym->setBinding(ResolveInfo::Global); |
| 123 | new_sym->setDesc(ResolveInfo::Undefined); |
| 124 | old_sym->setDesc(ResolveInfo::Undefined); |
| 125 | new_sym->setSource(true); |
| 126 | old_sym->setSource(true); |
| 127 | |
| 128 | new_sym->setSize(0); |
| 129 | |
| 130 | old_sym->setSize(1); |
| 131 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 132 | ASSERT_TRUE(mcld::ResolveInfo::Global == new_sym->binding()); |
| 133 | ASSERT_TRUE(mcld::ResolveInfo::Global == old_sym->binding()); |
| 134 | ASSERT_TRUE(mcld::ResolveInfo::Undefined == new_sym->desc()); |
| 135 | ASSERT_TRUE(mcld::ResolveInfo::Undefined == old_sym->desc()); |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 136 | |
| 137 | bool override = false; |
Stephen Hines | 87f3465 | 2014-02-14 18:00:16 -0800 | [diff] [blame] | 138 | bool result = m_pResolver->resolve(*old_sym, *new_sym, override, 0x0); |
Zonr Chang | affc150 | 2012-07-16 14:28:23 +0800 | [diff] [blame] | 139 | ASSERT_TRUE(result); |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 140 | ASSERT_FALSE(override); |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 141 | ASSERT_TRUE(1 == old_sym->size()); |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 142 | } |
| 143 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 144 | TEST_F(StaticResolverTest, OverrideWeakByGlobal) { |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 145 | ResolveInfo* old_sym = ResolveInfo::Create("abc"); |
| 146 | ResolveInfo* new_sym = ResolveInfo::Create("abc"); |
Stephen Hines | 551ae4e | 2014-04-24 14:41:24 -0700 | [diff] [blame] | 147 | |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 148 | new_sym->setBinding(ResolveInfo::Global); |
| 149 | old_sym->setBinding(ResolveInfo::Weak); |
| 150 | new_sym->setSize(0); |
| 151 | old_sym->setSize(1); |
| 152 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 153 | ASSERT_TRUE(mcld::ResolveInfo::Global == new_sym->binding()); |
| 154 | ASSERT_TRUE(mcld::ResolveInfo::Weak == old_sym->binding()); |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 155 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 156 | ASSERT_TRUE(mcld::ResolveInfo::global_flag == new_sym->info()); |
| 157 | ASSERT_TRUE(mcld::ResolveInfo::weak_flag == old_sym->info()); |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 158 | bool override = false; |
Stephen Hines | 87f3465 | 2014-02-14 18:00:16 -0800 | [diff] [blame] | 159 | bool result = m_pResolver->resolve(*old_sym, *new_sym, override, 0x0); |
Zonr Chang | affc150 | 2012-07-16 14:28:23 +0800 | [diff] [blame] | 160 | ASSERT_TRUE(result); |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 161 | ASSERT_TRUE(override); |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 162 | ASSERT_TRUE(0 == old_sym->size()); |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 163 | } |
| 164 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 165 | TEST_F(StaticResolverTest, DynWeakAfterDynDef) { |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 166 | ResolveInfo* old_sym = ResolveInfo::Create("abc"); |
| 167 | ResolveInfo* new_sym = ResolveInfo::Create("abc"); |
Stephen Hines | 551ae4e | 2014-04-24 14:41:24 -0700 | [diff] [blame] | 168 | |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 169 | old_sym->setBinding(ResolveInfo::Weak); |
| 170 | new_sym->setBinding(ResolveInfo::Global); |
| 171 | |
| 172 | new_sym->setSource(true); |
| 173 | old_sym->setSource(true); |
| 174 | |
| 175 | old_sym->setDesc(ResolveInfo::Define); |
| 176 | new_sym->setDesc(ResolveInfo::Define); |
| 177 | |
| 178 | new_sym->setSize(0); |
| 179 | |
| 180 | old_sym->setSize(1); |
| 181 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 182 | ASSERT_TRUE(mcld::ResolveInfo::Weak == old_sym->binding()); |
| 183 | ASSERT_TRUE(mcld::ResolveInfo::Global == new_sym->binding()); |
| 184 | ASSERT_TRUE(mcld::ResolveInfo::Define == old_sym->desc()); |
| 185 | ASSERT_TRUE(mcld::ResolveInfo::Define == new_sym->desc()); |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 186 | |
| 187 | bool override = false; |
Stephen Hines | 87f3465 | 2014-02-14 18:00:16 -0800 | [diff] [blame] | 188 | bool result = m_pResolver->resolve(*old_sym, *new_sym, override, 0x0); |
Zonr Chang | affc150 | 2012-07-16 14:28:23 +0800 | [diff] [blame] | 189 | ASSERT_TRUE(result); |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 190 | ASSERT_FALSE(override); |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 191 | ASSERT_TRUE(1 == old_sym->size()); |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 192 | } |
| 193 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 194 | TEST_F(StaticResolverTest, MarkByBiggerCommon) { |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 195 | ResolveInfo* old_sym = ResolveInfo::Create("abc"); |
| 196 | ResolveInfo* new_sym = ResolveInfo::Create("abc"); |
Stephen Hines | 551ae4e | 2014-04-24 14:41:24 -0700 | [diff] [blame] | 197 | |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 198 | new_sym->setDesc(ResolveInfo::Common); |
| 199 | old_sym->setDesc(ResolveInfo::Common); |
| 200 | new_sym->setSize(999); |
| 201 | old_sym->setSize(0); |
| 202 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 203 | ASSERT_TRUE(mcld::ResolveInfo::Common == new_sym->desc()); |
| 204 | ASSERT_TRUE(mcld::ResolveInfo::Common == old_sym->desc()); |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 205 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 206 | ASSERT_TRUE(mcld::ResolveInfo::common_flag == new_sym->info()); |
| 207 | ASSERT_TRUE(mcld::ResolveInfo::common_flag == old_sym->info()); |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 208 | bool override = true; |
Stephen Hines | 87f3465 | 2014-02-14 18:00:16 -0800 | [diff] [blame] | 209 | bool result = m_pResolver->resolve(*old_sym, *new_sym, override, 0x0); |
Zonr Chang | affc150 | 2012-07-16 14:28:23 +0800 | [diff] [blame] | 210 | ASSERT_TRUE(result); |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 211 | ASSERT_FALSE(override); |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 212 | ASSERT_TRUE(999 == old_sym->size()); |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 213 | } |
| 214 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 215 | TEST_F(StaticResolverTest, OverrideByBiggerCommon) { |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 216 | ResolveInfo* old_sym = ResolveInfo::Create("abc"); |
| 217 | ResolveInfo* new_sym = ResolveInfo::Create("abc"); |
Stephen Hines | 551ae4e | 2014-04-24 14:41:24 -0700 | [diff] [blame] | 218 | |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 219 | new_sym->setDesc(ResolveInfo::Common); |
| 220 | old_sym->setDesc(ResolveInfo::Common); |
| 221 | old_sym->setBinding(ResolveInfo::Weak); |
| 222 | new_sym->setSize(999); |
| 223 | old_sym->setSize(0); |
| 224 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 225 | ASSERT_TRUE(ResolveInfo::Common == new_sym->desc()); |
| 226 | ASSERT_TRUE(ResolveInfo::Common == old_sym->desc()); |
| 227 | ASSERT_TRUE(ResolveInfo::Weak == old_sym->binding()); |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 228 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 229 | ASSERT_TRUE(ResolveInfo::common_flag == new_sym->info()); |
| 230 | ASSERT_TRUE((ResolveInfo::weak_flag | ResolveInfo::common_flag) == |
| 231 | old_sym->info()); |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 232 | |
| 233 | bool override = false; |
Stephen Hines | 87f3465 | 2014-02-14 18:00:16 -0800 | [diff] [blame] | 234 | bool result = m_pResolver->resolve(*old_sym, *new_sym, override, 0x0); |
Zonr Chang | affc150 | 2012-07-16 14:28:23 +0800 | [diff] [blame] | 235 | ASSERT_TRUE(result); |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 236 | ASSERT_TRUE(override); |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 237 | ASSERT_TRUE(999 == old_sym->size()); |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 238 | } |
| 239 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 240 | TEST_F(StaticResolverTest, OverrideCommonByDefine) { |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 241 | ResolveInfo* old_sym = ResolveInfo::Create("abc"); |
| 242 | ResolveInfo* new_sym = ResolveInfo::Create("abc"); |
Stephen Hines | 551ae4e | 2014-04-24 14:41:24 -0700 | [diff] [blame] | 243 | |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 244 | old_sym->setDesc(ResolveInfo::Common); |
| 245 | old_sym->setSize(0); |
| 246 | |
| 247 | new_sym->setDesc(ResolveInfo::Define); |
| 248 | new_sym->setSize(999); |
| 249 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 250 | ASSERT_TRUE(ResolveInfo::Define == new_sym->desc()); |
| 251 | ASSERT_TRUE(ResolveInfo::Common == old_sym->desc()); |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 252 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 253 | ASSERT_TRUE(ResolveInfo::define_flag == new_sym->info()); |
| 254 | ASSERT_TRUE(ResolveInfo::common_flag == old_sym->info()); |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 255 | |
| 256 | bool override = false; |
Stephen Hines | 87f3465 | 2014-02-14 18:00:16 -0800 | [diff] [blame] | 257 | bool result = m_pResolver->resolve(*old_sym, *new_sym, override, 0x0); |
Zonr Chang | affc150 | 2012-07-16 14:28:23 +0800 | [diff] [blame] | 258 | ASSERT_TRUE(result); |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 259 | ASSERT_TRUE(override); |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 260 | ASSERT_TRUE(999 == old_sym->size()); |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 261 | } |
| 262 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 263 | TEST_F(StaticResolverTest, SetUpDesc) { |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 264 | ResolveInfo* sym = ResolveInfo::Create("abc"); |
Stephen Hines | 551ae4e | 2014-04-24 14:41:24 -0700 | [diff] [blame] | 265 | |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 266 | sym->setIsSymbol(true); |
| 267 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 268 | // ASSERT_FALSE( sym->isSymbol() ); |
| 269 | ASSERT_TRUE(sym->isSymbol()); |
| 270 | ASSERT_TRUE(sym->isGlobal()); |
| 271 | ASSERT_FALSE(sym->isWeak()); |
| 272 | ASSERT_FALSE(sym->isLocal()); |
| 273 | ASSERT_FALSE(sym->isDefine()); |
| 274 | ASSERT_TRUE(sym->isUndef()); |
| 275 | ASSERT_FALSE(sym->isDyn()); |
| 276 | ASSERT_FALSE(sym->isCommon()); |
| 277 | ASSERT_FALSE(sym->isIndirect()); |
| 278 | ASSERT_TRUE(ResolveInfo::NoType == sym->type()); |
| 279 | ASSERT_TRUE(0 == sym->desc()); |
| 280 | ASSERT_TRUE(0 == sym->binding()); |
| 281 | ASSERT_TRUE(0 == sym->other()); |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 282 | |
| 283 | sym->setIsSymbol(false); |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 284 | ASSERT_FALSE(sym->isSymbol()); |
| 285 | // ASSERT_TRUE( sym->isSymbol() ); |
| 286 | ASSERT_TRUE(sym->isGlobal()); |
| 287 | ASSERT_FALSE(sym->isWeak()); |
| 288 | ASSERT_FALSE(sym->isLocal()); |
| 289 | ASSERT_FALSE(sym->isDefine()); |
| 290 | ASSERT_TRUE(sym->isUndef()); |
| 291 | ASSERT_FALSE(sym->isDyn()); |
| 292 | ASSERT_FALSE(sym->isCommon()); |
| 293 | ASSERT_FALSE(sym->isIndirect()); |
| 294 | ASSERT_TRUE(ResolveInfo::NoType == sym->type()); |
| 295 | ASSERT_TRUE(0 == sym->desc()); |
| 296 | ASSERT_TRUE(0 == sym->binding()); |
| 297 | ASSERT_TRUE(0 == sym->other()); |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 298 | |
| 299 | sym->setDesc(ResolveInfo::Define); |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 300 | ASSERT_FALSE(sym->isSymbol()); |
| 301 | // ASSERT_TRUE( sym->isSymbol() ); |
| 302 | ASSERT_TRUE(sym->isGlobal()); |
| 303 | ASSERT_FALSE(sym->isWeak()); |
| 304 | ASSERT_FALSE(sym->isLocal()); |
| 305 | ASSERT_TRUE(sym->isDefine()); |
| 306 | ASSERT_FALSE(sym->isUndef()); |
| 307 | ASSERT_FALSE(sym->isDyn()); |
| 308 | ASSERT_FALSE(sym->isCommon()); |
| 309 | ASSERT_FALSE(sym->isIndirect()); |
| 310 | ASSERT_TRUE(ResolveInfo::NoType == sym->type()); |
| 311 | ASSERT_TRUE(ResolveInfo::Define == sym->desc()); |
| 312 | ASSERT_TRUE(0 == sym->binding()); |
| 313 | ASSERT_TRUE(0 == sym->other()); |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 314 | |
| 315 | sym->setDesc(ResolveInfo::Common); |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 316 | ASSERT_FALSE(sym->isSymbol()); |
| 317 | // ASSERT_TRUE( sym->isSymbol() ); |
| 318 | ASSERT_TRUE(sym->isGlobal()); |
| 319 | ASSERT_FALSE(sym->isWeak()); |
| 320 | ASSERT_FALSE(sym->isLocal()); |
| 321 | ASSERT_FALSE(sym->isDyn()); |
| 322 | ASSERT_FALSE(sym->isDefine()); |
| 323 | ASSERT_FALSE(sym->isUndef()); |
| 324 | ASSERT_TRUE(sym->isCommon()); |
| 325 | ASSERT_FALSE(sym->isIndirect()); |
| 326 | ASSERT_TRUE(ResolveInfo::NoType == sym->type()); |
| 327 | ASSERT_TRUE(ResolveInfo::Common == sym->desc()); |
| 328 | ASSERT_TRUE(0 == sym->binding()); |
| 329 | ASSERT_TRUE(0 == sym->other()); |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 330 | |
| 331 | sym->setDesc(ResolveInfo::Indirect); |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 332 | ASSERT_FALSE(sym->isSymbol()); |
| 333 | ASSERT_TRUE(sym->isGlobal()); |
| 334 | ASSERT_FALSE(sym->isWeak()); |
| 335 | ASSERT_FALSE(sym->isLocal()); |
| 336 | ASSERT_FALSE(sym->isDyn()); |
| 337 | ASSERT_FALSE(sym->isDefine()); |
| 338 | ASSERT_FALSE(sym->isUndef()); |
| 339 | ASSERT_FALSE(sym->isCommon()); |
| 340 | ASSERT_TRUE(sym->isIndirect()); |
| 341 | ASSERT_TRUE(ResolveInfo::NoType == sym->type()); |
| 342 | ASSERT_TRUE(ResolveInfo::Indirect == sym->desc()); |
| 343 | ASSERT_TRUE(0 == sym->binding()); |
| 344 | ASSERT_TRUE(0 == sym->other()); |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 345 | |
| 346 | sym->setDesc(ResolveInfo::Undefined); |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 347 | ASSERT_FALSE(sym->isSymbol()); |
| 348 | ASSERT_TRUE(sym->isGlobal()); |
| 349 | ASSERT_FALSE(sym->isWeak()); |
| 350 | ASSERT_FALSE(sym->isLocal()); |
| 351 | ASSERT_FALSE(sym->isDyn()); |
| 352 | ASSERT_TRUE(sym->isUndef()); |
| 353 | ASSERT_FALSE(sym->isDefine()); |
| 354 | ASSERT_FALSE(sym->isCommon()); |
| 355 | ASSERT_FALSE(sym->isIndirect()); |
| 356 | ASSERT_TRUE(ResolveInfo::NoType == sym->type()); |
| 357 | ASSERT_TRUE(0 == sym->desc()); |
| 358 | ASSERT_TRUE(0 == sym->binding()); |
| 359 | ASSERT_TRUE(0 == sym->other()); |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 360 | } |
| 361 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 362 | TEST_F(StaticResolverTest, SetUpBinding) { |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 363 | ResolveInfo* sym = ResolveInfo::Create("abc"); |
Stephen Hines | 551ae4e | 2014-04-24 14:41:24 -0700 | [diff] [blame] | 364 | |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 365 | sym->setIsSymbol(true); |
| 366 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 367 | // ASSERT_FALSE( sym->isSymbol() ); |
| 368 | ASSERT_TRUE(sym->isSymbol()); |
| 369 | ASSERT_TRUE(sym->isGlobal()); |
| 370 | ASSERT_FALSE(sym->isWeak()); |
| 371 | ASSERT_FALSE(sym->isLocal()); |
| 372 | ASSERT_FALSE(sym->isDefine()); |
| 373 | ASSERT_TRUE(sym->isUndef()); |
| 374 | ASSERT_FALSE(sym->isDyn()); |
| 375 | ASSERT_FALSE(sym->isCommon()); |
| 376 | ASSERT_FALSE(sym->isIndirect()); |
| 377 | ASSERT_TRUE(ResolveInfo::NoType == sym->type()); |
| 378 | ASSERT_TRUE(0 == sym->desc()); |
| 379 | ASSERT_TRUE(0 == sym->binding()); |
| 380 | ASSERT_TRUE(0 == sym->other()); |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 381 | |
| 382 | sym->setBinding(ResolveInfo::Global); |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 383 | ASSERT_TRUE(sym->isSymbol()); |
| 384 | ASSERT_TRUE(sym->isGlobal()); |
| 385 | ASSERT_FALSE(sym->isWeak()); |
| 386 | ASSERT_FALSE(sym->isLocal()); |
| 387 | ASSERT_FALSE(sym->isDefine()); |
| 388 | ASSERT_TRUE(sym->isUndef()); |
| 389 | ASSERT_FALSE(sym->isDyn()); |
| 390 | ASSERT_FALSE(sym->isCommon()); |
| 391 | ASSERT_FALSE(sym->isIndirect()); |
| 392 | ASSERT_TRUE(ResolveInfo::NoType == sym->type()); |
| 393 | ASSERT_TRUE(0 == sym->desc()); |
| 394 | ASSERT_TRUE(ResolveInfo::Global == sym->binding()); |
| 395 | ASSERT_TRUE(0 == sym->other()); |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 396 | |
| 397 | sym->setBinding(ResolveInfo::Weak); |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 398 | ASSERT_TRUE(sym->isSymbol()); |
| 399 | ASSERT_FALSE(sym->isGlobal()); |
| 400 | ASSERT_TRUE(sym->isWeak()); |
| 401 | ASSERT_FALSE(sym->isLocal()); |
| 402 | ASSERT_FALSE(sym->isDyn()); |
| 403 | ASSERT_FALSE(sym->isDefine()); |
| 404 | ASSERT_TRUE(sym->isUndef()); |
| 405 | ASSERT_FALSE(sym->isCommon()); |
| 406 | ASSERT_FALSE(sym->isIndirect()); |
| 407 | ASSERT_TRUE(ResolveInfo::NoType == sym->type()); |
| 408 | ASSERT_TRUE(0 == sym->desc()); |
| 409 | ASSERT_TRUE(ResolveInfo::Weak == sym->binding()); |
| 410 | ASSERT_TRUE(0 == sym->other()); |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 411 | |
| 412 | sym->setBinding(ResolveInfo::Local); |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 413 | ASSERT_TRUE(sym->isSymbol()); |
| 414 | ASSERT_FALSE(sym->isGlobal()); |
| 415 | ASSERT_FALSE(sym->isWeak()); |
| 416 | ASSERT_TRUE(sym->isLocal()); |
| 417 | ASSERT_FALSE(sym->isDyn()); |
| 418 | ASSERT_FALSE(sym->isDefine()); |
| 419 | ASSERT_TRUE(sym->isUndef()); |
| 420 | ASSERT_FALSE(sym->isCommon()); |
| 421 | ASSERT_FALSE(sym->isIndirect()); |
| 422 | ASSERT_TRUE(ResolveInfo::NoType == sym->type()); |
| 423 | ASSERT_TRUE(0 == sym->desc()); |
| 424 | ASSERT_TRUE(ResolveInfo::Local == sym->binding()); |
| 425 | ASSERT_TRUE(0 == sym->other()); |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 426 | } |