2023-06-09 04:35:52 -04:00
|
|
|
//go:build integration && cgo && linux
|
2022-08-02 06:35:23 -04:00
|
|
|
|
2022-09-05 03:06:08 -04:00
|
|
|
/*
|
|
|
|
Copyright (c) Edgeless Systems GmbH
|
|
|
|
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2022-08-02 06:35:23 -04:00
|
|
|
package integration
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2024-02-08 09:20:01 -05:00
|
|
|
"log/slog"
|
2022-08-02 06:35:23 -04:00
|
|
|
"math"
|
|
|
|
"testing"
|
|
|
|
|
2023-07-17 07:55:31 -04:00
|
|
|
"github.com/edgelesssys/constellation/v2/disk-mapper/internal/diskencryption"
|
2022-09-21 07:47:57 -04:00
|
|
|
"github.com/edgelesssys/constellation/v2/internal/logger"
|
2022-08-02 06:35:23 -04:00
|
|
|
"github.com/martinjungblut/go-cryptsetup"
|
|
|
|
)
|
|
|
|
|
|
|
|
func BenchmarkMapper(b *testing.B) {
|
|
|
|
cryptsetup.SetDebugLevel(cryptsetup.CRYPT_LOG_ERROR)
|
|
|
|
cryptsetup.SetLogCallback(func(_ int, message string) { fmt.Println(message) })
|
|
|
|
|
|
|
|
testPath := *diskPath
|
|
|
|
if testPath == "" {
|
|
|
|
// no disk specified, use 1GB loopback disk
|
|
|
|
testPath = devicePath
|
|
|
|
if err := setup(1); err != nil {
|
|
|
|
b.Fatal("Failed to setup test environment:", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
if err := teardown(); err != nil {
|
|
|
|
b.Fatal("failed to delete test disk:", err)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
|
|
|
passphrase := "benchmark"
|
2024-02-08 09:20:01 -05:00
|
|
|
mapper, free, err := diskencryption.New(testPath, logger.NewTextLogger(slog.LevelInfo))
|
2022-08-02 06:35:23 -04:00
|
|
|
if err != nil {
|
|
|
|
b.Fatal("Failed to create mapper:", err)
|
|
|
|
}
|
2023-07-17 07:55:31 -04:00
|
|
|
defer free()
|
2022-08-02 06:35:23 -04:00
|
|
|
|
|
|
|
if err := mapper.FormatDisk(passphrase); err != nil {
|
|
|
|
b.Fatal("Failed to format disk:", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
testCases := map[string]struct {
|
|
|
|
wipeBlockSize int
|
|
|
|
}{
|
|
|
|
"16KiB": {
|
|
|
|
wipeBlockSize: int(math.Pow(2, 14)),
|
|
|
|
},
|
|
|
|
"32KiB": {
|
|
|
|
wipeBlockSize: int(math.Pow(2, 15)),
|
|
|
|
},
|
|
|
|
"64KiB": {
|
|
|
|
wipeBlockSize: int(math.Pow(2, 16)),
|
|
|
|
},
|
|
|
|
"128KiB": {
|
|
|
|
wipeBlockSize: int(math.Pow(2, 17)),
|
|
|
|
},
|
|
|
|
"256KiB": {
|
|
|
|
wipeBlockSize: int(math.Pow(2, 18)),
|
|
|
|
},
|
|
|
|
"512KiB": {
|
|
|
|
wipeBlockSize: int(math.Pow(2, 19)),
|
|
|
|
},
|
|
|
|
"1MiB": {
|
|
|
|
wipeBlockSize: int(math.Pow(2, 20)),
|
|
|
|
},
|
|
|
|
"2MiB": {
|
|
|
|
wipeBlockSize: int(math.Pow(2, 21)),
|
|
|
|
},
|
|
|
|
"4MiB": {
|
|
|
|
wipeBlockSize: int(math.Pow(2, 22)),
|
|
|
|
},
|
|
|
|
"8MiB": {
|
|
|
|
wipeBlockSize: int(math.Pow(2, 23)),
|
|
|
|
},
|
|
|
|
"16MiB": {
|
|
|
|
wipeBlockSize: int(math.Pow(2, 24)),
|
|
|
|
},
|
|
|
|
"32MiB": {
|
|
|
|
wipeBlockSize: int(math.Pow(2, 25)),
|
|
|
|
},
|
|
|
|
"64MiB": {
|
|
|
|
wipeBlockSize: int(math.Pow(2, 26)),
|
|
|
|
},
|
|
|
|
"128MiB": {
|
|
|
|
wipeBlockSize: int(math.Pow(2, 27)),
|
|
|
|
},
|
|
|
|
"256MiB": {
|
|
|
|
wipeBlockSize: int(math.Pow(2, 28)),
|
|
|
|
},
|
|
|
|
"512MiB": {
|
|
|
|
wipeBlockSize: int(math.Pow(2, 29)),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for name, tc := range testCases {
|
|
|
|
b.Run(name, func(b *testing.B) {
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
if err := mapper.Wipe(tc.wipeBlockSize); err != nil {
|
|
|
|
b.Fatal("Failed to wipe disk:", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|