OLD | NEW |
1 // Copyright (c) 2014 Google Inc. | 1 // Copyright (c) 2014 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 |
11 // copyright notice, this list of conditions and the following disclaimer | 11 // copyright notice, this list of conditions and the following disclaimer |
12 // in the documentation and/or other materials provided with the | 12 // in the documentation and/or other materials provided with the |
13 // distribution. | 13 // distribution. |
14 // * Neither the name of Google Inc. nor the names of its | 14 // * Neither the name of Google Inc. nor the names of its |
15 // contributors may be used to endorse or promote products derived from | 15 // contributors may be used to endorse or promote products derived from |
16 // this software without specific prior written permission. | 16 // this software without specific prior written permission. |
17 // | 17 // |
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
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 #include <ctype.h> |
30 #include <sys/syscall.h> | 31 #include <sys/syscall.h> |
31 #include <sys/types.h> | 32 #include <sys/types.h> |
32 #include <unistd.h> | 33 #include <unistd.h> |
33 | 34 |
| 35 #include <sstream> |
34 #include <string> | 36 #include <string> |
35 | 37 |
36 #include "breakpad_googletest_includes.h" | 38 #include "breakpad_googletest_includes.h" |
37 #include "client/linux/handler/exception_handler.h" | 39 #include "client/linux/handler/exception_handler.h" |
38 #include "client/linux/microdump_writer/microdump_writer.h" | 40 #include "client/linux/microdump_writer/microdump_writer.h" |
39 #include "common/linux/eintr_wrapper.h" | 41 #include "common/linux/eintr_wrapper.h" |
40 #include "common/linux/ignore_ret.h" | 42 #include "common/linux/ignore_ret.h" |
41 #include "common/scoped_ptr.h" | 43 #include "common/scoped_ptr.h" |
42 #include "common/tests/auto_tempdir.h" | 44 #include "common/tests/auto_tempdir.h" |
43 #include "common/using_std_string.h" | 45 #include "common/using_std_string.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 buf->reset(new char[kBufSize]); | 98 buf->reset(new char[kBufSize]); |
97 ASSERT_GT(read(err_fd, buf->get(), kBufSize), 0); | 99 ASSERT_GT(read(err_fd, buf->get(), kBufSize), 0); |
98 | 100 |
99 close(err_fd); | 101 close(err_fd); |
100 close(fds[1]); | 102 close(fds[1]); |
101 | 103 |
102 ASSERT_NE(static_cast<char*>(0), strstr( | 104 ASSERT_NE(static_cast<char*>(0), strstr( |
103 buf->get(), "-----BEGIN BREAKPAD MICRODUMP-----")); | 105 buf->get(), "-----BEGIN BREAKPAD MICRODUMP-----")); |
104 ASSERT_NE(static_cast<char*>(0), strstr( | 106 ASSERT_NE(static_cast<char*>(0), strstr( |
105 buf->get(), "-----END BREAKPAD MICRODUMP-----")); | 107 buf->get(), "-----END BREAKPAD MICRODUMP-----")); |
| 108 } |
106 | 109 |
| 110 void CheckMicrodumpContents(const string µdum_content, |
| 111 const string &expected_fingerprint, |
| 112 const string &expected_product_info) { |
| 113 std::istringstream iss(microdum_content); |
| 114 bool did_find_os_info = false; |
| 115 bool did_find_product_info = false; |
| 116 for (string line; std::getline(iss, line);) { |
| 117 if (line.find("O ") == 0) { |
| 118 std::istringstream os_info_tokens(line); |
| 119 string token; |
| 120 os_info_tokens.ignore(2); // Ignore the "O " preamble. |
| 121 // Check the OS descriptor char (L=Linux, A=Android). |
| 122 os_info_tokens >> token; |
| 123 ASSERT_TRUE(token == "L" || token == "A"); |
| 124 |
| 125 os_info_tokens >> token; // HW architecture. |
| 126 os_info_tokens >> token; // Number of cpus. |
| 127 for (size_t i = 0; i < token.size(); ++i) |
| 128 ASSERT_TRUE(isxdigit(token[i])); |
| 129 os_info_tokens >> token; // SW architecture. |
| 130 |
| 131 // Check that the build fingerprint is in the right place. |
| 132 os_info_tokens >> token; |
| 133 ASSERT_EQ(expected_fingerprint, token); |
| 134 did_find_os_info = true; |
| 135 } else if (line.find("V ") == 0) { |
| 136 ASSERT_EQ("V " + expected_product_info, line); |
| 137 did_find_product_info = true; |
| 138 } |
| 139 } |
| 140 ASSERT_TRUE(did_find_os_info); |
| 141 ASSERT_TRUE(did_find_product_info); |
107 } | 142 } |
108 | 143 |
109 TEST(MicrodumpWriterTest, BasicWithMappings) { | 144 TEST(MicrodumpWriterTest, BasicWithMappings) { |
110 // Push some extra mapping to check the MappingList logic. | 145 // Push some extra mapping to check the MappingList logic. |
111 const uint32_t memory_size = sysconf(_SC_PAGESIZE); | 146 const uint32_t memory_size = sysconf(_SC_PAGESIZE); |
112 const char* kMemoryName = "libfoo.so"; | 147 const char* kMemoryName = "libfoo.so"; |
113 const uint8_t kModuleGUID[sizeof(MDGUID)] = { | 148 const uint8_t kModuleGUID[sizeof(MDGUID)] = { |
114 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, | 149 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, |
115 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF | 150 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF |
116 }; | 151 }; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 // Ensure that the product info and build fingerprint metadata show up in the | 184 // Ensure that the product info and build fingerprint metadata show up in the |
150 // final microdump if present. | 185 // final microdump if present. |
151 TEST(MicrodumpWriterTest, BuildFingerprintAndProductInfo) { | 186 TEST(MicrodumpWriterTest, BuildFingerprintAndProductInfo) { |
152 const char kProductInfo[] = "MockProduct:42.0.2311.99"; | 187 const char kProductInfo[] = "MockProduct:42.0.2311.99"; |
153 const char kBuildFingerprint[] = | 188 const char kBuildFingerprint[] = |
154 "aosp/occam/mako:5.1.1/LMY47W/12345678:userdegbug/dev-keys"; | 189 "aosp/occam/mako:5.1.1/LMY47W/12345678:userdegbug/dev-keys"; |
155 scoped_array<char> buf; | 190 scoped_array<char> buf; |
156 MappingList no_mappings; | 191 MappingList no_mappings; |
157 | 192 |
158 CrashAndGetMicrodump(no_mappings, kBuildFingerprint, kProductInfo, &buf); | 193 CrashAndGetMicrodump(no_mappings, kBuildFingerprint, kProductInfo, &buf); |
159 | 194 CheckMicrodumpContents(string(buf.get()), kBuildFingerprint, kProductInfo); |
160 ASSERT_NE(static_cast<char*>(0), strstr(buf.get(), kBuildFingerprint)); | |
161 ASSERT_NE(static_cast<char*>(0), strstr(buf.get(), kProductInfo)); | |
162 } | 195 } |
163 | 196 |
| 197 TEST(MicrodumpWriterTest, NoProductInfo) { |
| 198 const char kBuildFingerprint[] = "foobar"; |
| 199 scoped_array<char> buf; |
| 200 MappingList no_mappings; |
| 201 |
| 202 CrashAndGetMicrodump(no_mappings, kBuildFingerprint, NULL, &buf); |
| 203 CheckMicrodumpContents(string(buf.get()), kBuildFingerprint, "UNKNOWN:0.0.0.0"
); |
| 204 } |
164 } // namespace | 205 } // namespace |
OLD | NEW |