From: Paul Floyd Date: Sun, 17 Mar 2024 07:01:48 +0000 (+0100) Subject: FreeBSD regtest: add a test for interrupted clock_nanosleep X-Git-Tag: VALGRIND_3_23_0~100 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b7456269dfd2f841b811037362239ae6805054a4;p=thirdparty%2Fvalgrind.git FreeBSD regtest: add a test for interrupted clock_nanosleep Also add missing files for bug483786 --- diff --git a/.gitignore b/.gitignore index e9c302de7..1c54be91e 100644 --- a/.gitignore +++ b/.gitignore @@ -1381,6 +1381,7 @@ /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 diff --git a/memcheck/tests/freebsd/Makefile.am b/memcheck/tests/freebsd/Makefile.am index 2608724f4..d16ab2e92 100644 --- a/memcheck/tests/freebsd/Makefile.am +++ b/memcheck/tests/freebsd/Makefile.am @@ -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 index 000000000..ab4d44b91 --- /dev/null +++ b/memcheck/tests/freebsd/bug483786.c @@ -0,0 +1,37 @@ + +#include + +/* 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 index 000000000..b44e3324d --- /dev/null +++ b/memcheck/tests/freebsd/bug483786.stderr.exp @@ -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 index 000000000..60cb175cb --- /dev/null +++ b/memcheck/tests/freebsd/bug483786.vgtest @@ -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 index 000000000..49f4a2814 --- /dev/null +++ b/memcheck/tests/freebsd/clock_nanosleep_interrupt.c @@ -0,0 +1,32 @@ +#include +#include +#include +#include +#include +#include + +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 index 000000000..1152ed2f1 --- /dev/null +++ b/memcheck/tests/freebsd/clock_nanosleep_interrupt.stderr.exp @@ -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 index 000000000..c4b785d05 --- /dev/null +++ b/memcheck/tests/freebsd/clock_nanosleep_interrupt.vgtest @@ -0,0 +1,2 @@ +prog: clock_nanosleep_interrupt +vgopts: -q