Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | /* |
michael@0 | 7 | * This is a regression test for the bug that the interval timer |
michael@0 | 8 | * is not initialized when _PR_CreateCPU calls PR_IntervalNow. |
michael@0 | 9 | * The bug would make this test program finish prematurely, |
michael@0 | 10 | * when the SHORT_TIMEOUT period expires. The correct behavior |
michael@0 | 11 | * is for the test to finish when the LONG_TIMEOUT period expires. |
michael@0 | 12 | */ |
michael@0 | 13 | |
michael@0 | 14 | #include "prlock.h" |
michael@0 | 15 | #include "prcvar.h" |
michael@0 | 16 | #include "prthread.h" |
michael@0 | 17 | #include "prinrval.h" |
michael@0 | 18 | #include "prlog.h" |
michael@0 | 19 | #include <stdio.h> |
michael@0 | 20 | #include <stdlib.h> |
michael@0 | 21 | |
michael@0 | 22 | /* The timeouts, in milliseconds */ |
michael@0 | 23 | #define SHORT_TIMEOUT 1000 |
michael@0 | 24 | #define LONG_TIMEOUT 3000 |
michael@0 | 25 | |
michael@0 | 26 | PRLock *lock1, *lock2; |
michael@0 | 27 | PRCondVar *cv1, *cv2; |
michael@0 | 28 | |
michael@0 | 29 | void ThreadFunc(void *arg) |
michael@0 | 30 | { |
michael@0 | 31 | PR_Lock(lock1); |
michael@0 | 32 | PR_WaitCondVar(cv1, PR_MillisecondsToInterval(SHORT_TIMEOUT)); |
michael@0 | 33 | PR_Unlock(lock1); |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | int main(int argc, char **argv) |
michael@0 | 37 | { |
michael@0 | 38 | PRThread *thread; |
michael@0 | 39 | PRIntervalTime start, end; |
michael@0 | 40 | PRUint32 elapsed_ms; |
michael@0 | 41 | |
michael@0 | 42 | lock1 = PR_NewLock(); |
michael@0 | 43 | PR_ASSERT(NULL != lock1); |
michael@0 | 44 | cv1 = PR_NewCondVar(lock1); |
michael@0 | 45 | PR_ASSERT(NULL != cv1); |
michael@0 | 46 | lock2 = PR_NewLock(); |
michael@0 | 47 | PR_ASSERT(NULL != lock2); |
michael@0 | 48 | cv2 = PR_NewCondVar(lock2); |
michael@0 | 49 | PR_ASSERT(NULL != cv2); |
michael@0 | 50 | start = PR_IntervalNow(); |
michael@0 | 51 | thread = PR_CreateThread( |
michael@0 | 52 | PR_USER_THREAD, |
michael@0 | 53 | ThreadFunc, |
michael@0 | 54 | NULL, |
michael@0 | 55 | PR_PRIORITY_NORMAL, |
michael@0 | 56 | PR_LOCAL_THREAD, |
michael@0 | 57 | PR_JOINABLE_THREAD, |
michael@0 | 58 | 0); |
michael@0 | 59 | PR_ASSERT(NULL != thread); |
michael@0 | 60 | PR_Lock(lock2); |
michael@0 | 61 | PR_WaitCondVar(cv2, PR_MillisecondsToInterval(LONG_TIMEOUT)); |
michael@0 | 62 | PR_Unlock(lock2); |
michael@0 | 63 | PR_JoinThread(thread); |
michael@0 | 64 | end = PR_IntervalNow(); |
michael@0 | 65 | elapsed_ms = PR_IntervalToMilliseconds((PRIntervalTime)(end - start)); |
michael@0 | 66 | /* Allow 100ms imprecision */ |
michael@0 | 67 | if (elapsed_ms < LONG_TIMEOUT - 100 || elapsed_ms > LONG_TIMEOUT + 100) { |
michael@0 | 68 | printf("Elapsed time should be %u ms but is %u ms\n", |
michael@0 | 69 | LONG_TIMEOUT, elapsed_ms); |
michael@0 | 70 | printf("FAIL\n"); |
michael@0 | 71 | exit(1); |
michael@0 | 72 | } |
michael@0 | 73 | printf("Elapsed time: %u ms, expected time: %u ms\n", |
michael@0 | 74 | LONG_TIMEOUT, elapsed_ms); |
michael@0 | 75 | printf("PASS\n"); |
michael@0 | 76 | return 0; |
michael@0 | 77 | } |