blob: 55f77f5a3aeb5a0c9fa14cdb959674ed3f48c7a7 [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);
25 EXPECT_EQ(static_cast<int>(ErrorType::numTypes), 6);
26}
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 McCarney66332cd2020-07-13 19:14:18 -050037}
38
39TEST(ErrorHistoryTests, Clear)
40{
41 ErrorHistory history{};
Shawn McCarney2f1b7ba2021-03-17 10:21:14 -050042
43 history.setWasLogged(ErrorType::configFile, true);
44 history.setWasLogged(ErrorType::dbus, true);
45 history.setWasLogged(ErrorType::i2c, true);
46 history.setWasLogged(ErrorType::internal, true);
47 history.setWasLogged(ErrorType::pmbus, true);
48 history.setWasLogged(ErrorType::writeVerification, true);
49
50 EXPECT_TRUE(history.wasLogged(ErrorType::configFile));
51 EXPECT_TRUE(history.wasLogged(ErrorType::dbus));
52 EXPECT_TRUE(history.wasLogged(ErrorType::i2c));
53 EXPECT_TRUE(history.wasLogged(ErrorType::internal));
54 EXPECT_TRUE(history.wasLogged(ErrorType::pmbus));
55 EXPECT_TRUE(history.wasLogged(ErrorType::writeVerification));
56
Shawn McCarney66332cd2020-07-13 19:14:18 -050057 history.clear();
Shawn McCarney2f1b7ba2021-03-17 10:21:14 -050058
59 EXPECT_FALSE(history.wasLogged(ErrorType::configFile));
60 EXPECT_FALSE(history.wasLogged(ErrorType::dbus));
61 EXPECT_FALSE(history.wasLogged(ErrorType::i2c));
62 EXPECT_FALSE(history.wasLogged(ErrorType::internal));
63 EXPECT_FALSE(history.wasLogged(ErrorType::pmbus));
64 EXPECT_FALSE(history.wasLogged(ErrorType::writeVerification));
Shawn McCarney66332cd2020-07-13 19:14:18 -050065}
66
Shawn McCarney2f1b7ba2021-03-17 10:21:14 -050067TEST(ErrorHistoryTests, SetWasLogged)
Shawn McCarney66332cd2020-07-13 19:14:18 -050068{
69 ErrorHistory history{};
Shawn McCarney2f1b7ba2021-03-17 10:21:14 -050070 EXPECT_FALSE(history.wasLogged(ErrorType::dbus));
71 history.setWasLogged(ErrorType::dbus, true);
72 EXPECT_TRUE(history.wasLogged(ErrorType::dbus));
73 history.setWasLogged(ErrorType::dbus, false);
74 EXPECT_FALSE(history.wasLogged(ErrorType::dbus));
75}
Shawn McCarney66332cd2020-07-13 19:14:18 -050076
Shawn McCarney2f1b7ba2021-03-17 10:21:14 -050077TEST(ErrorHistoryTests, WasLogged)
78{
79 ErrorHistory history{};
80 EXPECT_FALSE(history.wasLogged(ErrorType::pmbus));
81 history.setWasLogged(ErrorType::pmbus, true);
82 EXPECT_TRUE(history.wasLogged(ErrorType::pmbus));
83 history.setWasLogged(ErrorType::pmbus, false);
84 EXPECT_FALSE(history.wasLogged(ErrorType::pmbus));
Shawn McCarney66332cd2020-07-13 19:14:18 -050085}