blob: c229caafa4eaa66a04831662cd0c735895e26ea6 [file] [log] [blame]
Sampa Misra032bd502019-03-06 05:03:22 -06001#include "libpldmresponder/bios.hpp"
Sampa Misrab37be312019-07-03 02:26:41 -05002#include "libpldmresponder/bios_table.hpp"
Sampa Misra032bd502019-03-06 05:03:22 -06003
George Liuc453e162022-12-21 17:16:23 +08004#include <libpldm/base.h>
5#include <libpldm/bios.h>
Sampa Misra032bd502019-03-06 05:03:22 -06006
7#include <array>
John Wang02700402019-10-06 16:34:29 +08008#include <cstring>
Sampa Misra032bd502019-03-06 05:03:22 -06009#include <ctime>
Sampa Misrab37be312019-07-03 02:26:41 -050010#include <filesystem>
Sampa Misra032bd502019-03-06 05:03:22 -060011
Sampa Misra032bd502019-03-06 05:03:22 -060012#include <gtest/gtest.h>
13
Sampa Misrab37be312019-07-03 02:26:41 -050014using namespace pldm;
Sampa Misra032bd502019-03-06 05:03:22 -060015using namespace pldm::responder;
Sampa Misrab37be312019-07-03 02:26:41 -050016using namespace pldm::responder::bios;
Sampa Misra032bd502019-03-06 05:03:22 -060017using namespace pldm::responder::utils;
18
19TEST(epochToBCDTime, testTime)
20{
21 struct tm time
George Liu6492f522020-06-16 10:34:05 +080022 {};
Sampa Misra032bd502019-03-06 05:03:22 -060023 time.tm_year = 119;
24 time.tm_mon = 3;
25 time.tm_mday = 13;
26 time.tm_hour = 5;
27 time.tm_min = 18;
28 time.tm_sec = 13;
29 time.tm_isdst = -1;
30
31 time_t epochTime = mktime(&time);
32 uint8_t seconds = 0;
33 uint8_t minutes = 0;
34 uint8_t hours = 0;
35 uint8_t day = 0;
36 uint8_t month = 0;
37 uint16_t year = 0;
38
39 epochToBCDTime(epochTime, seconds, minutes, hours, day, month, year);
40
41 ASSERT_EQ(0x13, seconds);
42 ASSERT_EQ(0x18, minutes);
43 ASSERT_EQ(0x5, hours);
44 ASSERT_EQ(0x13, day);
45 ASSERT_EQ(0x4, month);
46 ASSERT_EQ(0x2019, year);
47}
Tom Joseph52552ef2019-06-20 09:50:15 +053048
Xiaochao Ma60227a02019-12-04 09:00:12 +080049TEST(timeToEpoch, testTime0)
50{
51 std::time_t ret = 1555132693;
52
53 uint8_t sec = 13;
54 uint8_t min = 18;
55 uint8_t hours = 5;
56 uint8_t day = 13;
57 uint8_t month = 4;
58 uint16_t year = 2019;
59
60 std::time_t timeSec = 0;
61 timeSec = timeToEpoch(sec, min, hours, day, month, year);
62
63 EXPECT_EQ(ret, timeSec);
Patrick Williams6da4f912023-05-10 07:50:53 -050064}