Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | load(libdir + "parallelarray-helpers.js"); |
michael@0 | 2 | |
michael@0 | 3 | // Tests that reduce saves its intermediate state correctly by |
michael@0 | 4 | // inducing a bailout in the middle of the reduction. This test may |
michael@0 | 5 | // fail to test what it is intended to test if the wrong number of |
michael@0 | 6 | // worker threads etc are present. It reproduced an existing bug when |
michael@0 | 7 | // used with 8 worker threads. |
michael@0 | 8 | |
michael@0 | 9 | function testReduce() { |
michael@0 | 10 | var aCounter = 0; |
michael@0 | 11 | function sum(a, b) { |
michael@0 | 12 | var r = a + b; |
michael@0 | 13 | if (r == 234) // occurs once per slice |
michael@0 | 14 | aCounter++; |
michael@0 | 15 | return r; |
michael@0 | 16 | } |
michael@0 | 17 | |
michael@0 | 18 | // We use a big array, to make sure that the test runs with 64 slices. |
michael@0 | 19 | var array = build(8 * 4096, function() { return 1; }); |
michael@0 | 20 | var seqResult = array.reduce(sum); |
michael@0 | 21 | var seqCounter = aCounter; |
michael@0 | 22 | |
michael@0 | 23 | aCounter = 0; |
michael@0 | 24 | var parResult = array.reducePar(sum); |
michael@0 | 25 | var parCounter = aCounter; |
michael@0 | 26 | |
michael@0 | 27 | assertEq(true, parCounter >= seqCounter); |
michael@0 | 28 | assertStructuralEq(parResult, seqResult); |
michael@0 | 29 | } |
michael@0 | 30 | |
michael@0 | 31 | if (getBuildConfiguration().parallelJS) |
michael@0 | 32 | testReduce(); |