OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <memory> | 5 #include <memory> |
6 | 6 |
7 #include "tools/battor_agent/battor_agent.h" | 7 #include "tools/battor_agent/battor_agent.h" |
8 | 8 |
9 #include "base/test/test_simple_task_runner.h" | 9 #include "base/test/test_simple_task_runner.h" |
10 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 GetAgent()->GetFirmwareGitHash(); | 294 GetAgent()->GetFirmwareGitHash(); |
295 GetTaskRunner()->RunUntilIdle(); | 295 GetTaskRunner()->RunUntilIdle(); |
296 | 296 |
297 GetAgent()->OnConnectionOpened(true); | 297 GetAgent()->OnConnectionOpened(true); |
298 GetTaskRunner()->RunUntilIdle(); | 298 GetTaskRunner()->RunUntilIdle(); |
299 | 299 |
300 if (end_state == BattOrAgentState::CONNECTED) | 300 if (end_state == BattOrAgentState::CONNECTED) |
301 return; | 301 return; |
302 | 302 |
303 OnBytesSent(true); | 303 OnBytesSent(true); |
| 304 if (end_state == BattOrAgentState::INIT_SENT) |
| 305 return; |
| 306 |
| 307 OnMessageRead(true, BATTOR_MESSAGE_TYPE_CONTROL_ACK, |
| 308 ToCharVector(kInitAck)); |
| 309 if (end_state == BattOrAgentState::INIT_ACKED) |
| 310 return; |
| 311 |
| 312 OnBytesSent(true); |
304 if (end_state == BattOrAgentState::GIT_FIRMWARE_HASH_REQUEST_SENT) | 313 if (end_state == BattOrAgentState::GIT_FIRMWARE_HASH_REQUEST_SENT) |
305 return; | 314 return; |
306 | 315 |
307 DCHECK(end_state == BattOrAgentState::READ_GIT_HASH_RECEIVED); | 316 DCHECK(end_state == BattOrAgentState::READ_GIT_HASH_RECEIVED); |
308 | 317 |
309 std::unique_ptr<std::vector<char>> firmware_git_hash_vector( | 318 std::unique_ptr<std::vector<char>> firmware_git_hash_vector( |
310 new std::vector<char>{'G', 'I', 'T', 'H', 'A', 'S', 'H'}); | 319 new std::vector<char>{'G', 'I', 'T', 'H', 'A', 'S', 'H'}); |
311 OnMessageRead(true, BATTOR_MESSAGE_TYPE_CONTROL_ACK, | 320 OnMessageRead(true, BATTOR_MESSAGE_TYPE_CONTROL_ACK, |
312 std::move(firmware_git_hash_vector)); | 321 std::move(firmware_git_hash_vector)); |
313 } | 322 } |
(...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1020 TEST_F(BattOrAgentTest, GetFirmwareGitHashFailsIfReadHasWrongType) { | 1029 TEST_F(BattOrAgentTest, GetFirmwareGitHashFailsIfReadHasWrongType) { |
1021 RunGetFirmwareGitHashTo(BattOrAgentState::GIT_FIRMWARE_HASH_REQUEST_SENT); | 1030 RunGetFirmwareGitHashTo(BattOrAgentState::GIT_FIRMWARE_HASH_REQUEST_SENT); |
1022 | 1031 |
1023 uint32_t current_sample = 1; | 1032 uint32_t current_sample = 1; |
1024 OnMessageRead(true, BATTOR_MESSAGE_TYPE_CONTROL, | 1033 OnMessageRead(true, BATTOR_MESSAGE_TYPE_CONTROL, |
1025 ToCharVector(current_sample)); | 1034 ToCharVector(current_sample)); |
1026 | 1035 |
1027 EXPECT_TRUE(IsCommandComplete()); | 1036 EXPECT_TRUE(IsCommandComplete()); |
1028 EXPECT_EQ(BATTOR_ERROR_UNEXPECTED_MESSAGE, GetCommandError()); | 1037 EXPECT_EQ(BATTOR_ERROR_UNEXPECTED_MESSAGE, GetCommandError()); |
1029 } | 1038 } |
| 1039 |
| 1040 TEST_F(BattOrAgentTest, GetFirmwareGitHashFailsIfInitSendFails) { |
| 1041 RunGetFirmwareGitHashTo(BattOrAgentState::CONNECTED); |
| 1042 OnBytesSent(false); |
| 1043 |
| 1044 EXPECT_TRUE(IsCommandComplete()); |
| 1045 EXPECT_EQ(BATTOR_ERROR_SEND_ERROR, GetCommandError()); |
| 1046 } |
| 1047 |
| 1048 TEST_F(BattOrAgentTest, GetFirmwareGitHashFailsIfInitAckReadFails) { |
| 1049 RunGetFirmwareGitHashTo(BattOrAgentState::INIT_SENT); |
| 1050 |
| 1051 for (int i =0; i < 21; i++) { |
| 1052 OnMessageRead(false, BATTOR_MESSAGE_TYPE_CONTROL_ACK, nullptr); |
| 1053 |
| 1054 // Bytes will be sent because INIT will be retried. |
| 1055 OnBytesSent(true); |
| 1056 } |
| 1057 |
| 1058 EXPECT_TRUE(IsCommandComplete()); |
| 1059 EXPECT_EQ(BATTOR_ERROR_TOO_MANY_INIT_RETRIES, GetCommandError()); |
| 1060 } |
| 1061 |
| 1062 TEST_F(BattOrAgentTest, GetFirmwareGithashFailsIfInitWrongAckRead) { |
| 1063 RunGetFirmwareGitHashTo(BattOrAgentState::INIT_SENT); |
| 1064 for (int i = 0; i < 21; i++) { |
| 1065 OnMessageRead(true, BATTOR_MESSAGE_TYPE_CONTROL_ACK, |
| 1066 ToCharVector(kStartTracingAck)); |
| 1067 |
| 1068 // Bytes will be sent because INIT will be retried. |
| 1069 OnBytesSent(true); |
| 1070 } |
| 1071 |
| 1072 EXPECT_TRUE(IsCommandComplete()); |
| 1073 EXPECT_EQ(BATTOR_ERROR_TOO_MANY_INIT_RETRIES, GetCommandError()); |
| 1074 } |
1030 } // namespace battor | 1075 } // namespace battor |
OLD | NEW |