fuzz: ignores fuel in global match (#1784)

Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
This commit is contained in:
Takeshi Yoneda
2023-10-16 09:06:48 +09:00
committed by GitHub
parent 2b8047770f
commit 7e1e1e4fd8
9 changed files with 9 additions and 45 deletions

View File

@@ -2,7 +2,6 @@ package backend_test
import (
"context"
"encoding/hex"
"fmt"
"os"
"runtime"
@@ -2134,8 +2133,6 @@ L1 (SSA Block: blk0):
// Sanity check on the final binary encoding.
be.Encode()
fmt.Println(hex.EncodeToString(be.Buf()))
})
}
}

View File

@@ -1,8 +1,6 @@
package arm64
import (
"encoding/hex"
"fmt"
"testing"
"github.com/tetratelabs/wazero/internal/engine/wazevo/backend"
@@ -400,10 +398,7 @@ func TestAbiImpl_constructEntryPreamble(t *testing.T) {
_, _, m := newSetupWithMockContext()
abi := m.getOrCreateABIImpl(tc.sig)
m.rootInstr = abi.constructEntryPreamble()
fmt.Println(m.Format())
require.Equal(t, tc.exp, m.Format())
m.Encode()
fmt.Println(hex.EncodeToString(m.compiler.Buf()))
})
}
}
@@ -539,10 +534,8 @@ func TestMachine_goEntryPreamblePassArg(t *testing.T) {
cur := m.allocateNop()
m.rootInstr = cur
m.goEntryPreamblePassArg(cur, paramSlicePtr, &tc.arg, tc.argSlotBeginOffsetFromSP)
fmt.Println(m.Format())
require.Equal(t, tc.exp, m.Format())
m.Encode()
fmt.Println(hex.EncodeToString(m.compiler.Buf()))
})
}
}
@@ -694,10 +687,8 @@ func TestMachine_goEntryPreamblePassResult(t *testing.T) {
cur := m.allocateNop()
m.rootInstr = cur
m.goEntryPreamblePassResult(cur, paramSlicePtr, &tc.arg, tc.retStart)
fmt.Println(m.Format())
require.Equal(t, tc.exp, m.Format())
m.Encode()
fmt.Println(hex.EncodeToString(m.compiler.Buf()))
})
}
}

View File

@@ -1,8 +1,6 @@
package arm64
import (
"encoding/hex"
"fmt"
"sort"
"testing"
@@ -450,11 +448,9 @@ func TestMachine_CompileGoFunctionTrampoline(t *testing.T) {
_, _, m := newSetupWithMockContext()
m.CompileGoFunctionTrampoline(tc.exitCode, tc.sig, tc.needModuleContextPtr)
fmt.Println(m.Format())
require.Equal(t, tc.exp, m.Format())
m.Encode()
fmt.Println(hex.EncodeToString(m.compiler.Buf()))
})
}
}
@@ -568,11 +564,8 @@ func Test_goFunctionCallLoadStackArg(t *testing.T) {
m.rootInstr = nop
fmt.Println(m.Format())
require.Equal(t, tc.exp, m.Format())
m.Encode()
fmt.Println(hex.EncodeToString(m.compiler.Buf()))
})
})
}
@@ -637,11 +630,8 @@ func Test_goFunctionCallStoreStackResult(t *testing.T) {
m.rootInstr = nop
fmt.Println(m.Format())
require.Equal(t, tc.exp, m.Format())
m.Encode()
fmt.Println(hex.EncodeToString(m.compiler.Buf()))
})
})
}

View File

@@ -377,7 +377,6 @@ L2:
regalloc.VReg(3).SetRegType(regalloc.RegTypeInt)
_, _, m := newSetupWithMockContext()
m.lowerIDiv(execCtx, operandNR(rd), operandNR(rn), operandNR(rm), tc._64bit, tc.signed)
fmt.Println(formatEmittedInstructionsInCurrentBlock(m))
require.Equal(t, tc.exp, "\n"+formatEmittedInstructionsInCurrentBlock(m)+"\n")
})
}

View File

