diff options
author | charliea <charliea@chromium.org> | 2016-01-14 05:59:31 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-01-14 14:01:13 +0000 |
commit | 562564d9f2c3cfdcf1afb4be6dc7e874a078436e (patch) | |
tree | 09686e82e202631616479bb92dd3eefd9ee072f0 /tools/battor_agent | |
parent | 5f0df0518d4befa6b0c597d0ccdcfa8e50367d00 (diff) | |
download | chromium_src-562564d9f2c3cfdcf1afb4be6dc7e874a078436e.zip chromium_src-562564d9f2c3cfdcf1afb4be6dc7e874a078436e.tar.gz chromium_src-562564d9f2c3cfdcf1afb4be6dc7e874a078436e.tar.bz2 |
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}
Diffstat (limited to 'tools/battor_agent')
-rw-r--r-- | tools/battor_agent/battor_agent.cc | 1 | ||||
-rw-r--r-- | tools/battor_agent/battor_agent_unittest.cc | 31 |
2 files changed, 32 insertions, 0 deletions
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, |