[PATCH testsuite 3/3] tests/infiniband*: simplify test activation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Use Test::More and skip_all to enable/disable these tests if they are
configured instead of doing this in the Makefile via grep.

Signed-off-by: Ondrej Mosnacek <omosnace@xxxxxxxxxx>
---
 Vagrantfile                   |  1 +
 tests/Makefile                | 11 ++-------
 tests/infiniband_endport/test | 39 ++++++++++++++++++-------------
 tests/infiniband_pkey/test    | 44 ++++++++++++++++++++---------------
 4 files changed, 51 insertions(+), 44 deletions(-)

diff --git a/Vagrantfile b/Vagrantfile
index 6f7675f..682b805 100644
--- a/Vagrantfile
+++ b/Vagrantfile
@@ -89,6 +89,7 @@ EOF
       e2fsprogs \
       jfsutils \
       dosfstools \
+      rdma-core-devel \
       #{kernel_pkgs}
 
     #{extra_commands}
diff --git a/tests/Makefile b/tests/Makefile
index 5998a9f..74df247 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -27,7 +27,8 @@ SUBDIRS:= domain_trans entrypoint execshare exectrace execute_no_trans \
 	task_setnice task_setscheduler task_getscheduler task_getsid \
 	task_getpgid task_setpgid file ioctl capable_file capable_net \
 	capable_sys dyntrans dyntrace bounds nnp_nosuid mmap unix_socket \
-	inet_socket overlay checkreqprot mqueue mac_admin atsecure
+	inet_socket overlay checkreqprot mqueue mac_admin atsecure \
+	infiniband_endport infiniband_pkey
 
 ifeq ($(shell grep -q cap_userns $(POLDEV)/include/support/all_perms.spt && echo true),true)
 ifneq ($(shell ./kvercmp $$(uname -r) 4.7),-1)
@@ -82,14 +83,6 @@ endif # POL_VERS
 endif # POL_TYPE
 endif # MAX_KERNEL_POLICY
 
-ifeq ($(shell grep "^SELINUX_INFINIBAND_ENDPORT_TEST=" infiniband_endport/ibendport_test.conf | cut -d'=' -f 2),1)
-SUBDIRS += infiniband_endport
-endif
-
-ifeq ($(shell grep "^SELINUX_INFINIBAND_PKEY_TEST=" infiniband_pkey/ibpkey_test.conf | cut -d'=' -f 2),1)
-SUBDIRS += infiniband_pkey
-endif
-
 ifneq ($(shell ./kvercmp $$(uname -r) 5.2),-1)
 SUBDIRS += cgroupfs_label
 endif
diff --git a/tests/infiniband_endport/test b/tests/infiniband_endport/test
index f071fbc..c55ce84 100755
--- a/tests/infiniband_endport/test
+++ b/tests/infiniband_endport/test
@@ -1,25 +1,32 @@
 #!/usr/bin/perl
 
-use Test;
+use Test::More;
 
-BEGIN { plan tests => 3 }
+my %conf;
 
