1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is the Netscape Portable Runtime (NSPR).
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998-2000
20 * the Initial Developer. All Rights Reserved.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
39 * This is a regression test for the bug that the interval timer
40 * is not initialized when _PR_CreateCPU calls PR_IntervalNow.
41 * The bug would make this test program finish prematurely,
42 * when the SHORT_TIMEOUT period expires. The correct behavior
43 * is for the test to finish when the LONG_TIMEOUT period expires.
54 /* The timeouts, in milliseconds */
55 #define SHORT_TIMEOUT 1000
56 #define LONG_TIMEOUT 3000
58 PRLock
*lock1
, *lock2
;
61 void ThreadFunc(void *arg
)
64 PR_WaitCondVar(cv1
, PR_MillisecondsToInterval(SHORT_TIMEOUT
));
71 PRIntervalTime start
, end
;
75 PR_ASSERT(NULL
!= lock1
);
76 cv1
= PR_NewCondVar(lock1
);
77 PR_ASSERT(NULL
!= cv1
);
79 PR_ASSERT(NULL
!= lock2
);
80 cv2
= PR_NewCondVar(lock2
);
81 PR_ASSERT(NULL
!= cv2
);
82 start
= PR_IntervalNow();
83 thread
= PR_CreateThread(
91 PR_ASSERT(NULL
!= thread
);
93 PR_WaitCondVar(cv2
, PR_MillisecondsToInterval(LONG_TIMEOUT
));
95 PR_JoinThread(thread
);
96 end
= PR_IntervalNow();
97 elapsed_ms
= PR_IntervalToMilliseconds((PRIntervalTime
)(end
- start
));
98 /* Allow 100ms imprecision */
99 if (elapsed_ms
< LONG_TIMEOUT
- 100 || elapsed_ms
> LONG_TIMEOUT
+ 100) {
100 printf("Elapsed time should be %u ms but is %u ms\n",
101 LONG_TIMEOUT
, elapsed_ms
);
105 printf("Elapsed time: %u ms, expected time: %u ms\n",
106 LONG_TIMEOUT
, elapsed_ms
);