Adds libsodium integration tests (#2086)
Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
This commit is contained in:
42
.github/workflows/integration.yaml
vendored
42
.github/workflows/integration.yaml
vendored
@@ -359,3 +359,45 @@ jobs:
|
||||
run: |
|
||||
cd ${{ env.STDLIB_TESTS }}
|
||||
go test -bench='BenchmarkWasip1/${{ matrix.compiler }}'
|
||||
|
||||
libsodium:
|
||||
name: libsodium (${{ matrix.os.name }}, ${{ matrix.arch }}, optimizing)
|
||||
runs-on: ${{ matrix.os.version }}
|
||||
strategy:
|
||||
fail-fast: false # don't fail fast as sometimes failures are arch/OS specific
|
||||
matrix:
|
||||
# version is too verbose to be present in the name, so we use the name instead.
|
||||
# Note that it'd be better to use runner.os in the name, but the runner context is not available in the name field.
|
||||
os:
|
||||
- version: ubuntu-22.04
|
||||
name: Ubuntu
|
||||
arch: amd64
|
||||
- version: macos-14
|
||||
name: macOS
|
||||
arch: arm64
|
||||
|
||||
steps:
|
||||
- name: Checkout wazero
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- uses: actions/cache@v3
|
||||
id: binary-cache
|
||||
with:
|
||||
# Use share the cache containing archives across OSes.
|
||||
enableCrossOsArchive: true
|
||||
# We need this cache to run tests.
|
||||
fail-on-cache-miss: true
|
||||
key: tinygo-test-binaries-${{ env.TINYGO_VERSION }}
|
||||
path:
|
||||
${{ env.STDLIB_TESTS }}/testdata/tinygo
|
||||
|
||||
- uses: actions/setup-go@v4
|
||||
with:
|
||||
go-version: ${{ env.GO_VERSION }}
|
||||
|
||||
- name: Download test binaries
|
||||
run: make libsodium
|
||||
|
||||
- name: Run test binaries
|
||||
#
|
||||
run: go test ./internal/integration_test/libsodium -bench=. -benchtime=1x
|
||||
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -42,3 +42,4 @@ zig-out/
|
||||
|
||||
# Ignore compiled stdlib test cases.
|
||||
/internal/integration_test/stdlibs/testdata
|
||||
/internal/integration_test/libsodium/testdata
|
||||
|
||||
5
Makefile
5
Makefile
@@ -281,6 +281,11 @@ fuzz:
|
||||
@cd internal/integration_test/fuzz && cargo fuzz run memory_no_diff --sanitizer=none -- -rss_limit_mb=8192 -max_total_time=$(fuzz_timeout_seconds)
|
||||
@cd internal/integration_test/fuzz && cargo fuzz run validation --sanitizer=none -- -rss_limit_mb=8192 -max_total_time=$(fuzz_timeout_seconds)
|
||||
|
||||
libsodium:
|
||||
cd ./internal/integration_test/libsodium/testdata && \
|
||||
curl -s "https://api.github.com/repos/jedisct1/webassembly-benchmarks/contents/2022-12/wasm?ref=7e86d68e99e60130899fbe3b3ab6e9dce9187a7c" \
|
||||
| jq -r '.[] | .download_url' | xargs -n 1 curl -LO
|
||||
|
||||
#### CLI release related ####
|
||||
|
||||
VERSION ?= dev
|
||||
|
||||
135
internal/integration_test/libsodium/bench_test.go
Normal file
135
internal/integration_test/libsodium/bench_test.go
Normal file
@@ -0,0 +1,135 @@
|
||||
package libsodium
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/rand"
|
||||
"embed"
|
||||
"io"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/tetratelabs/wazero"
|
||||
"github.com/tetratelabs/wazero/experimental/opt"
|
||||
"github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1"
|
||||
"github.com/tetratelabs/wazero/internal/testing/require"
|
||||
)
|
||||
|
||||
//go:embed testdata/*
|
||||
var tests embed.FS
|
||||
|
||||
func BenchmarkLibsodium(b *testing.B) {
|
||||
cases, err := tests.ReadDir("testdata")
|
||||
require.NoError(b, err)
|
||||
if len(cases) < 10 {
|
||||
b.Skip("skipping libsodium bench because wasm files not found. `make libsodium` to download the binaries.")
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
r := wazero.NewRuntimeWithConfig(ctx, opt.NewRuntimeConfigOptimizingCompiler())
|
||||
defer r.Close(ctx)
|
||||
wasi_snapshot_preview1.MustInstantiate(ctx, r)
|
||||
|
||||
// Some tests are skipped because they are taking too long to run, but sure it is possible to run them.
|
||||
for _, c := range []struct {
|
||||
name string
|
||||
}{
|
||||
//{name: "box7"},
|
||||
{name: "box_easy2"},
|
||||
{name: "kdf_hkdf"},
|
||||
{name: "auth5"},
|
||||
{name: "stream2"},
|
||||
{name: "aead_xchacha20poly1305"},
|
||||
{name: "hash3"},
|
||||
{name: "aead_chacha20poly1305"},
|
||||
{name: "auth"},
|
||||
//{name: "core_ed25519_h2c"},
|
||||
{name: "onetimeauth"},
|
||||
{name: "aead_aegis256"},
|
||||
{name: "scalarmult_ristretto255"},
|
||||
//{name: "core_ristretto255"},
|
||||
{name: "stream3"},
|
||||
//{name: "pwhash_scrypt"},
|
||||
{name: "shorthash"},
|
||||
{name: "scalarmult"},
|
||||
{name: "chacha20"},
|
||||
//{name: "pwhash_argon2id"},
|
||||
{name: "onetimeauth7"},
|
||||
{name: "scalarmult7"},
|
||||
{name: "auth3"},
|
||||
{name: "stream4"},
|
||||
{name: "hash"},
|
||||
//{name: "sign"},
|
||||
{name: "auth2"},
|
||||
{name: "scalarmult6"},
|
||||
{name: "ed25519_convert"},
|
||||
{name: "box_seal"},
|
||||
{name: "secretbox7"},
|
||||
{name: "pwhash_argon2i"},
|
||||
{name: "secretstream_xchacha20poly1305"},
|
||||
{name: "codecs"},
|
||||
{name: "scalarmult_ed25519"},
|
||||
{name: "sodium_utils"},
|
||||
{name: "scalarmult5"},
|
||||
{name: "xchacha20"},
|
||||
{name: "secretbox8"},
|
||||
{name: "box2"},
|
||||
{name: "core3"},
|
||||
{name: "siphashx24"},
|
||||
{name: "generichash"},
|
||||
{name: "aead_chacha20poly13052"},
|
||||
{name: "randombytes"},
|
||||
{name: "scalarmult8"},
|
||||
//{name: "pwhash_scrypt_ll"},
|
||||
{name: "kx"},
|
||||
{name: "stream"},
|
||||
{name: "auth7"},
|
||||
{name: "generichash2"},
|
||||
{name: "box_seed"},
|
||||
{name: "keygen"},
|
||||
{name: "metamorphic"},
|
||||
{name: "secretbox_easy2"},
|
||||
{name: "sign2"},
|
||||
//{name: "core_ed25519"},
|
||||
{name: "box_easy"},
|
||||
{name: "secretbox2"},
|
||||
//{name: "box8"},
|
||||
{name: "box"},
|
||||
{name: "kdf"},
|
||||
{name: "secretbox_easy"},
|
||||
{name: "onetimeauth2"},
|
||||
{name: "generichash3"},
|
||||
{name: "scalarmult2"},
|
||||
{name: "aead_aegis128l"},
|
||||
{name: "auth6"},
|
||||
{name: "secretbox"},
|
||||
{name: "verify1"},
|
||||
} {
|
||||
b.Run(c.name, func(b *testing.B) {
|
||||
path := "testdata/" + c.name + ".wasm"
|
||||
wasm, err := tests.ReadFile(path)
|
||||
require.NoError(b, err)
|
||||
|
||||
cfg := wazero.NewModuleConfig().
|
||||
WithStdout(io.Discard).
|
||||
WithStderr(io.Discard).
|
||||
WithStdin(os.Stdin).
|
||||
WithRandSource(rand.Reader).
|
||||
WithFSConfig(wazero.NewFSConfig()).
|
||||
WithSysNanosleep().
|
||||
WithSysNanotime().
|
||||
WithSysWalltime().
|
||||
WithArgs(c.name + ".wasm")
|
||||
|
||||
compiled, err := r.CompileModule(ctx, wasm)
|
||||
require.NoError(b, err)
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
mod, err := r.InstantiateModule(ctx, compiled, cfg.WithName(""))
|
||||
require.NoError(b, err)
|
||||
err = mod.Close(ctx)
|
||||
require.NoError(b, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
0
internal/integration_test/libsodium/testdata/.keep
vendored
Normal file
0
internal/integration_test/libsodium/testdata/.keep
vendored
Normal file
Reference in New Issue
Block a user