[libc-commits] [libc] [libc][NFC] Forcing data type in gettimeofday_test when comparing the diff. (PR #69652)

via libc-commits libc-commits at lists.llvm.org
Thu Oct 19 16:34:53 PDT 2023


https://github.com/lntue updated https://github.com/llvm/llvm-project/pull/69652

>From 0ee9aeea47bbe21be52bda6c20e64ecfd37a4d3f Mon Sep 17 00:00:00 2001
From: Tue Ly <lntue at google.com>
Date: Thu, 19 Oct 2023 18:32:48 -0400
Subject: [PATCH 1/2] [libc][NFC] Forcing data type in gettimeofday_test when
 comparing the diff.

---
 libc/test/src/time/gettimeofday_test.cpp | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/libc/test/src/time/gettimeofday_test.cpp b/libc/test/src/time/gettimeofday_test.cpp
index 44250787c5381ef..6f4386ccec30ba8 100644
--- a/libc/test/src/time/gettimeofday_test.cpp
+++ b/libc/test/src/time/gettimeofday_test.cpp
@@ -18,7 +18,7 @@ namespace cpp = LIBC_NAMESPACE::cpp;
 TEST(LlvmLibcGettimeofday, SmokeTest) {
   using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
   void *tz = nullptr;
-  struct timeval tv;
+  timeval tv;
 
   int sleep_times[2] = {200, 1000};
   for (int i = 0; i < 2; i++) {
@@ -27,15 +27,15 @@ TEST(LlvmLibcGettimeofday, SmokeTest) {
 
     int sleep_time = sleep_times[i];
     // Sleep for {sleep_time} microsceconds.
-    struct timespec tim = {0, sleep_time * 1000};
-    struct timespec tim2 = {0, 0};
+    timespec tim = {0, sleep_time * 1000};
+    timespec tim2 = {0, 0};
     ret = LIBC_NAMESPACE::nanosleep(&tim, &tim2);
 
     // Call gettimeofday again and verify that it is more {sleep_time}
     // microscecods.
-    struct timeval tv1;
+    timeval tv1;
     ret = LIBC_NAMESPACE::gettimeofday(&tv1, tz);
     ASSERT_EQ(ret, 0);
-    ASSERT_GE(tv1.tv_usec - tv.tv_usec, sleep_time);
+    ASSERT_GE(tv1.tv_usec - tv.tv_usec, static_cast<suseconds_t>(sleep_time));
   }
 }

>From a1c2f2b3296949457487c7d6b806f969d175eb60 Mon Sep 17 00:00:00 2001
From: Tue Ly <lntue at google.com>
Date: Thu, 19 Oct 2023 19:33:49 -0400
Subject: [PATCH 2/2] Use suseconds_t for sleep_time(s).

---
 libc/test/src/time/gettimeofday_test.cpp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libc/test/src/time/gettimeofday_test.cpp b/libc/test/src/time/gettimeofday_test.cpp
index 6f4386ccec30ba8..2deb7726264ee39 100644
--- a/libc/test/src/time/gettimeofday_test.cpp
+++ b/libc/test/src/time/gettimeofday_test.cpp
@@ -20,12 +20,12 @@ TEST(LlvmLibcGettimeofday, SmokeTest) {
   void *tz = nullptr;
   timeval tv;
 
-  int sleep_times[2] = {200, 1000};
+  suseconds_t sleep_times[2] = {200, 1000};
   for (int i = 0; i < 2; i++) {
     int ret = LIBC_NAMESPACE::gettimeofday(&tv, tz);
     ASSERT_EQ(ret, 0);
 
-    int sleep_time = sleep_times[i];
+    suseconds_t sleep_time = sleep_times[i];
     // Sleep for {sleep_time} microsceconds.
     timespec tim = {0, sleep_time * 1000};
     timespec tim2 = {0, 0};
@@ -36,6 +36,6 @@ TEST(LlvmLibcGettimeofday, SmokeTest) {
     timeval tv1;
     ret = LIBC_NAMESPACE::gettimeofday(&tv1, tz);
     ASSERT_EQ(ret, 0);
-    ASSERT_GE(tv1.tv_usec - tv.tv_usec, static_cast<suseconds_t>(sleep_time));
+    ASSERT_GE(tv1.tv_usec - tv.tv_usec, sleep_time);
   }
 }



More information about the libc-commits mailing list