• 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 "posixtest.h"
21 
22 #define LARGENUMBER 8000000
main(void)23 int main(void)
24 {
25 	clock_t c1, c2;
26 	double sec1, sec2;
27 	int i;
28 
29 	c1 = clock();
30 	sec1 = c1 / CLOCKS_PER_SEC;
31 
32 	for (i = 0; i < LARGENUMBER; i++) {
33 		// keep busy so CPU time increases
34 		clock();
35 	}
36 
37 	c2 = clock();
38 	sec2 = c2 / CLOCKS_PER_SEC;
39 
40 	if (sec2 > sec1) {
41 		printf("Times T1=%.2f, T2=%.2f\n", sec1, sec2);
42 		printf("Test PASSED\n");
43 		return PTS_PASS;
44 	} else {
45 		if (sec2 < sec1) {
46 			/*
47 			 * probably wrapping happened; however, since
48 			 * we do not know the wrap value, results are
49 			 * undefined
50 			 */
51 			printf("TEST AGAIN:  Times probably wrapped\n");
52 			return PTS_UNRESOLVED;
53 		} else {
54 			printf("Error with processor times T1=%.2f, T2=%.2f\n",
55 			       sec1, sec2);
56 			return PTS_FAIL;
57 		}
58 	}
59 
60 	return PTS_UNRESOLVED;
61 }
62