prog: test TransitivelyEnabledCalls on all targets

Fixes #585
This commit is contained in:
Dmitry Vyukov 2018-05-03 13:40:21 +02:00
parent 8180779d1d
commit d169e0f3c4
2 changed files with 44 additions and 26 deletions

View File

@ -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)
}

View File

@ -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() {