-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathtest-runner.js
More file actions
124 lines (115 loc) · 3.48 KB
/
Copy pathtest-runner.js
File metadata and controls
124 lines (115 loc) · 3.48 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
const x11 = require('./lib');
const Mocha = require('mocha');
const fs = require('fs');
const path = require('path');
const async = require('async');
const mocha = new Mocha({
timeout : 80000,
reporter : 'spec'
});
// Extension-specific test files are only added when the server advertises the
// extension (checked with QueryExtension by on-the-wire name).
const extensionTests = {
'damage.js': 'DAMAGE',
'dbe.js': 'DOUBLE-BUFFER',
'dpms.js': 'DPMS',
'dri3-live.js': 'DRI3',
'fixes.js': 'XFIXES',
'ge.js': 'Generic Event Extension',
'glx.js': 'GLX',
'present.js': 'Present',
'randr.js': 'RANDR',
'record.js': 'RECORD',
'render.js': 'RENDER',
'res.js': 'X-Resource',
'screen-saver.js': 'MIT-SCREEN-SAVER',
'shape.js': 'SHAPE',
'shm.js': 'MIT-SHM',
'sync.js': 'SYNC',
'xc-misc.js': 'XC-MISC',
'xinerama.js': 'XINERAMA',
'xinput.js': 'XInputExtension',
'xkb.js': 'XKEYBOARD',
'xtest.js': 'XTEST',
'xv.js': 'XVideo'
};
// To be able to perform the tests we need the server:
// 1 - to support the dpms extension.
// 2 - dpms version is 1.1.
// 3 - to be dpms capable.
const run_dpms_test = (X, cb) => {
X.require('dpms', (err, ext) => {
if (!err) {
const dpms = ext;
dpms.GetVersion(undefined, undefined, (err, version) => {
if (!err && version[0] === 1 && version[1] === 1) {
dpms.Capable((err, capable) => {
if (!err && capable[0] == 1) cb(true);
else cb(false);
});
} else {
cb(false);
}
});
} else {
cb(false);
}
});
};
const run_randr_test = (X, cb) => {
X.require('randr', (err, ext) => {
if (!err) {
const randr = ext;
randr.QueryVersion(1, 2, (err, version) => {
if (err) {
cb(false);
} else {
cb((version[0] === 1) && (version[1] >= 2));
}
});
} else {
cb(false);
}
});
};
x11.createClient((err, display) => {
if (err) {
console.log('Could not create X client');
process.exit(-1);
}
const X = display.client;
// Add all files from test root directory. Subdirectories (test/xserver,
// test/glx-emu) hold suites that need no real X server and run separately
// via `npm run test:xserver` / `npm run test:glx-emu`.
async.forEach(
fs.readdirSync('./test').filter(
f => f.endsWith('.js') && fs.statSync(path.join('./test', f)).isFile()),
(file, cb) => {
const addIf = run => {
if (run) {
mocha.addFile(path.join('./test', file));
}
cb();
};
if (file === 'dpms.js') {
run_dpms_test(X, addIf);
} else if (file === 'randr.js') {
run_randr_test(X, addIf);
} else if (extensionTests[file]) {
X.QueryExtension(extensionTests[file], (err, ext) => {
addIf(!err && ext.present);
});
} else {
addIf(true);
}
},
() => {
X.terminate();
X.on('end', () => {
mocha.run(failures => {
process.exit(failures);
});
});
}
);
});