diff --git a/README.markdown b/README.markdown index 71c114a97..3d9e170c6 100644 --- a/README.markdown +++ b/README.markdown @@ -191,3 +191,11 @@ following steps: * Run the WebGL demo in examples/webgl_demo and make sure it looks ok. + +TODO +==== + + * The HEAP memory space may not be implemented as a flat object in + all JS engines, especially when we use a lot of memory. Need to + investigate this. + diff --git a/test.py b/test.py index 8f85e245b..d67fc17df 100644 --- a/test.py +++ b/test.py @@ -9,8 +9,12 @@ exec(open(os.path.expanduser('~/.emscripten'), 'r').read()) +print +print '===================================' +print + def run(filename): - return Popen(SPIDERMONKEY_ENGINE + ['-e', 'load("' + build + '");load("' + os.path.join('tests', 'testutils.js') + '")', filename], stdout=PIPE).communicate()[0] + return Popen(SPIDERMONKEY_ENGINE + ['-e', 'gcparam("maxBytes", 1024*1024*1024); load("' + build + '"); load("' + os.path.join('tests', 'testutils.js') + '")', filename], stdout=PIPE).communicate()[0] __counter = 0 def stage(text): @@ -57,8 +61,11 @@ def stage(text): 5 : 11.75,-5.00,11.25 6 : 2.35,-5.61,0.12 total time:''' in output, output -print ' stress benchmark: ' + output.split('\n')[-2] +assert 'ok.' in output, output +print ' stress benchmark: ' + output.split('\n')[-3] +print +print '===================================' print print 'ok.' diff --git a/tests/stress.js b/tests/stress.js index 4efb31925..f53d2e153 100644 --- a/tests/stress.js +++ b/tests/stress.js @@ -1,7 +1,17 @@ // Stress test -function main() { +var readMemoryCeiling; +try { + STATICTOP; + readMemoryCeiling = function() { return STATICTOP + _sbrk.DATASIZE } +} catch(e) { + var mapping = getClosureMapping(); + var key = '0'; + for (k in eval(mapping['_sbrk'])) { key = k }; // hackish - relies on the order. TODO: fix + readMemoryCeiling = eval('(function() { return ' + mapping['STATICTOP'] + ' + ' + mapping['_sbrk'] + '.' + key + ' })'); +} +function benchmark() { var collisionConfiguration = new Ammo.btDefaultCollisionConfiguration(); var dispatcher = new Ammo.btCollisionDispatcher(collisionConfiguration); var overlappingPairCache = new Ammo.btDbvtBroadphase(); @@ -51,22 +61,15 @@ function main() { bodies.push(body); }); - // Make sure we do not allocate memory! - var readMemoryCeiling; - try { - STATICTOP; - readMemoryCeiling = function() { return STATICTOP } - } catch(e) { - var mapping = getClosureMapping(); - readMemoryCeiling = eval('(function() { return ' + mapping['STATICTOP'] + ' })'); - } - var memoryStart = readMemoryCeiling(); + var memoryStart; var trans = new Ammo.btTransform(); // taking this out of the loop below us reduces the leaking var startTime = Date.now(); for (var i = 0; i < 450; i++) { + if (i === 250) memoryStart = readMemoryCeiling(); + dynamicsWorld.stepSimulation(1/60, 10); bodies.forEach(function(body, i) { @@ -84,5 +87,24 @@ function main() { print('total time: ' + ((endTime-startTime)/1000).toFixed(3)); } -main(); +function testDestroy() { + var NUM = 1000; // enough to force an increase in the memory ceiling + var vec = new Ammo.btVector3(4, 5, 6); + var memoryStart = readMemoryCeiling(); + for (var i = 0; i < NUM; i++) { + destroy(vec); + vec = new Ammo.btVector3(4, 5, 6); + } + destroy(vec); + assertEq(readMemoryCeiling(), memoryStart, 'Memory ceiling must remain stable!'); + for (var i = 0; i < NUM; i++) { + vec = new Ammo.btVector3(4, 5, 6); + } + assertNeq(readMemoryCeiling(), memoryStart, 'Memory ceiling must increase without destroy()!'); +} + +benchmark(); +testDestroy(); + +print('ok.') diff --git a/tests/testutils.js b/tests/testutils.js index eabd0ebbe..1e922681c 100644 --- a/tests/testutils.js +++ b/tests/testutils.js @@ -8,6 +8,14 @@ function assertEq(x, y, msg) { assert(x === y, (msg ? msg + ' : ' : '') + x + ' should be equal to ' + y + '.'); } +function assertNeq(x, y, msg) { + assert(x !== y, (msg ? msg + ' : ' : '') + x + ' should not be equal to ' + y + '.'); +} + +function assertLeq(x, y, msg) { + assert(x < y, (msg ? msg + ' : ' : '') + x + ' should be less than to ' + y + '.'); +} + function getClosureMapping() { var raw = read('../builds/ammo.vars'); var ret = {};