unofficial mirror of libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] tst: y2038: Add test to check sizes of struct timespec and time_t
@ 2020-11-18  9:43 Lukasz Majewski
  2020-11-18 14:05 ` Andreas Schwab
  0 siblings, 1 reply; 3+ messages in thread
From: Lukasz Majewski @ 2020-11-18  9:43 UTC (permalink / raw
  To: Joseph Myers, Paul Eggert, Adhemerval Zanella
  Cc: Florian Weimer, GNU C Library, Andreas Schwab, Stepan Golosunov,
	Alistair Francis

---
 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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] tst: y2038: Add test to check sizes of struct timespec and time_t
  2020-11-18  9:43 [PATCH] tst: y2038: Add test to check sizes of struct timespec and time_t Lukasz Majewski
@ 2020-11-18 14:05 ` Andreas Schwab
  2020-11-19 20:57   ` Lukasz Majewski
  0 siblings, 1 reply; 3+ messages in thread
From: Andreas Schwab @ 2020-11-18 14:05 UTC (permalink / raw
  To: Lukasz Majewski
  Cc: Florian Weimer, GNU C Library, Stepan Golosunov, Alistair Francis,
	Joseph Myers

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

Andreas.

-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] tst: y2038: Add test to check sizes of struct timespec and time_t
  2020-11-18 14:05 ` Andreas Schwab
@ 2020-11-19 20:57   ` Lukasz Majewski
  0 siblings, 0 replies; 3+ messages in thread
From: Lukasz Majewski @ 2020-11-19 20:57 UTC (permalink / raw
  To: Andreas Schwab
  Cc: Florian Weimer, GNU C Library, Stepan Golosunov, Alistair Francis,
	Joseph Myers

[-- Attachment #1: Type: text/plain, Size: 475 bytes --]

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

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-11-19 20:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-11-18  9:43 [PATCH] tst: y2038: Add test to check sizes of struct timespec and time_t Lukasz Majewski
2020-11-18 14:05 ` Andreas Schwab
2020-11-19 20:57   ` Lukasz Majewski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).