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 + |
| 24 | "], error : " + vpdSpecificUtility::getErrCodeMsg(l_errCode)); |
| 25 | } |
| 26 | |
Rekha Aparna | 5204188 | 2025-09-01 20:48:07 -0500 | [diff] [blame] | 27 | l_errCode = 0; |
Sunny Srivastava | fa5e4d3 | 2023-03-12 11:59:49 -0500 | [diff] [blame] | 28 | const bool l_result = |
Rekha Aparna | 5204188 | 2025-09-01 20:48:07 -0500 | [diff] [blame] | 29 | 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 Srivastava | fa5e4d3 | 2023-03-12 11:59:49 -0500 | [diff] [blame] | 38 | EXPECT_TRUE(l_result); |
| 39 | } |
| 40 | |
| 41 | TEST(IsFruPowerOffOnlyTest, NegativeTestCase) |
| 42 | { |
Rekha Aparna | ca9a086 | 2025-08-29 04:08:33 -0500 | [diff] [blame] | 43 | uint16_t l_errCode = 0; |
Sunny Srivastava | fa5e4d3 | 2023-03-12 11:59:49 -0500 | [diff] [blame] | 44 | 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 Aparna | ca9a086 | 2025-08-29 04:08:33 -0500 | [diff] [blame] | 46 | 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 Aparna | 5204188 | 2025-09-01 20:48:07 -0500 | [diff] [blame] | 56 | l_errCode = 0; |
Sunny Srivastava | fa5e4d3 | 2023-03-12 11:59:49 -0500 | [diff] [blame] | 57 | const bool l_result = |
Rekha Aparna | 5204188 | 2025-09-01 20:48:07 -0500 | [diff] [blame] | 58 | 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 Srivastava | fa5e4d3 | 2023-03-12 11:59:49 -0500 | [diff] [blame] | 67 | EXPECT_FALSE(l_result); |
| 68 | } |