1 /*
2 * Copyright (c) 2002, Intel Corporation. All rights reserved.
3 * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com
4 * This file is licensed under the GPL license. For the full content
5 * of this license, see the COPYING file at the top level of this
6 * source tree.
7 *
8 * Test that clock() returns a clock_t containing the processor time
9 * since a specific point in time.
10 * Dividing the return value by CLOCKS_PER_SEC gives time in seconds.
11 *
12 * 12/17/02 - Checking in correction made by
13 * jim.houston REMOVE-THIS AT attbi DOT com
14 * Test needed to do something as opposed to idle sleep to
15 * get the CPU time to increase.
16 */
17 #include <time.h>
18 #include <stdio.h>
19 #include <unistd.h>
20 #include <time.h>
21 #include "posixtest.h"
22
23 #define MAX_RUNTIME_SECONDS 15
24
main(void)25 int main(void)
26 {
27 clock_t c1, c2;
28 double sec1, sec2;
29 time_t end = time(NULL) + MAX_RUNTIME_SECONDS;
30
31 c1 = clock();
32 if (c1 == (clock_t)-1) {
33 printf("processor time not available\n");
34 return PTS_UNRESOLVED;
35 }
36 sec1 = (double) c1 / CLOCKS_PER_SEC;
37
38 do {
39 c2 = clock();
40 sec2 = (double) c2 / CLOCKS_PER_SEC;
41 if (sec2 - sec1 > 1) {
42 printf("Times T1=%.2lf, T2=%.2lf\n", sec1, sec2);
43 printf("Test PASSED\n");
44 return PTS_PASS;
45 }
46 } while (end >= time(NULL));
47
48 printf("Error with processor times T1=%.2lf, T2=%.2lf\n",
49 sec1, sec2);
50 return PTS_FAIL;
51 }
52