A basic test script for sqlite3-api.js. This file must be run in
main JS thread and sqlite3.js must have been loaded before it.
*/
-'use strict';
-//importScripts('jswasm/sqlite3-wasmfs.js');
-//importScripts('common/SqliteTestUtil.js');
import sqlite3InitModule from './jswasm/sqlite3-wasmfs.mjs';
//console.log('sqlite3InitModule =',sqlite3InitModule);
-(function(){
- const toss = function(...args){throw new Error(args.join(' '))};
- const log = console.log.bind(console),
- warn = console.warn.bind(console),
- error = console.error.bind(console);
+const toss = function(...args){throw new Error(args.join(' '))};
+const log = console.log.bind(console),
+ warn = console.warn.bind(console),
+ error = console.error.bind(console);
- const stdout = log;
- const stderr = error;
+const stdout = log;
+const stderr = error;
- const test1 = function(db){
- db.exec("create table if not exists t(a);")
- .transaction(function(db){
- db.prepare("insert into t(a) values(?)")
- .bind(new Date().getTime())
- .stepFinalize();
- stdout("Number of values in table t:",
- db.selectValue("select count(*) from t"));
- });
- };
+const test1 = function(db){
+ db.exec("create table if not exists t(a);")
+ .transaction(function(db){
+ db.prepare("insert into t(a) values(?)")
+ .bind(new Date().getTime())
+ .stepFinalize();
+ stdout("Number of values in table t:",
+ db.selectValue("select count(*) from t"));
+ });
+};
- const runTests = function(sqlite3){
- const capi = sqlite3.capi,
- oo = sqlite3.oo1,
- wasm = sqlite3.wasm;
- stdout("Loaded module:",sqlite3);
- stdout("Loaded sqlite3:",capi.sqlite3_libversion(), capi.sqlite3_sourceid());
- const persistentDir = capi.sqlite3_wasmfs_opfs_dir();
- if(persistentDir){
- stdout("Persistent storage dir:",persistentDir);
- }else{
- stderr("No persistent storage available.");
- }
- const startTime = performance.now();
- let db;
- try {
- db = new oo.DB(persistentDir+'/foo.db');
- stdout("DB filename:",db.filename);
- const banner1 = '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>',
- banner2 = '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<';
- [
- test1
- ].forEach((f)=>{
- const n = performance.now();
- stdout(banner1,"Running",f.name+"()...");
- f(db, sqlite3);
- stdout(banner2,f.name+"() took ",(performance.now() - n),"ms");
- });
- }finally{
- if(db) db.close();
- }
- stdout("Total test time:",(performance.now() - startTime),"ms");
- };
+const runTests = function(sqlite3){
+ const capi = sqlite3.capi,
+ oo = sqlite3.oo1,
+ wasm = sqlite3.wasm;
+ stdout("Loaded module:",sqlite3);
+ stdout("Loaded sqlite3:",capi.sqlite3_libversion(), capi.sqlite3_sourceid());
+ const persistentDir = capi.sqlite3_wasmfs_opfs_dir();
+ if(persistentDir){
+ stdout("Persistent storage dir:",persistentDir);
+ }else{
+ stderr("No persistent storage available.");
+ }
+ const startTime = performance.now();
+ let db;
+ try {
+ db = new oo.DB(persistentDir+'/foo.db');
+ stdout("DB filename:",db.filename);
+ const banner1 = '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>',
+ banner2 = '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<';
+ [
+ test1
+ ].forEach((f)=>{
+ const n = performance.now();
+ stdout(banner1,"Running",f.name+"()...");
+ f(db, sqlite3);
+ stdout(banner2,f.name+"() took ",(performance.now() - n),"ms");
+ });
+ }finally{
+ if(db) db.close();
+ }
+ stdout("Total test time:",(performance.now() - startTime),"ms");
+};
- sqlite3InitModule().then(runTests);
-})();
+sqlite3InitModule().then(runTests);
<header id='titlebar'><span>speedtest1-wasmfs.wasm</span></header>
<div>See also: <a href='speedtest1-worker.html'>A Worker-thread variant of this page.</a></div>
<!-- emscripten bits -->
- <figure id="module-spinner">
- <div class="spinner"></div>
- <div class='center'><strong>Initializing app...</strong></div>
- <div class='center'>
- On a slow internet connection this may take a moment. If this
- message displays for "a long time", intialization may have
- failed and the JavaScript console may contain clues as to why.
- </div>
- </figure>
- <div class="emscripten" id="module-status">Downloading...</div>
- <div class="emscripten">
- <progress value="0" max="100" id="module-progress" hidden='1'></progress>
- </div><!-- /emscripten bits -->
- <div class='warning'>This page starts running the main exe when it loads, which will
- block the UI until it finishes! Adding UI controls to manually configure and start it
- are TODO.</div>
- </div>
<div class='warning'>Achtung: running it with the dev tools open may
<em>drastically</em> slow it down. For faster results, keep the dev
tools closed when running it!
</div>
- <div>Output is delayed/buffered because we cannot update the UI while the
- speedtest is running. Output will appear below when ready...
<div id='test-output'></div>
- <script src="common/SqliteTestUtil.js"></script>
- <script src="speedtest1-wasmfs.js"></script>
- <script>(function(){
- /**
- If this environment contains OPFS, this function initializes it and
- returns the name of the dir on which OPFS is mounted, else it returns
- an empty string.
- */
- const wasmfsDir = function f(wasmUtil,dirName="/opfs"){
- if(undefined !== f._) return f._;
- if( !self.FileSystemHandle
- || !self.FileSystemDirectoryHandle
- || !self.FileSystemFileHandle){
- return f._ = "";
- }
- try{
- if(0===wasmUtil.xCallWrapped(
- 'sqlite3_wasm_init_wasmfs', 'i32', ['string'], dirName
- )){
- return f._ = dirName;
- }else{
- return f._ = "";
- }
- }catch(e){
- // sqlite3_wasm_init_wasmfs() is not available
- return f._ = "";
- }
- };
- wasmfsDir._ = undefined;
-
- const eOut = document.querySelector('#test-output');
- const log2 = function(cssClass,...args){
- const ln = document.createElement('div');
- if(cssClass) ln.classList.add(cssClass);
- ln.append(document.createTextNode(args.join(' ')));
- eOut.append(ln);
- //this.e.output.lastElementChild.scrollIntoViewIfNeeded();
- };
- const logList = [];
- const dumpLogList = function(){
- logList.forEach((v)=>log2('',v));
- logList.length = 0;
- };
- /* can't update DOM while speedtest is running unless we run
- speedtest in a worker thread. */;
- const log = (...args)=>{
- console.log(...args);
- logList.push(args.join(' '));
- };
- const logErr = function(...args){
- console.error(...args);
- logList.push('ERROR: '+args.join(' '));
- };
-
- const runTests = function(sqlite3){
- console.log("Module inited.",sqlite3);
- const wasm = sqlite3.wasm;
- const __unlink = wasm.xWrap("sqlite3_wasm_vfs_unlink", "int", ["*","string"]);
- const unlink = (fn)=>__unlink(0,fn);
- const pDir = wasmfsDir(wasm);
- if(pDir) log2('',"Persistent storage:",pDir);
- else{
- log2('error',"Expecting persistent storage in this build.");
- return;
- }
- const scope = wasm.scopedAllocPush();
- const dbFile = pDir+"/speedtest1.db";
- const urlParams = new URL(self.location.href).searchParams;
- const argv = ["speedtest1"];
- if(urlParams.has('flags')){
- argv.push(...(urlParams.get('flags').split(',')));
- let i = argv.indexOf('--vfs');
- if(i>=0) argv.splice(i,2);
- }else{
- argv.push(
- "--singlethread",
- "--nomutex",
- "--nosync",
- "--nomemstat"
- );
- //"--memdb", // note that memdb trumps the filename arg
- }
-
- if(argv.indexOf('--memdb')>=0){
- log2('error',"WARNING: --memdb flag trumps db filename.");
- }
- argv.push("--big-transactions"/*important for tests 410 and 510!*/,
- dbFile);
- console.log("argv =",argv);
- // These log messages are not emitted to the UI until after main() returns. Fixing that
- // requires moving the main() call and related cleanup into a timeout handler.
- if(pDir) unlink(dbFile);
- log2('',"Starting native app:\n ",argv.join(' '));
- log2('',"This will take a while and the browser might warn about the runaway JS.",
- "Give it time...");
- logList.length = 0;
- setTimeout(function(){
- wasm.xCall('wasm_main', argv.length,
- wasm.scopedAllocMainArgv(argv));
- wasm.scopedAllocPop(scope);
- if(pDir) unlink(dbFile);
- logList.unshift("Done running native main(). Output:");
- dumpLogList();
- }, 25);
- }/*runTests()*/;
-
- self.sqlite3TestModule.print = log;
- self.sqlite3TestModule.printErr = logErr;
- sqlite3InitModule(self.sqlite3TestModule).then(runTests);
-})();</script>
+ <script>
+ (function(){
+ const eOut = document.querySelector('#test-output');
+ const log2 = function(cssClass,...args){
+ const ln = document.createElement('div');
+ if(cssClass) ln.classList.add(cssClass);
+ ln.append(document.createTextNode(args.join(' ')));
+ eOut.append(ln);
+ //this.e.output.lastElementChild.scrollIntoViewIfNeeded();
+ };
+ /* can't update DOM while speedtest is running unless we run
+ speedtest in a worker thread. */;
+ const log = (...args)=>{
+ console.log(...args);
+ log2('',...args);
+ };
+ const logErr = function(...args){
+ console.error(...args);
+ log2('error',...args);
+ };
+ const W = new Worker('speedtest1-wasmfs.mjs',{
+ type: 'module'
+ });
+ log("Starting up...");
+ W.onmessage = function({data}){
+ switch(data.type){
+ case 'log': log(...data.args); break;
+ case 'logErr': logErr(...data.args); break;
+ default:
+ break;
+ }
+ };
+ })();
+ </script>
</body>
</html>
--- /dev/null
+import sqlite3InitModule from './jswasm/speedtest1-wasmfs.mjs';
+const wMsg = (type,...args)=>{
+ console.log("wMsg(",type,...args,")");
+ postMessage({type, args});
+};
+wMsg('log',"speedtest1-wasmfs starting...");
+/**
+ If this environment contains OPFS, this function initializes it and
+ returns the name of the dir on which OPFS is mounted, else it returns
+ an empty string.
+*/
+const wasmfsDir = function f(wasmUtil,dirName="/opfs"){
+ if(undefined !== f._) return f._;
+ if( !self.FileSystemHandle
+ || !self.FileSystemDirectoryHandle
+ || !self.FileSystemFileHandle){
+ return f._ = "";
+ }
+ try{
+ if(0===wasmUtil.xCallWrapped(
+ 'sqlite3_wasm_init_wasmfs', 'i32', ['string'], dirName
+ )){
+ return f._ = dirName;
+ }else{
+ return f._ = "";
+ }
+ }catch(e){
+ // sqlite3_wasm_init_wasmfs() is not available
+ return f._ = "";
+ }
+};
+wasmfsDir._ = undefined;
+
+const log = (...args)=>wMsg('log',...args);
+const logErr = (...args)=>wMsg('logErr',...args);
+
+const runTests = function(sqlite3){
+ console.log("Module inited.",sqlite3);
+ const wasm = sqlite3.wasm;
+ const __unlink = wasm.xWrap("sqlite3_wasm_vfs_unlink", "int", ["*","string"]);
+ const unlink = (fn)=>__unlink(0,fn);
+ const pDir = wasmfsDir(wasm);
+ if(pDir) log("Persistent storage:",pDir);
+ else{
+ logErr("Expecting persistent storage in this build.");
+ return;
+ }
+ const scope = wasm.scopedAllocPush();
+ const dbFile = pDir+"/speedtest1.db";
+ const urlParams = new URL(self.location.href).searchParams;
+ const argv = ["speedtest1"];
+ if(urlParams.has('flags')){
+ argv.push(...(urlParams.get('flags').split(',')));
+ let i = argv.indexOf('--vfs');
+ if(i>=0) argv.splice(i,2);
+ }else{
+ argv.push(
+ "--singlethread",
+ "--nomutex",
+ //"--nosync",
+ "--nomemstat",
+ "--size", "10"
+ );
+ }
+
+ if(argv.indexOf('--memdb')>=0){
+ logErr("WARNING: --memdb flag trumps db filename.");
+ }
+ argv.push("--big-transactions"/*important for tests 410 and 510!*/,
+ dbFile);
+ //log("argv =",argv);
+ // These log messages are not emitted to the UI until after main() returns. Fixing that
+ // requires moving the main() call and related cleanup into a timeout handler.
+ if(pDir) unlink(dbFile);
+ log("Starting native app:\n ",argv.join(' '));
+ log("This will take a while and the browser might warn about the runaway JS.",
+ "Give it time...");
+ setTimeout(function(){
+ if(pDir) unlink(dbFile);
+ wasm.xCall('wasm_main', argv.length,
+ wasm.scopedAllocMainArgv(argv));
+ wasm.scopedAllocPop(scope);
+ //if(pDir) unlink(dbFile);
+ log("Done running native main()");
+ }, 25);
+}/*runTests()*/;
+
+sqlite3InitModule({
+ print: log,
+ printErr: logErr
+}).then(runTests);
########################################################################
# emcc flags specific to building the final .js/.wasm file...
emcc.flags.sqlite3-wasmfs :=
-emcc.flags.sqlite3-wasmfs += -sEXPORTED_RUNTIME_METHODS=wasmMemory,allocateUTF8OnStack
+emcc.flags.sqlite3-wasmfs += \
+ -sEXPORTED_RUNTIME_METHODS=wasmMemory,allocateUTF8OnStack,stringToUTF8OnStack
# wasmMemory ==> for -sIMPORTED_MEMORY
- # allocateUTF8OnStack ==> wasmfs internals
+ # *OnStack ==> wasmfs internals (leaky abstraction)
emcc.flags.sqlite3-wasmfs += -sUSE_CLOSURE_COMPILER=0
emcc.flags.sqlite3-wasmfs += -Wno-limited-postlink-optimizations
# ^^^^^ it likes to warn when we have "limited optimizations" via the -g3 flag.
$(c-pp.D.sqlite3-bundler-friendly) -Dwasmfs,\
-sEXPORT_ES6 -sUSE_ES6_IMPORT_META\
))
-#$(eval $(call call-make-pre-post,sqlite3-wasmfs,vanilla))
$(sqlite3-wasmfs.js) $(sqlite3-wasmfs.mjs): $(MAKEFILE.wasmfs)
-#$(sqlite3-wasmfs.js): $(pre-post-sqlite3-wasmfs.deps.vanilla)
-#$(sqlite3-wasmfs.mjs): $(pre-post-sqlite3-wasmfs.deps.esm)
########################################################################
# Build quirk: we cannot build BOTH .js and .mjs with our current
# build infrastructure because the supplemental *.worker.js files get
########################################################################
# speedtest1 for wasmfs.
-speedtest1-wasmfs.js := $(dir.wasmfs)/speedtest1-wasmfs.js
-speedtest1-wasmfs.wasm := $(subst .js,.wasm,$(speedtest1-wasmfs.js))
+speedtest1-wasmfs.mjs := $(dir.wasmfs)/speedtest1-wasmfs.mjs
+speedtest1-wasmfs.wasm := $(subst .mjs,.wasm,$(speedtest1-wasmfs.mjs))
emcc.flags.speedtest1-wasmfs := $(sqlite3-wasmfs.fsflags)
-emcc.flags.speedtest1-wasmfs += $(SQLITE_OPT) -DSQLITE_ENABLE_WASMFS
+emcc.flags.speedtest1-wasmfs += $(SQLITE_OPT)
emcc.flags.speedtest1-wasmfs += -sALLOW_MEMORY_GROWTH=0
emcc.flags.speedtest1-wasmfs += -sINITIAL_MEMORY=$(emcc.INITIAL_MEMORY.128)
-#$(eval $(call call-make-pre-js,speedtest1-wasmfs,vanilla))
-$(speedtest1-wasmfs.js): $(speedtest1.cses) $(sqlite3-wasmfs.js) \
+#$(eval $(call call-make-pre-js,speedtest1-wasmfs,ems))
+$(speedtest1-wasmfs.mjs): $(speedtest1.cfiles) $(sqlite3-wasmfs.js) \
$(MAKEFILE) $(MAKEFILE.wasmfs) \
- $(pre-post-sqlite3-wasmfs.deps) \
+ $(pre-post-sqlite3-wasmfs-esm.deps) \
$(EXPORTED_FUNCTIONS.speedtest1)
@echo "Building $@ ..."
$(emcc.bin) \
- $(emcc.speedtest1.common) $(emcc.flags.speedtest1-wasmfs) \
- $(pre-post-sqlite3-wasmfs.flags.vanilla) \
+ $(pre-post-sqlite3-wasmfs-esm.flags) \
+ $(cflags.common) \
$(cflags.sqlite3-wasmfs) \
- -o $@ $(speedtest1.cses) -lm
+ $(emcc.speedtest1.common) \
+ $(emcc.flags.speedtest1-vanilla) \
+ $(emcc.flags.sqlite3-wasmfs) \
+ $(emcc.flags.speedtest1-wasmfs) \
+ -o $@ $(speedtest1.cfiles) -lm
+ @$(call SQLITE3.xJS.ESM-EXPORT-DEFAULT,1)
$(maybe-wasm-strip) $(speedtest1-wasmfs.wasm)
ls -la $@ $(speedtest1-wasmfs.wasm)
-#wasmfs: $(speedtest1-wasmfs.js)
-CLEAN_FILES += $(speedtest1-wasmfs.js) $(speedtest1-wasmfs.wasm) \
- $(subst .js,.worker.js,$(speedtest1-wasmfs.js))
+wasmfs: $(speedtest1-wasmfs.mjs)
+CLEAN_FILES += $(speedtest1-wasmfs.mjs) $(speedtest1-wasmfs.wasm) \
+ $(subst .js,.worker.js,$(speedtest1-wasmfs.mjs))
# end speedtest1.js
########################################################################
-C Significant\ssurgery\son\sthe\swasm\sbuild\son\sthe\sway\sto\sincorporating\swasmfs\sas\sa\sfirst-class\sbuild\soption.
-D 2023-07-13T14:08:30.624
+C Get\sspeedtest1\swasmfs\svariant\srunning\sagain.
+D 2023-07-13T16:33:45.070
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
F ext/wasm/jaccwabyt/jaccwabyt.md 37911f00db12cbcca73aa1ed72594430365f30aafae2fa9c886961de74e5e0eb
F ext/wasm/module-symbols.html 841de62fc198988b8330e238c260e70ec93028b096e1a1234db31b187a899d10
F ext/wasm/scratchpad-wasmfs-main.html bf23812d059da37399b34e27d6b4c5980e2e1fb2153e5d3318d39b41aa854c32
-F ext/wasm/scratchpad-wasmfs-main.js 97f8eff738871030b98b75166b75555ce140605c791143dace93058643275137
-F ext/wasm/speedtest1-wasmfs.html 3493c46b24bad00e9f6ebe14804143ae67a880f6c59c16ee13bf5f06e7dc4313
+F ext/wasm/scratchpad-wasmfs-main.js 66034b9256b218de59248aad796760a1584c1dd842231505895eff00dbd57c63
+F ext/wasm/speedtest1-wasmfs.html ce92a78f745e4fb837742624300a733046150507b1cac5c1aca81f396a8f46db
+F ext/wasm/speedtest1-wasmfs.mjs 934417fea36e7c8b41bad24fe5550aa2903140e2c2195d876215d6c902961cd2
F ext/wasm/speedtest1-worker.html 97c2bf5f8534091ce718de05801090d5a80c3f13575996f095ba23638e1bdca0
F ext/wasm/speedtest1-worker.js 13b57c4a41729678a1194014afec2bd5b94435dcfc8d1039dfa9a533ac819ee1
F ext/wasm/speedtest1.html ff048b4a623aa192e83e143e48f1ce2a899846dd42c023fdedc8772b6e3f07da
F ext/wasm/tests/opfs/concurrency/test.js a98016113eaf71e81ddbf71655aa29b0fed9a8b79a3cdd3620d1658eb1cc9a5d
F ext/wasm/tests/opfs/concurrency/worker.js 0a8c1a3e6ebb38aabbee24f122693f1fb29d599948915c76906681bb7da1d3d2
F ext/wasm/version-info.c 3b36468a90faf1bbd59c65fd0eb66522d9f941eedd364fabccd72273503ae7d5
-F ext/wasm/wasmfs.make 6cfe6cb04859ca7aa611f71f6e770811d023a519a7fb4cc4de1419189594c2a8
+F ext/wasm/wasmfs.make 889be53a3d0f6bb0d270e25c4fb29f679b8d764c7fe864217180e61537cb9ac0
F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x
F ltmain.sh 3ff0879076df340d2e23ae905484d8c15d5fdea8
F magic.txt 5ade0bc977aa135e79e3faaea894d5671b26107cc91e70783aa7dc83f22f3ba0
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P 4850a9e2d2b41b91e91b9ef99a6d26ddf11a161b4c970fc00d2d095606729a04
-R 68d56fe3eae005ed95f6c7df371b3baf
+P 215c37fce38cf647e073480689b79d952af7eb8165ae08c7f5caed27003fecfc
+R 65bf4d4d1cc787c57405349531ba9382
U stephan
-Z a358a57a699b604bd4cd582e774f0d4e
+Z 63407a73d630f95e1718b20fb63b6e0d
# Remove this line to create a well-formed Fossil manifest.
-215c37fce38cf647e073480689b79d952af7eb8165ae08c7f5caed27003fecfc
\ No newline at end of file
+0f77e031daf0121f7603409cedf57f138edbb43083cbbcf00d2a423e16de25a7
\ No newline at end of file