diff options
Diffstat (limited to 'test/openpower-pels/fru_identity_test.cpp')
-rw-r--r-- | test/openpower-pels/fru_identity_test.cpp | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/test/openpower-pels/fru_identity_test.cpp b/test/openpower-pels/fru_identity_test.cpp new file mode 100644 index 0000000..a6839b8 --- /dev/null +++ b/test/openpower-pels/fru_identity_test.cpp @@ -0,0 +1,89 @@ +/** + * 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 "extensions/openpower-pels/fru_identity.hpp" + +#include <gtest/gtest.h> + +using namespace openpower::pels; +using namespace openpower::pels::src; + +// Unflatten a FRUIdentity that is a HW FRU callout +TEST(FRUIdentityTest, TestHardwareFRU) +{ + // Has PN, SN, CCIN + std::vector<uint8_t> data{'I', 'D', 0x1C, 0x1D, // type, size, flags + '1', '2', '3', '4', // PN + '5', '6', '7', 0x00, 'A', 'A', 'A', 'A', // CCIN + '1', '2', '3', '4', '5', '6', '7', '8', // SN + '9', 'A', 'B', 'C'}; + + Stream stream{data}; + + FRUIdentity fru{stream}; + + EXPECT_EQ(fru.failingComponentType(), FRUIdentity::hardwareFRU); + EXPECT_EQ(fru.flattenedSize(), data.size()); + + EXPECT_EQ(fru.getPN().value(), "1234567"); + EXPECT_EQ(fru.getCCIN().value(), "AAAA"); + EXPECT_EQ(fru.getSN().value(), "123456789ABC"); + EXPECT_FALSE(fru.getMaintProc()); + + // Flatten + std::vector<uint8_t> newData; + Stream newStream{newData}; + fru.flatten(newStream); + EXPECT_EQ(data, newData); +} + +// Unflatten a FRUIdentity that is a Maintenance Procedure callout +TEST(FRUIdentityTest, TestMaintProcedure) +{ + // Only contains the maintenance procedure + std::vector<uint8_t> data{ + 0x49, 0x44, 0x0C, 0x42, // type, size, flags + '1', '2', '3', '4', '5', '6', '7', 0x00 // Procedure + }; + + Stream stream{data}; + + FRUIdentity fru{stream}; + + EXPECT_EQ(fru.failingComponentType(), FRUIdentity::maintenanceProc); + EXPECT_EQ(fru.flattenedSize(), data.size()); + + EXPECT_EQ(fru.getMaintProc().value(), "1234567"); + EXPECT_FALSE(fru.getPN()); + EXPECT_FALSE(fru.getCCIN()); + EXPECT_FALSE(fru.getSN()); + + // Flatten + std::vector<uint8_t> newData; + Stream newStream{newData}; + fru.flatten(newStream); + EXPECT_EQ(data, newData); +} + +// Try to unflatten garbage data +TEST(FRUIdentityTest, BadDataTest) +{ + std::vector<uint8_t> data{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF}; + + Stream stream{data}; + + EXPECT_THROW(FRUIdentity fru{stream}, std::out_of_range); +} |