Commit fc4c96b9 authored by rnephew's avatar rnephew Committed by Commit bot

[BattOr] Initialize BattOr before getting firmware git hash.

BUG=679375

Review-Url: https://codereview.chromium.org/2622003005
Cr-Commit-Position: refs/heads/master@{#443318}
parent 815414a7
...@@ -198,7 +198,8 @@ void BattOrAgent::OnConnectionOpened(bool success) { ...@@ -198,7 +198,8 @@ void BattOrAgent::OnConnectionOpened(bool success) {
PerformAction(Action::SEND_CURRENT_SAMPLE_REQUEST); PerformAction(Action::SEND_CURRENT_SAMPLE_REQUEST);
return; return;
case Command::GET_FIRMWARE_GIT_HASH: case Command::GET_FIRMWARE_GIT_HASH:
PerformAction(Action::SEND_GIT_HASH_REQUEST); num_init_attempts_ = 1;
PerformAction(Action::SEND_INIT);
return; return;
case Command::INVALID: case Command::INVALID:
NOTREACHED(); NOTREACHED();
...@@ -317,8 +318,17 @@ void BattOrAgent::OnMessageRead(bool success, ...@@ -317,8 +318,17 @@ void BattOrAgent::OnMessageRead(bool success,
return; return;
} }
PerformAction(Action::SEND_SET_GAIN); switch (command_) {
return; case Command::START_TRACING:
PerformAction(Action::SEND_SET_GAIN);
return;
case Command::GET_FIRMWARE_GIT_HASH:
PerformAction(Action::SEND_GIT_HASH_REQUEST);
return;
default:
CompleteCommand(BATTOR_ERROR_UNEXPECTED_MESSAGE);
return;
}
case Action::READ_SET_GAIN_ACK: case Action::READ_SET_GAIN_ACK:
if (!IsAckOfControlCommand(type, BATTOR_CONTROL_MESSAGE_TYPE_SET_GAIN, if (!IsAckOfControlCommand(type, BATTOR_CONTROL_MESSAGE_TYPE_SET_GAIN,
......
...@@ -300,6 +300,15 @@ class BattOrAgentTest : public testing::Test, public BattOrAgent::Listener { ...@@ -300,6 +300,15 @@ class BattOrAgentTest : public testing::Test, public BattOrAgent::Listener {
if (end_state == BattOrAgentState::CONNECTED) if (end_state == BattOrAgentState::CONNECTED)
return; return;
OnBytesSent(true);
if (end_state == BattOrAgentState::INIT_SENT)
return;
OnMessageRead(true, BATTOR_MESSAGE_TYPE_CONTROL_ACK,
ToCharVector(kInitAck));
if (end_state == BattOrAgentState::INIT_ACKED)
return;
OnBytesSent(true); OnBytesSent(true);
if (end_state == BattOrAgentState::GIT_FIRMWARE_HASH_REQUEST_SENT) if (end_state == BattOrAgentState::GIT_FIRMWARE_HASH_REQUEST_SENT)
return; return;
...@@ -1027,4 +1036,40 @@ TEST_F(BattOrAgentTest, GetFirmwareGitHashFailsIfReadHasWrongType) { ...@@ -1027,4 +1036,40 @@ TEST_F(BattOrAgentTest, GetFirmwareGitHashFailsIfReadHasWrongType) {
EXPECT_TRUE(IsCommandComplete()); EXPECT_TRUE(IsCommandComplete());
EXPECT_EQ(BATTOR_ERROR_UNEXPECTED_MESSAGE, GetCommandError()); EXPECT_EQ(BATTOR_ERROR_UNEXPECTED_MESSAGE, GetCommandError());
} }
TEST_F(BattOrAgentTest, GetFirmwareGitHashFailsIfInitSendFails) {
RunGetFirmwareGitHashTo(BattOrAgentState::CONNECTED);
OnBytesSent(false);
EXPECT_TRUE(IsCommandComplete());
EXPECT_EQ(BATTOR_ERROR_SEND_ERROR, GetCommandError());
}
TEST_F(BattOrAgentTest, GetFirmwareGitHashFailsIfInitAckReadFails) {
RunGetFirmwareGitHashTo(BattOrAgentState::INIT_SENT);
for (int i =0; i < 21; i++) {
OnMessageRead(false, BATTOR_MESSAGE_TYPE_CONTROL_ACK, nullptr);
// Bytes will be sent because INIT will be retried.
OnBytesSent(true);
}
EXPECT_TRUE(IsCommandComplete());
EXPECT_EQ(BATTOR_ERROR_TOO_MANY_INIT_RETRIES, GetCommandError());
}
TEST_F(BattOrAgentTest, GetFirmwareGithashFailsIfInitWrongAckRead) {
RunGetFirmwareGitHashTo(BattOrAgentState::INIT_SENT);
for (int i = 0; i < 21; i++) {
OnMessageRead(true, BATTOR_MESSAGE_TYPE_CONTROL_ACK,
ToCharVector(kStartTracingAck));
// Bytes will be sent because INIT will be retried.
OnBytesSent(true);
}
EXPECT_TRUE(IsCommandComplete());
EXPECT_EQ(BATTOR_ERROR_TOO_MANY_INIT_RETRIES, GetCommandError());
}
} // namespace battor } // namespace battor
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment