From f55d0801fa07067e49fa24df863dd20af7ac3a2a Mon Sep 17 00:00:00 2001 From: matthewkeil Date: Fri, 20 Dec 2024 15:24:40 +0700 Subject: [PATCH] test: non-simd implementation --- packages/as-sha256/src/index.ts | 3 ++- packages/as-sha256/test/unit/getSimdTests.ts | 7 ++++--- packages/as-sha256/test/unit/noSimd.test.ts | 1 - packages/as-sha256/test/unit/simd.test.ts | 1 - 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/as-sha256/src/index.ts b/packages/as-sha256/src/index.ts index f2374734..5dafdf38 100644 --- a/packages/as-sha256/src/index.ts +++ b/packages/as-sha256/src/index.ts @@ -5,7 +5,7 @@ import {HashObject, byteArrayIntoHashObject, byteArrayToHashObject, hashObjectTo import SHA256 from "./sha256.js"; export {HashObject, byteArrayToHashObject, hashObjectToByteArray, byteArrayIntoHashObject, SHA256}; -const hasSimd = await simd(); +let hasSimd = await simd(); let ctx: WasmSimdContext; let wasmInputValue: number; @@ -17,6 +17,7 @@ let outputUint8Array32: Uint8Array; let inputUint32Array: Uint32Array; function initializeInstance(useSimd: boolean): void { + hasSimd = useSimd; ctx = newInstance(useSimd) as WasmSimdContext; wasmInputValue = ctx.input.value; wasmOutputValue = ctx.output.value; diff --git a/packages/as-sha256/test/unit/getSimdTests.ts b/packages/as-sha256/test/unit/getSimdTests.ts index 8ed6f229..a9067eb5 100644 --- a/packages/as-sha256/test/unit/getSimdTests.ts +++ b/packages/as-sha256/test/unit/getSimdTests.ts @@ -7,10 +7,11 @@ import crypto from "crypto"; import {byteArrayToHashObject, hashObjectToByteArray} from "../../src/hashObject.js"; // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types -export function getSimdTests(sha256: any, hasSimd: boolean): void { - describe(`Test as-sha256 ${hasSimd ? "with SIMD" : "without SIMD"}`, () => { +export function getSimdTests(sha256: any, useSimd: boolean): void { + describe(`Test as-sha256 ${useSimd ? "with SIMD" : "without SIMD"}`, () => { before(function () { - expect(sha256.simdEnabled()).to.equal(hasSimd); + sha256.reinitializeInstance(useSimd); + expect(sha256.simdEnabled()).to.equal(useSimd); }); it("testHash4UintArray64s", () => { const input1 = "gajindergajindergajindergajinder"; diff --git a/packages/as-sha256/test/unit/noSimd.test.ts b/packages/as-sha256/test/unit/noSimd.test.ts index 9b38ee99..1d524567 100644 --- a/packages/as-sha256/test/unit/noSimd.test.ts +++ b/packages/as-sha256/test/unit/noSimd.test.ts @@ -2,5 +2,4 @@ import * as sha256 from "../../src/index.js"; import {getSimdTests} from "./getSimdTests.js"; const useSimd = false; -sha256.reinitializeInstance(useSimd); getSimdTests(sha256, useSimd); diff --git a/packages/as-sha256/test/unit/simd.test.ts b/packages/as-sha256/test/unit/simd.test.ts index acce45b3..cc5eb711 100644 --- a/packages/as-sha256/test/unit/simd.test.ts +++ b/packages/as-sha256/test/unit/simd.test.ts @@ -2,5 +2,4 @@ import * as sha256 from "../../src/index.js"; import {getSimdTests} from "./getSimdTests.js"; const useSimd = true; -sha256.reinitializeInstance(useSimd); getSimdTests(sha256, useSimd);