1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 * This is a regression test for the bug that the interval timer
8 * is not initialized when _PR_CreateCPU calls PR_IntervalNow.
9 * The bug would make this test program finish prematurely,
10 * when the SHORT_TIMEOUT period expires. The correct behavior
11 * is for the test to finish when the LONG_TIMEOUT period expires.
22 /* The timeouts, in milliseconds */
23 #define SHORT_TIMEOUT 1000
24 #define LONG_TIMEOUT 3000
26 PRLock
*lock1
, *lock2
;
29 void ThreadFunc(void *arg
)
32 PR_WaitCondVar(cv1
, PR_MillisecondsToInterval(SHORT_TIMEOUT
));
36 int main(int argc
, char **argv
)
39 PRIntervalTime start
, end
;
43 PR_ASSERT(NULL
!= lock1
);
44 cv1
= PR_NewCondVar(lock1
);
45 PR_ASSERT(NULL
!= cv1
);
47 PR_ASSERT(NULL
!= lock2
);
48 cv2
= PR_NewCondVar(lock2
);
49 PR_ASSERT(NULL
!= cv2
);
50 start
= PR_IntervalNow();
51 thread
= PR_CreateThread(
59 PR_ASSERT(NULL
!= thread
);
61 PR_WaitCondVar(cv2
, PR_MillisecondsToInterval(LONG_TIMEOUT
));
63 PR_JoinThread(thread
);
64 end
= PR_IntervalNow();
65 elapsed_ms
= PR_IntervalToMilliseconds((PRIntervalTime
)(end
- start
));
66 /* Allow 100ms imprecision */
67 if (elapsed_ms
< LONG_TIMEOUT
- 100 || elapsed_ms
> LONG_TIMEOUT
+ 100) {
68 printf("Elapsed time should be %u ms but is %u ms\n",
69 LONG_TIMEOUT
, elapsed_ms
);
73 printf("Elapsed time: %u ms, expected time: %u ms\n",
74 LONG_TIMEOUT
, elapsed_ms
);