tests/clock_nanosleep.c: use libtests
* tests/clock_nanosleep.c (main): Use assert and perror_msg_and_skip.
This commit is contained in:
parent
5bf0eb0859
commit
4bd7cad240
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2015 Dmitry V. Levin <ldv@altlinux.org>
|
* Copyright (c) 2015-2016 Dmitry V. Levin <ldv@altlinux.org>
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@ -26,6 +26,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "tests.h"
|
#include "tests.h"
|
||||||
|
#include <assert.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
@ -60,34 +61,32 @@ main(void)
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (syscall(__NR_clock_nanosleep, CLOCK_REALTIME, 0, &req.ts, NULL))
|
if (syscall(__NR_clock_nanosleep, CLOCK_REALTIME, 0, &req.ts, NULL))
|
||||||
return 77;
|
perror_msg_and_skip("clock_nanosleep CLOCK_REALTIME");
|
||||||
printf("clock_nanosleep(CLOCK_REALTIME, 0, {%jd, %jd}, NULL) = 0\n",
|
printf("clock_nanosleep(CLOCK_REALTIME, 0, {%jd, %jd}, NULL) = 0\n",
|
||||||
(intmax_t) req.ts.tv_sec, (intmax_t) req.ts.tv_nsec);
|
(intmax_t) req.ts.tv_sec, (intmax_t) req.ts.tv_nsec);
|
||||||
|
|
||||||
if (!syscall(__NR_clock_nanosleep, CLOCK_REALTIME, 0, NULL, &rem.ts))
|
assert(syscall(__NR_clock_nanosleep, CLOCK_REALTIME, 0,
|
||||||
return 77;
|
NULL, &rem.ts) == -1);
|
||||||
printf("clock_nanosleep(CLOCK_REALTIME, 0, NULL, %p)"
|
printf("clock_nanosleep(CLOCK_REALTIME, 0, NULL, %p)"
|
||||||
" = -1 EFAULT (Bad address)\n", &rem.ts);
|
" = -1 EFAULT (%m)\n", &rem.ts);
|
||||||
|
|
||||||
if (syscall(__NR_clock_nanosleep, CLOCK_REALTIME, 0, &req.ts, &rem.ts))
|
assert(syscall(__NR_clock_nanosleep, CLOCK_REALTIME, 0,
|
||||||
return 77;
|
&req.ts, &rem.ts) == 0);
|
||||||
printf("clock_nanosleep(CLOCK_REALTIME, 0, {%jd, %jd}, %p) = 0\n",
|
printf("clock_nanosleep(CLOCK_REALTIME, 0, {%jd, %jd}, %p) = 0\n",
|
||||||
(intmax_t) req.ts.tv_sec, (intmax_t) req.ts.tv_nsec, &rem.ts);
|
(intmax_t) req.ts.tv_sec, (intmax_t) req.ts.tv_nsec, &rem.ts);
|
||||||
|
|
||||||
req.ts.tv_nsec = 999999999 + 1;
|
req.ts.tv_nsec = 999999999 + 1;
|
||||||
if (!syscall(__NR_clock_nanosleep, CLOCK_MONOTONIC, 0, &req.ts, &rem.ts))
|
assert(syscall(__NR_clock_nanosleep, CLOCK_MONOTONIC, 0,
|
||||||
return 77;
|
&req.ts, &rem.ts) == -1);
|
||||||
printf("clock_nanosleep(CLOCK_MONOTONIC, 0"
|
printf("clock_nanosleep(CLOCK_MONOTONIC, 0"
|
||||||
", {%jd, %jd}, %p) = -1 EINVAL (Invalid argument)\n",
|
", {%jd, %jd}, %p) = -1 EINVAL (%m)\n",
|
||||||
(intmax_t) req.ts.tv_sec, (intmax_t) req.ts.tv_nsec, &rem.ts);
|
(intmax_t) req.ts.tv_sec, (intmax_t) req.ts.tv_nsec, &rem.ts);
|
||||||
|
|
||||||
if (sigaction(SIGALRM, &act, NULL))
|
assert(sigaction(SIGALRM, &act, NULL) == 0);
|
||||||
return 77;
|
assert(sigprocmask(SIG_SETMASK, &set, NULL) == 0);
|
||||||
if (sigprocmask(SIG_SETMASK, &set, NULL))
|
|
||||||
return 77;
|
|
||||||
|
|
||||||
if (setitimer(ITIMER_REAL, &itv, NULL))
|
if (setitimer(ITIMER_REAL, &itv, NULL))
|
||||||
return 77;
|
perror_msg_and_skip("setitimer");
|
||||||
printf("setitimer(ITIMER_REAL, {it_interval={%jd, %jd}"
|
printf("setitimer(ITIMER_REAL, {it_interval={%jd, %jd}"
|
||||||
", it_value={%jd, %jd}}, NULL) = 0\n",
|
", it_value={%jd, %jd}}, NULL) = 0\n",
|
||||||
(intmax_t) itv.it_interval.tv_sec,
|
(intmax_t) itv.it_interval.tv_sec,
|
||||||
@ -96,25 +95,23 @@ main(void)
|
|||||||
(intmax_t) itv.it_value.tv_usec);
|
(intmax_t) itv.it_value.tv_usec);
|
||||||
|
|
||||||
--req.ts.tv_nsec;
|
--req.ts.tv_nsec;
|
||||||
if (!syscall(__NR_clock_nanosleep, CLOCK_REALTIME, 0, &req.ts, &rem.ts))
|
assert(syscall(__NR_clock_nanosleep, CLOCK_REALTIME, 0,
|
||||||
return 77;
|
&req.ts, &rem.ts) == -1);
|
||||||
printf("clock_nanosleep(CLOCK_REALTIME, 0, {%jd, %jd}, {%jd, %jd})"
|
printf("clock_nanosleep(CLOCK_REALTIME, 0, {%jd, %jd}, {%jd, %jd})"
|
||||||
" = ? ERESTART_RESTARTBLOCK (Interrupted by signal)\n",
|
" = ? ERESTART_RESTARTBLOCK (Interrupted by signal)\n",
|
||||||
(intmax_t) req.ts.tv_sec, (intmax_t) req.ts.tv_nsec,
|
(intmax_t) req.ts.tv_sec, (intmax_t) req.ts.tv_nsec,
|
||||||
(intmax_t) rem.ts.tv_sec, (intmax_t) rem.ts.tv_nsec);
|
(intmax_t) rem.ts.tv_sec, (intmax_t) rem.ts.tv_nsec);
|
||||||
puts("--- SIGALRM {si_signo=SIGALRM, si_code=SI_KERNEL} ---");
|
puts("--- SIGALRM {si_signo=SIGALRM, si_code=SI_KERNEL} ---");
|
||||||
|
|
||||||
if (syscall(__NR_clock_gettime, CLOCK_REALTIME, &req.ts))
|
assert(syscall(__NR_clock_gettime, CLOCK_REALTIME, &req.ts) == 0);
|
||||||
return 77;
|
|
||||||
printf("clock_gettime(CLOCK_REALTIME, {%jd, %jd}) = 0\n",
|
printf("clock_gettime(CLOCK_REALTIME, {%jd, %jd}) = 0\n",
|
||||||
(intmax_t) req.ts.tv_sec, (intmax_t) req.ts.tv_nsec);
|
(intmax_t) req.ts.tv_sec, (intmax_t) req.ts.tv_nsec);
|
||||||
|
|
||||||
++req.ts.tv_sec;
|
++req.ts.tv_sec;
|
||||||
rem.ts.tv_sec = 0xc0de4;
|
rem.ts.tv_sec = 0xc0de4;
|
||||||
rem.ts.tv_nsec = 0xc0de5;
|
rem.ts.tv_nsec = 0xc0de5;
|
||||||
if (!syscall(__NR_clock_nanosleep, CLOCK_REALTIME, TIMER_ABSTIME,
|
assert(syscall(__NR_clock_nanosleep, CLOCK_REALTIME, TIMER_ABSTIME,
|
||||||
&req.ts, &rem.ts))
|
&req.ts, &rem.ts) == -1);
|
||||||
return 77;
|
|
||||||
printf("clock_nanosleep(CLOCK_REALTIME, TIMER_ABSTIME, {%jd, %jd}, %p)"
|
printf("clock_nanosleep(CLOCK_REALTIME, TIMER_ABSTIME, {%jd, %jd}, %p)"
|
||||||
" = ? ERESTARTNOHAND (To be restarted if no handler)\n",
|
" = ? ERESTARTNOHAND (To be restarted if no handler)\n",
|
||||||
(intmax_t) req.ts.tv_sec, (intmax_t) req.ts.tv_nsec, &rem.ts);
|
(intmax_t) req.ts.tv_sec, (intmax_t) req.ts.tv_nsec, &rem.ts);
|
||||||
|
Loading…
Reference in New Issue
Block a user