-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathrun_tests.js
109 lines (81 loc) · 3.2 KB
/
run_tests.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
tempfile=(+new Date()) + "." + process.pid + ".tmp",
assert=require("assert"), fs=require("fs"), mmap = require("./index")
var t = 128 | (Math.random() * 256);
var b = new Buffer(1);
b[0] = t;
fs.writeFileSync(tempfile, b);
process.on("exit", function() {
fs.unlink(tempfile);
});
(function(b) {
assert.equal(b[0], t, "value check (map read)");
assert.equal(b[1], 0, "value check (line noise)");
assert.equal(b[2], 0, "value check (line noise)");
assert.equal(b.sync(), true, "sync failed");
assert.equal(b.length, mmap.PAGESIZE, "map length is incorrect");
assert.equal(b.unmap(), true, "unmap failed");
assert.equal(b.length, 0, "unmap truncated fixed buffer");
})( mmap(mmap.PAGESIZE, // note using wrapper (with filename)
mmap.PROT_READ|mmap.PROT_WRITE,
mmap.MAP_SHARED,
tempfile) );
fd = fs.openSync(tempfile, "r+");
(function(b) {
assert.equal(b[0], t, "value check (still there)");
assert.equal(b[1], 0, "value check (always zero)");
assert.equal(b[2], 0, "value check (always zero)");
assert.equal(b.length, mmap.PAGESIZE, "map length is incorrect");
b[2] = t;
assert.equal(b.sync(), true, "sync failed");
})( mmap(mmap.PAGESIZE,
mmap.PROT_READ|mmap.PROT_WRITE,
mmap.MAP_SHARED,
fd) );
fs.closeSync(fd);
(function(b) {
assert.equal(b[0], t, "value check (still there)");
assert.equal(b[1], 0, "value check (always zero)");
assert.equal(b[2], t, "value check (now visible)");
assert.equal(b.length, mmap.PAGESIZE, "map length is incorrect");
assert.equal(b.sync(), true, "sync failed");
})( mmap(mmap.PAGESIZE,
mmap.PROT_READ,
mmap.MAP_SHARED,
tempfile) );
fd = fs.openSync(tempfile, "w+");
fs.truncateSync(fd, mmap.PAGESIZE);
(function(b) {
assert.equal(b[0], 0, "value check (truncated 0)");
assert.equal(b[1], 0, "value check (always zero)");
assert.equal(b[2], 0, "value check (always zero)");
assert.equal(b.length, mmap.PAGESIZE, "map length is incorrect");
b[2] = t;
assert.equal(b.sync(), true, "sync failed");
})( mmap.map(mmap.PAGESIZE,
mmap.PROT_READ|mmap.PROT_WRITE,
mmap.MAP_SHARED,
fd) );
(function(b) {
fs.closeSync(fd);
assert.equal(b[0], 0, "value check (truncated 0)");
assert.equal(b[1], 0, "value check (always zero)");
assert.equal(b[2], t, "third mapping");
assert.equal(b.length, mmap.PAGESIZE, "map length is incorrect");
})( mmap.map(mmap.PAGESIZE,
mmap.PROT_READ,
mmap.MAP_SHARED,
fd) );
fs.writeFileSync(tempfile, b);
global.gc();
(function(b) {
assert.equal(b[0], t, "value check (map read)");
assert.equal(b[1], 0, "value check (line noise)");
assert.equal(b[2], 0, "value check (line noise)");
assert.equal(b.sync(), true, "sync failed");
assert.equal(b.length, mmap.PAGESIZE, "map length is incorrect");
})( mmap(mmap.PAGESIZE, // note using wrapper (with filename)
mmap.PROT_READ|mmap.PROT_WRITE,
mmap.MAP_SHARED,
tempfile) );
global.gc();
console.log("> ok");