| 1 |
package main |
| 2 |
|
| 3 |
import ( |
| 4 |
"crypto/sha256" |
| 5 |
_ "embed" |
| 6 |
"encoding/hex" |
| 7 |
"fmt" |
| 8 |
"os" |
| 9 |
"path" |
| 10 |
) |
| 11 |
|
| 12 |
const failedCasesDir = "wazerolib/testdata" |
| 13 |
|
| 14 |
|
| 15 |
func saveFailedBinary(bin []byte, reproduceTestName string) { |
| 16 |
checksum := sha256.Sum256(bin) |
| 17 |
checkSumStr := hex.EncodeToString(checksum[:]) |
| 18 |
|
| 19 |
dir, err := os.Getwd() |
| 20 |
if err != nil { |
| 21 |
panic(err) |
| 22 |
} |
| 23 |
|
| 24 |
testDataDir := path.Join(dir, failedCasesDir) |
| 25 |
binaryPath := path.Join(testDataDir, fmt.Sprintf("%s.wasm", checkSumStr)) |
| 26 |
f, err := os.Create(binaryPath) |
| 27 |
if err != nil { |
| 28 |
panic(err) |
| 29 |
} |
| 30 |
|
| 31 |
defer f.Close() |
| 32 |
|
| 33 |
_, err = f.Write(bin) |
| 34 |
if err != nil { |
| 35 |
panic(err) |
| 36 |
} |
| 37 |
|
| 38 |
fmt.Printf(` |
| 39 |
Failed WebAssembly Binary in hex: %s |
| 40 |
Failed Wasm binary has been written to %s |
| 41 |
To reproduce the failure, execute: WASM_BINARY_PATH=%s go test -run=%s ./wazerolib/... |
| 42 |
`, hex.EncodeToString(bin), binaryPath, binaryPath, reproduceTestName) |
| 43 |
} |