Removed extra 'pulling file' message.
Taking a zip bugreport has 2 phases: generating the bugreport and pulling the file. Initially adb was printing 2 messages, but since the latter is almost instantaneously, it could be confusing to have 2 lines... Fixes: 30451250 Change-Id: I1c6cc6163492c1fb6064667dfdb7aaf6ed4c4c6f
This commit is contained in:
parent
cd42d658b2
commit
f7c38b4c03
3 changed files with 25 additions and 24 deletions
|
|
@ -30,7 +30,12 @@ static constexpr char BUGZ_PROGRESS_SEPARATOR[] = "/";
|
||||||
class BugreportStandardStreamsCallback : public StandardStreamsCallbackInterface {
|
class BugreportStandardStreamsCallback : public StandardStreamsCallbackInterface {
|
||||||
public:
|
public:
|
||||||
BugreportStandardStreamsCallback(const std::string& dest_file, bool show_progress, Bugreport* br)
|
BugreportStandardStreamsCallback(const std::string& dest_file, bool show_progress, Bugreport* br)
|
||||||
: br_(br), dest_file_(dest_file), show_progress_(show_progress), status_(-1), line_() {
|
: br_(br),
|
||||||
|
dest_file_(dest_file),
|
||||||
|
line_message_(android::base::StringPrintf("generating %s", dest_file_.c_str())),
|
||||||
|
show_progress_(show_progress),
|
||||||
|
status_(-1),
|
||||||
|
line_() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnStdout(const char* buffer, int length) {
|
void OnStdout(const char* buffer, int length) {
|
||||||
|
|
@ -62,12 +67,12 @@ class BugreportStandardStreamsCallback : public StandardStreamsCallbackInterface
|
||||||
if (android::base::StartsWith(line, BUGZ_OK_PREFIX)) {
|
if (android::base::StartsWith(line, BUGZ_OK_PREFIX)) {
|
||||||
if (show_progress_) {
|
if (show_progress_) {
|
||||||
// Make sure pull message doesn't conflict with generation message.
|
// Make sure pull message doesn't conflict with generation message.
|
||||||
br_->UpdateProgress(dest_file_, 100, 100, true);
|
br_->UpdateProgress(line_message_, 100, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* zip_file = &line[strlen(BUGZ_OK_PREFIX)];
|
const char* zip_file = &line[strlen(BUGZ_OK_PREFIX)];
|
||||||
std::vector<const char*> srcs{zip_file};
|
std::vector<const char*> srcs{zip_file};
|
||||||
status_ = br_->DoSyncPull(srcs, dest_file_.c_str(), true, dest_file_.c_str()) ? 0 : 1;
|
status_ = br_->DoSyncPull(srcs, dest_file_.c_str(), true, line_message_.c_str()) ? 0 : 1;
|
||||||
if (status_ != 0) {
|
if (status_ != 0) {
|
||||||
fprintf(stderr, "Could not copy file '%s' to '%s'\n", zip_file, dest_file_.c_str());
|
fprintf(stderr, "Could not copy file '%s' to '%s'\n", zip_file, dest_file_.c_str());
|
||||||
}
|
}
|
||||||
|
|
@ -96,6 +101,7 @@ class BugreportStandardStreamsCallback : public StandardStreamsCallbackInterface
|
||||||
|
|
||||||
Bugreport* br_;
|
Bugreport* br_;
|
||||||
const std::string dest_file_;
|
const std::string dest_file_;
|
||||||
|
const std::string line_message_;
|
||||||
bool show_progress_;
|
bool show_progress_;
|
||||||
int status_;
|
int status_;
|
||||||
|
|
||||||
|
|
@ -156,15 +162,11 @@ int Bugreport::DoIt(TransportType transport_type, const char* serial, int argc,
|
||||||
return SendShellCommand(transport_type, serial, bugz_command, false, &bugz_callback);
|
return SendShellCommand(transport_type, serial, bugz_command, false, &bugz_callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Bugreport::UpdateProgress(const std::string& file_name, int progress, int total,
|
void Bugreport::UpdateProgress(const std::string& message, int progress, int total) {
|
||||||
bool keep_info_line) {
|
|
||||||
int progress_percentage = (progress * 100 / total);
|
int progress_percentage = (progress * 100 / total);
|
||||||
line_printer_.Print(android::base::StringPrintf("[%3d%%] generating %s", progress_percentage,
|
line_printer_.Print(
|
||||||
file_name.c_str()),
|
android::base::StringPrintf("[%3d%%] %s", progress_percentage, message.c_str()),
|
||||||
LinePrinter::INFO);
|
LinePrinter::INFO);
|
||||||
if (keep_info_line) {
|
|
||||||
line_printer_.KeepInfoLine();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int Bugreport::SendShellCommand(TransportType transport_type, const char* serial,
|
int Bugreport::SendShellCommand(TransportType transport_type, const char* serial,
|
||||||
|
|
|
||||||
|
|
@ -43,8 +43,7 @@ class Bugreport {
|
||||||
const char* name);
|
const char* name);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual void UpdateProgress(const std::string& file_name, int progress, int total,
|
virtual void UpdateProgress(const std::string& file_name, int progress, int total);
|
||||||
bool keep_info_line = false);
|
|
||||||
LinePrinter line_printer_;
|
LinePrinter line_printer_;
|
||||||
DISALLOW_COPY_AND_ASSIGN(Bugreport);
|
DISALLOW_COPY_AND_ASSIGN(Bugreport);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -117,7 +117,7 @@ class BugreportMock : public Bugreport {
|
||||||
bool disable_shell_protocol, StandardStreamsCallbackInterface* callback));
|
bool disable_shell_protocol, StandardStreamsCallbackInterface* callback));
|
||||||
MOCK_METHOD4(DoSyncPull, bool(const std::vector<const char*>& srcs, const char* dst,
|
MOCK_METHOD4(DoSyncPull, bool(const std::vector<const char*>& srcs, const char* dst,
|
||||||
bool copy_attrs, const char* name));
|
bool copy_attrs, const char* name));
|
||||||
MOCK_METHOD4(UpdateProgress, void(const std::string&, int, int, bool));
|
MOCK_METHOD3(UpdateProgress, void(const std::string&, int, int));
|
||||||
};
|
};
|
||||||
|
|
||||||
class BugreportTest : public ::testing::Test {
|
class BugreportTest : public ::testing::Test {
|
||||||
|
|
@ -129,8 +129,8 @@ class BugreportTest : public ::testing::Test {
|
||||||
WithArg<4>(ReturnCallbackDone(0))));
|
WithArg<4>(ReturnCallbackDone(0))));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExpectProgress(int progress, int total, bool keep_info_line = false) {
|
void ExpectProgress(int progress, int total) {
|
||||||
EXPECT_CALL(br_, UpdateProgress(StrEq("file.zip"), progress, total, keep_info_line));
|
EXPECT_CALL(br_, UpdateProgress(HasSubstr("file.zip"), progress, total));
|
||||||
}
|
}
|
||||||
|
|
||||||
BugreportMock br_;
|
BugreportMock br_;
|
||||||
|
|
@ -159,7 +159,7 @@ TEST_F(BugreportTest, OkLegacy) {
|
||||||
.WillOnce(DoAll(WithArg<4>(WriteOnStdout("OK:/device/bugreport.zip")),
|
.WillOnce(DoAll(WithArg<4>(WriteOnStdout("OK:/device/bugreport.zip")),
|
||||||
WithArg<4>(ReturnCallbackDone())));
|
WithArg<4>(ReturnCallbackDone())));
|
||||||
EXPECT_CALL(br_, DoSyncPull(ElementsAre(StrEq("/device/bugreport.zip")), StrEq("file.zip"),
|
EXPECT_CALL(br_, DoSyncPull(ElementsAre(StrEq("/device/bugreport.zip")), StrEq("file.zip"),
|
||||||
true, StrEq("file.zip")))
|
true, HasSubstr("file.zip")))
|
||||||
.WillOnce(Return(true));
|
.WillOnce(Return(true));
|
||||||
|
|
||||||
const char* args[1024] = {"bugreport", "file.zip"};
|
const char* args[1024] = {"bugreport", "file.zip"};
|
||||||
|
|
@ -175,7 +175,7 @@ TEST_F(BugreportTest, OkLegacySplitBuffer) {
|
||||||
WithArg<4>(WriteOnStdout("/bugreport.zip")),
|
WithArg<4>(WriteOnStdout("/bugreport.zip")),
|
||||||
WithArg<4>(ReturnCallbackDone())));
|
WithArg<4>(ReturnCallbackDone())));
|
||||||
EXPECT_CALL(br_, DoSyncPull(ElementsAre(StrEq("/device/bugreport.zip")), StrEq("file.zip"),
|
EXPECT_CALL(br_, DoSyncPull(ElementsAre(StrEq("/device/bugreport.zip")), StrEq("file.zip"),
|
||||||
true, StrEq("file.zip")))
|
true, HasSubstr("file.zip")))
|
||||||
.WillOnce(Return(true));
|
.WillOnce(Return(true));
|
||||||
|
|
||||||
const char* args[1024] = {"bugreport", "file.zip"};
|
const char* args[1024] = {"bugreport", "file.zip"};
|
||||||
|
|
@ -189,7 +189,7 @@ TEST_F(BugreportTest, Ok) {
|
||||||
ExpectProgress(10, 100);
|
ExpectProgress(10, 100);
|
||||||
ExpectProgress(50, 100);
|
ExpectProgress(50, 100);
|
||||||
ExpectProgress(99, 100);
|
ExpectProgress(99, 100);
|
||||||
ExpectProgress(100, 100, true);
|
ExpectProgress(100, 100);
|
||||||
// clang-format off
|
// clang-format off
|
||||||
EXPECT_CALL(br_, SendShellCommand(kTransportLocal, "HannibalLecter", "bugreportz -p", false, _))
|
EXPECT_CALL(br_, SendShellCommand(kTransportLocal, "HannibalLecter", "bugreportz -p", false, _))
|
||||||
.WillOnce(DoAll(
|
.WillOnce(DoAll(
|
||||||
|
|
@ -208,7 +208,7 @@ TEST_F(BugreportTest, Ok) {
|
||||||
WithArg<4>(WriteOnStdout(".zip")),
|
WithArg<4>(WriteOnStdout(".zip")),
|
||||||
WithArg<4>(ReturnCallbackDone())));
|
WithArg<4>(ReturnCallbackDone())));
|
||||||
EXPECT_CALL(br_, DoSyncPull(ElementsAre(StrEq("/device/bugreport.zip")), StrEq("file.zip"),
|
EXPECT_CALL(br_, DoSyncPull(ElementsAre(StrEq("/device/bugreport.zip")), StrEq("file.zip"),
|
||||||
true, StrEq("file.zip")))
|
true, HasSubstr("file.zip")))
|
||||||
.WillOnce(Return(true));
|
.WillOnce(Return(true));
|
||||||
|
|
||||||
const char* args[1024] = {"bugreport", "file.zip"};
|
const char* args[1024] = {"bugreport", "file.zip"};
|
||||||
|
|
@ -218,12 +218,12 @@ TEST_F(BugreportTest, Ok) {
|
||||||
// Tests 'adb bugreport file' when it succeeds
|
// Tests 'adb bugreport file' when it succeeds
|
||||||
TEST_F(BugreportTest, OkNoExtension) {
|
TEST_F(BugreportTest, OkNoExtension) {
|
||||||
SetBugreportzVersion("1.1");
|
SetBugreportzVersion("1.1");
|
||||||
ExpectProgress(100, 100, true);
|
ExpectProgress(100, 100);
|
||||||
EXPECT_CALL(br_, SendShellCommand(kTransportLocal, "HannibalLecter", "bugreportz -p", false, _))
|
EXPECT_CALL(br_, SendShellCommand(kTransportLocal, "HannibalLecter", "bugreportz -p", false, _))
|
||||||
.WillOnce(DoAll(WithArg<4>(WriteOnStdout("OK:/device/bugreport.zip\n")),
|
.WillOnce(DoAll(WithArg<4>(WriteOnStdout("OK:/device/bugreport.zip\n")),
|
||||||
WithArg<4>(ReturnCallbackDone())));
|
WithArg<4>(ReturnCallbackDone())));
|
||||||
EXPECT_CALL(br_, DoSyncPull(ElementsAre(StrEq("/device/bugreport.zip")), StrEq("file.zip"),
|
EXPECT_CALL(br_, DoSyncPull(ElementsAre(StrEq("/device/bugreport.zip")), StrEq("file.zip"),
|
||||||
true, StrEq("file.zip")))
|
true, HasSubstr("file.zip")))
|
||||||
.WillOnce(Return(true));
|
.WillOnce(Return(true));
|
||||||
|
|
||||||
const char* args[1024] = {"bugreport", "file"};
|
const char* args[1024] = {"bugreport", "file"};
|
||||||
|
|
@ -294,12 +294,12 @@ TEST_F(BugreportTest, BugreportzFailed) {
|
||||||
// Tests 'adb bugreport file.zip' when the bugreport could not be pulled
|
// Tests 'adb bugreport file.zip' when the bugreport could not be pulled
|
||||||
TEST_F(BugreportTest, PullFails) {
|
TEST_F(BugreportTest, PullFails) {
|
||||||
SetBugreportzVersion("1.1");
|
SetBugreportzVersion("1.1");
|
||||||
ExpectProgress(100, 100, true);
|
ExpectProgress(100, 100);
|
||||||
EXPECT_CALL(br_, SendShellCommand(kTransportLocal, "HannibalLecter", "bugreportz -p", false, _))
|
EXPECT_CALL(br_, SendShellCommand(kTransportLocal, "HannibalLecter", "bugreportz -p", false, _))
|
||||||
.WillOnce(DoAll(WithArg<4>(WriteOnStdout("OK:/device/bugreport.zip")),
|
.WillOnce(DoAll(WithArg<4>(WriteOnStdout("OK:/device/bugreport.zip")),
|
||||||
WithArg<4>(ReturnCallbackDone())));
|
WithArg<4>(ReturnCallbackDone())));
|
||||||
EXPECT_CALL(br_, DoSyncPull(ElementsAre(StrEq("/device/bugreport.zip")), StrEq("file.zip"),
|
EXPECT_CALL(br_, DoSyncPull(ElementsAre(StrEq("/device/bugreport.zip")), StrEq("file.zip"),
|
||||||
true, StrEq("file.zip")))
|
true, HasSubstr("file.zip")))
|
||||||
.WillOnce(Return(false));
|
.WillOnce(Return(false));
|
||||||
|
|
||||||
const char* args[1024] = {"bugreport", "file.zip"};
|
const char* args[1024] = {"bugreport", "file.zip"};
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue