Move more complicated tests out of memcheck/tests/solaris/scalar_ioctl
to memcheck/tests/solaris/ioctl.
While at it, remove a fixed size buffer as reported by Florian Krohm.
n-i-bz



git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15690 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/memcheck/tests/solaris/Makefile.am b/memcheck/tests/solaris/Makefile.am
index 8736c87..4582769 100644
--- a/memcheck/tests/solaris/Makefile.am
+++ b/memcheck/tests/solaris/Makefile.am
@@ -20,6 +20,7 @@
 	getzoneoffset.stderr.exp getzoneoffset.vgtest \
 	gethrtime.stderr.exp gethrtime.stdout.exp gethrtime.vgtest \
 	gethrusec.stderr.exp gethrusec.stdout.exp gethrusec.vgtest \
+	ioctl.stderr.exp ioctl.stdout.exp ioctl.vgtest \
 	ldynsym.stderr.exp ldynsym.stdout.exp ldynsym.vgtest \
 	lsframe1.stderr.exp lsframe1.stdout.exp lsframe1.vgtest \
 	lsframe2.stderr.exp lsframe2.stdout.exp lsframe2.vgtest \
@@ -60,6 +61,7 @@
 	gethrtime \
 	inlinfo \
 	inlinfo_nested.so \
+	ioctl \
 	ldynsym \
 	lsframe1 \
 	lsframe2 \
@@ -147,6 +149,7 @@
 AM_CXXFLAGS += $(AM_FLAG_M3264_PRI)
 
 door_kill_LDADD = -lpthread
+ioctl_LDADD = -lsocket
 ldynsym_LDFLAGS = -Wl,--strip-all
 pkcs11_LDADD = -lpkcs11
 sendfilev_LDADD = -lsendfile
diff --git a/memcheck/tests/solaris/ioctl.c b/memcheck/tests/solaris/ioctl.c
new file mode 100644
index 0000000..9f7e53a
--- /dev/null
+++ b/memcheck/tests/solaris/ioctl.c
@@ -0,0 +1,91 @@
+/* Tests for ioctl wrappers.
+   More complicated ones than just trivial ones in scalar_ioctl. */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <strings.h>
+#include <unistd.h>
+#include <net/if.h>
+#include <sys/socket.h>
+#include <sys/sockio.h>
+
+/* sockio */
+__attribute__((noinline))
+static int test_SIOCGIFCONF(void)
+{
+   int fd = socket(AF_INET, SOCK_DGRAM, 0);
+   if (fd < 0)
+      perror("socket");
+
+   int n_ifs;
+   if (ioctl(fd, SIOCGIFNUM, &n_ifs) < 0)
+      perror("ioctl(SIOCGIFNUM)");
+
+   struct ifconf ifc;
+   ifc.ifc_len = (n_ifs + 1) * sizeof(struct ifreq);
+   ifc.ifc_buf = malloc((n_ifs + 1) * sizeof(struct ifreq));
+   if (ifc.ifc_buf == NULL)
+      perror("malloc");
+
+   if (ioctl(fd, SIOCGIFCONF, &ifc) < 0)
+      perror("ioctl(SIOCGIFCONF)");
+
+   /* Check definedness of ifc attributes ... */
+   int x = 0;
+   if (ifc.ifc_len != 0) x = -1; else x = -2;
+   if (ifc.ifc_req != NULL) x = -3; else x = -4;
+   if (strcmp(ifc.ifc_req[0].ifr_name, "") != 0) x = -5; else x = -6;
+   /* ... and now one which is not defined. */
+   if (strcmp(ifc.ifc_req[n_ifs].ifr_name, "") != 0) x = -7; else x = -8;
+
+   free(ifc.ifc_buf);
+   close(fd);
+   return x;
+}
+
+__attribute__((noinline))
+static int test_SIOCGLIFCONF(void)
+{
+   int fd = socket(AF_INET, SOCK_DGRAM, 0);
+   if (fd < 0)
+      perror("socket");
+
+   struct lifnum lifn;
+   lifn.lifn_family = AF_INET;
+   lifn.lifn_flags = 0;
+   if (ioctl(fd, SIOCGLIFNUM, &lifn) < 0)
+      perror("ioctl(SIOCGLIFNUM)");
+
+   struct lifconf lifc;
+   lifc.lifc_family = AF_INET;
+   lifc.lifc_flags = 0;
+   lifc.lifc_len = (lifn.lifn_count + 1) * sizeof(struct lifreq);
+   lifc.lifc_buf = malloc((lifn.lifn_count + 1) * sizeof(struct lifreq));
+   if (lifc.lifc_buf == NULL)
+      perror("malloc");
+
+   if (ioctl(fd, SIOCGLIFCONF, &lifc) < 0)
+      perror("ioctl(SIOCGLIFCONF)");
+
+   /* Check definedness of lifc attributes ... */
+   int x = 0;
+   if (lifc.lifc_len != 0) x = -1; else x = -2;
+   if (lifc.lifc_req != NULL) x = -3; else x = -4;
+   if (strcmp(lifc.lifc_req[0].lifr_name, "") != 0) x = -5; else x = -6;
+   /* ... and now one which is not defined. */
+   if (strcmp(lifc.lifc_req[lifn.lifn_count].lifr_name, "") != 0)
+      x = -7; else x = -8;
+
+   free(lifc.lifc_buf);
+   close(fd);
+   return x;
+}
+
+int main(void)
+{
+   /* sockio */
+   test_SIOCGIFCONF();
+   test_SIOCGLIFCONF();
+
+   return 0;
+}
diff --git a/memcheck/tests/solaris/ioctl.stderr.exp b/memcheck/tests/solaris/ioctl.stderr.exp
new file mode 100644
index 0000000..146ea8d
--- /dev/null
+++ b/memcheck/tests/solaris/ioctl.stderr.exp
@@ -0,0 +1,8 @@
+Conditional jump or move depends on uninitialised value(s)
+   at 0x........: test_SIOCGIFCONF (ioctl.c:39)
+   by 0x........: main (ioctl.c:87)
+
+Conditional jump or move depends on uninitialised value(s)
+   at 0x........: test_SIOCGLIFCONF (ioctl.c:76)
+   by 0x........: main (ioctl.c:88)
+
diff --git a/memcheck/tests/solaris/ioctl.stdout.exp b/memcheck/tests/solaris/ioctl.stdout.exp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/memcheck/tests/solaris/ioctl.stdout.exp
diff --git a/memcheck/tests/solaris/ioctl.vgtest b/memcheck/tests/solaris/ioctl.vgtest
new file mode 100644
index 0000000..a0daa78
--- /dev/null
+++ b/memcheck/tests/solaris/ioctl.vgtest
@@ -0,0 +1,2 @@
+prog: ioctl
+vgopts: -q
diff --git a/memcheck/tests/solaris/scalar_ioctl.c b/memcheck/tests/solaris/scalar_ioctl.c
index c4b4c79..dfc39fb 100644
--- a/memcheck/tests/solaris/scalar_ioctl.c
+++ b/memcheck/tests/solaris/scalar_ioctl.c
@@ -1,10 +1,9 @@
-/* Basic ioctl test. */
+/* Basic ioctl scalar tests. */
 
 #define __EXTENSIONS__ 1
 
 #include "scalar.h"
 
