/**
 * Copyright © 2019 IBM Corporation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#include "elog_entry.hpp"
#include "extensions/openpower-pels/generic.hpp"
#include "extensions/openpower-pels/pel.hpp"
#include "mocks.hpp"
#include "pel_utils.hpp"

#include <filesystem>
#include <fstream>

#include <gtest/gtest.h>

namespace fs = std::filesystem;
using namespace openpower::pels;
using ::testing::_;
using ::testing::DoAll;
using ::testing::NiceMock;
using ::testing::Return;
using ::testing::SetArgReferee;

class PELTest : public CleanLogID
{};

fs::path makeTempDir()
{
    char path[] = "/tmp/tempdirXXXXXX";
    std::filesystem::path dir = mkdtemp(path);
    return dir;
}

int writeFileAndGetFD(const fs::path& dir, const std::vector<uint8_t>& data)
{
    static size_t count = 0;
    fs::path path = dir / (std::string{"file"} + std::to_string(count));
    std::ofstream stream{path};
    count++;

    stream.write(reinterpret_cast<const char*>(data.data()), data.size());
    stream.close();

    FILE* fp = fopen(path.c_str(), "r");
    return fileno(fp);
}

TEST_F(PELTest, FlattenTest)
{
    auto data = pelDataFactory(TestPELType::pelSimple);
    auto pel = std::make_unique<PEL>(data);

    // Check a few fields
    EXPECT_TRUE(pel->valid());
    EXPECT_EQ(pel->id(), 0x80818283);
    EXPECT_EQ(pel->plid(), 0x50515253);
    EXPECT_EQ(pel->userHeader().subsystem(), 0x10);
    EXPECT_EQ(pel->userHeader().actionFlags(), 0x80C0);

    // Test that data in == data out
    auto flattenedData = pel->data();
    EXPECT_EQ(data, flattenedData);
    EXPECT_EQ(flattenedData.size(), pel->size());
}

TEST_F(PELTest, CommitTimeTest)
{
    auto data = pelDataFactory(TestPELType::pelSimple);
    auto pel = std::make_unique<PEL>(data);

    auto origTime = pel->commitTime();
    pel->setCommitTime();
    auto newTime = pel->commitTime();

    EXPECT_NE(origTime, newTime);

    // Make a new PEL and check new value is still there
    auto newData = pel->data();
    auto newPel = std::make_unique<PEL>(newData);
    EXPECT_EQ(newTime, newPel->commitTime());
}

TEST_F(PELTest, AssignIDTest)
{
    auto data = pelDataFactory(TestPELType::pelSimple);
    auto pel = std::make_unique<PEL>(data);

    auto origID = pel->id();
    pel->assignID();
    auto newID = pel->id();

    EXPECT_NE(origID, newID);

    // Make a new PEL and check new value is still there
    auto newData = pel->data();
    auto newPel = std::make_unique<PEL>(newData);
    EXPECT_EQ(newID, newPel->id());
}

TEST_F(PELTest, WithLogIDTest)
{
    auto data = pelDataFactory(TestPELType::pelSimple);
    auto pel = std::make_unique<PEL>(data, 0x42);

    EXPECT_TRUE(pel->valid());
    EXPECT_EQ(pel->obmcLogID(), 0x42);
}

TEST_F(PELTest, InvalidPELTest)
{
    auto data = pelDataFactory(TestPELType::pelSimple);

    // Too small
    data.resize(PrivateHeader::flattenedSize());

    auto pel = std::make_unique<PEL>(data);

    EXPECT_TRUE(pel->privateHeader().valid());
    EXPECT_FALSE(pel->userHeader().valid());
    EXPECT_FALSE(pel->valid());

    // Now corrupt the private header
    data = pelDataFactory(TestPELType::pelSimple);
    data.at(0) = 0;
    pel = std::make_unique<PEL>(data);

    EXPECT_FALSE(pel->privateHeader().valid());
    EXPECT_TRUE(pel->userHeader().valid());
    EXPECT_FALSE(pel->valid());
}

TEST_F(PELTest, EmptyDataTest)
{
    std::vector<uint8_t> data;
    auto pel = std::make_unique<PEL>(data);

    EXPECT_FALSE(pel->privateHeader().valid());
    EXPECT_FALSE(pel->userHeader().valid());
    EXPECT_FALSE(pel->valid());
}

TEST_F(PELTest, CreateFromRegistryTest)
{
    message::Entry regEntry;
    uint64_t timestamp = 5;

    regEntry.name = "test";
    regEntry.subsystem = 5;
    regEntry.actionFlags = 0xC000;
    regEntry.src.type = 0xBD;
    regEntry.src.reasonCode = 0x1234;

    std::vector<std::string> data{"KEY1=VALUE1"};
    AdditionalData ad{data};
    NiceMock<MockDataInterface> dataIface;
    NiceMock<MockJournal> journal;
    PelFFDC ffdc;

    std::vector<std::string> dumpType{"bmc/entry", "resource/entry",
                                      "system/entry"};
    EXPECT_CALL(dataIface, checkDumpStatus(dumpType))
        .WillRepeatedly(Return(std::vector<bool>{false, false, false}));

    PEL pel{regEntry, 42,   timestamp, phosphor::logging::Entry::Level::Error,
            ad,       ffdc, dataIface, journal};

    EXPECT_TRUE(pel.valid());
    EXPECT_EQ(pel.privateHeader().obmcLogID(), 42);
    EXPECT_EQ(pel.userHeader().severity(), 0x40);

    EXPECT_EQ(pel.primarySRC().value()->asciiString(),
              "BD051234                        ");

    // Check that certain optional sections have been created
    size_t mtmsCount = 0;
    size_t euhCount = 0;
    size_t udCount = 0;

    for (const auto& section : pel.optionalSections())
    {
        if (section->header().id ==
            static_cast<uint16_t>(SectionID::failingMTMS))
        {
            mtmsCount++;
        }
        else if (section->header().id ==
                 static_cast<uint16_t>(SectionID::extendedUserHeader))
        {
            euhCount++;
        }
        else if (section->header().id ==
                 static_cast<uint16_t>(SectionID::userData))
        {
            udCount++;
        }
    }

    EXPECT_EQ(mtmsCount, 1);
    EXPECT_EQ(euhCount, 1);
    EXPECT_EQ(udCount, 2); // AD section and sysInfo section
    ASSERT_FALSE(pel.isHwCalloutPresent());

    {
        // The same thing, but without the action flags specified
        // in the registry, so the constructor should set them.
        regEntry.actionFlags = std::nullopt;

        PEL pel2{
            regEntry, 42,   timestamp, phosphor::logging::Entry::Level::Error,
            ad,       ffdc, dataIface, journal};

        EXPECT_EQ(pel2.userHeader().actionFlags(), 0xA800);
    }
}

// Test that when the AdditionalData size is over 16KB that
// the PEL that's created is exactly 16KB since the UserData
// section that contains all that data was pruned.
TEST_F(PELTest, CreateTooBigADTest)
{
    message::Entry regEntry;
    uint64_t timestamp = 5;

    regEntry.name = "test";
    regEntry.subsystem = 5;
    regEntry.actionFlags = 0xC000;
    regEntry.src.type = 0xBD;
    regEntry.src.reasonCode = 0x1234;
    PelFFDC ffdc;

    // Over the 16KB max PEL size
    std::string bigAD{"KEY1="};
    bigAD += std::string(17000, 'G');

    std::vector<std::string> data{bigAD};
    AdditionalData ad{data};
    NiceMock<MockDataInterface> dataIface;
    NiceMock<MockJournal> journal;

    std::vector<std::string> dumpType{"bmc/entry", "resource/entry",
                                      "system/entry"};
    EXPECT_CALL(dataIface, checkDumpStatus(dumpType))
        .WillOnce(Return(std::vector<bool>{false, false, false}));

    PEL pel{regEntry, 42,   timestamp, phosphor::logging::Entry::Level::Error,
            ad,       ffdc, dataIface, journal};

    EXPECT_TRUE(pel.valid());
    EXPECT_EQ(pel.size(), 16384);

    // Make sure that there are still 2 UD sections.
    const auto& optSections = pel.optionalSections();
    auto udCount = std::count_if(optSections.begin(), optSections.end(),
                                 [](const auto& section) {
        return section->header().id ==
               static_cast<uint16_t>(SectionID::userData);
    });

    EXPECT_EQ(udCount, 2); // AD section and sysInfo section
}

// Test that we'll create Generic optional sections for sections that
// there aren't explicit classes for.
TEST_F(PELTest, GenericSectionTest)
{
    auto data = pelDataFactory(TestPELType::pelSimple);

    std::vector<uint8_t> section1{0x58, 0x58, // ID 'XX'
                                  0x00, 0x18, // Size
                                  0x01, 0x02, // version, subtype
                                  0x03, 0x04, // comp ID

                                  // some data
                                  0x20, 0x30, 0x05, 0x09, 0x11, 0x1E, 0x1, 0x63,
                                  0x20, 0x31, 0x06, 0x0F, 0x09, 0x22, 0x3A,
                                  0x00};

    std::vector<uint8_t> section2{
        0x59, 0x59, // ID 'YY'
        0x00, 0x20, // Size
        0x01, 0x02, // version, subtype
        0x03, 0x04, // comp ID

        // some data
        0x20, 0x30, 0x05, 0x09, 0x11, 0x1E, 0x1, 0x63, 0x20, 0x31, 0x06, 0x0F,
        0x09, 0x22, 0x3A, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};

    // Add the new sections at the end
    data.insert(data.end(), section1.begin(), section1.end());
    data.insert(data.end(), section2.begin(), section2.end());

    // Increment the section count
    data.at(27) += 2;
    auto origData = data;

    PEL pel{data};

    const auto& sections = pel.optionalSections();

    bool foundXX = false;
    bool foundYY = false;

    // Check that we can find these 2 Generic sections
    for (const auto& section : sections)
    {
        if (section->header().id == 0x5858)
        {
            foundXX = true;
            EXPECT_NE(dynamic_cast<Generic*>(section.get()), nullptr);
        }
        else if (section->header().id == 0x5959)
        {
            foundYY = true;
            EXPECT_NE(dynamic_cast<Generic*>(section.get()), nullptr);
        }
    }

    EXPECT_TRUE(foundXX);
    EXPECT_TRUE(foundYY);

    // Now flatten and check
    auto newData = pel.data();

    EXPECT_EQ(origData, newData);
}

// Test that an invalid section will still get a Generic object
TEST_F(PELTest, InvalidGenericTest)
{
    auto data = pelDataFactory(TestPELType::pelSimple);

    // Not a valid section
    std::vector<uint8_t> section1{0x01, 0x02, 0x03};

    data.insert(data.end(), section1.begin(), section1.end());

    // Increment the section count
    data.at(27) += 1;

    PEL pel{data};
    EXPECT_FALSE(pel.valid());

    const auto& sections = pel.optionalSections();

    bool foundGeneric = false;
    for (const auto& section : sections)
    {
        if (dynamic_cast<Generic*>(section.get()) != nullptr)
        {
            foundGeneric = true;
            EXPECT_EQ(section->valid(), false);
            break;
        }
    }

    EXPECT_TRUE(foundGeneric);
}

// Create a UserData section out of AdditionalData
TEST_F(PELTest, MakeUDSectionTest)
{
    std::vector<std::string> ad{"KEY1=VALUE1", "KEY2=VALUE2", "KEY3=VALUE3",
                                "ESEL=TEST"};
    AdditionalData additionalData{ad};

    auto ud = util::makeADUserDataSection(additionalData);

    EXPECT_TRUE(ud->valid());
    EXPECT_EQ(ud->header().id, 0x5544);
    EXPECT_EQ(ud->header().version, 0x01);
    EXPECT_EQ(ud->header().subType, 0x01);
    EXPECT_EQ(ud->header().componentID, 0x2000);

    const auto& d = ud->data();

    std::string jsonString{d.begin(), d.end()};

    std::string expectedJSON =
        R"({"KEY1":"VALUE1","KEY2":"VALUE2","KEY3":"VALUE3"})";

    // The actual data is null padded to a 4B boundary.
    std::vector<uint8_t> expectedData;
    expectedData.resize(52, '\0');
    memcpy(expectedData.data(), expectedJSON.data(), expectedJSON.size());

    EXPECT_EQ(d, expectedData);

    // Ensure we can read this as JSON
    auto newJSON = nlohmann::json::parse(jsonString);
    EXPECT_EQ(newJSON["KEY1"], "VALUE1");
    EXPECT_EQ(newJSON["KEY2"], "VALUE2");
    EXPECT_EQ(newJSON["KEY3"], "VALUE3");
}

// Create the UserData section that contains system info
TEST_F(PELTest, SysInfoSectionTest)
{
    MockDataInterface dataIface;

    EXPECT_CALL(dataIface, getBMCFWVersionID()).WillOnce(Return("ABCD1234"));
    EXPECT_CALL(dataIface, getBMCState()).WillOnce(Return("State.Ready"));
    EXPECT_CALL(dataIface, getChassisState()).WillOnce(Return("State.On"));
    EXPECT_CALL(dataIface, getHostState()).WillOnce(Return("State.Off"));
    EXPECT_CALL(dataIface, getBootState())
        .WillOnce(Return("State.SystemInitComplete"));
    EXPECT_CALL(dataIface, getSystemIMKeyword())
        .WillOnce(Return(std::vector<uint8_t>{0, 1, 0x55, 0xAA}));

    std::string pid = "_PID=" + std::to_string(getpid());
    std::vector<std::string> ad{pid};
    AdditionalData additionalData{ad};

    auto ud = util::makeSysInfoUserDataSection(additionalData, dataIface);

    EXPECT_TRUE(ud->valid());
    EXPECT_EQ(ud->header().id, 0x5544);
    EXPECT_EQ(ud->header().version, 0x01);
    EXPECT_EQ(ud->header().subType, 0x01);
    EXPECT_EQ(ud->header().componentID, 0x2000);

    // Pull out the JSON data and check it.
    const auto& d = ud->data();
    std::string jsonString{d.begin(), d.end()};
    auto json = nlohmann::json::parse(jsonString);

    // Ensure the 'Process Name' entry contains the name of this test
    // executable.
    auto name = json["Process Name"].get<std::string>();
    auto found = (name.find("pel_test") != std::string::npos) ||
                 (name.find("test-openpower-pels-pel") != std::string::npos);
    EXPECT_TRUE(found);
    // @TODO(stwcx): remove 'pel_test' when removing autotools.

    auto version = json["FW Version ID"].get<std::string>();
    EXPECT_EQ(version, "ABCD1234");

    auto state = json["BMCState"].get<std::string>();
    EXPECT_EQ(state, "Ready");

    state = json["ChassisState"].get<std::string>();
    EXPECT_EQ(state, "On");

    state = json["HostState"].get<std::string>();
    EXPECT_EQ(state, "Off");

    state = json["BootState"].get<std::string>();
    EXPECT_EQ(state, "SystemInitComplete");

    auto keyword = json["System IM"].get<std::string>();
    EXPECT_EQ(keyword, "000155AA");
}

// Test that the sections that override
//     virtual std::optional<std::string> Section::getJSON() const
// return valid JSON.
TEST_F(PELTest, SectionJSONTest)
{
    auto data = pelDataFactory(TestPELType::pelSimple);
    PEL pel{data};

    // Check that all JSON returned from the sections is
    // parseable by nlohmann::json, which will throw an
    // exception and fail the test if there is a problem.

    // The getJSON() response needs to be wrapped in a { } to make
    // actual valid JSON (PEL::toJSON() usually handles that).

    auto jsonString = pel.privateHeader().getJSON('O');

    // PrivateHeader always prints JSON
    ASSERT_TRUE(jsonString);
    *jsonString = '{' + *jsonString + '}';
    auto json = nlohmann::json::parse(*jsonString);

    jsonString = pel.userHeader().getJSON('O');

    // UserHeader always prints JSON
    ASSERT_TRUE(jsonString);
    *jsonString = '{' + *jsonString + '}';
    json = nlohmann::json::parse(*jsonString);

    for (const auto& section : pel.optionalSections())
    {
        // The optional sections may or may not have implemented getJSON().
        jsonString = section->getJSON('O');
        if (jsonString)
        {
            *jsonString = '{' + *jsonString + '}';
            auto json = nlohmann::json::parse(*jsonString);
        }
    }
}

PelFFDCfile getJSONFFDC(const fs::path& dir)
{
    PelFFDCfile ffdc;
    ffdc.format = UserDataFormat::json;
    ffdc.subType = 5;
    ffdc.version = 42;

    auto inputJSON = R"({
        "key1": "value1",
        "key2": 42,
        "key3" : [1, 2, 3, 4, 5],
        "key4": {"key5": "value5"}
    })"_json;

    // Write the JSON to a file and get its descriptor.
    auto s = inputJSON.dump();
    std::vector<uint8_t> data{s.begin(), s.end()};
    ffdc.fd = writeFileAndGetFD(dir, data);

    return ffdc;
}

TEST_F(PELTest, MakeJSONFileUDSectionTest)
{
    auto dir = makeTempDir();

    {
        auto ffdc = getJSONFFDC(dir);

        auto ud = util::makeFFDCuserDataSection(0x2002, ffdc);
        close(ffdc.fd);
        ASSERT_TRUE(ud);
        ASSERT_TRUE(ud->valid());
        EXPECT_EQ(ud->header().id, 0x5544);

        EXPECT_EQ(ud->header().version,
                  static_cast<uint8_t>(UserDataFormatVersion::json));
        EXPECT_EQ(ud->header().subType,
                  static_cast<uint8_t>(UserDataFormat::json));
        EXPECT_EQ(ud->header().componentID,
                  static_cast<uint16_t>(ComponentID::phosphorLogging));

        // Pull the JSON back out of the the UserData section
        const auto& d = ud->data();
        std::string js{d.begin(), d.end()};
        auto json = nlohmann::json::parse(js);

        EXPECT_EQ("value1", json["key1"].get<std::string>());
        EXPECT_EQ(42, json["key2"].get<int>());

        std::vector<int> key3Values{1, 2, 3, 4, 5};
        EXPECT_EQ(key3Values, json["key3"].get<std::vector<int>>());

        std::map<std::string, std::string> key4Values{{"key5", "value5"}};
        auto actual = json["key4"].get<std::map<std::string, std::string>>();
        EXPECT_EQ(key4Values, actual);
    }

    {
        // A bad FD
        PelFFDCfile ffdc;
        ffdc.format = UserDataFormat::json;
        ffdc.subType = 5;
        ffdc.version = 42;
        ffdc.fd = 10000;

        // The section shouldn't get made
        auto ud = util::makeFFDCuserDataSection(0x2002, ffdc);
        ASSERT_FALSE(ud);
    }

    fs::remove_all(dir);
}

PelFFDCfile getCBORFFDC(const fs::path& dir)
{
    PelFFDCfile ffdc;
    ffdc.format = UserDataFormat::cbor;
    ffdc.subType = 5;
    ffdc.version = 42;

    auto inputJSON = R"({
        "key1": "value1",
        "key2": 42,
        "key3" : [1, 2, 3, 4, 5],
        "key4": {"key5": "value5"}
    })"_json;

    // Convert the JSON to CBOR and write it to a file
    auto data = nlohmann::json::to_cbor(inputJSON);
    ffdc.fd = writeFileAndGetFD(dir, data);

    return ffdc;
}

TEST_F(PELTest, MakeCBORFileUDSectionTest)
{
    auto dir = makeTempDir();

    auto ffdc = getCBORFFDC(dir);
    auto ud = util::makeFFDCuserDataSection(0x2002, ffdc);
    close(ffdc.fd);
    ASSERT_TRUE(ud);
    ASSERT_TRUE(ud->valid());
    EXPECT_EQ(ud->header().id, 0x5544);

    EXPECT_EQ(ud->header().version,
              static_cast<uint8_t>(UserDataFormatVersion::cbor));
    EXPECT_EQ(ud->header().subType, static_cast<uint8_t>(UserDataFormat::cbor));
    EXPECT_EQ(ud->header().componentID,
              static_cast<uint16_t>(ComponentID::phosphorLogging));

    // Pull the CBOR back out of the PEL section
    // The number of pad bytes to make the section be 4B aligned
    // was added at the end, read it and then remove it and the
    // padding before parsing it.
    auto data = ud->data();
    Stream stream{data};
    stream.offset(data.size() - 4);
    uint32_t pad;
    stream >> pad;

    data.resize(data.size() - 4 - pad);

    auto json = nlohmann::json::from_cbor(data);

    EXPECT_EQ("value1", json["key1"].get<std::string>());
    EXPECT_EQ(42, json["key2"].get<int>());

    std::vector<int> key3Values{1, 2, 3, 4, 5};
    EXPECT_EQ(key3Values, json["key3"].get<std::vector<int>>());

    std::map<std::string, std::string> key4Values{{"key5", "value5"}};
    auto actual = json["key4"].get<std::map<std::string, std::string>>();
    EXPECT_EQ(key4Values, actual);

    fs::remove_all(dir);
}

PelFFDCfile getTextFFDC(const fs::path& dir)
{
    PelFFDCfile ffdc;
    ffdc.format = UserDataFormat::text;
    ffdc.subType = 5;
    ffdc.version = 42;

    std::string text{"this is some text that will be used for FFDC"};
    std::vector<uint8_t> data{text.begin(), text.end()};

    ffdc.fd = writeFileAndGetFD(dir, data);

    return ffdc;
}

TEST_F(PELTest, MakeTextFileUDSectionTest)
{
    auto dir = makeTempDir();

    auto ffdc = getTextFFDC(dir);
    auto ud = util::makeFFDCuserDataSection(0x2002, ffdc);
    close(ffdc.fd);
    ASSERT_TRUE(ud);
    ASSERT_TRUE(ud->valid());
    EXPECT_EQ(ud->header().id, 0x5544);

    EXPECT_EQ(ud->header().version,
              static_cast<uint8_t>(UserDataFormatVersion::text));
    EXPECT_EQ(ud->header().subType, static_cast<uint8_t>(UserDataFormat::text));
    EXPECT_EQ(ud->header().componentID,
              static_cast<uint16_t>(ComponentID::phosphorLogging));

    // Get the text back out
    std::string text{ud->data().begin(), ud->data().end()};
    EXPECT_EQ(text, "this is some text that will be used for FFDC");

    fs::remove_all(dir);
}

PelFFDCfile getCustomFFDC(const fs::path& dir, const std::vector<uint8_t>& data)
{
    PelFFDCfile ffdc;
    ffdc.format = UserDataFormat::custom;
    ffdc.subType = 5;
    ffdc.version = 42;

    ffdc.fd = writeFileAndGetFD(dir, data);

    return ffdc;
}

TEST_F(PELTest, MakeCustomFileUDSectionTest)
{
    auto dir = makeTempDir();

    {
        std::vector<uint8_t> data{1, 2, 3, 4, 5, 6, 7, 8};

        auto ffdc = getCustomFFDC(dir, data);
        auto ud = util::makeFFDCuserDataSection(0x2002, ffdc);
        close(ffdc.fd);
        ASSERT_TRUE(ud);
        ASSERT_TRUE(ud->valid());
        EXPECT_EQ(ud->header().size, 8 + 8); // data size + header size
        EXPECT_EQ(ud->header().id, 0x5544);

        EXPECT_EQ(ud->header().version, 42);
        EXPECT_EQ(ud->header().subType, 5);
        EXPECT_EQ(ud->header().componentID, 0x2002);

        // Get the data back out
        std::vector<uint8_t> newData{ud->data().begin(), ud->data().end()};
        EXPECT_EQ(data, newData);
    }

    // Do the same thing again, but make it be non 4B aligned
    // so the data gets padded.
    {
        std::vector<uint8_t> data{1, 2, 3, 4, 5, 6, 7, 8, 9};

        auto ffdc = getCustomFFDC(dir, data);
        auto ud = util::makeFFDCuserDataSection(0x2002, ffdc);
        close(ffdc.fd);
        ASSERT_TRUE(ud);
        ASSERT_TRUE(ud->valid());
        EXPECT_EQ(ud->header().size, 12 + 8); // data size + header size
        EXPECT_EQ(ud->header().id, 0x5544);

        EXPECT_EQ(ud->header().version, 42);
        EXPECT_EQ(ud->header().subType, 5);
        EXPECT_EQ(ud->header().componentID, 0x2002);

        // Get the data back out
        std::vector<uint8_t> newData{ud->data().begin(), ud->data().end()};

        // pad the original to 12B so we can compare
        data.push_back(0);
        data.push_back(0);
        data.push_back(0);

        EXPECT_EQ(data, newData);
    }

    fs::remove_all(dir);
}

// Test Adding FFDC from files to a PEL
TEST_F(PELTest, CreateWithFFDCTest)
{
    auto dir = makeTempDir();
    message::Entry regEntry;
    uint64_t timestamp = 5;

    regEntry.name = "test";
    regEntry.subsystem = 5;
    regEntry.actionFlags = 0xC000;
    regEntry.src.type = 0xBD;
    regEntry.src.reasonCode = 0x1234;

    std::vector<std::string> additionalData{"KEY1=VALUE1"};
    AdditionalData ad{additionalData};
    NiceMock<MockDataInterface> dataIface;
    NiceMock<MockJournal> journal;
    PelFFDC ffdc;

    std::vector<uint8_t> customData{1, 2, 3, 4, 5, 6, 7, 8};

    // This will be trimmed when added
    std::vector<uint8_t> hugeCustomData(17000, 0x42);

    ffdc.emplace_back(std::move(getJSONFFDC(dir)));
    ffdc.emplace_back(std::move(getCBORFFDC(dir)));
    ffdc.emplace_back(std::move(getTextFFDC(dir)));
    ffdc.emplace_back(std::move(getCustomFFDC(dir, customData)));
    ffdc.emplace_back(std::move(getCustomFFDC(dir, hugeCustomData)));

    std::vector<std::string> dumpType{"bmc/entry", "resource/entry",
                                      "system/entry"};
    EXPECT_CALL(dataIface, checkDumpStatus(dumpType))
        .WillOnce(Return(std::vector<bool>{false, false, false}));

    PEL pel{regEntry, 42,   timestamp, phosphor::logging::Entry::Level::Error,
            ad,       ffdc, dataIface, journal};

    EXPECT_TRUE(pel.valid());

    // Clipped to the max
    EXPECT_EQ(pel.size(), 16384);

    // Check for the FFDC sections
    size_t udCount = 0;
    Section* ud = nullptr;

    for (const auto& section : pel.optionalSections())
    {
        if (section->header().id == static_cast<uint16_t>(SectionID::userData))
        {
            udCount++;
            ud = section.get();
        }
    }

    EXPECT_EQ(udCount, 7); // AD section, sysInfo, 5 ffdc sections

    // Check the last section was trimmed to
    // something a bit less that 17000.
    EXPECT_GT(ud->header().size, 14000);
    EXPECT_LT(ud->header().size, 16000);

    fs::remove_all(dir);
}

// Create a PEL with device callouts
TEST_F(PELTest, CreateWithDevCalloutsTest)
{
    message::Entry regEntry;
    uint64_t timestamp = 5;

    regEntry.name = "test";
    regEntry.subsystem = 5;
    regEntry.actionFlags = 0xC000;
    regEntry.src.type = 0xBD;
    regEntry.src.reasonCode = 0x1234;

    NiceMock<MockDataInterface> dataIface;
    NiceMock<MockJournal> journal;
    PelFFDC ffdc;

    const auto calloutJSON = R"(
    {
        "I2C":
        {
            "14":
            {
                "114":
                {
                    "Callouts":[
                        {
                        "Name": "/chassis/motherboard/cpu0",
                        "LocationCode": "P1",
                        "Priority": "H"
                        }
                    ],
                    "Dest": "proc 0 target"
                }
            }
        }
    })";

    std::vector<std::string> names{"systemA"};
    EXPECT_CALL(dataIface, getSystemNames)
        .Times(2)
        .WillRepeatedly(Return(names));

    EXPECT_CALL(dataIface, expandLocationCode("P1", 0))
        .Times(1)
        .WillOnce(Return("UXXX-P1"));

    EXPECT_CALL(dataIface, getInventoryFromLocCode("P1", 0, false))
        .WillOnce(Return(std::vector<std::string>{
            "/xyz/openbmc_project/inventory/chassis/motherboard/cpu0"}));

    EXPECT_CALL(
        dataIface,
        getHWCalloutFields(
            "/xyz/openbmc_project/inventory/chassis/motherboard/cpu0", _, _, _))
        .WillOnce(DoAll(SetArgReferee<1>("1234567"), SetArgReferee<2>("CCCC"),
                        SetArgReferee<3>("123456789ABC")));

    std::vector<std::string> dumpType{"bmc/entry", "resource/entry",
                                      "system/entry"};
    EXPECT_CALL(dataIface, checkDumpStatus(dumpType))
        .WillRepeatedly(Return(std::vector<bool>{false, false, false}));

    auto dataPath = getPELReadOnlyDataPath();
    std::ofstream file{dataPath / "systemA_dev_callouts.json"};
    file << calloutJSON;
    file.close();

    {
        std::vector<std::string> data{
            "CALLOUT_ERRNO=5",
            "CALLOUT_DEVICE_PATH=/sys/devices/platform/ahb/ahb:apb/"
            "ahb:apb:bus@1e78a000/1e78a340.i2c-bus/i2c-14/14-0072"};

        AdditionalData ad{data};

        PEL pel{
            regEntry, 42,   timestamp, phosphor::logging::Entry::Level::Error,
            ad,       ffdc, dataIface, journal};

        ASSERT_TRUE(pel.primarySRC().value()->callouts());
        auto& callouts = pel.primarySRC().value()->callouts()->callouts();
        ASSERT_EQ(callouts.size(), 1);
        ASSERT_TRUE(pel.isHwCalloutPresent());

        EXPECT_EQ(callouts[0]->priority(), 'H');
        EXPECT_EQ(callouts[0]->locationCode(), "UXXX-P1");

        auto& fru = callouts[0]->fruIdentity();
        EXPECT_EQ(fru->getPN().value(), "1234567");
        EXPECT_EQ(fru->getCCIN().value(), "CCCC");
        EXPECT_EQ(fru->getSN().value(), "123456789ABC");

        const auto& section = pel.optionalSections().back();

        ASSERT_EQ(section->header().id, 0x5544); // UD
        auto ud = static_cast<UserData*>(section.get());

        // Check that there was a UserData section added that
        // contains debug details about the device.
        const auto& d = ud->data();
        std::string jsonString{d.begin(), d.end()};
        auto actualJSON = nlohmann::json::parse(jsonString);

        auto expectedJSON = R"(
            {
                "PEL Internal Debug Data": {
                    "SRC": [
                      "I2C: bus: 14 address: 114 dest: proc 0 target"
                    ]
                }
            }
        )"_json;

        EXPECT_EQ(actualJSON, expectedJSON);
    }

    {
        // Device path not found (wrong i2c addr), so no callouts
        std::vector<std::string> data{
            "CALLOUT_ERRNO=5",
            "CALLOUT_DEVICE_PATH=/sys/devices/platform/ahb/ahb:apb/"
            "ahb:apb:bus@1e78a000/1e78a340.i2c-bus/i2c-14/14-0099"};

        AdditionalData ad{data};

        PEL pel{
            regEntry, 42,   timestamp, phosphor::logging::Entry::Level::Error,
            ad,       ffdc, dataIface, journal};

        // no callouts
        EXPECT_FALSE(pel.primarySRC().value()->callouts());

        // Now check that there was a UserData section
        // that contains the lookup error.
        const auto& section = pel.optionalSections().back();

        ASSERT_EQ(section->header().id, 0x5544); // UD
        auto ud = static_cast<UserData*>(section.get());

        const auto& d = ud->data();

        std::string jsonString{d.begin(), d.end()};

        auto actualJSON = nlohmann::json::parse(jsonString);

        auto expectedJSON =
            "{\"PEL Internal Debug Data\":{\"SRC\":"
            "[\"Problem looking up I2C callouts on 14 153: "
            "[json.exception.out_of_range.403] key '153' not found\"]}}"_json;

        EXPECT_EQ(actualJSON, expectedJSON);
    }

    fs::remove_all(dataPath);
}

// Test PELs when the callouts are passed in using a JSON file.
TEST_F(PELTest, CreateWithJSONCalloutsTest)
{
    PelFFDCfile ffdcFile;
    ffdcFile.format = UserDataFormat::json;
    ffdcFile.subType = 0xCA; // Callout JSON
    ffdcFile.version = 1;

    // Write these callouts to a JSON file and pass it into
    // the PEL as an FFDC file.
    auto inputJSON = R"([
        {
            "Priority": "H",
            "LocationCode": "P0-C1"
        },
        {
            "Priority": "M",
            "Procedure": "PROCEDURE"
        }
    ])"_json;

    auto s = inputJSON.dump();
    std::vector<uint8_t> data{s.begin(), s.end()};
    auto dir = makeTempDir();
    ffdcFile.fd = writeFileAndGetFD(dir, data);

    PelFFDC ffdc;
    ffdc.push_back(std::move(ffdcFile));

    AdditionalData ad;
    NiceMock<MockDataInterface> dataIface;
    NiceMock<MockJournal> journal;

    EXPECT_CALL(dataIface, expandLocationCode("P0-C1", 0))
        .Times(1)
        .WillOnce(Return("UXXX-P0-C1"));
    EXPECT_CALL(dataIface, getInventoryFromLocCode("P0-C1", 0, false))
        .Times(1)
        .WillOnce(Return(
            std::vector<std::string>{"/inv/system/chassis/motherboard/bmc"}));
    EXPECT_CALL(dataIface, getHWCalloutFields(
                               "/inv/system/chassis/motherboard/bmc", _, _, _))
        .Times(1)
        .WillOnce(DoAll(SetArgReferee<1>("1234567"), SetArgReferee<2>("CCCC"),
                        SetArgReferee<3>("123456789ABC")));

    std::vector<std::string> dumpType{"bmc/entry", "resource/entry",
                                      "system/entry"};
    EXPECT_CALL(dataIface, checkDumpStatus(dumpType))
        .WillOnce(Return(std::vector<bool>{false, false, false}));

    message::Entry regEntry;
    regEntry.name = "test";
    regEntry.subsystem = 5;
    regEntry.actionFlags = 0xC000;
    regEntry.src.type = 0xBD;
    regEntry.src.reasonCode = 0x1234;

    PEL pel{regEntry, 42,   5,         phosphor::logging::Entry::Level::Error,
            ad,       ffdc, dataIface, journal};

    ASSERT_TRUE(pel.valid());
    ASSERT_TRUE(pel.primarySRC().value()->callouts());
    const auto& callouts = pel.primarySRC().value()->callouts()->callouts();
    ASSERT_EQ(callouts.size(), 2);
    ASSERT_TRUE(pel.isHwCalloutPresent());

    {
        EXPECT_EQ(callouts[0]->priority(), 'H');
        EXPECT_EQ(callouts[0]->locationCode(), "UXXX-P0-C1");

        auto& fru = callouts[0]->fruIdentity();
        EXPECT_EQ(fru->getPN().value(), "1234567");
        EXPECT_EQ(fru->getCCIN().value(), "CCCC");
        EXPECT_EQ(fru->getSN().value(), "123456789ABC");
        EXPECT_EQ(fru->failingComponentType(), src::FRUIdentity::hardwareFRU);
    }
    {
        EXPECT_EQ(callouts[1]->priority(), 'M');
        EXPECT_EQ(callouts[1]->locationCode(), "");

        auto& fru = callouts[1]->fruIdentity();
        EXPECT_EQ(fru->getMaintProc().value(), "PROCEDU");
        EXPECT_EQ(fru->failingComponentType(),
                  src::FRUIdentity::maintenanceProc);
    }
    fs::remove_all(dir);
}

// Test PELs with symblic FRU callout.
TEST_F(PELTest, CreateWithJSONSymblicCalloutTest)
{
    PelFFDCfile ffdcFile;
    ffdcFile.format = UserDataFormat::json;
    ffdcFile.subType = 0xCA; // Callout JSON
    ffdcFile.version = 1;

    // Write these callouts to a JSON file and pass it into
    // the PEL as an FFDC file.
    auto inputJSON = R"([
        {
            "Priority": "M",
            "Procedure": "SVCDOCS"
        }
    ])"_json;

    auto s = inputJSON.dump();
    std::vector<uint8_t> data{s.begin(), s.end()};
    auto dir = makeTempDir();
    ffdcFile.fd = writeFileAndGetFD(dir, data);

    PelFFDC ffdc;
    ffdc.push_back(std::move(ffdcFile));

    AdditionalData ad;
    NiceMock<MockDataInterface> dataIface;
    NiceMock<MockJournal> journal;

    std::vector<std::string> dumpType{"bmc/entry", "resource/entry",
                                      "system/entry"};
    EXPECT_CALL(dataIface, checkDumpStatus(dumpType))
        .WillRepeatedly(Return(std::vector<bool>{false, false, false}));

    message::Entry regEntry;
    regEntry.name = "test";
    regEntry.subsystem = 5;
    regEntry.actionFlags = 0xC000;
    regEntry.src.type = 0xBD;
    regEntry.src.reasonCode = 0x1234;

    PEL pel{regEntry, 42,   5,         phosphor::logging::Entry::Level::Error,
            ad,       ffdc, dataIface, journal};

    ASSERT_TRUE(pel.valid());
    ASSERT_TRUE(pel.primarySRC().value()->callouts());
    const auto& callouts = pel.primarySRC().value()->callouts()->callouts();
    ASSERT_EQ(callouts.size(), 1);
    ASSERT_FALSE(pel.isHwCalloutPresent());

    {
        EXPECT_EQ(callouts[0]->priority(), 'M');
        EXPECT_EQ(callouts[0]->locationCode(), "");

        auto& fru = callouts[0]->fruIdentity();
        EXPECT_EQ(fru->getMaintProc().value(), "SVCDOCS");
    }
    fs::remove_all(dir);
}

TEST_F(PELTest, FlattenLinesTest)
{
    std::vector<std::string> msgs{"test1 test2", "test3 test4", "test5 test6"};

    auto buffer = util::flattenLines(msgs);

    std::string string{"test1 test2\ntest3 test4\ntest5 test6\n"};
    std::vector<uint8_t> expected(string.begin(), string.end());

    EXPECT_EQ(buffer, expected);
}

void checkJournalSection(const std::unique_ptr<Section>& section,
                         const std::string& expected)
{
    ASSERT_EQ(SectionID::userData,
              static_cast<SectionID>(section->header().id));
    ASSERT_EQ(UserDataFormat::text,
              static_cast<UserDataFormat>(section->header().subType));
    ASSERT_EQ(section->header().version,
              static_cast<uint8_t>(UserDataFormatVersion::text));

    auto ud = static_cast<UserData*>(section.get());

    std::vector<uint8_t> expectedData(expected.begin(), expected.end());

    // PEL sections are 4B aligned so add padding before the compare
    while (expectedData.size() % 4 != 0)
    {
        expectedData.push_back('\0');
    }

    EXPECT_EQ(ud->data(), expectedData);
}

TEST_F(PELTest, CaptureJournalTest)
{
    message::Entry regEntry;
    uint64_t timestamp = 5;

    regEntry.name = "test";
    regEntry.subsystem = 5;
    regEntry.actionFlags = 0xC000;
    regEntry.src.type = 0xBD;
    regEntry.src.reasonCode = 0x1234;

    std::vector<std::string> data;
    AdditionalData ad{data};
    NiceMock<MockDataInterface> dataIface;
    NiceMock<MockJournal> journal;
    PelFFDC ffdc;

    std::vector<std::string> dumpType{"bmc/entry", "resource/entry",
                                      "system/entry"};
    EXPECT_CALL(dataIface, checkDumpStatus(dumpType))
        .WillRepeatedly(Return(std::vector<bool>{false, false, false}));

    size_t pelSectsWithOneUD{0};

    {
        // Capture 5 lines from the journal into a single UD section
        message::JournalCapture jc = size_t{5};
        regEntry.journalCapture = jc;

        std::vector<std::string> msgs{"test1 test2", "test3 test4",
                                      "test5 test6", "4", "5"};

        EXPECT_CALL(journal, getMessages("", 5)).WillOnce(Return(msgs));

        PEL pel{
            regEntry, 42,   timestamp, phosphor::logging::Entry::Level::Error,
            ad,       ffdc, dataIface, journal};

        // Check the generated UserData section
        std::string expected{"test1 test2\ntest3 test4\ntest5 test6\n4\n5\n"};

        checkJournalSection(pel.optionalSections().back(), expected);

        // Save for upcoming testcases
        pelSectsWithOneUD = pel.privateHeader().sectionCount();
    }

    {
        // Attempt to capture too many journal entries so the
        // section gets dropped.
        message::JournalCapture jc = size_t{1};
        regEntry.journalCapture = jc;

        EXPECT_CALL(journal, sync()).Times(1);

        // A 20000 byte line won't fit in a PEL
        EXPECT_CALL(journal, getMessages("", 1))
            .WillOnce(
                Return(std::vector<std::string>{std::string(20000, 'x')}));

        PEL pel{
            regEntry, 42,   timestamp, phosphor::logging::Entry::Level::Error,
            ad,       ffdc, dataIface, journal};

        // Check for 1 fewer sections than in the previous PEL
        EXPECT_EQ(pel.privateHeader().sectionCount(), pelSectsWithOneUD - 1);
    }

    // Capture 3 different journal sections
    {
        message::AppCaptureList captureList{
            message::AppCapture{"app1", 3},
            message::AppCapture{"app2", 4},
            message::AppCapture{"app3", 1},
        };
        message::JournalCapture jc = captureList;
        regEntry.journalCapture = jc;

        std::vector<std::string> app1{"A B", "C D", "E F"};
        std::vector<std::string> app2{"1 2", "3 4", "5 6", "7 8"};
        std::vector<std::string> app3{"a b c"};

        std::string expected1{"A B\nC D\nE F\n"};
        std::string expected2{"1 2\n3 4\n5 6\n7 8\n"};
        std::string expected3{"a b c\n"};

        EXPECT_CALL(journal, sync()).Times(1);
        EXPECT_CALL(journal, getMessages("app1", 3)).WillOnce(Return(app1));
        EXPECT_CALL(journal, getMessages("app2", 4)).WillOnce(Return(app2));
        EXPECT_CALL(journal, getMessages("app3", 1)).WillOnce(Return(app3));

        PEL pel{
            regEntry, 42,   timestamp, phosphor::logging::Entry::Level::Error,
            ad,       ffdc, dataIface, journal};

        // Two more sections than the 1 extra UD section in the first testcase
        ASSERT_EQ(pel.privateHeader().sectionCount(), pelSectsWithOneUD + 2);

        const auto& optionalSections = pel.optionalSections();
        auto numOptSections = optionalSections.size();

        checkJournalSection(optionalSections[numOptSections - 3], expected1);
        checkJournalSection(optionalSections[numOptSections - 2], expected2);
        checkJournalSection(optionalSections[numOptSections - 1], expected3);
    }

    {
        // One section gets saved, and one is too big and gets dropped
        message::AppCaptureList captureList{
            message::AppCapture{"app4", 2},
            message::AppCapture{"app5", 1},
        };
        message::JournalCapture jc = captureList;
        regEntry.journalCapture = jc;

        std::vector<std::string> app4{"w x", "y z"};
        std::string expected4{"w x\ny z\n"};

        EXPECT_CALL(journal, sync()).Times(1);

        EXPECT_CALL(journal, getMessages("app4", 2)).WillOnce(Return(app4));

        // A 20000 byte line won't fit in a PEL
        EXPECT_CALL(journal, getMessages("app5", 1))
            .WillOnce(
                Return(std::vector<std::string>{std::string(20000, 'x')}));

        PEL pel{
            regEntry, 42,   timestamp, phosphor::logging::Entry::Level::Error,
            ad,       ffdc, dataIface, journal};

        // The last section should have been dropped, so same as first TC
        ASSERT_EQ(pel.privateHeader().sectionCount(), pelSectsWithOneUD);

        checkJournalSection(pel.optionalSections().back(), expected4);
    }
}
