blob: 6674c5169c525974a564e9a24f491a84184e5407 [file] [log] [blame]
Sunny Srivastavafa5e4d32023-03-12 11:59:49 -05001#include "vpdecc.h"
2
3#include "ddimm_parser.hpp"
4#include "exceptions.hpp"
5#include "parser.hpp"
6#include "types.hpp"
7
8#include <cstdint>
9#include <exception>
10#include <fstream>
11
12#include <gtest/gtest.h>
13
14using namespace vpd;
15
16TEST(DdimmVpdParserTest, GoodTestCase)
17{
18 types::DdimmVpdMap l_ddimmMap{
19 std::pair<std::string, size_t>{"MemorySizeInKB", 0x2000000},
20 std::pair<std::string, types::BinaryVector>{
21 "FN", {0x30, 0x33, 0x48, 0x44, 0x37, 0x30, 0x30}},
22 std::pair<std::string, types::BinaryVector>{
23 "PN", {0x30, 0x33, 0x48, 0x44, 0x37, 0x30, 0x30}},
24 std::pair<std::string, types::BinaryVector>{
25 "SN",
26 {0x59, 0x48, 0x33, 0x33, 0x31, 0x54, 0x33, 0x38, 0x34, 0x30, 0x33,
27 0x46}},
28 std::pair<std::string, types::BinaryVector>{"CC",
29 {0x33, 0x32, 0x41, 0x31}}};
30
31 nlohmann::json l_json;
32 std::string l_vpdFile("vpd_files/ddr5_ddimm.dat");
33 Parser l_vpdParser(l_vpdFile, l_json);
34
35 ASSERT_EQ(1,
36 l_ddimmMap == std::get<types::DdimmVpdMap>(l_vpdParser.parse()));
37}
38
39TEST(DdimmVpdParserTest, DDR4GoodTestCase)
40{
41 types::DdimmVpdMap l_ddimmMap{
42 std::pair<std::string, size_t>{"MemorySizeInKB", 0x4000000},
43 std::pair<std::string, types::BinaryVector>{
44 "FN", {0x37, 0x38, 0x50, 0x36, 0x35, 0x37, 0x35}},
45 std::pair<std::string, types::BinaryVector>{
46 "PN", {0x37, 0x38, 0x50, 0x36, 0x35, 0x37, 0x35}},
47 std::pair<std::string, types::BinaryVector>{
48 "SN",
49 {0x59, 0x48, 0x33, 0x35, 0x31, 0x54, 0x31, 0x35, 0x53, 0x30, 0x44,
50 0x35}},
51 std::pair<std::string, types::BinaryVector>{"CC",
52 {0x33, 0x32, 0x37, 0x42}}};
53
54 nlohmann::json l_json;
55 std::string l_vpdFile("vpd_files/ddr4_ddimm.dat");
56 Parser l_vpdParser(l_vpdFile, l_json);
57
58 ASSERT_EQ(1,
59 l_ddimmMap == std::get<types::DdimmVpdMap>(l_vpdParser.parse()));
60}
61
62TEST(DdimmVpdParserTest, InvalidDdrType)
63{
64 // Invalid DDR type, corrupted at index[2]
65 nlohmann::json l_json;
66 std::string l_vpdFile("vpd_files/ddr5_ddimm_corrupted_index_2.dat");
67 Parser l_vpdParser(l_vpdFile, l_json);
68
69 EXPECT_THROW(l_vpdParser.parse(), std::exception);
70}
71
72TEST(DdimmVpdParserTest, ZeroDdimmSize)
73{
74 // Badly formed DDIMM VPD data - corrupted at index[235],
75 // ddimm size calculated a zero
76 nlohmann::json l_json;
77 std::string l_vpdFile("vpd_files/ddr5_ddimm_corrupted_index_235.dat");
78 Parser l_vpdParser(l_vpdFile, l_json);
79
80 EXPECT_THROW(l_vpdParser.parse(), std::exception);
81}
82
83TEST(DdimmVpdParserTest, InvalidDensityPerDie)
84{
85 // Out of range data, fails to check valid value - corrupted at index[4]
86 nlohmann::json l_json;
87 std::string l_vpdFile("vpd_files/ddr5_ddimm_corrupted_index_4.dat");
88 Parser l_vpdParser(l_vpdFile, l_json);
89
90 EXPECT_THROW(l_vpdParser.parse(), std::exception);
91}
92
93TEST(DdimmVpdParserTest, InvalidVpdType)
94{
95 // Invalid VPD type - corrupted at index[2] & index[3]
96 // Not able to find the VPD type, vpdTypeCheck failed
97 nlohmann::json l_json;
98 std::string l_vpdFile("vpd_files/ddr5_ddimm_corrupted_index_2_3.dat");
99 Parser l_vpdParser(l_vpdFile, l_json);
100
101 EXPECT_THROW(l_vpdParser.parse(), std::exception);
102}
103
104TEST(DdimmVpdParserTest, EmptyInputVector)
105{
106 // Blank VPD
107 types::BinaryVector emptyVector{};
108
109 EXPECT_THROW(DdimmVpdParser(std::move(emptyVector)), DataException);
110}
111
112int main(int i_argc, char** io_argv)
113{
114 ::testing::InitGoogleTest(&i_argc, io_argv);
115
116 return RUN_ALL_TESTS();
117}