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
|
---|
4 | *
|
---|
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/
|
---|
9 | *
|
---|
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
|
---|
13 | * License.
|
---|
14 | *
|
---|
15 | * The Original Code is the Netscape Portable Runtime (NSPR).
|
---|
16 | *
|
---|
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.
|
---|
21 | *
|
---|
22 | * Contributor(s):
|
---|
23 | *
|
---|
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.
|
---|
35 | *
|
---|
36 | * ***** END LICENSE BLOCK ***** */
|
---|
37 |
|
---|
38 | /*
|
---|
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.
|
---|
44 | */
|
---|
45 |
|
---|
46 | #include "prlock.h"
|
---|
47 | #include "prcvar.h"
|
---|
48 | #include "prthread.h"
|
---|
49 | #include "prinrval.h"
|
---|
50 | #include "prlog.h"
|
---|
51 | #include <stdio.h>
|
---|
52 |
|
---|
53 | /* The timeouts, in milliseconds */
|
---|
54 | #define SHORT_TIMEOUT 1000
|
---|
55 | #define LONG_TIMEOUT 3000
|
---|
56 |
|
---|
57 | PRLock *lock1, *lock2;
|
---|
58 | PRCondVar *cv1, *cv2;
|
---|
59 |
|
---|
60 | void ThreadFunc(void *arg)
|
---|
61 | {
|
---|
62 | PR_Lock(lock1);
|
---|
63 | PR_WaitCondVar(cv1, PR_MillisecondsToInterval(SHORT_TIMEOUT));
|
---|
64 | PR_Unlock(lock1);
|
---|
65 | }
|
---|
66 |
|
---|
67 | int main()
|
---|
68 | {
|
---|
69 | PRThread *thread;
|
---|
70 | PRIntervalTime start, end;
|
---|
71 | PRUint32 elapsed_ms;
|
---|
72 |
|
---|
73 | lock1 = PR_NewLock();
|
---|
74 | PR_ASSERT(NULL != lock1);
|
---|
75 | cv1 = PR_NewCondVar(lock1);
|
---|
76 | PR_ASSERT(NULL != cv1);
|
---|
77 | lock2 = PR_NewLock();
|
---|
78 | PR_ASSERT(NULL != lock2);
|
---|
79 | cv2 = PR_NewCondVar(lock2);
|
---|
80 | PR_ASSERT(NULL != cv2);
|
---|
81 | start = PR_IntervalNow();
|
---|
82 | thread = PR_CreateThread(
|
---|
83 | PR_USER_THREAD,
|
---|
84 | ThreadFunc,
|
---|
85 | NULL,
|
---|
86 | PR_PRIORITY_NORMAL,
|
---|
87 | PR_LOCAL_THREAD,
|
---|
88 | PR_JOINABLE_THREAD,
|
---|
89 | 0);
|
---|
90 | PR_ASSERT(NULL != thread);
|
---|
91 | PR_Lock(lock2);
|
---|
92 | PR_WaitCondVar(cv2, PR_MillisecondsToInterval(LONG_TIMEOUT));
|
---|
93 | PR_Unlock(lock2);
|
---|
94 | PR_JoinThread(thread);
|
---|
95 | end = PR_IntervalNow();
|
---|
96 | elapsed_ms = PR_IntervalToMilliseconds((PRIntervalTime)(end - start));
|
---|
97 | /* Allow 100ms imprecision */
|
---|
98 | if (elapsed_ms < LONG_TIMEOUT - 100 || elapsed_ms > LONG_TIMEOUT + 100) {
|
---|
99 | printf("Elapsed time should be %u ms but is %u ms\n",
|
---|
100 | LONG_TIMEOUT, elapsed_ms);
|
---|
101 | printf("FAIL\n");
|
---|
102 | exit(1);
|
---|
103 | }
|
---|
104 | printf("Elapsed time: %u ms, expected time: %u ms\n",
|
---|
105 | LONG_TIMEOUT, elapsed_ms);
|
---|
106 | printf("PASS\n");
|
---|
107 | return 0;
|
---|
108 | }
|
---|