| 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 | 57 |
| 58 ASSERT_GE(dumper.threads().size(), 1); | 58 ASSERT_GE(dumper.threads().size(), 1); |
| 59 bool found = false; | 59 bool found = false; |
| 60 for (size_t i = 0; i < dumper.threads().size(); ++i) { | 60 for (size_t i = 0; i < dumper.threads().size(); ++i) { |
| 61 if (dumper.threads()[i] == getpid()) { | 61 if (dumper.threads()[i] == getpid()) { |
| 62 found = true; | 62 found = true; |
| 63 break; | 63 break; |
| 64 } | 64 } |
| 65 } | 65 } |
| 66 } | 66 } |
| 67 |
| 68 TEST(LinuxDumperTest, BuildProcPath) { |
| 69 const pid_t pid = getpid(); |
| 70 LinuxDumper dumper(pid); |
| 71 |
| 72 char maps_path[256] = "dummymappath"; |
| 73 char maps_path_expected[256]; |
| 74 snprintf(maps_path_expected, sizeof(maps_path_expected), |
| 75 "/proc/%d/maps", pid); |
| 76 dumper.BuildProcPath(maps_path, pid, "maps"); |
| 77 ASSERT_STREQ(maps_path, maps_path_expected); |
| 78 |
| 79 // In release mode, we expect BuildProcPath to handle the invalid |
| 80 // parameters correctly and fill map_path with an empty |
| 81 // NULL-terminated string. |
| 82 #ifdef NDEBUG |
| 83 snprintf(maps_path, sizeof(maps_path), "dummymappath"); |
| 84 dumper.BuildProcPath(maps_path, 0, "maps"); |
| 85 EXPECT_STREQ(maps_path, ""); |
| 86 |
| 87 snprintf(maps_path, sizeof(maps_path), "dummymappath"); |
| 88 dumper.BuildProcPath(maps_path, getpid(), ""); |
| 89 EXPECT_STREQ(maps_path, ""); |
| 90 |
| 91 snprintf(maps_path, sizeof(maps_path), "dummymappath"); |
| 92 dumper.BuildProcPath(maps_path, getpid(), NULL); |
| 93 EXPECT_STREQ(maps_path, ""); |
| 94 #endif |
| 95 } |
| 96 |
| 97 TEST(LinuxDumperTest, MappingsIncludeLinuxGate) { |
| 98 LinuxDumper dumper(getpid()); |
| 99 ASSERT_TRUE(dumper.Init()); |
| 100 |
| 101 void* linux_gate_loc = dumper.FindBeginningOfLinuxGateSharedLibrary(getpid()); |
| 102 if (linux_gate_loc) { |
| 103 bool found_linux_gate = false; |
| 104 |
| 105 const wasteful_vector<MappingInfo*> mappings = dumper.mappings(); |
| 106 const MappingInfo* mapping; |
| 107 for (unsigned i = 0; i < mappings.size(); ++i) { |
| 108 mapping = mappings[i]; |
| 109 if (!strcmp(mapping->name, kLinuxGateLibraryName)) { |
| 110 found_linux_gate = true; |
| 111 break; |
| 112 } |
| 113 } |
| 114 EXPECT_TRUE(found_linux_gate); |
| 115 EXPECT_EQ(linux_gate_loc, reinterpret_cast<void*>(mapping->start_addr)); |
| 116 EXPECT_EQ(0, memcmp(linux_gate_loc, ELFMAG, SELFMAG)); |
| 117 } |
| 118 } |
| OLD | NEW |