Browse Source

Bugfix for getsockopt (#102)

* Unit test and fix for issue #92 

* Take out another flaky LTP test for now
Don Porter 6 years ago
parent
commit
7807773a76

+ 1 - 1
LibOS/shim/src/sys/shim_socket.c

@@ -1676,7 +1676,7 @@ int shim_do_getsockopt (int fd, int level, int optname, char * optval,
                 }
                 goto out;
             case SO_TYPE:
-                *intval = sock->protocol;
+                *intval = sock->sock_type;
                 goto out;
             case SO_KEEPALIVE:
             case SO_LINGER:

+ 1 - 1
LibOS/shim/test/apps/gcc/test_files

@@ -1 +1 @@
-Subproject commit cde135bd3afd11a5c1571c5a5c91d42873712150
+Subproject commit 58516010a9c343bc6fd474657544d42b0272f5c0

+ 1 - 1
LibOS/shim/test/apps/lighttpd/.gitignore

@@ -5,4 +5,4 @@ build
 html
 lighttpd-*
 lighttpd.conf
-
+server.pem

+ 2 - 0
LibOS/shim/test/apps/ltp/FLAKY

@@ -16,3 +16,5 @@ waitpid02,3
 
 clock_nanosleep01,11 - Pretty prone to hanging, don't think it is a timeout
 
+sendfile05,1 - pretty prone to a segfault, perhaps an unrelated issue
+Internal memory fault at 0x8 (IP = +0x34f1a, VMID = 3902099696, TID = 1)

+ 0 - 1
LibOS/shim/test/apps/ltp/PASSED

@@ -727,7 +727,6 @@ sendfile03,3
 sendfile03_64,1
 sendfile03_64,2
 sendfile03_64,3
-sendfile05,1
 sendfile05_64,1
 setgid01,1
 setitimer01,1

+ 1 - 0
LibOS/shim/test/apps/ltp/TIMEOUTS

@@ -15,6 +15,7 @@ exit01,40
 faccessat01,80
 fchdir02,40
 fchmod07,40
+fchmodat01,40
 fcntl02_64,40
 fcntl13_64,40
 fork02,40

+ 15 - 0
LibOS/shim/test/regression/80_sockets.py

@@ -0,0 +1,15 @@
+#!/usr/bin/python
+
+import os, sys, mmap
+from regression import Regression
+
+loader = sys.argv[1]
+
+# Running getsockopt
+regression = Regression(loader, "getsockopt", None)
+
+regression.add_check(name="getsockopt",
+    check=lambda res: "getsockopt: Got socket type OK" in res[0].out)
+
+rv = regression.run_checks()
+if rv: sys.exit(rv)

+ 2 - 0
LibOS/shim/test/regression/Makefile

@@ -57,6 +57,8 @@ regression: $(target)
 	@for f in $(wildcard 00_*.py); do env $(PYTHONENV) python $$f $(RUNTIME)/pal-$(PAL_HOST) || exit $?; done
 	@echo "\n\nSyscall Support:"
 	@for f in $(wildcard 30_*.py); do env $(PYTHONENV) python $$f $(RUNTIME)/pal-$(PAL_HOST) || exit $?; done
+	@echo "\n\nSocket Support:"
+	@for f in $(wildcard 80_*.py); do env $(PYTHONENV) python $$f $(RUNTIME)/pal-$(PAL_HOST) || exit $?; done
 	@echo "\n\nLarge File Support:"
 	@for f in $(wildcard 90_*.py); do env $(PYTHONENV) python $$f $(RUNTIME)/pal-$(PAL_HOST) || exit $?; done
 

+ 50 - 0
LibOS/shim/test/regression/getsockopt.c

@@ -0,0 +1,50 @@
+/* Unit test for issue #92.  
+ * Example for use of getsockopt with SO_TYPE 
+ * taken from here: http://alas.matf.bg.ac.rs/manuals/lspe/snode=103.html
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <sys/socket.h>
+#include <assert.h>
+
+int main(int argc,char **argv) {
+
+  int z;
+  int s = -1;                /* Socket */
+  int so_type = -1;    /* Socket type */
+  socklen_t optlen;  /* Option length */
+  int rv;
+  
+  /*
+   * Create a TCP/IP socket to use:
+   */
+  s = socket(PF_INET,SOCK_STREAM,0);
+  if ( s == -1 ) {
+    printf("socket(2) error %d", errno);
+    exit(-1);
+  }
+
+  /*
+   * Get socket option SO_SNDBUF:
+   */
+  optlen = sizeof so_type;
+  z = getsockopt(s,SOL_SOCKET,SO_TYPE,
+		 &so_type,&optlen);
+  if ( z ) {
+    printf("getsockopt(s,SOL_SOCKET,"
+	    "SO_TYPE) %d", errno);
+    exit(-1);
+  }
+  
+  assert(optlen == sizeof so_type);
+  if (so_type == SOCK_STREAM) {
+    printf("getsockopt: Got socket type OK\n");
+  } else {
+    printf("getsockopt: Got socket type failed\n");
+    rv = -1;
+  }
+    
+  return rv;
+}
+