aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2018-05-03 13:40:21 +0200
committerDmitry Vyukov <dvyukov@google.com>2018-05-03 13:40:21 +0200
commitd169e0f3c4b76b7ca0edbb69130c17a2277984e9 (patch)
tree86c194c0bea9556333db7f1f6d66727af539c5b9
parent8180779d1d06e1cdf27882f50e7f72650f95797d (diff)
prog: test TransitivelyEnabledCalls on all targets
Fixes #585
-rw-r--r--prog/decl_test.go60
-rw-r--r--prog/export_test.go10
2 files changed, 44 insertions, 26 deletions
diff --git a/prog/decl_test.go b/prog/decl_test.go
index 4539be2fb..65230c7ca 100644
--- a/prog/decl_test.go
+++ b/prog/decl_test.go
@@ -4,28 +4,50 @@
package prog
import (
- "runtime"
"strings"
"testing"
)
func TestResourceCtors(t *testing.T) {
- target, err := GetTarget("linux", runtime.GOARCH)
- if err != nil {
- t.Fatal(err)
- }
- for _, c := range target.Syscalls {
- for _, res := range c.inputResources() {
- if len(target.calcResourceCtors(res.Desc.Kind, true)) == 0 {
- t.Errorf("call %v requires input resource %v, but there are no calls that can create this resource", c.Name, res.Desc.Name)
+ testEachTarget(t, func(t *testing.T, target *Target) {
+ for _, c := range target.Syscalls {
+ for _, res := range c.inputResources() {
+ if len(target.calcResourceCtors(res.Desc.Kind, true)) == 0 {
+ t.Errorf("call %v requires input resource %v,"+
+ " but there are no calls that can create this resource",
+ c.Name, res.Desc.Name)
+ }
}
}
- }
+ })
}
func TestTransitivelyEnabledCalls(t *testing.T) {
+ testEachTarget(t, func(t *testing.T, target *Target) {
+ calls := make(map[*Syscall]bool)
+ for _, c := range target.Syscalls {
+ calls[c] = true
+ }
+ if trans, disabled := target.TransitivelyEnabledCalls(calls); len(disabled) != 0 {
+ for c, reason := range disabled {
+ t.Logf("disabled %v: %v", c.Name, reason)
+ }
+ t.Fatalf("can't create some resource")
+ } else if len(trans) != len(calls) {
+ t.Fatalf("transitive syscalls are not full")
+ } else {
+ for c, ok := range trans {
+ if !ok {
+ t.Fatalf("syscalls %v is false in transitive map", c.Name)
+ }
+ }
+ }
+ })
+}
+
+func TestTransitivelyEnabledCallsLinux(t *testing.T) {
t.Parallel()
- target, err := GetTarget("linux", runtime.GOARCH)
+ target, err := GetTarget("linux", "amd64")
if err != nil {
t.Fatal(err)
}
@@ -33,20 +55,6 @@ func TestTransitivelyEnabledCalls(t *testing.T) {
for _, c := range target.Syscalls {
calls[c] = true
}
- if trans, disabled := target.TransitivelyEnabledCalls(calls); len(disabled) != 0 {
- for c, reason := range disabled {
- t.Logf("disabled %v: %v", c.Name, reason)
- }
- t.Fatalf("can't create some resource")
- } else if len(trans) != len(calls) {
- t.Fatalf("transitive syscalls are not full")
- } else {
- for c, ok := range trans {
- if !ok {
- t.Fatalf("syscalls %v is false in transitive map", c.Name)
- }
- }
- }
delete(calls, target.SyscallMap["epoll_create"])
if trans, disabled := target.TransitivelyEnabledCalls(calls); len(disabled) != 0 || len(trans) != len(calls) {
t.Fatalf("still must be able to create epoll fd with epoll_create1")
@@ -74,7 +82,7 @@ func TestTransitivelyEnabledCalls(t *testing.T) {
func TestClockGettime(t *testing.T) {
t.Parallel()
- target, err := GetTarget("linux", runtime.GOARCH)
+ target, err := GetTarget("linux", "amd64")
if err != nil {
t.Fatal(err)
}
diff --git a/prog/export_test.go b/prog/export_test.go
index e22c903f4..015d4f319 100644
--- a/prog/export_test.go
+++ b/prog/export_test.go
@@ -49,6 +49,16 @@ func initTest(t *testing.T) (*Target, rand.Source, int) {
return initRandomTargetTest(t, "linux", "amd64")
}
+func testEachTarget(t *testing.T, fn func(t *testing.T, target *Target)) {
+ for _, target := range AllTargets() {
+ target := target
+ t.Run(fmt.Sprintf("%v/%v", target.OS, target.Arch), func(t *testing.T) {
+ t.Parallel()
+ fn(t, target)
+ })
+ }
+}
+
func testEachTargetRandom(t *testing.T, fn func(t *testing.T, target *Target, rs rand.Source, iters int)) {
iters := 10000
if testing.Short() {