| 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 0239649d2c972dfdf8de289657476e957dbdb38b..75ec3015930070b1505461e0eacc8a16b44658be 100644
|
| --- a/tools/battor_agent/battor_agent_unittest.cc
|
| +++ b/tools/battor_agent/battor_agent_unittest.cc
|
| @@ -2,6 +2,8 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| +#include <memory>
|
| +
|
| #include "tools/battor_agent/battor_agent.h"
|
|
|
| #include "base/test/test_simple_task_runner.h"
|
| @@ -117,6 +119,13 @@ class BattOrAgentTest : public testing::Test, public BattOrAgent::Listener {
|
| command_error_ = error;
|
| }
|
|
|
| + void OnGetFirmwareGitHashComplete(const std::string& firmware_git_hash,
|
| + BattOrError error) override {
|
| + is_command_complete_ = true;
|
| + command_error_ = error;
|
| + firmware_git_hash_ = firmware_git_hash;
|
| + }
|
| +
|
| void OnBytesSent(bool success) {
|
| agent_->OnBytesSent(success);
|
| task_runner_->RunUntilIdle();
|
| @@ -159,6 +168,10 @@ class BattOrAgentTest : public testing::Test, public BattOrAgent::Listener {
|
| // States required to RecordClockSyncMarker.
|
| CURRENT_SAMPLE_REQUEST_SENT,
|
| RECORD_CLOCK_SYNC_MARKER_COMPLETE,
|
| +
|
| + // States required to GetFirmwareGitHash.
|
| + GIT_FIRMWARE_HASH_REQUEST_SENT,
|
| + READ_GIT_HASH_RECEIVED,
|
| };
|
|
|
| // Runs BattOrAgent::StartTracing until it reaches the specified state by
|
| @@ -273,6 +286,32 @@ class BattOrAgentTest : public testing::Test, public BattOrAgent::Listener {
|
| ToCharVector(current_sample));
|
| }
|
|
|
| + // Runs BattOrAgent::GetFirmwareGitHash until it reaches the specified
|
| + // state by feeding it the callbacks it needs to progress.
|
| + void RunGetFirmwareGitHashTo(BattOrAgentState end_state) {
|
| + is_command_complete_ = false;
|
| +
|
| + GetAgent()->GetFirmwareGitHash();
|
| + GetTaskRunner()->RunUntilIdle();
|
| +
|
| + GetAgent()->OnConnectionOpened(true);
|
| + GetTaskRunner()->RunUntilIdle();
|
| +
|
| + if (end_state == BattOrAgentState::CONNECTED)
|
| + return;
|
| +
|
| + OnBytesSent(true);
|
| + if (end_state == BattOrAgentState::GIT_FIRMWARE_HASH_REQUEST_SENT)
|
| + return;
|
| +
|
| + DCHECK(end_state == BattOrAgentState::READ_GIT_HASH_RECEIVED);
|
| +
|
| + std::unique_ptr<std::vector<char>> firmware_git_hash_vector(
|
| + new std::vector<char>{'G', 'I', 'T', 'H', 'A', 'S', 'H'});
|
| + OnMessageRead(true, BATTOR_MESSAGE_TYPE_CONTROL_ACK,
|
| + std::move(firmware_git_hash_vector));
|
| + }
|
| +
|
| TestableBattOrAgent* GetAgent() { return agent_.get(); }
|
|
|
| scoped_refptr<base::TestSimpleTaskRunner> GetTaskRunner() {
|
| @@ -282,6 +321,7 @@ class BattOrAgentTest : public testing::Test, public BattOrAgent::Listener {
|
| bool IsCommandComplete() { return is_command_complete_; }
|
| BattOrError GetCommandError() { return command_error_; }
|
| std::string GetTrace() { return trace_; }
|
| + std::string GetGitHash() { return firmware_git_hash_; }
|
|
|
| private:
|
| scoped_refptr<base::TestSimpleTaskRunner> task_runner_;
|
| @@ -292,6 +332,7 @@ class BattOrAgentTest : public testing::Test, public BattOrAgent::Listener {
|
| bool is_command_complete_;
|
| BattOrError command_error_;
|
| std::string trace_;
|
| + std::string firmware_git_hash_;
|
| };
|
|
|
| TEST_F(BattOrAgentTest, StartTracing) {
|
| @@ -893,4 +934,32 @@ TEST_F(BattOrAgentTest,
|
| EXPECT_EQ(BATTOR_ERROR_UNEXPECTED_MESSAGE, GetCommandError());
|
| }
|
|
|
| +TEST_F(BattOrAgentTest, GetFirmwareGitHash) {
|
| + RunGetFirmwareGitHashTo(BattOrAgentState::READ_GIT_HASH_RECEIVED);
|
| + EXPECT_TRUE(IsCommandComplete());
|
| + EXPECT_EQ(BATTOR_ERROR_NONE, GetCommandError());
|
| + EXPECT_EQ("GITHASH", GetGitHash());
|
| +}
|
| +
|
| +TEST_F(BattOrAgentTest, GetFirmwareGitHashFailsWithoutConnection) {
|
| + GetAgent()->GetFirmwareGitHash();
|
| + GetTaskRunner()->RunUntilIdle();
|
| +
|
| + GetAgent()->OnConnectionOpened(false);
|
| + GetTaskRunner()->RunUntilIdle();
|
| +
|
| + EXPECT_TRUE(IsCommandComplete());
|
| + EXPECT_EQ(BATTOR_ERROR_CONNECTION_FAILED, GetCommandError());
|
| +}
|
| +
|
| +TEST_F(BattOrAgentTest, GetFirmwareGitHashFailsIfReadHasWrongType) {
|
| + RunGetFirmwareGitHashTo(BattOrAgentState::GIT_FIRMWARE_HASH_REQUEST_SENT);
|
| +
|
| + uint32_t current_sample = 1;
|
| + OnMessageRead(true, BATTOR_MESSAGE_TYPE_CONTROL,
|
| + ToCharVector(current_sample));
|
| +
|
| + EXPECT_TRUE(IsCommandComplete());
|
| + EXPECT_EQ(BATTOR_ERROR_UNEXPECTED_MESSAGE, GetCommandError());
|
| +}
|
| } // namespace battor
|
|
|