[PATCH] tst: y2038: Add test to check sizes of struct timespec and time_t

Lukasz Majewski lukma@denx.de
Wed Nov 18 09:43:30 GMT 2020


---
 time/Makefile          |  2 +-
 time/tst-y2038-sizes.c | 47 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+), 1 deletion(-)
 create mode 100644 time/tst-y2038-sizes.c

diff --git a/time/Makefile b/time/Makefile
index f27a75a115..e09d17f231 100644
--- a/time/Makefile
+++ b/time/Makefile
@@ -48,7 +48,7 @@ tests	:= test_time clocktest tst-posixtz tst-strptime tst_wcsftime \
 	   tst-strptime3 bug-getdate1 tst-strptime-whitespace tst-ftime \
 	   tst-tzname tst-y2039 bug-mktime4 tst-strftime2 tst-strftime3 \
 	   tst-clock tst-clock2 tst-clock_nanosleep tst-cpuclock1 \
-	   tst-adjtime
+	   tst-adjtime tst-y2038-sizes
 
 include ../Rules
 
diff --git a/time/tst-y2038-sizes.c b/time/tst-y2038-sizes.c
new file mode 100644
index 0000000000..5f3bbd3c4b
--- /dev/null
+++ b/time/tst-y2038-sizes.c
@@ -0,0 +1,47 @@
+/* Test for most important time related variables (structs)
+   Copyright (C) 2020 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+/* Defines necessary for Y2038 time support on ports with
+   __WORDSIZE == 32 and __TIMESIZE == 64.  */
+#define _TIME_BITS 64
+#define _FILE_OFFSET_BITS 64
+
+#include <time.h>
+#include <support/check.h>
+
+static int
+do_test (void)
+{
+  struct timespec t0;
+  time_t t;
+
+#if __TIMESIZE == 64 || defined __USE_TIME_BITS64
+  TEST_COMPARE (sizeof(t), 8);
+  TEST_COMPARE (sizeof(t0), 16);
+  TEST_COMPARE (sizeof(t0.tv_sec), 8);
+  TEST_COMPARE (sizeof(t0.tv_nsec), 8);
+#else
+  TEST_COMPARE (sizeof(t), 4);
+  TEST_COMPARE (sizeof(t0), 8);
+  TEST_COMPARE (sizeof(t0.tv_sec), 4);
+  TEST_COMPARE (sizeof(t0.tv_nsec), 4);
+#endif
+  return 0;
+}
+
+#include <support/test-driver.c>
-- 
2.20.1



More information about the Libc-alpha mailing list