diff options
Diffstat (limited to 'libc/test/src/time')
| -rw-r--r-- | libc/test/src/time/CMakeLists.txt | 25 | ||||
| -rw-r--r-- | libc/test/src/time/TmHelper.h | 9 | ||||
| -rw-r--r-- | libc/test/src/time/TmMatcher.h | 3 | ||||
| -rw-r--r-- | libc/test/src/time/asctime_r_test.cpp | 8 | ||||
| -rw-r--r-- | libc/test/src/time/clock_gettime_test.cpp | 5 | ||||
| -rw-r--r-- | libc/test/src/time/clock_test.cpp | 3 | ||||
| -rw-r--r-- | libc/test/src/time/ctime_r_test.cpp | 12 | ||||
| -rw-r--r-- | libc/test/src/time/difftime_test.cpp | 7 | ||||
| -rw-r--r-- | libc/test/src/time/gettimeofday_test.cpp | 3 | ||||
| -rw-r--r-- | libc/test/src/time/gmtime_r_test.cpp | 46 | ||||
| -rw-r--r-- | libc/test/src/time/gmtime_test.cpp | 383 | ||||
| -rw-r--r-- | libc/test/src/time/mktime_test.cpp | 438 | ||||
| -rw-r--r-- | libc/test/src/time/nanosleep_test.cpp | 3 |
13 files changed, 546 insertions, 399 deletions
diff --git a/libc/test/src/time/CMakeLists.txt b/libc/test/src/time/CMakeLists.txt index da3903f3e0e4..12add224f386 100644 --- a/libc/test/src/time/CMakeLists.txt +++ b/libc/test/src/time/CMakeLists.txt @@ -13,6 +13,8 @@ add_libc_unittest( 20 DEPENDS libc.src.time.asctime + libc.hdr.types.struct_tm + libc.src.time.time_constants ) add_libc_unittest( @@ -28,6 +30,8 @@ add_libc_unittest( 20 DEPENDS libc.src.time.asctime_r + libc.hdr.types.struct_tm + libc.src.time.time_constants ) add_libc_unittest( @@ -45,7 +49,8 @@ add_libc_unittest( libc.include.time libc.hdr.types.time_t libc.src.time.ctime - libc.src.time.time_utils + libc.src.time.time_constants + libc.hdr.types.struct_tm ) add_libc_unittest( @@ -63,7 +68,8 @@ add_libc_unittest( libc.include.time libc.hdr.types.time_t libc.src.time.ctime_r - libc.src.time.time_utils + libc.src.time.time_constants + libc.hdr.types.struct_tm ) add_libc_test( @@ -74,6 +80,9 @@ add_libc_test( clock_gettime_test.cpp DEPENDS libc.src.time.clock_gettime + libc.hdr.types.time_t + libc.hdr.types.struct_timespec + libc.hdr.time_macros ) add_libc_test( @@ -94,6 +103,8 @@ add_libc_unittest( difftime_test.cpp DEPENDS libc.src.time.difftime + libc.src.time.time_constants + libc.src.__support.FPUtil.fp_bits ) add_libc_unittest( @@ -105,6 +116,7 @@ add_libc_unittest( DEPENDS libc.include.time libc.src.time.gettimeofday + libc.hdr.types.struct_timeval ) add_libc_unittest( @@ -118,6 +130,8 @@ add_libc_unittest( DEPENDS libc.src.time.gmtime libc.src.__support.CPP.limits + libc.hdr.types.struct_tm + libc.src.time.time_constants ) add_libc_unittest( @@ -130,6 +144,8 @@ add_libc_unittest( TmMatcher.h DEPENDS libc.src.time.gmtime_r + libc.hdr.types.struct_tm + libc.src.time.time_constants ) add_libc_unittest( @@ -146,6 +162,8 @@ add_libc_unittest( DEPENDS libc.src.time.mktime libc.src.__support.CPP.limits + libc.hdr.types.struct_tm + libc.src.time.time_constants ) add_libc_test( @@ -158,6 +176,7 @@ add_libc_test( libc.include.time libc.src.time.nanosleep libc.src.errno.errno + libc.hdr.types.struct_timespec ) add_libc_unittest( @@ -180,6 +199,7 @@ add_libc_test( timespec_get_test.cpp DEPENDS libc.src.time.timespec_get + libc.hdr.types.struct_timespec ) add_libc_test( @@ -192,4 +212,5 @@ add_libc_test( libc.include.time libc.src.time.clock libc.src.errno.errno + libc.hdr.types.clock_t ) diff --git a/libc/test/src/time/TmHelper.h b/libc/test/src/time/TmHelper.h index 5ae258461099..1582839ffaf2 100644 --- a/libc/test/src/time/TmHelper.h +++ b/libc/test/src/time/TmHelper.h @@ -9,12 +9,9 @@ #ifndef LLVM_LIBC_TEST_SRC_TIME_TMHELPER_H #define LLVM_LIBC_TEST_SRC_TIME_TMHELPER_H -#include <time.h> - +#include "hdr/types/struct_tm.h" #include "src/__support/macros/config.h" -#include "src/time/time_utils.h" - -using LIBC_NAMESPACE::time_utils::TimeConstants; +#include "src/time/time_constants.h" namespace LIBC_NAMESPACE_DECL { namespace tmhelper { @@ -30,7 +27,7 @@ static inline void initialize_tm_data(struct tm *tm_data, int year, int month, .tm_mday = mday, .tm_mon = month - 1, // tm_mon starts with 0 for Jan // years since 1900 - .tm_year = year - TimeConstants::TIME_YEAR_BASE, + .tm_year = year - time_constants::TIME_YEAR_BASE, .tm_wday = wday, .tm_yday = yday, .tm_isdst = 0}; diff --git a/libc/test/src/time/TmMatcher.h b/libc/test/src/time/TmMatcher.h index 630956b0f08d..d39ee396057b 100644 --- a/libc/test/src/time/TmMatcher.h +++ b/libc/test/src/time/TmMatcher.h @@ -9,8 +9,7 @@ #ifndef LLVM_LIBC_TEST_SRC_TIME_TM_MATCHER_H #define LLVM_LIBC_TEST_SRC_TIME_TM_MATCHER_H -#include <time.h> - +#include "hdr/types/struct_tm.h" #include "src/__support/macros/config.h" #include "test/UnitTest/Test.h" diff --git a/libc/test/src/time/asctime_r_test.cpp b/libc/test/src/time/asctime_r_test.cpp index f3aadbb39de4..b595cfe02486 100644 --- a/libc/test/src/time/asctime_r_test.cpp +++ b/libc/test/src/time/asctime_r_test.cpp @@ -8,12 +8,10 @@ #include "src/errno/libc_errno.h" #include "src/time/asctime_r.h" -#include "src/time/time_utils.h" +#include "src/time/time_constants.h" #include "test/UnitTest/Test.h" #include "test/src/time/TmHelper.h" -using LIBC_NAMESPACE::time_utils::TimeConstants; - static inline char *call_asctime_r(struct tm *tm_data, int year, int month, int mday, int hour, int min, int sec, int wday, int yday, char *buffer) { @@ -30,7 +28,7 @@ TEST(LlvmLibcAsctimeR, Nullptr) { ASSERT_ERRNO_EQ(EINVAL); ASSERT_STREQ(nullptr, result); - char buffer[TimeConstants::ASCTIME_BUFFER_SIZE]; + char buffer[LIBC_NAMESPACE::time_constants::ASCTIME_BUFFER_SIZE]; result = LIBC_NAMESPACE::asctime_r(nullptr, buffer); ASSERT_ERRNO_EQ(EINVAL); ASSERT_STREQ(nullptr, result); @@ -42,7 +40,7 @@ TEST(LlvmLibcAsctimeR, Nullptr) { } TEST(LlvmLibcAsctimeR, ValidDate) { - char buffer[TimeConstants::ASCTIME_BUFFER_SIZE]; + char buffer[LIBC_NAMESPACE::time_constants::ASCTIME_BUFFER_SIZE]; struct tm tm_data; char *result; // 1970-01-01 00:00:00. Test with a valid buffer size. diff --git a/libc/test/src/time/clock_gettime_test.cpp b/libc/test/src/time/clock_gettime_test.cpp index 43715c0265f1..d3edcae00cdd 100644 --- a/libc/test/src/time/clock_gettime_test.cpp +++ b/libc/test/src/time/clock_gettime_test.cpp @@ -6,12 +6,13 @@ // //===----------------------------------------------------------------------===// +#include "hdr/time_macros.h" +#include "hdr/types/struct_timespec.h" +#include "hdr/types/time_t.h" #include "src/__support/macros/properties/architectures.h" #include "src/time/clock_gettime.h" #include "test/UnitTest/Test.h" -#include <time.h> - TEST(LlvmLibcClockGetTime, RealTime) { timespec tp; int result; diff --git a/libc/test/src/time/clock_test.cpp b/libc/test/src/time/clock_test.cpp index 05082aa23388..8d8d89d577a9 100644 --- a/libc/test/src/time/clock_test.cpp +++ b/libc/test/src/time/clock_test.cpp @@ -6,11 +6,10 @@ // //===----------------------------------------------------------------------===// +#include "hdr/types/clock_t.h" #include "src/time/clock.h" #include "test/UnitTest/Test.h" -#include <time.h> - TEST(LlvmLibcClockTest, SmokeTest) { clock_t c1 = LIBC_NAMESPACE::clock(); ASSERT_GT(c1, clock_t(0)); diff --git a/libc/test/src/time/ctime_r_test.cpp b/libc/test/src/time/ctime_r_test.cpp index 9ce6f75f7548..27011b7e0fbd 100644 --- a/libc/test/src/time/ctime_r_test.cpp +++ b/libc/test/src/time/ctime_r_test.cpp @@ -8,18 +8,16 @@ #include "src/errno/libc_errno.h" #include "src/time/ctime_r.h" -#include "src/time/time_utils.h" +#include "src/time/time_constants.h" #include "test/UnitTest/Test.h" #include "test/src/time/TmHelper.h" -using LIBC_NAMESPACE::time_utils::TimeConstants; - TEST(LlvmLibcCtimeR, Nullptr) { char *result; result = LIBC_NAMESPACE::ctime_r(nullptr, nullptr); ASSERT_STREQ(nullptr, result); - char buffer[TimeConstants::ASCTIME_BUFFER_SIZE]; + char buffer[LIBC_NAMESPACE::time_constants::ASCTIME_BUFFER_SIZE]; result = LIBC_NAMESPACE::ctime_r(nullptr, buffer); ASSERT_STREQ(nullptr, result); @@ -29,7 +27,7 @@ TEST(LlvmLibcCtimeR, Nullptr) { } TEST(LlvmLibcCtimeR, ValidUnixTimestamp0) { - char buffer[TimeConstants::ASCTIME_BUFFER_SIZE]; + char buffer[LIBC_NAMESPACE::time_constants::ASCTIME_BUFFER_SIZE]; time_t t; char *result; // 1970-01-01 00:00:00. Test with a valid buffer size. @@ -39,7 +37,7 @@ TEST(LlvmLibcCtimeR, ValidUnixTimestamp0) { } TEST(LlvmLibcCtime, ValidUnixTimestamp32Int) { - char buffer[TimeConstants::ASCTIME_BUFFER_SIZE]; + char buffer[LIBC_NAMESPACE::time_constants::ASCTIME_BUFFER_SIZE]; time_t t; char *result; // 2038-01-19 03:14:07. Test with a valid buffer size. @@ -49,7 +47,7 @@ TEST(LlvmLibcCtime, ValidUnixTimestamp32Int) { } TEST(LlvmLibcCtimeR, InvalidArgument) { - char buffer[TimeConstants::ASCTIME_BUFFER_SIZE]; + char buffer[LIBC_NAMESPACE::time_constants::ASCTIME_BUFFER_SIZE]; time_t t; char *result; t = 2147483648; diff --git a/libc/test/src/time/difftime_test.cpp b/libc/test/src/time/difftime_test.cpp index 68ff4630e61b..4dab1ac91104 100644 --- a/libc/test/src/time/difftime_test.cpp +++ b/libc/test/src/time/difftime_test.cpp @@ -8,15 +8,12 @@ #include "src/__support/FPUtil/FPBits.h" #include "src/time/difftime.h" -#include "src/time/time_utils.h" +#include "src/time/time_constants.h" #include "test/UnitTest/ErrnoSetterMatcher.h" #include "test/UnitTest/Test.h" -using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds; -using LIBC_NAMESPACE::time_utils::TimeConstants; - TEST(LlvmLibcDifftime, SmokeTest) { - time_t t1_seconds = TimeConstants::SECONDS_PER_HOUR; + time_t t1_seconds = LIBC_NAMESPACE::time_constants::SECONDS_PER_HOUR; time_t t2_seconds = 0; LIBC_NAMESPACE::fputil::FPBits<long double> expected_fp = diff --git a/libc/test/src/time/gettimeofday_test.cpp b/libc/test/src/time/gettimeofday_test.cpp index ee934b7f3a20..8f9f136164f5 100644 --- a/libc/test/src/time/gettimeofday_test.cpp +++ b/libc/test/src/time/gettimeofday_test.cpp @@ -6,8 +6,7 @@ // //===----------------------------------------------------------------------===// -#include <time.h> - +#include "hdr/types/struct_timeval.h" #include "src/time/gettimeofday.h" #include "test/UnitTest/Test.h" diff --git a/libc/test/src/time/gmtime_r_test.cpp b/libc/test/src/time/gmtime_r_test.cpp index 2276b4803f19..9d466f444f97 100644 --- a/libc/test/src/time/gmtime_r_test.cpp +++ b/libc/test/src/time/gmtime_r_test.cpp @@ -7,12 +7,10 @@ //===----------------------------------------------------------------------===// #include "src/time/gmtime_r.h" -#include "src/time/time_utils.h" +#include "src/time/time_constants.h" #include "test/UnitTest/Test.h" #include "test/src/time/TmMatcher.h" -using LIBC_NAMESPACE::time_utils::TimeConstants; - // gmtime and gmtime_r share the same code and thus didn't repeat all the tests // from gmtime. Added couple of validation tests. TEST(LlvmLibcGmTimeR, EndOf32BitEpochYear) { @@ -22,16 +20,17 @@ TEST(LlvmLibcGmTimeR, EndOf32BitEpochYear) { struct tm tm_data; struct tm *tm_data_ptr; tm_data_ptr = LIBC_NAMESPACE::gmtime_r(&seconds, &tm_data); - EXPECT_TM_EQ((tm{7, // sec - 14, // min - 3, // hr - 19, // day - 0, // tm_mon starts with 0 for Jan - 2038 - TimeConstants::TIME_YEAR_BASE, // year - 2, // wday - 7, // yday - 0}), - *tm_data_ptr); + EXPECT_TM_EQ( + (tm{7, // sec + 14, // min + 3, // hr + 19, // day + 0, // tm_mon starts with 0 for Jan + 2038 - LIBC_NAMESPACE::time_constants::TIME_YEAR_BASE, // year + 2, // wday + 7, // yday + 0}), + *tm_data_ptr); EXPECT_TM_EQ(*tm_data_ptr, tm_data); } @@ -43,15 +42,16 @@ TEST(LlvmLibcGmTimeR, Max64BitYear) { struct tm tm_data; struct tm *tm_data_ptr; tm_data_ptr = LIBC_NAMESPACE::gmtime_r(&seconds, &tm_data); - EXPECT_TM_EQ((tm{50, // sec - 50, // min - 12, // hr - 1, // day - 0, // tm_mon starts with 0 for Jan - 2147483647 - TimeConstants::TIME_YEAR_BASE, // year - 2, // wday - 50, // yday - 0}), - *tm_data_ptr); + EXPECT_TM_EQ( + (tm{50, // sec + 50, // min + 12, // hr + 1, // day + 0, // tm_mon starts with 0 for Jan + 2147483647 - LIBC_NAMESPACE::time_constants::TIME_YEAR_BASE, // year + 2, // wday + 50, // yday + 0}), + *tm_data_ptr); EXPECT_TM_EQ(*tm_data_ptr, tm_data); } diff --git a/libc/test/src/time/gmtime_test.cpp b/libc/test/src/time/gmtime_test.cpp index 433fbf666705..6af5a18d3699 100644 --- a/libc/test/src/time/gmtime_test.cpp +++ b/libc/test/src/time/gmtime_test.cpp @@ -6,32 +6,36 @@ // //===----------------------------------------------------------------------===// +#include "hdr/types/struct_tm.h" #include "src/__support/CPP/limits.h" // INT_MAX, INT_MIN #include "src/errno/libc_errno.h" #include "src/time/gmtime.h" -#include "src/time/time_utils.h" +#include "src/time/time_constants.h" #include "test/UnitTest/ErrnoSetterMatcher.h" #include "test/UnitTest/Test.h" #include "test/src/time/TmMatcher.h" using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails; using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds; -using LIBC_NAMESPACE::time_utils::TimeConstants; TEST(LlvmLibcGmTime, OutOfRange) { if (sizeof(time_t) < sizeof(int64_t)) return; time_t seconds = - 1 + INT_MAX * static_cast<int64_t>( - TimeConstants::NUMBER_OF_SECONDS_IN_LEAP_YEAR); + 1 + + INT_MAX * + static_cast<int64_t>( + LIBC_NAMESPACE::time_constants::NUMBER_OF_SECONDS_IN_LEAP_YEAR); struct tm *tm_data = LIBC_NAMESPACE::gmtime(&seconds); EXPECT_TRUE(tm_data == nullptr); ASSERT_ERRNO_EQ(EOVERFLOW); LIBC_NAMESPACE::libc_errno = 0; - seconds = INT_MIN * static_cast<int64_t>( - TimeConstants::NUMBER_OF_SECONDS_IN_LEAP_YEAR) - - 1; + seconds = + INT_MIN * + static_cast<int64_t>( + LIBC_NAMESPACE::time_constants::NUMBER_OF_SECONDS_IN_LEAP_YEAR) - + 1; tm_data = LIBC_NAMESPACE::gmtime(&seconds); EXPECT_TRUE(tm_data == nullptr); ASSERT_ERRNO_EQ(EOVERFLOW); @@ -43,201 +47,215 @@ TEST(LlvmLibcGmTime, InvalidSeconds) { // -1 second from 1970-01-01 00:00:00 returns 1969-12-31 23:59:59. seconds = -1; tm_data = LIBC_NAMESPACE::gmtime(&seconds); - EXPECT_TM_EQ((tm{59, // sec - 59, // min - 23, // hr - 31, // day - 12 - 1, // tm_mon starts with 0 for Jan - 1969 - TimeConstants::TIME_YEAR_BASE, // year - 3, // wday - 364, // yday - 0}), - *tm_data); + EXPECT_TM_EQ( + (tm{59, // sec + 59, // min + 23, // hr + 31, // day + 12 - 1, // tm_mon starts with 0 for Jan + 1969 - LIBC_NAMESPACE::time_constants::TIME_YEAR_BASE, // year + 3, // wday + 364, // yday + 0}), + *tm_data); // 60 seconds from 1970-01-01 00:00:00 returns 1970-01-01 00:01:00. seconds = 60; tm_data = LIBC_NAMESPACE::gmtime(&seconds); - EXPECT_TM_EQ((tm{0, // sec - 1, // min - 0, // hr - 1, // day - 0, // tm_mon starts with 0 for Jan - 1970 - TimeConstants::TIME_YEAR_BASE, // year - 4, // wday - 0, // yday - 0}), - *tm_data); + EXPECT_TM_EQ( + (tm{0, // sec + 1, // min + 0, // hr + 1, // day + 0, // tm_mon starts with 0 for Jan + 1970 - LIBC_NAMESPACE::time_constants::TIME_YEAR_BASE, // year + 4, // wday + 0, // yday + 0}), + *tm_data); } TEST(LlvmLibcGmTime, InvalidMinutes) { time_t seconds = 0; struct tm *tm_data = nullptr; // -1 minute from 1970-01-01 00:00:00 returns 1969-12-31 23:59:00. - seconds = -TimeConstants::SECONDS_PER_MIN; + seconds = -LIBC_NAMESPACE::time_constants::SECONDS_PER_MIN; tm_data = LIBC_NAMESPACE::gmtime(&seconds); - EXPECT_TM_EQ((tm{0, // sec - 59, // min - 23, // hr - 31, // day - 11, // tm_mon starts with 0 for Jan - 1969 - TimeConstants::TIME_YEAR_BASE, // year - 3, // wday - 0, // yday - 0}), - *tm_data); + EXPECT_TM_EQ( + (tm{0, // sec + 59, // min + 23, // hr + 31, // day + 11, // tm_mon starts with 0 for Jan + 1969 - LIBC_NAMESPACE::time_constants::TIME_YEAR_BASE, // year + 3, // wday + 0, // yday + 0}), + *tm_data); // 60 minutes from 1970-01-01 00:00:00 returns 1970-01-01 01:00:00. - seconds = 60 * TimeConstants::SECONDS_PER_MIN; + seconds = 60 * LIBC_NAMESPACE::time_constants::SECONDS_PER_MIN; tm_data = LIBC_NAMESPACE::gmtime(&seconds); - EXPECT_TM_EQ((tm{0, // sec - 0, // min - 1, // hr - 1, // day - 0, // tm_mon starts with 0 for Jan - 1970 - TimeConstants::TIME_YEAR_BASE, // year - 4, // wday - 0, // yday - 0}), - *tm_data); + EXPECT_TM_EQ( + (tm{0, // sec + 0, // min + 1, // hr + 1, // day + 0, // tm_mon starts with 0 for Jan + 1970 - LIBC_NAMESPACE::time_constants::TIME_YEAR_BASE, // year + 4, // wday + 0, // yday + 0}), + *tm_data); } TEST(LlvmLibcGmTime, InvalidHours) { time_t seconds = 0; struct tm *tm_data = nullptr; // -1 hour from 1970-01-01 00:00:00 returns 1969-12-31 23:00:00. - seconds = -TimeConstants::SECONDS_PER_HOUR; + seconds = -LIBC_NAMESPACE::time_constants::SECONDS_PER_HOUR; tm_data = LIBC_NAMESPACE::gmtime(&seconds); - EXPECT_TM_EQ((tm{0, // sec - 0, // min - 23, // hr - 31, // day - 11, // tm_mon starts with 0 for Jan - 1969 - TimeConstants::TIME_YEAR_BASE, // year - 3, // wday - 0, // yday - 0}), - *tm_data); + EXPECT_TM_EQ( + (tm{0, // sec + 0, // min + 23, // hr + 31, // day + 11, // tm_mon starts with 0 for Jan + 1969 - LIBC_NAMESPACE::time_constants::TIME_YEAR_BASE, // year + 3, // wday + 0, // yday + 0}), + *tm_data); // 24 hours from 1970-01-01 00:00:00 returns 1970-01-02 00:00:00. - seconds = 24 * TimeConstants::SECONDS_PER_HOUR; + seconds = 24 * LIBC_NAMESPACE::time_constants::SECONDS_PER_HOUR; tm_data = LIBC_NAMESPACE::gmtime(&seconds); - EXPECT_TM_EQ((tm{0, // sec - 0, // min - 0, // hr - 2, // day - 0, // tm_mon starts with 0 for Jan - 1970 - TimeConstants::TIME_YEAR_BASE, // year - 5, // wday - 0, // yday - 0}), - *tm_data); + EXPECT_TM_EQ( + (tm{0, // sec + 0, // min + 0, // hr + 2, // day + 0, // tm_mon starts with 0 for Jan + 1970 - LIBC_NAMESPACE::time_constants::TIME_YEAR_BASE, // year + 5, // wday + 0, // yday + 0}), + *tm_data); } TEST(LlvmLibcGmTime, InvalidYear) { // -1 year from 1970-01-01 00:00:00 returns 1969-01-01 00:00:00. - time_t seconds = - -TimeConstants::DAYS_PER_NON_LEAP_YEAR * TimeConstants::SECONDS_PER_DAY; + time_t seconds = -LIBC_NAMESPACE::time_constants::DAYS_PER_NON_LEAP_YEAR * + LIBC_NAMESPACE::time_constants::SECONDS_PER_DAY; struct tm *tm_data = LIBC_NAMESPACE::gmtime(&seconds); - EXPECT_TM_EQ((tm{0, // sec - 0, // min - 0, // hr - 1, // day - 0, // tm_mon starts with 0 for Jan - 1969 - TimeConstants::TIME_YEAR_BASE, // year - 3, // wday - 0, // yday - 0}), - *tm_data); + EXPECT_TM_EQ( + (tm{0, // sec + 0, // min + 0, // hr + 1, // day + 0, // tm_mon starts with 0 for Jan + 1969 - LIBC_NAMESPACE::time_constants::TIME_YEAR_BASE, // year + 3, // wday + 0, // yday + 0}), + *tm_data); } TEST(LlvmLibcGmTime, InvalidMonths) { time_t seconds = 0; struct tm *tm_data = nullptr; // -1 month from 1970-01-01 00:00:00 returns 1969-12-01 00:00:00. - seconds = -31 * TimeConstants::SECONDS_PER_DAY; + seconds = -31 * LIBC_NAMESPACE::time_constants::SECONDS_PER_DAY; tm_data = LIBC_NAMESPACE::gmtime(&seconds); - EXPECT_TM_EQ((tm{0, // sec - 0, // min - 0, // hr - 1, // day - 12 - 1, // tm_mon starts with 0 for Jan - 1969 - TimeConstants::TIME_YEAR_BASE, // year - 1, // wday - 0, // yday - 0}), - *tm_data); + EXPECT_TM_EQ( + (tm{0, // sec + 0, // min + 0, // hr + 1, // day + 12 - 1, // tm_mon starts with 0 for Jan + 1969 - LIBC_NAMESPACE::time_constants::TIME_YEAR_BASE, // year + 1, // wday + 0, // yday + 0}), + *tm_data); // 1970-13-01 00:00:00 returns 1971-01-01 00:00:00. - seconds = - TimeConstants::DAYS_PER_NON_LEAP_YEAR * TimeConstants::SECONDS_PER_DAY; + seconds = LIBC_NAMESPACE::time_constants::DAYS_PER_NON_LEAP_YEAR * + LIBC_NAMESPACE::time_constants::SECONDS_PER_DAY; tm_data = LIBC_NAMESPACE::gmtime(&seconds); - EXPECT_TM_EQ((tm{0, // sec - 0, // min - 0, // hr - 1, // day - 0, // tm_mon starts with 0 for Jan - 1971 - TimeConstants::TIME_YEAR_BASE, // year - 5, // wday - 0, // yday - 0}), - *tm_data); + EXPECT_TM_EQ( + (tm{0, // sec + 0, // min + 0, // hr + 1, // day + 0, // tm_mon starts with 0 for Jan + 1971 - LIBC_NAMESPACE::time_constants::TIME_YEAR_BASE, // year + 5, // wday + 0, // yday + 0}), + *tm_data); } TEST(LlvmLibcGmTime, InvalidDays) { time_t seconds = 0; struct tm *tm_data = nullptr; // -1 day from 1970-01-01 00:00:00 returns 1969-12-31 00:00:00. - seconds = -1 * TimeConstants::SECONDS_PER_DAY; + seconds = -1 * LIBC_NAMESPACE::time_constants::SECONDS_PER_DAY; tm_data = LIBC_NAMESPACE::gmtime(&seconds); - EXPECT_TM_EQ((tm{0, // sec - 0, // min - 0, // hr - 31, // day - 11, // tm_mon starts with 0 for Jan - 1969 - TimeConstants::TIME_YEAR_BASE, // year - 3, // wday - 0, // yday - 0}), - *tm_data); + EXPECT_TM_EQ( + (tm{0, // sec + 0, // min + 0, // hr + 31, // day + 11, // tm_mon starts with 0 for Jan + 1969 - LIBC_NAMESPACE::time_constants::TIME_YEAR_BASE, // year + 3, // wday + 0, // yday + 0}), + *tm_data); // 1970-01-32 00:00:00 returns 1970-02-01 00:00:00. - seconds = 31 * TimeConstants::SECONDS_PER_DAY; + seconds = 31 * LIBC_NAMESPACE::time_constants::SECONDS_PER_DAY; tm_data = LIBC_NAMESPACE::gmtime(&seconds); - EXPECT_TM_EQ((tm{0, // sec - 0, // min - 0, // hr - 1, // day - 0, // tm_mon starts with 0 for Jan - 1970 - TimeConstants::TIME_YEAR_BASE, // year - 0, // wday - 0, // yday - 0}), - *tm_data); + EXPECT_TM_EQ( + (tm{0, // sec + 0, // min + 0, // hr + 1, // day + 0, // tm_mon starts with 0 for Jan + 1970 - LIBC_NAMESPACE::time_constants::TIME_YEAR_BASE, // year + 0, // wday + 0, // yday + 0}), + *tm_data); // 1970-02-29 00:00:00 returns 1970-03-01 00:00:00. - seconds = 59 * TimeConstants::SECONDS_PER_DAY; + seconds = 59 * LIBC_NAMESPACE::time_constants::SECONDS_PER_DAY; tm_data = LIBC_NAMESPACE::gmtime(&seconds); - EXPECT_TM_EQ((tm{0, // sec - 0, // min - 0, // hr - 1, // day - 2, // tm_mon starts with 0 for Jan - 1970 - TimeConstants::TIME_YEAR_BASE, // year - 0, // wday - 0, // yday - 0}), - *tm_data); + EXPECT_TM_EQ( + (tm{0, // sec + 0, // min + 0, // hr + 1, // day + 2, // tm_mon starts with 0 for Jan + 1970 - LIBC_NAMESPACE::time_constants::TIME_YEAR_BASE, // year + 0, // wday + 0, // yday + 0}), + *tm_data); // 1972-02-30 00:00:00 returns 1972-03-01 00:00:00. - seconds = ((2 * TimeConstants::DAYS_PER_NON_LEAP_YEAR) + 60) * - TimeConstants::SECONDS_PER_DAY; + seconds = + ((2 * LIBC_NAMESPACE::time_constants::DAYS_PER_NON_LEAP_YEAR) + 60) * + LIBC_NAMESPACE::time_constants::SECONDS_PER_DAY; tm_data = LIBC_NAMESPACE::gmtime(&seconds); - EXPECT_TM_EQ((tm{0, // sec - 0, // min - 0, // hr - 1, // day - 2, // tm_mon starts with 0 for Jan - 1972 - TimeConstants::TIME_YEAR_BASE, // year - 3, // wday - 0, // yday - 0}), - *tm_data); + EXPECT_TM_EQ( + (tm{0, // sec + 0, // min + 0, // hr + 1, // day + 2, // tm_mon starts with 0 for Jan + 1972 - LIBC_NAMESPACE::time_constants::TIME_YEAR_BASE, // year + 3, // wday + 0, // yday + 0}), + *tm_data); } TEST(LlvmLibcGmTime, EndOf32BitEpochYear) { @@ -245,16 +263,17 @@ TEST(LlvmLibcGmTime, EndOf32BitEpochYear) { // Test implementation can encode time for Tue 19 January 2038 03:14:07 UTC. time_t seconds = 0x7FFFFFFF; struct tm *tm_data = LIBC_NAMESPACE::gmtime(&seconds); - EXPECT_TM_EQ((tm{7, // sec - 14, // min - 3, // hr - 19, // day - 0, // tm_mon starts with 0 for Jan - 2038 - TimeConstants::TIME_YEAR_BASE, // year - 2, // wday - 7, // yday - 0}), - *tm_data); + EXPECT_TM_EQ( + (tm{7, // sec + 14, // min + 3, // hr + 19, // day + 0, // tm_mon starts with 0 for Jan + 2038 - LIBC_NAMESPACE::time_constants::TIME_YEAR_BASE, // year + 2, // wday + 7, // yday + 0}), + *tm_data); } TEST(LlvmLibcGmTime, Max64BitYear) { @@ -263,28 +282,30 @@ TEST(LlvmLibcGmTime, Max64BitYear) { // Mon Jan 1 12:50:50 2170 (200 years from 1970), time_t seconds = 6311479850; struct tm *tm_data = LIBC_NAMESPACE::gmtime(&seconds); - EXPECT_TM_EQ((tm{50, // sec - 50, // min - 12, // hr - 1, // day - 0, // tm_mon starts with 0 for Jan - 2170 - TimeConstants::TIME_YEAR_BASE, // year - 1, // wday - 50, // yday - 0}), - *tm_data); + EXPECT_TM_EQ( + (tm{50, // sec + 50, // min + 12, // hr + 1, // day + 0, // tm_mon starts with 0 for Jan + 2170 - LIBC_NAMESPACE::time_constants::TIME_YEAR_BASE, // year + 1, // wday + 50, // yday + 0}), + *tm_data); // Test for Tue Jan 1 12:50:50 in 2,147,483,647th year. seconds = 67767976202043050; tm_data = LIBC_NAMESPACE::gmtime(&seconds); - EXPECT_TM_EQ((tm{50, // sec - 50, // min - 12, // hr - 1, // day - 0, // tm_mon starts with 0 for Jan - 2147483647 - TimeConstants::TIME_YEAR_BASE, // year - 2, // wday - 50, // yday - 0}), - *tm_data); + EXPECT_TM_EQ( + (tm{50, // sec + 50, // min + 12, // hr + 1, // day + 0, // tm_mon starts with 0 for Jan + 2147483647 - LIBC_NAMESPACE::time_constants::TIME_YEAR_BASE, // year + 2, // wday + 50, // yday + 0}), + *tm_data); } diff --git a/libc/test/src/time/mktime_test.cpp b/libc/test/src/time/mktime_test.cpp index 84e6c7eb2c42..fe1116f7dd2e 100644 --- a/libc/test/src/time/mktime_test.cpp +++ b/libc/test/src/time/mktime_test.cpp @@ -8,7 +8,7 @@ #include "src/__support/CPP/limits.h" // INT_MAX #include "src/time/mktime.h" -#include "src/time/time_utils.h" +#include "src/time/time_constants.h" #include "test/UnitTest/ErrnoSetterMatcher.h" #include "test/UnitTest/Test.h" #include "test/src/time/TmHelper.h" @@ -16,29 +16,37 @@ using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails; using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds; -using LIBC_NAMESPACE::time_utils::Month; +using LIBC_NAMESPACE::time_constants::Month; static inline constexpr int tm_year(int year) { - return year - TimeConstants::TIME_YEAR_BASE; + return year - LIBC_NAMESPACE::time_constants::TIME_YEAR_BASE; } TEST(LlvmLibcMkTime, FailureSetsErrno) { - struct tm tm_data { - .tm_sec = INT_MAX, .tm_min = INT_MAX, .tm_hour = INT_MAX, - .tm_mday = INT_MAX, .tm_mon = INT_MAX - 1, .tm_year = tm_year(INT_MAX), - .tm_wday = 0, .tm_yday = 0, .tm_isdst = 0 - }; + struct tm tm_data{.tm_sec = INT_MAX, + .tm_min = INT_MAX, + .tm_hour = INT_MAX, + .tm_mday = INT_MAX, + .tm_mon = INT_MAX - 1, + .tm_year = tm_year(INT_MAX), + .tm_wday = 0, + .tm_yday = 0, + .tm_isdst = 0}; EXPECT_THAT(LIBC_NAMESPACE::mktime(&tm_data), Fails(EOVERFLOW)); } TEST(LlvmLibcMkTime, InvalidSeconds) { { // -1 second from 1970-01-01 00:00:00 returns 1969-12-31 23:59:59. - struct tm tm_data { - .tm_sec = -1, .tm_min = 0, .tm_hour = 0, .tm_mday = 1, - .tm_mon = Month::JANUARY, .tm_year = tm_year(1970), .tm_wday = 0, - .tm_yday = 0, .tm_isdst = 0 - }; + struct tm tm_data{.tm_sec = -1, + .tm_min = 0, + .tm_hour = 0, + .tm_mday = 1, + .tm_mon = Month::JANUARY, + .tm_year = tm_year(1970), + .tm_wday = 0, + .tm_yday = 0, + .tm_isdst = 0}; EXPECT_THAT(LIBC_NAMESPACE::mktime(&tm_data), Succeeds(-1)); EXPECT_TM_EQ((tm{.tm_sec = 59, .tm_min = 59, @@ -54,11 +62,15 @@ TEST(LlvmLibcMkTime, InvalidSeconds) { { // 60 seconds from 1970-01-01 00:00:00 returns 1970-01-01 00:01:00. - struct tm tm_data { - .tm_sec = 60, .tm_min = 0, .tm_hour = 0, .tm_mday = 1, - .tm_mon = Month::JANUARY, .tm_year = tm_year(1970), .tm_wday = 0, - .tm_yday = 0, .tm_isdst = 0 - }; + struct tm tm_data{.tm_sec = 60, + .tm_min = 0, + .tm_hour = 0, + .tm_mday = 1, + .tm_mon = Month::JANUARY, + .tm_year = tm_year(1970), + .tm_wday = 0, + .tm_yday = 0, + .tm_isdst = 0}; EXPECT_THAT(LIBC_NAMESPACE::mktime(&tm_data), Succeeds(60)); EXPECT_TM_EQ((tm{.tm_sec = 0, .tm_min = 1, @@ -76,13 +88,17 @@ TEST(LlvmLibcMkTime, InvalidSeconds) { TEST(LlvmLibcMkTime, InvalidMinutes) { { // -1 minute from 1970-01-01 00:00:00 returns 1969-12-31 23:59:00. - struct tm tm_data { - .tm_sec = 0, .tm_min = -1, .tm_hour = 0, .tm_mday = 1, - .tm_mon = Month::JANUARY, .tm_year = tm_year(1970), .tm_wday = 0, - .tm_yday = 0, .tm_isdst = 0 - }; + struct tm tm_data{.tm_sec = 0, + .tm_min = -1, + .tm_hour = 0, + .tm_mday = 1, + .tm_mon = Month::JANUARY, + .tm_year = tm_year(1970), + .tm_wday = 0, + .tm_yday = 0, + .tm_isdst = 0}; EXPECT_THAT(LIBC_NAMESPACE::mktime(&tm_data), - Succeeds(-TimeConstants::SECONDS_PER_MIN)); + Succeeds(-LIBC_NAMESPACE::time_constants::SECONDS_PER_MIN)); EXPECT_TM_EQ((tm{.tm_sec = 0, .tm_min = 59, .tm_hour = 23, @@ -97,13 +113,17 @@ TEST(LlvmLibcMkTime, InvalidMinutes) { { // 60 minutes from 1970-01-01 00:00:00 returns 1970-01-01 01:00:00. - struct tm tm_data { - .tm_sec = 0, .tm_min = 60, .tm_hour = 0, .tm_mday = 1, - .tm_mon = Month::JANUARY, .tm_year = tm_year(1970), .tm_wday = 0, - .tm_yday = 0, .tm_isdst = 0 - }; + struct tm tm_data{.tm_sec = 0, + .tm_min = 60, + .tm_hour = 0, + .tm_mday = 1, + .tm_mon = Month::JANUARY, + .tm_year = tm_year(1970), + .tm_wday = 0, + .tm_yday = 0, + .tm_isdst = 0}; EXPECT_THAT(LIBC_NAMESPACE::mktime(&tm_data), - Succeeds(60 * TimeConstants::SECONDS_PER_MIN)); + Succeeds(60 * LIBC_NAMESPACE::time_constants::SECONDS_PER_MIN)); EXPECT_TM_EQ((tm{.tm_sec = 0, .tm_min = 0, .tm_hour = 1, @@ -120,13 +140,17 @@ TEST(LlvmLibcMkTime, InvalidMinutes) { TEST(LlvmLibcMkTime, InvalidHours) { { // -1 hour from 1970-01-01 00:00:00 returns 1969-12-31 23:00:00. - struct tm tm_data { - .tm_sec = 0, .tm_min = 0, .tm_hour = -1, .tm_mday = 1, - .tm_mon = Month::JANUARY, .tm_year = tm_year(1970), .tm_wday = 0, - .tm_yday = 0, .tm_isdst = 0 - }; + struct tm tm_data{.tm_sec = 0, + .tm_min = 0, + .tm_hour = -1, + .tm_mday = 1, + .tm_mon = Month::JANUARY, + .tm_year = tm_year(1970), + .tm_wday = 0, + .tm_yday = 0, + .tm_isdst = 0}; EXPECT_THAT(LIBC_NAMESPACE::mktime(&tm_data), - Succeeds(-TimeConstants::SECONDS_PER_HOUR)); + Succeeds(-LIBC_NAMESPACE::time_constants::SECONDS_PER_HOUR)); EXPECT_TM_EQ((tm{.tm_sec = 0, .tm_min = 0, .tm_hour = 23, @@ -141,13 +165,18 @@ TEST(LlvmLibcMkTime, InvalidHours) { { // 24 hours from 1970-01-01 00:00:00 returns 1970-01-02 00:00:00. - struct tm tm_data { - .tm_sec = 0, .tm_min = 0, .tm_hour = 24, .tm_mday = 1, - .tm_mon = Month::JANUARY, .tm_year = tm_year(1970), .tm_wday = 0, - .tm_yday = 0, .tm_isdst = 0 - }; - EXPECT_THAT(LIBC_NAMESPACE::mktime(&tm_data), - Succeeds(24 * TimeConstants::SECONDS_PER_HOUR)); + struct tm tm_data{.tm_sec = 0, + .tm_min = 0, + .tm_hour = 24, + .tm_mday = 1, + .tm_mon = Month::JANUARY, + .tm_year = tm_year(1970), + .tm_wday = 0, + .tm_yday = 0, + .tm_isdst = 0}; + EXPECT_THAT( + LIBC_NAMESPACE::mktime(&tm_data), + Succeeds(24 * LIBC_NAMESPACE::time_constants::SECONDS_PER_HOUR)); EXPECT_TM_EQ((tm{.tm_sec = 0, .tm_min = 0, .tm_hour = 0, @@ -163,14 +192,18 @@ TEST(LlvmLibcMkTime, InvalidHours) { TEST(LlvmLibcMkTime, InvalidYear) { // -1 year from 1970-01-01 00:00:00 returns 1969-01-01 00:00:00. - struct tm tm_data { - .tm_sec = 0, .tm_min = 0, .tm_hour = 0, .tm_mday = 1, - .tm_mon = Month::JANUARY, .tm_year = tm_year(1969), .tm_wday = 0, - .tm_yday = 0, .tm_isdst = 0 - }; + struct tm tm_data{.tm_sec = 0, + .tm_min = 0, + .tm_hour = 0, + .tm_mday = 1, + .tm_mon = Month::JANUARY, + .tm_year = tm_year(1969), + .tm_wday = 0, + .tm_yday = 0, + .tm_isdst = 0}; EXPECT_THAT(LIBC_NAMESPACE::mktime(&tm_data), - Succeeds(-TimeConstants::DAYS_PER_NON_LEAP_YEAR * - TimeConstants::SECONDS_PER_DAY)); + Succeeds(-LIBC_NAMESPACE::time_constants::DAYS_PER_NON_LEAP_YEAR * + LIBC_NAMESPACE::time_constants::SECONDS_PER_DAY)); EXPECT_TM_EQ((tm{.tm_sec = 0, .tm_min = 0, .tm_hour = 0, @@ -188,61 +221,85 @@ TEST(LlvmLibcMkTime, InvalidEndOf32BitEpochYear) { return; { // 2038-01-19 03:14:08 tests overflow of the second in 2038. - struct tm tm_data { - .tm_sec = 8, .tm_min = 14, .tm_hour = 3, .tm_mday = 19, - .tm_mon = Month::JANUARY, .tm_year = tm_year(2038), .tm_wday = 0, - .tm_yday = 0, .tm_isdst = 0 - }; + struct tm tm_data{.tm_sec = 8, + .tm_min = 14, + .tm_hour = 3, + .tm_mday = 19, + .tm_mon = Month::JANUARY, + .tm_year = tm_year(2038), + .tm_wday = 0, + .tm_yday = 0, + .tm_isdst = 0}; EXPECT_THAT(LIBC_NAMESPACE::mktime(&tm_data), Fails(EOVERFLOW)); } { // 2038-01-19 03:15:07 tests overflow of the minute in 2038. - struct tm tm_data { - .tm_sec = 7, .tm_min = 15, .tm_hour = 3, .tm_mday = 19, - .tm_mon = Month::JANUARY, .tm_year = tm_year(2038), .tm_wday = 0, - .tm_yday = 0, .tm_isdst = 0 - }; + struct tm tm_data{.tm_sec = 7, + .tm_min = 15, + .tm_hour = 3, + .tm_mday = 19, + .tm_mon = Month::JANUARY, + .tm_year = tm_year(2038), + .tm_wday = 0, + .tm_yday = 0, + .tm_isdst = 0}; EXPECT_THAT(LIBC_NAMESPACE::mktime(&tm_data), Fails(EOVERFLOW)); } { // 2038-01-19 04:14:07 tests overflow of the hour in 2038. - struct tm tm_data { - .tm_sec = 7, .tm_min = 14, .tm_hour = 4, .tm_mday = 19, - .tm_mon = Month::JANUARY, .tm_year = tm_year(2038), .tm_wday = 0, - .tm_yday = 0, .tm_isdst = 0 - }; + struct tm tm_data{.tm_sec = 7, + .tm_min = 14, + .tm_hour = 4, + .tm_mday = 19, + .tm_mon = Month::JANUARY, + .tm_year = tm_year(2038), + .tm_wday = 0, + .tm_yday = 0, + .tm_isdst = 0}; EXPECT_THAT(LIBC_NAMESPACE::mktime(&tm_data), Fails(EOVERFLOW)); } { // 2038-01-20 03:14:07 tests overflow of the day in 2038. - struct tm tm_data { - .tm_sec = 7, .tm_min = 14, .tm_hour = 3, .tm_mday = 20, - .tm_mon = Month::JANUARY, .tm_year = tm_year(2038), .tm_wday = 0, - .tm_yday = 0, .tm_isdst = 0 - }; + struct tm tm_data{.tm_sec = 7, + .tm_min = 14, + .tm_hour = 3, + .tm_mday = 20, + .tm_mon = Month::JANUARY, + .tm_year = tm_year(2038), + .tm_wday = 0, + .tm_yday = 0, + .tm_isdst = 0}; EXPECT_THAT(LIBC_NAMESPACE::mktime(&tm_data), Fails(EOVERFLOW)); } { // 2038-02-19 03:14:07 tests overflow of the month in 2038. - struct tm tm_data { - .tm_sec = 7, .tm_min = 14, .tm_hour = 3, .tm_mday = 19, - .tm_mon = Month::FEBRUARY, .tm_year = tm_year(2038), .tm_wday = 0, - .tm_yday = 0, .tm_isdst = 0 - }; + struct tm tm_data{.tm_sec = 7, + .tm_min = 14, + .tm_hour = 3, + .tm_mday = 19, + .tm_mon = Month::FEBRUARY, + .tm_year = tm_year(2038), + .tm_wday = 0, + .tm_yday = 0, + .tm_isdst = 0}; EXPECT_THAT(LIBC_NAMESPACE::mktime(&tm_data), Fails(EOVERFLOW)); } { // 2039-01-19 03:14:07 tests overflow of the year. - struct tm tm_data { - .tm_sec = 7, .tm_min = 14, .tm_hour = 3, .tm_mday = 19, - .tm_mon = Month::JANUARY, .tm_year = tm_year(2039), .tm_wday = 0, - .tm_yday = 0, .tm_isdst = 0 - }; + struct tm tm_data{.tm_sec = 7, + .tm_min = 14, + .tm_hour = 3, + .tm_mday = 19, + .tm_mon = Month::JANUARY, + .tm_year = tm_year(2039), + .tm_wday = 0, + .tm_yday = 0, + .tm_isdst = 0}; EXPECT_THAT(LIBC_NAMESPACE::mktime(&tm_data), Fails(EOVERFLOW)); } } @@ -250,12 +307,18 @@ TEST(LlvmLibcMkTime, InvalidEndOf32BitEpochYear) { TEST(LlvmLibcMkTime, InvalidMonths) { { // -1 month from 1970-01-01 00:00:00 returns 1969-12-01 00:00:00. - struct tm tm_data { - .tm_sec = 0, .tm_min = 0, .tm_hour = 0, .tm_mday = 0, .tm_mon = -1, - .tm_year = tm_year(1970), .tm_wday = 0, .tm_yday = 0, .tm_isdst = 0 - }; - EXPECT_THAT(LIBC_NAMESPACE::mktime(&tm_data), - Succeeds(-32 * TimeConstants::SECONDS_PER_DAY)); + struct tm tm_data{.tm_sec = 0, + .tm_min = 0, + .tm_hour = 0, + .tm_mday = 0, + .tm_mon = -1, + .tm_year = tm_year(1970), + .tm_wday = 0, + .tm_yday = 0, + .tm_isdst = 0}; + EXPECT_THAT( + LIBC_NAMESPACE::mktime(&tm_data), + Succeeds(-32 * LIBC_NAMESPACE::time_constants::SECONDS_PER_DAY)); EXPECT_TM_EQ((tm{.tm_sec = 0, .tm_min = 0, .tm_hour = 0, @@ -270,13 +333,19 @@ TEST(LlvmLibcMkTime, InvalidMonths) { { // 1970-13-01 00:00:00 returns 1971-01-01 00:00:00. - struct tm tm_data { - .tm_sec = 0, .tm_min = 0, .tm_hour = 0, .tm_mday = 1, .tm_mon = 12, - .tm_year = tm_year(1970), .tm_wday = 0, .tm_yday = 0, .tm_isdst = 0 - }; - EXPECT_THAT(LIBC_NAMESPACE::mktime(&tm_data), - Succeeds(TimeConstants::DAYS_PER_NON_LEAP_YEAR * - TimeConstants::SECONDS_PER_DAY)); + struct tm tm_data{.tm_sec = 0, + .tm_min = 0, + .tm_hour = 0, + .tm_mday = 1, + .tm_mon = 12, + .tm_year = tm_year(1970), + .tm_wday = 0, + .tm_yday = 0, + .tm_isdst = 0}; + EXPECT_THAT( + LIBC_NAMESPACE::mktime(&tm_data), + Succeeds(LIBC_NAMESPACE::time_constants::DAYS_PER_NON_LEAP_YEAR * + LIBC_NAMESPACE::time_constants::SECONDS_PER_DAY)); EXPECT_TM_EQ((tm{.tm_sec = 0, .tm_min = 0, .tm_hour = 0, @@ -293,13 +362,17 @@ TEST(LlvmLibcMkTime, InvalidMonths) { TEST(LlvmLibcMkTime, InvalidDays) { { // -1 day from 1970-01-01 00:00:00 returns 1969-12-31 00:00:00. - struct tm tm_data { - .tm_sec = 0, .tm_min = 0, .tm_hour = 0, .tm_mday = (1 - 1), - .tm_mon = Month::JANUARY, .tm_year = tm_year(1970), .tm_wday = 0, - .tm_yday = 0, .tm_isdst = 0 - }; + struct tm tm_data{.tm_sec = 0, + .tm_min = 0, + .tm_hour = 0, + .tm_mday = (1 - 1), + .tm_mon = Month::JANUARY, + .tm_year = tm_year(1970), + .tm_wday = 0, + .tm_yday = 0, + .tm_isdst = 0}; EXPECT_THAT(LIBC_NAMESPACE::mktime(&tm_data), - Succeeds(-1 * TimeConstants::SECONDS_PER_DAY)); + Succeeds(-1 * LIBC_NAMESPACE::time_constants::SECONDS_PER_DAY)); EXPECT_TM_EQ((tm{.tm_sec = 0, .tm_min = 0, .tm_hour = 0, @@ -314,13 +387,17 @@ TEST(LlvmLibcMkTime, InvalidDays) { { // 1970-01-32 00:00:00 returns 1970-02-01 00:00:00. - struct tm tm_data { - .tm_sec = 0, .tm_min = 0, .tm_hour = 0, .tm_mday = 32, - .tm_mon = Month::JANUARY, .tm_year = tm_year(1970), .tm_wday = 0, - .tm_yday = 0, .tm_isdst = 0 - }; + struct tm tm_data{.tm_sec = 0, + .tm_min = 0, + .tm_hour = 0, + .tm_mday = 32, + .tm_mon = Month::JANUARY, + .tm_year = tm_year(1970), + .tm_wday = 0, + .tm_yday = 0, + .tm_isdst = 0}; EXPECT_THAT(LIBC_NAMESPACE::mktime(&tm_data), - Succeeds(31 * TimeConstants::SECONDS_PER_DAY)); + Succeeds(31 * LIBC_NAMESPACE::time_constants::SECONDS_PER_DAY)); EXPECT_TM_EQ((tm{.tm_sec = 0, .tm_min = 0, .tm_hour = 0, @@ -335,13 +412,17 @@ TEST(LlvmLibcMkTime, InvalidDays) { { // 1970-02-29 00:00:00 returns 1970-03-01 00:00:00. - struct tm tm_data { - .tm_sec = 0, .tm_min = 0, .tm_hour = 0, .tm_mday = 29, - .tm_mon = Month::FEBRUARY, .tm_year = tm_year(1970), .tm_wday = 0, - .tm_yday = 0, .tm_isdst = 0 - }; + struct tm tm_data{.tm_sec = 0, + .tm_min = 0, + .tm_hour = 0, + .tm_mday = 29, + .tm_mon = Month::FEBRUARY, + .tm_year = tm_year(1970), + .tm_wday = 0, + .tm_yday = 0, + .tm_isdst = 0}; EXPECT_THAT(LIBC_NAMESPACE::mktime(&tm_data), - Succeeds(59 * TimeConstants::SECONDS_PER_DAY)); + Succeeds(59 * LIBC_NAMESPACE::time_constants::SECONDS_PER_DAY)); EXPECT_TM_EQ((tm{.tm_sec = 0, .tm_min = 0, .tm_hour = 0, @@ -356,14 +437,20 @@ TEST(LlvmLibcMkTime, InvalidDays) { { // 1972-02-30 00:00:00 returns 1972-03-01 00:00:00. - struct tm tm_data { - .tm_sec = 0, .tm_min = 0, .tm_hour = 0, .tm_mday = 30, - .tm_mon = Month::FEBRUARY, .tm_year = tm_year(1972), .tm_wday = 0, - .tm_yday = 0, .tm_isdst = 0 - }; - EXPECT_THAT(LIBC_NAMESPACE::mktime(&tm_data), - Succeeds(((2 * TimeConstants::DAYS_PER_NON_LEAP_YEAR) + 60) * - TimeConstants::SECONDS_PER_DAY)); + struct tm tm_data{.tm_sec = 0, + .tm_min = 0, + .tm_hour = 0, + .tm_mday = 30, + .tm_mon = Month::FEBRUARY, + .tm_year = tm_year(1972), + .tm_wday = 0, + .tm_yday = 0, + .tm_isdst = 0}; + EXPECT_THAT( + LIBC_NAMESPACE::mktime(&tm_data), + Succeeds(((2 * LIBC_NAMESPACE::time_constants::DAYS_PER_NON_LEAP_YEAR) + + 60) * + LIBC_NAMESPACE::time_constants::SECONDS_PER_DAY)); EXPECT_TM_EQ((tm{.tm_sec = 0, .tm_min = 0, .tm_hour = 0, @@ -381,11 +468,15 @@ TEST(LlvmLibcMkTime, EndOf32BitEpochYear) { // Test for maximum value of a signed 32-bit integer. // Test implementation can encode time for Tue 19 January 2038 03:14:07 UTC. { - struct tm tm_data { - .tm_sec = 7, .tm_min = 14, .tm_hour = 3, .tm_mday = 19, - .tm_mon = Month::JANUARY, .tm_year = tm_year(2038), .tm_wday = 0, - .tm_yday = 0, .tm_isdst = 0 - }; + struct tm tm_data{.tm_sec = 7, + .tm_min = 14, + .tm_hour = 3, + .tm_mday = 19, + .tm_mon = Month::JANUARY, + .tm_year = tm_year(2038), + .tm_wday = 0, + .tm_yday = 0, + .tm_isdst = 0}; EXPECT_THAT(LIBC_NAMESPACE::mktime(&tm_data), Succeeds(0x7FFFFFFF)); EXPECT_TM_EQ((tm{.tm_sec = 7, .tm_min = 14, @@ -403,11 +494,15 @@ TEST(LlvmLibcMkTime, EndOf32BitEpochYear) { { // 2038-01-19 03:13:59 tests that even a large seconds field is // accepted if the minutes field is smaller. - struct tm tm_data { - .tm_sec = 59, .tm_min = 13, .tm_hour = 3, .tm_mday = 19, - .tm_mon = Month::JANUARY, .tm_year = tm_year(2038), .tm_wday = 0, - .tm_yday = 0, .tm_isdst = 0 - }; + struct tm tm_data{.tm_sec = 59, + .tm_min = 13, + .tm_hour = 3, + .tm_mday = 19, + .tm_mon = Month::JANUARY, + .tm_year = tm_year(2038), + .tm_wday = 0, + .tm_yday = 0, + .tm_isdst = 0}; EXPECT_THAT(LIBC_NAMESPACE::mktime(&tm_data), Succeeds(0x7FFFFFFF - 8)); EXPECT_TM_EQ((tm{.tm_sec = 59, .tm_min = 13, @@ -424,13 +519,18 @@ TEST(LlvmLibcMkTime, EndOf32BitEpochYear) { { // 2038-01-19 02:59:59 tests that large seconds and minutes are // accepted if the hours field is smaller. - struct tm tm_data { - .tm_sec = 59, .tm_min = 59, .tm_hour = 2, .tm_mday = 19, - .tm_mon = Month::JANUARY, .tm_year = tm_year(2038), .tm_wday = 0, - .tm_yday = 0, .tm_isdst = 0 - }; + struct tm tm_data{.tm_sec = 59, + .tm_min = 59, + .tm_hour = 2, + .tm_mday = 19, + .tm_mon = Month::JANUARY, + .tm_year = tm_year(2038), + .tm_wday = 0, + .tm_yday = 0, + .tm_isdst = 0}; EXPECT_THAT(LIBC_NAMESPACE::mktime(&tm_data), - Succeeds(0x7FFFFFFF - 8 - 14 * TimeConstants::SECONDS_PER_MIN)); + Succeeds(0x7FFFFFFF - 8 - + 14 * LIBC_NAMESPACE::time_constants::SECONDS_PER_MIN)); EXPECT_TM_EQ((tm{.tm_sec = 59, .tm_min = 59, .tm_hour = 2, @@ -446,14 +546,19 @@ TEST(LlvmLibcMkTime, EndOf32BitEpochYear) { { // 2038-01-18 23:59:59 tests that large seconds, minutes and hours // are accepted if the days field is smaller. - struct tm tm_data { - .tm_sec = 59, .tm_min = 59, .tm_hour = 23, .tm_mday = 18, - .tm_mon = Month::JANUARY, .tm_year = tm_year(2038), .tm_wday = 0, - .tm_yday = 0, .tm_isdst = 0 - }; + struct tm tm_data{.tm_sec = 59, + .tm_min = 59, + .tm_hour = 23, + .tm_mday = 18, + .tm_mon = Month::JANUARY, + .tm_year = tm_year(2038), + .tm_wday = 0, + .tm_yday = 0, + .tm_isdst = 0}; EXPECT_THAT(LIBC_NAMESPACE::mktime(&tm_data), - Succeeds(0x7FFFFFFF - 8 - 14 * TimeConstants::SECONDS_PER_MIN - - 3 * TimeConstants::SECONDS_PER_HOUR)); + Succeeds(0x7FFFFFFF - 8 - + 14 * LIBC_NAMESPACE::time_constants::SECONDS_PER_MIN - + 3 * LIBC_NAMESPACE::time_constants::SECONDS_PER_HOUR)); EXPECT_TM_EQ((tm{.tm_sec = 59, .tm_min = 59, .tm_hour = 23, @@ -469,15 +574,20 @@ TEST(LlvmLibcMkTime, EndOf32BitEpochYear) { { // 2038-01-18 23:59:59 tests that the final second of 2037 is // accepted. - struct tm tm_data { - .tm_sec = 59, .tm_min = 59, .tm_hour = 23, .tm_mday = 31, - .tm_mon = Month::DECEMBER, .tm_year = tm_year(2037), .tm_wday = 0, - .tm_yday = 0, .tm_isdst = 0 - }; + struct tm tm_data{.tm_sec = 59, + .tm_min = 59, + .tm_hour = 23, + .tm_mday = 31, + .tm_mon = Month::DECEMBER, + .tm_year = tm_year(2037), + .tm_wday = 0, + .tm_yday = 0, + .tm_isdst = 0}; EXPECT_THAT(LIBC_NAMESPACE::mktime(&tm_data), - Succeeds(0x7FFFFFFF - 8 - 14 * TimeConstants::SECONDS_PER_MIN - - 3 * TimeConstants::SECONDS_PER_HOUR - - 18 * TimeConstants::SECONDS_PER_DAY)); + Succeeds(0x7FFFFFFF - 8 - + 14 * LIBC_NAMESPACE::time_constants::SECONDS_PER_MIN - + 3 * LIBC_NAMESPACE::time_constants::SECONDS_PER_HOUR - + 18 * LIBC_NAMESPACE::time_constants::SECONDS_PER_DAY)); EXPECT_TM_EQ((tm{.tm_sec = 59, .tm_min = 59, .tm_hour = 23, @@ -496,11 +606,15 @@ TEST(LlvmLibcMkTime, Max64BitYear) { return; { // Mon Jan 1 12:50:50 2170 (200 years from 1970), - struct tm tm_data { - .tm_sec = 50, .tm_min = 50, .tm_hour = 12, .tm_mday = 1, - .tm_mon = Month::JANUARY, .tm_year = tm_year(2170), .tm_wday = 0, - .tm_yday = 0, .tm_isdst = 0 - }; + struct tm tm_data{.tm_sec = 50, + .tm_min = 50, + .tm_hour = 12, + .tm_mday = 1, + .tm_mon = Month::JANUARY, + .tm_year = tm_year(2170), + .tm_wday = 0, + .tm_yday = 0, + .tm_isdst = 0}; EXPECT_THAT(LIBC_NAMESPACE::mktime(&tm_data), Succeeds(6311479850)); EXPECT_TM_EQ((tm{.tm_sec = 50, .tm_min = 50, @@ -516,11 +630,15 @@ TEST(LlvmLibcMkTime, Max64BitYear) { { // Test for Tue Jan 1 12:50:50 in 2,147,483,647th year. - struct tm tm_data { - .tm_sec = 50, .tm_min = 50, .tm_hour = 12, .tm_mday = 1, - .tm_mon = Month::JANUARY, .tm_year = tm_year(2147483647), .tm_wday = 0, - .tm_yday = 0, .tm_isdst = 0 - }; + struct tm tm_data{.tm_sec = 50, + .tm_min = 50, + .tm_hour = 12, + .tm_mday = 1, + .tm_mon = Month::JANUARY, + .tm_year = tm_year(2147483647), + .tm_wday = 0, + .tm_yday = 0, + .tm_isdst = 0}; EXPECT_THAT(LIBC_NAMESPACE::mktime(&tm_data), Succeeds(67767976202043050)); EXPECT_TM_EQ((tm{.tm_sec = 50, .tm_min = 50, diff --git a/libc/test/src/time/nanosleep_test.cpp b/libc/test/src/time/nanosleep_test.cpp index 2a6eea4d5e16..d4f98e29bd98 100644 --- a/libc/test/src/time/nanosleep_test.cpp +++ b/libc/test/src/time/nanosleep_test.cpp @@ -6,8 +6,7 @@ // //===----------------------------------------------------------------------===// -#include <time.h> - +#include "hdr/types/struct_timespec.h" #include "src/errno/libc_errno.h" #include "src/time/nanosleep.h" #include "test/UnitTest/ErrnoSetterMatcher.h" |
