Skip to content

Commit

Permalink
additional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kripken committed Aug 17, 2011
1 parent cc73d75 commit 9ab6900
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 14 deletions.
8 changes: 8 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.

11 changes: 9 additions & 2 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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.'

46 changes: 34 additions & 12 deletions tests/stress.js
Original file line number Diff line number Diff line change
@@ -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();
Expand Down Expand Up @@ -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) {
Expand All @@ -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.')

8 changes: 8 additions & 0 deletions tests/testutils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand Down

0 comments on commit 9ab6900

Please sign in to comment.