Daniel Lezcano | 596be9b | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 1 | /******************************************************************************* |
Daniel Lezcano | 35fb172 | 2011-10-03 13:56:11 +0200 | [diff] [blame] | 2 | * PM-QA validation test suite for the power management on Linux |
Daniel Lezcano | 596be9b | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2011, Linaro Limited. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version 2 |
| 9 | * of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 19 | * |
| 20 | * Contributors: |
| 21 | * Daniel Lezcano <daniel.lezcano@linaro.org> (IBM Corporation) |
| 22 | * - initial API and implementation |
| 23 | * |
| 24 | *******************************************************************************/ |
| 25 | #include <stdio.h> |
| 26 | #include <stdlib.h> |
| 27 | #include <errno.h> |
| 28 | #include <time.h> |
| 29 | |
Lisa Nguyen | 7220c17 | 2016-06-21 11:13:12 -0700 | [diff] [blame] | 30 | #define SECOND 1000000000 /* in nanoseconds */ |
| 31 | |
Daniel Lezcano | 596be9b | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 32 | int main(int argc, char *argv[]) |
| 33 | { |
| 34 | struct timespec req = { 0 }, rem = { 0 }; |
| 35 | |
| 36 | if (argc != 2) { |
| 37 | fprintf(stderr, "%s <nanoseconds>\n", argv[0]); |
| 38 | return 1; |
| 39 | } |
| 40 | |
Lisa Nguyen | 7220c17 | 2016-06-21 11:13:12 -0700 | [diff] [blame] | 41 | int total_nsec = atoi(argv[1]); |
| 42 | |
| 43 | /* if total of nanoseconds equals or exceeds one second */ |
| 44 | if (total_nsec >= SECOND) { |
| 45 | req.tv_sec = total_nsec / SECOND; |
| 46 | req.tv_nsec = total_nsec % SECOND; |
| 47 | } |
Daniel Lezcano | 596be9b | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 48 | |
| 49 | for (;;) { |
| 50 | if (!nanosleep(&req, &rem)) |
| 51 | break; |
| 52 | |
| 53 | if (errno == EINTR) { |
| 54 | req = rem; |
| 55 | continue; |
| 56 | } |
| 57 | |
| 58 | perror("failed to nanosleep"); |
| 59 | return 1; |
| 60 | } |
| 61 | |
| 62 | return 0; |
| 63 | } |