-$basedir = $0;
-$basedir =~ s|(.*)/[^/]*|$1|;
+BEGIN {
+    $basedir = $0;
+    $basedir =~ s|(.*)/[^/]*|$1|;
+
+    $confpath = $basedir . "/ibendport_test.conf";
+    open( $f, $confpath ) or die("Couldn't open $confpath");
+    while ( $r = <$f> ) {
+        if ( $r =~ /^\s*#/ || $r =~ /^\s*$/ ) { next; }
+        chomp $r;
+        ( $k, $v ) = split( /=/, $r );
+        $conf{$k} = $v;
+    }
+    close($f);
 
-my %conf;
-my $confpath = $basedir . "/ibendport_test.conf";
-open( $f, $confpath ) or die("Couldn't open ibtest.conf");
-while ( $r = <$f> ) {
-    if ( $r =~ /^\s*#/ || $r =~ /^\s*$/ ) { next; }
-    chomp $r;
-    ( $k, $v ) = split( /=/, $r );
-    $conf{$k} = $v;
+    # Verify that we really want to run these tests.
+    if ( $conf{SELINUX_INFINIBAND_ENDPORT_TEST} eq 1 ) {
+        plan tests => 2;
+    }
+    else {
+        plan skip_all => "test not configured";
+    }
 }
 
-# verify that we really want to run these tests
-ok( $conf{SELINUX_INFINIBAND_ENDPORT_TEST} eq 1 );
-
 @allowed_device_port =
   split( /,/, $conf{SELINUX_INFINIBAND_ENDPORT_TEST_ALLOWED} );
 @denied_device_port =
@@ -36,7 +43,7 @@ foreach (@allowed_device_port) {
         last;
     }
 }
-ok( $result, 0 );
+ok( $result eq 0 );
 
 foreach (@denied_device_port) {
     @dev_port_pair = split( / /, $_ );
diff --git a/tests/infiniband_pkey/test b/tests/infiniband_pkey/test
index 382c259..e5d2efb 100755
--- a/tests/infiniband_pkey/test
+++ b/tests/infiniband_pkey/test
@@ -1,25 +1,31 @@
 #!/usr/bin/perl
 
-use Test;
+use Test::More;
 
-BEGIN { plan tests => 4 }
+my %conf;
 
-$basedir = $0;
-$basedir =~ s|(.*)/[^/]*|$1|;
+BEGIN {
+    $basedir = $0;
+    $basedir =~ s|(.*)/[^/]*|$1|;
 
-my %conf;
-$confpath = $basedir . "/ibpkey_test.conf";
-open( $f, $confpath ) or die("Couldn't open $confpath");
-while ( $r = <$f> ) {
-    if ( $r =~ /^\s*#/ || $r =~ /^\s*$/ ) { next; }
-    chomp $r;
-    ( $k, $v ) = split( /=/, $r );
-    $conf{$k} = $v;
-}
-close($f);
+    $confpath = $basedir . "/ibpkey_test.conf";
+    open( $f, $confpath ) or die("Couldn't open $confpath");
+    while ( $r = <$f> ) {
+        if ( $r =~ /^\s*#/ || $r =~ /^\s*$/ ) { next; }
+        chomp $r;
+        ( $k, $v ) = split( /=/, $r );
+        $conf{$k} = $v;
+    }
+    close($f);
 
-# Verify that we really want to run these tests.
-ok( $conf{SELINUX_INFINIBAND_PKEY_TEST} eq 1 );
+    # Verify that we really want to run these tests.
+    if ( $conf{SELINUX_INFINIBAND_PKEY_TEST} eq 1 ) {
+        plan tests => 3;
+    }
+    else {
+        plan skip_all => "test not configured";
+    }
+}
 
 $device = $conf{SELINUX_INFINIBAND_PKEY_TEST_DEV};
 $port   = $conf{SELINUX_INFINIBAND_PKEY_TEST_PORT};
@@ -47,7 +53,7 @@ foreach (@unlabeled_pkeys) {
     }
 }
 if (@unlabeled_pkeys) {
-    ok( $result, 0 );
+    ok( $result eq 0 );
 }
 else {
     ok(1);
@@ -69,7 +75,7 @@ foreach (@unlabeled_pkeys) {
     }
 }
 if (@unlabeled_pkeys) {
-    ok( $result >> 8, 13 );
+    ok( $result >> 8 eq 13 );
 }
 else {
     ok(1);
@@ -83,7 +89,7 @@ foreach (@labeled_pkeys) {
     }
 }
 if (@labeled_pkeys) {
-    ok( $result >> 8, 13 );
+    ok( $result >> 8 eq 13 );
 }
 else {
     ok(1);
-- 
2.39.2




[Index of Archives]     [Selinux Refpolicy]     [Linux SGX]     [Fedora Users]     [Fedora Desktop]     [Yosemite Photos]     [Yosemite Camping]     [Yosemite Campsites]     [KDE Users]     [Gnome Users]

  Powered by Linux