@@ -1,8 +1,6 @@
package arm64
import (
"encoding/hex"
"fmt"
"testing"
"github.com/tetratelabs/wazero/internal/engine/wazevo/backend/regalloc"
@@ -95,7 +93,7 @@ func TestMachine_SetupPrologue(t *testing.T) {
} {
tc := tc
t.Run(tc.exp, func(t *testing.T) {
ctx, _, m := newSetupWithMockContext()
_, _, m := newSetupWithMockContext()
m.DisableStackCheck()
m.spillSlotSize = tc.spillSlotSize
m.clobberedRegs = tc.clobberedRegs
@@ -111,8 +109,6 @@ func TestMachine_SetupPrologue(t *testing.T) {
m.SetupPrologue()
require.Equal(t, root, m.rootInstr)
m.Encode()
fmt.Println(hex.EncodeToString(ctx.buf))
fmt.Println(m.Format())
require.Equal(t, tc.exp, m.Format())
})
}
@@ -211,7 +207,7 @@ func TestMachine_SetupEpilogue(t *testing.T) {
} {
tc := tc
t.Run(tc.exp, func(t *testing.T) {
ctx, _, m := newSetupWithMockContext()
_, _, m := newSetupWithMockContext()
m.spillSlotSize = tc.spillSlotSize
m.clobberedRegs = tc.clobberedRegs
m.currentABI = &tc.abi
@@ -226,8 +222,6 @@ func TestMachine_SetupEpilogue(t *testing.T) {
require.Equal(t, root, m.rootInstr)
m.Encode()
fmt.Println(hex.EncodeToString(ctx.buf))
fmt.Println(m.Format())
require.Equal(t, tc.exp, m.Format())
})
}
@@ -268,13 +262,11 @@ func TestMachine_insertStackBoundsCheck(t *testing.T) {
} {
tc := tc
t.Run(tc.exp, func(t *testing.T) {
ctx, _, m := newSetupWithMockContext()
_, _, m := newSetupWithMockContext()
m.rootInstr = m.allocateInstr()
m.rootInstr.asNop0()
m.insertStackBoundsCheck(tc.requiredStackSize, m.rootInstr)
fmt.Println(m.Format())
m.Encode()
fmt.Println(hex.EncodeToString(ctx.buf))
require.Equal(t, tc.exp, m.Format())
})
}
@@ -282,8 +274,7 @@ func TestMachine_insertStackBoundsCheck(t *testing.T) {
func TestMachine_CompileStackGrowCallSequence(t *testing.T) {
_, _, m := newSetupWithMockContext()
src := m.CompileStackGrowCallSequence()
fmt.Println(hex.EncodeToString(src))
_ = m.CompileStackGrowCallSequence()
require.Equal(t, `
str x1, [x0, #0x60]

View File

@@ -1,7 +1,6 @@
package arm64
import (
"fmt"
"testing"
"github.com/tetratelabs/wazero/internal/engine/wazevo/backend/regalloc"
@@ -189,7 +188,6 @@ func TestMachine_insertStoreRegisterAt(t *testing.T) {
m.insertStoreRegisterAt(v1VReg, i2, after)
}
m.rootInstr = i1
fmt.Println(m.Format())
require.Equal(t, tc.expected, m.Format())
})
}
@@ -264,7 +262,6 @@ func TestMachine_insertReloadRegisterAt(t *testing.T) {
}
m.rootInstr = i1
fmt.Println(m.Format())
require.Equal(t, tc.expected, m.Format())
})
}

View File

@@ -1,7 +1,6 @@
package ssa
import (
"fmt"
"testing"
"github.com/tetratelabs/wazero/internal/testing/require"
@@ -604,11 +603,7 @@ func TestBuilder_LayoutBlocks(t *testing.T) {
tc.setup(b)
b.RunPasses() // LayoutBlocks() must be called after RunPasses().
fmt.Println("============ SSA before block layout ============")
fmt.Println(b.Format())
b.LayoutBlocks()
fmt.Println("============ SSA after block layout ============")
fmt.Println(b.Format())
var actual []BasicBlockID
for blk := b.BlockIteratorReversePostOrderBegin(); blk != nil; blk = b.BlockIteratorReversePostOrderNext() {

View File

@@ -130,7 +130,7 @@ func requireNoDiff(wasmBin []byte, checkMemory bool, requireNoError func(err err
func ensureMutableGlobalsMatch(compilerMod, interpreterMod api.Module, requireNoError func(err error)) {
ci, ii := compilerMod.(*wasm.ModuleInstance), interpreterMod.(*wasm.ModuleInstance)
for i := range ci.Globals {
for i := range ci.Globals[:len(ci.Globals)-1] { // The last global is the fuel, so we can ignore it.
cg := ci.Globals[i]
ig := ii.Globals[i]
if !cg.Type.Mutable {

View File

@@ -196,6 +196,10 @@ func Test_ensureMutableGlobalsMatch(t *testing.T) {
} {
t.Run(tc.name, func(t *testing.T) {
var actualErr error
// Append the "fuel" inserted by the fuzzer, which will be ignored by ensureMutableGlobalsMatch.
tc.im.Globals = append(tc.im.Globals, &wasm.GlobalInstance{Type: wasm.GlobalType{Mutable: true, ValType: wasm.ValueTypeI32}, Val: 10000})
tc.cm.Globals = append(tc.cm.Globals, &wasm.GlobalInstance{Type: wasm.GlobalType{Mutable: true, ValType: wasm.ValueTypeI32}, Val: 1})
ensureMutableGlobalsMatch(tc.cm, tc.im, func(err error) {
actualErr = err
})