• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 BUSY_LOOP_SECONDS 5
24 
main(void)25 int main(void)
26 {
27 	clock_t c1, c2;
28 	double sec1, sec2;
29 	time_t end;
30 
31 	c1 = clock();
32 	sec1 = c1 / CLOCKS_PER_SEC;
33 
34 	end = time(NULL) + BUSY_LOOP_SECONDS;
35 
36 	while (end >= time(NULL)) {
37 		clock();
38 	}
39 
40 	c2 = clock();
41 	sec2 = c2 / CLOCKS_PER_SEC;
42 
43 	if (sec2 > sec1) {
44 		printf("Times T1=%.2f, T2=%.2f\n", sec1, sec2);
45 		printf("Test PASSED\n");
46 		return PTS_PASS;
47 	} else {
48 		if (sec2 < sec1) {
49 			/*
50 			 * probably wrapping happened; however, since
51 			 * we do not know the wrap value, results are
52 			 * undefined
53 			 */
54 			printf("TEST AGAIN:  Times probably wrapped\n");
55 			return PTS_UNRESOLVED;
56 		} else {
57 			printf("Error with processor times T1=%.2f, T2=%.2f\n",
58 			       sec1, sec2);
59 			return PTS_FAIL;
60 		}
61 	}
62 
63 	return PTS_UNRESOLVED;
64 }
65