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

Message ID 20201118094330.27186-1-lukma@denx.de
State Not applicable
Delegated to: Lukasz Majewski
Headers
Series tst: y2038: Add test to check sizes of struct timespec and time_t |

Commit Message

Lukasz Majewski Nov. 18, 2020, 9:43 a.m. UTC
  ---
 time/Makefile          |  2 +-
 time/tst-y2038-sizes.c | 47 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+), 1 deletion(-)
 create mode 100644 time/tst-y2038-sizes.c
  

Comments

Andreas Schwab Nov. 18, 2020, 2:05 p.m. UTC | #1
Wouldn't it make sense to test this via some _Static_assert in the sources?

Andreas.
  
Lukasz Majewski Nov. 19, 2020, 8:57 p.m. UTC | #2
Hi Andreas,

> Wouldn't it make sense to test this via some _Static_assert in the
> sources?

Ok. I will look into that option (it was also suggested by Adhemerval
some time ago).

> 
> Andreas.
> 




Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lukma@denx.de
  

Patch

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>