| Alexander Hansen | 40fb549 | 2025-10-28 17:56:12 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // SPDX-FileCopyrightText: Copyright 2019 IBM Corporation |
| 3 | |
| Matt Spinler | 8c686cc | 2019-09-20 13:46:02 -0500 | [diff] [blame] | 4 | #include "extensions/openpower-pels/severity.hpp" |
| 5 | |
| 6 | #include <gtest/gtest.h> |
| 7 | |
| 8 | using namespace openpower::pels; |
| 9 | using LogSeverity = phosphor::logging::Entry::Level; |
| 10 | |
| 11 | TEST(SeverityTest, SeverityMapTest) |
| 12 | { |
| 13 | ASSERT_EQ(convertOBMCSeverityToPEL(LogSeverity::Informational), 0x00); |
| 14 | ASSERT_EQ(convertOBMCSeverityToPEL(LogSeverity::Notice), 0x00); |
| 15 | ASSERT_EQ(convertOBMCSeverityToPEL(LogSeverity::Debug), 0x00); |
| 16 | ASSERT_EQ(convertOBMCSeverityToPEL(LogSeverity::Warning), 0x20); |
| 17 | ASSERT_EQ(convertOBMCSeverityToPEL(LogSeverity::Critical), 0x50); |
| 18 | ASSERT_EQ(convertOBMCSeverityToPEL(LogSeverity::Emergency), 0x40); |
| 19 | ASSERT_EQ(convertOBMCSeverityToPEL(LogSeverity::Alert), 0x40); |
| 20 | ASSERT_EQ(convertOBMCSeverityToPEL(LogSeverity::Error), 0x40); |
| 21 | } |
| Matt Spinler | 8b81ec0 | 2022-07-12 13:25:37 -0500 | [diff] [blame] | 22 | |
| 23 | TEST(SeverityTest, fixupLogSeverityTest) |
| 24 | { |
| 25 | struct TestParams |
| 26 | { |
| 27 | LogSeverity sevIn; |
| 28 | SeverityType pelSevIn; |
| 29 | std::optional<LogSeverity> sevOut; |
| 30 | }; |
| 31 | |
| 32 | const std::vector<TestParams> testParams{ |
| 33 | // Convert nonInfo sevs to info |
| 34 | {LogSeverity::Error, SeverityType::nonError, |
| 35 | LogSeverity::Informational}, |
| 36 | {LogSeverity::Critical, SeverityType::recovered, |
| 37 | LogSeverity::Informational}, |
| 38 | {LogSeverity::Warning, SeverityType::nonError, |
| 39 | LogSeverity::Informational}, |
| 40 | |
| 41 | // Convert info sevs to nonInfo |
| 42 | {LogSeverity::Informational, SeverityType::predictive, |
| 43 | LogSeverity::Warning}, |
| 44 | {LogSeverity::Notice, SeverityType::unrecoverable, LogSeverity::Error}, |
| 45 | {LogSeverity::Debug, SeverityType::critical, LogSeverity::Critical}, |
| 46 | |
| 47 | // Convert non-critical to critical |
| 48 | {LogSeverity::Warning, SeverityType::critical, LogSeverity::Critical}, |
| 49 | |
| 50 | // No change |
| 51 | {LogSeverity::Informational, SeverityType::nonError, std::nullopt}, |
| 52 | {LogSeverity::Debug, SeverityType::recovered, std::nullopt}, |
| 53 | {LogSeverity::Notice, SeverityType::nonError, std::nullopt}, |
| 54 | {LogSeverity::Error, SeverityType::unrecoverable, std::nullopt}, |
| 55 | {LogSeverity::Critical, SeverityType::unrecoverable, std::nullopt}}; |
| 56 | |
| 57 | for (const auto& test : testParams) |
| 58 | { |
| 59 | EXPECT_EQ(fixupLogSeverity(test.sevIn, test.pelSevIn), test.sevOut); |
| 60 | } |
| 61 | } |