blob: 0a36ad7f9d5c851f1575addef5ec85e1a78b7f98 [file] [log] [blame]
SunnySrivastava1984e12b1812020-05-26 02:23:11 -05001#include "ipz_parser.hpp"
2
girik18bb9852022-11-16 05:48:13 -06003#include <const.hpp>
Alpana Kumari26a74af2019-09-10 23:53:58 -05004#include <defines.hpp>
Alpana Kumari26a74af2019-09-10 23:53:58 -05005#include <impl.hpp>
Alpana Kumari26a74af2019-09-10 23:53:58 -05006#include <store.hpp>
7
Patrick Williamsc78d8872023-05-10 07:50:56 -05008#include <cassert>
9#include <fstream>
10#include <iterator>
11
Alpana Kumari26a74af2019-09-10 23:53:58 -050012#include <gtest/gtest.h>
13
14using namespace openpower::vpd;
girik18bb9852022-11-16 05:48:13 -060015using namespace openpower::vpd::constants;
16
17constexpr uint32_t vpdOffset = 0;
Alpana Kumari26a74af2019-09-10 23:53:58 -050018
19TEST(IpzVpdParserApp, vpdGoodPath)
20{
21 // Create a vpd
22 Binary vpd = {
23 0x00, 0x0f, 0x17, 0xba, 0x42, 0xca, 0x82, 0xd7, 0x7b, 0x77, 0x1e, 0x84,
24 0x28, 0x00, 0x52, 0x54, 0x04, 0x56, 0x48, 0x44, 0x52, 0x56, 0x44, 0x02,
25 0x30, 0x31, 0x50, 0x54, 0x0e, 0x56, 0x54, 0x4f, 0x43, 0xd5, 0x00, 0x37,
26 0x00, 0x4c, 0x00, 0x97, 0x05, 0x13, 0x00, 0x50, 0x46, 0x08, 0x00, 0x00,
27 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x84, 0x48, 0x00, 0x52, 0x54,
28 0x04, 0x56, 0x54, 0x4f, 0x43, 0x50, 0x54, 0x0e, 0x56, 0x49, 0x4e, 0x49,
29 0xd5, 0x00, 0x52, 0x00, 0x90, 0x00, 0x73, 0x05, 0x24, 0x00, 0x84, 0x8c,
30 0x00, 0x52, 0x54, 0x04, 0x56, 0x49, 0x4e, 0x49, 0x44, 0x52, 0x10, 0x41,
31 0x50, 0x53, 0x53, 0x20, 0x26, 0x20, 0x54, 0x50, 0x4d, 0x20, 0x20, 0x43,
32 0x41, 0x52, 0x44, 0x43, 0x45, 0x01, 0x31, 0x56, 0x5a, 0x02, 0x30, 0x31,
33 0x46, 0x4e, 0x07, 0x30, 0x31, 0x44, 0x48, 0x32, 0x30, 0x30, 0x50, 0x4e,
34 0x07, 0x30, 0x31, 0x44, 0x48, 0x32, 0x30, 0x31, 0x53, 0x4e, 0x0c, 0x59,
35 0x4c, 0x33, 0x30, 0x42, 0x47, 0x37, 0x43, 0x46, 0x30, 0x33, 0x50, 0x43,
36 0x43, 0x04, 0x36, 0x42, 0x36, 0x36, 0x50, 0x52, 0x08, 0x00, 0x00, 0x00,
37 0x00, 0x00, 0x00, 0x00, 0x00, 0x48, 0x45, 0x04, 0x30, 0x30, 0x30, 0x31,
38 0x43, 0x54, 0x04, 0x40, 0xb8, 0x02, 0x03, 0x48, 0x57, 0x02, 0x00, 0x01,
39 0x42, 0x33, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x34, 0x01,
40 0x00, 0x42, 0x37, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
41 0x00, 0x00, 0x00, 0x00, 0x50, 0x46, 0x02, 0x00, 0x00, 0x78, 0x84, 0xdc,
42 0x00, 0x52, 0x54, 0x04};
43
44 // call app for this vpd
girik18bb9852022-11-16 05:48:13 -060045 parser::Impl p(std::move(vpd), std::string{}, systemVpdFilePath, vpdOffset);
Alpana Kumari26a74af2019-09-10 23:53:58 -050046 Store vpdStore = p.run();
47
48 static const std::string record = "VINI";
49 static const std::string keyword = "DR";
50
51 // TODO 2: Move this as an utility to store.hpp
52 std::string dataFound;
53 Parsed st_bin = vpdStore.getVpdMap();
54
55 auto kw = st_bin.find(record);
56 if (st_bin.end() != kw)
57 {
58 auto value = (kw->second).find(keyword);
59 if ((kw->second).end() != value)
60 {
61 dataFound = value->second;
62 }
63 }
64
65 ASSERT_EQ(dataFound, "APSS & TPM CARD");
66}
67
68TEST(IpzVpdParserApp, vpdBadPathEmptyVPD)
69{
70 Binary vpd = {};
71
72 // VPD is empty
girik18bb9852022-11-16 05:48:13 -060073 parser::Impl p(std::move(vpd), std::string{}, systemVpdFilePath, vpdOffset);
Alpana Kumari26a74af2019-09-10 23:53:58 -050074
75 // Expecting a throw here
76 EXPECT_THROW(p.run(), std::runtime_error);
77}
78
79TEST(IpzVpdParserApp, vpdBadPathMissingHeader)
80{
81 Binary vpd = {
82 0x00, 0x0f, 0x17, 0xba, 0x42, 0xca, 0x82, 0xd7, 0x7b, 0x77, 0x1e, 0x84,
83 0x28, 0x00, 0x52, 0x54, 0x04, 0x56, 0x48, 0x44, 0x52, 0x56, 0x44, 0x02,
84 0x30, 0x31, 0x50, 0x54, 0x0e, 0x56, 0x54, 0x4f, 0x43, 0xd5, 0x00, 0x37,
85 0x00, 0x4c, 0x00, 0x97, 0x05, 0x13, 0x00, 0x50, 0x46, 0x08, 0x00, 0x00,
86 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x84, 0x48, 0x00, 0x52, 0x54,
87 0x04, 0x56, 0x54, 0x4f, 0x43, 0x50, 0x54, 0x0e, 0x56, 0x49, 0x4e, 0x49,
88 0xd5, 0x00, 0x52, 0x00, 0x90, 0x00, 0x73, 0x05, 0x24, 0x00, 0x84, 0x8c,
89 0x00, 0x52, 0x54, 0x04, 0x56, 0x49, 0x4e, 0x49, 0x44, 0x52, 0x10, 0x41,
90 0x50, 0x53, 0x53, 0x20, 0x26, 0x20, 0x54, 0x50, 0x4d, 0x20, 0x20, 0x43,
91 0x41, 0x52, 0x44, 0x43, 0x45, 0x01, 0x31, 0x56, 0x5a, 0x02, 0x30, 0x31,
92 0x46, 0x4e, 0x07, 0x30, 0x31, 0x44, 0x48, 0x32, 0x30, 0x30, 0x50, 0x4e,
93 0x07, 0x30, 0x31, 0x44, 0x48, 0x32, 0x30, 0x31, 0x53, 0x4e, 0x0c, 0x59,
94 0x4c, 0x33, 0x30, 0x42, 0x47, 0x37, 0x43, 0x46, 0x30, 0x33, 0x50, 0x43,
95 0x43, 0x04, 0x36, 0x42, 0x36, 0x36, 0x50, 0x52, 0x08, 0x00, 0x00, 0x00,
96 0x00, 0x00, 0x00, 0x00, 0x00, 0x48, 0x45, 0x04, 0x30, 0x30, 0x30, 0x31,
97 0x43, 0x54, 0x04, 0x40, 0xb8, 0x02, 0x03, 0x48, 0x57, 0x02, 0x00, 0x01,
98 0x42, 0x33, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x34, 0x01,
99 0x00, 0x42, 0x37, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
100 0x00, 0x00, 0x00, 0x00, 0x50, 0x46, 0x02, 0x00, 0x00, 0x78, 0x84, 0xdc,
101 0x00, 0x52, 0x54, 0x04};
102
103 // corrupt the VHDR
104 vpd[17] = 0x00;
105
girik18bb9852022-11-16 05:48:13 -0600106 parser::Impl p(std::move(vpd), std::string{}, systemVpdFilePath, vpdOffset);
Alpana Kumari26a74af2019-09-10 23:53:58 -0500107
108 // Expecting a throw here
109 EXPECT_THROW(p.run(), std::runtime_error);
110}
111
112TEST(IpzVpdParserApp, vpdBadPathMissingVTOC)
113{
114 Binary vpd = {
115 0x00, 0x0f, 0x17, 0xba, 0x42, 0xca, 0x82, 0xd7, 0x7b, 0x77, 0x1e, 0x84,
116 0x28, 0x00, 0x52, 0x54, 0x04, 0x56, 0x48, 0x44, 0x52, 0x56, 0x44, 0x02,
117 0x30, 0x31, 0x50, 0x54, 0x0e, 0x56, 0x54, 0x4f, 0x43, 0xd5, 0x00, 0x37,
118 0x00, 0x4c, 0x00, 0x97, 0x05, 0x13, 0x00, 0x50, 0x46, 0x08, 0x00, 0x00,
119 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x84, 0x48, 0x00, 0x52, 0x54,
120 0x04, 0x56, 0x54, 0x4f, 0x43, 0x50, 0x54, 0x0e, 0x56, 0x49, 0x4e, 0x49,
121 0xd5, 0x00, 0x52, 0x00, 0x90, 0x00, 0x73, 0x05, 0x24, 0x00, 0x84, 0x8c,
122 0x00, 0x52, 0x54, 0x04, 0x56, 0x49, 0x4e, 0x49, 0x44, 0x52, 0x10, 0x41,
123 0x50, 0x53, 0x53, 0x20, 0x26, 0x20, 0x54, 0x50, 0x4d, 0x20, 0x20, 0x43,
124 0x41, 0x52, 0x44, 0x43, 0x45, 0x01, 0x31, 0x56, 0x5a, 0x02, 0x30, 0x31,
125 0x46, 0x4e, 0x07, 0x30, 0x31, 0x44, 0x48, 0x32, 0x30, 0x30, 0x50, 0x4e,
126 0x07, 0x30, 0x31, 0x44, 0x48, 0x32, 0x30, 0x31, 0x53, 0x4e, 0x0c, 0x59,
127 0x4c, 0x33, 0x30, 0x42, 0x47, 0x37, 0x43, 0x46, 0x30, 0x33, 0x50, 0x43,
128 0x43, 0x04, 0x36, 0x42, 0x36, 0x36, 0x50, 0x52, 0x08, 0x00, 0x00, 0x00,
129 0x00, 0x00, 0x00, 0x00, 0x00, 0x48, 0x45, 0x04, 0x30, 0x30, 0x30, 0x31,
130 0x43, 0x54, 0x04, 0x40, 0xb8, 0x02, 0x03, 0x48, 0x57, 0x02, 0x00, 0x01,
131 0x42, 0x33, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x34, 0x01,
132 0x00, 0x42, 0x37, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
133 0x00, 0x00, 0x00, 0x00, 0x50, 0x46, 0x02, 0x00, 0x00, 0x78, 0x84, 0xdc,
134 0x00, 0x52, 0x54, 0x04};
135
136 // corrupt the VTOC
137 vpd[61] = 0x00;
138
girik18bb9852022-11-16 05:48:13 -0600139 parser::Impl p(std::move(vpd), std::string{}, systemVpdFilePath, vpdOffset);
Alpana Kumari26a74af2019-09-10 23:53:58 -0500140
141 // Expecting a throw here
142 EXPECT_THROW(p.run(), std::runtime_error);
143}
144
145int main(int argc, char** argv)
146{
147 ::testing::InitGoogleTest(&argc, argv);
148
149 return RUN_ALL_TESTS();
150}