Shawn McCarney | 66332cd | 2020-07-13 19:14:18 -0500 | [diff] [blame] | 1 | /** |
| 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 McCarney | 66332cd | 2020-07-13 19:14:18 -0500 | [diff] [blame] | 18 | #include <gtest/gtest.h> |
| 19 | |
| 20 | using namespace phosphor::power::regulators; |
| 21 | |
Shawn McCarney | 2f1b7ba | 2021-03-17 10:21:14 -0500 | [diff] [blame] | 22 | TEST(ErrorHistoryTests, ErrorType) |
| 23 | { |
| 24 | EXPECT_EQ(static_cast<int>(ErrorType::internal), 3); |
Shawn McCarney | 3f7da6e | 2021-08-27 14:15:11 -0500 | [diff] [blame] | 25 | EXPECT_EQ(static_cast<int>(ErrorType::numTypes), 8); |
Shawn McCarney | 2f1b7ba | 2021-03-17 10:21:14 -0500 | [diff] [blame] | 26 | } |
| 27 | |
Shawn McCarney | 66332cd | 2020-07-13 19:14:18 -0500 | [diff] [blame] | 28 | TEST(ErrorHistoryTests, Constructor) |
| 29 | { |
| 30 | ErrorHistory history{}; |
Shawn McCarney | 2f1b7ba | 2021-03-17 10:21:14 -0500 | [diff] [blame] | 31 | 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 McCarney | 3f7da6e | 2021-08-27 14:15:11 -0500 | [diff] [blame] | 37 | EXPECT_FALSE(history.wasLogged(ErrorType::phaseFaultN)); |
| 38 | EXPECT_FALSE(history.wasLogged(ErrorType::phaseFaultNPlus1)); |
Shawn McCarney | 66332cd | 2020-07-13 19:14:18 -0500 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | TEST(ErrorHistoryTests, Clear) |
| 42 | { |
| 43 | ErrorHistory history{}; |
Shawn McCarney | 2f1b7ba | 2021-03-17 10:21:14 -0500 | [diff] [blame] | 44 | |
| 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 McCarney | 3f7da6e | 2021-08-27 14:15:11 -0500 | [diff] [blame] | 51 | history.setWasLogged(ErrorType::phaseFaultN, true); |
| 52 | history.setWasLogged(ErrorType::phaseFaultNPlus1, true); |
Shawn McCarney | 2f1b7ba | 2021-03-17 10:21:14 -0500 | [diff] [blame] | 53 | |
| 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 McCarney | 3f7da6e | 2021-08-27 14:15:11 -0500 | [diff] [blame] | 60 | EXPECT_TRUE(history.wasLogged(ErrorType::phaseFaultN)); |
| 61 | EXPECT_TRUE(history.wasLogged(ErrorType::phaseFaultNPlus1)); |
Shawn McCarney | 2f1b7ba | 2021-03-17 10:21:14 -0500 | [diff] [blame] | 62 | |
Shawn McCarney | 66332cd | 2020-07-13 19:14:18 -0500 | [diff] [blame] | 63 | history.clear(); |
Shawn McCarney | 2f1b7ba | 2021-03-17 10:21:14 -0500 | [diff] [blame] | 64 | |
| 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 McCarney | 3f7da6e | 2021-08-27 14:15:11 -0500 | [diff] [blame] | 71 | EXPECT_FALSE(history.wasLogged(ErrorType::phaseFaultN)); |
| 72 | EXPECT_FALSE(history.wasLogged(ErrorType::phaseFaultNPlus1)); |
Shawn McCarney | 66332cd | 2020-07-13 19:14:18 -0500 | [diff] [blame] | 73 | } |
| 74 | |
Shawn McCarney | 2f1b7ba | 2021-03-17 10:21:14 -0500 | [diff] [blame] | 75 | TEST(ErrorHistoryTests, SetWasLogged) |
Shawn McCarney | 66332cd | 2020-07-13 19:14:18 -0500 | [diff] [blame] | 76 | { |
| 77 | ErrorHistory history{}; |
Shawn McCarney | 2f1b7ba | 2021-03-17 10:21:14 -0500 | [diff] [blame] | 78 | 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 McCarney | 66332cd | 2020-07-13 19:14:18 -0500 | [diff] [blame] | 84 | |
Shawn McCarney | 2f1b7ba | 2021-03-17 10:21:14 -0500 | [diff] [blame] | 85 | TEST(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 McCarney | 66332cd | 2020-07-13 19:14:18 -0500 | [diff] [blame] | 93 | } |