| OLD | NEW |
| 1 // Copyright (c) 2009, Google Inc. | 1 // Copyright (c) 2009, 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 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 if (!strcmp(mappings[i]->name, kLinuxGateLibraryName)) { | 303 if (!strcmp(mappings[i]->name, kLinuxGateLibraryName)) { |
| 304 found_linux_gate = true; | 304 found_linux_gate = true; |
| 305 index = i; | 305 index = i; |
| 306 break; | 306 break; |
| 307 } | 307 } |
| 308 } | 308 } |
| 309 ASSERT_TRUE(found_linux_gate); | 309 ASSERT_TRUE(found_linux_gate); |
| 310 | 310 |
| 311 // Need to suspend the child so ptrace actually works. | 311 // Need to suspend the child so ptrace actually works. |
| 312 ASSERT_TRUE(dumper.ThreadsSuspend()); | 312 ASSERT_TRUE(dumper.ThreadsSuspend()); |
| 313 uint8_t identifier[sizeof(MDGUID)]; | 313 uint8_t identifier[kMaxBuildID]; |
| 314 size_t identifier_length; |
| 314 ASSERT_TRUE(dumper.ElfFileIdentifierForMapping(*mappings[index], | 315 ASSERT_TRUE(dumper.ElfFileIdentifierForMapping(*mappings[index], |
| 315 true, | 316 true, |
| 316 index, | 317 index, |
| 317 identifier)); | 318 identifier, |
| 318 uint8_t empty_identifier[sizeof(MDGUID)]; | 319 &identifier_length)); |
| 320 uint8_t empty_identifier[kMaxBuildID]; |
| 319 memset(empty_identifier, 0, sizeof(empty_identifier)); | 321 memset(empty_identifier, 0, sizeof(empty_identifier)); |
| 320 EXPECT_NE(0, memcmp(empty_identifier, identifier, sizeof(identifier))); | 322 EXPECT_NE(0, memcmp(empty_identifier, identifier, sizeof(identifier))); |
| 321 EXPECT_TRUE(dumper.ThreadsResume()); | 323 EXPECT_TRUE(dumper.ThreadsResume()); |
| 322 } | 324 } |
| 323 #endif | 325 #endif |
| 324 | 326 |
| 325 TEST_F(LinuxPtraceDumperChildTest, FileIDsMatch) { | 327 TEST_F(LinuxPtraceDumperChildTest, FileIDsMatch) { |
| 326 // Calculate the File ID of our binary using both | 328 // Calculate the File ID of our binary using both |
| 327 // FileID::ElfFileIdentifier and LinuxDumper::ElfFileIdentifierForMapping | 329 // FileID::ElfFileIdentifier and LinuxDumper::ElfFileIdentifierForMapping |
| 328 // and ensure that we get the same result from both. | 330 // and ensure that we get the same result from both. |
| 329 char exe_name[PATH_MAX]; | 331 char exe_name[PATH_MAX]; |
| 330 ASSERT_TRUE(SafeReadLink("/proc/self/exe", exe_name)); | 332 ASSERT_TRUE(SafeReadLink("/proc/self/exe", exe_name)); |
| 331 | 333 |
| 332 LinuxPtraceDumper dumper(getppid()); | 334 LinuxPtraceDumper dumper(getppid()); |
| 333 ASSERT_TRUE(dumper.Init()); | 335 ASSERT_TRUE(dumper.Init()); |
| 334 const wasteful_vector<MappingInfo*> mappings = dumper.mappings(); | 336 const wasteful_vector<MappingInfo*> mappings = dumper.mappings(); |
| 335 bool found_exe = false; | 337 bool found_exe = false; |
| 336 unsigned i; | 338 unsigned i; |
| 337 for (i = 0; i < mappings.size(); ++i) { | 339 for (i = 0; i < mappings.size(); ++i) { |
| 338 const MappingInfo* mapping = mappings[i]; | 340 const MappingInfo* mapping = mappings[i]; |
| 339 if (!strcmp(mapping->name, exe_name)) { | 341 if (!strcmp(mapping->name, exe_name)) { |
| 340 found_exe = true; | 342 found_exe = true; |
| 341 break; | 343 break; |
| 342 } | 344 } |
| 343 } | 345 } |
| 344 ASSERT_TRUE(found_exe); | 346 ASSERT_TRUE(found_exe); |
| 345 | 347 |
| 346 uint8_t identifier1[sizeof(MDGUID)]; | 348 uint8_t identifier1[kMaxBuildID]; |
| 347 uint8_t identifier2[sizeof(MDGUID)]; | 349 size_t identifier1_length; |
| 350 uint8_t identifier2[kMaxBuildID]; |
| 351 size_t identifier2_length; |
| 348 EXPECT_TRUE(dumper.ElfFileIdentifierForMapping(*mappings[i], true, i, | 352 EXPECT_TRUE(dumper.ElfFileIdentifierForMapping(*mappings[i], true, i, |
| 349 identifier1)); | 353 identifier1, |
| 354 &identifier1_length)); |
| 350 FileID fileid(exe_name); | 355 FileID fileid(exe_name); |
| 351 EXPECT_TRUE(fileid.ElfFileIdentifier(identifier2)); | 356 EXPECT_TRUE(fileid.ElfFileIdentifier(identifier2, &identifier2_length)); |
| 352 char identifier_string1[37]; | 357 char identifier_string1[37]; |
| 353 char identifier_string2[37]; | 358 char identifier_string2[37]; |
| 354 FileID::ConvertIdentifierToString(identifier1, identifier_string1, | 359 FileID::ConvertIdentifierToString(identifier1, identifier_string1, |
| 355 37); | 360 37); |
| 356 FileID::ConvertIdentifierToString(identifier2, identifier_string2, | 361 FileID::ConvertIdentifierToString(identifier2, identifier_string2, |
| 357 37); | 362 37); |
| 358 EXPECT_STREQ(identifier_string1, identifier_string2); | 363 EXPECT_STREQ(identifier_string1, identifier_string2); |
| 359 } | 364 } |
| 360 | 365 |
| 361 /* Get back to normal behavior of TEST*() macros wrt TestBody. */ | 366 /* Get back to normal behavior of TEST*() macros wrt TestBody. */ |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 } | 459 } |
| 455 EXPECT_TRUE(dumper.ThreadsResume()); | 460 EXPECT_TRUE(dumper.ThreadsResume()); |
| 456 kill(child_pid, SIGKILL); | 461 kill(child_pid, SIGKILL); |
| 457 | 462 |
| 458 // Reap child | 463 // Reap child |
| 459 int status; | 464 int status; |
| 460 ASSERT_NE(-1, HANDLE_EINTR(waitpid(child_pid, &status, 0))); | 465 ASSERT_NE(-1, HANDLE_EINTR(waitpid(child_pid, &status, 0))); |
| 461 ASSERT_TRUE(WIFSIGNALED(status)); | 466 ASSERT_TRUE(WIFSIGNALED(status)); |
| 462 ASSERT_EQ(SIGKILL, WTERMSIG(status)); | 467 ASSERT_EQ(SIGKILL, WTERMSIG(status)); |
| 463 } | 468 } |
| OLD | NEW |