Chromium Code Reviews| 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 378 GetAgent()->StartTracing(); | 387 GetAgent()->StartTracing(); |
| 379 GetTaskRunner()->RunUntilIdle(); | 388 GetTaskRunner()->RunUntilIdle(); |
| 380 | 389 |
| 381 GetAgent()->OnConnectionOpened(false); | 390 GetAgent()->OnConnectionOpened(false); |
| 382 GetTaskRunner()->RunUntilIdle(); | 391 GetTaskRunner()->RunUntilIdle(); |
| 383 | 392 |
| 384 EXPECT_TRUE(IsCommandComplete()); | 393 EXPECT_TRUE(IsCommandComplete()); |
| 385 EXPECT_EQ(BATTOR_ERROR_CONNECTION_FAILED, GetCommandError()); | 394 EXPECT_EQ(BATTOR_ERROR_CONNECTION_FAILED, GetCommandError()); |
| 386 } | 395 } |
| 387 | 396 |
| 388 TEST_F(BattOrAgentTest, StartTracingFailsIfInitSendFails) { | 397 TEST_F(BattOrAgentTest, StartTracingFailsIfInitSendFails) { |
|
charliea (OOO until 10-5)
2017/01/12 17:05:50
Seems like we probably want a similar test for get
rnephew (Reviews Here)
2017/01/12 17:53:21
Done.
| |
| 389 RunStartTracingTo(BattOrAgentState::CONNECTED); | 398 RunStartTracingTo(BattOrAgentState::CONNECTED); |
| 390 OnBytesSent(false); | 399 OnBytesSent(false); |
| 391 | 400 |
| 392 EXPECT_TRUE(IsCommandComplete()); | 401 EXPECT_TRUE(IsCommandComplete()); |
| 393 EXPECT_EQ(BATTOR_ERROR_SEND_ERROR, GetCommandError()); | 402 EXPECT_EQ(BATTOR_ERROR_SEND_ERROR, GetCommandError()); |
| 394 } | 403 } |
| 395 | 404 |
| 396 TEST_F(BattOrAgentTest, StartTracingFailsIfInitAckReadFails) { | 405 TEST_F(BattOrAgentTest, StartTracingFailsIfInitAckReadFails) { |
|
charliea (OOO until 10-5)
2017/01/12 17:05:50
same
rnephew (Reviews Here)
2017/01/12 17:53:21
Done.
| |
| 397 RunStartTracingTo(BattOrAgentState::INIT_SENT); | 406 RunStartTracingTo(BattOrAgentState::INIT_SENT); |
| 398 | 407 |
| 399 for (int i = 0; i < 21; i++) { | 408 for (int i = 0; i < 21; i++) { |
| 400 OnMessageRead(false, BATTOR_MESSAGE_TYPE_CONTROL_ACK, nullptr); | 409 OnMessageRead(false, BATTOR_MESSAGE_TYPE_CONTROL_ACK, nullptr); |
| 401 | 410 |
| 402 // Bytes will be sent because INIT will be retried. | 411 // Bytes will be sent because INIT will be retried. |
| 403 OnBytesSent(true); | 412 OnBytesSent(true); |
| 404 } | 413 } |
| 405 | 414 |
| 406 EXPECT_TRUE(IsCommandComplete()); | 415 EXPECT_TRUE(IsCommandComplete()); |
| 407 EXPECT_EQ(BATTOR_ERROR_TOO_MANY_INIT_RETRIES, GetCommandError()); | 416 EXPECT_EQ(BATTOR_ERROR_TOO_MANY_INIT_RETRIES, GetCommandError()); |
| 408 } | 417 } |
| 409 | 418 |
| 410 TEST_F(BattOrAgentTest, StartTracingFailsIfInitWrongAckRead) { | 419 TEST_F(BattOrAgentTest, StartTracingFailsIfInitWrongAckRead) { |
|
charliea (OOO until 10-5)
2017/01/12 17:05:50
same
rnephew (Reviews Here)
2017/01/12 17:53:21
Done.
| |
| 411 RunStartTracingTo(BattOrAgentState::INIT_SENT); | 420 RunStartTracingTo(BattOrAgentState::INIT_SENT); |
| 412 | 421 |
| 413 for (int i = 0; i < 21; i++) { | 422 for (int i = 0; i < 21; i++) { |
| 414 OnMessageRead(true, BATTOR_MESSAGE_TYPE_CONTROL_ACK, | 423 OnMessageRead(true, BATTOR_MESSAGE_TYPE_CONTROL_ACK, |
| 415 ToCharVector(kStartTracingAck)); | 424 ToCharVector(kStartTracingAck)); |
| 416 | 425 |
| 417 // Bytes will be sent because INIT will be retried. | 426 // Bytes will be sent because INIT will be retried. |
| 418 OnBytesSent(true); | 427 OnBytesSent(true); |
| 419 } | 428 } |
| 420 | 429 |
| (...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 } |
| 1030 } // namespace battor | 1039 } // namespace battor |
| OLD | NEW |