diff options
-rw-r--r-- | src/headless.js (renamed from tools/reproduceriter_shell.js) | 14 | ||||
-rw-r--r-- | src/jsifier.js | 5 | ||||
-rw-r--r-- | src/settings.js | 8 | ||||
-rwxr-xr-x | tests/runner.py | 12 | ||||
-rw-r--r-- | tests/sdl_canvas.c | 2 | ||||
-rwxr-xr-x | tools/reproduceriter.py | 2 |
6 files changed, 42 insertions, 1 deletions
diff --git a/tools/reproduceriter_shell.js b/src/headless.js index f425df82..a528e8af 100644 --- a/tools/reproduceriter_shell.js +++ b/src/headless.js @@ -1,4 +1,6 @@ +//== HEADLESS ==// + var window = { location: { toString: function() { @@ -666,6 +668,11 @@ var document = { data: new Uint8ClampedArray(w*h), }; }, + save: function(){}, + restore: function(){}, + fillRect: function(){}, + measureText: function() { return 10 }, + fillText: function(){}, }; } default: throw 'canvas.getContext: ' + which; @@ -869,3 +876,10 @@ var MozBlobBuilder = function() { }; }; +// additional setup +if (!Module['canvas']) { + Module['canvas'] = document.getElementById('canvas'); +} + +//== HEADLESS ==// + diff --git a/src/jsifier.js b/src/jsifier.js index feb7b74d..fae92f70 100644 --- a/src/jsifier.js +++ b/src/jsifier.js @@ -1294,6 +1294,11 @@ function JSify(data, functionsOnly, givenFunctions) { print('// Warning: printing of i64 values may be slightly rounded! No deep i64 math used, so precise i64 code not included'); print('var i64Math = null;'); } + if (HEADLESS) { + print('if (!ENVIRONMENT_IS_WEB) {'); + print(read('headless.js').replace("'%s'", "'http://emscripten.org'").replace("'?%s'", "''").replace('%s,', 'null,').replace('%d', '0')); + print('}'); + } var generated = itemsDict.functionStub.concat(itemsDict.GlobalVariablePostSet); generated.forEach(function(item) { print(indentify(item.JS || '', 2)); }); if (RUNTIME_TYPE_INFO) { diff --git a/src/settings.js b/src/settings.js index 5d4299a4..58635950 100644 --- a/src/settings.js +++ b/src/settings.js @@ -277,6 +277,14 @@ var SMALL_XHR_CHUNKS = 0; // Use small chunk size for binary synchronous XHR's i // Used for testing. // See test_chunked_synchronous_xhr in runner.py and library.js. +var HEADLESS = 0; // If 1, will include shim code that tries to 'fake' a browser + // environment, in order to let you run a browser program (say, + // using SDL) in the shell. Obviously nothing is rendered, but + // this can be useful for benchmarking and debugging if actual + // rendering is not the issue. Note that the shim code is + // very partial - it is hard to fake a whole browser! - so + // keep your expectations low for this to work. + var NECESSARY_BLOCKADDRS = []; // List of (function, block) for all block addresses that are taken. // Compiler debugging options diff --git a/tests/runner.py b/tests/runner.py index 7fc2f284..62e1b7e1 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -8323,6 +8323,18 @@ fscanfed: 10 - hello Popen(['python', FILE_PACKAGER, 'test.data', '--pre-run', '--crunch=32', '--preload', 'ship.dds'], stdout=open('pre.js', 'w')).communicate() assert crunch_time < os.stat('ship.crn').st_mtime, 'Crunch was changed' + def test_headless(self): + shutil.copyfile(path_from_root('tests', 'screenshot.png'), os.path.join(self.get_dir(), 'example.png')) + Popen(['python', EMCC, path_from_root('tests', 'sdl_canvas.c'), '-s', 'HEADLESS=1']).communicate() + output = run_js('a.out.js', engine=SPIDERMONKEY_ENGINE, stderr=PIPE) + assert '''Init: 0 +Font: 0x1 +Sum: 0 +you should see two lines of text in different colors and a blue rectangle +SDL_Quit called (and ignored) +done. +''' in output, output + elif 'browser' in str(sys.argv): # Browser tests. diff --git a/tests/sdl_canvas.c b/tests/sdl_canvas.c index 5d1c849c..7dcfa043 100644 --- a/tests/sdl_canvas.c +++ b/tests/sdl_canvas.c @@ -53,6 +53,8 @@ int main(int argc, char **argv) { SDL_Quit(); + printf("done.\n"); + int result = sum > 3000 && sum < 5000; // varies a little on different browsers, font differences? REPORT_RESULT(); diff --git a/tools/reproduceriter.py b/tools/reproduceriter.py index a1912396..058eeecf 100755 --- a/tools/reproduceriter.py +++ b/tools/reproduceriter.py @@ -149,7 +149,7 @@ for parent, dirs, files in os.walk(out_dir): print 'add boilerplate...' open(os.path.join(out_dir, first_js), 'w').write( - (open(os.path.join(os.path.dirname(__file__), 'reproduceriter_shell.js')).read() % ( + (open(os.path.join(os.path.dirname(os.path.dirname(__file__)), 'src', 'headless.js')).read() % ( window_location, window_location.split('?')[-1], on_idle or 'null', dirs_to_drop ) if shell else '') + open(os.path.join(os.path.dirname(__file__), 'reproduceriter.js')).read() + |