forked from downthemall/downthemall-legacy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestPreallocator.js
58 lines (53 loc) · 1.73 KB
/
testPreallocator.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
"use strict";
/* jshint browser:true */
/* globals module, test, asyncTest, checkExports, QUnit, equal, ok */
/* globals FileUtils, start */
module("manager/preallocator.js");
(function() {
function _do_test(title, impl, size, sparse) {
setTimeout(function() {
var allocStart = Date.now();
var file = FileUtils.getFile("TmpD", ["dtm_prealloc_test" + title + ".tmp"]);
var cb = function callback(result) {
var allocEnd = Date.now();
var allocDiff = allocEnd - allocStart;
var bytesPerSecond = ((size / 1048576.0) / (allocDiff / 1000.0)).toFixed(0);
ok(result, title);
if (result) {
equal(file.fileSize, size,
"file size correct, run time " + (allocDiff) + "ms, " + bytesPerSecond + " Mbytes/s");
}
try {
file.remove(false);
}
catch (ex) {}
start();
};
var pa = impl(file, size, 416, sparse, cb);
if ("then" in pa) {
pa.then(cb);
}
}, 100);
}
test("exports", function() {
checkExports("manager/preallocator", ["prealloc"]);
checkExports("manager/preallocator/asynccopier", ["prealloc"]);
checkExports("manager/preallocator/cothread", ["prealloc"]);
});
asyncTest("worker non-sparse", function() {
var {prealloc} = require("manager/preallocator");
_do_test("non-sparse", prealloc, (1<<26), false);
});
asyncTest("worker sparse", function() {
var {prealloc} = require("manager/preallocator");
_do_test("sparse", prealloc, (1<<26), true);
});
asyncTest("asynccopier", function() {
var {prealloc} = require("manager/preallocator/asynccopier");
_do_test("asynccopier", prealloc, (1<<25), false);
});
asyncTest("cothread", function() {
var {prealloc} = require("manager/preallocator/cothread");
_do_test("cothread", prealloc, (1<<25), false);
});
})();