From 562564d9f2c3cfdcf1afb4be6dc7e874a078436e Mon Sep 17 00:00:00 2001 From: charliea Date: Thu, 14 Jan 2016 05:59:31 -0800 Subject: tools/battor_agent: Fixes bug where read attempts aren't reset per frame This meant that only 20 retries were allowed total, instead of 20 retries being allowed for each read. TBR=nednguyen@google.com BUG=542837 Review URL: https://codereview.chromium.org/1589583002 Cr-Commit-Position: refs/heads/master@{#369405} --- tools/battor_agent/battor_agent.cc | 1 + tools/battor_agent/battor_agent_unittest.cc | 31 +++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) (limited to 'tools/battor_agent') diff --git a/tools/battor_agent/battor_agent.cc b/tools/battor_agent/battor_agent.cc index 06c8602..48ab7bd 100644 --- a/tools/battor_agent/battor_agent.cc +++ b/tools/battor_agent/battor_agent.cc @@ -293,6 +293,7 @@ void BattOrAgent::OnMessageRead(bool success, samples_.insert(samples_.end(), frame.begin(), frame.end()); + num_read_attempts_ = 1; PerformAction(Action::READ_DATA_FRAME); return; } diff --git a/tools/battor_agent/battor_agent_unittest.cc b/tools/battor_agent/battor_agent_unittest.cc index e97492f..b65e647 100644 --- a/tools/battor_agent/battor_agent_unittest.cc +++ b/tools/battor_agent/battor_agent_unittest.cc @@ -616,6 +616,37 @@ TEST_F(BattOrAgentTest, StopTracingFailsWithManyDataFrameReadFailures) { EXPECT_EQ(BATTOR_ERROR_RECEIVE_ERROR, GetCommandError()); } +TEST_F(BattOrAgentTest, StopTracingRetriesResetEachFrame) { + RunStopTracingTo(BattOrAgentState::CALIBRATION_FRAME_SENT); + + // Send 11 failures on two different reads: because the retry count should + // reset after a successful read, this should still be okay. + for (int i = 0; i < 11; i++) { + GetAgent()->OnMessageRead(false, BATTOR_MESSAGE_TYPE_SAMPLES, nullptr); + GetTaskRunner()->RunUntilIdle(); + } + + BattOrFrameHeader frame_header1{0, 1 * sizeof(RawBattOrSample)}; + RawBattOrSample frame1[] = {RawBattOrSample{1, 1}}; + GetAgent()->OnMessageRead(true, BATTOR_MESSAGE_TYPE_SAMPLES, + CreateFrame(frame_header1, frame1, 1)); + GetTaskRunner()->RunUntilIdle(); + + for (int i = 0; i < 11; i++) { + GetAgent()->OnMessageRead(false, BATTOR_MESSAGE_TYPE_SAMPLES, nullptr); + GetTaskRunner()->RunUntilIdle(); + } + + BattOrFrameHeader frame_header2{0, 0}; + RawBattOrSample frame2[] = {}; + GetAgent()->OnMessageRead(true, BATTOR_MESSAGE_TYPE_SAMPLES, + CreateFrame(frame_header2, frame2, 0)); + GetTaskRunner()->RunUntilIdle(); + + EXPECT_TRUE(IsCommandComplete()); + EXPECT_EQ(BATTOR_ERROR_NONE, GetCommandError()); +} + TEST_F(BattOrAgentTest, StopTracingFailsIfSamplesReadHasWrongType) { RunStopTracingTo(BattOrAgentState::SAMPLES_REQUEST_SENT); GetAgent()->OnMessageRead(true, BATTOR_MESSAGE_TYPE_CONTROL_ACK, -- cgit v1.1