From dcb1eebb7ffdd179de39e7cb89ca085368ee69d5 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Mon, 18 Jun 2018 19:45:48 +0200 Subject: prog: more precise constructor calculation Currently a call that both accepts and creates a resource self-justifies itself and thus is always enabled. A good example is accept call. Accepts are always self-enable and thus enable all other syscalls that work with the socket. Calculate TransitivelyEnabledCalls in the opposite direction to resolve this. Start with empty set of enable syscalls, then enable syscalls that don't accept any resources, then enable syscalls that accept resources created by the previous batch of syscalls, and so on. This prevents self-enablement of accept. --- prog/decl_test.go | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) (limited to 'prog/decl_test.go') diff --git a/prog/decl_test.go b/prog/decl_test.go index 0f727aa7f..ac353e66a 100644 --- a/prog/decl_test.go +++ b/prog/decl_test.go @@ -14,11 +14,11 @@ func TestResourceCtors(t *testing.T) { } 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 { + for _, res := range target.inputResources(c) { + if len(target.calcResourceCtors(res.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) + c.Name, res.Name) } } } @@ -31,18 +31,29 @@ func TestTransitivelyEnabledCalls(t *testing.T) { for _, c := range target.Syscalls { calls[c] = true } - if trans, disabled := target.TransitivelyEnabledCalls(calls); len(disabled) != 0 { + enabled, disabled := target.TransitivelyEnabledCalls(calls) + for c, ok := range enabled { + if !ok { + t.Fatalf("syscalls %v is false in enabled map", c.Name) + } + } + if target.OS == "test" { + for c := range enabled { + if c.CallName == "unsupported" { + t.Errorf("call %v is not disabled", c.Name) + } + } for c, reason := range disabled { - t.Logf("disabled %v: %v", c.Name, reason) + if c.CallName != "unsupported" { + t.Errorf("call %v is disabled: %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) - } + if len(enabled) != len(target.Syscalls) { + t.Errorf("some calls are disabled: %v/%v", len(enabled), len(target.Syscalls)) + } + for c, reason := range disabled { + t.Errorf("disabled %v: %v", c.Name, reason) } } }) -- cgit mrf-deployment