diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2018-01-06 14:46:52 +0100 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2018-01-08 12:52:31 +0100 |
| commit | 402a0dc87e7d51812a18fa76feeb46d66efda175 (patch) | |
| tree | 03ae2832257917a68829137b0a504f6f8c2e499a /pkg/compiler/compiler_test.go | |
| parent | 93b4c6f135aeecbb756fe8c8a3d46c7a05412a54 (diff) | |
sys: support type aliases (aka typedefs)
Complex types that are often repeated can be given short type aliases using the
following syntax:
```
type identifier underlying_type
```
For example:
```
type signalno int32[0:65]
type net_port proc[20000, 4, int16be]
```
Then, type alias can be used instead of the underlying type in any contexts.
Underlying type needs to be described as if it's a struct field, that is,
with the base type if it's required. However, type alias can be used as syscall
arguments as well. Underlying types are currently restricted to integer types,
`ptr`, `ptr64`, `const`, `flags` and `proc` types.
Diffstat (limited to 'pkg/compiler/compiler_test.go')
| -rw-r--r-- | pkg/compiler/compiler_test.go | 49 |
1 files changed, 30 insertions, 19 deletions
diff --git a/pkg/compiler/compiler_test.go b/pkg/compiler/compiler_test.go index ac2d88167..f26c272e6 100644 --- a/pkg/compiler/compiler_test.go +++ b/pkg/compiler/compiler_test.go @@ -5,7 +5,6 @@ package compiler import ( "path/filepath" - "runtime" "testing" "github.com/google/syzkaller/pkg/ast" @@ -13,21 +12,33 @@ import ( ) func TestCompileAll(t *testing.T) { - eh := func(pos ast.Pos, msg string) { - t.Logf("%v: %v", pos, msg) - } - desc := ast.ParseGlob(filepath.Join("..", "..", "sys", "linux", "*.txt"), eh) - if desc == nil { - t.Fatalf("parsing failed") - } - glob := filepath.Join("..", "..", "sys", "linux", "*_"+runtime.GOARCH+".const") - consts := DeserializeConstsGlob(glob, eh) - if consts == nil { - t.Fatalf("reading consts failed") - } - prog := Compile(desc, consts, targets.List["linux"]["amd64"], eh) - if prog == nil { - t.Fatalf("compilation failed") + for os, arches := range targets.List { + os, arches := os, arches + t.Run(os, func(t *testing.T) { + t.Parallel() + eh := func(pos ast.Pos, msg string) { + t.Logf("%v: %v", pos, msg) + } + path := filepath.Join("..", "..", "sys", os) + desc := ast.ParseGlob(filepath.Join(path, "*.txt"), eh) + if desc == nil { + t.Fatalf("parsing failed") + } + for arch, target := range arches { + arch, target := arch, target + t.Run(arch, func(t *testing.T) { + t.Parallel() + consts := DeserializeConstsGlob(filepath.Join(path, "*_"+arch+".const"), eh) + if consts == nil { + t.Fatalf("reading consts failed") + } + prog := Compile(desc, consts, target, eh) + if prog == nil { + t.Fatalf("compilation failed") + } + }) + } + }) } } @@ -38,7 +49,7 @@ func TestErrors(t *testing.T) { "C1": 1, "C2": 2, } - target := targets.List["linux"]["amd64"] + target := targets.List["test"]["64"] for _, name := range []string{"errors.txt", "errors2.txt"} { name := name t.Run(name, func(t *testing.T) { @@ -69,7 +80,7 @@ func TestFuzz(t *testing.T) { for _, data := range inputs { desc := ast.Parse([]byte(data), "", eh) if desc != nil { - Compile(desc, consts, targets.List["linux"]["amd64"], eh) + Compile(desc, consts, targets.List["test"]["64"], eh) } } } @@ -96,7 +107,7 @@ s2 { if desc == nil { t.Fatal("failed to parse") } - p := Compile(desc, map[string]uint64{"__NR_foo": 1}, targets.List["linux"]["amd64"], nil) + p := Compile(desc, map[string]uint64{"__NR_foo": 1}, targets.List["test"]["64"], nil) if p == nil { t.Fatal("failed to compile") } |
