aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-02-05 13:33:20 -0800
committerAlon Zakai <alonzakai@gmail.com>2012-02-05 13:33:20 -0800
commitc161ef0fe82c320b367bc29cd1ba14cd9f90206e (patch)
treeada0a2ed3c1304d285a885684e293c7e9dab8c2d
parentb8a79ced1fa51e6feb772702057375b71344f5e5 (diff)
add preRun and postRun hooks in Module, and tweak FS initialization
-rw-r--r--src/library.js8
-rw-r--r--src/postamble.js8
-rwxr-xr-xtests/runner.py41
3 files changed, 27 insertions, 30 deletions
diff --git a/src/library.js b/src/library.js
index 8de71659..5587ca3e 100644
--- a/src/library.js
+++ b/src/library.js
@@ -26,8 +26,7 @@ LibraryManager.library = {
_impure_ptr: 0,
$FS__deps: ['$ERRNO_CODES', '__setErrNo', 'stdin', 'stdout', 'stderr', '_impure_ptr'],
- $FS__postset: '__ATINIT__.push({ func: function() { FS.ignorePermissions = false } });' +
- 'if (!FS.init.initialized) FS.init();' +
+ $FS__postset: '__ATINIT__.push({ func: function() { FS.ignorePermissions = false; if (!FS.init.initialized) FS.init() } });' +
'__ATEXIT__.push({ func: function() { FS.quit() } });',
$FS: {
// The path to the current folder.
@@ -343,7 +342,7 @@ LibraryManager.library = {
FS.createFolder('/', 'tmp', true, true);
// Create the I/O devices.
- var devFolder = FS.createFolder('/', 'dev', true, false);
+ var devFolder = FS.createFolder('/', 'dev', true, true);
var stdin = FS.createDevice(devFolder, 'stdin', input);
var stdout = FS.createDevice(devFolder, 'stdout', null, output);
var stderr = FS.createDevice(devFolder, 'stderr', null, error);
@@ -387,6 +386,9 @@ LibraryManager.library = {
_stdout = allocate([2], 'void*', ALLOC_STATIC);
_stderr = allocate([3], 'void*', ALLOC_STATIC);
+ // Other system paths
+ FS.createPath('/', 'dev/shm/tmp', true, true); // temp files
+
// Newlib initialization
FS.streams[_stdin] = FS.streams[1];
FS.streams[_stdout] = FS.streams[2];
diff --git a/src/postamble.js b/src/postamble.js
index ada13016..390f9f27 100644
--- a/src/postamble.js
+++ b/src/postamble.js
@@ -45,6 +45,10 @@ Module['run'] = run;
// {{PRE_RUN_ADDITIONS}}
+if (Module['preRun']) {
+ Module['preRun']();
+}
+
#if INVOKE_RUN
#else
Module['noInitialRun'] = true;
@@ -59,3 +63,7 @@ if (!Module['noInitialRun']) {
// {{POST_RUN_ADDITIONS}}
+if (Module['postRun']) {
+ Module['postRun']();
+}
+
diff --git a/tests/runner.py b/tests/runner.py
index aaa9cf69..fb3a1e05 100755
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -3362,18 +3362,19 @@ Pass: 0.000012 0.000012''')
Settings.CORRECT_SIGNS = 1 # Just so our output is what we expect. Can flip them both.
post = '''
def process(filename):
- src = open(filename, 'r').read().replace('FS.init();', '').replace( # Disable normal initialization, replace with ours
- '// {{PRE_RUN_ADDITIONS}}',
- \'\'\'
- FS.createDataFile('/', 'somefile.binary', [100, 200, 50, 25, 10, 77, 123], true, false); // 200 becomes -56, since signed chars are used in memory
- FS.createLazyFile('/', 'test.file', 'test.file', true, false);
- var test_files_input = 'hi there!';
- var test_files_input_index = 0;
- FS.init(function() {
- return test_files_input.charCodeAt(test_files_input_index++) || null;
- });
- \'\'\'
- )
+ src = \'\'\'
+ var Module = {
+ 'preRun': function() {
+ FS.createDataFile('/', 'somefile.binary', [100, 200, 50, 25, 10, 77, 123], true, false); // 200 becomes -56, since signed chars are used in memory
+ FS.createLazyFile('/', 'test.file', 'test.file', true, false);
+ var test_files_input = 'hi there!';
+ var test_files_input_index = 0;
+ FS.init(function() {
+ return test_files_input.charCodeAt(test_files_input_index++) || null;
+ });
+ }
+ };
+ \'\'\' + open(filename, 'r').read()
open(filename, 'w').write(src)
'''
other = open(os.path.join(self.get_dir(), 'test.file'), 'w')
@@ -4315,19 +4316,6 @@ def process(filename):
Settings.FAST_MEMORY = 4*1024*1024
Settings.EXPORTED_FUNCTIONS = ['_main', '_sqlite3_open', '_sqlite3_close', '_sqlite3_exec', '_sqlite3_free', '_callback'];
- Settings.INVOKE_RUN = 0 # We append code that does run() ourselves
-
- post = '''
-def process(filename):
- src = open(filename, 'a')
- src.write(\'\'\'
- FS.createPath('/', 'dev/shm/tmp', true, true);
- FS.currentPath = '/dev/shm/tmp';
- run();
- \'\'\')
- src.close()
-'''
-
self.do_run(r'''
#define SQLITE_DISABLE_LFS
#define LONGDOUBLE_TYPE double
@@ -4338,8 +4326,7 @@ def process(filename):
open(path_from_root('tests', 'sqlite', 'benchmark.txt'), 'r').read(),
includes=[path_from_root('tests', 'sqlite')],
force_c=True,
- js_engines=[SPIDERMONKEY_ENGINE], # V8 is slow
- post_build=post)#,build_ll_hook=self.do_autodebug)
+ js_engines=[SPIDERMONKEY_ENGINE]) # V8 is slow
def test_zlib(self):
if self.emcc_args is not None and '-O2' in self.emcc_args: