4 * Objective: The purpose of this test is to make sure that the timeout mechanisms
7 * Description: Executes a select as if it was a sleep and compares the time it
8 * has been actually sleeping against the specified time in the select call.
9 * Three cases are tested: first, a timeout specified in seconds, second, a timeout in
10 * microseconds, and third, a timeout with more precision than seconds.
15 #include <sys/types.h>
16 #include <sys/select.h>
24 #define USECONDS 3000000L
28 time_t start
, end
; /* variables for timing */
29 struct timeval timeout
; /* timeout structure */
31 /* Set timeout for 3 seconds */
32 timeout
.tv_sec
= SECONDS
;
34 printf("Sleeping now for %d seconds...\n", SECONDS
);
35 /* Record time before starting */
37 r
= select(0, NULL
, NULL
, NULL
, &timeout
);
38 printf("select return code: %d error: %s\n",
41 printf("For a timeout with select of %d seconds, it took %d actual seconds\n",
44 /* Set timeout for 3 seconds , but specified in microseconds */
47 timeout
.tv_usec
= USECONDS
;
48 printf("\n***************************\n");
49 printf("Sleeping now for %ld microseconds...\n", USECONDS
);
50 /* Record time before starting */
52 r
= select(0, NULL
, NULL
, NULL
, &timeout
);
53 printf("select return code: %d error: %s\n",
56 printf("For a timeout with select of %ld useconds, it took %d actual seconds\n",
59 /* Set timeout for 1.5 seconds, but specified in microseconds */
62 timeout
.tv_usec
= USECONDS
/2;
63 printf("\n***************************\n");
64 printf("Sleeping now for %ld microseconds...\n", USECONDS
/2);
65 /* Record time before starting */
67 r
= select(0, NULL
, NULL
, NULL
, &timeout
);
68 printf("select return code: %d error: %s\n",
71 printf("For a timeout with select of %ld useconds, it took %d actual seconds\n",
72 USECONDS
/2, end
-start
);