5 <meta http-equiv=
"Content-Type" content=
"text/html; charset=utf-8">
6 <link rel=
"shortcut icon" href=
"data:image/x-icon;," type=
"image/x-icon">
7 <link rel=
"stylesheet" href=
"common/emscripten.css"/>
8 <link rel=
"stylesheet" href=
"common/testing.css"/>
9 <title>speedtest1-wasmfs.wasm
</title>
12 <header id='titlebar'
><span>speedtest1-wasmfs.wasm
</span></header>
13 <div>See also:
<a href='speedtest1-worker.html'
>A Worker-thread variant of this page.
</a></div>
14 <!-- emscripten bits -->
15 <figure id=
"module-spinner">
16 <div class=
"spinner"></div>
17 <div class='center'
><strong>Initializing app...
</strong></div>
19 On a slow internet connection this may take a moment. If this
20 message displays for
"a long time", intialization may have
21 failed and the JavaScript console may contain clues as to why.
24 <div class=
"emscripten" id=
"module-status">Downloading...
</div>
25 <div class=
"emscripten">
26 <progress value=
"0" max=
"100" id=
"module-progress" hidden='
1'
></progress>
27 </div><!-- /emscripten bits -->
28 <div class='warning'
>This page starts running the main exe when it loads, which will
29 block the UI until it finishes! Adding UI controls to manually configure and start it
32 <div class='warning'
>Achtung: running it with the dev tools open may
33 <em>drastically
</em> slow it down. For faster results, keep the dev
34 tools closed when running it!
36 <div>Output is delayed/buffered because we cannot update the UI while the
37 speedtest is running. Output will appear below when ready...
38 <div id='test-output'
></div>
39 <script src=
"common/SqliteTestUtil.js"></script>
40 <script src=
"speedtest1-wasmfs.js"></script>
43 If this environment contains OPFS, this function initializes it and
44 returns the name of the dir on which OPFS is mounted, else it returns
47 const wasmfsDir
= function f(wasmUtil
,dirName
="/opfs"){
48 if(undefined !== f
._
) return f
._
;
49 if( !self
.FileSystemHandle
50 || !self
.FileSystemDirectoryHandle
51 || !self
.FileSystemFileHandle
){
55 if(0===wasmUtil
.xCallWrapped(
56 'sqlite3_wasm_init_wasmfs', 'i32', ['string'], dirName
63 // sqlite3_wasm_init_wasmfs() is not available
67 wasmfsDir
._
= undefined;
69 const eOut
= document
.querySelector('#test-output');
70 const log2 = function(cssClass
,...args
){
71 const ln
= document
.createElement('div');
72 if(cssClass
) ln
.classList
.add(cssClass
);
73 ln
.append(document
.createTextNode(args
.join(' ')));
75 //this.e.output.lastElementChild.scrollIntoViewIfNeeded();
78 const dumpLogList = function(){
79 logList
.forEach((v
)=>log2('',v
));
82 /* can't update DOM while speedtest is running unless we run
83 speedtest in a worker thread. */;
84 const log
= (...args
)=>{
86 logList
.push(args
.join(' '));
88 const logErr = function(...args
){
89 console
.error(...args
);
90 logList
.push('ERROR: '+args
.join(' '));
93 const runTests = function(sqlite3
){
94 console
.log("Module inited.");
95 const wasm
= sqlite3
.capi
.wasm
;
96 const unlink
= wasm
.xWrap("sqlite3_wasm_vfs_unlink", "int", ["string"]);
97 const pDir
= wasmfsDir(wasm
);
98 if(pDir
) log2('',"Persistent storage:",pDir
);
100 log2('error',"Expecting persistent storage in this build.");
103 const scope
= wasm
.scopedAllocPush();
104 const dbFile
= pDir
+"/speedtest1.db";
105 const urlParams
= new URL(self
.location
.href
).searchParams
;
106 const argv
= ["speedtest1"];
107 if(urlParams
.has('flags')){
108 argv
.push(...(urlParams
.get('flags').split(',')));
109 let i
= argv
.indexOf('--vfs');
110 if(i
>=0) argv
.splice(i
,2);
118 //"--memdb", // note that memdb trumps the filename arg
121 if(argv
.indexOf('--memdb')>=0){
122 log2('error',"WARNING: --memdb flag trumps db filename.");
124 argv
.push("--big-transactions"/*important for tests 410 and 510!*/,
126 console
.log("argv =",argv
);
127 // These log messages are not emitted to the UI until after main() returns. Fixing that
128 // requires moving the main() call and related cleanup into a timeout handler.
129 if(pDir
) unlink(dbFile
);
130 log2('',"Starting native app:\n ",argv
.join(' '));
131 log2('',"This will take a while and the browser might warn about the runaway JS.",
134 setTimeout(function(){
135 wasm
.xCall('wasm_main', argv
.length
,
136 wasm
.scopedAllocMainArgv(argv
));
137 wasm
.scopedAllocPop(scope
);
138 if(pDir
) unlink(dbFile
);
139 logList
.unshift("Done running native main(). Output:");
144 self
.sqlite3TestModule
.print
= log
;
145 self
.sqlite3TestModule
.printErr
= logErr
;
146 sqlite3InitModule(self
.sqlite3TestModule
).then(runTests
);