blob: 0088eb481344d9ba73c670264fbce683f36fbc85 [file] [log] [blame]
Daniel Lezcano596be9b2011-07-26 14:38:59 +02001/*******************************************************************************
Daniel Lezcano35fb1722011-10-03 13:56:11 +02002 * PM-QA validation test suite for the power management on Linux
Daniel Lezcano596be9b2011-07-26 14:38:59 +02003 *
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 Nguyen7220c172016-06-21 11:13:12 -070030#define SECOND 1000000000 /* in nanoseconds */
31
Daniel Lezcano596be9b2011-07-26 14:38:59 +020032int 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 Nguyen7220c172016-06-21 11:13:12 -070041 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 Lezcano596be9b2011-07-26 14:38:59 +020048
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}