OLD | NEW |
1 // Copyright 2014 The Crashpad Authors. All rights reserved. | 1 // Copyright 2014 The Crashpad Authors. All rights reserved. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 #else | 98 #else |
99 EXPECT_TRUE(process_reader.Is64Bit()); | 99 EXPECT_TRUE(process_reader.Is64Bit()); |
100 #endif | 100 #endif |
101 | 101 |
102 EXPECT_EQ(getpid(), process_reader.ParentProcessID()); | 102 EXPECT_EQ(getpid(), process_reader.ParentProcessID()); |
103 EXPECT_EQ(ChildPID(), process_reader.ProcessID()); | 103 EXPECT_EQ(ChildPID(), process_reader.ProcessID()); |
104 | 104 |
105 FileHandle read_handle = ReadPipeHandle(); | 105 FileHandle read_handle = ReadPipeHandle(); |
106 | 106 |
107 mach_vm_address_t address; | 107 mach_vm_address_t address; |
108 CheckedReadFile(read_handle, &address, sizeof(address)); | 108 CheckedReadFileExactly(read_handle, &address, sizeof(address)); |
109 | 109 |
110 std::string read_string; | 110 std::string read_string; |
111 ASSERT_TRUE(process_reader.Memory()->ReadCString(address, &read_string)); | 111 ASSERT_TRUE(process_reader.Memory()->ReadCString(address, &read_string)); |
112 EXPECT_EQ(kTestMemory, read_string); | 112 EXPECT_EQ(kTestMemory, read_string); |
113 } | 113 } |
114 | 114 |
115 void MachMultiprocessChild() override { | 115 void MachMultiprocessChild() override { |
116 FileHandle write_handle = WritePipeHandle(); | 116 FileHandle write_handle = WritePipeHandle(); |
117 | 117 |
118 mach_vm_address_t address = | 118 mach_vm_address_t address = |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 FileHandle read_handle = ReadPipeHandle(); | 441 FileHandle read_handle = ReadPipeHandle(); |
442 | 442 |
443 // Build a map of all expected threads, keyed by each thread’s ID, and with | 443 // Build a map of all expected threads, keyed by each thread’s ID, and with |
444 // addresses that should lie somewhere within each thread’s stack as values. | 444 // addresses that should lie somewhere within each thread’s stack as values. |
445 // These IDs and addresses all come from the child process via the pipe. | 445 // These IDs and addresses all come from the child process via the pipe. |
446 ThreadMap thread_map; | 446 ThreadMap thread_map; |
447 for (size_t thread_index = 0; | 447 for (size_t thread_index = 0; |
448 thread_index < thread_count_ + 1; | 448 thread_index < thread_count_ + 1; |
449 ++thread_index) { | 449 ++thread_index) { |
450 uint64_t thread_id; | 450 uint64_t thread_id; |
451 CheckedReadFile(read_handle, &thread_id, sizeof(thread_id)); | 451 CheckedReadFileExactly(read_handle, &thread_id, sizeof(thread_id)); |
452 | 452 |
453 TestThreadPool::ThreadExpectation expectation; | 453 TestThreadPool::ThreadExpectation expectation; |
454 CheckedReadFile(read_handle, | 454 CheckedReadFileExactly(read_handle, |
455 &expectation.stack_address, | 455 &expectation.stack_address, |
456 sizeof(expectation.stack_address)); | 456 sizeof(expectation.stack_address)); |
457 CheckedReadFile(read_handle, | 457 CheckedReadFileExactly(read_handle, |
458 &expectation.suspend_count, | 458 &expectation.suspend_count, |
459 sizeof(expectation.suspend_count)); | 459 sizeof(expectation.suspend_count)); |
460 | 460 |
461 // There can’t be any duplicate thread IDs. | 461 // There can’t be any duplicate thread IDs. |
462 EXPECT_EQ(0u, thread_map.count(thread_id)); | 462 EXPECT_EQ(0u, thread_map.count(thread_id)); |
463 | 463 |
464 thread_map[thread_id] = expectation; | 464 thread_map[thread_id] = expectation; |
465 } | 465 } |
466 | 466 |
467 const std::vector<ProcessReader::Thread>& threads = process_reader.Threads()
; | 467 const std::vector<ProcessReader::Thread>& threads = process_reader.Threads()
; |
468 | 468 |
469 // The child shouldn’t have any threads other than its main thread and the | 469 // The child shouldn’t have any threads other than its main thread and the |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
723 const std::vector<ProcessReader::Module>& modules = | 723 const std::vector<ProcessReader::Module>& modules = |
724 process_reader.Modules(); | 724 process_reader.Modules(); |
725 | 725 |
726 // There needs to be at least an entry for the main executable, for a dylib, | 726 // There needs to be at least an entry for the main executable, for a dylib, |
727 // and for dyld. | 727 // and for dyld. |
728 ASSERT_GE(modules.size(), 3u); | 728 ASSERT_GE(modules.size(), 3u); |
729 | 729 |
730 FileHandle read_handle = ReadPipeHandle(); | 730 FileHandle read_handle = ReadPipeHandle(); |
731 | 731 |
732 uint32_t expect_modules; | 732 uint32_t expect_modules; |
733 CheckedReadFile(read_handle, &expect_modules, sizeof(expect_modules)); | 733 CheckedReadFileExactly( |
| 734 read_handle, &expect_modules, sizeof(expect_modules)); |
734 | 735 |
735 ASSERT_EQ(expect_modules, modules.size()); | 736 ASSERT_EQ(expect_modules, modules.size()); |
736 | 737 |
737 bool found_cl_kernels = false; | 738 bool found_cl_kernels = false; |
738 for (size_t index = 0; index < modules.size(); ++index) { | 739 for (size_t index = 0; index < modules.size(); ++index) { |
739 SCOPED_TRACE(base::StringPrintf( | 740 SCOPED_TRACE(base::StringPrintf( |
740 "index %zu, name %s", index, modules[index].name.c_str())); | 741 "index %zu, name %s", index, modules[index].name.c_str())); |
741 | 742 |
742 uint32_t expect_name_length; | 743 uint32_t expect_name_length; |
743 CheckedReadFile( | 744 CheckedReadFileExactly( |
744 read_handle, &expect_name_length, sizeof(expect_name_length)); | 745 read_handle, &expect_name_length, sizeof(expect_name_length)); |
745 | 746 |
746 // The NUL terminator is not read. | 747 // The NUL terminator is not read. |
747 std::string expect_name(expect_name_length, '\0'); | 748 std::string expect_name(expect_name_length, '\0'); |
748 CheckedReadFile(read_handle, &expect_name[0], expect_name_length); | 749 CheckedReadFileExactly(read_handle, &expect_name[0], expect_name_length); |
749 EXPECT_EQ(expect_name, modules[index].name); | 750 EXPECT_EQ(expect_name, modules[index].name); |
750 | 751 |
751 mach_vm_address_t expect_address; | 752 mach_vm_address_t expect_address; |
752 CheckedReadFile(read_handle, &expect_address, sizeof(expect_address)); | 753 CheckedReadFileExactly( |
| 754 read_handle, &expect_address, sizeof(expect_address)); |
753 ASSERT_TRUE(modules[index].reader); | 755 ASSERT_TRUE(modules[index].reader); |
754 EXPECT_EQ(expect_address, modules[index].reader->Address()); | 756 EXPECT_EQ(expect_address, modules[index].reader->Address()); |
755 | 757 |
756 if (index == 0 || index == modules.size() - 1) { | 758 if (index == 0 || index == modules.size() - 1) { |
757 // dyld didn’t load the main executable or itself, so it couldn’t record | 759 // dyld didn’t load the main executable or itself, so it couldn’t record |
758 // these timestamps, and they are reported as 0. | 760 // these timestamps, and they are reported as 0. |
759 EXPECT_EQ(0, modules[index].timestamp); | 761 EXPECT_EQ(0, modules[index].timestamp); |
760 } else if (modules[index].reader->FileType() == MH_BUNDLE && | 762 } else if (modules[index].reader->FileType() == MH_BUNDLE && |
761 modules[index].name == "cl_kernels") { | 763 modules[index].name == "cl_kernels") { |
762 // cl_kernels doesn’t exist as a file. | 764 // cl_kernels doesn’t exist as a file. |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
831 ScopedOpenCLNoOpKernel ensure_cl_kernels; | 833 ScopedOpenCLNoOpKernel ensure_cl_kernels; |
832 ASSERT_NO_FATAL_FAILURE(ensure_cl_kernels.SetUp()); | 834 ASSERT_NO_FATAL_FAILURE(ensure_cl_kernels.SetUp()); |
833 | 835 |
834 ProcessReaderModulesChild process_reader_modules_child; | 836 ProcessReaderModulesChild process_reader_modules_child; |
835 process_reader_modules_child.Run(); | 837 process_reader_modules_child.Run(); |
836 } | 838 } |
837 | 839 |
838 } // namespace | 840 } // namespace |
839 } // namespace test | 841 } // namespace test |
840 } // namespace crashpad | 842 } // namespace crashpad |
OLD | NEW |