Skip to content

Commit

Permalink
chore(ci): format javascript code using prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
soonum committed Mar 14, 2024
1 parent 937c364 commit 9efe4ac
Show file tree
Hide file tree
Showing 11 changed files with 754 additions and 637 deletions.
6 changes: 1 addition & 5 deletions tfhe/web_wasm_parallel_tests/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
const presets = [
[
"@babel/preset-env",
]
];
const presets = [["@babel/preset-env"]];

module.exports = { presets };
143 changes: 106 additions & 37 deletions tfhe/web_wasm_parallel_tests/index.html
Original file line number Diff line number Diff line change
@@ -1,52 +1,121 @@
<!DOCTYPE html>
<!doctype html>
<title>TFHE-RS Web Wasm Demo</title>
<body>
<style>
.loader {
border: 16px solid #f3f3f3; /* Light grey */
border-top: 16px solid #3498db; /* Blue */
border-radius: 50%;
width: 120px;
height: 120px;
animation: spin 2s linear infinite;
}
<style>
.loader {
border: 16px solid #f3f3f3; /* Light grey */
border-top: 16px solid #3498db; /* Blue */
border-radius: 50%;
width: 120px;
height: 120px;
animation: spin 2s linear infinite;
}

@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
</style>
@keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
</style>

<div>
<input type="button" id="publicKeyTest" value="Public Key Test" disabled />
<input type="button" id="compressedPublicKeyTest" value="Compressed Public Key Test" disabled />
<div>
<input type="button" id="publicKeyTest" value="Public Key Test" disabled />
<input
type="button"
id="compressedPublicKeyTest"
value="Compressed Public Key Test"
disabled
/>

<input type="button" id="compactPublicKeyTest32BitSmall" value="Compact Public Key Test 32 Bits Small" disabled />
<input type="button" id="compactPublicKeyTest32BitBig" value="Compact Public Key Test 32 Bits Big" disabled />
<input
type="button"
id="compactPublicKeyTest32BitSmall"
value="Compact Public Key Test 32 Bits Small"
disabled
/>
<input
type="button"
id="compactPublicKeyTest32BitBig"
value="Compact Public Key Test 32 Bits Big"
disabled
/>

<input type="button" id="compactPublicKeyTest256BitSmall" value="Compact Public Key Test 256 Bits Small" disabled />
<input type="button" id="compactPublicKeyTest256BitBig" value="Compact Public Key Test 256 Bits Big" disabled />
<input
type="button"
id="compactPublicKeyTest256BitSmall"
value="Compact Public Key Test 256 Bits Small"
disabled
/>
<input
type="button"
id="compactPublicKeyTest256BitBig"
value="Compact Public Key Test 256 Bits Big"
disabled
/>

<input type="button" id="compressedCompactPublicKeyTest256BitSmall" value="Compressed Compact Public Key Test 256 Bits Small" disabled />
<input type="button" id="compressedCompactPublicKeyTest256BitBig" value="Compressed Compact Public Key Test 256 Bits Big" disabled />
<input
type="button"
id="compressedCompactPublicKeyTest256BitSmall"
value="Compressed Compact Public Key Test 256 Bits Small"
disabled
/>
<input
type="button"
id="compressedCompactPublicKeyTest256BitBig"
value="Compressed Compact Public Key Test 256 Bits Big"
disabled
/>

<input type="checkbox" id="testSuccess" disabled>
<label for="testSuccess"> TestSuccess </label><br>
<input type="checkbox" id="testSuccess" disabled />
<label for="testSuccess"> TestSuccess </label><br />

<input type="button" id="compactPublicKeyBench32BitSmall" value="Compact Public Key Bench 32 Bits Small" disabled />
<input type="button" id="compactPublicKeyBench32BitBig" value="Compact Public Key Bench 32 Bits Big" disabled />
<input
type="button"
id="compactPublicKeyBench32BitSmall"
value="Compact Public Key Bench 32 Bits Small"
disabled
/>
<input
type="button"
id="compactPublicKeyBench32BitBig"
value="Compact Public Key Bench 32 Bits Big"
disabled
/>

<input type="button" id="compactPublicKeyBench256BitSmall" value="Compact Public Key Bench 256 Bits Small" disabled />
<input type="button" id="compactPublicKeyBench256BitBig" value="Compact Public Key Bench 256 Bits Big" disabled />
<input
type="button"
id="compactPublicKeyBench256BitSmall"
value="Compact Public Key Bench 256 Bits Small"
disabled
/>
<input
type="button"
id="compactPublicKeyBench256BitBig"
value="Compact Public Key Bench 256 Bits Big"
disabled
/>

<input type="button" id="compressedServerKeyBenchMessage1Carry1" value="Compressed Server Key Bench 1_1" disabled />
<input type="button" id="compressedServerKeyBenchMessage2Carry2" value="Compressed Server Key Bench 2_2" disabled />
<input
type="button"
id="compressedServerKeyBenchMessage1Carry1"
value="Compressed Server Key Bench 1_1"
disabled
/>
<input
type="button"
id="compressedServerKeyBenchMessage2Carry2"
value="Compressed Server Key Bench 2_2"
disabled
/>

<input type="text" id="benchmarkResults" disabled>
<label for="benchmarkResults"> BenchmarkResults </label><br>
<input type="text" id="benchmarkResults" disabled />
<label for="benchmarkResults"> BenchmarkResults </label><br />

<div id="loader" class="loader" hidden></div>
</div>
<div id="loader" class="loader" hidden></div>
</div>

<script type="module" src="index.js"></script>
<script type="module" src="index.js"></script>
</body>
140 changes: 69 additions & 71 deletions tfhe/web_wasm_parallel_tests/index.js
Original file line number Diff line number Diff line change
@@ -1,87 +1,85 @@
import { threads } from 'wasm-feature-detect';
import * as Comlink from 'comlink';

