@@ -777,35 +777,18 @@ func TestNotif(t *testing.T) {
777777}
778778
779779func subprocessNotif (t * testing.T ) {
780- // seccomp notification requires API level >= 6
781- api , err := GetAPI ()
782- if err != nil {
783- if ! APILevelIsSupported () {
784- t .Skipf ("Skipping test: %s" , err )
785- }
786-
787- t .Errorf ("Error getting API level: %s" , err )
788- } else {
789- t .Logf ("Got API level %v" , api )
790- if api < 6 {
791- err = SetAPI (6 )
792- if err != nil {
793- t .Skipf ("Skipping test: API level %d is less than 6 and could not set it to 6" , api )
794- return
795- }
796- }
780+ if err := notifSupported (); err != nil {
781+ t .Skip (err )
797782 }
798783
799784 arch , err := GetNativeArch ()
800785 if err != nil {
801- t .Errorf ("Error in GetNativeArch(): %s" , err )
802- return
786+ t .Fatalf ("Error in GetNativeArch(): %s" , err )
803787 }
804788
805789 cwd , err := os .Getwd ()
806790 if err != nil {
807- t .Errorf ("Error in Getwd(): %s" , err )
808- return
791+ t .Fatal (err )
809792 }
810793
811794 // Create a filter that only notifies on chdir. This way, while the
@@ -814,27 +797,27 @@ func subprocessNotif(t *testing.T) {
814797 // goroutine uses chdir.
815798 filter , err := NewFilter (ActAllow )
816799 if err != nil {
817- t .Errorf ("Error creating filter: %s" , err )
800+ t .Fatalf ("Error creating filter: %s" , err )
818801 }
819802 defer filter .Release ()
820803
821804 call , err := GetSyscallFromName ("chdir" )
822805 if err != nil {
823- t .Errorf ("Error getting syscall number: %s" , err )
806+ t .Fatalf ("Error getting syscall number: %s" , err )
824807 }
825808
826809 err = filter .AddRule (call , ActNotify )
827810 if err != nil {
828- t .Errorf ("Error adding rule to log syscall: %s" , err )
811+ t .Fatalf ("Error adding rule to log syscall: %s" , err )
829812 }
830813
831814 nonExistentPath , err := syscall .BytePtrFromString ("/non-existent-path" )
832815 if err != nil {
833- t .Errorf ("Error converting string: %s" , err )
816+ t .Fatalf ("Error converting string: %s" , err )
834817 }
835818 currentWorkingDirectory , err := syscall .BytePtrFromString (cwd )
836819 if err != nil {
837- t .Errorf ("Error converting string: %s" , err )
820+ t .Fatalf ("Error converting string: %s" , err )
838821 }
839822
840823 tests := []notifTest {
@@ -945,25 +928,18 @@ func TestNotifUnsupported(t *testing.T) {
945928}
946929
947930func subprocessNotifUnsupported (t * testing.T ) {
948- // seccomp notification requires API level >= 6
949- api := 0
950- if APILevelIsSupported () {
951- api , err := GetAPI ()
952- if err != nil {
953- t .Errorf ("Error getting API level: %s" , err )
954- } else if api >= 6 {
955- t .Skipf ("Skipping test for old libseccomp support: API level %d is >= 6" , api )
956- }
931+ if err := notifSupported (); err == nil {
932+ t .Skip ("seccomp notification is supported" )
957933 }
958934
959935 filter , err := NewFilter (ActAllow )
960936 if err != nil {
961- t .Errorf ("Error creating filter: %s" , err )
937+ t .Fatalf ("Error creating filter: %s" , err )
962938 }
963939 defer filter .Release ()
964940
965941 _ , err = filter .GetNotifFd ()
966942 if err == nil {
967- t .Errorf ( "Error: GetNotifFd was supposed to fail with API level %d" , api )
943+ t .Error ( "GetNotifFd: got nil, want error" )
968944 }
969945}
0 commit comments