system/corennnnn
Révision | 9a882a3ef38c487eaa26dee845bb738997d5023d (tree) |
---|---|
l'heure | 2016-08-05 05:12:39 |
Auteur | Felipe Leme <felipeal@goog...> |
Commiter | Felipe Leme |
Ignore bugreportz output when it's not supported.
On devices running M or below, calling 'bugreportz -v' writes
'/system/bin/sh: bugreportz: not found' in the stdout output, which must
be redirected to stderr so it's not shown in the flat-file bugreport,
above the bugreport header.
BUG: 30451114
Change-Id: I942c92fdf6ae85e0cde7b9f94b9eb0b1fecad77a
@@ -14,6 +14,8 @@ | ||
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | 16 | |
17 | +#define TRACE_TAG ADB | |
18 | + | |
17 | 19 | #include "bugreport.h" |
18 | 20 | |
19 | 21 | #include <string> |
@@ -187,22 +189,30 @@ int Bugreport::DoIt(TransportType transport_type, const char* serial, int argc, | ||
187 | 189 | if (argc > 2) return usage(); |
188 | 190 | |
189 | 191 | // Gets bugreportz version. |
190 | - std::string bugz_stderr; | |
191 | - DefaultStandardStreamsCallback version_callback(nullptr, &bugz_stderr); | |
192 | + std::string bugz_stdout, bugz_stderr; | |
193 | + DefaultStandardStreamsCallback version_callback(&bugz_stdout, &bugz_stderr); | |
192 | 194 | int status = SendShellCommand(transport_type, serial, "bugreportz -v", false, &version_callback); |
193 | 195 | std::string bugz_version = android::base::Trim(bugz_stderr); |
196 | + std::string bugz_output = android::base::Trim(bugz_stdout); | |
194 | 197 | |
195 | 198 | if (status != 0 || bugz_version.empty()) { |
196 | - // Device does not support bugreportz: if called as 'adb bugreport', just falls out to the | |
197 | - // flat-file version | |
198 | - if (argc == 1) return SendShellCommand(transport_type, serial, "bugreport", false); | |
199 | + D("'bugreportz' -v results: status=%d, stdout='%s', stderr='%s'", status, | |
200 | + bugz_output.c_str(), bugz_version.c_str()); | |
201 | + if (argc == 1) { | |
202 | + // Device does not support bugreportz: if called as 'adb bugreport', just falls out to | |
203 | + // the flat-file version. | |
204 | + fprintf(stderr, | |
205 | + "Failed to get bugreportz version, which is only available on devices " | |
206 | + "running Android 7.0 or later.\nTrying a plain-text bug report instead.\n"); | |
207 | + return SendShellCommand(transport_type, serial, "bugreport", false); | |
208 | + } | |
199 | 209 | |
200 | 210 | // But if user explicitly asked for a zipped bug report, fails instead (otherwise calling |
201 | - // 'bugreport' would generate a lot of output the user might not be prepared to handle) | |
211 | + // 'bugreport' would generate a lot of output the user might not be prepared to handle). | |
202 | 212 | fprintf(stderr, |
203 | 213 | "Failed to get bugreportz version: 'bugreportz -v' returned '%s' (code %d).\n" |
204 | - "If the device runs Android M or below, try 'adb bugreport' instead.\n", | |
205 | - bugz_stderr.c_str(), status); | |
214 | + "If the device does not run Android 7.0 or above, try 'adb bugreport' instead.\n", | |
215 | + bugz_output.c_str(), status); | |
206 | 216 | return status != 0 ? status : -1; |
207 | 217 | } |
208 | 218 |
@@ -36,7 +36,9 @@ using ::testing::Return; | ||
36 | 36 | using ::testing::StrEq; |
37 | 37 | using ::testing::WithArg; |
38 | 38 | using ::testing::internal::CaptureStderr; |
39 | +using ::testing::internal::CaptureStdout; | |
39 | 40 | using ::testing::internal::GetCapturedStderr; |
41 | +using ::testing::internal::GetCapturedStdout; | |
40 | 42 | |
41 | 43 | // Empty function so tests don't need to be linked against file_sync_service.cpp, which requires |
42 | 44 | // SELinux and its transitive dependencies... |
@@ -152,19 +154,28 @@ class BugreportTest : public ::testing::Test { | ||
152 | 154 | |
153 | 155 | // Tests when called with invalid number of arguments |
154 | 156 | TEST_F(BugreportTest, InvalidNumberArgs) { |
155 | - const char* args[1024] = {"bugreport", "to", "principal"}; | |
157 | + const char* args[] = {"bugreport", "to", "principal"}; | |
156 | 158 | ASSERT_EQ(-42, br_.DoIt(kTransportLocal, "HannibalLecter", 3, args)); |
157 | 159 | } |
158 | 160 | |
159 | 161 | // Tests the 'adb bugreport' option when the device does not support 'bugreportz' - it falls back |
160 | 162 | // to the flat-file format ('bugreport' binary on device) |
161 | 163 | TEST_F(BugreportTest, NoArgumentsPreNDevice) { |
162 | - ExpectBugreportzVersion(""); | |
164 | + // clang-format off | |
165 | + EXPECT_CALL(br_, SendShellCommand(kTransportLocal, "HannibalLecter", "bugreportz -v", false, _)) | |
166 | + .WillOnce(DoAll(WithArg<4>(WriteOnStderr("")), | |
167 | + // Write some bogus output on stdout to make sure it's ignored | |
168 | + WithArg<4>(WriteOnStdout("Dude, where is my bugreportz?")), | |
169 | + WithArg<4>(ReturnCallbackDone(0)))); | |
170 | + // clang-format on | |
171 | + std::string bugreport = "Reported the bug was."; | |
172 | + CaptureStdout(); | |
163 | 173 | EXPECT_CALL(br_, SendShellCommand(kTransportLocal, "HannibalLecter", "bugreport", false, _)) |
164 | - .WillOnce(Return(0)); | |
174 | + .WillOnce(DoAll(WithArg<4>(WriteOnStdout(bugreport)), Return(0))); | |
165 | 175 | |
166 | - const char* args[1024] = {"bugreport"}; | |
176 | + const char* args[] = {"bugreport"}; | |
167 | 177 | ASSERT_EQ(0, br_.DoIt(kTransportLocal, "HannibalLecter", 1, args)); |
178 | + ASSERT_THAT(GetCapturedStdout(), StrEq(bugreport)); | |
168 | 179 | } |
169 | 180 | |
170 | 181 | // Tests the 'adb bugreport' option when the device supports 'bugreportz' version 1.0 - it will |
@@ -181,7 +192,7 @@ TEST_F(BugreportTest, NoArgumentsNDevice) { | ||
181 | 192 | true, StrEq("generating da_bugreport.zip"))) |
182 | 193 | .WillOnce(Return(true)); |
183 | 194 | |
184 | - const char* args[1024] = {"bugreport"}; | |
195 | + const char* args[] = {"bugreport"}; | |
185 | 196 | ASSERT_EQ(0, br_.DoIt(kTransportLocal, "HannibalLecter", 1, args)); |
186 | 197 | } |
187 | 198 |
@@ -201,7 +212,7 @@ TEST_F(BugreportTest, NoArgumentsPostNDevice) { | ||
201 | 212 | true, StrEq("generating da_bugreport.zip"))) |
202 | 213 | .WillOnce(Return(true)); |
203 | 214 | |
204 | - const char* args[1024] = {"bugreport"}; | |
215 | + const char* args[] = {"bugreport"}; | |
205 | 216 | ASSERT_EQ(0, br_.DoIt(kTransportLocal, "HannibalLecter", 1, args)); |
206 | 217 | } |
207 | 218 |
@@ -215,7 +226,7 @@ TEST_F(BugreportTest, OkNDevice) { | ||
215 | 226 | true, StrEq("generating file.zip"))) |
216 | 227 | .WillOnce(Return(true)); |
217 | 228 | |
218 | - const char* args[1024] = {"bugreport", "file.zip"}; | |
229 | + const char* args[] = {"bugreport", "file.zip"}; | |
219 | 230 | ASSERT_EQ(0, br_.DoIt(kTransportLocal, "HannibalLecter", 2, args)); |
220 | 231 | } |
221 | 232 |
@@ -231,7 +242,7 @@ TEST_F(BugreportTest, OkNDeviceSplitBuffer) { | ||
231 | 242 | true, StrEq("generating file.zip"))) |
232 | 243 | .WillOnce(Return(true)); |
233 | 244 | |
234 | - const char* args[1024] = {"bugreport", "file.zip"}; | |
245 | + const char* args[] = {"bugreport", "file.zip"}; | |
235 | 246 | ASSERT_EQ(0, br_.DoIt(kTransportLocal, "HannibalLecter", 2, args)); |
236 | 247 | } |
237 | 248 |
@@ -267,7 +278,7 @@ TEST_F(BugreportTest, OkProgress) { | ||
267 | 278 | true, StrEq("generating file.zip"))) |
268 | 279 | .WillOnce(Return(true)); |
269 | 280 | |
270 | - const char* args[1024] = {"bugreport", "file.zip"}; | |
281 | + const char* args[] = {"bugreport", "file.zip"}; | |
271 | 282 | ASSERT_EQ(0, br_.DoIt(kTransportLocal, "HannibalLecter", 2, args)); |
272 | 283 | } |
273 | 284 |
@@ -286,7 +297,7 @@ TEST_F(BugreportTest, OkDirectory) { | ||
286 | 297 | true, StrEq("generating da_bugreport.zip"))) |
287 | 298 | .WillOnce(Return(true)); |
288 | 299 | |
289 | - const char* args[1024] = {"bugreport", td.path}; | |
300 | + const char* args[] = {"bugreport", td.path}; | |
290 | 301 | ASSERT_EQ(0, br_.DoIt(kTransportLocal, "HannibalLecter", 2, args)); |
291 | 302 | } |
292 | 303 |
@@ -300,7 +311,7 @@ TEST_F(BugreportTest, OkNoExtension) { | ||
300 | 311 | true, StrEq("generating file.zip"))) |
301 | 312 | .WillOnce(Return(true)); |
302 | 313 | |
303 | - const char* args[1024] = {"bugreport", "file"}; | |
314 | + const char* args[] = {"bugreport", "file"}; | |
304 | 315 | ASSERT_EQ(0, br_.DoIt(kTransportLocal, "HannibalLecter", 2, args)); |
305 | 316 | } |
306 | 317 |
@@ -319,7 +330,7 @@ TEST_F(BugreportTest, OkNDeviceDirectory) { | ||
319 | 330 | true, StrEq("generating da_bugreport.zip"))) |
320 | 331 | .WillOnce(Return(true)); |
321 | 332 | |
322 | - const char* args[1024] = {"bugreport", td.path}; | |
333 | + const char* args[] = {"bugreport", td.path}; | |
323 | 334 | ASSERT_EQ(0, br_.DoIt(kTransportLocal, "HannibalLecter", 2, args)); |
324 | 335 | } |
325 | 336 |
@@ -331,7 +342,7 @@ TEST_F(BugreportTest, BugreportzReturnedFail) { | ||
331 | 342 | DoAll(WithArg<4>(WriteOnStdout("FAIL:D'OH!\n")), WithArg<4>(ReturnCallbackDone()))); |
332 | 343 | |
333 | 344 | CaptureStderr(); |
334 | - const char* args[1024] = {"bugreport", "file.zip"}; | |
345 | + const char* args[] = {"bugreport", "file.zip"}; | |
335 | 346 | ASSERT_EQ(-1, br_.DoIt(kTransportLocal, "HannibalLecter", 2, args)); |
336 | 347 | ASSERT_THAT(GetCapturedStderr(), HasSubstr("D'OH!")); |
337 | 348 | } |
@@ -346,7 +357,7 @@ TEST_F(BugreportTest, BugreportzReturnedFailSplitBuffer) { | ||
346 | 357 | WithArg<4>(ReturnCallbackDone()))); |
347 | 358 | |
348 | 359 | CaptureStderr(); |
349 | - const char* args[1024] = {"bugreport", "file.zip"}; | |
360 | + const char* args[] = {"bugreport", "file.zip"}; | |
350 | 361 | ASSERT_EQ(-1, br_.DoIt(kTransportLocal, "HannibalLecter", 2, args)); |
351 | 362 | ASSERT_THAT(GetCapturedStderr(), HasSubstr("D'OH!")); |
352 | 363 | } |
@@ -360,7 +371,7 @@ TEST_F(BugreportTest, BugreportzReturnedUnsupported) { | ||
360 | 371 | WithArg<4>(ReturnCallbackDone()))); |
361 | 372 | |
362 | 373 | CaptureStderr(); |
363 | - const char* args[1024] = {"bugreport", "file.zip"}; | |
374 | + const char* args[] = {"bugreport", "file.zip"}; | |
364 | 375 | ASSERT_EQ(-1, br_.DoIt(kTransportLocal, "HannibalLecter", 2, args)); |
365 | 376 | ASSERT_THAT(GetCapturedStderr(), HasSubstr("bugreportz? What am I, a zombie?")); |
366 | 377 | } |
@@ -370,7 +381,7 @@ TEST_F(BugreportTest, BugreportzVersionFailed) { | ||
370 | 381 | EXPECT_CALL(br_, SendShellCommand(kTransportLocal, "HannibalLecter", "bugreportz -v", false, _)) |
371 | 382 | .WillOnce(Return(666)); |
372 | 383 | |
373 | - const char* args[1024] = {"bugreport", "file.zip"}; | |
384 | + const char* args[] = {"bugreport", "file.zip"}; | |
374 | 385 | ASSERT_EQ(666, br_.DoIt(kTransportLocal, "HannibalLecter", 2, args)); |
375 | 386 | } |
376 | 387 |
@@ -378,7 +389,7 @@ TEST_F(BugreportTest, BugreportzVersionFailed) { | ||
378 | 389 | TEST_F(BugreportTest, BugreportzVersionEmpty) { |
379 | 390 | ExpectBugreportzVersion(""); |
380 | 391 | |
381 | - const char* args[1024] = {"bugreport", "file.zip"}; | |
392 | + const char* args[] = {"bugreport", "file.zip"}; | |
382 | 393 | ASSERT_EQ(-1, br_.DoIt(kTransportLocal, "HannibalLecter", 2, args)); |
383 | 394 | } |
384 | 395 |
@@ -388,7 +399,7 @@ TEST_F(BugreportTest, BugreportzFailed) { | ||
388 | 399 | EXPECT_CALL(br_, SendShellCommand(kTransportLocal, "HannibalLecter", "bugreportz -p", false, _)) |
389 | 400 | .WillOnce(Return(666)); |
390 | 401 | |
391 | - const char* args[1024] = {"bugreport", "file.zip"}; | |
402 | + const char* args[] = {"bugreport", "file.zip"}; | |
392 | 403 | ASSERT_EQ(666, br_.DoIt(kTransportLocal, "HannibalLecter", 2, args)); |
393 | 404 | } |
394 | 405 |
@@ -402,6 +413,6 @@ TEST_F(BugreportTest, PullFails) { | ||
402 | 413 | true, HasSubstr("file.zip"))) |
403 | 414 | .WillOnce(Return(false)); |
404 | 415 | |
405 | - const char* args[1024] = {"bugreport", "file.zip"}; | |
416 | + const char* args[] = {"bugreport", "file.zip"}; | |
406 | 417 | ASSERT_EQ(1, br_.DoIt(kTransportLocal, "HannibalLecter", 2, args)); |
407 | 418 | } |