blob: 187c36e78710248ca2eb0336a4e34d9eed9160b3 [file] [log] [blame]
Shawn McCarney66332cd2020-07-13 19:14:18 -05001/**
2 * Copyright © 2020 IBM Corporation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#include "error_history.hpp"
17
Shawn McCarney66332cd2020-07-13 19:14:18 -050018#include <gtest/gtest.h>
19
20using namespace phosphor::power::regulators;
21
Shawn McCarney2f1b7ba2021-03-17 10:21:14 -050022TEST(ErrorHistoryTests, ErrorType)
23{
24 EXPECT_EQ(static_cast<int>(ErrorType::internal), 3);
Shawn McCarney3f7da6e2021-08-27 14:15:11 -050025 EXPECT_EQ(static_cast<int>(ErrorType::numTypes), 8);
Shawn McCarney2f1b7ba2021-03-17 10:21:14 -050026}
27
Shawn McCarney66332cd2020-07-13 19:14:18 -050028TEST(ErrorHistoryTests, Constructor)
29{
30 ErrorHistory history{};
Shawn McCarney2f1b7ba2021-03-17 10:21:14 -050031 EXPECT_FALSE(history.wasLogged(ErrorType::configFile));
32 EXPECT_FALSE(history.wasLogged(ErrorType::dbus));
33 EXPECT_FALSE(history.wasLogged(ErrorType::i2c));
34 EXPECT_FALSE(history.wasLogged(ErrorType::internal));
35 EXPECT_FALSE(history.wasLogged(ErrorType::pmbus));
36 EXPECT_FALSE(history.wasLogged(ErrorType::writeVerification));
Shawn McCarney3f7da6e2021-08-27 14:15:11 -050037 EXPECT_FALSE(history.wasLogged(ErrorType::phaseFaultN));
38 EXPECT_FALSE(history.wasLogged(ErrorType::phaseFaultNPlus1));
Shawn McCarney66332cd2020-07-13 19:14:18 -050039}
40
41TEST(ErrorHistoryTests, Clear)
42{
43 ErrorHistory history{};
Shawn McCarney2f1b7ba2021-03-17 10:21:14 -050044
45 history.setWasLogged(ErrorType::configFile, true);
46 history.setWasLogged(ErrorType::dbus, true);
47 history.setWasLogged(ErrorType::i2c, true);
48 history.setWasLogged(ErrorType::internal, true);
49 history.setWasLogged(ErrorType::pmbus, true);
50 history.setWasLogged(ErrorType::writeVerification, true);
Shawn McCarney3f7da6e2021-08-27 14:15:11 -050051 history.setWasLogged(ErrorType::phaseFaultN, true);
52 history.setWasLogged(ErrorType::phaseFaultNPlus1, true);
Shawn McCarney2f1b7ba2021-03-17 10:21:14 -050053
54 EXPECT_TRUE(history.wasLogged(ErrorType::configFile));
55 EXPECT_TRUE(history.wasLogged(ErrorType::dbus));
56 EXPECT_TRUE(history.wasLogged(ErrorType::i2c));
57 EXPECT_TRUE(history.wasLogged(ErrorType::internal));
58 EXPECT_TRUE(history.wasLogged(ErrorType::pmbus));
59 EXPECT_TRUE(history.wasLogged(ErrorType::writeVerification));
Shawn McCarney3f7da6e2021-08-27 14:15:11 -050060 EXPECT_TRUE(history.wasLogged(ErrorType::phaseFaultN));
61 EXPECT_TRUE(history.wasLogged(ErrorType::phaseFaultNPlus1));
Shawn McCarney2f1b7ba2021-03-17 10:21:14 -050062
Shawn McCarney66332cd2020-07-13 19:14:18 -050063 history.clear();
Shawn McCarney2f1b7ba2021-03-17 10:21:14 -050064
65 EXPECT_FALSE(history.wasLogged(ErrorType::configFile));
66 EXPECT_FALSE(history.wasLogged(ErrorType::dbus));
67 EXPECT_FALSE(history.wasLogged(ErrorType::i2c));
68 EXPECT_FALSE(history.wasLogged(ErrorType::internal));
69 EXPECT_FALSE(history.wasLogged(ErrorType::pmbus));
70 EXPECT_FALSE(history.wasLogged(ErrorType::writeVerification));
Shawn McCarney3f7da6e2021-08-27 14:15:11 -050071 EXPECT_FALSE(history.wasLogged(ErrorType::phaseFaultN));
72 EXPECT_FALSE(history.wasLogged(ErrorType::phaseFaultNPlus1));
Shawn McCarney66332cd2020-07-13 19:14:18 -050073}
74
Shawn McCarney2f1b7ba2021-03-17 10:21:14 -050075TEST(ErrorHistoryTests, SetWasLogged)
Shawn McCarney66332cd2020-07-13 19:14:18 -050076{
77 ErrorHistory history{};
Shawn McCarney2f1b7ba2021-03-17 10:21:14 -050078 EXPECT_FALSE(history.wasLogged(ErrorType::dbus));
79 history.setWasLogged(ErrorType::dbus, true);
80 EXPECT_TRUE(history.wasLogged(ErrorType::dbus));
81 history.setWasLogged(ErrorType::dbus, false);
82 EXPECT_FALSE(history.wasLogged(ErrorType::dbus));
83}
Shawn McCarney66332cd2020-07-13 19:14:18 -050084
Shawn McCarney2f1b7ba2021-03-17 10:21:14 -050085TEST(ErrorHistoryTests, WasLogged)
86{
87 ErrorHistory history{};
88 EXPECT_FALSE(history.wasLogged(ErrorType::pmbus));
89 history.setWasLogged(ErrorType::pmbus, true);
90 EXPECT_TRUE(history.wasLogged(ErrorType::pmbus));
91 history.setWasLogged(ErrorType::pmbus, false);
92 EXPECT_FALSE(history.wasLogged(ErrorType::pmbus));
Shawn McCarney66332cd2020-07-13 19:14:18 -050093}