blob: 364a3f17e75e71a0394949e72b6f4e63a8c9f2e3 [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",
Priyanga Ramasamye606f062025-01-27 07:16:37 -060029 {0x33, 0x32, 0x41, 0x31}},
30 std::pair<std::string, types::BinaryVector>{"DI", {0x80, 0xCE}}};
Sunny Srivastavafa5e4d32023-03-12 11:59:49 -050031
32 nlohmann::json l_json;
33 std::string l_vpdFile("vpd_files/ddr5_ddimm.dat");
34 Parser l_vpdParser(l_vpdFile, l_json);
35
36 ASSERT_EQ(1,
37 l_ddimmMap == std::get<types::DdimmVpdMap>(l_vpdParser.parse()));
38}
39
40TEST(DdimmVpdParserTest, DDR4GoodTestCase)
41{
42 types::DdimmVpdMap l_ddimmMap{
43 std::pair<std::string, size_t>{"MemorySizeInKB", 0x4000000},
44 std::pair<std::string, types::BinaryVector>{
45 "FN", {0x37, 0x38, 0x50, 0x36, 0x35, 0x37, 0x35}},
46 std::pair<std::string, types::BinaryVector>{
47 "PN", {0x37, 0x38, 0x50, 0x36, 0x35, 0x37, 0x35}},
48 std::pair<std::string, types::BinaryVector>{
49 "SN",
50 {0x59, 0x48, 0x33, 0x35, 0x31, 0x54, 0x31, 0x35, 0x53, 0x30, 0x44,
51 0x35}},
52 std::pair<std::string, types::BinaryVector>{"CC",
Priyanga Ramasamye606f062025-01-27 07:16:37 -060053 {0x33, 0x32, 0x37, 0x42}},
54 std::pair<std::string, types::BinaryVector>{"DI", {0x80, 0xAD}}};
Sunny Srivastavafa5e4d32023-03-12 11:59:49 -050055
56 nlohmann::json l_json;
57 std::string l_vpdFile("vpd_files/ddr4_ddimm.dat");
58 Parser l_vpdParser(l_vpdFile, l_json);
59
60 ASSERT_EQ(1,
61 l_ddimmMap == std::get<types::DdimmVpdMap>(l_vpdParser.parse()));
62}
63
64TEST(DdimmVpdParserTest, InvalidDdrType)
65{
66 // Invalid DDR type, corrupted at index[2]
67 nlohmann::json l_json;
68 std::string l_vpdFile("vpd_files/ddr5_ddimm_corrupted_index_2.dat");
69 Parser l_vpdParser(l_vpdFile, l_json);
70
71 EXPECT_THROW(l_vpdParser.parse(), std::exception);
72}
73
74TEST(DdimmVpdParserTest, ZeroDdimmSize)
75{
76 // Badly formed DDIMM VPD data - corrupted at index[235],
77 // ddimm size calculated a zero
78 nlohmann::json l_json;
79 std::string l_vpdFile("vpd_files/ddr5_ddimm_corrupted_index_235.dat");
80 Parser l_vpdParser(l_vpdFile, l_json);
81
82 EXPECT_THROW(l_vpdParser.parse(), std::exception);
83}
84
85TEST(DdimmVpdParserTest, InvalidDensityPerDie)
86{
87 // Out of range data, fails to check valid value - corrupted at index[4]
88 nlohmann::json l_json;
89 std::string l_vpdFile("vpd_files/ddr5_ddimm_corrupted_index_4.dat");
90 Parser l_vpdParser(l_vpdFile, l_json);
91
92 EXPECT_THROW(l_vpdParser.parse(), std::exception);
93}
94
95TEST(DdimmVpdParserTest, InvalidVpdType)
96{
97 // Invalid VPD type - corrupted at index[2] & index[3]
98 // Not able to find the VPD type, vpdTypeCheck failed
99 nlohmann::json l_json;
100 std::string l_vpdFile("vpd_files/ddr5_ddimm_corrupted_index_2_3.dat");
101 Parser l_vpdParser(l_vpdFile, l_json);
102
103 EXPECT_THROW(l_vpdParser.parse(), std::exception);
104}
105
106TEST(DdimmVpdParserTest, EmptyInputVector)
107{
108 // Blank VPD
109 types::BinaryVector emptyVector{};
110
111 EXPECT_THROW(DdimmVpdParser(std::move(emptyVector)), DataException);
112}
113
114int main(int i_argc, char** io_argv)
115{
116 ::testing::InitGoogleTest(&i_argc, io_argv);
117
118 return RUN_ALL_TESTS();
119}