[PATCH testsuite] tests/overlay: replace Python script with a C program

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

 



This was the only Python script in the whole testsuite. No need to
depend on Python just for access(2)...

Signed-off-by: Ondrej Mosnacek <omosnace@xxxxxxxxxx>
---
 tests/overlay/.gitignore |  1 +
 tests/overlay/Makefile   |  4 +++-
 tests/overlay/access     |  7 -------
 tests/overlay/access.c   | 16 ++++++++++++++++
 tests/overlay/test       | 26 +++++++++++++-------------
 5 files changed, 33 insertions(+), 21 deletions(-)
 create mode 100644 tests/overlay/.gitignore
 delete mode 100755 tests/overlay/access
 create mode 100644 tests/overlay/access.c

diff --git a/tests/overlay/.gitignore b/tests/overlay/.gitignore
new file mode 100644
index 0000000..73bc322
--- /dev/null
+++ b/tests/overlay/.gitignore
@@ -0,0 +1 @@
+access
diff --git a/tests/overlay/Makefile b/tests/overlay/Makefile
index e7c006f..8dce555 100644
--- a/tests/overlay/Makefile
+++ b/tests/overlay/Makefile
@@ -1,2 +1,4 @@
-all:
+TARGETS=$(patsubst %.c,%,$(wildcard *.c))
+all: $(TARGETS)
 clean:
+	rm -f $(TARGETS)
diff --git a/tests/overlay/access b/tests/overlay/access
deleted file mode 100755
index e50d5b4..0000000
--- a/tests/overlay/access
+++ /dev/null
@@ -1,7 +0,0 @@
-#!/usr/bin/python3
-import os, sys
-try:
-        acc=eval("os.%s" % sys.argv[2])
-        print(os.access(sys.argv[1], acc))
-except AttributeError as e:
-        print(e)
diff --git a/tests/overlay/access.c b/tests/overlay/access.c
new file mode 100644
index 0000000..f968dc6
--- /dev/null
+++ b/tests/overlay/access.c
@@ -0,0 +1,16 @@
+#include <unistd.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+
+int main(int argc, const char **argv)
+{
+	if (argc != 3 || (strcmp(argv[2], "R_OK") && strcmp(argv[2], "W_OK"))) {
+		fprintf(stderr, "Usage %s <file> R_OK|W_OK\n", argv[0]);
+		return EINVAL;
+	}
+
+	errno = 0;
+	access(argv[1], strcmp(argv[2], "R_OK") == 0 ? R_OK : W_OK);
+	return errno;
+}
diff --git a/tests/overlay/test b/tests/overlay/test
index 72affdf..2b28c47 100755
--- a/tests/overlay/test
+++ b/tests/overlay/test
@@ -34,10 +34,10 @@ sub getfilecon {
 
 sub access {
     my ( $filename, $accesstype ) = @_;
-    $output =
-`runcon -t test_overlay_client_t -l s0:c10,c20 $basedir/access $filename $accesstype`;
-    $output =~ s/\n//g;
-    return $output;
+    $result = system(
+"runcon -t test_overlay_client_t -l s0:c10,c20 $basedir/access $filename $accesstype"
+    );
+    return $result >> 8;
 }
 
 sub xattr_test_setup {
@@ -496,63 +496,63 @@ sub test_52 {
 sub test_60 {
     print "Check read access on readfile, should succeed.\n";
     $result = access( "$basedir/container1/merged/readfile", "R_OK" );
-    ok( $result eq "True" );
+    ok( $result eq 0 );
     return;
 }
 
 sub test_61 {
     print "Check read access on writefile, should succeed.\n";
     $result = access( "$basedir/container1/merged/writefile", "R_OK" );
-    ok( $result eq "True" );
+    ok( $result eq 0 );
     return;
 }
 
 sub test_62 {
     print "Check read access on noaccessfile, should fail.\n";
     $result = access( "$basedir/container1/merged/noaccessfile", "R_OK" );
-    ok( $result eq "False" );
+    ok( $result eq 13 );
     return;
 }
 
 sub test_63 {
     print "Check write access on readfile, should fail.\n";
     $result = access( "$basedir/container1/merged/readfile", "W_OK" );
-    ok( $result eq "False" );
+    ok( $result eq 13 );
     return;
 }
 
 sub test_63_ctx {
     print "Check write access on readfile, should succeed.\n";
     $result = access( "$basedir/container1/merged/readfile", "W_OK" );
-    ok( $result eq "True" );
+    ok( $result eq 0 );
     return;
 }
 
 sub test_64 {
     print "Check write access on writefile, should succeed.\n";
     $result = access( "$basedir/container1/merged/writefile", "W_OK" );
-    ok( $result eq "True" );
+    ok( $result eq 0 );
     return;
 }
 
 sub test_65 {
     print "Check write access on noaccessfile, should fail.\n";
     $result = access( "$basedir/container1/merged/noaccessfile", "W_OK" );
-    ok( $result eq "False" );
+    ok( $result eq 13 );
     return;
 }
 
 sub test_66 {
     print "Check read to read null device should fail\n";
     $result = access( "$basedir/container1/merged/null_read", "R_OK" );
-    ok( $result eq "True" );
+    ok( $result eq 0 );
     return;
 }
 
 sub test_67 {
     print "Check write to read null device should fail\n";
     $result = access( "$basedir/container1/merged/null_read", "W_OK" );
-    ok( $result eq "False" );
+    ok( $result eq 13 );
     return;
 }
 
-- 
2.26.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