public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc/azanella/y2038] time: Add getitimer and setitimer basic tests
@ 2021-03-01 17:37 Adhemerval Zanella
0 siblings, 0 replies; 5+ messages in thread
From: Adhemerval Zanella @ 2021-03-01 17:37 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=73efedb7301ae4b344d744667e310ce62095ac8c
commit 73efedb7301ae4b344d744667e310ce62095ac8c
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date: Sun Feb 28 17:31:25 2021 -0300
time: Add getitimer and setitimer basic tests
Checked on i686-linux-gnu and x86_64-linux-gnu.
Diff:
---
time/Makefile | 3 +-
time/tst-itimer.c | 175 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 177 insertions(+), 1 deletion(-)
diff --git a/time/Makefile b/time/Makefile
index b3c5368c3b..8fe439c5e0 100644
--- a/time/Makefile
+++ b/time/Makefile
@@ -48,7 +48,8 @@ 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-ctime tst-difftime tst-mktime4 tst-clock_settime
+ tst-adjtime tst-ctime tst-difftime tst-mktime4 tst-clock_settime \
+ tst-itimer
include ../Rules
diff --git a/time/tst-itimer.c b/time/tst-itimer.c
new file mode 100644
index 0000000000..e464d6b092
--- /dev/null
+++ b/time/tst-itimer.c
@@ -0,0 +1,175 @@
+/* Basic tests for getitimer and setitimer.
+ Copyright (C) 2021 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/>. */
+
+#include <array_length.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <sys/time.h>
+#include <support/check.h>
+#include <support/xsignal.h>
+#include <unistd.h>
+#include <time.h>
+
+static sig_atomic_t cnt;
+
+static void
+alrm_handler (int sig)
+{
+ if (++cnt > 3)
+ cnt = 3;
+}
+
+static void
+intr_sleep (int sec)
+{
+ struct timespec ts = { .tv_sec = sec, .tv_nsec = 0 };
+ while (nanosleep (&ts, &ts) == -1 && errno == EINTR)
+ ;
+}
+
+static int
+do_test (void)
+{
+ struct itimerval it, it_old;
+ const int timers[] = { ITIMER_REAL, ITIMER_VIRTUAL, ITIMER_PROF };
+ for (int i = 0; i < array_length (timers); i++)
+ {
+ TEST_COMPARE (getitimer (timers[i], &it), 0);
+
+ /* No timer set, all value should be 0. */
+ TEST_COMPARE (it.it_interval.tv_sec, 0);
+ TEST_COMPARE (it.it_interval.tv_usec, 0);
+ TEST_COMPARE (it.it_value.tv_sec, 0);
+ TEST_COMPARE (it.it_value.tv_usec, 0);
+
+ it.it_interval.tv_sec = 10;
+ it.it_interval.tv_usec = 20;
+ TEST_COMPARE (setitimer (timers[i], &it, NULL), 0);
+
+ TEST_COMPARE (setitimer (timers[i], &(struct itimerval) { 0 }, &it_old),
+ 0);
+ /* ITIMER_REAL returns { 0, 0 } for single-sort timers, while
+ other timers returns setitimer value. */
+ if (timers[i] == ITIMER_REAL)
+ {
+ TEST_COMPARE (it_old.it_interval.tv_sec, 0);
+ TEST_COMPARE (it_old.it_interval.tv_usec, 0);
+ }
+ else
+ {
+ TEST_COMPARE (it_old.it_interval.tv_sec, 10);
+ TEST_COMPARE (it_old.it_interval.tv_usec, 20);
+ }
+
+ /* Create a periodic timer and check if the return value is the one
+ previously set. */
+ it.it_interval.tv_sec = 10;
+ it.it_interval.tv_usec = 20;
+ it.it_value.tv_sec = 30;
+ it.it_value.tv_usec = 40;
+ TEST_COMPARE (setitimer (timers[i], &it, NULL), 0);
+
+ TEST_COMPARE (setitimer (timers[i], &(struct itimerval) { 0 }, &it_old),
+ 0);
+ TEST_COMPARE (it.it_interval.tv_sec, it_old.it_interval.tv_sec);
+ TEST_COMPARE (it.it_interval.tv_usec, it_old.it_interval.tv_usec);
+
+ if (sizeof (time_t) == 4)
+ continue;
+
+ /* Same as before, but with a 64 bit time_t value. */
+ it.it_interval.tv_sec = (time_t) 0x1ffffffffull;
+ it.it_interval.tv_usec = 20;
+ it.it_value.tv_sec = 0;
+ it.it_value.tv_usec = 0;
+
+ /* Linux does not provide 64 bit time_t support for getitimer and
+ setitimer on architectures with 32 bit time_t support. */
+ if (sizeof (__time_t) == 8)
+ {
+ TEST_COMPARE (setitimer (timers[i], &it, NULL), 0);
+ TEST_COMPARE (setitimer (timers[i], &(struct itimerval) { 0 },
+ &it_old),
+ 0);
+ /* ITIMER_REAL returns { 0, 0 } for single-sort timers, while other
+ timers returns setitimer value. */
+ if (timers[i] == ITIMER_REAL)
+ {
+ TEST_COMPARE (it_old.it_interval.tv_sec, 0ull);
+ TEST_COMPARE (it_old.it_interval.tv_usec, 0);
+ }
+ else
+ {
+ TEST_COMPARE (it_old.it_interval.tv_sec, 0x1ffffffffull);
+ TEST_COMPARE (it_old.it_interval.tv_usec, 20);
+ }
+ }
+ else
+ {
+ TEST_COMPARE (setitimer (timers[i], &it, NULL), -1);
+ TEST_COMPARE (errno, EOVERFLOW);
+ }
+
+ /* Create a periodic timer and check if the return value is the one
+ previously set. */
+ it.it_interval.tv_sec = (time_t) 0x1ffffffffull;
+ it.it_interval.tv_usec = 20;
+ it.it_value.tv_sec = 30;
+ it.it_value.tv_usec = 40;
+ if (sizeof (__time_t) == 8)
+ {
+ TEST_COMPARE (setitimer (timers[i], &it, NULL), 0);
+
+ TEST_COMPARE (setitimer (timers[i], &(struct itimerval) { 0 },
+ &it_old),
+ 0);
+ TEST_COMPARE (it.it_interval.tv_sec, it_old.it_interval.tv_sec);
+ TEST_COMPARE (it.it_interval.tv_usec, it_old.it_interval.tv_usec);
+ }
+ else
+ {
+ TEST_COMPARE (setitimer (timers[i], &it, NULL), -1);
+ TEST_COMPARE (errno, EOVERFLOW);
+ }
+ }
+
+ {
+ struct sigaction sa = { .sa_handler = alrm_handler, .sa_flags = 0 };
+ sigemptyset (&sa.sa_mask);
+ xsigaction (SIGALRM, &sa, NULL);
+ }
+
+ /* Setup a timer to 0.1s and sleep for 1s and check to 3 signal handler
+ execution. */
+ it.it_interval.tv_sec = 0;
+ it.it_interval.tv_usec = 100000;
+ it.it_value.tv_sec = 0;
+ it.it_value.tv_usec = 100000;
+
+ /* Check ITIMER_VIRTUAL and ITIMER_PROF would require to generate load
+ and be subject to system load. */
+ cnt = 0;
+ TEST_COMPARE (setitimer (ITIMER_REAL, &it, NULL), 0);
+ intr_sleep (1);
+ TEST_COMPARE (cnt, 3);
+ TEST_COMPARE (setitimer (ITIMER_REAL, &(struct itimerval) { 0 }, NULL), 0);
+
+ return 0;
+}
+
+#include <support/test-driver.c>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [glibc/azanella/y2038] time: Add getitimer and setitimer basic tests
@ 2021-03-05 19:18 Adhemerval Zanella
0 siblings, 0 replies; 5+ messages in thread
From: Adhemerval Zanella @ 2021-03-05 19:18 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=189912c02a372f19e0f05039074d2bd7ae079c35
commit 189912c02a372f19e0f05039074d2bd7ae079c35
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date: Sun Feb 28 17:31:25 2021 -0300
time: Add getitimer and setitimer basic tests
Checked on i686-linux-gnu and x86_64-linux-gnu.
Diff:
---
time/Makefile | 2 +-
time/tst-itimer.c | 175 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 176 insertions(+), 1 deletion(-)
diff --git a/time/Makefile b/time/Makefile
index a52b6b94bc..ccc9eefd61 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-ctime tst-difftime tst-mktime4
+ tst-adjtime tst-ctime tst-difftime tst-mktime4 tst-itimer
include ../Rules
diff --git a/time/tst-itimer.c b/time/tst-itimer.c
new file mode 100644
index 0000000000..e464d6b092
--- /dev/null
+++ b/time/tst-itimer.c
@@ -0,0 +1,175 @@
+/* Basic tests for getitimer and setitimer.
+ Copyright (C) 2021 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/>. */
+
+#include <array_length.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <sys/time.h>
+#include <support/check.h>
+#include <support/xsignal.h>
+#include <unistd.h>
+#include <time.h>
+
+static sig_atomic_t cnt;
+
+static void
+alrm_handler (int sig)
+{
+ if (++cnt > 3)
+ cnt = 3;
+}
+
+static void
+intr_sleep (int sec)
+{
+ struct timespec ts = { .tv_sec = sec, .tv_nsec = 0 };
+ while (nanosleep (&ts, &ts) == -1 && errno == EINTR)
+ ;
+}
+
+static int
+do_test (void)
+{
+ struct itimerval it, it_old;
+ const int timers[] = { ITIMER_REAL, ITIMER_VIRTUAL, ITIMER_PROF };
+ for (int i = 0; i < array_length (timers); i++)
+ {
+ TEST_COMPARE (getitimer (timers[i], &it), 0);
+
+ /* No timer set, all value should be 0. */
+ TEST_COMPARE (it.it_interval.tv_sec, 0);
+ TEST_COMPARE (it.it_interval.tv_usec, 0);
+ TEST_COMPARE (it.it_value.tv_sec, 0);
+ TEST_COMPARE (it.it_value.tv_usec, 0);
+
+ it.it_interval.tv_sec = 10;
+ it.it_interval.tv_usec = 20;
+ TEST_COMPARE (setitimer (timers[i], &it, NULL), 0);
+
+ TEST_COMPARE (setitimer (timers[i], &(struct itimerval) { 0 }, &it_old),
+ 0);
+ /* ITIMER_REAL returns { 0, 0 } for single-sort timers, while
+ other timers returns setitimer value. */
+ if (timers[i] == ITIMER_REAL)
+ {
+ TEST_COMPARE (it_old.it_interval.tv_sec, 0);
+ TEST_COMPARE (it_old.it_interval.tv_usec, 0);
+ }
+ else
+ {
+ TEST_COMPARE (it_old.it_interval.tv_sec, 10);
+ TEST_COMPARE (it_old.it_interval.tv_usec, 20);
+ }
+
+ /* Create a periodic timer and check if the return value is the one
+ previously set. */
+ it.it_interval.tv_sec = 10;
+ it.it_interval.tv_usec = 20;
+ it.it_value.tv_sec = 30;
+ it.it_value.tv_usec = 40;
+ TEST_COMPARE (setitimer (timers[i], &it, NULL), 0);
+
+ TEST_COMPARE (setitimer (timers[i], &(struct itimerval) { 0 }, &it_old),
+ 0);
+ TEST_COMPARE (it.it_interval.tv_sec, it_old.it_interval.tv_sec);
+ TEST_COMPARE (it.it_interval.tv_usec, it_old.it_interval.tv_usec);
+
+ if (sizeof (time_t) == 4)
+ continue;
+
+ /* Same as before, but with a 64 bit time_t value. */
+ it.it_interval.tv_sec = (time_t) 0x1ffffffffull;
+ it.it_interval.tv_usec = 20;
+ it.it_value.tv_sec = 0;
+ it.it_value.tv_usec = 0;
+
+ /* Linux does not provide 64 bit time_t support for getitimer and
+ setitimer on architectures with 32 bit time_t support. */
+ if (sizeof (__time_t) == 8)
+ {
+ TEST_COMPARE (setitimer (timers[i], &it, NULL), 0);
+ TEST_COMPARE (setitimer (timers[i], &(struct itimerval) { 0 },
+ &it_old),
+ 0);
+ /* ITIMER_REAL returns { 0, 0 } for single-sort timers, while other
+ timers returns setitimer value. */
+ if (timers[i] == ITIMER_REAL)
+ {
+ TEST_COMPARE (it_old.it_interval.tv_sec, 0ull);
+ TEST_COMPARE (it_old.it_interval.tv_usec, 0);
+ }
+ else
+ {
+ TEST_COMPARE (it_old.it_interval.tv_sec, 0x1ffffffffull);
+ TEST_COMPARE (it_old.it_interval.tv_usec, 20);
+ }
+ }
+ else
+ {
+ TEST_COMPARE (setitimer (timers[i], &it, NULL), -1);
+ TEST_COMPARE (errno, EOVERFLOW);
+ }
+
+ /* Create a periodic timer and check if the return value is the one
+ previously set. */
+ it.it_interval.tv_sec = (time_t) 0x1ffffffffull;
+ it.it_interval.tv_usec = 20;
+ it.it_value.tv_sec = 30;
+ it.it_value.tv_usec = 40;
+ if (sizeof (__time_t) == 8)
+ {
+ TEST_COMPARE (setitimer (timers[i], &it, NULL), 0);
+
+ TEST_COMPARE (setitimer (timers[i], &(struct itimerval) { 0 },
+ &it_old),
+ 0);
+ TEST_COMPARE (it.it_interval.tv_sec, it_old.it_interval.tv_sec);
+ TEST_COMPARE (it.it_interval.tv_usec, it_old.it_interval.tv_usec);
+ }
+ else
+ {
+ TEST_COMPARE (setitimer (timers[i], &it, NULL), -1);
+ TEST_COMPARE (errno, EOVERFLOW);
+ }
+ }
+
+ {
+ struct sigaction sa = { .sa_handler = alrm_handler, .sa_flags = 0 };
+ sigemptyset (&sa.sa_mask);
+ xsigaction (SIGALRM, &sa, NULL);
+ }
+
+ /* Setup a timer to 0.1s and sleep for 1s and check to 3 signal handler
+ execution. */
+ it.it_interval.tv_sec = 0;
+ it.it_interval.tv_usec = 100000;
+ it.it_value.tv_sec = 0;
+ it.it_value.tv_usec = 100000;
+
+ /* Check ITIMER_VIRTUAL and ITIMER_PROF would require to generate load
+ and be subject to system load. */
+ cnt = 0;
+ TEST_COMPARE (setitimer (ITIMER_REAL, &it, NULL), 0);
+ intr_sleep (1);
+ TEST_COMPARE (cnt, 3);
+ TEST_COMPARE (setitimer (ITIMER_REAL, &(struct itimerval) { 0 }, NULL), 0);
+
+ return 0;
+}
+
+#include <support/test-driver.c>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [glibc/azanella/y2038] time: Add getitimer and setitimer basic tests
@ 2021-03-04 17:37 Adhemerval Zanella
0 siblings, 0 replies; 5+ messages in thread
From: Adhemerval Zanella @ 2021-03-04 17:37 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=5702e40ff7cc0fa7c33a5c29c26903ef36a9840a
commit 5702e40ff7cc0fa7c33a5c29c26903ef36a9840a
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date: Sun Feb 28 17:31:25 2021 -0300
time: Add getitimer and setitimer basic tests
Checked on i686-linux-gnu and x86_64-linux-gnu.
Diff:
---
time/Makefile | 3 +-
time/tst-itimer.c | 175 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 177 insertions(+), 1 deletion(-)
diff --git a/time/Makefile b/time/Makefile
index b3c5368c3b..8fe439c5e0 100644
--- a/time/Makefile
+++ b/time/Makefile
@@ -48,7 +48,8 @@ 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-ctime tst-difftime tst-mktime4 tst-clock_settime
+ tst-adjtime tst-ctime tst-difftime tst-mktime4 tst-clock_settime \
+ tst-itimer
include ../Rules
diff --git a/time/tst-itimer.c b/time/tst-itimer.c
new file mode 100644
index 0000000000..e464d6b092
--- /dev/null
+++ b/time/tst-itimer.c
@@ -0,0 +1,175 @@
+/* Basic tests for getitimer and setitimer.
+ Copyright (C) 2021 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/>. */
+
+#include <array_length.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <sys/time.h>
+#include <support/check.h>
+#include <support/xsignal.h>
+#include <unistd.h>
+#include <time.h>
+
+static sig_atomic_t cnt;
+
+static void
+alrm_handler (int sig)
+{
+ if (++cnt > 3)
+ cnt = 3;
+}
+
+static void
+intr_sleep (int sec)
+{
+ struct timespec ts = { .tv_sec = sec, .tv_nsec = 0 };
+ while (nanosleep (&ts, &ts) == -1 && errno == EINTR)
+ ;
+}
+
+static int
+do_test (void)
+{
+ struct itimerval it, it_old;
+ const int timers[] = { ITIMER_REAL, ITIMER_VIRTUAL, ITIMER_PROF };
+ for (int i = 0; i < array_length (timers); i++)
+ {
+ TEST_COMPARE (getitimer (timers[i], &it), 0);
+
+ /* No timer set, all value should be 0. */
+ TEST_COMPARE (it.it_interval.tv_sec, 0);
+ TEST_COMPARE (it.it_interval.tv_usec, 0);
+ TEST_COMPARE (it.it_value.tv_sec, 0);
+ TEST_COMPARE (it.it_value.tv_usec, 0);
+
+ it.it_interval.tv_sec = 10;
+ it.it_interval.tv_usec = 20;
+ TEST_COMPARE (setitimer (timers[i], &it, NULL), 0);
+
+ TEST_COMPARE (setitimer (timers[i], &(struct itimerval) { 0 }, &it_old),
+ 0);
+ /* ITIMER_REAL returns { 0, 0 } for single-sort timers, while
+ other timers returns setitimer value. */
+ if (timers[i] == ITIMER_REAL)
+ {
+ TEST_COMPARE (it_old.it_interval.tv_sec, 0);
+ TEST_COMPARE (it_old.it_interval.tv_usec, 0);
+ }
+ else
+ {
+ TEST_COMPARE (it_old.it_interval.tv_sec, 10);
+ TEST_COMPARE (it_old.it_interval.tv_usec, 20);
+ }
+
+ /* Create a periodic timer and check if the return value is the one
+ previously set. */
+ it.it_interval.tv_sec = 10;
+ it.it_interval.tv_usec = 20;
+ it.it_value.tv_sec = 30;
+ it.it_value.tv_usec = 40;
+ TEST_COMPARE (setitimer (timers[i], &it, NULL), 0);
+
+ TEST_COMPARE (setitimer (timers[i], &(struct itimerval) { 0 }, &it_old),
+ 0);
+ TEST_COMPARE (it.it_interval.tv_sec, it_old.it_interval.tv_sec);
+ TEST_COMPARE (it.it_interval.tv_usec, it_old.it_interval.tv_usec);
+
+ if (sizeof (time_t) == 4)
+ continue;
+
+ /* Same as before, but with a 64 bit time_t value. */
+ it.it_interval.tv_sec = (time_t) 0x1ffffffffull;
+ it.it_interval.tv_usec = 20;
+ it.it_value.tv_sec = 0;
+ it.it_value.tv_usec = 0;
+
+ /* Linux does not provide 64 bit time_t support for getitimer and
+ setitimer on architectures with 32 bit time_t support. */
+ if (sizeof (__time_t) == 8)
+ {
+ TEST_COMPARE (setitimer (timers[i], &it, NULL), 0);
+ TEST_COMPARE (setitimer (timers[i], &(struct itimerval) { 0 },
+ &it_old),
+ 0);
+ /* ITIMER_REAL returns { 0, 0 } for single-sort timers, while other
+ timers returns setitimer value. */
+ if (timers[i] == ITIMER_REAL)
+ {
+ TEST_COMPARE (it_old.it_interval.tv_sec, 0ull);
+ TEST_COMPARE (it_old.it_interval.tv_usec, 0);
+ }
+ else
+ {
+ TEST_COMPARE (it_old.it_interval.tv_sec, 0x1ffffffffull);
+ TEST_COMPARE (it_old.it_interval.tv_usec, 20);
+ }
+ }
+ else
+ {
+ TEST_COMPARE (setitimer (timers[i], &it, NULL), -1);
+ TEST_COMPARE (errno, EOVERFLOW);
+ }
+
+ /* Create a periodic timer and check if the return value is the one
+ previously set. */
+ it.it_interval.tv_sec = (time_t) 0x1ffffffffull;
+ it.it_interval.tv_usec = 20;
+ it.it_value.tv_sec = 30;
+ it.it_value.tv_usec = 40;
+ if (sizeof (__time_t) == 8)
+ {
+ TEST_COMPARE (setitimer (timers[i], &it, NULL), 0);
+
+ TEST_COMPARE (setitimer (timers[i], &(struct itimerval) { 0 },
+ &it_old),
+ 0);
+ TEST_COMPARE (it.it_interval.tv_sec, it_old.it_interval.tv_sec);
+ TEST_COMPARE (it.it_interval.tv_usec, it_old.it_interval.tv_usec);
+ }
+ else
+ {
+ TEST_COMPARE (setitimer (timers[i], &it, NULL), -1);
+ TEST_COMPARE (errno, EOVERFLOW);
+ }
+ }
+
+ {
+ struct sigaction sa = { .sa_handler = alrm_handler, .sa_flags = 0 };
+ sigemptyset (&sa.sa_mask);
+ xsigaction (SIGALRM, &sa, NULL);
+ }
+
+ /* Setup a timer to 0.1s and sleep for 1s and check to 3 signal handler
+ execution. */
+ it.it_interval.tv_sec = 0;
+ it.it_interval.tv_usec = 100000;
+ it.it_value.tv_sec = 0;
+ it.it_value.tv_usec = 100000;
+
+ /* Check ITIMER_VIRTUAL and ITIMER_PROF would require to generate load
+ and be subject to system load. */
+ cnt = 0;
+ TEST_COMPARE (setitimer (ITIMER_REAL, &it, NULL), 0);
+ intr_sleep (1);
+ TEST_COMPARE (cnt, 3);
+ TEST_COMPARE (setitimer (ITIMER_REAL, &(struct itimerval) { 0 }, NULL), 0);
+
+ return 0;
+}
+
+#include <support/test-driver.c>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [glibc/azanella/y2038] time: Add getitimer and setitimer basic tests
@ 2021-03-04 11:30 Adhemerval Zanella
0 siblings, 0 replies; 5+ messages in thread
From: Adhemerval Zanella @ 2021-03-04 11:30 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=5702e40ff7cc0fa7c33a5c29c26903ef36a9840a
commit 5702e40ff7cc0fa7c33a5c29c26903ef36a9840a
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date: Sun Feb 28 17:31:25 2021 -0300
time: Add getitimer and setitimer basic tests
Checked on i686-linux-gnu and x86_64-linux-gnu.
Diff:
---
time/Makefile | 3 +-
time/tst-itimer.c | 175 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 177 insertions(+), 1 deletion(-)
diff --git a/time/Makefile b/time/Makefile
index b3c5368c3b..8fe439c5e0 100644
--- a/time/Makefile
+++ b/time/Makefile
@@ -48,7 +48,8 @@ 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-ctime tst-difftime tst-mktime4 tst-clock_settime
+ tst-adjtime tst-ctime tst-difftime tst-mktime4 tst-clock_settime \
+ tst-itimer
include ../Rules
diff --git a/time/tst-itimer.c b/time/tst-itimer.c
new file mode 100644
index 0000000000..e464d6b092
--- /dev/null
+++ b/time/tst-itimer.c
@@ -0,0 +1,175 @@
+/* Basic tests for getitimer and setitimer.
+ Copyright (C) 2021 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/>. */
+
+#include <array_length.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <sys/time.h>
+#include <support/check.h>
+#include <support/xsignal.h>
+#include <unistd.h>
+#include <time.h>
+
+static sig_atomic_t cnt;
+
+static void
+alrm_handler (int sig)
+{
+ if (++cnt > 3)
+ cnt = 3;
+}
+
+static void
+intr_sleep (int sec)
+{
+ struct timespec ts = { .tv_sec = sec, .tv_nsec = 0 };
+ while (nanosleep (&ts, &ts) == -1 && errno == EINTR)
+ ;
+}
+
+static int
+do_test (void)
+{
+ struct itimerval it, it_old;
+ const int timers[] = { ITIMER_REAL, ITIMER_VIRTUAL, ITIMER_PROF };
+ for (int i = 0; i < array_length (timers); i++)
+ {
+ TEST_COMPARE (getitimer (timers[i], &it), 0);
+
+ /* No timer set, all value should be 0. */
+ TEST_COMPARE (it.it_interval.tv_sec, 0);
+ TEST_COMPARE (it.it_interval.tv_usec, 0);
+ TEST_COMPARE (it.it_value.tv_sec, 0);
+ TEST_COMPARE (it.it_value.tv_usec, 0);
+
+ it.it_interval.tv_sec = 10;
+ it.it_interval.tv_usec = 20;
+ TEST_COMPARE (setitimer (timers[i], &it, NULL), 0);
+
+ TEST_COMPARE (setitimer (timers[i], &(struct itimerval) { 0 }, &it_old),
+ 0);
+ /* ITIMER_REAL returns { 0, 0 } for single-sort timers, while
+ other timers returns setitimer value. */
+ if (timers[i] == ITIMER_REAL)
+ {
+ TEST_COMPARE (it_old.it_interval.tv_sec, 0);
+ TEST_COMPARE (it_old.it_interval.tv_usec, 0);
+ }
+ else
+ {
+ TEST_COMPARE (it_old.it_interval.tv_sec, 10);
+ TEST_COMPARE (it_old.it_interval.tv_usec, 20);
+ }
+
+ /* Create a periodic timer and check if the return value is the one
+ previously set. */
+ it.it_interval.tv_sec = 10;
+ it.it_interval.tv_usec = 20;
+ it.it_value.tv_sec = 30;
+ it.it_value.tv_usec = 40;
+ TEST_COMPARE (setitimer (timers[i], &it, NULL), 0);
+
+ TEST_COMPARE (setitimer (timers[i], &(struct itimerval) { 0 }, &it_old),
+ 0);
+ TEST_COMPARE (it.it_interval.tv_sec, it_old.it_interval.tv_sec);
+ TEST_COMPARE (it.it_interval.tv_usec, it_old.it_interval.tv_usec);
+
+ if (sizeof (time_t) == 4)
+ continue;
+
+ /* Same as before, but with a 64 bit time_t value. */
+ it.it_interval.tv_sec = (time_t) 0x1ffffffffull;
+ it.it_interval.tv_usec = 20;
+ it.it_value.tv_sec = 0;
+ it.it_value.tv_usec = 0;
+
+ /* Linux does not provide 64 bit time_t support for getitimer and
+ setitimer on architectures with 32 bit time_t support. */
+ if (sizeof (__time_t) == 8)
+ {
+ TEST_COMPARE (setitimer (timers[i], &it, NULL), 0);
+ TEST_COMPARE (setitimer (timers[i], &(struct itimerval) { 0 },
+ &it_old),
+ 0);
+ /* ITIMER_REAL returns { 0, 0 } for single-sort timers, while other
+ timers returns setitimer value. */
+ if (timers[i] == ITIMER_REAL)
+ {
+ TEST_COMPARE (it_old.it_interval.tv_sec, 0ull);
+ TEST_COMPARE (it_old.it_interval.tv_usec, 0);
+ }
+ else
+ {
+ TEST_COMPARE (it_old.it_interval.tv_sec, 0x1ffffffffull);
+ TEST_COMPARE (it_old.it_interval.tv_usec, 20);
+ }
+ }
+ else
+ {
+ TEST_COMPARE (setitimer (timers[i], &it, NULL), -1);
+ TEST_COMPARE (errno, EOVERFLOW);
+ }
+
+ /* Create a periodic timer and check if the return value is the one
+ previously set. */
+ it.it_interval.tv_sec = (time_t) 0x1ffffffffull;
+ it.it_interval.tv_usec = 20;
+ it.it_value.tv_sec = 30;
+ it.it_value.tv_usec = 40;
+ if (sizeof (__time_t) == 8)
+ {
+ TEST_COMPARE (setitimer (timers[i], &it, NULL), 0);
+
+ TEST_COMPARE (setitimer (timers[i], &(struct itimerval) { 0 },
+ &it_old),
+ 0);
+ TEST_COMPARE (it.it_interval.tv_sec, it_old.it_interval.tv_sec);
+ TEST_COMPARE (it.it_interval.tv_usec, it_old.it_interval.tv_usec);
+ }
+ else
+ {
+ TEST_COMPARE (setitimer (timers[i], &it, NULL), -1);
+ TEST_COMPARE (errno, EOVERFLOW);
+ }
+ }
+
+ {
+ struct sigaction sa = { .sa_handler = alrm_handler, .sa_flags = 0 };
+ sigemptyset (&sa.sa_mask);
+ xsigaction (SIGALRM, &sa, NULL);
+ }
+
+ /* Setup a timer to 0.1s and sleep for 1s and check to 3 signal handler
+ execution. */
+ it.it_interval.tv_sec = 0;
+ it.it_interval.tv_usec = 100000;
+ it.it_value.tv_sec = 0;
+ it.it_value.tv_usec = 100000;
+
+ /* Check ITIMER_VIRTUAL and ITIMER_PROF would require to generate load
+ and be subject to system load. */
+ cnt = 0;
+ TEST_COMPARE (setitimer (ITIMER_REAL, &it, NULL), 0);
+ intr_sleep (1);
+ TEST_COMPARE (cnt, 3);
+ TEST_COMPARE (setitimer (ITIMER_REAL, &(struct itimerval) { 0 }, NULL), 0);
+
+ return 0;
+}
+
+#include <support/test-driver.c>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [glibc/azanella/y2038] time: Add getitimer and setitimer basic tests
@ 2021-03-02 12:32 Adhemerval Zanella
0 siblings, 0 replies; 5+ messages in thread
From: Adhemerval Zanella @ 2021-03-02 12:32 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=f4b0e7f4f09d42cffb6c4b2dd191a1ef2c05a07e
commit f4b0e7f4f09d42cffb6c4b2dd191a1ef2c05a07e
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date: Sun Feb 28 17:31:25 2021 -0300
time: Add getitimer and setitimer basic tests
Checked on i686-linux-gnu and x86_64-linux-gnu.
Diff:
---
time/Makefile | 3 +-
time/tst-itimer.c | 175 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 177 insertions(+), 1 deletion(-)
diff --git a/time/Makefile b/time/Makefile
index b3c5368c3b..8fe439c5e0 100644
--- a/time/Makefile
+++ b/time/Makefile
@@ -48,7 +48,8 @@ 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-ctime tst-difftime tst-mktime4 tst-clock_settime
+ tst-adjtime tst-ctime tst-difftime tst-mktime4 tst-clock_settime \
+ tst-itimer
include ../Rules
diff --git a/time/tst-itimer.c b/time/tst-itimer.c
new file mode 100644
index 0000000000..e464d6b092
--- /dev/null
+++ b/time/tst-itimer.c
@@ -0,0 +1,175 @@
+/* Basic tests for getitimer and setitimer.
+ Copyright (C) 2021 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/>. */
+
+#include <array_length.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <sys/time.h>
+#include <support/check.h>
+#include <support/xsignal.h>
+#include <unistd.h>
+#include <time.h>
+
+static sig_atomic_t cnt;
+
+static void
+alrm_handler (int sig)
+{
+ if (++cnt > 3)
+ cnt = 3;
+}
+
+static void
+intr_sleep (int sec)
+{
+ struct timespec ts = { .tv_sec = sec, .tv_nsec = 0 };
+ while (nanosleep (&ts, &ts) == -1 && errno == EINTR)
+ ;
+}
+
+static int
+do_test (void)
+{
+ struct itimerval it, it_old;
+ const int timers[] = { ITIMER_REAL, ITIMER_VIRTUAL, ITIMER_PROF };
+ for (int i = 0; i < array_length (timers); i++)
+ {
+ TEST_COMPARE (getitimer (timers[i], &it), 0);
+
+ /* No timer set, all value should be 0. */
+ TEST_COMPARE (it.it_interval.tv_sec, 0);
+ TEST_COMPARE (it.it_interval.tv_usec, 0);
+ TEST_COMPARE (it.it_value.tv_sec, 0);
+ TEST_COMPARE (it.it_value.tv_usec, 0);
+
+ it.it_interval.tv_sec = 10;
+ it.it_interval.tv_usec = 20;
+ TEST_COMPARE (setitimer (timers[i], &it, NULL), 0);
+
+ TEST_COMPARE (setitimer (timers[i], &(struct itimerval) { 0 }, &it_old),
+ 0);
+ /* ITIMER_REAL returns { 0, 0 } for single-sort timers, while
+ other timers returns setitimer value. */
+ if (timers[i] == ITIMER_REAL)
+ {
+ TEST_COMPARE (it_old.it_interval.tv_sec, 0);
+ TEST_COMPARE (it_old.it_interval.tv_usec, 0);
+ }
+ else
+ {
+ TEST_COMPARE (it_old.it_interval.tv_sec, 10);
+ TEST_COMPARE (it_old.it_interval.tv_usec, 20);
+ }
+
+ /* Create a periodic timer and check if the return value is the one
+ previously set. */
+ it.it_interval.tv_sec = 10;
+ it.it_interval.tv_usec = 20;
+ it.it_value.tv_sec = 30;
+ it.it_value.tv_usec = 40;
+ TEST_COMPARE (setitimer (timers[i], &it, NULL), 0);
+
+ TEST_COMPARE (setitimer (timers[i], &(struct itimerval) { 0 }, &it_old),
+ 0);
+ TEST_COMPARE (it.it_interval.tv_sec, it_old.it_interval.tv_sec);
+ TEST_COMPARE (it.it_interval.tv_usec, it_old.it_interval.tv_usec);
+
+ if (sizeof (time_t) == 4)
+ continue;
+
+ /* Same as before, but with a 64 bit time_t value. */
+ it.it_interval.tv_sec = (time_t) 0x1ffffffffull;
+ it.it_interval.tv_usec = 20;
+ it.it_value.tv_sec = 0;
+ it.it_value.tv_usec = 0;
+
+ /* Linux does not provide 64 bit time_t support for getitimer and
+ setitimer on architectures with 32 bit time_t support. */
+ if (sizeof (__time_t) == 8)
+ {
+ TEST_COMPARE (setitimer (timers[i], &it, NULL), 0);
+ TEST_COMPARE (setitimer (timers[i], &(struct itimerval) { 0 },
+ &it_old),
+ 0);
+ /* ITIMER_REAL returns { 0, 0 } for single-sort timers, while other
+ timers returns setitimer value. */
+ if (timers[i] == ITIMER_REAL)
+ {
+ TEST_COMPARE (it_old.it_interval.tv_sec, 0ull);
+ TEST_COMPARE (it_old.it_interval.tv_usec, 0);
+ }
+ else
+ {
+ TEST_COMPARE (it_old.it_interval.tv_sec, 0x1ffffffffull);
+ TEST_COMPARE (it_old.it_interval.tv_usec, 20);
+ }
+ }
+ else
+ {
+ TEST_COMPARE (setitimer (timers[i], &it, NULL), -1);
+ TEST_COMPARE (errno, EOVERFLOW);
+ }
+
+ /* Create a periodic timer and check if the return value is the one
+ previously set. */
+ it.it_interval.tv_sec = (time_t) 0x1ffffffffull;
+ it.it_interval.tv_usec = 20;
+ it.it_value.tv_sec = 30;
+ it.it_value.tv_usec = 40;
+ if (sizeof (__time_t) == 8)
+ {
+ TEST_COMPARE (setitimer (timers[i], &it, NULL), 0);
+
+ TEST_COMPARE (setitimer (timers[i], &(struct itimerval) { 0 },
+ &it_old),
+ 0);
+ TEST_COMPARE (it.it_interval.tv_sec, it_old.it_interval.tv_sec);
+ TEST_COMPARE (it.it_interval.tv_usec, it_old.it_interval.tv_usec);
+ }
+ else
+ {
+ TEST_COMPARE (setitimer (timers[i], &it, NULL), -1);
+ TEST_COMPARE (errno, EOVERFLOW);
+ }
+ }
+
+ {
+ struct sigaction sa = { .sa_handler = alrm_handler, .sa_flags = 0 };
+ sigemptyset (&sa.sa_mask);
+ xsigaction (SIGALRM, &sa, NULL);
+ }
+
+ /* Setup a timer to 0.1s and sleep for 1s and check to 3 signal handler
+ execution. */
+ it.it_interval.tv_sec = 0;
+ it.it_interval.tv_usec = 100000;
+ it.it_value.tv_sec = 0;
+ it.it_value.tv_usec = 100000;
+
+ /* Check ITIMER_VIRTUAL and ITIMER_PROF would require to generate load
+ and be subject to system load. */
+ cnt = 0;
+ TEST_COMPARE (setitimer (ITIMER_REAL, &it, NULL), 0);
+ intr_sleep (1);
+ TEST_COMPARE (cnt, 3);
+ TEST_COMPARE (setitimer (ITIMER_REAL, &(struct itimerval) { 0 }, NULL), 0);
+
+ return 0;
+}
+
+#include <support/test-driver.c>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-03-05 19:18 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-01 17:37 [glibc/azanella/y2038] time: Add getitimer and setitimer basic tests Adhemerval Zanella
2021-03-02 12:32 Adhemerval Zanella
2021-03-04 11:30 Adhemerval Zanella
2021-03-04 17:37 Adhemerval Zanella
2021-03-05 19:18 Adhemerval Zanella
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).