]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
FreeBSD regtest: add a test for interrupted clock_nanosleep
authorPaul Floyd <pjfloyd@wanadoo.fr>
Sun, 17 Mar 2024 07:01:48 +0000 (08:01 +0100)
committerPaul Floyd <pjfloyd@wanadoo.fr>
Sun, 17 Mar 2024 07:01:48 +0000 (08:01 +0100)
Also add missing files for bug483786

.gitignore
memcheck/tests/freebsd/Makefile.am
memcheck/tests/freebsd/bug483786.c [new file with mode: 0644]
memcheck/tests/freebsd/bug483786.stderr.exp [new file with mode: 0644]
memcheck/tests/freebsd/bug483786.vgtest [new file with mode: 0644]
memcheck/tests/freebsd/clock_nanosleep_interrupt.c [new file with mode: 0644]
memcheck/tests/freebsd/clock_nanosleep_interrupt.stderr.exp [new file with mode: 0644]
memcheck/tests/freebsd/clock_nanosleep_interrupt.vgtest [new file with mode: 0644]

index e9c302de730905b03d97d99cbe7558f20054f95b..1c54be91e1254fab5d34f0bbe841c2430818dd4b 100644 (file)
 /memcheck/tests/freebsd/capsicum
 /memcheck/tests/freebsd/chflags
 /memcheck/tests/freebsd/chmod_chown
+/memcheck/tests/freebsd/clock_nanosleep_interrupt
 /memcheck/tests/freebsd/delete_sized_mismatch
 /memcheck/tests/freebsd/errno_aligned_allocs
 /memcheck/tests/freebsd/eventfd1
index 2608724f4b777713386ec3780d1b76fff1ef0b0f..d16ab2e920460783d4d338bfce7f2df5cb304461 100644 (file)
@@ -36,6 +36,8 @@ EXTRA_DIST = \
                chflags.stderr.exp-x86 \
        chmod_chown.vgtest \
        chmod_chown.stderr.exp \
+       clock_nanosleep_interrupt.vgtest \
+       clock_nanosleep_interrupt.stderr.exp \
        delete_sized_mismatch.vgtest \
        delete_sized_mismatch.stderr.exp \
        delete_sized_mismatch_xml.vgtest \
@@ -140,7 +142,8 @@ check_PROGRAMS = \
        access aio aio_read aligned_alloc bug464476 bug470713 \
        bug483786 \
        capsicum chflags \
-       chmod_chown delete_sized_mismatch errno_aligned_allocs \
+       chmod_chown clock_nanosleep_interrupt \
+       delete_sized_mismatch errno_aligned_allocs \
        extattr \
        fexecve \
        file_locking_wait6 \
diff --git a/memcheck/tests/freebsd/bug483786.c b/memcheck/tests/freebsd/bug483786.c
new file mode 100644 (file)
index 0000000..ab4d44b
--- /dev/null
@@ -0,0 +1,37 @@
+
+#include <time.h>
+
+/* should complain about rqtp and rmtp */
+void valgrind_should_complain(void)
+{
+   struct timespec ts_uninitialized;
+
+   clock_nanosleep(CLOCK_MONOTONIC, 0, &ts_uninitialized, &ts_uninitialized);
+}
+
+/* should have no complaints */
+void valgrind_should_not_complain(void)
+{
+   struct timespec ts_initialized = {0};
+
+   clock_nanosleep(CLOCK_MONOTONIC, 0, &ts_initialized, &ts_initialized);
+}
+
+/* should have no complaints */
+void valgrind_should_not_complain2(void)
+{
+   struct timespec ts_initialized = {0};
+
+   clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &ts_initialized,
+                   &ts_initialized);
+}
+
+int main(int argc, char** argv)
+{
+
+   valgrind_should_complain();
+   valgrind_should_not_complain();
+   valgrind_should_not_complain2();
+
+   return (0);
+}
diff --git a/memcheck/tests/freebsd/bug483786.stderr.exp b/memcheck/tests/freebsd/bug483786.stderr.exp
new file mode 100644 (file)
index 0000000..b44e332
--- /dev/null
@@ -0,0 +1,7 @@
+Syscall param clock_nanosleep(rqtp) points to uninitialised byte(s)
+   ...
+   by 0x........: valgrind_should_complain (bug483786.c:9)
+   by 0x........: main (bug483786.c:32)
+ Address 0x........ is on thread 1's stack
+ in frame #1, created by valgrind_should_complain (bug483786.c:6)
+
diff --git a/memcheck/tests/freebsd/bug483786.vgtest b/memcheck/tests/freebsd/bug483786.vgtest
new file mode 100644 (file)
index 0000000..60cb175
--- /dev/null
@@ -0,0 +1,2 @@
+prog: bug483786
+vgopts: -q
diff --git a/memcheck/tests/freebsd/clock_nanosleep_interrupt.c b/memcheck/tests/freebsd/clock_nanosleep_interrupt.c
new file mode 100644 (file)
index 0000000..49f4a28
--- /dev/null
@@ -0,0 +1,32 @@
+#include <fcntl.h>
+#include <signal.h>
+#include <stdio.h>
+#include <sys/time.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+volatile int     ticks = 0;
+struct itimerval timert;
+struct sigaction timer_action;
+
+void handle_vtalrm(int sig) { ticks++; }
+
+
+int main(int argc, char* argv[])
+{
+   timer_action.sa_handler = handle_vtalrm;
+   sigemptyset(&timer_action.sa_mask);
+   timer_action.sa_flags = SA_RESTART;
+
+   sigaction(SIGVTALRM, &timer_action, NULL);
+
+   timert.it_interval.tv_sec = timert.it_value.tv_sec = 0;
+   timert.it_interval.tv_usec = timert.it_value.tv_usec = 500;
+   setitimer(ITIMER_VIRTUAL, &timert, NULL);
+   
+   struct timespec ts_initialized = {0, 1000000};
+   struct timespec* too_small = malloc(1);
+
+   clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &ts_initialized,
+                   too_small);
+}
diff --git a/memcheck/tests/freebsd/clock_nanosleep_interrupt.stderr.exp b/memcheck/tests/freebsd/clock_nanosleep_interrupt.stderr.exp
new file mode 100644 (file)
index 0000000..1152ed2
--- /dev/null
@@ -0,0 +1,7 @@
+Syscall param clock_nanosleep(rmtp) points to unaddressable byte(s)
+   ...
+   by 0x........: main (clock_nanosleep_interrupt.c:30)
+ Address 0x........ is 0 bytes after a block of size 1 alloc'd
+   at 0x........: malloc (vg_replace_malloc.c:...)
+   by 0x........: main (clock_nanosleep_interrupt.c:28)
+
diff --git a/memcheck/tests/freebsd/clock_nanosleep_interrupt.vgtest b/memcheck/tests/freebsd/clock_nanosleep_interrupt.vgtest
new file mode 100644 (file)
index 0000000..c4b785d
--- /dev/null
@@ -0,0 +1,2 @@
+prog: clock_nanosleep_interrupt
+vgopts: -q