1 #include "libpldm/base.h"
2 #include "libpldm/bios.h"
3 
4 #include "libpldmresponder/bios.hpp"
5 #include "libpldmresponder/bios_table.hpp"
6 
7 #include <string.h>
8 
9 #include <array>
10 #include <cstring>
11 #include <ctime>
12 #include <filesystem>
13 
14 #include <gtest/gtest.h>
15 
16 using namespace pldm;
17 using namespace pldm::responder;
18 using namespace pldm::responder::bios;
19 using namespace pldm::responder::utils;
20 
21 TEST(epochToBCDTime, testTime)
22 {
23     struct tm time
24     {};
25     time.tm_year = 119;
26     time.tm_mon = 3;
27     time.tm_mday = 13;
28     time.tm_hour = 5;
29     time.tm_min = 18;
30     time.tm_sec = 13;
31     time.tm_isdst = -1;
32 
33     time_t epochTime = mktime(&time);
34     uint8_t seconds = 0;
35     uint8_t minutes = 0;
36     uint8_t hours = 0;
37     uint8_t day = 0;
38     uint8_t month = 0;
39     uint16_t year = 0;
40 
41     epochToBCDTime(epochTime, seconds, minutes, hours, day, month, year);
42 
43     ASSERT_EQ(0x13, seconds);
44     ASSERT_EQ(0x18, minutes);
45     ASSERT_EQ(0x5, hours);
46     ASSERT_EQ(0x13, day);
47     ASSERT_EQ(0x4, month);
48     ASSERT_EQ(0x2019, year);
49 }
50 
51 TEST(timeToEpoch, testTime0)
52 {
53     std::time_t ret = 1555132693;
54 
55     uint8_t sec = 13;
56     uint8_t min = 18;
57     uint8_t hours = 5;
58     uint8_t day = 13;
59     uint8_t month = 4;
60     uint16_t year = 2019;
61 
62     std::time_t timeSec = 0;
63     timeSec = timeToEpoch(sec, min, hours, day, month, year);
64 
65     EXPECT_EQ(ret, timeSec);
66 }