1 /* 2 * Copyright (C) 2015-2017 Cyril Hrubis <chrubis (at) suse.cz> 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 12 * the GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software Foundation, 16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 */ 18 19 /* 20 * Check that poll() timeouts correctly. 21 */ 22 #include <errno.h> 23 #include <fcntl.h> 24 #include <sys/wait.h> 25 #include <sys/poll.h> 26 27 #include "tst_timer_test.h" 28 29 static int fds[2]; 30 31 int sample_fn(int clk_id, long long usec) 32 { 33 unsigned int sleep_ms = usec / 1000; 34 35 struct pollfd pfds[] = { 36 {.fd = fds[0], .events = POLLIN} 37 }; 38 39 tst_timer_start(clk_id); 40 TEST(poll(pfds, 1, sleep_ms)); 41 tst_timer_stop(); 42 tst_timer_sample(); 43 44 if (TEST_RETURN != 0) { 45 tst_res(TFAIL | TTERRNO, "poll() returned %li", TEST_RETURN); 46 return 1; 47 } 48 49 return 0; 50 } 51 52 static void setup(void) 53 { 54 SAFE_PIPE(fds); 55 } 56 57 static void cleanup(void) 58 { 59 if (fds[0] > 0) 60 SAFE_CLOSE(fds[0]); 61 62 if (fds[1] > 0) 63 SAFE_CLOSE(fds[1]); 64 } 65 66 static struct tst_test test = { 67 .scall = "poll()", 68 .sample = sample_fn, 69 .setup = setup, 70 .cleanup = cleanup, 71 }; 72