2015-09-17 23:05:20 +03:00
/*
2016-01-06 12:51:37 +03:00
* Copyright ( c ) 2015 - 2016 Dmitry V . Levin < ldv @ altlinux . org >
2017-05-22 20:14:52 +03:00
* Copyright ( c ) 2015 - 2017 The strace developers .
2015-09-17 23:05:20 +03:00
* All rights reserved .
*
2018-12-10 03:00:00 +03:00
* SPDX - License - Identifier : GPL - 2.0 - or - later
2015-09-17 23:05:20 +03:00
*/
2016-01-02 16:28:43 +03:00
# include "tests.h"
2015-09-17 23:05:20 +03:00
# include <fcntl.h>
2016-08-09 17:38:29 +03:00
# include <asm/unistd.h>
2015-09-17 23:05:20 +03:00
# if defined __NR_timerfd_create \
& & defined __NR_timerfd_gettime \
& & defined __NR_timerfd_settime \
& & defined O_CLOEXEC
2016-01-06 12:51:37 +03:00
# include <stdio.h>
# include <stdint.h>
# include <time.h>
# include <unistd.h>
2015-09-17 23:05:20 +03:00
int
main ( void )
{
( void ) close ( 0 ) ;
if ( syscall ( __NR_timerfd_create , CLOCK_MONOTONIC , O_CLOEXEC | O_NONBLOCK ) )
2016-01-06 12:51:37 +03:00
perror_msg_and_skip ( " timerfd_create " ) ;
2015-09-17 23:05:20 +03:00
puts ( " timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC|TFD_NONBLOCK) = 0 " ) ;
2017-04-24 02:10:57 +03:00
TAIL_ALLOC_OBJECT_CONST_PTR ( struct itimerspec , its_new ) ;
TAIL_ALLOC_OBJECT_CONST_PTR ( struct itimerspec , its_old ) ;
2015-09-17 23:05:20 +03:00
2017-04-24 02:10:57 +03:00
its_new - > it_interval . tv_sec = 0xdeadbeefU ;
its_new - > it_interval . tv_nsec = 0xfacefeedU ;
its_new - > it_value . tv_sec = ( time_t ) 0xcafef00ddeadbeefLL ;
its_new - > it_value . tv_nsec = ( long ) 0xbadc0dedfacefeedLL ;
long rc = syscall ( __NR_timerfd_settime , 0 , 0 , its_new , its_old ) ;
printf ( " timerfd_settime(0, 0 "
" , {it_interval={tv_sec=%lld, tv_nsec=%llu} "
" , it_value={tv_sec=%lld, tv_nsec=%llu}}, %p) = %s \n " ,
( long long ) its_new - > it_interval . tv_sec ,
zero_extend_signed_to_ull ( its_new - > it_interval . tv_nsec ) ,
( long long ) its_new - > it_value . tv_sec ,
zero_extend_signed_to_ull ( its_new - > it_value . tv_nsec ) ,
its_old , sprintrc ( rc ) ) ;
its_new - > it_interval . tv_sec = 0xdeface1 ;
its_new - > it_interval . tv_nsec = 0xdeface2 ;
its_new - > it_value . tv_sec = 0xdeface3 ;
its_new - > it_value . tv_nsec = 0xdeface4 ;
its_old - > it_interval . tv_sec = 0xdeface5 ;
its_old - > it_interval . tv_nsec = 0xdeface6 ;
its_old - > it_value . tv_sec = 0xdeface7 ;
its_old - > it_value . tv_nsec = 0xdeface8 ;
if ( syscall ( __NR_timerfd_settime , 0 , 0 , its_new , its_old ) )
2016-01-06 12:51:37 +03:00
perror_msg_and_skip ( " timerfd_settime " ) ;
2015-09-17 23:05:20 +03:00
printf ( " timerfd_settime(0, 0 "
Print microseconds/nanoseconds as non-negative
Negative micro/nanoseconds values are treated as invalid by kernel
anyway, and in one case (timespec_valid in include/linux/time.h)
it is even checked by conversion to unsigned long.
* print_timespec.c (timespec_fmt): Change tv_sec format to %lld and
tv_nsec format to %llu.
(print_timespec_t): Cast tv_sec to long long and process tv_nsec with
zero_extend_signed_to_ull.
(sprint_timespec): Likewise.
* print_timeval.c (timeval_fmt): Change tv_sec format to %lld and
tv_usec format to %llu.
(print_timeval_t): Cast tv_sec to long long and process tv_nsec with
zero_extend_signed_to_ull.
(sprint_timeval, print_timeval32_t, sprint_timeval32): Likewise.
* defs.h (TIMESPEC_TEXT_BUFSIZE): Update.
* tests/adjtimex.c (main): Change tv_sec printing format to %lld, cast
it to long long; change tv_usec printing format to %llu, process it with
zero_extend_signed_to_ull.
* tests/clock_nanosleep.c (main): Change tv_sec printing format to %lld,
cast it to long long; change tv_nsec printing format to %llu, process it
with zero_extend_signed_to_ull.
* tests/clock_xettime.c (main): Likewise.
* tests/futex.c (main): Likewise.
* tests/futimesat.c (print_tv): Likewise.
* tests/getrusage.c (invoke_print): Likewise.
* tests/mq_sendrecv.c (do_send, do_recv, main): Likewise.
* tests/nanosleep.c (main): Likewise.
* tests/pselect6.c (main): Likewise.
* tests/restart_syscall.c (main): Likewise.
* tests/rt_sigtimedwait.c (iterate, main): Likewise.
* tests/sched_rr_get_interval.c (main): Likewise.
* tests/semop.c (main): Likewise.
* tests/timer_xettime.c (main): Likewise.
* tests/timerfd_xettime.c (main): Likewise.
* tests/waitid.c (main): Likewise.
* tests/xetitimer.c (main): Likewise.
* tests/xettimeofday.c (main): Likewise.
* tests/xselect.c (main): Likewise.
* tests/xutimes.c (print_tv): Likewise.
* tests/wait4.c (sprint_rusage): Likewise.
* tests/waitid.c (sprint_rusage): Likewise.
* tests/utimensat.c (print_ts): Likewise.
(main): Add check for higher bits of tv_sec/tv_nsec.
Co-authored-by: Dmitry V. Levin <ldv@altlinux.org>
2017-04-23 06:57:03 +03:00
" , {it_interval={tv_sec=%lld, tv_nsec=%llu} "
" , it_value={tv_sec=%lld, tv_nsec=%llu}} "
" , {it_interval={tv_sec=%lld, tv_nsec=%llu} "
" , it_value={tv_sec=%lld, tv_nsec=%llu}} "
2015-09-17 23:05:20 +03:00
" ) = 0 \n " ,
2017-04-24 02:10:57 +03:00
( long long ) its_new - > it_interval . tv_sec ,
zero_extend_signed_to_ull ( its_new - > it_interval . tv_nsec ) ,
( long long ) its_new - > it_value . tv_sec ,
zero_extend_signed_to_ull ( its_new - > it_value . tv_nsec ) ,
( long long ) its_old - > it_interval . tv_sec ,
zero_extend_signed_to_ull ( its_old - > it_interval . tv_nsec ) ,
( long long ) its_old - > it_value . tv_sec ,
zero_extend_signed_to_ull ( its_old - > it_value . tv_nsec ) ) ;
2015-09-17 23:05:20 +03:00
2017-04-24 02:10:57 +03:00
if ( syscall ( __NR_timerfd_gettime , 0 , its_old ) )
2016-01-06 12:51:37 +03:00
perror_msg_and_skip ( " timerfd_gettime " ) ;
2015-09-17 23:05:20 +03:00
printf ( " timerfd_gettime(0 "
Print microseconds/nanoseconds as non-negative
Negative micro/nanoseconds values are treated as invalid by kernel
anyway, and in one case (timespec_valid in include/linux/time.h)
it is even checked by conversion to unsigned long.
* print_timespec.c (timespec_fmt): Change tv_sec format to %lld and
tv_nsec format to %llu.
(print_timespec_t): Cast tv_sec to long long and process tv_nsec with
zero_extend_signed_to_ull.
(sprint_timespec): Likewise.
* print_timeval.c (timeval_fmt): Change tv_sec format to %lld and
tv_usec format to %llu.
(print_timeval_t): Cast tv_sec to long long and process tv_nsec with
zero_extend_signed_to_ull.
(sprint_timeval, print_timeval32_t, sprint_timeval32): Likewise.
* defs.h (TIMESPEC_TEXT_BUFSIZE): Update.
* tests/adjtimex.c (main): Change tv_sec printing format to %lld, cast
it to long long; change tv_usec printing format to %llu, process it with
zero_extend_signed_to_ull.
* tests/clock_nanosleep.c (main): Change tv_sec printing format to %lld,
cast it to long long; change tv_nsec printing format to %llu, process it
with zero_extend_signed_to_ull.
* tests/clock_xettime.c (main): Likewise.
* tests/futex.c (main): Likewise.
* tests/futimesat.c (print_tv): Likewise.
* tests/getrusage.c (invoke_print): Likewise.
* tests/mq_sendrecv.c (do_send, do_recv, main): Likewise.
* tests/nanosleep.c (main): Likewise.
* tests/pselect6.c (main): Likewise.
* tests/restart_syscall.c (main): Likewise.
* tests/rt_sigtimedwait.c (iterate, main): Likewise.
* tests/sched_rr_get_interval.c (main): Likewise.
* tests/semop.c (main): Likewise.
* tests/timer_xettime.c (main): Likewise.
* tests/timerfd_xettime.c (main): Likewise.
* tests/waitid.c (main): Likewise.
* tests/xetitimer.c (main): Likewise.
* tests/xettimeofday.c (main): Likewise.
* tests/xselect.c (main): Likewise.
* tests/xutimes.c (print_tv): Likewise.
* tests/wait4.c (sprint_rusage): Likewise.
* tests/waitid.c (sprint_rusage): Likewise.
* tests/utimensat.c (print_ts): Likewise.
(main): Add check for higher bits of tv_sec/tv_nsec.
Co-authored-by: Dmitry V. Levin <ldv@altlinux.org>
2017-04-23 06:57:03 +03:00
" , {it_interval={tv_sec=%lld, tv_nsec=%llu} "
" , it_value={tv_sec=%lld, tv_nsec=%llu}}) = 0 \n " ,
2017-04-24 02:10:57 +03:00
( long long ) its_old - > it_interval . tv_sec ,
zero_extend_signed_to_ull ( its_old - > it_interval . tv_nsec ) ,
( long long ) its_old - > it_value . tv_sec ,
zero_extend_signed_to_ull ( its_old - > it_value . tv_nsec ) ) ;
2015-09-17 23:05:20 +03:00
puts ( " +++ exited with 0 +++ " ) ;
return 0 ;
}
# else
2016-01-06 12:51:37 +03:00
SKIP_MAIN_UNDEFINED ( " __NR_timerfd_create && __NR_timerfd_gettime "
" && __NR_timerfd_settime && O_CLOEXEC " )
2015-09-17 23:05:20 +03:00
# endif