aboutsummaryrefslogtreecommitdiff
path: root/ext/wasm/tester1.c-pp.js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/wasm/tester1.c-pp.js')
-rw-r--r--ext/wasm/tester1.c-pp.js81
1 files changed, 73 insertions, 8 deletions
diff --git a/ext/wasm/tester1.c-pp.js b/ext/wasm/tester1.c-pp.js
index 8b7119866..ed0e5c3c7 100644
--- a/ext/wasm/tester1.c-pp.js
+++ b/ext/wasm/tester1.c-pp.js
@@ -65,6 +65,14 @@ globalThis.sqlite3InitModule = sqlite3InitModule;
const haveWasmCTests = ()=>{
return !!wasm.exports.sqlite3_wasm_test_intptr;
};
+ const hasOpfs = ()=>{
+ return globalThis.FileSystemHandle
+ && globalThis.FileSystemDirectoryHandle
+ && globalThis.FileSystemFileHandle
+ && globalThis.FileSystemFileHandle.prototype.createSyncAccessHandle
+ && navigator?.storage?.getDirectory;
+ };
+
{
const mapToString = (v)=>{
switch(typeof v){
@@ -277,7 +285,14 @@ globalThis.sqlite3InitModule = sqlite3InitModule;
}
}
const tc = TestUtil.counter, now = performance.now();
- await t.test.call(groupState, sqlite3);
+ let rc = t.test.call(groupState, sqlite3);
+ /*if(rc instanceof Promise){
+ rc = rc.catch((e)=>{
+ error("Test failure:",e);
+ throw e;
+ });
+ }*/
+ await rc;
const then = performance.now();
runtime += then - now;
logClass('faded',indent, indent,
@@ -339,6 +354,11 @@ globalThis.sqlite3InitModule = sqlite3InitModule;
T.g = T.addGroup;
T.t = T.addTest;
let capi, wasm/*assigned after module init*/;
+ const sahPoolConfig = {
+ name: 'opfs-sahpool-tester1',
+ clearOnInit: true,
+ initialCapacity: 3
+ };
////////////////////////////////////////////////////////////////////////
// End of infrastructure setup. Now define the tests...
////////////////////////////////////////////////////////////////////////
@@ -1288,7 +1308,6 @@ globalThis.sqlite3InitModule = sqlite3InitModule;
if(1){
const vfsList = capi.sqlite3_js_vfs_list();
T.assert(vfsList.length>1);
- //log("vfsList =",vfsList);
wasm.scopedAllocCall(()=>{
const vfsArg = (v)=>wasm.xWrap.testConvertArg('sqlite3_vfs*',v);
for(const v of vfsList){
@@ -2617,8 +2636,8 @@ globalThis.sqlite3InitModule = sqlite3InitModule;
////////////////////////////////////////////////////////////////////////
T.g('OPFS: Origin-Private File System',
- (sqlite3)=>(sqlite3.opfs
- ? true : "requires Worker thread in a compatible browser"))
+ (sqlite3)=>(sqlite3.capi.sqlite3_vfs_find("opfs")
+ || 'requires "opfs" VFS'))
.t({
name: 'OPFS db sanity checks',
test: async function(sqlite3){
@@ -2738,6 +2757,48 @@ globalThis.sqlite3InitModule = sqlite3InitModule;
;/* end OPFS tests */
////////////////////////////////////////////////////////////////////////
+ T.g('OPFS SyncAccessHandle Pool VFS',
+ (sqlite3)=>(hasOpfs() || "requires OPFS APIs"))
+ .t({
+ name: 'SAH sanity checks',
+ test: async function(sqlite3){
+ T.assert(!sqlite3.capi.sqlite3_vfs_find(sahPoolConfig.name))
+ .assert(sqlite3.capi.sqlite3_js_vfs_list().indexOf(sahPoolConfig.name) < 0)
+ const inst = sqlite3.installOpfsSAHPoolVfs,
+ catcher = (e)=>{
+ error("Cannot load SAH pool VFS.",
+ "This might not be a problem,",
+ "depending on the environment.");
+ return false;
+ };
+ let u1, u2;
+ const P1 = inst(sahPoolConfig).then(u=>u1 = u).catch(catcher),
+ P2 = inst(sahPoolConfig).then(u=>u2 = u).catch(catcher);
+ await Promise.all([P1, P2]);
+ if(!P1) return;
+ T.assert(u1 === u2)
+ .assert(sahPoolConfig.name === u1.vfsName)
+ .assert(sqlite3.capi.sqlite3_vfs_find(sahPoolConfig.name))
+ .assert(u1.getCapacity() === sahPoolConfig.initialCapacity)
+ .assert(5 === (await u2.addCapacity(2)))
+ .assert(sqlite3.capi.sqlite3_js_vfs_list().indexOf(sahPoolConfig.name) >= 0)
+ .assert(true === await u2.removeVfs())
+ .assert(false === await u1.removeVfs())
+ .assert(!sqlite3.capi.sqlite3_vfs_find(sahPoolConfig.name));
+
+ let cErr, u3;
+ const conf2 = JSON.parse(JSON.stringify(sahPoolConfig));
+ conf2.$testThrowInInit = new Error("Testing throwing during init.");
+ conf2.name = sahPoolConfig.name+'-err';
+ const P3 = await inst(conf2).then(u=>u3 = u).catch((e)=>cErr=e);
+ T.assert(P3 === conf2.$testThrowInInit)
+ .assert(cErr === P3)
+ .assert(undefined === u3)
+ .assert(!sqlite3.capi.sqlite3_vfs_find(conf2.name));
+ }
+ }/*OPFS SAH Pool sanity checks*/)
+
+ ////////////////////////////////////////////////////////////////////////
T.g('Hook APIs')
.t({
name: "sqlite3_commit/rollback/update_hook()",
@@ -2942,8 +3003,7 @@ globalThis.sqlite3InitModule = sqlite3InitModule;
.assert( capi.sqlite3session_enable(pSession, -1) > 0 )
.assert(undefined === db1.selectValue('select a from t where rowid=2'));
}else{
- warn("sqlite3session_enable() tests disabled due to unexpected results.",
- "(Possibly a tester misunderstanding, as opposed to a bug.)");
+ warn("sqlite3session_enable() tests are currently disabled.");
}
let db1Count = db1.selectValue("select count(*) from t");
T.assert( db1Count === (testSessionEnable ? 2 : 3) );
@@ -3088,11 +3148,15 @@ globalThis.sqlite3InitModule = sqlite3InitModule;
globalThis.sqlite3InitModule({
print: log,
printErr: error
- }).then(function(sqlite3){
- //console.log('sqlite3 =',sqlite3);
+ }).then(async function(sqlite3){
log("Done initializing WASM/JS bits. Running tests...");
sqlite3.config.warn("Installing sqlite3 bits as global S for local dev/test purposes.");
globalThis.S = sqlite3;
+ /*await sqlite3.installOpfsSAHPoolVfs(sahPoolConfig)
+ .then((u)=>log("Loaded",u.vfsName,"VFS"))
+ .catch(e=>{
+ log("Cannot install OpfsSAHPool.",e);
+ });*/
capi = sqlite3.capi;
wasm = sqlite3.wasm;
log("sqlite3 version:",capi.sqlite3_libversion(),
@@ -3107,6 +3171,7 @@ globalThis.sqlite3InitModule = sqlite3InitModule;
}else{
logClass('warning',"sqlite3_wasm_test_...() APIs unavailable.");
}
+ log("registered vfs list =",capi.sqlite3_js_vfs_list());
TestUtil.runTests(sqlite3);
});
})(self);