Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 1 | #include "libpldmresponder/bios.hpp" |
Sampa Misra | b37be31 | 2019-07-03 02:26:41 -0500 | [diff] [blame] | 2 | #include "libpldmresponder/bios_table.hpp" |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 3 | |
| 4 | #include <string.h> |
| 5 | |
| 6 | #include <array> |
John Wang | 0270040 | 2019-10-06 16:34:29 +0800 | [diff] [blame] | 7 | #include <cstring> |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 8 | #include <ctime> |
Sampa Misra | b37be31 | 2019-07-03 02:26:41 -0500 | [diff] [blame] | 9 | #include <filesystem> |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 10 | |
| 11 | #include "libpldm/base.h" |
| 12 | #include "libpldm/bios.h" |
| 13 | |
| 14 | #include <gtest/gtest.h> |
| 15 | |
Sampa Misra | b37be31 | 2019-07-03 02:26:41 -0500 | [diff] [blame] | 16 | using namespace pldm; |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 17 | using namespace pldm::responder; |
Sampa Misra | b37be31 | 2019-07-03 02:26:41 -0500 | [diff] [blame] | 18 | using namespace pldm::responder::bios; |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 19 | using namespace pldm::responder::utils; |
| 20 | |
| 21 | TEST(epochToBCDTime, testTime) |
| 22 | { |
| 23 | struct tm time |
| 24 | { |
| 25 | }; |
| 26 | time.tm_year = 119; |
| 27 | time.tm_mon = 3; |
| 28 | time.tm_mday = 13; |
| 29 | time.tm_hour = 5; |
| 30 | time.tm_min = 18; |
| 31 | time.tm_sec = 13; |
| 32 | time.tm_isdst = -1; |
| 33 | |
| 34 | time_t epochTime = mktime(&time); |
| 35 | uint8_t seconds = 0; |
| 36 | uint8_t minutes = 0; |
| 37 | uint8_t hours = 0; |
| 38 | uint8_t day = 0; |
| 39 | uint8_t month = 0; |
| 40 | uint16_t year = 0; |
| 41 | |
| 42 | epochToBCDTime(epochTime, seconds, minutes, hours, day, month, year); |
| 43 | |
| 44 | ASSERT_EQ(0x13, seconds); |
| 45 | ASSERT_EQ(0x18, minutes); |
| 46 | ASSERT_EQ(0x5, hours); |
| 47 | ASSERT_EQ(0x13, day); |
| 48 | ASSERT_EQ(0x4, month); |
| 49 | ASSERT_EQ(0x2019, year); |
| 50 | } |
Tom Joseph | 52552ef | 2019-06-20 09:50:15 +0530 | [diff] [blame] | 51 | |
Xiaochao Ma | 60227a0 | 2019-12-04 09:00:12 +0800 | [diff] [blame] | 52 | TEST(timeToEpoch, testTime0) |
| 53 | { |
| 54 | std::time_t ret = 1555132693; |
| 55 | |
| 56 | uint8_t sec = 13; |
| 57 | uint8_t min = 18; |
| 58 | uint8_t hours = 5; |
| 59 | uint8_t day = 13; |
| 60 | uint8_t month = 4; |
| 61 | uint16_t year = 2019; |
| 62 | |
| 63 | std::time_t timeSec = 0; |
| 64 | timeSec = timeToEpoch(sec, min, hours, day, month, year); |
| 65 | |
| 66 | EXPECT_EQ(ret, timeSec); |
John Wang | 6080aae | 2020-02-14 09:34:25 +0800 | [diff] [blame] | 67 | } |