|
| 1 | +// 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 | + |
| 22 | +var path = require('path'); |
| 23 | +var assert = require('assert'); |
| 24 | + |
| 25 | +exports.testDir = path.dirname(__filename); |
| 26 | +exports.fixturesDir = path.join(exports.testDir, 'fixtures'); |
| 27 | +exports.libDir = path.join(exports.testDir, '../lib'); |
| 28 | +exports.tmpDir = path.join(exports.testDir, 'tmp'); |
| 29 | +exports.PORT = 12346; |
| 30 | +exports.PROXY_PORT = 1234567; |
| 31 | + |
| 32 | +if (process.platform == 'win32') { |
| 33 | + exports.PIPE = '\\\\.\\pipe\\libuv-test'; |
| 34 | +} else { |
| 35 | + exports.PIPE = exports.tmpDir + '/test.sock'; |
| 36 | +} |
| 37 | + |
| 38 | +var util = require('util'); |
| 39 | +for (var i in util) exports[i] = util[i]; |
| 40 | +//for (var i in exports) global[i] = exports[i]; |
| 41 | + |
| 42 | +function protoCtrChain(o) { |
| 43 | + var result = []; |
| 44 | + for (; o; o = o.__proto__) { result.push(o.constructor); } |
| 45 | + return result.join(); |
| 46 | +} |
| 47 | + |
| 48 | +exports.indirectInstanceOf = function(obj, cls) { |
| 49 | + if (obj instanceof cls) { return true; } |
| 50 | + var clsChain = protoCtrChain(cls.prototype); |
| 51 | + var objChain = protoCtrChain(obj); |
| 52 | + return objChain.slice(-clsChain.length) === clsChain; |
| 53 | +}; |
| 54 | + |
| 55 | + |
| 56 | +exports.ddCommand = function(filename, kilobytes) { |
| 57 | + if (process.platform == 'win32') { |
| 58 | + return '"' + process.argv[0] + '" "' + path.resolve(exports.fixturesDir, |
| 59 | + 'create-file.js') + '" "' + filename + '" ' + (kilobytes * 1024); |
| 60 | + } else { |
| 61 | + return 'dd if=/dev/zero of="' + filename + '" bs=1024 count=' + kilobytes; |
| 62 | + } |
| 63 | +}; |
| 64 | + |
| 65 | + |
| 66 | +exports.spawnPwd = function(options) { |
| 67 | + var spawn = require('child_process').spawn; |
| 68 | + |
| 69 | + if (process.platform == 'win32') { |
| 70 | + return spawn('cmd.exe', ['/c', 'cd'], options); |
| 71 | + } else { |
| 72 | + return spawn('pwd', [], options); |
| 73 | + } |
| 74 | +}; |
| 75 | + |
| 76 | + |
| 77 | +// Turn this off if the test should not check for global leaks. |
| 78 | +exports.globalCheck = true; |
| 79 | + |
| 80 | +process.on('exit', function() { |
| 81 | + if (!exports.globalCheck) return; |
| 82 | + var knownGlobals = [setTimeout, |
| 83 | + setInterval, |
| 84 | + clearTimeout, |
| 85 | + clearInterval, |
| 86 | + console, |
| 87 | + Buffer, |
| 88 | + process, |
| 89 | + global]; |
| 90 | + |
| 91 | + if (global.errno) { |
| 92 | + knownGlobals.push(errno); |
| 93 | + } |
| 94 | + |
| 95 | + if (global.gc) { |
| 96 | + knownGlobals.push(gc); |
| 97 | + } |
| 98 | + |
| 99 | + if (global.DTRACE_HTTP_SERVER_RESPONSE) { |
| 100 | + knownGlobals.push(DTRACE_HTTP_SERVER_RESPONSE); |
| 101 | + knownGlobals.push(DTRACE_HTTP_SERVER_REQUEST); |
| 102 | + knownGlobals.push(DTRACE_HTTP_CLIENT_RESPONSE); |
| 103 | + knownGlobals.push(DTRACE_HTTP_CLIENT_REQUEST); |
| 104 | + knownGlobals.push(DTRACE_NET_STREAM_END); |
| 105 | + knownGlobals.push(DTRACE_NET_SERVER_CONNECTION); |
| 106 | + knownGlobals.push(DTRACE_NET_SOCKET_READ); |
| 107 | + knownGlobals.push(DTRACE_NET_SOCKET_WRITE); |
| 108 | + } |
| 109 | + |
| 110 | + 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 | + |
| 123 | + 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) { |
| 134 | + console.error('Unknown global: %s', x); |
| 135 | + assert.ok(false, 'Unknown global found'); |
| 136 | + } |
| 137 | + } |
| 138 | +}); |
| 139 | + |
| 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. |
| 143 | +exports.httpTest = function httpTest(cb) { |
| 144 | +}; |
| 145 | + |
0 commit comments