[PATCH testsuite 23/24] tests/vsock_socket: use modprobe to check vsock availability

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

 



On Fedora sysadm_t is not allowed to create vsock sockets, so the check
would fail. Since modprobing the relevant kernel modules is also a
reliable way to check the general vsock support, use that instead of the
more direct check.

Signed-off-by: Ondrej Mosnacek <omosnace@xxxxxxxxxx>
---
 tests/vsock_socket/.gitignore    |  1 -
 tests/vsock_socket/Makefile      |  2 +-
 tests/vsock_socket/check_vsock.c | 47 --------------------------------
 tests/vsock_socket/test          | 11 ++------
 4 files changed, 4 insertions(+), 57 deletions(-)
 delete mode 100644 tests/vsock_socket/check_vsock.c

diff --git a/tests/vsock_socket/.gitignore b/tests/vsock_socket/.gitignore
index 13eeb1b..f2ad853 100644
--- a/tests/vsock_socket/.gitignore
+++ b/tests/vsock_socket/.gitignore
@@ -1,3 +1,2 @@
 client
 server
-check_vsock
diff --git a/tests/vsock_socket/Makefile b/tests/vsock_socket/Makefile
index bf6ec7b..5266096 100644
--- a/tests/vsock_socket/Makefile
+++ b/tests/vsock_socket/Makefile
@@ -1,4 +1,4 @@
-TARGETS=client server check_vsock
+TARGETS=client server
 
 LDLIBS+= -lselinux
 
diff --git a/tests/vsock_socket/check_vsock.c b/tests/vsock_socket/check_vsock.c
deleted file mode 100644
index 6eecd62..0000000
--- a/tests/vsock_socket/check_vsock.c
+++ /dev/null
@@ -1,47 +0,0 @@
-#include <errno.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/un.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <unistd.h>
-
-// Must be included after sys/socket.h
-#include <linux/vm_sockets.h>
-
-int main(int argc, char **argv)
-{
-	int sock;
-	struct sockaddr_vm svm;
-
-	sock = socket(AF_VSOCK, SOCK_STREAM, 0);
-	if (sock < 0) {
-		if (errno == EAFNOSUPPORT) {
-			// AF_VSOCK not supported
-			exit(2);
-		} else {
-			perror("socket");
-			exit(1);
-		}
-	}
-
-	bzero(&svm, sizeof(svm));
-	svm.svm_family = AF_VSOCK;
-	svm.svm_port = VMADDR_PORT_ANY;
-	svm.svm_cid = VMADDR_CID_LOCAL;
-
-	if (bind(sock, (struct sockaddr *)&svm, sizeof(svm)) < 0) {
-		if (errno == EADDRNOTAVAIL) {
-			// vsock_loopback not supported
-			close(sock);
-			exit(3);
-		} else {
-			perror("bind");
-			close(sock);
-			exit(1);
-		}
-	}
-
-	close(sock);
-	exit(0);
-}
diff --git a/tests/vsock_socket/test b/tests/vsock_socket/test
index f05b972..9a0d72c 100755
--- a/tests/vsock_socket/test
+++ b/tests/vsock_socket/test
@@ -6,19 +6,14 @@ BEGIN {
     $basedir =~ s|(.*)/[^/]*|$1|;
 
     # check if vsock and vsock_loopback are available
-    $rc = system("$basedir/check_vsock");
-
-    if ( $rc eq 0 ) {
-        plan tests => 12;
-    }
-    elsif ( $rc eq 2 << 8 ) {
+    if ( system("modprobe vsock 2>/dev/null") ne 0 ) {
         plan skip_all => "vsock socket family not supported";
     }
-    elsif ( $rc eq 3 << 8 ) {
+    elsif ( system("modprobe vsock_loopback 2>/dev/null") ne 0 ) {
         plan skip_all => "vsock_loopback transport not supported";
     }
     else {
-        plan skip_all => "unexpected error when checking vsock support";
+        plan tests => 12;
     }
 }
 
-- 
2.37.1




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

  Powered by Linux