Skip to content

Commit e5af786

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 6e53b43 commit e5af786

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
@@ -788,35 +788,18 @@ func TestNotif(t *testing.T) {
788788
execInSubprocess(t, subprocessNotif)
789789
}
790790
func subprocessNotif(t *testing.T) {
791-
// seccomp notification requires API level >= 6
792-
api, err := GetAPI()
793-
if err != nil {
794-
if !APILevelIsSupported() {
795-
t.Skipf("Skipping test: %s", err)
796-
}
797-
798-
t.Errorf("Error getting API level: %s", err)
799-
} else {
800-
t.Logf("Got API level %v", api)
801-
if api < 6 {
802-
err = SetAPI(6)
803-
if err != nil {
804-
t.Skipf("Skipping test: API level %d is less than 6 and could not set it to 6", api)
805-
return
806-
}
807-
}
791+
if err := notifSupported(); err != nil {
792+
t.Skip(err)
808793
}
809794

810795
arch, err := GetNativeArch()
811796
if err != nil {
812-
t.Errorf("Error in GetNativeArch(): %s", err)
813-
return
797+
t.Fatalf("Error in GetNativeArch(): %s", err)
814798
}
815799

816800
cwd, err := os.Getwd()
817801
if err != nil {
818-
t.Errorf("Error in Getwd(): %s", err)
819-
return
802+
t.Fatal(err)
820803
}
821804

822805
// Create a filter that only notifies on chdir. This way, while the
@@ -825,27 +808,27 @@ func subprocessNotif(t *testing.T) {
825808
// goroutine uses chdir.
826809
filter, err := NewFilter(ActAllow)
827810
if err != nil {
828-
t.Errorf("Error creating filter: %s", err)
811+
t.Fatalf("Error creating filter: %s", err)
829812
}
830813
defer filter.Release()
831814

832815
call, err := GetSyscallFromName("chdir")
833816
if err != nil {
834-
t.Errorf("Error getting syscall number: %s", err)
817+
t.Fatalf("Error getting syscall number: %s", err)
835818
}
836819

837820
err = filter.AddRule(call, ActNotify)
838821
if err != nil {
839-
t.Errorf("Error adding rule to log syscall: %s", err)
822+
t.Fatalf("Error adding rule to log syscall: %s", err)
840823
}
841824

842825
nonExistentPath, err := syscall.BytePtrFromString("/non-existent-path")
843826
if err != nil {
844-
t.Errorf("Error converting string: %s", err)
827+
t.Fatalf("Error converting string: %s", err)
845828
}
846829
currentWorkingDirectory, err := syscall.BytePtrFromString(cwd)
847830
if err != nil {
848-
t.Errorf("Error converting string: %s", err)
831+
t.Fatalf("Error converting string: %s", err)
849832
}
850833

851834
tests := []notifTest{
@@ -955,25 +938,18 @@ func TestNotifUnsupported(t *testing.T) {
955938
execInSubprocess(t, subprocessNotifUnsupported)
956939
}
957940
func subprocessNotifUnsupported(t *testing.T) {
958-
// seccomp notification requires API level >= 6
959-
api := 0
960-
if APILevelIsSupported() {
961-
api, err := GetAPI()
962-
if err != nil {
963-
t.Errorf("Error getting API level: %s", err)
964-
} else if api >= 6 {
965-
t.Skipf("Skipping test for old libseccomp support: API level %d is >= 6", api)
966-
}
941+
if err := notifSupported(); err == nil {
942+
t.Skip("seccomp notification is supported")
967943
}
968944

969945
filter, err := NewFilter(ActAllow)
970946
if err != nil {
971-
t.Errorf("Error creating filter: %s", err)
947+
t.Fatalf("Error creating filter: %s", err)
972948
}
973949
defer filter.Release()
974950

975951
_, err = filter.GetNotifFd()
976952
if err == nil {
977-
t.Errorf("Error: GetNotifFd was supposed to fail with API level %d", api)
953+
t.Error("GetNotifFd: got nil, want error")
978954
}
979955
}

0 commit comments

Comments
 (0)