blob: 2656c91b38e00da5d831f321c9b66838303f5ff6 [file] [log] [blame]
Ryan Dahl55048cd2011-03-10 08:54:521// Copyright Joyent, Inc. and other Node contributors.
2//
3// Permission is hereby granted, free of charge, to any person obtaining a
4// copy of this software and associated documentation files (the
5// "Software"), to deal in the Software without restriction, including
6// without limitation the rights to use, copy, modify, merge, publish,
7// distribute, sublicense, and/or sell copies of the Software, and to permit
8// persons to whom the Software is furnished to do so, subject to the
9// following conditions:
10//
11// The above copyright notice and this permission notice shall be included
12// in all copies or substantial portions of the Software.
13//
14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20// USE OR OTHER DEALINGS IN THE SOFTWARE.
21
Oleg Efimov0ce9cba2010-12-04 22:45:5222var path = require('path');
Oleg Efimov093dfaf2010-12-05 22:33:5223var assert = require('assert');
Ryan Dahl7a2e7842009-10-31 18:02:3024
25exports.testDir = path.dirname(__filename);
Oleg Efimov0ce9cba2010-12-04 22:45:5226exports.fixturesDir = path.join(exports.testDir, 'fixtures');
27exports.libDir = path.join(exports.testDir, '../lib');
28exports.tmpDir = path.join(exports.testDir, 'tmp');
arlolra724ccf12010-02-26 20:06:3229exports.PORT = 12346;
Ryan Dahl4b8f5032009-09-20 16:19:3330
Ben Noordhuisbff96022011-07-21 19:21:0631if (process.platform == 'win32') {
Ryan Dahla6a3bf62011-07-21 21:19:2432 exports.PIPE = '\\\\.\\pipe\\libuv-test';
Ben Noordhuisbff96022011-07-21 19:21:0633} else {
34 exports.PIPE = exports.tmpDir + '/test.sock';
35}
36
Oleg Efimov0ce9cba2010-12-04 22:45:5237var util = require('util');
Micheil Smithe38eb0c2010-10-11 21:04:0938for (var i in util) exports[i] = util[i];
Herbert Vojčíkcf2b2062010-08-17 15:21:4339//for (var i in exports) global[i] = exports[i];
40
Oleg Efimov0665f022010-12-05 19:15:3041function protoCtrChain(o) {
Herbert Vojčíkcf2b2062010-08-17 15:21:4342 var result = [];
43 for (; o; o = o.__proto__) { result.push(o.constructor); }
44 return result.join();
45}
46
Oleg Efimov0ce9cba2010-12-04 22:45:5247exports.indirectInstanceOf = function(obj, cls) {
Herbert Vojčíkcf2b2062010-08-17 15:21:4348 if (obj instanceof cls) { return true; }
49 var clsChain = protoCtrChain(cls.prototype);
50 var objChain = protoCtrChain(obj);
51 return objChain.slice(-clsChain.length) === clsChain;
52};
Ryan Dahl02cc39f2010-12-04 21:40:3953
54
Ryan Dahl3b0f2ce2011-08-10 00:43:5755exports.ddCommand = function(filename, kilobytes) {
56 if (process.platform == 'win32') {
isaacs0cdf85e2012-02-18 23:01:3557 var p = path.resolve(exports.fixturesDir, 'create-file.js');
58 return '"' + process.argv[0] + '" "' + p + '" "' +
59 filename + '" ' + (kilobytes * 1024);
Ryan Dahl3b0f2ce2011-08-10 00:43:5760 } else {
Ryan Dahl3b0f2ce2011-08-10 00:43:5761 return 'dd if=/dev/zero of="' + filename + '" bs=1024 count=' + kilobytes;
62 }
63};
64
65
Ryan Dahl4983bd32011-08-10 18:22:5866exports.spawnPwd = function(options) {
67 var spawn = require('child_process').spawn;
68
Colton Baker87286cc2011-10-04 22:08:1869 if (process.platform == 'win32') {
Ryan Dahl4983bd32011-08-10 18:22:5870 return spawn('cmd.exe', ['/c', 'cd'], options);
71 } else {
72 return spawn('pwd', [], options);
73 }
74};
75
Ryan Dahl3b0f2ce2011-08-10 00:43:5776
Ryan Dahl02cc39f2010-12-04 21:40:3977// Turn this off if the test should not check for global leaks.
78exports.globalCheck = true;
79
Oleg Efimov0665f022010-12-05 19:15:3080process.on('exit', function() {
Ryan Dahl02cc39f2010-12-04 21:40:3981 if (!exports.globalCheck) return;
Oleg Efimov0665f022010-12-05 19:15:3082 var knownGlobals = [setTimeout,
83 setInterval,
84 clearTimeout,
85 clearInterval,
86 console,
87 Buffer,
88 process,
89 global];
Ryan Dahl02cc39f2010-12-04 21:40:3990
Ryan Dahl86214c92011-06-14 16:02:5891 if (global.errno) {
92 knownGlobals.push(errno);
93 }
94
Jorge Chamorro Bielinge7604b12011-03-23 11:29:4995 if (global.gc) {
96 knownGlobals.push(gc);
97 }
98
Ryan Dahle9257b82011-02-10 02:50:2699 if (global.DTRACE_HTTP_SERVER_RESPONSE) {
Ryan Dahl068b7332011-01-25 01:50:10100 knownGlobals.push(DTRACE_HTTP_SERVER_RESPONSE);
101 knownGlobals.push(DTRACE_HTTP_SERVER_REQUEST);
Ryan Dahle9257b82011-02-10 02:50:26102 knownGlobals.push(DTRACE_HTTP_CLIENT_RESPONSE);
103 knownGlobals.push(DTRACE_HTTP_CLIENT_REQUEST);
Ryan Dahl068b7332011-01-25 01:50:10104 knownGlobals.push(DTRACE_NET_STREAM_END);
105 knownGlobals.push(DTRACE_NET_SERVER_CONNECTION);
Ryan Dahle9257b82011-02-10 02:50:26106 knownGlobals.push(DTRACE_NET_SOCKET_READ);
107 knownGlobals.push(DTRACE_NET_SOCKET_WRITE);
Ryan Dahl068b7332011-01-25 01:50:10108 }
109
Thomas Shinnick59b815b2011-08-13 21:51:31110 if (global.ArrayBuffer) {
111 knownGlobals.push(ArrayBuffer);
112 knownGlobals.push(Int8Array);
113 knownGlobals.push(Uint8Array);
114 knownGlobals.push(Int16Array);
115 knownGlobals.push(Uint16Array);
116 knownGlobals.push(Int32Array);
117 knownGlobals.push(Uint32Array);
118 knownGlobals.push(Float32Array);
119 knownGlobals.push(Float64Array);
120 knownGlobals.push(DataView);
121 }
122
Ryan Dahl02cc39f2010-12-04 21:40:39123 for (var x in global) {
124 var found = false;
125
126 for (var y in knownGlobals) {
127 if (global[x] === knownGlobals[y]) {
128 found = true;
129 break;
130 }
131 }
132
133 if (!found) {
Oleg Efimov0665f022010-12-05 19:15:30134 console.error('Unknown global: %s', x);
Ben Noordhuisfa446592011-09-28 23:11:26135 assert.ok(false, 'Unknown global found');
Ryan Dahl02cc39f2010-12-04 21:40:39136 }
137 }
138});
Ryan Dahlaac5cbe2011-02-18 18:05:31139
140
141// This function allows one two run an HTTP test agaist both HTTPS and
142// normal HTTP modules. This ensures they fit the same API.
143exports.httpTest = function httpTest(cb) {
144};
145