blob: ceccb5f83eb94d7c474142c047053e75576eaca1 [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 +
Rekha Aparnac6159a22025-10-09 12:20:20 +053024 "], error : " + commonUtility::getErrCodeMsg(l_errCode));
Rekha Aparnaca9a0862025-08-29 04:08:33 -050025 }
26
Sunny Srivastavafa5e4d32023-03-12 11:59:49 -050027 const bool l_result =
Rekha Aparna52041882025-09-01 20:48:07 -050028 jsonUtility::isFruPowerOffOnly(l_parsedJson, l_vpdPath, l_errCode);
29
30 if (l_errCode)
31 {
32 logging::logMessage(
33 "Failed to check if FRU is power off only for FRU [" + l_vpdPath +
Rekha Aparnac6159a22025-10-09 12:20:20 +053034 "], error : " + commonUtility::getErrCodeMsg(l_errCode));
Rekha Aparna52041882025-09-01 20:48:07 -050035 }
36
Sunny Srivastavafa5e4d32023-03-12 11:59:49 -050037 EXPECT_TRUE(l_result);
38}
39
40TEST(IsFruPowerOffOnlyTest, NegativeTestCase)
41{
Rekha Aparnaca9a0862025-08-29 04:08:33 -050042 uint16_t l_errCode = 0;
Sunny Srivastavafa5e4d32023-03-12 11:59:49 -050043 const std::string l_jsonPath{"/usr/local/share/vpd/50001001.json"};
44 const std::string l_vpdPath{"/sys/bus/i2c/drivers/at24/4-0050/eeprom"};
Rekha Aparnaca9a0862025-08-29 04:08:33 -050045 const nlohmann::json l_parsedJson =
46 jsonUtility::getParsedJson(l_jsonPath, l_errCode);
47
48 if (l_errCode)
49 {
50 logging::logMessage(
51 "Failed to parse JSON file [" + l_jsonPath +
Rekha Aparnac6159a22025-10-09 12:20:20 +053052 "], error : " + commonUtility::getErrCodeMsg(l_errCode));
Rekha Aparnaca9a0862025-08-29 04:08:33 -050053 }
54
Sunny Srivastavafa5e4d32023-03-12 11:59:49 -050055 const bool l_result =
Rekha Aparna52041882025-09-01 20:48:07 -050056 jsonUtility::isFruPowerOffOnly(l_parsedJson, l_vpdPath, l_errCode);
57
58 if (l_errCode)
59 {
60 logging::logMessage(
61 "Failed to check if FRU is power off only for FRU [" + l_vpdPath +
Rekha Aparnac6159a22025-10-09 12:20:20 +053062 "], error : " + commonUtility::getErrCodeMsg(l_errCode));
Rekha Aparna52041882025-09-01 20:48:07 -050063 }
64
Sunny Srivastavafa5e4d32023-03-12 11:59:49 -050065 EXPECT_FALSE(l_result);
66}