From: Ivo Raisr Date: Tue, 29 Sep 2015 18:57:56 +0000 (+0000) Subject: Move more complicated tests out of memcheck/tests/solaris/scalar_ioctl X-Git-Tag: svn/VALGRIND_3_12_0~333 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=386124cab0d9519119cac8ddf205d45efd633564;p=thirdparty%2Fvalgrind.git 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 --- diff --git a/memcheck/tests/solaris/Makefile.am b/memcheck/tests/solaris/Makefile.am index 8736c87234..458276983c 100644 --- a/memcheck/tests/solaris/Makefile.am +++ b/memcheck/tests/solaris/Makefile.am @@ -20,6 +20,7 @@ EXTRA_DIST = \ 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 @@ check_PROGRAMS = \ gethrtime \ inlinfo \ inlinfo_nested.so \ + ioctl \ ldynsym \ lsframe1 \ lsframe2 \ @@ -147,6 +149,7 @@ AM_CFLAGS += $(AM_FLAG_M3264_PRI) 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 0000000000..9f7e53aa9a --- /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 +#include +#include +#include +#include +#include +#include + +/* 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 0000000000..146ea8d2e4 --- /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 0000000000..e69de29bb2 diff --git a/memcheck/tests/solaris/ioctl.vgtest b/memcheck/tests/solaris/ioctl.vgtest new file mode 100644 index 0000000000..a0daa7865e --- /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 c4b4c79dc9..dfc39fbce1 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 #include #include #include @@ -223,49 +222,15 @@ __attribute__((noinline)) 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"); SY(SYS_ioctl, x0 - 1, x0 + SIOCGIFCONF, &ifc + x0); FAIL; } -__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) { @@ -356,9 +321,9 @@ __attribute__((noinline)) 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; @@ -367,45 +332,6 @@ static void sys_ioctl_SIOCGLIFCONF_2(void) SY(SYS_ioctl, x0 - 1, x0 + SIOCGLIFCONF, &lifc + x0); FAIL; } -__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) { @@ -557,7 +483,6 @@ int main(void) /* 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 @@ int main(void) 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 5a53d6eb61..fdb1a56508 100644 --- a/memcheck/tests/solaris/scalar_ioctl.stderr.exp +++ b/memcheck/tests/solaris/scalar_ioctl.stderr.exp @@ -463,12 +463,6 @@ Syscall param ioctl(SIOCGIFCONF, ifconf->ifc_buf) points to uninitialised byte(s ... 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 --------------------------------------------------------- @@ -661,12 +655,6 @@ Syscall param ioctl(SIOCGLIFCONF, lifconf->lifc_flags) points to uninitialised b ... 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 ---------------------------------------------------------