aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstephan <stephan@noemail.net>2025-02-03 17:21:54 +0000
committerstephan <stephan@noemail.net>2025-02-03 17:21:54 +0000
commitc97abeac0b33a06a274bc4363b5162c5eed6a5d0 (patch)
tree21b0a8156c429ea904e4ea02b054a0453ad58a92
parent40ce00b54613bce948251264c2dae694db881aa3 (diff)
downloadsqlite-c97abeac0b33a06a274bc4363b5162c5eed6a5d0.tar.gz
sqlite-c97abeac0b33a06a274bc4363b5162c5eed6a5d0.zip
Add a test app to assist in validating the SAHPool digest calculation fix.
FossilOrigin-Name: a1e304b8020025cc73a658bd8c7697d59b4f3ad96cac0a3e36553a3207d13dc6
-rw-r--r--ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js4
-rw-r--r--ext/wasm/tests/opfs/sahpool/digest-worker.js95
-rw-r--r--ext/wasm/tests/opfs/sahpool/digest.html141
-rw-r--r--manifest17
-rw-r--r--manifest.uuid2
5 files changed, 247 insertions, 12 deletions
diff --git a/ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js b/ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js
index 38a1b91dd..08b77c9c1 100644
--- a/ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js
+++ b/ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js
@@ -659,7 +659,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
const fileDigest = new Uint32Array(HEADER_DIGEST_SIZE / 4);
sah.read(fileDigest, {at: HEADER_OFFSET_DIGEST});
const compDigest = this.computeDigest(this.#apBody, flags);
- //console.warn("getAssociatedPath() compDigest",compDigest);
+ console.warn("getAssociatedPath() flags",flags.toString(16), "compDigest", compDigest);
if(fileDigest.every((v,i) => v===compDigest[i])){
// Valid digest
const pathBytes = this.#apBody.findIndex((v)=>0===v);
@@ -700,7 +700,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
this.#apBody.fill(0, enc.written, HEADER_MAX_PATH_SIZE);
this.#dvBody.setUint32(HEADER_OFFSET_FLAGS, flags);
const digest = this.computeDigest(this.#apBody, flags);
- //console.warn("setAssociatedPath(",path,") digest",digest);
+ console.warn("setAssociatedPath(",path,") digest",digest);
sah.write(this.#apBody, {at: 0});
sah.write(digest, {at: HEADER_OFFSET_DIGEST});
sah.flush();
diff --git a/ext/wasm/tests/opfs/sahpool/digest-worker.js b/ext/wasm/tests/opfs/sahpool/digest-worker.js
new file mode 100644
index 000000000..5396252a8
--- /dev/null
+++ b/ext/wasm/tests/opfs/sahpool/digest-worker.js
@@ -0,0 +1,95 @@
+/*
+ 2025-01-31
+
+ The author disclaims copyright to this source code. In place of a
+ legal notice, here is a blessing:
+
+ * May you do good and not evil.
+ * May you find forgiveness for yourself and forgive others.
+ * May you share freely, never taking more than you give.
+
+ ***********************************************************************
+
+ This file is part of sahpool-pausing.js's demonstration of the
+ pause/unpause feature of the opfs-sahpool VFS.
+*/
+const clog = console.log.bind(console);
+const wPost = (type,...args)=>postMessage({type, payload:args});
+const log = (...args)=>{
+ clog("Worker:",...args);
+ wPost('log',...args);
+}
+
+const hasOpfs = ()=>{
+ return globalThis.FileSystemHandle
+ && globalThis.FileSystemDirectoryHandle
+ && globalThis.FileSystemFileHandle
+ && globalThis.FileSystemFileHandle.prototype.createSyncAccessHandle
+ && navigator?.storage?.getDirectory;
+};
+if( !hasOpfs() ){
+ wPost('error',"OPFS not detected");
+ throw new Error("OPFS not detected");
+}
+
+clog("Importing sqlite3...");
+const searchParams = new URL(self.location.href).searchParams;
+importScripts(searchParams.get('sqlite3.dir') + '/sqlite3.js');
+
+const runTests = function(sqlite3, poolUtil){
+ const fname = '/my.db';
+ let db = new poolUtil.OpfsSAHPoolDb(fname);
+ let n = (new Date()).valueOf();
+ try {
+ db.exec([
+ "create table if not exists t(a);"
+ ]);
+ db.exec({
+ sql: "insert into t(a) values(?)",
+ bind: n++
+ });
+ log("Record count: ",db.selectValue("select count(*) from t"));
+ }finally{
+ db.close();
+ }
+
+ db = new poolUtil.OpfsSAHPoolDb(fname);
+ try {
+ db.exec({
+ sql: "insert into t(a) values(?)",
+ bind: n++
+ });
+ log("Record count: ",db.selectValue("select count(*) from t"));
+ }finally{
+ db.close();
+ }
+
+ const fname2 = '/my2.db';
+ db = new poolUtil.OpfsSAHPoolDb(fname2);
+ try {
+ db.exec([
+ "create table if not exists t(a);"
+ ]);
+ db.exec({
+ sql: "insert into t(a) values(?)",
+ bind: n++
+ });
+ log("Record count: ",db.selectValue("select count(*) from t"));
+ }finally{
+ db.close();
+ }
+};
+
+globalThis.sqlite3InitModule().then(async function(sqlite3){
+ log("sqlite3 version:",sqlite3.capi.sqlite3_libversion(),
+ sqlite3.capi.sqlite3_sourceid());
+ const sahPoolConfig = {
+ name: 'opfs-sahpool-digest',
+ clearOnInit: false,
+ initialCapacity: 6
+ };
+ return sqlite3.installOpfsSAHPoolVfs(sahPoolConfig).then(poolUtil=>{
+ log('vfs acquired');
+ runTests(sqlite3, poolUtil);
+ });
+});
diff --git a/ext/wasm/tests/opfs/sahpool/digest.html b/ext/wasm/tests/opfs/sahpool/digest.html
new file mode 100644
index 000000000..c4ba6cc1a
--- /dev/null
+++ b/ext/wasm/tests/opfs/sahpool/digest.html
@@ -0,0 +1,141 @@
+<!doctype html>
+<html lang="en-us">
+ <head>
+ <meta charset="utf-8">
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+ <link rel="shortcut icon" href="data:image/x-icon;," type="image/x-icon">
+ <link rel="stylesheet" href="../../../common/emscripten.css"/>
+ <link rel="stylesheet" href="../../../common/testing.css"/>
+ <title>sqlite3 tester: OpfsSAHPool Digest</title>
+ <style></style>
+ </head>
+ <body><h1 id='color-target'></h1>
+
+ <p>
+ This is a test app for the digest calculation of the OPFS
+ SAHPool VFS. It requires running it with a new database created using
+ v3.49.0 or older, then running it again with a newer version, then
+ again with 3.49.0 or older.
+ </p>
+ <div class='input-wrapper'>
+ <input type='checkbox' id='cb-log-reverse'>
+ <label for='cb-log-reverse'>Reverse log order?</label>
+ </div>
+ <div id='test-output'></div>
+ <script>
+ /*
+ 2025-02-03
+
+ The author disclaims copyright to this source code. In place of a
+ legal notice, here is a blessing:
+
+ * May you do good and not evil.
+ * May you find forgiveness for yourself and forgive others.
+ * May you share freely, never taking more than you give.
+
+ ***********************************************************************
+
+ This is a bugfix test for the OPFS SAHPool VFS. It requires setting up
+ a database created using v3.49.0 or older, then runnig it again with
+ a newer version.
+ */
+ (function(){
+ 'use strict';
+ document.querySelector('h1').innerHTML =
+ document.querySelector('title').innerHTML;
+ const mapToString = (v)=>{
+ switch(typeof v){
+ case 'number': case 'string': case 'boolean':
+ case 'undefined': case 'bigint':
+ return ''+v;
+ default: break;
+ }
+ if(null===v) return 'null';
+ if(v instanceof Error){
+ v = {
+ message: v.message,
+ stack: v.stack,
+ errorClass: v.name
+ };
+ }
+ return JSON.stringify(v,undefined,2);
+ };
+ const normalizeArgs = (args)=>args.map(mapToString);
+ const logTarget = document.querySelector('#test-output');
+ const logClass = function(cssClass,...args){
+ const ln = document.createElement('div');
+ if(cssClass){
+ for(const c of (Array.isArray(cssClass) ? cssClass : [cssClass])){
+ ln.classList.add(c);
+ }
+ }
+ ln.append(document.createTextNode(normalizeArgs(args).join(' ')));
+ logTarget.append(ln);
+ };
+ const cbReverse = document.querySelector('#cb-log-reverse');
+ //cbReverse.setAttribute('checked','checked');
+ const cbReverseKey = 'tester1:cb-log-reverse';
+ const cbReverseIt = ()=>{
+ logTarget.classList[cbReverse.checked ? 'add' : 'remove']('reverse');
+ //localStorage.setItem(cbReverseKey, cbReverse.checked ? 1 : 0);
+ };
+ cbReverse.addEventListener('change', cbReverseIt, true);
+ /*if(localStorage.getItem(cbReverseKey)){
+ cbReverse.checked = !!(+localStorage.getItem(cbReverseKey));
+ }*/
+ cbReverseIt();
+
+ const log = (...args)=>{
+ //console.log(...args);
+ logClass('',...args);
+ }
+ const warn = (...args)=>{
+ console.warn(...args);
+ logClass('warning',...args);
+ }
+ const error = (...args)=>{
+ console.error(...args);
+ logClass('error',...args);
+ };
+
+ const toss = (...args)=>{
+ error(...args);
+ throw new Error(args.join(' '));
+ };
+
+ const endOfWork = (passed=true)=>{
+ const eH = document.querySelector('#color-target');
+ const eT = document.querySelector('title');
+ if(passed){
+ log("End of work chain. If you made it this far, you win.");
+ eH.innerText = 'PASS: '+eH.innerText;
+ eH.classList.add('tests-pass');
+ eT.innerText = 'PASS: '+eT.innerText;
+ }else{
+ eH.innerText = 'FAIL: '+eH.innerText;
+ eH.classList.add('tests-fail');
+ eT.innerText = 'FAIL: '+eT.innerText;
+ }
+ };
+
+ log("Running opfs-sahpool digest tests...");
+ const W1 = new Worker('digest-worker.js?sqlite3.dir=../../../jswasm');
+ W1.onmessage = function({data}){
+ //log("onmessage:",data);
+ switch(data.type){
+ case 'log':
+ log('worker says:', ...data.payload);
+ break;
+ case 'error':
+ error('worker says:', ...data.payload);
+ endOfWork(false);
+ break;
+ case 'initialized':
+ log(data.workerId, ': Worker initialized',...data.payload);
+ break;
+ }
+ };
+ })();
+ </script>
+ </body>
+</html>
diff --git a/manifest b/manifest
index 05212cec0..638b314db 100644
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Initial\swork\son\sa\sfix\sfor\sthe\sSAHPool\sVFS's\seffectively-no-op\sdigest\scalculation,\sas\sreported\sin\s[https://github.com/sqlite/sqlite-wasm/issues/97|ticket\s#97\sof\sthe\sdownstream\snpm\ssubproject].\sThis\srequires\smore\stesting\salongside\sdatabases\screated\sbefore\sthis\sversion\sto\sensure\sthat\sit's\sbackwards-compatible.
-D 2025-02-03T16:26:30.488
+C Add\sa\stest\sapp\sto\sassist\sin\svalidating\sthe\sSAHPool\sdigest\scalculation\sfix.
+D 2025-02-03T17:21:54.248
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md e108e1e69ae8e8a59e93c455654b8ac9356a11720d3345df2a4743e9590fb20d
@@ -645,7 +645,7 @@ F ext/wasm/api/sqlite3-api-worker1.c-pp.js 5cc22a3c0d52828cb32aad8691488719f47d2
F ext/wasm/api/sqlite3-license-version-header.js 0c807a421f0187e778dc1078f10d2994b915123c1223fe752b60afdcd1263f89
F ext/wasm/api/sqlite3-opfs-async-proxy.js 3774befd97cd1a5e2895c8225a894aad946848c6d9b4028acc988b5d123475af
F ext/wasm/api/sqlite3-vfs-helper.c-pp.js 3f828cc66758acb40e9c5b4dcfd87fd478a14c8fb7f0630264e6c7fa0e57515d
-F ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js 2635b4c7f63a8ab496bcff91cb33a890d060e979c34d34e5c782d970fdbce36d
+F ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js d1d17004bfee7a9159b56888b83345c6219262448297a81966faae4fd28f749c
F ext/wasm/api/sqlite3-vfs-opfs.c-pp.js 9b86ca2d8276cf919fbc9ba2a10e9786033b64f92c2db844d951804dee6c4b4e
F ext/wasm/api/sqlite3-vtab-helper.c-pp.js e809739d71e8b35dfe1b55d24d91f02d04239e6aef7ca1ea92a15a29e704f616
F ext/wasm/api/sqlite3-wasm.c 6f9d8529072d072359cd22dc5dfb0572c524684686569cfbd0f9640d7619fc10
@@ -700,6 +700,8 @@ F ext/wasm/tester1.c-pp.js 005a94be87b888ca33aff130aeaef58045781ebfb92e559063d14
F ext/wasm/tests/opfs/concurrency/index.html 657578a6e9ce1e9b8be951549ed93a6a471f4520a99e5b545928668f4285fb5e
F ext/wasm/tests/opfs/concurrency/test.js d08889a5bb6e61937d0b8cbb78c9efbefbf65ad09f510589c779b7cc6a803a88
F ext/wasm/tests/opfs/concurrency/worker.js 0a8c1a3e6ebb38aabbee24f122693f1fb29d599948915c76906681bb7da1d3d2
+F ext/wasm/tests/opfs/sahpool/digest-worker.js cdf4bb6dad5e274985e4b0022d0d85f9e782df03352044d8c7c22532845d7304
+F ext/wasm/tests/opfs/sahpool/digest.html 83d0c2f1dd6fe83e9088c603091514ac8549ee04a4632d8cc51d27fd094f05b3
F ext/wasm/wasmfs.make 68999f5bd8c489239592d59a420f8c627c99169bbd6fa16a404751f757b9f702
F magic.txt 5ade0bc977aa135e79e3faaea894d5671b26107cc91e70783aa7dc83f22f3ba0
F main.mk 8cfe182232ac7bbc87530792db6f31c09f2a2f35e9887d0412978746efe42ea9
@@ -2209,11 +2211,8 @@ F tool/version-info.c 3b36468a90faf1bbd59c65fd0eb66522d9f941eedd364fabccd7227350
F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee87c1b31a7
F tool/warnings.sh 49a486c5069de041aedcbde4de178293e0463ae9918ecad7539eedf0ec77a139
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
-P d693c2dddbd10a2e0b77893b04b11502e30b768f1b06814105f7f35172845fb9
-R f5d8b5467421514674c485e5d9d6f1f0
-T *branch * sahpool-digest
-T *sym-sahpool-digest *
-T -sym-trunk * Cancelled\sby\sbranch.
+P 9234c33f92d92bfddc6211c9c587f1072e70837c0ffe1416ef7d84d59bacd364
+R 176b17e8248aa3df480fb81ba267bf4c
U stephan
-Z fa5f726034dfcd33aa64a420eace023f
+Z 9279d9607c28db362f757a9d03a072e6
# Remove this line to create a well-formed Fossil manifest.
diff --git a/manifest.uuid b/manifest.uuid
index 0ea45d1c3..fef85d18d 100644
--- a/manifest.uuid
+++ b/manifest.uuid
@@ -1 +1 @@
-9234c33f92d92bfddc6211c9c587f1072e70837c0ffe1416ef7d84d59bacd364
+a1e304b8020025cc73a658bd8c7697d59b4f3ad96cac0a3e36553a3207d13dc6