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

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 comment 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..8b2358bfb0aac33164d8b9b19496817084c1d543 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(
@@ -354,16 +344,8 @@ TEST_F(BattOrAgentTest, StartTracingFailsWithoutConnection) {
EXPECT_EQ(BATTOR_ERROR_CONNECTION_FAILED, GetCommandError());
}
-TEST_F(BattOrAgentTest, StartTracingFailsIfResetSendFails) {
- RunStartTracingTo(BattOrAgentState::CONNECTED);
- OnBytesSent(false);
-
- EXPECT_TRUE(IsCommandComplete());
- EXPECT_EQ(BATTOR_ERROR_SEND_ERROR, GetCommandError());
-}
-
TEST_F(BattOrAgentTest, StartTracingFailsIfInitSendFails) {
- RunStartTracingTo(BattOrAgentState::RESET_SENT);
+ RunStartTracingTo(BattOrAgentState::CONNECTED);
OnBytesSent(false);
EXPECT_TRUE(IsCommandComplete());
@@ -372,23 +354,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 +407,7 @@ TEST_F(BattOrAgentTest, StartTracingFailsIfSetGainWrongAckRead) {
}
TEST_F(BattOrAgentTest, StartTracingFailsIfStartTracingSendFails) {
- RunStartTracingTo(BattOrAgentState::RESET_SENT);
+ RunStartTracingTo(BattOrAgentState::INIT_SENT);
OnBytesSent(false);
EXPECT_TRUE(IsCommandComplete());
@@ -436,6 +430,32 @@ TEST_F(BattOrAgentTest, StartTracingFailsIfStartTracingWrongAckRead) {
EXPECT_EQ(BATTOR_ERROR_UNEXPECTED_MESSAGE, GetCommandError());
}
+TEST_F(BattOrAgentTest, StartTracingSucceedsWithOneInitFailure) {
+ RunStartTracingTo(BattOrAgentState::INIT_SENT);
+
+ // Send some samples instead of an INIT ACK. This will force an INIT retry.
+ BattOrFrameHeader frame_header{1, 3 * sizeof(RawBattOrSample)};
+ RawBattOrSample frame[] = {
+ RawBattOrSample{1, 1}, RawBattOrSample{2, 2}, RawBattOrSample{3, 3},
+ };
+ OnMessageRead(true, BATTOR_MESSAGE_TYPE_SAMPLES,
+ CreateFrame(frame_header, frame, 3));
+
+ OnBytesSent(true);
+ OnMessageRead(true, BATTOR_MESSAGE_TYPE_CONTROL_ACK, ToCharVector(kInitAck));
+
+ OnBytesSent(true);
+ OnMessageRead(true, BATTOR_MESSAGE_TYPE_CONTROL_ACK,
+ ToCharVector(kSetGainAck));
+
+ OnBytesSent(true);
+ OnMessageRead(true, BATTOR_MESSAGE_TYPE_CONTROL_ACK,
+ ToCharVector(kStartTracingAck));
+
+ EXPECT_TRUE(IsCommandComplete());
+ EXPECT_EQ(BATTOR_ERROR_NONE, GetCommandError());
+}
+
TEST_F(BattOrAgentTest, StopTracing) {
testing::InSequence s;
EXPECT_CALL(*GetAgent()->GetConnection(), Open());
« 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