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

Side by Side Diff: src/client/linux/microdump_writer/microdump_writer_unittest.cc

Issue 1334473003: Add GPU fingerprint information to breakpad microdumps. (Closed) Base URL: https://chromium.googlesource.com/breakpad/breakpad.git@master
Patch Set: Created 5 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
OLDNEW
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
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 using namespace google_breakpad; 47 using namespace google_breakpad;
48 48
49 namespace { 49 namespace {
50 50
51 typedef testing::Test MicrodumpWriterTest; 51 typedef testing::Test MicrodumpWriterTest;
52 52
53 void CrashAndGetMicrodump( 53 void CrashAndGetMicrodump(
54 const MappingList& mappings, 54 const MappingList& mappings,
55 const char* build_fingerprint, 55 const char* build_fingerprint,
56 const char* product_info, 56 const char* product_info,
57 const char* gpu_fingerprint,
57 scoped_array<char>* buf) { 58 scoped_array<char>* buf) {
58 int fds[2]; 59 int fds[2];
59 ASSERT_NE(-1, pipe(fds)); 60 ASSERT_NE(-1, pipe(fds));
60 61
61 AutoTempDir temp_dir; 62 AutoTempDir temp_dir;
62 string stderr_file = temp_dir.path() + "/stderr.log"; 63 string stderr_file = temp_dir.path() + "/stderr.log";
63 int err_fd = open(stderr_file.c_str(), O_CREAT | O_RDWR, S_IRUSR | S_IWUSR); 64 int err_fd = open(stderr_file.c_str(), O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
64 ASSERT_NE(-1, err_fd); 65 ASSERT_NE(-1, err_fd);
65 66
66 const pid_t child = fork(); 67 const pid_t child = fork();
(...skipping 11 matching lines...) Expand all
78 79
79 // Set a non-zero tid to avoid tripping asserts. 80 // Set a non-zero tid to avoid tripping asserts.
80 context.tid = child; 81 context.tid = child;
81 82
82 // Redirect temporarily stderr to the stderr.log file. 83 // Redirect temporarily stderr to the stderr.log file.
83 int save_err = dup(STDERR_FILENO); 84 int save_err = dup(STDERR_FILENO);
84 ASSERT_NE(-1, save_err); 85 ASSERT_NE(-1, save_err);
85 ASSERT_NE(-1, dup2(err_fd, STDERR_FILENO)); 86 ASSERT_NE(-1, dup2(err_fd, STDERR_FILENO));
86 87
87 ASSERT_TRUE(WriteMicrodump(child, &context, sizeof(context), mappings, 88 ASSERT_TRUE(WriteMicrodump(child, &context, sizeof(context), mappings,
88 build_fingerprint, product_info)); 89 build_fingerprint, product_info, gpu_fingerprint));
89 90
90 // Revert stderr back to the console. 91 // Revert stderr back to the console.
91 dup2(save_err, STDERR_FILENO); 92 dup2(save_err, STDERR_FILENO);
92 close(save_err); 93 close(save_err);
93 94
94 // Read back the stderr file and check for the microdump marker. 95 // Read back the stderr file and check for the microdump marker.
95 fsync(err_fd); 96 fsync(err_fd);
96 lseek(err_fd, 0, SEEK_SET); 97 lseek(err_fd, 0, SEEK_SET);
97 const size_t kBufSize = 64 * 1024; 98 const size_t kBufSize = 64 * 1024;
98 buf->reset(new char[kBufSize]); 99 buf->reset(new char[kBufSize]);
99 ASSERT_GT(read(err_fd, buf->get(), kBufSize), 0); 100 ASSERT_GT(read(err_fd, buf->get(), kBufSize), 0);
100 101
101 close(err_fd); 102 close(err_fd);
102 close(fds[1]); 103 close(fds[1]);
103 104
104 ASSERT_NE(static_cast<char*>(0), strstr( 105 ASSERT_NE(static_cast<char*>(0), strstr(
105 buf->get(), "-----BEGIN BREAKPAD MICRODUMP-----")); 106 buf->get(), "-----BEGIN BREAKPAD MICRODUMP-----"));
106 ASSERT_NE(static_cast<char*>(0), strstr( 107 ASSERT_NE(static_cast<char*>(0), strstr(
107 buf->get(), "-----END BREAKPAD MICRODUMP-----")); 108 buf->get(), "-----END BREAKPAD MICRODUMP-----"));
108 } 109 }
109 110
110 void CheckMicrodumpContents(const string &microdum_content, 111 void CheckMicrodumpContents(const string &microdum_content,
111 const string &expected_fingerprint, 112 const string &expected_fingerprint,
112 const string &expected_product_info) { 113 const string &expected_product_info) {
Primiano Tucci (use gerrit) 2015/09/09 18:59:34 would be nice if this was covering also the gpu fi
Tobias Sargeant 2015/09/10 10:45:04 Done.
113 std::istringstream iss(microdum_content); 114 std::istringstream iss(microdum_content);
114 bool did_find_os_info = false; 115 bool did_find_os_info = false;
115 bool did_find_product_info = false; 116 bool did_find_product_info = false;
116 for (string line; std::getline(iss, line);) { 117 for (string line; std::getline(iss, line);) {
117 if (line.find("O ") == 0) { 118 if (line.find("O ") == 0) {
118 std::istringstream os_info_tokens(line); 119 std::istringstream os_info_tokens(line);
119 string token; 120 string token;
120 os_info_tokens.ignore(2); // Ignore the "O " preamble. 121 os_info_tokens.ignore(2); // Ignore the "O " preamble.
121 // Check the OS descriptor char (L=Linux, A=Android). 122 // Check the OS descriptor char (L=Linux, A=Android).
122 os_info_tokens >> token; 123 os_info_tokens >> token;
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 197
197 TEST(MicrodumpWriterTest, NoProductInfo) { 198 TEST(MicrodumpWriterTest, NoProductInfo) {
198 const char kBuildFingerprint[] = "foobar"; 199 const char kBuildFingerprint[] = "foobar";
199 scoped_array<char> buf; 200 scoped_array<char> buf;
200 MappingList no_mappings; 201 MappingList no_mappings;
201 202
202 CrashAndGetMicrodump(no_mappings, kBuildFingerprint, NULL, &buf); 203 CrashAndGetMicrodump(no_mappings, kBuildFingerprint, NULL, &buf);
203 CheckMicrodumpContents(string(buf.get()), kBuildFingerprint, "UNKNOWN:0.0.0.0" ); 204 CheckMicrodumpContents(string(buf.get()), kBuildFingerprint, "UNKNOWN:0.0.0.0" );
204 } 205 }
205 } // namespace 206 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698