| Sunny Srivastava | fa5e4d3 | 2023-03-12 11:59:49 -0500 | [diff] [blame] | 1 | #include "parser.hpp" |
| 2 | #include "types.hpp" |
| 3 | #include "utility/json_utility.hpp" |
| Rekha Aparna | ca9a086 | 2025-08-29 04:08:33 -0500 | [diff] [blame] | 4 | #include "utility/vpd_specific_utility.hpp" |
| Sunny Srivastava | fa5e4d3 | 2023-03-12 11:59:49 -0500 | [diff] [blame] | 5 | |
| 6 | #include <iostream> |
| 7 | |
| 8 | #include <gtest/gtest.h> |
| 9 | |
| 10 | using namespace vpd; |
| 11 | |
| 12 | TEST(IsFruPowerOffOnlyTest, PositiveTestCase) |
| 13 | { |
| Rekha Aparna | ca9a086 | 2025-08-29 04:08:33 -0500 | [diff] [blame] | 14 | uint16_t l_errCode = 0; |
| Sunny Srivastava | fa5e4d3 | 2023-03-12 11:59:49 -0500 | [diff] [blame] | 15 | 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 Aparna | ca9a086 | 2025-08-29 04:08:33 -0500 | [diff] [blame] | 17 | 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 Aparna | c6159a2 | 2025-10-09 12:20:20 +0530 | [diff] [blame] | 24 | "], error : " + commonUtility::getErrCodeMsg(l_errCode)); |
| Rekha Aparna | ca9a086 | 2025-08-29 04:08:33 -0500 | [diff] [blame] | 25 | } |
| 26 | |
| Sunny Srivastava | fa5e4d3 | 2023-03-12 11:59:49 -0500 | [diff] [blame] | 27 | const bool l_result = |
| Rekha Aparna | 5204188 | 2025-09-01 20:48:07 -0500 | [diff] [blame] | 28 | 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 Aparna | c6159a2 | 2025-10-09 12:20:20 +0530 | [diff] [blame] | 34 | "], error : " + commonUtility::getErrCodeMsg(l_errCode)); |
| Rekha Aparna | 5204188 | 2025-09-01 20:48:07 -0500 | [diff] [blame] | 35 | } |
| 36 | |
| Sunny Srivastava | fa5e4d3 | 2023-03-12 11:59:49 -0500 | [diff] [blame] | 37 | EXPECT_TRUE(l_result); |
| 38 | } |
| 39 | |
| 40 | TEST(IsFruPowerOffOnlyTest, NegativeTestCase) |
| 41 | { |
| Rekha Aparna | ca9a086 | 2025-08-29 04:08:33 -0500 | [diff] [blame] | 42 | uint16_t l_errCode = 0; |
| Sunny Srivastava | fa5e4d3 | 2023-03-12 11:59:49 -0500 | [diff] [blame] | 43 | 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 Aparna | ca9a086 | 2025-08-29 04:08:33 -0500 | [diff] [blame] | 45 | 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 Aparna | c6159a2 | 2025-10-09 12:20:20 +0530 | [diff] [blame] | 52 | "], error : " + commonUtility::getErrCodeMsg(l_errCode)); |
| Rekha Aparna | ca9a086 | 2025-08-29 04:08:33 -0500 | [diff] [blame] | 53 | } |
| 54 | |
| Sunny Srivastava | fa5e4d3 | 2023-03-12 11:59:49 -0500 | [diff] [blame] | 55 | const bool l_result = |
| Rekha Aparna | 5204188 | 2025-09-01 20:48:07 -0500 | [diff] [blame] | 56 | 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 Aparna | c6159a2 | 2025-10-09 12:20:20 +0530 | [diff] [blame] | 62 | "], error : " + commonUtility::getErrCodeMsg(l_errCode)); |
| Rekha Aparna | 5204188 | 2025-09-01 20:48:07 -0500 | [diff] [blame] | 63 | } |
| 64 | |
| Sunny Srivastava | fa5e4d3 | 2023-03-12 11:59:49 -0500 | [diff] [blame] | 65 | EXPECT_FALSE(l_result); |
| 66 | } |