Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Unified Diff: tools/battor_agent/battor_agent_unittest.cc

Issue 2622003005: [BattOr] Initialize BattOr before getting firmware git hash. (Closed)
Patch Set: fix spelling Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/battor_agent/battor_agent.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/battor_agent/battor_agent_unittest.cc
diff --git a/tools/battor_agent/battor_agent_unittest.cc b/tools/battor_agent/battor_agent_unittest.cc
index 291c109c9ae016f7a3620e3bedbf1678cca3e631..f59452b799ae9e5bf289bbc41baef61c4ef1ab0a 100644
--- a/tools/battor_agent/battor_agent_unittest.cc
+++ b/tools/battor_agent/battor_agent_unittest.cc
@@ -301,6 +301,15 @@ class BattOrAgentTest : public testing::Test, public BattOrAgent::Listener {
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);
if (end_state == BattOrAgentState::GIT_FIRMWARE_HASH_REQUEST_SENT)
return;
@@ -1027,4 +1036,40 @@ TEST_F(BattOrAgentTest, GetFirmwareGitHashFailsIfReadHasWrongType) {
EXPECT_TRUE(IsCommandComplete());
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
« no previous file with comments | « tools/battor_agent/battor_agent.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698