import { threads } from "wasm-feature-detect";
import * as Comlink from "comlink";

function setButtonsDisabledState(buttonIds, state) {
for (let id of buttonIds) {
let btn = document.getElementById(id);
if (btn) {
btn.disabled = state;
}
for (let id of buttonIds) {
let btn = document.getElementById(id);
if (btn) {
btn.disabled = state;
}
}
}

async function setup() {
let supportsThreads = await threads()
if (!supportsThreads) {
console.error("This browser does not support threads")
return
}
let supportsThreads = await threads();
if (!supportsThreads) {
console.error("This browser does not support threads");
return;
}

const worker = new Worker(
new URL("worker.js", import.meta.url),
{type: 'module'}
);
const demos = await Comlink.wrap(worker).demos;
const worker = new Worker(new URL("worker.js", import.meta.url), {
type: "module",
});
const demos = await Comlink.wrap(worker).demos;

const demoNames = [
'publicKeyTest',
'compressedPublicKeyTest',
'compactPublicKeyTest32BitBig',
'compactPublicKeyTest32BitSmall',
'compactPublicKeyTest256BitBig',
'compactPublicKeyTest256BitSmall',
'compressedCompactPublicKeyTest256BitBig',
'compressedCompactPublicKeyTest256BitSmall',
'compactPublicKeyBench32BitBig',
'compactPublicKeyBench32BitSmall',
'compactPublicKeyBench256BitBig',
'compactPublicKeyBench256BitSmall',
'compressedServerKeyBenchMessage1Carry1',
'compressedServerKeyBenchMessage2Carry2',
]
const demoNames = [
"publicKeyTest",
"compressedPublicKeyTest",
"compactPublicKeyTest32BitBig",
"compactPublicKeyTest32BitSmall",
"compactPublicKeyTest256BitBig",
"compactPublicKeyTest256BitSmall",
"compressedCompactPublicKeyTest256BitBig",
"compressedCompactPublicKeyTest256BitSmall",
"compactPublicKeyBench32BitBig",
"compactPublicKeyBench32BitSmall",
"compactPublicKeyBench256BitBig",
"compactPublicKeyBench256BitSmall",
"compressedServerKeyBenchMessage1Carry1",
"compressedServerKeyBenchMessage2Carry2",
];

function setupBtn(id) {
// Handlers are named in the same way as buttons.
let fn = demos[id];
function setupBtn(id) {
// Handlers are named in the same way as buttons.
let fn = demos[id];

let button = document.getElementById(id);
if (button === null) {
console.error("button with id: ", id , "not found")
return null;
}
let button = document.getElementById(id);
if (button === null) {
console.error("button with id: ", id, "not found");
return null;
}

// Assign onclick handler + enable the button.
Object.assign(button, {
onclick: async () => {
document.getElementById("loader").hidden = false
document.getElementById("testSuccess").checked = false
setButtonsDisabledState(demoNames, true);
// Assign onclick handler + enable the button.
Object.assign(button, {
onclick: async () => {
document.getElementById("loader").hidden = false;
document.getElementById("testSuccess").checked = false;
setButtonsDisabledState(demoNames, true);

console.log("Running: ", id)
try {
let results = await fn()
document.getElementById("testSuccess").checked = true
if (results !== undefined) {
document.getElementById("benchmarkResults").value = JSON.stringify(results);
}
} catch (error) {
console.error(`Test Failed: ${error}`)
document.getElementById("testSuccess").checked = false
}
document.getElementById("loader").hidden = true
setButtonsDisabledState(demoNames, false);
},
disabled: false
});
console.log("Running: ", id);
try {
let results = await fn();
document.getElementById("testSuccess").checked = true;
if (results !== undefined) {
document.getElementById("benchmarkResults").value =
JSON.stringify(results);
}
} catch (error) {
console.error(`Test Failed: ${error}`);
document.getElementById("testSuccess").checked = false;
}
document.getElementById("loader").hidden = true;
setButtonsDisabledState(demoNames, false);
},
disabled: false,
});

return button;
}
return button;
}

for (let demo of demoNames) {
setupBtn(demo)
}
for (let demo of demoNames) {
setupBtn(demo);
}
}


setup()
setup();
6 changes: 3 additions & 3 deletions tfhe/web_wasm_parallel_tests/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
const secs = 60
const secs = 60;

const config = {
verbose: true,
testTimeout: secs * 1000,
testTimeout: secs * 1000,
testRegex: "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|js?|tsx?|ts?)$",
transform: {
"^.+\\.jsx?$": "babel-jest",
"^.+\\.mjs$": "babel-jest",
},
testPathIgnorePatterns: ["<rootDir>/build/", "<rootDir>/node_modules/"],
moduleFileExtensions: ["js", "jsx", "mjs"]
moduleFileExtensions: ["js", "jsx", "mjs"],
};

module.exports = config;
20 changes: 10 additions & 10 deletions tfhe/web_wasm_parallel_tests/serve.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"headers": [
{
"source": "**/*.@(js|html)",
"headers": [
{ "key": "Cross-Origin-Embedder-Policy", "value": "require-corp" },
{ "key": "Cross-Origin-Opener-Policy", "value": "same-origin" }
]
}
]
}
"headers": [
{
"source": "**/*.@(js|html)",
"headers": [
{ "key": "Cross-Origin-Embedder-Policy", "value": "require-corp" },
{ "key": "Cross-Origin-Opener-Policy", "value": "same-origin" }
]
}
]
}
Loading

0 comments on commit 9efe4ac

Please sign in to comment.