aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/tool
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2025-04-03 10:27:09 +0200
committerDmitry Vyukov <dvyukov@google.com>2025-04-03 20:00:12 +0000
commit6dc47718fdbb634024bcfe47cbc4d7cc781b4cc4 (patch)
tree27df5135e412a5f1cc816d418b75e8ce4e2d4a20 /pkg/tool
parentd7ae3a111bd75df44dda69b37da945b50d5133e2 (diff)
tools/syz-declextract: allow to run on subset of arches
This may be useful for downstream kernels that only build and are supposed to be used with a subset of arches. Some esoteric arches may be broken on such kernels. Allow to ignore them.
Diffstat (limited to 'pkg/tool')
-rw-r--r--pkg/tool/flags.go26
-rw-r--r--pkg/tool/flags_test.go39
2 files changed, 65 insertions, 0 deletions
diff --git a/pkg/tool/flags.go b/pkg/tool/flags.go
index ec0d3015f..c74026540 100644
--- a/pkg/tool/flags.go
+++ b/pkg/tool/flags.go
@@ -9,9 +9,11 @@ import (
"errors"
"flag"
"fmt"
+ "sort"
"strings"
"github.com/google/syzkaller/pkg/log"
+ "github.com/google/syzkaller/sys/targets"
)
type Flag struct {
@@ -50,6 +52,30 @@ func ParseFlags(set *flag.FlagSet, args []string) error {
return nil
}
+func ParseArchList(OS, archList string) ([]string, error) {
+ allArches := targets.List[OS]
+ if allArches == nil {
+ return nil, fmt.Errorf("bad OS %q", OS)
+ }
+ archMap := make(map[string]bool)
+ if archList != "" {
+ for _, arch := range strings.Split(archList, ",") {
+ if allArches[arch] == nil {
+ return nil, fmt.Errorf("bad arch %q for OS %q in arches flag", arch, OS)
+ }
+ archMap[arch] = true
+ }
+ }
+ var arches []string
+ for arch := range allArches {
+ if len(archMap) == 0 || archMap[arch] {
+ arches = append(arches, arch)
+ }
+ }
+ sort.Strings(arches)
+ return arches, nil
+}
+
const optionalFlag = "optional"
func serializeFlags(flags []Flag) string {
diff --git a/pkg/tool/flags_test.go b/pkg/tool/flags_test.go
index 0503c48fc..df642bca6 100644
--- a/pkg/tool/flags_test.go
+++ b/pkg/tool/flags_test.go
@@ -4,6 +4,7 @@
package tool
import (
+ "errors"
"flag"
"fmt"
"io"
@@ -11,6 +12,7 @@ import (
"testing"
"github.com/google/go-cmp/cmp"
+ "github.com/stretchr/testify/assert"
)
func TestParseFlags(t *testing.T) {
@@ -84,3 +86,40 @@ func TestCfgsFlagAlreadySet(t *testing.T) {
t.Errorf("cfgs.Set got: nil, want: error")
}
}
+
+func TestParseArchList(t *testing.T) {
+ type Test struct {
+ OS string
+ In string
+ Out []string
+ Err error
+ }
+ tests := []Test{
+ {
+ OS: "foo",
+ Err: errors.New(`bad OS "foo"`),
+ },
+ {
+ OS: "linux",
+ In: "amd64,bar",
+ Err: errors.New(`bad arch "bar" for OS "linux" in arches flag`),
+ },
+ {
+ OS: "linux",
+ In: "",
+ Out: []string{"386", "amd64", "arm", "arm64", "mips64le", "ppc64le", "riscv64", "s390x"},
+ },
+ {
+ OS: "linux",
+ In: "ppc64le,386",
+ Out: []string{"386", "ppc64le"},
+ },
+ }
+ for i, test := range tests {
+ t.Run(fmt.Sprint(i), func(t *testing.T) {
+ got, err := ParseArchList(test.OS, test.In)
+ assert.Equal(t, err, test.Err)
+ assert.Equal(t, got, test.Out)
+ })
+ }
+}