diff --git a/test/common.js b/test/common.js index 470f2f4688d598..5fb1e05a5f9c20 100644 --- a/test/common.js +++ b/test/common.js @@ -22,6 +22,8 @@ exports.isLinuxPPCBE = (process.platform === 'linux') && exports.isSunOS = process.platform === 'sunos'; exports.isFreeBSD = process.platform === 'freebsd'; +exports.enoughTestMem = os.totalmem() > 0x20000000; /* 512MB */ + function rimrafSync(p) { try { var st = fs.lstatSync(p); diff --git a/test/parallel/test-stringbytes-external-at-max.js b/test/parallel/test-stringbytes-external-at-max.js index 6678e5355224b3..31f476d66b18ba 100644 --- a/test/parallel/test-stringbytes-external-at-max.js +++ b/test/parallel/test-stringbytes-external-at-max.js @@ -1,22 +1,32 @@ 'use strict'; +// Flags: --expose-gc -require('../common'); +const common = require('../common'); const assert = require('assert'); // v8 fails silently if string length > v8::String::kMaxLength // v8::String::kMaxLength defined in v8.h const kStringMaxLength = process.binding('buffer').kStringMaxLength; +const skipMessage = + '1..0 # Skipped: intensive toString tests due to memory confinements'; +if (!common.enoughTestMem) { + console.log(skipMessage); + return; +} +assert(typeof gc === 'function', 'Run this test with --expose-gc'); + try { - new Buffer(kStringMaxLength * 3); + var buf = new Buffer(kStringMaxLength); + // Try to allocate memory first then force gc so future allocations succeed. + new Buffer(2 * kStringMaxLength); + gc(); } catch(e) { - assert.equal(e.message, 'Invalid array buffer length'); - console.log( - '1..0 # Skipped: intensive toString tests due to memory confinements'); + // If the exception is not due to memory confinement then rethrow it. + if (e.message !== 'Invalid array buffer length') throw (e); + console.log(skipMessage); return; } -const buf = new Buffer(kStringMaxLength); - const maxString = buf.toString('binary'); assert.equal(maxString.length, kStringMaxLength); diff --git a/test/parallel/test-stringbytes-external-exceed-max-by-1-ascii.js b/test/parallel/test-stringbytes-external-exceed-max-by-1-ascii.js index aab34e54486017..46590cd492fa14 100644 --- a/test/parallel/test-stringbytes-external-exceed-max-by-1-ascii.js +++ b/test/parallel/test-stringbytes-external-exceed-max-by-1-ascii.js @@ -1,23 +1,33 @@ 'use strict'; +// Flags: --expose-gc -require('../common'); +const common = require('../common'); const assert = require('assert'); +const skipMessage = + '1..0 # Skipped: intensive toString tests due to memory confinements'; +if (!common.enoughTestMem) { + console.log(skipMessage); + return; +} +assert(typeof gc === 'function', 'Run this test with --expose-gc'); + // v8 fails silently if string length > v8::String::kMaxLength // v8::String::kMaxLength defined in v8.h const kStringMaxLength = process.binding('buffer').kStringMaxLength; try { - new Buffer(kStringMaxLength * 3); + var buf = new Buffer(kStringMaxLength + 1); + // Try to allocate memory first then force gc so future allocations succeed. + new Buffer(2 * kStringMaxLength); + gc(); } catch(e) { - assert.equal(e.message, 'Invalid array buffer length'); - console.log( - '1..0 # Skipped: intensive toString tests due to memory confinements'); + // If the exception is not due to memory confinement then rethrow it. + if (e.message !== 'Invalid array buffer length') throw (e); + console.log(skipMessage); return; } -const buf = new Buffer(kStringMaxLength + 1); - assert.throws(function() { buf.toString('ascii'); }, /"toString\(\)" failed/); diff --git a/test/parallel/test-stringbytes-external-exceed-max-by-1-base64.js b/test/parallel/test-stringbytes-external-exceed-max-by-1-base64.js index 62e3a4c1d2103b..905f4ac9731796 100644 --- a/test/parallel/test-stringbytes-external-exceed-max-by-1-base64.js +++ b/test/parallel/test-stringbytes-external-exceed-max-by-1-base64.js @@ -1,23 +1,33 @@ 'use strict'; +// Flags: --expose-gc -require('../common'); +const common = require('../common'); const assert = require('assert'); +const skipMessage = + '1..0 # Skipped: intensive toString tests due to memory confinements'; +if (!common.enoughTestMem) { + console.log(skipMessage); + return; +} +assert(typeof gc === 'function', 'Run this test with --expose-gc'); + // v8 fails silently if string length > v8::String::kMaxLength // v8::String::kMaxLength defined in v8.h const kStringMaxLength = process.binding('buffer').kStringMaxLength; try { - new Buffer(kStringMaxLength * 3); + var buf = new Buffer(kStringMaxLength + 1); + // Try to allocate memory first then force gc so future allocations succeed. + new Buffer(2 * kStringMaxLength); + gc(); } catch(e) { - assert.equal(e.message, 'Invalid array buffer length'); - console.log( - '1..0 # Skipped: intensive toString tests due to memory confinements'); + // If the exception is not due to memory confinement then rethrow it. + if (e.message !== 'Invalid array buffer length') throw (e); + console.log(skipMessage); return; } -const buf = new Buffer(kStringMaxLength + 1); - assert.throws(function() { buf.toString('base64'); }, /"toString\(\)" failed/); diff --git a/test/parallel/test-stringbytes-external-exceed-max-by-1-binary.js b/test/parallel/test-stringbytes-external-exceed-max-by-1-binary.js index 2827150729e66e..9564af08de2752 100644 --- a/test/parallel/test-stringbytes-external-exceed-max-by-1-binary.js +++ b/test/parallel/test-stringbytes-external-exceed-max-by-1-binary.js @@ -1,23 +1,33 @@ 'use strict'; +// Flags: --expose-gc -require('../common'); +const common = require('../common'); const assert = require('assert'); +const skipMessage = + '1..0 # Skipped: intensive toString tests due to memory confinements'; +if (!common.enoughTestMem) { + console.log(skipMessage); + return; +} +assert(typeof gc === 'function', 'Run this test with --expose-gc'); + // v8 fails silently if string length > v8::String::kMaxLength // v8::String::kMaxLength defined in v8.h const kStringMaxLength = process.binding('buffer').kStringMaxLength; try { - new Buffer(kStringMaxLength * 3); + var buf = new Buffer(kStringMaxLength + 1); + // Try to allocate memory first then force gc so future allocations succeed. + new Buffer(2 * kStringMaxLength); + gc(); } catch(e) { - assert.equal(e.message, 'Invalid array buffer length'); - console.log( - '1..0 # Skipped: intensive toString tests due to memory confinements'); + // If the exception is not due to memory confinement then rethrow it. + if (e.message !== 'Invalid array buffer length') throw (e); + console.log(skipMessage); return; } -const buf = new Buffer(kStringMaxLength + 1); - assert.throws(function() { buf.toString('binary'); }, /"toString\(\)" failed/); diff --git a/test/parallel/test-stringbytes-external-exceed-max-by-1-hex.js b/test/parallel/test-stringbytes-external-exceed-max-by-1-hex.js index 08b76ce6bde2fb..1ca75403c243a7 100644 --- a/test/parallel/test-stringbytes-external-exceed-max-by-1-hex.js +++ b/test/parallel/test-stringbytes-external-exceed-max-by-1-hex.js @@ -1,23 +1,33 @@ 'use strict'; +// Flags: --expose-gc -require('../common'); +const common = require('../common'); const assert = require('assert'); +const skipMessage = + '1..0 # Skipped: intensive toString tests due to memory confinements'; +if (!common.enoughTestMem) { + console.log(skipMessage); + return; +} +assert(typeof gc === 'function', 'Run this test with --expose-gc'); + // v8 fails silently if string length > v8::String::kMaxLength // v8::String::kMaxLength defined in v8.h const kStringMaxLength = process.binding('buffer').kStringMaxLength; try { - new Buffer(kStringMaxLength * 3); + var buf = new Buffer(kStringMaxLength + 1); + // Try to allocate memory first then force gc so future allocations succeed. + new Buffer(2 * kStringMaxLength); + gc(); } catch(e) { - assert.equal(e.message, 'Invalid array buffer length'); - console.log( - '1..0 # Skipped: intensive toString tests due to memory confinements'); + // If the exception is not due to memory confinement then rethrow it. + if (e.message !== 'Invalid array buffer length') throw (e); + console.log(skipMessage); return; } -const buf = new Buffer(kStringMaxLength + 1); - assert.throws(function() { buf.toString('hex'); }, /"toString\(\)" failed/); diff --git a/test/parallel/test-stringbytes-external-exceed-max-by-1-utf8.js b/test/parallel/test-stringbytes-external-exceed-max-by-1-utf8.js index a566af0a942ea5..5e4bca5c9a56e8 100644 --- a/test/parallel/test-stringbytes-external-exceed-max-by-1-utf8.js +++ b/test/parallel/test-stringbytes-external-exceed-max-by-1-utf8.js @@ -1,23 +1,33 @@ 'use strict'; +// Flags: --expose-gc -require('../common'); +const common = require('../common'); const assert = require('assert'); +const skipMessage = + '1..0 # Skipped: intensive toString tests due to memory confinements'; +if (!common.enoughTestMem) { + console.log(skipMessage); + return; +} +assert(typeof gc === 'function', 'Run this test with --expose-gc'); + // v8 fails silently if string length > v8::String::kMaxLength // v8::String::kMaxLength defined in v8.h const kStringMaxLength = process.binding('buffer').kStringMaxLength; try { - new Buffer(kStringMaxLength * 3); + var buf = new Buffer(kStringMaxLength + 1); + // Try to allocate memory first then force gc so future allocations succeed. + new Buffer(2 * kStringMaxLength); + gc(); } catch(e) { - assert.equal(e.message, 'Invalid array buffer length'); - console.log( - '1..0 # Skipped: intensive toString tests due to memory confinements'); + // If the exception is not due to memory confinement then rethrow it. + if (e.message !== 'Invalid array buffer length') throw (e); + console.log(skipMessage); return; } -const buf = new Buffer(kStringMaxLength + 1); - assert.throws(function() { buf.toString(); }, /"toString\(\)" failed|Invalid array buffer length/); diff --git a/test/parallel/test-stringbytes-external-exceed-max-by-2.js b/test/parallel/test-stringbytes-external-exceed-max-by-2.js index 879e4ae91dfb60..8350c4532eafdc 100644 --- a/test/parallel/test-stringbytes-external-exceed-max-by-2.js +++ b/test/parallel/test-stringbytes-external-exceed-max-by-2.js @@ -1,22 +1,32 @@ 'use strict'; +// Flags: --expose-gc -require('../common'); +const common = require('../common'); const assert = require('assert'); +const skipMessage = + '1..0 # Skipped: intensive toString tests due to memory confinements'; +if (!common.enoughTestMem) { + console.log(skipMessage); + return; +} +assert(typeof gc === 'function', 'Run this test with --expose-gc'); + // v8 fails silently if string length > v8::String::kMaxLength // v8::String::kMaxLength defined in v8.h const kStringMaxLength = process.binding('buffer').kStringMaxLength; try { - new Buffer(kStringMaxLength * 3); + var buf = new Buffer(kStringMaxLength + 2); + // Try to allocate memory first then force gc so future allocations succeed. + new Buffer(2 * kStringMaxLength); + gc(); } catch(e) { - assert.equal(e.message, 'Invalid array buffer length'); - console.log( - '1..0 # Skipped: intensive toString tests due to memory confinements'); + // If the exception is not due to memory confinement then rethrow it. + if (e.message !== 'Invalid array buffer length') throw (e); + console.log(skipMessage); return; } -const buf2 = new Buffer(kStringMaxLength + 2); - -const maxString = buf2.toString('utf16le'); +const maxString = buf.toString('utf16le'); assert.equal(maxString.length, (kStringMaxLength + 2) / 2); diff --git a/test/parallel/test-stringbytes-external-exceed-max.js b/test/parallel/test-stringbytes-external-exceed-max.js index 4bec03699309fb..33bc2eaee7cb5c 100644 --- a/test/parallel/test-stringbytes-external-exceed-max.js +++ b/test/parallel/test-stringbytes-external-exceed-max.js @@ -1,23 +1,33 @@ 'use strict'; +// Flags: --expose-gc -require('../common'); +const common = require('../common'); const assert = require('assert'); +const skipMessage = + '1..0 # Skipped: intensive toString tests due to memory confinements'; +if (!common.enoughTestMem) { + console.log(skipMessage); + return; +} +assert(typeof gc === 'function', 'Run this test with --expose-gc'); + // v8 fails silently if string length > v8::String::kMaxLength // v8::String::kMaxLength defined in v8.h const kStringMaxLength = process.binding('buffer').kStringMaxLength; try { - new Buffer(kStringMaxLength * 3); + var buf = new Buffer(kStringMaxLength * 2 + 2); + // Try to allocate memory first then force gc so future allocations succeed. + new Buffer(2 * kStringMaxLength); + gc(); } catch(e) { - assert.equal(e.message, 'Invalid array buffer length'); - console.log( - '1..0 # Skipped: intensive toString tests due to memory confinements'); + // If the exception is not due to memory confinement then rethrow it. + if (e.message !== 'Invalid array buffer length') throw (e); + console.log(skipMessage); return; } -const buf0 = new Buffer(kStringMaxLength * 2 + 2); - assert.throws(function() { - buf0.toString('utf16le'); + buf.toString('utf16le'); }, /"toString\(\)" failed/);