Skip to content

Commit

Permalink
fixup! tlv: fuzz tests for streams
Browse files Browse the repository at this point in the history
better documentation
  • Loading branch information
morehouse committed Sep 28, 2023
1 parent 93cd750 commit 5bb4df4
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion tlv/fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,19 +173,24 @@ func FuzzTUint64(f *testing.F) {
}

// encodeParsedTypes re-encodes TLVs decoded from a stream, using the
// parsedTypes and decodedRecords produced during decoding.
// parsedTypes and decodedRecords produced during decoding. This function
// requires that each record in decodedRecords has a type number equivalent to
// its index in the slice.
func encodeParsedTypes(t *testing.T, parsedTypes TypeMap,
decodedRecords []Record) []byte {

var encodeRecords []Record
for typ, val := range parsedTypes {
// If typ is present in decodedRecords, use the decoded value.
if typ < Type(len(decodedRecords)) {
encodeRecords = append(
encodeRecords, decodedRecords[typ],
)
continue
}

// Otherwise, typ is not present in decodedRecords, and we must
// create a new one.
val := val
encodeRecords = append(
encodeRecords, MakePrimitiveRecord(typ, &val),
Expand Down Expand Up @@ -231,6 +236,9 @@ func FuzzStream(f *testing.F) {
return SizeTUint64(tu64)
}

// We deliberately set each record's type number to its index in
// the slice, as this simplifies the re-encoding logic in
// encodeParsedTypes().
decodeRecords := []Record{
MakePrimitiveRecord(0, &u8),
MakePrimitiveRecord(1, &u16),
Expand Down

0 comments on commit 5bb4df4

Please sign in to comment.