blob: f5abf6aa5066bc4c34400d07e3b9bac0721cefef [file] [log] [blame]
// Copyright 2021 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <vector>
#include <base/macros.h>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <metrics/metrics_library_mock.h>
#include "hps/hps_metrics.h"
using ::testing::_;
using ::testing::Ge;
using ::testing::Le;
namespace hps {
class HpsMetricsTest : public testing::Test {
protected:
HpsMetricsTest() {
hps_metrics_.SetMetricsLibraryForTesting(
std::make_unique<MetricsLibraryMock>());
}
HpsMetricsTest(const HpsMetricsTest&) = delete;
HpsMetricsTest& operator=(const HpsMetricsTest&) = delete;
~HpsMetricsTest() override = default;
MetricsLibraryMock* GetMetricsLibraryMock() {
return static_cast<MetricsLibraryMock*>(
hps_metrics_.metrics_library_for_testing());
}
HpsMetrics hps_metrics_;
};
TEST_F(HpsMetricsTest, SendHpsTurnOnResult) {
std::vector<HpsTurnOnResult> all_results = {
HpsTurnOnResult::kSuccess, HpsTurnOnResult::kMcuVersionMismatch,
HpsTurnOnResult::kSpiNotVerified, HpsTurnOnResult::kMcuNotVerified,
HpsTurnOnResult::kStage1NotStarted, HpsTurnOnResult::kApplNotStarted,
HpsTurnOnResult::kNoResponse, HpsTurnOnResult::kTimeout,
HpsTurnOnResult::kBadMagic, HpsTurnOnResult::kFault,
HpsTurnOnResult::kMcuUpdateFailure, HpsTurnOnResult::kSpiUpdateFailure,
};
// Check that we have all the values of the enum
ASSERT_EQ(all_results.size(),
static_cast<int>(HpsTurnOnResult::kMaxValue) + 1);
constexpr int kDuration = 49;
for (auto result : all_results) {
switch (result) {
case HpsTurnOnResult::kSuccess:
EXPECT_CALL(*GetMetricsLibraryMock(),
SendToUMA(kHpsBootSuccessDuration, kDuration, _, _, _))
.Times(1);
break;
case HpsTurnOnResult::kMcuVersionMismatch:
case HpsTurnOnResult::kSpiNotVerified:
case HpsTurnOnResult::kMcuNotVerified:
break;
case HpsTurnOnResult::kStage1NotStarted:
case HpsTurnOnResult::kApplNotStarted:
case HpsTurnOnResult::kNoResponse:
case HpsTurnOnResult::kTimeout:
case HpsTurnOnResult::kBadMagic:
case HpsTurnOnResult::kFault:
case HpsTurnOnResult::kMcuUpdateFailure:
case HpsTurnOnResult::kSpiUpdateFailure:
EXPECT_CALL(*GetMetricsLibraryMock(),
SendToUMA(kHpsBootFailedDuration, kDuration, _, _, _))
.Times(1);
break;
}
EXPECT_CALL(*GetMetricsLibraryMock(),
SendEnumToUMA(kHpsTurnOnResult, static_cast<int>(result), _))
.Times(1);
hps_metrics_.SendHpsTurnOnResult(
result, base::TimeDelta::FromMilliseconds(kDuration));
}
}
} // namespace hps