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 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 571 SendBytes(BATTOR_MESSAGE_TYPE_CONTROL, | 571 SendBytes(BATTOR_MESSAGE_TYPE_CONTROL, |
| 572 BufferEq(&request_samples_msg, sizeof(request_samples_msg)), | 572 BufferEq(&request_samples_msg, sizeof(request_samples_msg)), |
| 573 sizeof(request_samples_msg))); | 573 sizeof(request_samples_msg))); |
| 574 | 574 |
| 575 // We send the agent four frames: a calibration frame, and two real frames, | 575 // We send the agent four frames: a calibration frame, and two real frames, |
| 576 // and one zero-length frame to indicate that we're done. | 576 // and one zero-length frame to indicate that we're done. |
| 577 EXPECT_CALL(*GetAgent()->GetConnection(), | 577 EXPECT_CALL(*GetAgent()->GetConnection(), |
| 578 ReadMessage(BATTOR_MESSAGE_TYPE_SAMPLES)) | 578 ReadMessage(BATTOR_MESSAGE_TYPE_SAMPLES)) |
| 579 .Times(4); | 579 .Times(4); |
| 580 | 580 |
| 581 // Ensure that the proactive reset message is be sent after the trace, | |
| 582 BattOrControlMessage reset_msg{BATTOR_CONTROL_MESSAGE_TYPE_RESET, 0, 0}; | |
| 583 EXPECT_CALL( | |
| 584 *GetAgent()->GetConnection(), | |
| 585 SendBytes(BATTOR_MESSAGE_TYPE_CONTROL, | |
| 586 BufferEq(&reset_msg, sizeof(reset_msg)), sizeof(reset_msg))); | |
| 587 | |
| 581 GetAgent()->StopTracing(); | 588 GetAgent()->StopTracing(); |
| 589 | |
| 582 RunStopTracingTo(BattOrAgentState::SAMPLES_REQUEST_SENT); | 590 RunStopTracingTo(BattOrAgentState::SAMPLES_REQUEST_SENT); |
| 583 | 591 |
| 584 // Send the calibration frame. | 592 // Send the calibration frame. |
| 585 BattOrFrameHeader cal_frame_header{0, 2 * sizeof(RawBattOrSample)}; | 593 BattOrFrameHeader cal_frame_header{0, 2 * sizeof(RawBattOrSample)}; |
| 586 RawBattOrSample cal_frame[] = { | 594 RawBattOrSample cal_frame[] = { |
| 587 RawBattOrSample{1, 1}, RawBattOrSample{2, 2}, | 595 RawBattOrSample{1, 1}, RawBattOrSample{2, 2}, |
| 588 }; | 596 }; |
| 589 OnMessageRead(true, BATTOR_MESSAGE_TYPE_SAMPLES, | 597 OnMessageRead(true, BATTOR_MESSAGE_TYPE_SAMPLES, |
| 590 CreateFrame(cal_frame_header, cal_frame, 2)); | 598 CreateFrame(cal_frame_header, cal_frame, 2)); |
| 591 | 599 |
| 592 // Send the two real data frames. | 600 // Send the two real data frames. |
| 593 BattOrFrameHeader frame_header1{1, 3 * sizeof(RawBattOrSample)}; | 601 BattOrFrameHeader frame_header1{1, 3 * sizeof(RawBattOrSample)}; |
| 594 RawBattOrSample frame1[] = { | 602 RawBattOrSample frame1[] = { |
| 595 RawBattOrSample{1, 1}, RawBattOrSample{2, 2}, RawBattOrSample{3, 3}, | 603 RawBattOrSample{1, 1}, RawBattOrSample{2, 2}, RawBattOrSample{3, 3}, |
| 596 }; | 604 }; |
| 597 OnMessageRead(true, BATTOR_MESSAGE_TYPE_SAMPLES, | 605 OnMessageRead(true, BATTOR_MESSAGE_TYPE_SAMPLES, |
| 598 CreateFrame(frame_header1, frame1, 3)); | 606 CreateFrame(frame_header1, frame1, 3)); |
| 599 | 607 |
| 600 BattOrFrameHeader frame_header2{2, 1 * sizeof(RawBattOrSample)}; | 608 BattOrFrameHeader frame_header2{2, 1 * sizeof(RawBattOrSample)}; |
| 601 RawBattOrSample frame2[] = {RawBattOrSample{1, 1}}; | 609 RawBattOrSample frame2[] = {RawBattOrSample{1, 1}}; |
| 602 OnMessageRead(true, BATTOR_MESSAGE_TYPE_SAMPLES, | 610 OnMessageRead(true, BATTOR_MESSAGE_TYPE_SAMPLES, |
| 603 CreateFrame(frame_header2, frame2, 1)); | 611 CreateFrame(frame_header2, frame2, 1)); |
| 604 | 612 |
| 605 // Send an empty last frame to indicate that we're done. | 613 // Send an empty last frame to indicate that we're done. |
| 606 BattOrFrameHeader frame_header3{3, 0 * sizeof(RawBattOrSample)}; | 614 BattOrFrameHeader frame_header3{3, 0 * sizeof(RawBattOrSample)}; |
| 607 OnMessageRead(true, BATTOR_MESSAGE_TYPE_SAMPLES, | 615 OnMessageRead(true, BATTOR_MESSAGE_TYPE_SAMPLES, |
| 608 CreateFrame(frame_header3, nullptr, 0)); | 616 CreateFrame(frame_header3, nullptr, 0)); |
| 609 | 617 |
| 618 // Bytes will be sent beause the proactive RESET message will be sent. | |
| 619 OnBytesSent(true); | |
| 620 | |
| 610 EXPECT_TRUE(IsCommandComplete()); | 621 EXPECT_TRUE(IsCommandComplete()); |
| 611 EXPECT_EQ(BATTOR_ERROR_NONE, GetCommandError()); | 622 EXPECT_EQ(BATTOR_ERROR_NONE, GetCommandError()); |
| 612 EXPECT_EQ( | 623 EXPECT_EQ( |
| 613 "# BattOr\n# voltage_range [-2401.8, 2398.2] mV\n# " | 624 "# BattOr\n# voltage_range [-2401.8, 2398.2] mV\n# " |
| 614 "current_range [-1200.9, 1199.1] mA\n" | 625 "current_range [-1200.9, 1199.1] mA\n" |
| 615 "# sample_rate 1000 Hz, gain 1.0x\n" | 626 "# sample_rate 1000 Hz, gain 1.0x\n" |
| 616 "0.00 -0.3 -0.6\n1.00 0.3 0.6\n2.00 0.9 1.8\n3.00 -0.3 -0.6\n", | 627 "0.00 -0.3 -0.6\n1.00 0.3 0.6\n2.00 0.9 1.8\n3.00 -0.3 -0.6\n", |
| 617 GetTrace()); | 628 GetTrace()); |
| 618 } | 629 } |
| 619 | 630 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 681 RunStopTracingTo(BattOrAgentState::SAMPLES_REQUEST_SENT); | 692 RunStopTracingTo(BattOrAgentState::SAMPLES_REQUEST_SENT); |
| 682 // Make a read fail in order to make sure that the agent will retry. | 693 // Make a read fail in order to make sure that the agent will retry. |
| 683 OnMessageRead(false, BATTOR_MESSAGE_TYPE_SAMPLES, nullptr); | 694 OnMessageRead(false, BATTOR_MESSAGE_TYPE_SAMPLES, nullptr); |
| 684 | 695 |
| 685 RunStopTracingTo(BattOrAgentState::SAMPLES_REQUEST_SENT); | 696 RunStopTracingTo(BattOrAgentState::SAMPLES_REQUEST_SENT); |
| 686 | 697 |
| 687 EXPECT_FALSE(IsCommandComplete()); | 698 EXPECT_FALSE(IsCommandComplete()); |
| 688 | 699 |
| 689 RunStopTracingTo(BattOrAgentState::SAMPLES_END_FRAME_RECEIVED); | 700 RunStopTracingTo(BattOrAgentState::SAMPLES_END_FRAME_RECEIVED); |
| 690 | 701 |
| 702 // Bytes will be sent beause the proactive RESET message will be sent. | |
| 703 OnBytesSent(true); | |
| 704 | |
| 691 EXPECT_TRUE(IsCommandComplete()); | 705 EXPECT_TRUE(IsCommandComplete()); |
| 692 EXPECT_EQ(BATTOR_ERROR_NONE, GetCommandError()); | 706 EXPECT_EQ(BATTOR_ERROR_NONE, GetCommandError()); |
| 693 } | 707 } |
| 694 | 708 |
| 695 TEST_F(BattOrAgentTest, StopTracingSucceedsAfterDataFrameReadFailure) { | 709 TEST_F(BattOrAgentTest, StopTracingSucceedsAfterDataFrameReadFailure) { |
| 696 GetAgent()->StopTracing(); | 710 GetAgent()->StopTracing(); |
| 697 | 711 |
| 698 RunStopTracingTo(BattOrAgentState::CALIBRATION_FRAME_RECEIVED); | 712 RunStopTracingTo(BattOrAgentState::CALIBRATION_FRAME_RECEIVED); |
| 699 | 713 |
| 700 // Make a read fail in order to make sure that the agent will retry. | 714 // Make a read fail in order to make sure that the agent will retry. |
| 701 OnMessageRead(false, BATTOR_MESSAGE_TYPE_SAMPLES, nullptr); | 715 OnMessageRead(false, BATTOR_MESSAGE_TYPE_SAMPLES, nullptr); |
| 702 | 716 |
| 703 EXPECT_FALSE(IsCommandComplete()); | 717 EXPECT_FALSE(IsCommandComplete()); |
| 704 | 718 |
| 705 RunStopTracingTo(BattOrAgentState::SAMPLES_END_FRAME_RECEIVED); | 719 RunStopTracingTo(BattOrAgentState::SAMPLES_END_FRAME_RECEIVED); |
| 706 | 720 |
| 721 // Bytes will be sent beause the proactive RESET message will be sent. | |
| 722 OnBytesSent(true); | |
| 723 | |
| 707 EXPECT_TRUE(IsCommandComplete()); | 724 EXPECT_TRUE(IsCommandComplete()); |
| 708 EXPECT_EQ(BATTOR_ERROR_NONE, GetCommandError()); | 725 EXPECT_EQ(BATTOR_ERROR_NONE, GetCommandError()); |
| 709 } | 726 } |
| 710 | 727 |
| 711 TEST_F(BattOrAgentTest, StopTracingFailsWithManyCalibrationFrameReadFailures) { | 728 TEST_F(BattOrAgentTest, StopTracingFailsWithManyCalibrationFrameReadFailures) { |
| 712 GetAgent()->StopTracing(); | 729 GetAgent()->StopTracing(); |
| 713 | 730 |
| 714 for (int i = 0; i < 9; i++) { | 731 for (int i = 0; i < 9; i++) { |
| 715 RunStopTracingTo(BattOrAgentState::SAMPLES_REQUEST_SENT); | 732 RunStopTracingTo(BattOrAgentState::SAMPLES_REQUEST_SENT); |
| 716 OnMessageRead(false, BATTOR_MESSAGE_TYPE_SAMPLES, nullptr); | 733 OnMessageRead(false, BATTOR_MESSAGE_TYPE_SAMPLES, nullptr); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 755 | 772 |
| 756 RunStopTracingTo(BattOrAgentState::CALIBRATION_FRAME_RECEIVED); | 773 RunStopTracingTo(BattOrAgentState::CALIBRATION_FRAME_RECEIVED); |
| 757 OnMessageRead(true, BATTOR_MESSAGE_TYPE_SAMPLES, | 774 OnMessageRead(true, BATTOR_MESSAGE_TYPE_SAMPLES, |
| 758 CreateFrame(frame_header, frame, 1)); | 775 CreateFrame(frame_header, frame, 1)); |
| 759 OnMessageRead(false, BATTOR_MESSAGE_TYPE_SAMPLES, nullptr); | 776 OnMessageRead(false, BATTOR_MESSAGE_TYPE_SAMPLES, nullptr); |
| 760 | 777 |
| 761 EXPECT_FALSE(IsCommandComplete()); | 778 EXPECT_FALSE(IsCommandComplete()); |
| 762 | 779 |
| 763 RunStopTracingTo(BattOrAgentState::SAMPLES_END_FRAME_RECEIVED); | 780 RunStopTracingTo(BattOrAgentState::SAMPLES_END_FRAME_RECEIVED); |
| 764 | 781 |
| 782 // Bytes will be sent beause the proactive RESET message will be sent. | |
| 783 OnBytesSent(true); | |
|
charliea (OOO until 10-5)
2017/05/24 18:41:29
I think there should be a test where everything go
| |
| 784 | |
| 765 EXPECT_TRUE(IsCommandComplete()); | 785 EXPECT_TRUE(IsCommandComplete()); |
| 766 EXPECT_EQ(BATTOR_ERROR_NONE, GetCommandError()); | 786 EXPECT_EQ(BATTOR_ERROR_NONE, GetCommandError()); |
| 767 } | 787 } |
| 768 | 788 |
| 769 TEST_F(BattOrAgentTest, StopTracingSucceedsAfterSamplesReadHasWrongType) { | 789 TEST_F(BattOrAgentTest, StopTracingSucceedsAfterSamplesReadHasWrongType) { |
| 770 GetAgent()->StopTracing(); | 790 GetAgent()->StopTracing(); |
| 771 | 791 |
| 772 RunStopTracingTo(BattOrAgentState::SAMPLES_REQUEST_SENT); | 792 RunStopTracingTo(BattOrAgentState::SAMPLES_REQUEST_SENT); |
| 773 OnMessageRead(true, BATTOR_MESSAGE_TYPE_CONTROL_ACK, ToCharVector(kInitAck)); | 793 OnMessageRead(true, BATTOR_MESSAGE_TYPE_CONTROL_ACK, ToCharVector(kInitAck)); |
| 774 | 794 |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1079 ToCharVector(kStartTracingAck)); | 1099 ToCharVector(kStartTracingAck)); |
| 1080 | 1100 |
| 1081 EXPECT_FALSE(IsCommandComplete()); | 1101 EXPECT_FALSE(IsCommandComplete()); |
| 1082 | 1102 |
| 1083 RunGetFirmwareGitHashTo(BattOrAgentState::READ_GIT_HASH_RECEIVED); | 1103 RunGetFirmwareGitHashTo(BattOrAgentState::READ_GIT_HASH_RECEIVED); |
| 1084 | 1104 |
| 1085 EXPECT_TRUE(IsCommandComplete()); | 1105 EXPECT_TRUE(IsCommandComplete()); |
| 1086 EXPECT_EQ(BATTOR_ERROR_NONE, GetCommandError()); | 1106 EXPECT_EQ(BATTOR_ERROR_NONE, GetCommandError()); |
| 1087 } | 1107 } |
| 1088 } // namespace battor | 1108 } // namespace battor |
| OLD | NEW |