-#include <unistd.h>
 #include <net/if.h>
 #include <sys/crypto/ioctl.h>
 #include <sys/dtrace.h>
@@ -223,9 +222,9 @@
 static void sys_ioctl_SIOCGIFCONF_2(void)
 {
    struct ifconf ifc;
-   char buf[5];
+   char buf[] = "";
 
-   ifc.ifc_len = x0 + 5;
+   ifc.ifc_len = x0 + 1;
    ifc.ifc_buf = (void *) (x0 + buf);
 
    GO(SYS_ioctl, "(SIOCGIFCONF), 5s 0m");
@@ -233,40 +232,6 @@
 }
 
 __attribute__((noinline))
-static int sys_ioctl_SIOCGIFCONF_3(void)
-{
-   int fd = socket(AF_INET, SOCK_DGRAM, 0);
-   if (fd < 0)
-      perror("socket");
-
-   int n_ifs;
-   if (ioctl(fd, SIOCGIFNUM, &n_ifs) < 0)
-      perror("ioctl(SIOCGIFNUM)");
-
-   struct ifconf ifc;
-   ifc.ifc_len = (n_ifs + 1) * sizeof(struct ifreq);
-   ifc.ifc_buf = malloc((n_ifs + 1) * sizeof(struct ifreq));
-   if (ifc.ifc_buf == NULL)
-      perror("malloc");
-
-   GO(SYS_ioctl, "(SIOCGIFCONF), 1s 0m");
-   if (ioctl(fd, SIOCGIFCONF, &ifc) < 0)
-      perror("ioctl(SIOCGIFCONF)");
-
-   /* Check definedness of ifc attributes ... */
-   int x = 0;
-   if (ifc.ifc_len != 0) x = -1; else x = -2;
-   if (ifc.ifc_req != NULL) x = -3; else x = -4;
-   if (strcmp(ifc.ifc_req[0].ifr_name, "") != 0) x = -5; else x = -6;
-   /* ... and now one which is not defined. */
-   if (strcmp(ifc.ifc_req[n_ifs].ifr_name, "") != 0) x = -7; else x = -8;
-
-   free(ifc.ifc_buf);
-   close(fd);
-   return x;
-}
-
-__attribute__((noinline))
 static void sys_ioctl_SIOCGIFFLAGS(void)
 {
    GO(SYS_ioctl, "(SIOCGIFFLAGS) 3s 2m");
@@ -356,9 +321,9 @@
 static void sys_ioctl_SIOCGLIFCONF_2(void)
 {
    struct lifconf lifc;
-   char buf[5];
+   char buf[] = "";
 
-   lifc.lifc_len = x0 + 5;
+   lifc.lifc_len = x0 + 1;
    lifc.lifc_buf = (void *) (x0 + buf);
    lifc.lifc_family = x0 + 1;
    lifc.lifc_flags = x0 + 0;
@@ -368,45 +333,6 @@
 }
 
 __attribute__((noinline))
-static int sys_ioctl_SIOCGLIFCONF_3(void)
-{
-   int fd = socket(AF_INET, SOCK_DGRAM, 0);
-   if (fd < 0)
-      perror("socket");
-
-   struct lifnum lifn;
-   lifn.lifn_family = AF_INET;
-   lifn.lifn_flags = 0;
-   if (ioctl(fd, SIOCGLIFNUM, &lifn) < 0)
-      perror("ioctl(SIOCGLIFNUM)");
-
-   struct lifconf lifc;
-   lifc.lifc_family = AF_INET;
-   lifc.lifc_flags = 0;
-   lifc.lifc_len = (lifn.lifn_count + 1) * sizeof(struct lifreq);
-   lifc.lifc_buf = malloc((lifn.lifn_count + 1) * sizeof(struct lifreq));
-   if (lifc.lifc_buf == NULL)
-      perror("malloc");
-
-   GO(SYS_ioctl, "(SIOCGLIFCONF), 1s 0m");
-   if (ioctl(fd, SIOCGLIFCONF, &lifc) < 0)
-      perror("ioctl(SIOCGLIFCONF)");
-
-   /* Check definedness of lifc attributes ... */
-   int x = 0;
-   if (lifc.lifc_len != 0) x = -1; else x = -2;
-   if (lifc.lifc_req != NULL) x = -3; else x = -4;
-   if (strcmp(lifc.lifc_req[0].lifr_name, "") != 0) x = -5; else x = -6;
-   /* ... and now one which is not defined. */
-   if (strcmp(lifc.lifc_req[lifn.lifn_count].lifr_name, "") != 0)
-      x = -7; else x = -8;
-
-   free(lifc.lifc_buf);
-   close(fd);
-   return x;
-}
-
-__attribute__((noinline))
 static void sys_ioctl_SIOCGLIFFLAGS(void)
 {
    GO(SYS_ioctl, "(SIOCGLIFFLAGS) 3s 2m");
@@ -557,7 +483,6 @@
    /* sockio */
    sys_ioctl_SIOCGIFCONF();
    sys_ioctl_SIOCGIFCONF_2();
-   sys_ioctl_SIOCGIFCONF_3();
    sys_ioctl_SIOCGIFFLAGS();
    sys_ioctl_SIOCGIFFLAGS_2();
    sys_ioctl_SIOCGIFNETMASK();
@@ -568,7 +493,6 @@
    sys_ioctl_SIOCGLIFBRDADDR_2();
    sys_ioctl_SIOCGLIFCONF();
    sys_ioctl_SIOCGLIFCONF_2();
-   sys_ioctl_SIOCGLIFCONF_3();
    sys_ioctl_SIOCGLIFFLAGS();
    sys_ioctl_SIOCGLIFFLAGS_2();
    sys_ioctl_SIOCGLIFNETMASK();
diff --git a/memcheck/tests/solaris/scalar_ioctl.stderr.exp b/memcheck/tests/solaris/scalar_ioctl.stderr.exp
index 5a53d6e..fdb1a56 100644
--- a/memcheck/tests/solaris/scalar_ioctl.stderr.exp
+++ b/memcheck/tests/solaris/scalar_ioctl.stderr.exp
@@ -464,12 +464,6 @@
  Address 0x........ is on thread 1's stack
 
 ---------------------------------------------------------
- 54:               SYS_ioctl (SIOCGIFCONF), 1s 0m
----------------------------------------------------------
-Conditional jump or move depends on uninitialised value(s)
-   ...
-
----------------------------------------------------------
  54:               SYS_ioctl (SIOCGIFFLAGS) 3s 2m
 ---------------------------------------------------------
 Syscall param ioctl(fd) contains uninitialised byte(s)
@@ -662,12 +656,6 @@
  Address 0x........ is on thread 1's stack
 
 ---------------------------------------------------------
- 54:               SYS_ioctl (SIOCGLIFCONF), 1s 0m
----------------------------------------------------------
-Conditional jump or move depends on uninitialised value(s)
-   ...
-
----------------------------------------------------------
  54:               SYS_ioctl (SIOCGLIFFLAGS) 3s 2m
 ---------------------------------------------------------
 Syscall param ioctl(fd) contains uninitialised byte(s)