aboutsummaryrefslogtreecommitdiffstats
path: root/prog
diff options
context:
space:
mode:
authorAleksandr Nogikh <nogikh@google.com>2025-08-27 12:04:13 +0200
committerAleksandr Nogikh <nogikh@google.com>2025-11-03 15:02:52 +0000
commit791d18fa26e3c5b62656e16b65aac5b748fcf8fc (patch)
treee8c7f749fcab1269c68d6be9fdd034fdae387a7f /prog
parente6c64ba827e8dc077b172b714151ef9e21b6f3ef (diff)
prog: take multiple serialization flags
Refactor Prog.Serialize() to accept a variadic list of flags. For now, two are supported: 1) Verbose (equal to SerializeVerbose()). 2) SkipImages (don't serialize fs images).
Diffstat (limited to 'prog')
-rw-r--r--prog/encoding.go52
-rw-r--r--prog/encoding_test.go13
2 files changed, 48 insertions, 17 deletions
diff --git a/prog/encoding.go b/prog/encoding.go
index 5d2750630..3bae29316 100644
--- a/prog/encoding.go
+++ b/prog/encoding.go
@@ -26,21 +26,30 @@ func (p *Prog) String() string {
return buf.String()
}
-func (p *Prog) Serialize() []byte {
- return p.serialize(false)
-}
+type SerializeFlag int
-func (p *Prog) SerializeVerbose() []byte {
- return p.serialize(true)
-}
+const (
+ // Include all field values, even if they have default values.
+ Verbose SerializeFlag = 0
+ // Don't serialize compressed fs images.
+ // This is used in coverage report generation to prevent the bloating of the resulting HTML file.
+ SkipImages SerializeFlag = 1
+)
-func (p *Prog) serialize(verbose bool) []byte {
+func (p *Prog) Serialize(flags ...SerializeFlag) []byte {
p.debugValidate()
ctx := &serializer{
- target: p.Target,
- buf: new(bytes.Buffer),
- vars: make(map[*ResultArg]int),
- verbose: verbose,
+ target: p.Target,
+ buf: new(bytes.Buffer),
+ vars: make(map[*ResultArg]int),
+ }
+ for _, flag := range flags {
+ switch flag {
+ case Verbose:
+ ctx.verbose = true
+ case SkipImages:
+ ctx.skipImages = true
+ }
}
for _, c := range p.Calls {
ctx.call(c)
@@ -48,12 +57,17 @@ func (p *Prog) serialize(verbose bool) []byte {
return ctx.buf.Bytes()
}
+func (p *Prog) SerializeVerbose() []byte {
+ return p.Serialize(Verbose)
+}
+
type serializer struct {
- target *Target
- buf *bytes.Buffer
- vars map[*ResultArg]int
- varSeq int
- verbose bool
+ target *Target
+ buf *bytes.Buffer
+ vars map[*ResultArg]int
+ varSeq int
+ verbose bool
+ skipImages bool
}
func (ctx *serializer) print(text string) {
@@ -154,7 +168,11 @@ func (a *DataArg) serialize(ctx *serializer) {
}
data := a.Data()
if typ.IsCompressed() {
- serializeCompressedData(ctx.buf, data)
+ if ctx.skipImages {
+ ctx.printf(`"<<IMAGE>>"`)
+ } else {
+ serializeCompressedData(ctx.buf, data)
+ }
} else {
// Statically typed data will be padded with 0s during deserialization,
// so we can strip them here for readability always. For variable-size
diff --git a/prog/encoding_test.go b/prog/encoding_test.go
index a577c5be5..130740df7 100644
--- a/prog/encoding_test.go
+++ b/prog/encoding_test.go
@@ -12,6 +12,7 @@ import (
"testing"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func setToArray(s map[string]struct{}) []string {
@@ -570,3 +571,15 @@ func TestHasNext(t *testing.T) {
}
}
}
+
+// nolint: lll
+func TestDeserializeSkipImage(t *testing.T) {
+ target := initTargetTest(t, "linux", "amd64")
+ p, err := target.Deserialize([]byte(`
+syz_mount_image$ext4(&(0x7f0000000080)='ext4\x00', &(0x7f00000000c0)='./file0\x00', 0x0, &(0x7f0000000100), 0x1, 0x71, &(0x7f0000000140)="$eJzszrENAVAUBdDrLyASnUIYwA5GESWdiljJDiYwgg0UWs1XfArfABI5J3kvue827/I4Tc6zpA6T2tntD5vVtu3wl0qSUZJxkum85duydYNXf70f1+/59b8AAAAAAAAAwLeSRZ8/Ds8AAAD//9ZiI98=")
+`), Strict)
+ require.NoError(t, err)
+ assert.Equal(t, `syz_mount_image$ext4(&(0x7f0000000080)='ext4\x00', &(0x7f00000000c0)='./file0\x00', 0x0, &(0x7f0000000100), 0x1, 0x71, &(0x7f0000000140)="<<IMAGE>>")
+`,
+ string(p.Serialize(SkipImages)))
+}