diff mbox series

[testsuite,2/2] tests: check more thoroughly for SCTP support

Message ID 20220413164810.2122305-3-omosnace@redhat.com (mailing list archive)
State Accepted
Delegated to: Ondrej Mosnáček
Headers show
Series Make SCTP and Bluetooth support optional | expand

Commit Message

Ondrej Mosnacek April 13, 2022, 4:48 p.m. UTC
1. Add SCTP support checking also to extended_socket_class test, where
   it was missing previously.
2. Attempt to explicitly load the 'sctp' module as part of the check to
   ensure that SCTP support is activated and detected also when it is
   excluded from autoloading (as is the case e.g. on RHEL 8+).

Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com>
---
 tests/extended_socket_class/test | 77 ++++++++++++++++++--------------
 tests/sctp/test                  |  4 +-
 2 files changed, 46 insertions(+), 35 deletions(-)
diff mbox series

Patch

diff --git a/tests/extended_socket_class/test b/tests/extended_socket_class/test
index 022993d..86c706b 100755
--- a/tests/extended_socket_class/test
+++ b/tests/extended_socket_class/test
@@ -3,14 +3,22 @@ 
 use Test;
 
 BEGIN {
-    $test_count     = 14;
+    $test_count     = 6;
     $test_bluetooth = 0;
+    $test_sctp      = 0;
+
+    # check if SCTP is enabled
+    if ( system("modprobe sctp 2>/dev/null && checksctp 2>/dev/null") eq 0 ) {
+        $test_count += 8;
+        $test_sctp = 1;
+    }
 
     # check if Bluetooth is supported (commonly disabled e.g. on s390x)
     if ( system("modprobe bluetooth 2>/dev/null") eq 0 ) {
         $test_count += 2;
         $test_bluetooth = 1;
     }
+
     plan tests => $test_count;
 }
 
@@ -46,53 +54,56 @@  ok($result);
 # Restore to the kernel defaults - no one allowed to create ICMP sockets.
 system("echo 1 0 > /proc/sys/net/ipv4/ping_group_range");
 
-# Verify that test_sctp_socket_t can create an IPv4 stream SCTP socket.
-$result = system(
-    "runcon -t test_sctp_socket_t -- $basedir/sockcreate inet stream sctp 2>&1"
-);
-ok( $result, 0 );
+if ($test_sctp) {
 
-# Verify that test_no_sctp_socket_t cannot create an IPv4 stream SCTP socket.
-$result = system(
+    # Verify that test_sctp_socket_t can create an IPv4 stream SCTP socket.
+    $result = system(
+"runcon -t test_sctp_socket_t -- $basedir/sockcreate inet stream sctp 2>&1"
+    );
+    ok( $result, 0 );
+
+   # Verify that test_no_sctp_socket_t cannot create an IPv4 stream SCTP socket.
+    $result = system(
 "runcon -t test_no_sctp_socket_t -- $basedir/sockcreate inet stream sctp 2>&1"
-);
-ok($result);
+    );
+    ok($result);
 
-# Verify that test_sctp_socket_t can create an IPv4 seqpacket SCTP socket.
-$result = system(
+    # Verify that test_sctp_socket_t can create an IPv4 seqpacket SCTP socket.
+    $result = system(
 "runcon -t test_sctp_socket_t -- $basedir/sockcreate inet seqpacket sctp 2>&1"
-);
-ok( $result, 0 );
+    );
+    ok( $result, 0 );
 
 # Verify that test_no_sctp_socket_t cannot create an IPv4 seqpacket SCTP socket.
-$result = system(
+    $result = system(
 "runcon -t test_no_sctp_socket_t -- $basedir/sockcreate inet seqpacket sctp 2>&1"
-);
-ok($result);
+    );
+    ok($result);
 
-# Verify that test_sctp_socket_t can create an IPv6 stream SCTP socket.
-$result = system(
-    "runcon -t test_sctp_socket_t -- $basedir/sockcreate inet6 stream sctp 2>&1"
-);
-ok( $result, 0 );
+    # Verify that test_sctp_socket_t can create an IPv6 stream SCTP socket.
+    $result = system(
+"runcon -t test_sctp_socket_t -- $basedir/sockcreate inet6 stream sctp 2>&1"
+    );
+    ok( $result, 0 );
 
-# Verify that test_no_sctp_socket_t cannot create an IPv6 stream SCTP socket.
-$result = system(
+   # Verify that test_no_sctp_socket_t cannot create an IPv6 stream SCTP socket.
+    $result = system(
 "runcon -t test_no_sctp_socket_t -- $basedir/sockcreate inet6 stream sctp 2>&1"
-);
-ok($result);
+    );
+    ok($result);
 
-# Verify that test_sctp_socket_t can create an IPv6 seqpacket SCTP socket.
-$result = system(
+    # Verify that test_sctp_socket_t can create an IPv6 seqpacket SCTP socket.
+    $result = system(
 "runcon -t test_sctp_socket_t -- $basedir/sockcreate inet6 seqpacket sctp 2>&1"
-);
-ok( $result, 0 );
+    );
+    ok( $result, 0 );
 
 # Verify that test_no_sctp_socket_t cannot create an IPv6 seqpacket SCTP socket.
-$result = system(
+    $result = system(
 "runcon -t test_no_sctp_socket_t -- $basedir/sockcreate inet6 seqpacket sctp 2>&1"
-);
-ok($result);
+    );
+    ok($result);
+}
 
 if ($test_bluetooth) {
 
diff --git a/tests/sctp/test b/tests/sctp/test
index 0f017e8..1258de4 100755
--- a/tests/sctp/test
+++ b/tests/sctp/test
@@ -28,8 +28,8 @@  BEGIN {
         $v = " ";
     }
 
-    # check if sctp enabled
-    if ( system("checksctp 2> /dev/null") != 0 ) {
+    # check if SCTP is enabled
+    if ( system("modprobe sctp 2>/dev/null && checksctp 2>/dev/null") != 0 ) {
         plan skip_all => "SCTP not supported";
     }
     else {