diff options
| author | Jiao, Joey <quic_jiangenj@quicinc.com> | 2024-10-10 15:08:01 +0800 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2024-11-13 07:42:55 +0000 |
| commit | c352ddf895e4f5a5b7e8f7caa37f476c6926326f (patch) | |
| tree | 3554710b5e1fbc4b381ee4f4775e164a842a020c /tools/syz-db/syz-db_test.go | |
| parent | 617b12b1032fb934c8af6f425777d72c92011805 (diff) | |
tools/syz-db: add rm function to remove match syscalls
Ex:
bin/syz-db rm corpus.db "ioctl\$some"
Diffstat (limited to 'tools/syz-db/syz-db_test.go')
| -rw-r--r-- | tools/syz-db/syz-db_test.go | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/tools/syz-db/syz-db_test.go b/tools/syz-db/syz-db_test.go new file mode 100644 index 000000000..56aa055c6 --- /dev/null +++ b/tools/syz-db/syz-db_test.go @@ -0,0 +1,52 @@ +// Copyright (c) Qualcomm Innovation Center, Inc. All rights reserved +// Copyright 2024 syzkaller project authors. All rights reserved. +// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. + +package main + +import ( + "fmt" + "os" + "strings" + "testing" + + "github.com/google/syzkaller/pkg/db" + "github.com/google/syzkaller/pkg/osutil" + "github.com/google/syzkaller/prog" + "github.com/google/syzkaller/sys/targets" + "github.com/stretchr/testify/assert" +) + +func TestDBRemoveMatchLine(t *testing.T) { + fn, err := osutil.TempFile("syzkaller.test.db") + if err != nil { + t.Fatal(err) + } + defer os.Remove(fn) + db1, err := db.Open(fn, false) + if err != nil { + t.Fatalf("failed to open db: %v", err) + } + input := []string{ + "r0 = open$dir(&(0x7f0000000000), 0x161840, 0x162)", + "ioctl$BTRFS_IOC_DEFRAG(r0, 0x50009402, 0x0)", + "close(r0)", + } + want := []string{ + "ioctl$BTRFS_IOC_DEFRAG(0xffffffffffffffff, 0x50009402, 0x0)", + "close(0xffffffffffffffff)", + } + db1.Save("rm", []byte(strings.Join(input, "\n")), 0) + db1.Flush() + target, err := prog.GetTarget(targets.Linux, targets.AMD64) + if err != nil { + t.Fatal(err) + } + rm(fn, "open$dir", target) + db1, err = db.Open(fn, false) + if err != nil { + t.Fatalf("failed to open db: %v", err) + } + expected := fmt.Sprintf("%s\n", strings.Join(want, "\n")) + assert.Equal(t, expected, string(db1.Records["rm"].Val)) +} |
