fuzz: makes execution order deterministic (#1850)

Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
This commit is contained in:
Takeshi Yoneda
2023-11-27 10:54:16 +09:00
committed by GitHub
parent 9ec72567db
commit d39d84505a

View File

@@ -7,6 +7,7 @@ import (
"errors"
"fmt"
"reflect"
"sort"
"strings"
"unsafe"
@@ -275,8 +276,16 @@ const valueTypeVector = 0x7b
func ensureInvocationResultMatch(compiledMod, interpreterMod api.Module, exportedFunctions map[string]api.FunctionDefinition) (err error) {
ctx := context.Background()
// In order to do the deterministic execution, we need to sort the exported functions.
var names []string
for f := range exportedFunctions {
names = append(names, f)
}
sort.Strings(names)
outer:
for name, def := range exportedFunctions {
for _, name := range names {
def := exportedFunctions[name]
resultTypes := def.ResultTypes()
for _, rt := range resultTypes {
switch rt {