blob: 12598da27ddd30ee184f1fd5950ac19d02d46a85 [file] [log] [blame]
Sunny Srivastavafa5e4d32023-03-12 11:59:49 -05001#include "parser.hpp"
2#include "types.hpp"
3#include "utility/json_utility.hpp"
Rekha Aparnaca9a0862025-08-29 04:08:33 -05004#include "utility/vpd_specific_utility.hpp"
Sunny Srivastavafa5e4d32023-03-12 11:59:49 -05005
6#include <iostream>
7
8#include <gtest/gtest.h>
9
10using namespace vpd;
11
12TEST(IsFruPowerOffOnlyTest, PositiveTestCase)
13{
Rekha Aparnaca9a0862025-08-29 04:08:33 -050014 uint16_t l_errCode = 0;
Sunny Srivastavafa5e4d32023-03-12 11:59:49 -050015 const std::string l_jsonPath{"/usr/local/share/vpd/50001001.json"};
16 const std::string l_vpdPath{"/sys/bus/spi/drivers/at25/spi12.0/eeprom"};
Rekha Aparnaca9a0862025-08-29 04:08:33 -050017 const nlohmann::json l_parsedJson =
18 jsonUtility::getParsedJson(l_jsonPath, l_errCode);
19
20 if (l_errCode)
21 {
22 logging::logMessage(
23 "Failed to parse JSON file [" + l_jsonPath +
24 "], error : " + vpdSpecificUtility::getErrCodeMsg(l_errCode));
25 }
26
Rekha Aparna52041882025-09-01 20:48:07 -050027 l_errCode = 0;
Sunny Srivastavafa5e4d32023-03-12 11:59:49 -050028 const bool l_result =
Rekha Aparna52041882025-09-01 20:48:07 -050029 jsonUtility::isFruPowerOffOnly(l_parsedJson, l_vpdPath, l_errCode);
30
31 if (l_errCode)
32 {
33 logging::logMessage(
34 "Failed to check if FRU is power off only for FRU [" + l_vpdPath +
35 "], error : " + vpdSpecificUtility::getErrCodeMsg(l_errCode));
36 }
37
Sunny Srivastavafa5e4d32023-03-12 11:59:49 -050038 EXPECT_TRUE(l_result);
39}
40
41TEST(IsFruPowerOffOnlyTest, NegativeTestCase)
42{
Rekha Aparnaca9a0862025-08-29 04:08:33 -050043 uint16_t l_errCode = 0;
Sunny Srivastavafa5e4d32023-03-12 11:59:49 -050044 const std::string l_jsonPath{"/usr/local/share/vpd/50001001.json"};
45 const std::string l_vpdPath{"/sys/bus/i2c/drivers/at24/4-0050/eeprom"};
Rekha Aparnaca9a0862025-08-29 04:08:33 -050046 const nlohmann::json l_parsedJson =
47 jsonUtility::getParsedJson(l_jsonPath, l_errCode);
48
49 if (l_errCode)
50 {
51 logging::logMessage(
52 "Failed to parse JSON file [" + l_jsonPath +
53 "], error : " + vpdSpecificUtility::getErrCodeMsg(l_errCode));
54 }
55
Rekha Aparna52041882025-09-01 20:48:07 -050056 l_errCode = 0;
Sunny Srivastavafa5e4d32023-03-12 11:59:49 -050057 const bool l_result =
Rekha Aparna52041882025-09-01 20:48:07 -050058 jsonUtility::isFruPowerOffOnly(l_parsedJson, l_vpdPath, l_errCode);
59
60 if (l_errCode)
61 {
62 logging::logMessage(
63 "Failed to check if FRU is power off only for FRU [" + l_vpdPath +
64 "], error : " + vpdSpecificUtility::getErrCodeMsg(l_errCode));
65 }
66
Sunny Srivastavafa5e4d32023-03-12 11:59:49 -050067 EXPECT_FALSE(l_result);
68}