OLD | NEW |
1 // Copyright (c) 2010, Google Inc. | 1 // Copyright (c) 2010, Google Inc. |
2 // All rights reserved. | 2 // All rights reserved. |
3 // | 3 // |
4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
6 // met: | 6 // met: |
7 // | 7 // |
8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
(...skipping 15 matching lines...) Expand all Loading... |
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 | 29 |
30 // Unit tests for FileID | 30 // Unit tests for FileID |
31 | 31 |
32 #include <elf.h> | 32 #include <elf.h> |
33 #include <stdlib.h> | 33 #include <stdlib.h> |
34 | 34 |
35 #include <string> | 35 #include <string> |
| 36 #include <vector> |
36 | 37 |
37 #include "common/linux/elf_gnu_compat.h" | 38 #include "common/linux/elf_gnu_compat.h" |
38 #include "common/linux/elfutils.h" | 39 #include "common/linux/elfutils.h" |
39 #include "common/linux/file_id.h" | 40 #include "common/linux/file_id.h" |
40 #include "common/linux/safe_readlink.h" | 41 #include "common/linux/safe_readlink.h" |
41 #include "common/linux/synth_elf.h" | 42 #include "common/linux/synth_elf.h" |
42 #include "common/test_assembler.h" | 43 #include "common/test_assembler.h" |
43 #include "common/tests/auto_tempdir.h" | 44 #include "common/tests/auto_tempdir.h" |
44 #include "common/using_std_string.h" | 45 #include "common/using_std_string.h" |
45 #include "breakpad_googletest_includes.h" | 46 #include "breakpad_googletest_includes.h" |
46 | 47 |
47 using namespace google_breakpad; | 48 using namespace google_breakpad; |
48 using google_breakpad::ElfClass32; | |
49 using google_breakpad::ElfClass64; | |
50 using google_breakpad::SafeReadLink; | |
51 using google_breakpad::synth_elf::ELF; | 49 using google_breakpad::synth_elf::ELF; |
52 using google_breakpad::synth_elf::Notes; | 50 using google_breakpad::synth_elf::Notes; |
53 using google_breakpad::test_assembler::kLittleEndian; | 51 using google_breakpad::test_assembler::kLittleEndian; |
54 using google_breakpad::test_assembler::Section; | 52 using google_breakpad::test_assembler::Section; |
| 53 using std::vector; |
55 using ::testing::Types; | 54 using ::testing::Types; |
56 | 55 |
57 namespace { | 56 namespace { |
58 | 57 |
59 // Simply calling Section::Append(size, byte) produces a uninteresting pattern | 58 // Simply calling Section::Append(size, byte) produces a uninteresting pattern |
60 // that tends to get hashed to 0000...0000. This populates the section with | 59 // that tends to get hashed to 0000...0000. This populates the section with |
61 // data to produce better hashes. | 60 // data to produce better hashes. |
62 void PopulateSection(Section* section, int size, int prime_number) { | 61 void PopulateSection(Section* section, int size, int prime_number) { |
63 for (int i = 0; i < size; i++) | 62 for (int i = 0; i < size; i++) |
64 section->Append(1, (i % prime_number) % 256); | 63 section->Append(1, (i % prime_number) % 256); |
65 } | 64 } |
66 | 65 |
| 66 typedef wasteful_vector<uint8_t> id_vector; |
| 67 |
67 } // namespace | 68 } // namespace |
68 | 69 |
69 #ifndef __ANDROID__ | 70 #ifndef __ANDROID__ |
70 // This test is disabled on Android: It will always fail, since there is no | 71 // This test is disabled on Android: It will always fail, since there is no |
71 // 'strip' binary installed on test devices. | 72 // 'strip' binary installed on test devices. |
72 TEST(FileIDStripTest, StripSelf) { | 73 TEST(FileIDStripTest, StripSelf) { |
73 // Calculate the File ID of this binary using | 74 // Calculate the File ID of this binary using |
74 // FileID::ElfFileIdentifier, then make a copy of this binary, | 75 // FileID::ElfFileIdentifier, then make a copy of this binary, |
75 // strip it, and ensure that the result is the same. | 76 // strip it, and ensure that the result is the same. |
76 char exe_name[PATH_MAX]; | 77 char exe_name[PATH_MAX]; |
77 ASSERT_TRUE(SafeReadLink("/proc/self/exe", exe_name)); | 78 ASSERT_TRUE(SafeReadLink("/proc/self/exe", exe_name)); |
78 | 79 |
79 // copy our binary to a temp file, and strip it | 80 // copy our binary to a temp file, and strip it |
80 AutoTempDir temp_dir; | 81 AutoTempDir temp_dir; |
81 string templ = temp_dir.path() + "/file-id-unittest"; | 82 string templ = temp_dir.path() + "/file-id-unittest"; |
82 char cmdline[4096]; | 83 char cmdline[4096]; |
83 sprintf(cmdline, "cp \"%s\" \"%s\"", exe_name, templ.c_str()); | 84 sprintf(cmdline, "cp \"%s\" \"%s\"", exe_name, templ.c_str()); |
84 ASSERT_EQ(0, system(cmdline)) << "Failed to execute: " << cmdline; | 85 ASSERT_EQ(0, system(cmdline)) << "Failed to execute: " << cmdline; |
85 sprintf(cmdline, "chmod u+w \"%s\"", templ.c_str()); | 86 sprintf(cmdline, "chmod u+w \"%s\"", templ.c_str()); |
86 ASSERT_EQ(0, system(cmdline)) << "Failed to execute: " << cmdline; | 87 ASSERT_EQ(0, system(cmdline)) << "Failed to execute: " << cmdline; |
87 sprintf(cmdline, "strip \"%s\"", templ.c_str()); | 88 sprintf(cmdline, "strip \"%s\"", templ.c_str()); |
88 ASSERT_EQ(0, system(cmdline)) << "Failed to execute: " << cmdline; | 89 ASSERT_EQ(0, system(cmdline)) << "Failed to execute: " << cmdline; |
89 | 90 |
90 uint8_t identifier1[sizeof(MDGUID)]; | 91 PageAllocator allocator; |
91 uint8_t identifier2[sizeof(MDGUID)]; | 92 id_vector identifier1(&allocator, kDefaultBuildIdSize); |
| 93 id_vector identifier2(&allocator, kDefaultBuildIdSize); |
| 94 |
92 FileID fileid1(exe_name); | 95 FileID fileid1(exe_name); |
93 EXPECT_TRUE(fileid1.ElfFileIdentifier(identifier1)); | 96 EXPECT_TRUE(fileid1.ElfFileIdentifier(identifier1)); |
94 FileID fileid2(templ.c_str()); | 97 FileID fileid2(templ.c_str()); |
95 EXPECT_TRUE(fileid2.ElfFileIdentifier(identifier2)); | 98 EXPECT_TRUE(fileid2.ElfFileIdentifier(identifier2)); |
96 char identifier_string1[37]; | 99 |
97 char identifier_string2[37]; | 100 string identifier_string1 = |
98 FileID::ConvertIdentifierToString(identifier1, identifier_string1, | 101 FileID::ConvertIdentifierToUUIDString(identifier1); |
99 37); | 102 string identifier_string2 = |
100 FileID::ConvertIdentifierToString(identifier2, identifier_string2, | 103 FileID::ConvertIdentifierToUUIDString(identifier2); |
101 37); | 104 EXPECT_EQ(identifier_string1, identifier_string2); |
102 EXPECT_STREQ(identifier_string1, identifier_string2); | |
103 } | 105 } |
104 #endif // !__ANDROID__ | 106 #endif // !__ANDROID__ |
105 | 107 |
106 template<typename ElfClass> | 108 template<typename ElfClass> |
107 class FileIDTest : public testing::Test { | 109 class FileIDTest : public testing::Test { |
108 public: | 110 public: |
109 void GetElfContents(ELF& elf) { | 111 void GetElfContents(ELF& elf) { |
110 string contents; | 112 string contents; |
111 ASSERT_TRUE(elf.GetContents(&contents)); | 113 ASSERT_TRUE(elf.GetContents(&contents)); |
112 ASSERT_LT(0U, contents.size()); | 114 ASSERT_LT(0U, contents.size()); |
113 | 115 |
114 elfdata_v.clear(); | 116 elfdata_v.clear(); |
115 elfdata_v.insert(elfdata_v.begin(), contents.begin(), contents.end()); | 117 elfdata_v.insert(elfdata_v.begin(), contents.begin(), contents.end()); |
116 elfdata = &elfdata_v[0]; | 118 elfdata = &elfdata_v[0]; |
117 } | 119 } |
118 | 120 |
| 121 id_vector make_vector() { |
| 122 return id_vector(&allocator, kDefaultBuildIdSize); |
| 123 } |
| 124 |
| 125 template<size_t N> |
| 126 string get_file_id(const uint8_t (&data)[N]) { |
| 127 id_vector expected_identifier(make_vector()); |
| 128 expected_identifier.insert(expected_identifier.end(), |
| 129 &data[0], |
| 130 data + N); |
| 131 return FileID::ConvertIdentifierToUUIDString(expected_identifier); |
| 132 } |
| 133 |
119 vector<uint8_t> elfdata_v; | 134 vector<uint8_t> elfdata_v; |
120 uint8_t* elfdata; | 135 uint8_t* elfdata; |
| 136 PageAllocator allocator; |
121 }; | 137 }; |
122 | 138 |
123 typedef Types<ElfClass32, ElfClass64> ElfClasses; | 139 typedef Types<ElfClass32, ElfClass64> ElfClasses; |
124 | 140 |
125 TYPED_TEST_CASE(FileIDTest, ElfClasses); | 141 TYPED_TEST_CASE(FileIDTest, ElfClasses); |
126 | 142 |
127 TYPED_TEST(FileIDTest, ElfClass) { | 143 TYPED_TEST(FileIDTest, ElfClass) { |
128 uint8_t identifier[sizeof(MDGUID)]; | |
129 const char expected_identifier_string[] = | 144 const char expected_identifier_string[] = |
130 "80808080-8080-0000-0000-008080808080"; | 145 "80808080808000000000008080808080"; |
131 char identifier_string[sizeof(expected_identifier_string)]; | |
132 const size_t kTextSectionSize = 128; | 146 const size_t kTextSectionSize = 128; |
133 | 147 |
134 ELF elf(EM_386, TypeParam::kClass, kLittleEndian); | 148 ELF elf(EM_386, TypeParam::kClass, kLittleEndian); |
135 Section text(kLittleEndian); | 149 Section text(kLittleEndian); |
136 for (size_t i = 0; i < kTextSectionSize; ++i) { | 150 for (size_t i = 0; i < kTextSectionSize; ++i) { |
137 text.D8(i * 3); | 151 text.D8(i * 3); |
138 } | 152 } |
139 elf.AddSection(".text", text, SHT_PROGBITS); | 153 elf.AddSection(".text", text, SHT_PROGBITS); |
140 elf.Finish(); | 154 elf.Finish(); |
141 this->GetElfContents(elf); | 155 this->GetElfContents(elf); |
142 | 156 |
| 157 id_vector identifier(this->make_vector()); |
143 EXPECT_TRUE(FileID::ElfFileIdentifierFromMappedFile(this->elfdata, | 158 EXPECT_TRUE(FileID::ElfFileIdentifierFromMappedFile(this->elfdata, |
144 identifier)); | 159 identifier)); |
145 | 160 |
146 FileID::ConvertIdentifierToString(identifier, identifier_string, | 161 string identifier_string = FileID::ConvertIdentifierToUUIDString(identifier); |
147 sizeof(identifier_string)); | 162 EXPECT_EQ(expected_identifier_string, identifier_string); |
148 EXPECT_STREQ(expected_identifier_string, identifier_string); | |
149 } | 163 } |
150 | 164 |
151 TYPED_TEST(FileIDTest, BuildID) { | 165 TYPED_TEST(FileIDTest, BuildID) { |
152 const uint8_t kExpectedIdentifier[sizeof(MDGUID)] = | 166 const uint8_t kExpectedIdentifierBytes[] = |
153 {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | 167 {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
154 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}; | 168 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, |
155 char expected_identifier_string[] = | 169 0x10, 0x11, 0x12, 0x13}; |
156 "00000000-0000-0000-0000-000000000000"; | 170 const string expected_identifier_string = |
157 FileID::ConvertIdentifierToString(kExpectedIdentifier, | 171 this->get_file_id(kExpectedIdentifierBytes); |
158 expected_identifier_string, | |
159 sizeof(expected_identifier_string)); | |
160 | |
161 uint8_t identifier[sizeof(MDGUID)]; | |
162 char identifier_string[sizeof(expected_identifier_string)]; | |
163 | 172 |
164 ELF elf(EM_386, TypeParam::kClass, kLittleEndian); | 173 ELF elf(EM_386, TypeParam::kClass, kLittleEndian); |
165 Section text(kLittleEndian); | 174 Section text(kLittleEndian); |
166 text.Append(4096, 0); | 175 text.Append(4096, 0); |
167 elf.AddSection(".text", text, SHT_PROGBITS); | 176 elf.AddSection(".text", text, SHT_PROGBITS); |
168 Notes notes(kLittleEndian); | 177 Notes notes(kLittleEndian); |
169 notes.AddNote(NT_GNU_BUILD_ID, "GNU", kExpectedIdentifier, | 178 notes.AddNote(NT_GNU_BUILD_ID, "GNU", kExpectedIdentifierBytes, |
170 sizeof(kExpectedIdentifier)); | 179 sizeof(kExpectedIdentifierBytes)); |
171 elf.AddSection(".note.gnu.build-id", notes, SHT_NOTE); | 180 elf.AddSection(".note.gnu.build-id", notes, SHT_NOTE); |
172 elf.Finish(); | 181 elf.Finish(); |
173 this->GetElfContents(elf); | 182 this->GetElfContents(elf); |
174 | 183 |
| 184 id_vector identifier(this->make_vector()); |
175 EXPECT_TRUE(FileID::ElfFileIdentifierFromMappedFile(this->elfdata, | 185 EXPECT_TRUE(FileID::ElfFileIdentifierFromMappedFile(this->elfdata, |
176 identifier)); | 186 identifier)); |
| 187 EXPECT_EQ(sizeof(kExpectedIdentifierBytes), identifier.size()); |
177 | 188 |
178 FileID::ConvertIdentifierToString(identifier, identifier_string, | 189 string identifier_string = FileID::ConvertIdentifierToUUIDString(identifier); |
179 sizeof(identifier_string)); | 190 EXPECT_EQ(expected_identifier_string, identifier_string); |
180 EXPECT_STREQ(expected_identifier_string, identifier_string); | 191 } |
| 192 |
| 193 // Test that a build id note with fewer bytes than usual is handled. |
| 194 TYPED_TEST(FileIDTest, BuildIDShort) { |
| 195 const uint8_t kExpectedIdentifierBytes[] = |
| 196 {0x00, 0x01, 0x02, 0x03}; |
| 197 const string expected_identifier_string = |
| 198 this->get_file_id(kExpectedIdentifierBytes); |
| 199 |
| 200 ELF elf(EM_386, TypeParam::kClass, kLittleEndian); |
| 201 Section text(kLittleEndian); |
| 202 text.Append(4096, 0); |
| 203 elf.AddSection(".text", text, SHT_PROGBITS); |
| 204 Notes notes(kLittleEndian); |
| 205 notes.AddNote(NT_GNU_BUILD_ID, "GNU", kExpectedIdentifierBytes, |
| 206 sizeof(kExpectedIdentifierBytes)); |
| 207 elf.AddSection(".note.gnu.build-id", notes, SHT_NOTE); |
| 208 elf.Finish(); |
| 209 this->GetElfContents(elf); |
| 210 |
| 211 id_vector identifier(this->make_vector()); |
| 212 EXPECT_TRUE(FileID::ElfFileIdentifierFromMappedFile(this->elfdata, |
| 213 identifier)); |
| 214 EXPECT_EQ(sizeof(kExpectedIdentifierBytes), identifier.size()); |
| 215 |
| 216 string identifier_string = FileID::ConvertIdentifierToUUIDString(identifier); |
| 217 EXPECT_EQ(expected_identifier_string, identifier_string); |
| 218 } |
| 219 |
| 220 // Test that a build id note with more bytes than usual is handled. |
| 221 TYPED_TEST(FileIDTest, BuildIDLong) { |
| 222 const uint8_t kExpectedIdentifierBytes[] = |
| 223 {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 224 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, |
| 225 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, |
| 226 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F}; |
| 227 const string expected_identifier_string = |
| 228 this->get_file_id(kExpectedIdentifierBytes); |
| 229 |
| 230 ELF elf(EM_386, TypeParam::kClass, kLittleEndian); |
| 231 Section text(kLittleEndian); |
| 232 text.Append(4096, 0); |
| 233 elf.AddSection(".text", text, SHT_PROGBITS); |
| 234 Notes notes(kLittleEndian); |
| 235 notes.AddNote(NT_GNU_BUILD_ID, "GNU", kExpectedIdentifierBytes, |
| 236 sizeof(kExpectedIdentifierBytes)); |
| 237 elf.AddSection(".note.gnu.build-id", notes, SHT_NOTE); |
| 238 elf.Finish(); |
| 239 this->GetElfContents(elf); |
| 240 |
| 241 id_vector identifier(this->make_vector()); |
| 242 EXPECT_TRUE(FileID::ElfFileIdentifierFromMappedFile(this->elfdata, |
| 243 identifier)); |
| 244 EXPECT_EQ(sizeof(kExpectedIdentifierBytes), identifier.size()); |
| 245 |
| 246 string identifier_string = FileID::ConvertIdentifierToUUIDString(identifier); |
| 247 EXPECT_EQ(expected_identifier_string, identifier_string); |
181 } | 248 } |
182 | 249 |
183 TYPED_TEST(FileIDTest, BuildIDPH) { | 250 TYPED_TEST(FileIDTest, BuildIDPH) { |
184 const uint8_t kExpectedIdentifier[sizeof(MDGUID)] = | 251 const uint8_t kExpectedIdentifierBytes[] = |
185 {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | 252 {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
186 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}; | 253 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, |
187 char expected_identifier_string[] = | 254 0x10, 0x11, 0x12, 0x13}; |
188 "00000000-0000-0000-0000-000000000000"; | 255 const string expected_identifier_string = |
189 FileID::ConvertIdentifierToString(kExpectedIdentifier, | 256 this->get_file_id(kExpectedIdentifierBytes); |
190 expected_identifier_string, | |
191 sizeof(expected_identifier_string)); | |
192 | |
193 uint8_t identifier[sizeof(MDGUID)]; | |
194 char identifier_string[sizeof(expected_identifier_string)]; | |
195 | 257 |
196 ELF elf(EM_386, TypeParam::kClass, kLittleEndian); | 258 ELF elf(EM_386, TypeParam::kClass, kLittleEndian); |
197 Section text(kLittleEndian); | 259 Section text(kLittleEndian); |
198 text.Append(4096, 0); | 260 text.Append(4096, 0); |
199 elf.AddSection(".text", text, SHT_PROGBITS); | 261 elf.AddSection(".text", text, SHT_PROGBITS); |
200 Notes notes(kLittleEndian); | 262 Notes notes(kLittleEndian); |
201 notes.AddNote(0, "Linux", | 263 notes.AddNote(0, "Linux", |
202 reinterpret_cast<const uint8_t *>("\0x42\0x02\0\0"), 4); | 264 reinterpret_cast<const uint8_t *>("\0x42\0x02\0\0"), 4); |
203 notes.AddNote(NT_GNU_BUILD_ID, "GNU", kExpectedIdentifier, | 265 notes.AddNote(NT_GNU_BUILD_ID, "GNU", kExpectedIdentifierBytes, |
204 sizeof(kExpectedIdentifier)); | 266 sizeof(kExpectedIdentifierBytes)); |
205 int note_idx = elf.AddSection(".note", notes, SHT_NOTE); | 267 int note_idx = elf.AddSection(".note", notes, SHT_NOTE); |
206 elf.AddSegment(note_idx, note_idx, PT_NOTE); | 268 elf.AddSegment(note_idx, note_idx, PT_NOTE); |
207 elf.Finish(); | 269 elf.Finish(); |
208 this->GetElfContents(elf); | 270 this->GetElfContents(elf); |
209 | 271 |
| 272 id_vector identifier(this->make_vector()); |
210 EXPECT_TRUE(FileID::ElfFileIdentifierFromMappedFile(this->elfdata, | 273 EXPECT_TRUE(FileID::ElfFileIdentifierFromMappedFile(this->elfdata, |
211 identifier)); | 274 identifier)); |
| 275 EXPECT_EQ(sizeof(kExpectedIdentifierBytes), identifier.size()); |
212 | 276 |
213 FileID::ConvertIdentifierToString(identifier, identifier_string, | 277 string identifier_string = FileID::ConvertIdentifierToUUIDString(identifier); |
214 sizeof(identifier_string)); | 278 EXPECT_EQ(expected_identifier_string, identifier_string); |
215 EXPECT_STREQ(expected_identifier_string, identifier_string); | |
216 } | 279 } |
217 | 280 |
218 // Test to make sure two files with different text sections produce | 281 // Test to make sure two files with different text sections produce |
219 // different hashes when not using a build id. | 282 // different hashes when not using a build id. |
220 TYPED_TEST(FileIDTest, UniqueHashes) { | 283 TYPED_TEST(FileIDTest, UniqueHashes) { |
221 char identifier_string_1[] = | |
222 "00000000-0000-0000-0000-000000000000"; | |
223 char identifier_string_2[] = | |
224 "00000000-0000-0000-0000-000000000000"; | |
225 uint8_t identifier_1[sizeof(MDGUID)]; | |
226 uint8_t identifier_2[sizeof(MDGUID)]; | |
227 | |
228 { | 284 { |
229 ELF elf1(EM_386, TypeParam::kClass, kLittleEndian); | 285 ELF elf1(EM_386, TypeParam::kClass, kLittleEndian); |
230 Section foo_1(kLittleEndian); | 286 Section foo_1(kLittleEndian); |
231 PopulateSection(&foo_1, 32, 5); | 287 PopulateSection(&foo_1, 32, 5); |
232 elf1.AddSection(".foo", foo_1, SHT_PROGBITS); | 288 elf1.AddSection(".foo", foo_1, SHT_PROGBITS); |
233 Section text_1(kLittleEndian); | 289 Section text_1(kLittleEndian); |
234 PopulateSection(&text_1, 4096, 17); | 290 PopulateSection(&text_1, 4096, 17); |
235 elf1.AddSection(".text", text_1, SHT_PROGBITS); | 291 elf1.AddSection(".text", text_1, SHT_PROGBITS); |
236 elf1.Finish(); | 292 elf1.Finish(); |
237 this->GetElfContents(elf1); | 293 this->GetElfContents(elf1); |
238 } | 294 } |
239 | 295 |
| 296 id_vector identifier_1(this->make_vector()); |
240 EXPECT_TRUE(FileID::ElfFileIdentifierFromMappedFile(this->elfdata, | 297 EXPECT_TRUE(FileID::ElfFileIdentifierFromMappedFile(this->elfdata, |
241 identifier_1)); | 298 identifier_1)); |
242 FileID::ConvertIdentifierToString(identifier_1, identifier_string_1, | 299 string identifier_string_1 = |
243 sizeof(identifier_string_1)); | 300 FileID::ConvertIdentifierToUUIDString(identifier_1); |
244 | 301 |
245 { | 302 { |
246 ELF elf2(EM_386, TypeParam::kClass, kLittleEndian); | 303 ELF elf2(EM_386, TypeParam::kClass, kLittleEndian); |
247 Section text_2(kLittleEndian); | 304 Section text_2(kLittleEndian); |
248 Section foo_2(kLittleEndian); | 305 Section foo_2(kLittleEndian); |
249 PopulateSection(&foo_2, 32, 5); | 306 PopulateSection(&foo_2, 32, 5); |
250 elf2.AddSection(".foo", foo_2, SHT_PROGBITS); | 307 elf2.AddSection(".foo", foo_2, SHT_PROGBITS); |
251 PopulateSection(&text_2, 4096, 31); | 308 PopulateSection(&text_2, 4096, 31); |
252 elf2.AddSection(".text", text_2, SHT_PROGBITS); | 309 elf2.AddSection(".text", text_2, SHT_PROGBITS); |
253 elf2.Finish(); | 310 elf2.Finish(); |
254 this->GetElfContents(elf2); | 311 this->GetElfContents(elf2); |
255 } | 312 } |
256 | 313 |
| 314 id_vector identifier_2(this->make_vector()); |
257 EXPECT_TRUE(FileID::ElfFileIdentifierFromMappedFile(this->elfdata, | 315 EXPECT_TRUE(FileID::ElfFileIdentifierFromMappedFile(this->elfdata, |
258 identifier_2)); | 316 identifier_2)); |
259 FileID::ConvertIdentifierToString(identifier_2, identifier_string_2, | 317 string identifier_string_2 = |
260 sizeof(identifier_string_2)); | 318 FileID::ConvertIdentifierToUUIDString(identifier_2); |
261 | 319 |
262 EXPECT_STRNE(identifier_string_1, identifier_string_2); | 320 EXPECT_NE(identifier_string_1, identifier_string_2); |
263 } | 321 } |
OLD | NEW |