sqlite
[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.
Brought by drakestapleton
sqlite / ext / wasm / tests / opfs / sahpool / digest.html
| 1 | <!doctype html> |
| 2 | <html lang="en-us"> |
| 3 | <head> |
| 4 | <meta charset="utf-8"> |
| 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>sqlite3 tester: OpfsSAHPool Digest</title> |
| 10 | <style></style> |
| 11 | </head> |
| 12 | <body><h1 id='color-target'></h1> |
| 13 | |
| 14 | <p> |
| 15 | This is a test app for the digest calculation of the OPFS |
| 16 | SAHPool VFS. It requires running it with a new database created using |
| 17 | v3.49.0 or older, then running it again with a newer version, then |
| 18 | again with 3.49.0 or older. |
| 19 | </p> |
| 20 | <div class='input-wrapper'> |
| 21 | <input type='checkbox' id='cb-log-reverse'> |
| 22 | <label for='cb-log-reverse'>Reverse log order?</label> |
| 23 | </div> |
| 24 | <div id='test-output'></div> |
| 25 | <script> |
| 26 | /* |
| 27 | 2025-02-03 |
| 28 | |
| 29 | The author disclaims copyright to this source code. In place of a |
| 30 | legal notice, here is a blessing: |
| 31 | |
| 32 | * May you do good and not evil. |
| 33 | * May you find forgiveness for yourself and forgive others. |
| 34 | * May you share freely, never taking more than you give. |
| 35 | |
| 36 | *********************************************************************** |
| 37 | |
| 38 | This is a bugfix test for the OPFS SAHPool VFS. It requires |
| 39 | setting up a database created using v3.49.0 or older, then |
| 40 | running it again with a newer version. In that case, the newer |
| 41 | version should be able to read the older version's db files |
| 42 | just fine. Revering back to the old version should also still |
| 43 | work - it should be able to read databases modified by the |
| 44 | newer version. However, a database _created_ by a version with |
| 45 | this fix will _not_ be legible by a version which predates |
| 46 | this fix, in which case the older version will see that VFS |
| 47 | file slot as corrupt and will clear it for re-use. |
| 48 | |
| 49 | This is unfortunately rather cumbersome to test properly, |
| 50 | and essentially impossible to automate. |
| 51 | */ |
| 52 | (function(){ |
| 53 | 'use strict'; |
| 54 | document.querySelector('h1').innerHTML = |
| 55 | document.querySelector('title').innerHTML; |
| 56 | const mapToString = (v)=>{ |
| 57 | switch(typeof v){ |
| 58 | case 'number': case 'string': case 'boolean': |
| 59 | case 'undefined': case 'bigint': |
| 60 | return ''+v; |
| 61 | default: break; |
| 62 | } |
| 63 | if(null===v) return 'null'; |
| 64 | if(v instanceof Error){ |
| 65 | v = { |
| 66 | message: v.message, |
| 67 | stack: v.stack, |
| 68 | errorClass: v.name |
| 69 | }; |
| 70 | } |
| 71 | return JSON.stringify(v,undefined,2); |
| 72 | }; |
| 73 | const normalizeArgs = (args)=>args.map(mapToString); |
| 74 | const logTarget = document.querySelector('#test-output'); |
| 75 | const logClass = function(cssClass,...args){ |
| 76 | const ln = document.createElement('div'); |
| 77 | if(cssClass){ |
| 78 | for(const c of (Array.isArray(cssClass) ? cssClass : [cssClass])){ |
| 79 | ln.classList.add(c); |
| 80 | } |
| 81 | } |
| 82 | ln.append(document.createTextNode(normalizeArgs(args).join(' '))); |
| 83 | logTarget.append(ln); |
| 84 | }; |
| 85 | const cbReverse = document.querySelector('#cb-log-reverse'); |
| 86 | //cbReverse.setAttribute('checked','checked'); |
| 87 | const cbReverseKey = 'tester1:cb-log-reverse'; |
| 88 | const cbReverseIt = ()=>{ |
| 89 | logTarget.classList[cbReverse.checked ? 'add' : 'remove']('reverse'); |
| 90 | //localStorage.setItem(cbReverseKey, cbReverse.checked ? 1 : 0); |
| 91 | }; |
| 92 | cbReverse.addEventListener('change', cbReverseIt, true); |
| 93 | /*if(localStorage.getItem(cbReverseKey)){ |
| 94 | cbReverse.checked = !!(+localStorage.getItem(cbReverseKey)); |
| 95 | }*/ |
| 96 | cbReverseIt(); |
| 97 | |
| 98 | const log = (...args)=>{ |
| 99 | //console.log(...args); |
| 100 | logClass('',...args); |
| 101 | } |
| 102 | const warn = (...args)=>{ |
| 103 | console.warn(...args); |
| 104 | logClass('warning',...args); |
| 105 | } |
| 106 | const error = (...args)=>{ |
| 107 | console.error(...args); |
| 108 | logClass('error',...args); |
| 109 | }; |
| 110 | |
| 111 | const toss = (...args)=>{ |
| 112 | error(...args); |
| 113 | throw new Error(args.join(' ')); |
| 114 | }; |
| 115 | |
| 116 | const endOfWork = (passed=true)=>{ |
| 117 | const eH = document.querySelector('#color-target'); |
| 118 | const eT = document.querySelector('title'); |
| 119 | if(passed){ |
| 120 | log("End of work chain. If you made it this far, you win."); |
| 121 | eH.innerText = 'PASS: '+eH.innerText; |
| 122 | eH.classList.add('tests-pass'); |
| 123 | eT.innerText = 'PASS: '+eT.innerText; |
| 124 | }else{ |
| 125 | eH.innerText = 'FAIL: '+eH.innerText; |
| 126 | eH.classList.add('tests-fail'); |
| 127 | eT.innerText = 'FAIL: '+eT.innerText; |
| 128 | } |
| 129 | }; |
| 130 | |
| 131 | log("Running opfs-sahpool digest tests..."); |
| 132 | const W1 = new Worker('digest-worker.js?sqlite3.dir=../../../jswasm'); |
| 133 | W1.onmessage = function({data}){ |
| 134 | //log("onmessage:",data); |
| 135 | switch(data.type){ |
| 136 | case 'log': |
| 137 | log('worker says:', ...data.payload); |
| 138 | break; |
| 139 | case 'error': |
| 140 | error('worker says:', ...data.payload); |
| 141 | endOfWork(false); |
| 142 | break; |
| 143 | case 'initialized': |
| 144 | log(data.workerId, ': Worker initialized',...data.payload); |
| 145 | break; |
| 146 | } |
| 147 | }; |
| 148 | })(); |
| 149 | </script> |
| 150 | </body> |
| 151 | </html> |