Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

selftests/timers/nanosleep: Add tests for return of remaining time

If interrupted by a signal clock_nanosleep() returns the remaining time
into the structure pointed to by the rmtp parameter. So far this
functionality was not tested by the timer selftests.

Extend the nanosleep selftest to cover this feature.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://patch.msgid.link/20251106-nanosleep-rtmp-selftest-v1-1-f9212fb295fe@linutronix.de

authored by

Thomas Weißschuh and committed by
Thomas Gleixner
308bc2e3 05d89fe7

+55
+55
tools/testing/selftests/timers/nanosleep.c
··· 116 116 return 0; 117 117 } 118 118 119 + static void dummy_event_handler(int val) 120 + { 121 + /* No action needed */ 122 + } 123 + 124 + static int nanosleep_test_remaining(int clockid) 125 + { 126 + struct timespec rqtp = {}, rmtp = {}; 127 + struct itimerspec itimer = {}; 128 + struct sigaction sa = {}; 129 + timer_t timer; 130 + int ret; 131 + 132 + sa.sa_handler = dummy_event_handler; 133 + ret = sigaction(SIGALRM, &sa, NULL); 134 + if (ret) 135 + return -1; 136 + 137 + ret = timer_create(clockid, NULL, &timer); 138 + if (ret) 139 + return -1; 140 + 141 + itimer.it_value.tv_nsec = NSEC_PER_SEC / 4; 142 + ret = timer_settime(timer, 0, &itimer, NULL); 143 + if (ret) 144 + return -1; 145 + 146 + rqtp.tv_nsec = NSEC_PER_SEC / 2; 147 + ret = clock_nanosleep(clockid, 0, &rqtp, &rmtp); 148 + if (ret != EINTR) 149 + return -1; 150 + 151 + ret = timer_delete(timer); 152 + if (ret) 153 + return -1; 154 + 155 + sa.sa_handler = SIG_DFL; 156 + ret = sigaction(SIGALRM, &sa, NULL); 157 + if (ret) 158 + return -1; 159 + 160 + if (!in_order((struct timespec) {}, rmtp)) 161 + return -1; 162 + 163 + if (!in_order(rmtp, rqtp)) 164 + return -1; 165 + 166 + return 0; 167 + } 168 + 119 169 int main(int argc, char **argv) 120 170 { 121 171 long long length; ··· 199 149 ksft_exit_fail(); 200 150 } 201 151 length *= 100; 152 + } 153 + ret = nanosleep_test_remaining(clockid); 154 + if (ret < 0) { 155 + ksft_test_result_fail("%-31s\n", clockstring(clockid)); 156 + ksft_exit_fail(); 202 157 } 203 158 ksft_test_result_pass("%-31s\n", clockstring(clockid)); 204 159 next: