197f7abcfSMatt Spinler /**
297f7abcfSMatt Spinler * Copyright © 2019 IBM Corporation
397f7abcfSMatt Spinler *
497f7abcfSMatt Spinler * Licensed under the Apache License, Version 2.0 (the "License");
597f7abcfSMatt Spinler * you may not use this file except in compliance with the License.
697f7abcfSMatt Spinler * You may obtain a copy of the License at
797f7abcfSMatt Spinler *
897f7abcfSMatt Spinler * http://www.apache.org/licenses/LICENSE-2.0
997f7abcfSMatt Spinler *
1097f7abcfSMatt Spinler * Unless required by applicable law or agreed to in writing, software
1197f7abcfSMatt Spinler * distributed under the License is distributed on an "AS IS" BASIS,
1297f7abcfSMatt Spinler * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1397f7abcfSMatt Spinler * See the License for the specific language governing permissions and
1497f7abcfSMatt Spinler * limitations under the License.
1597f7abcfSMatt Spinler */
168c686ccaSMatt Spinler #include "extensions/openpower-pels/severity.hpp"
178c686ccaSMatt Spinler
188c686ccaSMatt Spinler #include <gtest/gtest.h>
198c686ccaSMatt Spinler
208c686ccaSMatt Spinler using namespace openpower::pels;
218c686ccaSMatt Spinler using LogSeverity = phosphor::logging::Entry::Level;
228c686ccaSMatt Spinler
TEST(SeverityTest,SeverityMapTest)238c686ccaSMatt Spinler TEST(SeverityTest, SeverityMapTest)
248c686ccaSMatt Spinler {
258c686ccaSMatt Spinler ASSERT_EQ(convertOBMCSeverityToPEL(LogSeverity::Informational), 0x00);
268c686ccaSMatt Spinler ASSERT_EQ(convertOBMCSeverityToPEL(LogSeverity::Notice), 0x00);
278c686ccaSMatt Spinler ASSERT_EQ(convertOBMCSeverityToPEL(LogSeverity::Debug), 0x00);
288c686ccaSMatt Spinler ASSERT_EQ(convertOBMCSeverityToPEL(LogSeverity::Warning), 0x20);
298c686ccaSMatt Spinler ASSERT_EQ(convertOBMCSeverityToPEL(LogSeverity::Critical), 0x50);
308c686ccaSMatt Spinler ASSERT_EQ(convertOBMCSeverityToPEL(LogSeverity::Emergency), 0x40);
318c686ccaSMatt Spinler ASSERT_EQ(convertOBMCSeverityToPEL(LogSeverity::Alert), 0x40);
328c686ccaSMatt Spinler ASSERT_EQ(convertOBMCSeverityToPEL(LogSeverity::Error), 0x40);
338c686ccaSMatt Spinler }
34*8b81ec0eSMatt Spinler
TEST(SeverityTest,fixupLogSeverityTest)35*8b81ec0eSMatt Spinler TEST(SeverityTest, fixupLogSeverityTest)
36*8b81ec0eSMatt Spinler {
37*8b81ec0eSMatt Spinler struct TestParams
38*8b81ec0eSMatt Spinler {
39*8b81ec0eSMatt Spinler LogSeverity sevIn;
40*8b81ec0eSMatt Spinler SeverityType pelSevIn;
41*8b81ec0eSMatt Spinler std::optional<LogSeverity> sevOut;
42*8b81ec0eSMatt Spinler };
43*8b81ec0eSMatt Spinler
44*8b81ec0eSMatt Spinler const std::vector<TestParams> testParams{
45*8b81ec0eSMatt Spinler // Convert nonInfo sevs to info
46*8b81ec0eSMatt Spinler {LogSeverity::Error, SeverityType::nonError,
47*8b81ec0eSMatt Spinler LogSeverity::Informational},
48*8b81ec0eSMatt Spinler {LogSeverity::Critical, SeverityType::recovered,
49*8b81ec0eSMatt Spinler LogSeverity::Informational},
50*8b81ec0eSMatt Spinler {LogSeverity::Warning, SeverityType::nonError,
51*8b81ec0eSMatt Spinler LogSeverity::Informational},
52*8b81ec0eSMatt Spinler
53*8b81ec0eSMatt Spinler // Convert info sevs to nonInfo
54*8b81ec0eSMatt Spinler {LogSeverity::Informational, SeverityType::predictive,
55*8b81ec0eSMatt Spinler LogSeverity::Warning},
56*8b81ec0eSMatt Spinler {LogSeverity::Notice, SeverityType::unrecoverable, LogSeverity::Error},
57*8b81ec0eSMatt Spinler {LogSeverity::Debug, SeverityType::critical, LogSeverity::Critical},
58*8b81ec0eSMatt Spinler
59*8b81ec0eSMatt Spinler // Convert non-critical to critical
60*8b81ec0eSMatt Spinler {LogSeverity::Warning, SeverityType::critical, LogSeverity::Critical},
61*8b81ec0eSMatt Spinler
62*8b81ec0eSMatt Spinler // No change
63*8b81ec0eSMatt Spinler {LogSeverity::Informational, SeverityType::nonError, std::nullopt},
64*8b81ec0eSMatt Spinler {LogSeverity::Debug, SeverityType::recovered, std::nullopt},
65*8b81ec0eSMatt Spinler {LogSeverity::Notice, SeverityType::nonError, std::nullopt},
66*8b81ec0eSMatt Spinler {LogSeverity::Error, SeverityType::unrecoverable, std::nullopt},
67*8b81ec0eSMatt Spinler {LogSeverity::Critical, SeverityType::unrecoverable, std::nullopt}};
68*8b81ec0eSMatt Spinler
69*8b81ec0eSMatt Spinler for (const auto& test : testParams)
70*8b81ec0eSMatt Spinler {
71*8b81ec0eSMatt Spinler EXPECT_EQ(fixupLogSeverity(test.sevIn, test.pelSevIn), test.sevOut);
72*8b81ec0eSMatt Spinler }
73*8b81ec0eSMatt Spinler }
74