Skip to content

Commit c0e39af

Browse files
committed
TestNotif*: fix
1. TestNotif should check not only for API level >= 6, but also for libseccomp >= 2.5.0. Use notifSupported() to fix. Same applies to TestNotifUnsupported. 2. Use t.Fatal[f] for places where the error is fatal (i.e. we can not continue the test). Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent 9d8dc90 commit c0e39af

File tree

1 file changed

+13
-37
lines changed

1 file changed

+13
-37
lines changed

seccomp_test.go

Lines changed: 13 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -793,35 +793,18 @@ func TestNotif(t *testing.T) {
793793
}
794794

795795
func subprocessNotif(t *testing.T) {
796-
// seccomp notification requires API level >= 6
797-
api, err := GetAPI()
798-
if err != nil {
799-
if !APILevelIsSupported() {
800-
t.Skipf("Skipping test: %s", err)
801-
}
802-
803-
t.Errorf("Error getting API level: %s", err)
804-
} else {
805-
t.Logf("Got API level %v", api)
806-
if api < 6 {
807-
err = SetAPI(6)
808-
if err != nil {
809-
t.Skipf("Skipping test: API level %d is less than 6 and could not set it to 6", api)
810-
return
811-
}
812-
}
796+
if err := notifSupported(); err != nil {
797+
t.Skip(err)
813798
}
814799

815800
arch, err := GetNativeArch()
816801
if err != nil {
817-
t.Errorf("Error in GetNativeArch(): %s", err)
818-
return
802+
t.Fatalf("Error in GetNativeArch(): %s", err)
819803
}
820804

821805
cwd, err := os.Getwd()
822806
if err != nil {
823-
t.Errorf("Error in Getwd(): %s", err)
824-
return
807+
t.Fatal(err)
825808
}
826809

827810
// Create a filter that only notifies on chdir. This way, while the
@@ -830,27 +813,27 @@ func subprocessNotif(t *testing.T) {
830813
// goroutine uses chdir.
831814
filter, err := NewFilter(ActAllow)
832815
if err != nil {
833-
t.Errorf("Error creating filter: %s", err)
816+
t.Fatalf("Error creating filter: %s", err)
834817
}
835818
defer filter.Release()
836819

837820
call, err := GetSyscallFromName("chdir")
838821
if err != nil {
839-
t.Errorf("Error getting syscall number: %s", err)
822+
t.Fatalf("Error getting syscall number: %s", err)
840823
}
841824

842825
err = filter.AddRule(call, ActNotify)
843826
if err != nil {
844-
t.Errorf("Error adding rule to log syscall: %s", err)
827+
t.Fatalf("Error adding rule to log syscall: %s", err)
845828
}
846829

847830
nonExistentPath, err := syscall.BytePtrFromString("/non-existent-path")
848831
if err != nil {
849-
t.Errorf("Error converting string: %s", err)
832+
t.Fatalf("Error converting string: %s", err)
850833
}
851834
currentWorkingDirectory, err := syscall.BytePtrFromString(cwd)
852835
if err != nil {
853-
t.Errorf("Error converting string: %s", err)
836+
t.Fatalf("Error converting string: %s", err)
854837
}
855838

856839
tests := []notifTest{
@@ -961,25 +944,18 @@ func TestNotifUnsupported(t *testing.T) {
961944
}
962945

963946
func subprocessNotifUnsupported(t *testing.T) {
964-
// seccomp notification requires API level >= 6
965-
api := 0
966-
if APILevelIsSupported() {
967-
api, err := GetAPI()
968-
if err != nil {
969-
t.Errorf("Error getting API level: %s", err)
970-
} else if api >= 6 {
971-
t.Skipf("Skipping test for old libseccomp support: API level %d is >= 6", api)
972-
}
947+
if err := notifSupported(); err == nil {
948+
t.Skip("seccomp notification is supported")
973949
}
974950

975951
filter, err := NewFilter(ActAllow)
976952
if err != nil {
977-
t.Errorf("Error creating filter: %s", err)
953+
t.Fatalf("Error creating filter: %s", err)
978954
}
979955
defer filter.Release()
980956

981957
_, err = filter.GetNotifFd()
982958
if err == nil {
983-
t.Errorf("Error: GetNotifFd was supposed to fail with API level %d", api)
959+
t.Error("GetNotifFd: got nil, want error")
984960
}
985961
}

0 commit comments

Comments
 (0)