53 lines
1.3 KiB
Go
53 lines
1.3 KiB
Go
// Copyright (c) 2026 Petr Balvín <opensource@petrbalvin.org> (https://petrbalvin.org)
|
|||
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
||
|
|
|
||
|
|
package verify
|
||
|
|
|
||
|
|
import (
|
||
|
|
"testing"
|
||
|
|
)
|
||
|
|
|
||
|
|
func TestFuzzResultString(t *testing.T) {
|
||
|
|
t.Run("ok", func(t *testing.T) {
|
||
|
|
r := FuzzResult{Func: "add", Iterations: 100, Matches: 100}
|
||
|
|
s := r.String()
|
||
|
|
if s != "add: 100/100 iterations match" {
|
||
|
|
t.Errorf("String() = %q", s)
|
||
|
|
}
|
||
|
|
})
|
||
|
|
|
||
|
|
t.Run("mismatch", func(t *testing.T) {
|
||
|
|
r := FuzzResult{Func: "mul", Iterations: 100, Matches: 95, Mismatches: 5, FirstFail: "iter 23"}
|
||
|
|
s := r.String()
|
||
|
|
if s != "mul: 95/100 match, 5 MISMATCH — iter 23" {
|
||
|
|
t.Errorf("String() = %q", s)
|
||
|
|
}
|
||
|
|
})
|
||
|
|
|
||
|
|
t.Run("crash", func(t *testing.T) {
|
||
|
|
r := FuzzResult{Func: "dec", Iterations: 100, Matches: 99, Mismatches: 1, FirstFail: "SIGSEGV", CrashInput: []byte{0x01, 0x02}}
|
||
|
|
s := r.String()
|
||
|
|
if s != "dec: 99/100 match, 1 MISMATCH — SIGSEGV\n input: 0102" {
|
||
|
|
t.Errorf("String() = %q", s)
|
||
|
|
}
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
func TestArrayLen(t *testing.T) {
|
||
|
|
tests := []struct {
|
||
|
|
typ string
|
||
|
|
want int
|
||
|
|
}{
|
||
|
|
{"*[32]uint16", 32},
|
||
|
|
{"*[16]int32", 16},
|
||
|
|
{"bad", 1},
|
||
|
|
{"*[]", 1},
|
||
|
|
{"*[0x]", 1},
|
||
|
|
}
|
||
|
|
for _, tt := range tests {
|
||
|
|
if got := arrayLen(tt.typ); got != tt.want {
|
||
|
|
t.Errorf("arrayLen(%q) = %d, want %d", tt.typ, got, tt.want)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|