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

Unified Diff: tools/battor_agent/battor_agent_unittest.cc

Issue 1991403002: [battor agent] Fix the init sequence so it retries inits instead of resets. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed unit tests that were broken by this patch Created 4 years, 6 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') | tools/battor_agent/battor_connection.h » ('j') | 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 008877514f01e2e3baf99b55b94bd20c0a25ce37..7efb499c084c28a9a21dc9a932d44c0850f8e27c 100644
--- a/tools/battor_agent/battor_agent_unittest.cc
+++ b/tools/battor_agent/battor_agent_unittest.cc
@@ -67,6 +67,7 @@ class MockBattOrConnection : public BattOrConnection {
const void* buffer,
size_t bytes_to_send));
MOCK_METHOD1(ReadMessage, void(BattOrMessageType type));
+ MOCK_METHOD0(CancelReadMessage, void());
MOCK_METHOD0(Flush, void());
private:
@@ -142,7 +143,6 @@ class BattOrAgentTest : public testing::Test, public BattOrAgent::Listener {
CONNECTED,
// States required to StartTracing.
- RESET_SENT,
INIT_SENT,
INIT_ACKED,
SET_GAIN_SENT,
@@ -176,10 +176,6 @@ class BattOrAgentTest : public testing::Test, public BattOrAgent::Listener {
return;
OnBytesSent(true);
- if (end_state == BattOrAgentState::RESET_SENT)
- return;
-
- OnBytesSent(true);
if (end_state == BattOrAgentState::INIT_SENT)
return;
@@ -302,12 +298,6 @@ TEST_F(BattOrAgentTest, StartTracing) {
testing::InSequence s;
EXPECT_CALL(*GetAgent()->GetConnection(), Open());
- BattOrControlMessage reset_msg{BATTOR_CONTROL_MESSAGE_TYPE_RESET, 0, 0};
- EXPECT_CALL(
- *GetAgent()->GetConnection(),
- SendBytes(BATTOR_MESSAGE_TYPE_CONTROL,
- BufferEq(&reset_msg, sizeof(reset_msg)), sizeof(reset_msg)));
-
EXPECT_CALL(*GetAgent()->GetConnection(), Flush());
BattOrControlMessage init_msg{BATTOR_CONTROL_MESSAGE_TYPE_INIT, 0, 0};
EXPECT_CALL(
@@ -363,7 +353,7 @@ TEST_F(BattOrAgentTest, StartTracingFailsIfResetSendFails) {
}
TEST_F(BattOrAgentTest, StartTracingFailsIfInitSendFails) {
- RunStartTracingTo(BattOrAgentState::RESET_SENT);
+ RunStartTracingTo(BattOrAgentState::CONNECTED);
OnBytesSent(false);
EXPECT_TRUE(IsCommandComplete());
@@ -372,23 +362,35 @@ TEST_F(BattOrAgentTest, StartTracingFailsIfInitSendFails) {
TEST_F(BattOrAgentTest, StartTracingFailsIfInitAckReadFails) {
RunStartTracingTo(BattOrAgentState::INIT_SENT);
- OnMessageRead(false, BATTOR_MESSAGE_TYPE_CONTROL_ACK, nullptr);
+
+ for (int i = 0; i < 20; 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_RECEIVE_ERROR, GetCommandError());
+ EXPECT_EQ(BATTOR_ERROR_TOO_MANY_INIT_RETRIES, GetCommandError());
}
TEST_F(BattOrAgentTest, StartTracingFailsIfInitWrongAckRead) {
RunStartTracingTo(BattOrAgentState::INIT_SENT);
- OnMessageRead(true, BATTOR_MESSAGE_TYPE_CONTROL_ACK,
- ToCharVector(kStartTracingAck));
+
+ for (int i = 0; i < 20; 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_UNEXPECTED_MESSAGE, GetCommandError());
+ EXPECT_EQ(BATTOR_ERROR_TOO_MANY_INIT_RETRIES, GetCommandError());
}
TEST_F(BattOrAgentTest, StartTracingFailsIfSetGainSendFails) {
- RunStartTracingTo(BattOrAgentState::RESET_SENT);
+ RunStartTracingTo(BattOrAgentState::INIT_SENT);
OnBytesSent(false);
EXPECT_TRUE(IsCommandComplete());
@@ -413,7 +415,7 @@ TEST_F(BattOrAgentTest, StartTracingFailsIfSetGainWrongAckRead) {
}
TEST_F(BattOrAgentTest, StartTracingFailsIfStartTracingSendFails) {
- RunStartTracingTo(BattOrAgentState::RESET_SENT);
+ RunStartTracingTo(BattOrAgentState::INIT_SENT);
OnBytesSent(false);
EXPECT_TRUE(IsCommandComplete());
« no previous file with comments | « tools/battor_agent/battor_agent.cc ('k') | tools/battor_agent/battor_connection.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698