Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(151)

Side by Side Diff: util/mac/process_reader_test.cc

Issue 586123002: 10.6 runtime compatibility for ProcessReader and MachOImageReader test (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Split MachOImageReader test changes into their own CL Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« util/mac/process_reader.cc ('K') | « util/mac/process_reader.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 14 matching lines...) Expand all
25 #include <string> 25 #include <string>
26 #include <vector> 26 #include <vector>
27 27
28 #include "base/logging.h" 28 #include "base/logging.h"
29 #include "base/mac/scoped_mach_port.h" 29 #include "base/mac/scoped_mach_port.h"
30 #include "base/posix/eintr_wrapper.h" 30 #include "base/posix/eintr_wrapper.h"
31 #include "base/strings/stringprintf.h" 31 #include "base/strings/stringprintf.h"
32 #include "build/build_config.h" 32 #include "build/build_config.h"
33 #include "gtest/gtest.h" 33 #include "gtest/gtest.h"
34 #include "util/file/fd_io.h" 34 #include "util/file/fd_io.h"
35 #include "util/mac/mach_o_image_reader.h"
35 #include "util/mach/mach_extensions.h" 36 #include "util/mach/mach_extensions.h"
36 #include "util/stdlib/pointer_container.h" 37 #include "util/stdlib/pointer_container.h"
37 #include "util/test/errors.h" 38 #include "util/test/errors.h"
38 #include "util/test/mac/dyld.h" 39 #include "util/test/mac/dyld.h"
39 #include "util/test/mac/mach_errors.h" 40 #include "util/test/mac/mach_errors.h"
40 #include "util/test/mac/mach_multiprocess.h" 41 #include "util/test/mac/mach_multiprocess.h"
41 42
42 namespace { 43 namespace {
43 44
44 using namespace crashpad; 45 using namespace crashpad;
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 ASSERT_EQ(dyld_image_count + 1, modules.size()); 547 ASSERT_EQ(dyld_image_count + 1, modules.size());
547 548
548 for (uint32_t index = 0; index < dyld_image_count; ++index) { 549 for (uint32_t index = 0; index < dyld_image_count; ++index) {
549 SCOPED_TRACE(base::StringPrintf( 550 SCOPED_TRACE(base::StringPrintf(
550 "index %u, name %s", index, modules[index].name.c_str())); 551 "index %u, name %s", index, modules[index].name.c_str()));
551 552
552 const char* dyld_image_name = _dyld_get_image_name(index); 553 const char* dyld_image_name = _dyld_get_image_name(index);
553 EXPECT_EQ(dyld_image_name, modules[index].name); 554 EXPECT_EQ(dyld_image_name, modules[index].name);
554 EXPECT_EQ( 555 EXPECT_EQ(
555 reinterpret_cast<mach_vm_address_t>(_dyld_get_image_header(index)), 556 reinterpret_cast<mach_vm_address_t>(_dyld_get_image_header(index)),
556 modules[index].address); 557 modules[index].reader->Address());
557 558
558 if (index == 0) { 559 if (index == 0) {
559 // dyld didn’t load the main executable, so it couldn’t record its 560 // dyld didn’t load the main executable, so it couldn’t record its
560 // timestamp, and it is reported as 0. 561 // timestamp, and it is reported as 0.
561 EXPECT_EQ(0, modules[index].timestamp); 562 EXPECT_EQ(0, modules[index].timestamp);
562 } else { 563 } else {
563 // Hope that the module didn’t change on disk. 564 // Hope that the module didn’t change on disk.
564 struct stat stat_buf; 565 struct stat stat_buf;
565 int rv = stat(dyld_image_name, &stat_buf); 566 int rv = stat(dyld_image_name, &stat_buf);
566 EXPECT_EQ(0, rv) << ErrnoMessage("stat"); 567 EXPECT_EQ(0, rv) << ErrnoMessage("stat");
567 if (rv == 0) { 568 if (rv == 0) {
568 EXPECT_EQ(stat_buf.st_mtime, modules[index].timestamp); 569 EXPECT_EQ(stat_buf.st_mtime, modules[index].timestamp);
569 } 570 }
570 } 571 }
571 } 572 }
572 573
573 size_t index = modules.size() - 1; 574 size_t index = modules.size() - 1;
574 EXPECT_EQ("/usr/lib/dyld", modules[index].name); 575 EXPECT_EQ("/usr/lib/dyld", modules[index].name);
575 576
576 // dyld didn’t load itself either, so it couldn’t record its timestamp, and it 577 // dyld didn’t load itself either, so it couldn’t record its timestamp, and it
577 // is also reported as 0. 578 // is also reported as 0.
578 EXPECT_EQ(0, modules[index].timestamp); 579 EXPECT_EQ(0, modules[index].timestamp);
579 580
580 const struct dyld_all_image_infos* dyld_image_infos = 581 const struct dyld_all_image_infos* dyld_image_infos =
581 _dyld_get_all_image_infos(); 582 _dyld_get_all_image_infos();
582 if (dyld_image_infos->version >= 2) { 583 if (dyld_image_infos->version >= 2) {
583 EXPECT_EQ(reinterpret_cast<mach_vm_address_t>( 584 EXPECT_EQ(
584 dyld_image_infos->dyldImageLoadAddress), modules[index].address); 585 reinterpret_cast<mach_vm_address_t>(
586 dyld_image_infos->dyldImageLoadAddress),
587 modules[index].reader->Address());
585 } 588 }
586 } 589 }
587 590
588 class ProcessReaderModulesChild final : public MachMultiprocess { 591 class ProcessReaderModulesChild final : public MachMultiprocess {
589 public: 592 public:
590 ProcessReaderModulesChild() : MachMultiprocess() {} 593 ProcessReaderModulesChild() : MachMultiprocess() {}
591 594
592 ~ProcessReaderModulesChild() {} 595 ~ProcessReaderModulesChild() {}
593 596
594 private: 597 private:
(...skipping 23 matching lines...) Expand all
618 CheckedReadFD( 621 CheckedReadFD(
619 read_fd, &expect_name_length, sizeof(expect_name_length)); 622 read_fd, &expect_name_length, sizeof(expect_name_length));
620 623
621 // The NUL terminator is not read. 624 // The NUL terminator is not read.
622 std::string expect_name(expect_name_length, '\0'); 625 std::string expect_name(expect_name_length, '\0');
623 CheckedReadFD(read_fd, &expect_name[0], expect_name_length); 626 CheckedReadFD(read_fd, &expect_name[0], expect_name_length);
624 EXPECT_EQ(expect_name, modules[index].name); 627 EXPECT_EQ(expect_name, modules[index].name);
625 628
626 mach_vm_address_t expect_address; 629 mach_vm_address_t expect_address;
627 CheckedReadFD(read_fd, &expect_address, sizeof(expect_address)); 630 CheckedReadFD(read_fd, &expect_address, sizeof(expect_address));
628 EXPECT_EQ(expect_address, modules[index].address); 631 EXPECT_EQ(expect_address, modules[index].reader->Address());
629 632
630 if (index == 0 || index == modules.size() - 1) { 633 if (index == 0 || index == modules.size() - 1) {
631 // dyld didn’t load the main executable or itself, so it couldn’t record 634 // dyld didn’t load the main executable or itself, so it couldn’t record
632 // these timestamps, and they are reported as 0. 635 // these timestamps, and they are reported as 0.
633 EXPECT_EQ(0, modules[index].timestamp); 636 EXPECT_EQ(0, modules[index].timestamp);
634 } else { 637 } else {
635 // Hope that the module didn’t change on disk. 638 // Hope that the module didn’t change on disk.
636 struct stat stat_buf; 639 struct stat stat_buf;
637 int rv = stat(expect_name.c_str(), &stat_buf); 640 int rv = stat(expect_name.c_str(), &stat_buf);
638 EXPECT_EQ(0, rv) << ErrnoMessage("stat"); 641 EXPECT_EQ(0, rv) << ErrnoMessage("stat");
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 693
691 DISALLOW_COPY_AND_ASSIGN(ProcessReaderModulesChild); 694 DISALLOW_COPY_AND_ASSIGN(ProcessReaderModulesChild);
692 }; 695 };
693 696
694 TEST(ProcessReader, ChildModules) { 697 TEST(ProcessReader, ChildModules) {
695 ProcessReaderModulesChild process_reader_modules_child; 698 ProcessReaderModulesChild process_reader_modules_child;
696 process_reader_modules_child.Run(); 699 process_reader_modules_child.Run();
697 } 700 }
698 701
699 } // namespace 702 } // namespace
OLDNEW
« util/mac/process_reader.cc ('K') | « util/mac/process_reader.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698