All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH 1/6] lib6/runcc.c: use TCONF instead of TBROK when no C compiler is present
@ 2015-03-31  7:46 Xing Gu
  2015-03-31  7:46 ` [LTP] [PATCH 2/6] lib6/asapi_04.c: cleanup Xing Gu
                   ` (5 more replies)
  0 siblings, 6 replies; 55+ messages in thread
From: Xing Gu @ 2015-03-31  7:46 UTC (permalink / raw)
  To: ltp-list

Signed-off-by: Xing Gu <gux.fnst@cn.fujitsu.com>
---
 testcases/network/lib6/runcc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/testcases/network/lib6/runcc.c b/testcases/network/lib6/runcc.c
index 91a0b16..3a89598 100644
--- a/testcases/network/lib6/runcc.c
+++ b/testcases/network/lib6/runcc.c
@@ -93,7 +93,7 @@ int runcc(char *tname, char *filename0, char *program)
 		 cflags, filename0, filename);
 	es = system(cmd);
 	if (WEXITSTATUS(es) == 127) {
-		tst_resm(TBROK, "can't run C compiler: \"%s\"", cmd);
+		tst_resm(TCONF, "can't run C compiler: \"%s\"", cmd);
 		if (unlink(filename) < 0)
 			tst_resm(TWARN, "%s; unlink \"%s\" failed: %s", tname,
 				 filename, strerror(errno));
-- 
1.9.3


------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [LTP] [PATCH 2/6] lib6/asapi_04.c: cleanup
  2015-03-31  7:46 [LTP] [PATCH 1/6] lib6/runcc.c: use TCONF instead of TBROK when no C compiler is present Xing Gu
@ 2015-03-31  7:46 ` Xing Gu
  2015-04-30 11:55   ` Cyril Hrubis
  2015-04-30 12:18   ` Cyril Hrubis
  2015-03-31  7:46 ` [LTP] [PATCH 3/6] lib6/asapi_05.c: cleanup Xing Gu
                   ` (4 subsequent siblings)
  5 siblings, 2 replies; 55+ messages in thread
From: Xing Gu @ 2015-03-31  7:46 UTC (permalink / raw)
  To: ltp-list

* Remove cleanup() function.
* Remove useless comments.
* Modify the format of ptab[] and cstab[].
* Move the test body from main() to (*testfunc[])().
* In every test function, using TINFO instead of TPASS
  marks the success of each inner test.

Signed-off-by: Xing Gu <gux.fnst@cn.fujitsu.com>
---
 testcases/network/lib6/asapi_04.c | 210 +++++++++++++++++++-------------------
 1 file changed, 103 insertions(+), 107 deletions(-)

diff --git a/testcases/network/lib6/asapi_04.c b/testcases/network/lib6/asapi_04.c
index 76de26b..58ed3bf 100644
--- a/testcases/network/lib6/asapi_04.c
+++ b/testcases/network/lib6/asapi_04.c
@@ -1,6 +1,7 @@
 /*
  *
  *   Copyright (c) International Business Machines  Corp., 2001
+ *   Author: David L Stevens
  *
  *   This program is free software;  you can redistribute it and/or modify
  *   it under the terms of the GNU General Public License as published by
@@ -13,26 +14,13 @@
  *   the GNU General Public License for more details.
  *
  *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *   along with this program;  if not, write to the Free Software Foundation,
+ *   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
-
 /*
- * Test Name: asapi_04
- *
- * Test Description:
- *  Verify that in6 and sockaddr fields are present. Most of these are
- *  "PASS" if they just compile.
- *
- * Usage:  <for command-line>
- *  asapi_04
- *
- * HISTORY
- *	04/2005 written by David L Stevens
- *
- * RESTRICTIONS:
- *  None.
- *
+ *   Description:
+ *     Verify that in6 and sockaddr fields are present. Most of these are
+ *     "PASS" if they just compile.
  */
 
 #include <stdio.h>
@@ -49,36 +37,27 @@
 
 #include "test.h"
 
-char *TCID = "asapi_04";	/* Test program identifier.    */
+#define READ_TIMEOUT	5	/* secs */
 
 pid_t pid;
 
-struct {
-	char *prt_name;
-	int prt_value;
-} ptab[] = {
-	{
-	"hopopt", 0}, {
-	"ipv6", 41}, {
-	"ipv6-route", 43}, {
-	"ipv6-frag", 44}, {
-	"esp", 50}, {
-	"ah", 51}, {
-	"ipv6-icmp", 58}, {
-	"ipv6-nonxt", 59}, {
-"ipv6-opts", 60},};
-
-#define PTCOUNT	(sizeof(ptab)/sizeof(ptab[0]))
+static void setup(void);
+static void test_in6_are_addr_equal(void);
+static void test_protocols_entry(void);
+static int csum_test(char *rhost);
+static void test_ipv6_checksum(void);
 
-#define READ_TIMEOUT	5	/* secs */
 
-void do_tests(void);
-void setup(void), cleanup(void);
-int csum_test(char *rhost);
+static void (*testfunc[])(void) = { test_in6_are_addr_equal,
+	test_protocols_entry, test_ipv6_checksum };
+
+char *TCID = "asapi_04";
+int TST_TOTAL = ARRAY_SIZE(testfunc);
 
 int main(int argc, char *argv[])
 {
 	int lc;
+	int i;
 
 	tst_parse_opts(argc, argv, 0, 0);
 
@@ -86,22 +65,27 @@ int main(int argc, char *argv[])
 
 	setup();
 
-	for (lc = 0; TEST_LOOPING(lc); ++lc)
-		do_tests();
+	for (lc = 0; TEST_LOOPING(lc); ++lc) {
+		tst_count = 0;
 
-	cleanup();
+		for (i = 0; i < TST_TOTAL; i++)
+			(*testfunc[i])();
+	}
 
 	tst_exit();
 }
 
-void do_tests(void)
+void setup(void)
 {
-	int i;
+	TEST_PAUSE;
+}
 
 /* RFC 3542, Section 2.3 */
+void test_in6_are_addr_equal(void)
+{
 #ifndef IN6_ARE_ADDR_EQUAL
 	tst_resm(TBROK, "IN6_ARE_ADDR_EQUAL not present");
-#else /* IN6_ARE_ADDR_EQUAL */
+#else
 	/*
 	 * set each bit in an address and check for unequal; then set
 	 * in the second address and check for equal. Covers all bits, all
@@ -128,30 +112,56 @@ void do_tests(void)
 			}
 		tst_resm(rv ? TPASS : TFAIL, "IN6_ARE_ADDR_EQUAL");
 	}
-#endif /* IN6_ARE_ADDR_EQUAL */
+#endif
+}
+
+struct {
+	char *prt_name;
+	int prt_value;
+} ptab[] = {
+	{ "hopopt", 0 },
+	{ "ipv6", 41 },
+	{ "ipv6-route", 43 },
+	{ "ipv6-frag", 44 },
+	{ "esp", 50 },
+	{ "ah", 51 },
+	{ "ipv6-icmp", 58 },
+	{ "ipv6-nonxt", 59 },
+	{ "ipv6-opts", 60 },
+};
+
+#define PTCOUNT (sizeof(ptab)/sizeof(ptab[0]))
 
 /* RFC 3542, Section 2.4 */
+void test_protocols_entry(void)
+{
+	unsigned int i;
+
 	for (i = 0; i < PTCOUNT; ++i) {
 		struct protoent *pe;
 		int pass;
 
 		pe = getprotobyname(ptab[i].prt_name);
 		pass = pe && pe->p_proto == ptab[i].prt_value;
-		tst_resm(pass ? TPASS : TFAIL, "\"%s\" protocols entry",
-			 ptab[i].prt_name);
+		if (pass) {
+			tst_resm(TINFO, "\"%s\" protocols entry",
+				ptab[i].prt_name);
+		} else {
+			tst_resm(TFAIL, "\"%s\" protocols entry",
+				ptab[i].prt_name);
+			return;
+		}
 	}
+
+	tst_resm(TPASS, "protocols entry tests succeed");
+}
+
 /* RFC 3542, Section 3.1 */
+void test_ipv6_checksum(void)
+{
 	csum_test("::1");
 }
 
-/*
- * this next-header value shouldn't be a real protocol!!
- * 0x9f = 01 0 11111
- *         | |     |
- *         | |     |--- rest- ~0
- *         | |--------- chg - "no change enroute"
- *         |----------- act - "discard unknown"
- */
 #define	NH_TEST	0x9f
 
 struct tprot {
@@ -173,17 +183,13 @@ struct csent {
 	int cs_sndresult;	/* send expected result */
 	int cs_snderrno;	/* send expected errno */
 } cstab[] = {
-	{
-	0, 5, 0, 0, 0, 0}, {
-	6, 30, 0, 0, 0, 0}, {
-	3, 20, -1, EINVAL, -1, -1},	/* non-aligned offset */
-	{
-	4, 5, 0, 0, -1, EINVAL},	/* not enough space */
-	{
-	50, 5, 0, 0, -1, EINVAL},	/* outside of packet */
-	{
-	22, 30, 0, 0, 0, 0}, {
-	2000, 2004, 0, 0, 0, 0},	/* in a fragment (over Ethernet) */
+	{ 0, 5, 0, 0, 0, 0 },
+	{ 6, 30, 0, 0, 0, 0 },
+	{ 3, 20, -1, EINVAL, -1, -1 },	/* non-aligned offset */
+	{ 4, 5, 0, 0, -1, EINVAL },	/* not enough space */
+	{ 50, 5, 0, 0, -1, EINVAL },	/* outside of packet */
+	{ 22, 30, 0, 0, 0, 0 },
+	{ 2000, 2004, 0, 0, 0, 0 },	/* in a fragment (over Ethernet) */
 };
 
 #define CSCOUNT	(sizeof(cstab)/sizeof(cstab[0]))
@@ -197,7 +203,7 @@ static int recvtprot(int sd, unsigned char *packet, int psize)
 	tpt = (struct tprot *)packet;
 	total = cc = recv(sd, packet, sizeof(struct tprot), 0);
 	expected = sizeof(struct tprot);	/* until we get tp_dlen */
-	gothead = total >= sizeof(struct tprot);
+	gothead = (unsigned int)total >= sizeof(struct tprot);
 	if (gothead)
 		expected += ntohl(tpt->tp_dlen);
 	if (cc <= 0)
@@ -206,7 +212,8 @@ static int recvtprot(int sd, unsigned char *packet, int psize)
 		cc = recv(sd, &packet[total], expected - total, 0);
 		if (cc >= 0) {
 			total += cc;
-			if (!gothead && total >= sizeof(struct tprot)) {
+			if (!gothead && (unsigned int)total >=
+				sizeof(struct tprot)) {
 				gothead = 1;
 				expected += ntohl(tpt->tp_dlen);
 			}
@@ -248,7 +255,8 @@ static int client(int prot, int sfd)
 	struct tprot *prtp = (struct tprot *)rpbuf;
 	struct sockaddr_in6 rsin6;
 	static int seq;
-	int i, sd, cc, cs;
+	unsigned int i;
+	int sd, cc, cs;
 
 	memset(&rsin6, 0, sizeof(rsin6));
 	rsin6.sin6_family = AF_INET6;
@@ -261,8 +269,8 @@ static int client(int prot, int sfd)
 
 	sd = socket(PF_INET6, SOCK_RAW, NH_TEST);
 	if (sd < 0) {
-		tst_resm(TBROK, "can't create raw socket: %s", strerror(errno));
-		return -1;
+		tst_brkm(TBROK | TERRNO, NULL, "can't create raw socket: %s",
+			strerror(errno));
 	}
 	for (i = 0; i < CSCOUNT; ++i) {
 		int offset, len, xlen;
@@ -287,10 +295,10 @@ static int client(int prot, int sfd)
 				 "IPV6_CHECKSUM offset %d len %d "
 				 "- result %ld != %d", offset, len, TEST_RETURN,
 				 cstab[i].cs_setresult);
-			continue;
+			return -1;
 		}
 		if (TEST_RETURN < 0) {
-			tst_resm(TPASS, "IPV6_CHECKSUM offset %d len %d",
+			tst_resm(TINFO, "IPV6_CHECKSUM offset %d len %d",
 				 offset, len);
 			continue;
 		}
@@ -298,7 +306,7 @@ static int client(int prot, int sfd)
 			tst_resm(TFAIL, "IPV6_CHECKSUM offset %d len %d "
 				 "- errno %d != %d", offset, len,
 				 TEST_ERRNO, cstab[i].cs_seterrno);
-			continue;
+			return -1;
 		}
 		/* send packet */
 		TEST(sendto(sd, pttp, len, 0, (struct sockaddr *)&rsin6,
@@ -309,22 +317,22 @@ static int client(int prot, int sfd)
 				 "IPV6_CHECKSUM offset %d len %d "
 				 "- sndresult %ld != %d", offset, len,
 				 TEST_RETURN, xlen);
-			continue;
+			return -1;
 		}
 		if (TEST_RETURN < 0 && TEST_ERRNO != cstab[i].cs_snderrno) {
 			tst_resm(TFAIL, "IPV6_CHECKSUM offset %d len %d "
 				 "- snderrno %d != %d", offset, len,
 				 TEST_ERRNO, cstab[i].cs_snderrno);
-			continue;
+			return -1;
 		}
 		if (TEST_RETURN < 0) {
-			tst_resm(TPASS, "IPV6_CHECKSUM offset %d len %d",
+			tst_resm(TINFO, "IPV6_CHECKSUM offset %d len %d",
 				 offset, len);
 			continue;
 		}
 		while ((cc = recvtprot(sfd, rpbuf, sizeof(rpbuf)))) {
-			if (htonl(prtp->tp_pid) == pid &&
-			    htonl(prtp->tp_seq) == seq)
+			if (htonl(prtp->tp_pid) == (uint32_t)pid &&
+			    htonl(prtp->tp_seq) == (uint32_t)seq)
 				break;
 		}
 		rv = 1;
@@ -334,10 +342,10 @@ static int client(int prot, int sfd)
 				continue;
 			if (*p != 0xa5) {
 				tst_resm(TFAIL, "IPV6_CHECKSUM corrupt data "
-					 "0x%02x != 0xa5 at offset %d in packet",
+					 "0x%02x != 0xa5 at offset %ld in packet",
 					 *p, p - rpbuf);
 				rv = 0;
-				break;
+				return -1;
 			}
 		}
 		if (rv == 0)
@@ -348,10 +356,12 @@ static int client(int prot, int sfd)
 		if (!csum(0, rpbuf, xlen)) {
 			tst_resm(TFAIL, "IPV6_CHECKSUM offset %d len %d (bad "
 				 "checksum)", offset, len);
-			continue;
+			return -1;
 		}
-		tst_resm(TPASS, "IPV6_CHECKSUM offset %d len %d", offset, len);
+		tst_resm(TINFO, "IPV6_CHECKSUM offset %d len %d", offset, len);
 	}
+
+	tst_resm(TPASS, "IPV6_CHECKSUM tests succeed");
 	return 0;
 }
 
@@ -372,7 +382,7 @@ int isocketpair(int pf, int type, int proto, int fd[2])
 	struct sockaddr_in sin4;
 	socklen_t namelen;
 
-/* restrict to PF_INET for now */
+	/* restrict to PF_INET for now */
 	if (pf != PF_INET) {
 		errno = EOPNOTSUPP;
 		return -1;
@@ -420,7 +430,7 @@ int isocketpair(int pf, int type, int proto, int fd[2])
 
 #ifndef MAX
 #define MAX(a, b) ((a) >= (b) ? (a) : (b))
-#endif /* MAX */
+#endif
 
 int csum_test(char *rhost)
 {
@@ -429,25 +439,23 @@ int csum_test(char *rhost)
 	int sd, nfds, maxfd, cc;
 	struct timeval tv;
 
-/* rhost == loopback, for now */
+	/* rhost == loopback, for now */
 	if (strcmp(rhost, "::1")) {
-		tst_resm(TBROK, "invalid rhost \"%s\"", rhost);
-		return -1;
+		tst_brkm(TBROK, NULL, "invalid rhost \"%s\"", rhost);
 	}
 	if (isocketpair(PF_INET, SOCK_STREAM, 0, csd) < 0) {
-		tst_resm(TBROK, "socketpair: %s", strerror(errno));
-		return -1;
+		tst_brkm(TBROK, NULL, "socketpair: %s", strerror(errno));
 	}
 	sd = socket(PF_INET6, SOCK_RAW, NH_TEST);
 	if (sd < 0) {
 		int saved_errno = errno;
 
 		if (errno == EPERM && geteuid())
-			tst_resm(TBROK, "IPV6_CHECKSUM tests must run as root");
+			tst_brkm(TBROK, NULL, "IPV6_CHECKSUM tests must "
+				"run as root");
 		else
-			tst_resm(TBROK, "All IPv6_CHECKSUM tests broken: "
+			tst_brkm(TBROK, NULL, "All IPv6_CHECKSUM tests broken: "
 				 "socket: %s", strerror(saved_errno));
-		return -1;
 	}
 	FD_ZERO(&rset_save);
 	FD_SET(sd, &rset_save);
@@ -461,8 +469,7 @@ int csum_test(char *rhost)
 		close(csd[0]);
 		break;
 	case -1:
-		tst_resm(TBROK, "can't fork rserver");
-		return -1;
+		tst_brkm(TBROK, NULL, "can't fork rserver");
 	default:		/* parent */
 		close(sd);
 		close(csd[1]);
@@ -514,14 +521,3 @@ int csum_test(char *rhost)
 	}
 	return 0;
 }
-
-void setup(void)
-{
-	TEST_PAUSE;		/* if -P option specified */
-}
-
-void cleanup(void)
-{
-}
-
-int TST_TOTAL = PTCOUNT + CSCOUNT;
-- 
1.9.3


------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [LTP] [PATCH 3/6] lib6/asapi_05.c: cleanup
  2015-03-31  7:46 [LTP] [PATCH 1/6] lib6/runcc.c: use TCONF instead of TBROK when no C compiler is present Xing Gu
  2015-03-31  7:46 ` [LTP] [PATCH 2/6] lib6/asapi_04.c: cleanup Xing Gu
@ 2015-03-31  7:46 ` Xing Gu
  2015-04-30 12:15   ` Cyril Hrubis
  2015-03-31  7:46 ` [LTP] [PATCH 4/6] lib6/asapi_06.c: cleanup Xing Gu
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 55+ messages in thread
From: Xing Gu @ 2015-03-31  7:46 UTC (permalink / raw)
  To: ltp-list

* Remove cleanup() function.
* Remove useless comments.
* Modify the format of etab[] and ftab[].
* Some cleanup.

Signed-off-by: Xing Gu <gux.fnst@cn.fujitsu.com>
---
 testcases/network/lib6/asapi_05.c | 327 +++++++++++++++++---------------------
 1 file changed, 144 insertions(+), 183 deletions(-)

diff --git a/testcases/network/lib6/asapi_05.c b/testcases/network/lib6/asapi_05.c
index 9acc6a2..373e84b 100644
--- a/testcases/network/lib6/asapi_05.c
+++ b/testcases/network/lib6/asapi_05.c
@@ -1,6 +1,7 @@
 /*
  *
  *   Copyright (c) International Business Machines  Corp., 2001
+ *   Author: David L Stevens
  *
  *   This program is free software;  you can redistribute it and/or modify
  *   it under the terms of the GNU General Public License as published by
@@ -13,26 +14,13 @@
  *   the GNU General Public License for more details.
  *
  *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *   along with this program;  if not, write to the Free Software Foundation,
+ *   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
-
 /*
- * Test Name: asapi_05
- *
- * Test Description:
- *  These tests are for the "Advanced Sockets API" (RFC 3542)
- *  Verify that in6 and sockaddr fields are present.
- *
- * Usage:  <for command-line>
- *  asapi_05
- *
- * HISTORY
- *	04/2005 written by David L Stevens
- *
- * RESTRICTIONS:
- *  None.
- *
+ *   Description:
+ *     These tests are for the "Advanced Sockets API" (RFC 3542).
+ *     Verify that in6 and sockaddr fields are present.
  */
 
 #include <stdio.h>
@@ -49,19 +37,120 @@
 #include "test.h"
 #include "runcc.h"
 
-char *TCID = "asapi_05";	/* Test program identifier.    */
+enum ttype { EXISTS, ALIAS, VALUE, DEFINED };
+
+struct etent {
+	char *et_tname;		/* test name */
+	int et_type;		/* test type */
+	char *et_incl;		/* include file list */
+	char *et_struct;	/* structure name */
+	char *et_field;		/* field name */
+	char *et_offset;	/* field offset */
+	union {
+		char *fu_value;	/* field size or value */
+		char *fu_dname;	/* #define name */
+	} ftun;
+#define et_value	ftun.fu_value
+#define et_dname	ftun.fu_dname
+} etab[] = {
+	/* existence checks, RFC 3542 section 3 */
+	{ "icmp6_filter icmp6_filt", EXISTS, ICMP6_H,
+		"icmp6_filter", "icmp6_filt", "0", {"32"} },
+	{ "icmp6_filter icmp6_filt[0]", EXISTS, ICMP6_H,
+		"icmp6_filter", "icmp6_filt[0]", "0", {"4"} },
+	{ "ICMP6_FILTER_WILLPASS", DEFINED, ICMP6_H,
+		"ICMP6_FILTER_WILLPASS", NULL, NULL, {0} },
+	{ "ICMP6_FILTER_WILLBLOCK", DEFINED, ICMP6_H,
+		"ICMP6_FILTER_WILLBLOCK", NULL, NULL, {0} },
+	{ "ICMP6_FILTER_SETPASS", DEFINED, ICMP6_H,
+		"ICMP6_FILTER_SETPASS", NULL, NULL, {0} },
+	{ "ICMP6_FILTER_SETBLOCK", DEFINED, ICMP6_H,
+		"ICMP6_FILTER_SETBLOCK", NULL, NULL, {0} },
+	{ "ICMP6_FILTER_SETPASSALL", DEFINED, ICMP6_H,
+		"ICMP6_FILTER_SETPASSALL", NULL, NULL, {0} },
+	{ "ICMP6_FILTER_SETBLOCKALL", DEFINED, ICMP6_H,
+		"ICMP6_FILTER_SETBLOCKALL", NULL, NULL, {0} },
+	{ "ICMP6_FILTER", DEFINED, ICMP6_H, "ICMP6_FILTER",
+		NULL, NULL, {0} },
+	/* existence checks, RFC 3542 section 4 */
+	/* socket options */
+	{ "IPV6_RECVPKTINFO", VALUE, IN_H, "IPV6_RECVPKTINFO",
+		NULL, NULL, {"IPV6_RECVPKTINFO"} },
+	{ "IPV6_RECVHOPLIMIT", VALUE, IN_H, "IPV6_RECVHOPLIMIT",
+		NULL, NULL, {"IPV6_RECVHOPLIMIT"} },
+	{ "IPV6_RECVRTHDR", VALUE, IN_H, "IPV6_RECVRTHDR",
+		NULL, NULL, {"IPV6_RECVRTHDR"} },
+	{ "IPV6_RECVHOPOPTS", VALUE, IN_H, "IPV6_RECVHOPOPTS",
+		NULL, NULL, {"IPV6_RECVHOPOPTS"} },
+	{ "IPV6_RECVDSTOPTS", VALUE, IN_H, "IPV6_RECVDSTOPTS",
+		NULL, NULL, {"IPV6_RECVDSTOPTS"} },
+	{ "IPV6_RECVTCLASS", VALUE, IN_H, "IPV6_RECVTCLASS",
+		NULL, NULL, {"IPV6_RECVTCLASS"} },
+	/* cmsg types */
+	{ "IPV6_PKTINFO", DEFINED, IN_H, "IPV6_PKTINFO",
+		NULL, NULL, {0} },
+	{ "IPV6_HOPLIMIT", DEFINED, IN_H, "IPV6_HOPLIMIT",
+		NULL, NULL, {0} },
+	{ "IPV6_NEXTHOP", DEFINED, IN_H, "IPV6_NEXTHOP",
+		NULL, NULL, {0} },
+	{ "IPV6_RTHDR", DEFINED, IN_H, "IPV6_RTHDR",
+		NULL, NULL, {0} },
+	{ "IPV6_HOPOPTS", DEFINED, IN_H, "IPV6_HOPOPTS",
+		NULL, NULL, {0} },
+	{ "IPV6_DSTOPTS", DEFINED, IN_H, "IPV6_DSTOPTS",
+		NULL, NULL, {0} },
+	{ "IPV6_RTHDRDSTOPTS", DEFINED, IN_H, "IPV6_RTHDRDSTOPTS",
+		NULL, NULL, {0} },
+	{ "IPV6_TCLASS", DEFINED, IN_H, "IPV6_TCLASS",
+		NULL, NULL, {0} },
+};
+
+#define ETCOUNT	(sizeof(etab)/sizeof(etab[0]))
+
+/*
+ * This is for old, broken glibc-header icmp6_filter structure definitions.
+ * If icmp6.h has struct icmp6_filter with field named "data" instead
+ * of the standard "icmp_filt", uncomment this line.
+ */
+/*#define icmp_filt	data */
+
+enum tt { T_WILLPASS, T_WILLBLOCK, T_SETPASS, T_SETBLOCK, T_SETPASSALL,
+	T_SETBLOCKALL
+};
+struct ftent {
+	char *ft_tname;		/* test name, for logging */
+	unsigned char ft_sndtype;	/* send type field */
+	unsigned char ft_flttype;	/* filter type field */
+	enum tt ft_test;	/* what macro to test */
+	int ft_expected;	/* packet should pass? */
+} ftab[] = {
+	{ "ICMP6_FILTER_SETPASS s 20 f 20", 20, 20, T_SETPASS, 1 },
+	{ "ICMP6_FILTER_SETPASS s 20 f 21", 20, 21, T_SETPASS, 0 },
+	{ "ICMP6_FILTER_SETBLOCK s 20 f 20", 20, 20, T_SETBLOCK, 0 },
+	{ "ICMP6_FILTER_SETBLOCK s 20 f 21", 20, 21, T_SETBLOCK, 1 },
+	{ "ICMP6_FILTER_PASSALL s 20", 20, 0, T_SETPASSALL, 1 },
+	{ "ICMP6_FILTER_PASSALL s 20", 21, 0, T_SETPASSALL, 1 },
+	{ "ICMP6_FILTER_BLOCKALL s 20", 20, 0, T_SETBLOCKALL, 0 },
+	{ "ICMP6_FILTER_BLOCKALL s 20", 21, 0, T_SETBLOCKALL, 0 },
+	{ "ICMP6_FILTER_WILLBLOCK s 20 f 21", 20, 21, T_WILLBLOCK, 0 },
+	{ "ICMP6_FILTER_WILLBLOCK s 20 f 20", 20, 20, T_WILLBLOCK, 1 },
+	{ "ICMP6_FILTER_WILLPASS s 20 f 21", 20, 21, T_WILLPASS, 0 },
+	{ "ICMP6_FILTER_WILLPASS s 22 f 22", 22, 22, T_WILLPASS, 1 },
+};
+
+#define FTCOUNT	(sizeof(ftab)/sizeof(ftab[0]))
 
-void setup(void);
-void cleanup(void);
+static void setup(void);
+static void icmp6_et(void);
+static void icmp6_ft(void);
 
-void icmp6_et(void);
-void icmp6_ft(void);
+char *TCID = "asapi_05";
+int TST_TOTAL = ETCOUNT + FTCOUNT;
 
 int main(int argc, char *argv[])
 {
 	int lc;
 
-	/* Parse standard options given to run the test. */
 	tst_parse_opts(argc, argv, NULL, NULL);
 
 	setup();
@@ -71,168 +160,47 @@ int main(int argc, char *argv[])
 		icmp6_ft();
 	}
 
-	cleanup();
-
 	tst_exit();
 }
 
-enum ttype { EXISTS, ALIAS, VALUE, DEFINED };
-
-struct etent {
-	char *et_tname;		/* test name */
-	int et_type;		/* test type */
-	char *et_incl;		/* include file list */
-	char *et_struct;	/* structure name */
-	char *et_field;		/* field name */
-	char *et_offset;	/* field offset */
-	union {
-		char *fu_value;	/* field size or value */
-		char *fu_dname;	/* #define name */
-	} ftun;
-#define et_value	ftun.fu_value
-#define et_dname	ftun.fu_dname
-} etab[] = {
-/* existence checks, RFC 3542 section 3 */
-	{
-		"icmp6_filter icmp6_filt", EXISTS, ICMP6_H, "icmp6_filter",
-		    "icmp6_filt", "0", {
-	"32"}}, {
-		"icmp6_filter icmp6_filt[0]", EXISTS, ICMP6_H, "icmp6_filter",
-		    "icmp6_filt[0]", "0", {
-	"4"}}, {
-		"ICMP6_FILTER_WILLPASS", DEFINED, ICMP6_H,
-		    "ICMP6_FILTER_WILLPASS", NULL, NULL, {
-	0}}, {
-		"ICMP6_FILTER_WILLBLOCK", DEFINED, ICMP6_H,
-		    "ICMP6_FILTER_WILLBLOCK", NULL, NULL, {
-	0}}, {
-		"ICMP6_FILTER_SETPASS", DEFINED, ICMP6_H,
-		    "ICMP6_FILTER_SETPASS", NULL, NULL, {
-	0}}, {
-		"ICMP6_FILTER_SETBLOCK", DEFINED, ICMP6_H,
-		    "ICMP6_FILTER_SETBLOCK", NULL, NULL, {
-	0}}, {
-		"ICMP6_FILTER_SETPASSALL", DEFINED, ICMP6_H,
-		    "ICMP6_FILTER_SETPASSALL", NULL, NULL, {
-	0}}, {
-		"ICMP6_FILTER_SETBLOCKALL", DEFINED, ICMP6_H,
-		    "ICMP6_FILTER_SETBLOCKALL", NULL, NULL, {
-	0}}, {
-		"ICMP6_FILTER", DEFINED, ICMP6_H, "ICMP6_FILTER", NULL, NULL, {
-	0}},
-/* existence checks, RFC 3542 section 4 */
-/* socket options */
-	{
-		"IPV6_RECVPKTINFO", VALUE, IN_H, "IPV6_RECVPKTINFO", NULL, NULL, {
-	"IPV6_RECVPKTINFO"}}, {
-		"IPV6_RECVHOPLIMIT", VALUE, IN_H, "IPV6_RECVHOPLIMIT", NULL,
-		    NULL, {
-	"IPV6_RECVHOPLIMIT"}}, {
-		"IPV6_RECVRTHDR", VALUE, IN_H, "IPV6_RECVRTHDR", NULL, NULL, {
-	"IPV6_RECVRTHDR"}}, {
-		"IPV6_RECVHOPOPTS", VALUE, IN_H, "IPV6_RECVHOPOPTS", NULL, NULL, {
-	"IPV6_RECVHOPOPTS"}}, {
-		"IPV6_RECVDSTOPTS", VALUE, IN_H, "IPV6_RECVDSTOPTS", NULL, NULL, {
-	"IPV6_RECVDSTOPTS"}}, {
-		"IPV6_RECVTCLASS", VALUE, IN_H, "IPV6_RECVTCLASS", NULL, NULL, {
-	"IPV6_RECVTCLASS"}},
-/* cmsg types */
-	{
-		"IPV6_PKTINFO", DEFINED, IN_H, "IPV6_PKTINFO", NULL, NULL, {
-	0}}, {
-		"IPV6_HOPLIMIT", DEFINED, IN_H, "IPV6_HOPLIMIT", NULL, NULL, {
-	0}}, {
-		"IPV6_NEXTHOP", DEFINED, IN_H, "IPV6_NEXTHOP", NULL, NULL, {
-	0}}, {
-		"IPV6_RTHDR", DEFINED, IN_H, "IPV6_RTHDR", NULL, NULL, {
-	0}}, {
-		"IPV6_HOPOPTS", DEFINED, IN_H, "IPV6_HOPOPTS", NULL, NULL, {
-	0}}, {
-		"IPV6_DSTOPTS", DEFINED, IN_H, "IPV6_DSTOPTS", NULL, NULL, {
-	0}}, {
-		"IPV6_RTHDRDSTOPTS", DEFINED, IN_H, "IPV6_RTHDRDSTOPTS", NULL,
-		    NULL, {
-	0}}, {
-		"IPV6_TCLASS", DEFINED, IN_H, "IPV6_TCLASS", NULL, NULL, {
-0}},};
-
-#define ETCOUNT	(sizeof(etab)/sizeof(etab[0]))
+void setup(void)
+{
+	TEST_PAUSE;
+	tst_require_root(NULL);
+}
 
 /*  existence tests */
 void icmp6_et(void)
 {
-	int i;
+	unsigned int i;
 
 	for (i = 0; i < ETCOUNT; ++i) {
 		switch (etab[i].et_type) {
 		case EXISTS:
 			structcheck(etab[i].et_tname, etab[i].et_incl,
-				    etab[i].et_struct, etab[i].et_field,
-				    etab[i].et_offset, etab[i].et_value);
+				etab[i].et_struct, etab[i].et_field,
+				etab[i].et_offset, etab[i].et_value);
 			break;
 		case ALIAS:
 			aliascheck(etab[i].et_tname, etab[i].et_incl,
-				   etab[i].et_struct, etab[i].et_field,
-				   etab[i].et_dname);
+				etab[i].et_struct, etab[i].et_field,
+				etab[i].et_dname);
 			break;
 		case VALUE:
 			valuecheck(etab[i].et_tname, etab[i].et_incl,
-				   etab[i].et_struct, etab[i].et_dname);
+				etab[i].et_struct, etab[i].et_dname);
 			break;
 		case DEFINED:
 			funccheck(etab[i].et_tname, etab[i].et_incl,
-				  etab[i].et_struct);
+				etab[i].et_struct);
 			break;
 		default:
-			tst_resm(TBROK, "invalid type %d", etab[i].et_type);
-			break;
+			tst_brkm(TBROK, NULL, "invalid type %d",
+				etab[i].et_type);
 		}
 	}
 }
 
-void setup(void)
-{
-	TEST_PAUSE;		/* if -P option specified */
-	tst_require_root(NULL);
-}
-
-void cleanup(void)
-{
-}
-
-/*
- * This is for old, broken glibc-header icmp6_filter structure definitions.
- * If icmp6.h has struct icmp6_filter with field named "data" instead
- * of the standard "icmp_filt", uncomment this line.
- */
-/*#define icmp_filt	data */
-
-enum tt { T_WILLPASS, T_WILLBLOCK, T_SETPASS, T_SETBLOCK, T_SETPASSALL,
-	T_SETBLOCKALL
-};
-struct ftent {
-	char *ft_tname;		/* test name, for logging */
-	unsigned char ft_sndtype;	/* send type field */
-	unsigned char ft_flttype;	/* filter type field */
-	enum tt ft_test;	/* what macro to test */
-	int ft_expected;	/* packet should pass? */
-} ftab[] = {
-	{
-	"ICMP6_FILTER_SETPASS s 20 f 20", 20, 20, T_SETPASS, 1}, {
-	"ICMP6_FILTER_SETPASS s 20 f 21", 20, 21, T_SETPASS, 0}, {
-	"ICMP6_FILTER_SETBLOCK s 20 f 20", 20, 20, T_SETBLOCK, 0}, {
-	"ICMP6_FILTER_SETBLOCK s 20 f 21", 20, 21, T_SETBLOCK, 1}, {
-	"ICMP6_FILTER_PASSALL s 20", 20, 0, T_SETPASSALL, 1}, {
-	"ICMP6_FILTER_PASSALL s 20", 21, 0, T_SETPASSALL, 1}, {
-	"ICMP6_FILTER_BLOCKALL s 20", 20, 0, T_SETBLOCKALL, 0}, {
-	"ICMP6_FILTER_BLOCKALL s 20", 21, 0, T_SETBLOCKALL, 0}, {
-	"ICMP6_FILTER_WILLBLOCK s 20 f 21", 20, 21, T_WILLBLOCK, 0}, {
-	"ICMP6_FILTER_WILLBLOCK s 20 f 20", 20, 20, T_WILLBLOCK, 1}, {
-	"ICMP6_FILTER_WILLPASS s 20 f 21", 20, 21, T_WILLPASS, 0}, {
-"ICMP6_FILTER_WILLPASS s 22 f 22", 22, 22, T_WILLPASS, 1},};
-
-#define FTCOUNT	(sizeof(ftab)/sizeof(ftab[0]))
-
 int ic6_send1(char *tname, unsigned char type)
 {
 	struct sockaddr_in6 sin6;
@@ -241,8 +209,7 @@ int ic6_send1(char *tname, unsigned char type)
 
 	s = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
 	if (s == -1) {
-		tst_resm(TBROK, "%s: socket failed", tname);
-		return 1;
+		tst_brkm(TBROK | TERRNO, NULL, "%s: socket failed", tname);
 	}
 	memset(&ic6, 0, sizeof(ic6));
 	ic6.icmp6_type = type;
@@ -253,8 +220,7 @@ int ic6_send1(char *tname, unsigned char type)
 	sin6.sin6_addr = in6addr_loopback;
 	if (sendto(s, &ic6, sizeof(ic6), 0, (struct sockaddr *)&sin6,
 		   sizeof(sin6)) == -1) {
-		tst_resm(TBROK | TERRNO, "%s: sendto failed", tname);
-		return 1;
+		tst_brkm(TBROK | TERRNO, NULL, "%s: sendto failed", tname);
 	}
 	return 0;
 }
@@ -292,35 +258,35 @@ int ic6_recv1(char *tname, int sall, int sf)
 		if (nfds < 0) {
 			if (errno == EINTR)
 				continue;
-			tst_resm(TBROK | TERRNO, "%s: select failed", tname);
+			tst_brkm(TBROK | TERRNO, NULL,
+				"%s: select failed", tname);
 		}
 		if (FD_ISSET(sall, &readfds)) {
 			cc = recv(sall, rbuf, sizeof(rbuf), 0);
 			if (cc < 0) {
-				tst_resm(TBROK | TERRNO,
+				tst_brkm(TBROK | TERRNO, NULL,
 					 "%s: recv(sall, ..) failed", tname);
-				return -1;
 			}
 			/* if packet check succeeds... */
-			if (htonl(pic6->icmp6_data32[0]) == getpid())
+			if (htonl(pic6->icmp6_data32[0]) ==
+				(uint32_t)getpid())
 				gotall = 1;
 		}
 		if (FD_ISSET(sf, &readfds)) {
 			cc = recv(sf, rbuf, sizeof(rbuf), 0);
 			if (cc < 0) {
-				tst_resm(TBROK | TERRNO,
+				tst_brkm(TBROK | TERRNO, NULL,
 					 "%s: recv(sf, ..) failed", tname);
-				return -1;
 			}
 			/* if packet check succeeds... */
-			if (htonl(pic6->icmp6_data32[0]) == getpid())
+			if (htonl(pic6->icmp6_data32[0]) ==
+				(uint32_t)getpid())
 				gotone = 1;
 		}
 		memcpy(&readfds, &readfds_saved, sizeof(readfds));
 	}
 	if (!gotall) {
-		tst_resm(TBROK, "%s: recv all timed out", tname);
-		return -1;
+		tst_brkm(TBROK, NULL, "%s: recv all timed out", tname);
 	}
 	if (gotone)
 		return 1;
@@ -332,26 +298,24 @@ void icmp6_ft(void)
 {
 	struct icmp6_filter i6f;
 	int sall, sf;
-	int i;
+	unsigned int i;
 
 	sall = socket(PF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
 	if (sall < 0) {
-		tst_resm(TBROK | TERRNO,
+		tst_brkm(TBROK | TERRNO, NULL,
 			 "icmp6_ft socket: can't create sall socket");
-		return;
 	}
 	ICMP6_FILTER_SETPASSALL(&i6f);
 	if (setsockopt(sall, IPPROTO_ICMPV6, ICMP6_FILTER, &i6f,
 		       sizeof(i6f)) < 0) {
-		tst_resm(TBROK | TERRNO,
+		tst_brkm(TBROK | TERRNO, NULL,
 			 "setsockopt pass all ICMP6_FILTER failed");
 	}
 
 	sf = socket(PF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
 	if (sf < 0) {
-		tst_resm(TBROK | TERRNO,
+		tst_brkm(TBROK | TERRNO, NULL,
 			 "icmp6_ft socket: can't create test socket");
-		return;
 	}
 
 	int rv;
@@ -386,9 +350,8 @@ void icmp6_ft(void)
 			rv = ICMP6_FILTER_WILLPASS(ftab[i].ft_sndtype, &i6f);
 			break;
 		default:
-			tst_resm(TBROK, "%s: unknown test type %d",
+			tst_brkm(TBROK, NULL, "%s: unknown test type %d",
 				 ftab[i].ft_tname, ftab[i].ft_test);
-			continue;
 		}
 		if (ftab[i].ft_test != T_WILLBLOCK &&
 		    ftab[i].ft_test != T_WILLPASS) {
@@ -396,7 +359,7 @@ void icmp6_ft(void)
 				       sizeof(i6f)) < 0) {
 				tst_resm(TFAIL | TERRNO,
 					 "setsockopt ICMP6_FILTER");
-				continue;
+				return;
 			}
 			if (ic6_send1(ftab[i].ft_tname, ftab[i].ft_sndtype))
 				continue;
@@ -413,5 +376,3 @@ void icmp6_ft(void)
 			tst_resm(TPASS, "%s", ftab[i].ft_tname);
 	}
 }
-
-int TST_TOTAL = ETCOUNT;
-- 
1.9.3


------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [LTP] [PATCH 4/6] lib6/asapi_06.c: cleanup
  2015-03-31  7:46 [LTP] [PATCH 1/6] lib6/runcc.c: use TCONF instead of TBROK when no C compiler is present Xing Gu
  2015-03-31  7:46 ` [LTP] [PATCH 2/6] lib6/asapi_04.c: cleanup Xing Gu
  2015-03-31  7:46 ` [LTP] [PATCH 3/6] lib6/asapi_05.c: cleanup Xing Gu
@ 2015-03-31  7:46 ` Xing Gu
  2015-04-30 13:33   ` Cyril Hrubis
  2015-03-31  7:46 ` [LTP] [PATCH 5/6] lib6/getaddrinfo_01.c: cleanup Xing Gu
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 55+ messages in thread
From: Xing Gu @ 2015-03-31  7:46 UTC (permalink / raw)
  To: ltp-list

* Remove cleanup() function.
* Remove useless comments.
* Modify the format of sotab[] and cmtab[].
* Modify the initialization of sotab[].
* Move the test body from main() to (*testfunc[])().
* In every test function, using TINFO instead of TPASS
  marks the success of each inner test.

Signed-off-by: Xing Gu <gux.fnst@cn.fujitsu.com>
---
 testcases/network/lib6/asapi_06.c | 374 +++++++++++++++++---------------------
 1 file changed, 167 insertions(+), 207 deletions(-)

diff --git a/testcases/network/lib6/asapi_06.c b/testcases/network/lib6/asapi_06.c
index 960ebb5..733d1c4 100644
--- a/testcases/network/lib6/asapi_06.c
+++ b/testcases/network/lib6/asapi_06.c
@@ -1,6 +1,7 @@
 /*
  *
  *   Copyright (c) International Business Machines  Corp., 2001
+ *   Author: David L Stevens
  *
  *   This program is free software;  you can redistribute it and/or modify
  *   it under the terms of the GNU General Public License as published by
@@ -13,25 +14,12 @@
  *   the GNU General Public License for more details.
  *
  *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *   along with this program;  if not, write to the Free Software Foundation,
+ *   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
-
 /*
- * Test Name: asapi_06
- *
- * Test Description:
- *  Tests for RFC 3542 section 4 socket options and ancillary data
- *
- * Usage:  <for command-line>
- *  asapi_06
- *
- * HISTORY
- *	05/2005 written by David L Stevens
- *
- * RESTRICTIONS:
- *  None.
- *
+ *   Description:
+ *     Tests for RFC 3542 section 4 socket options and ancillary data.
  */
 
 #include "config.h"
@@ -58,42 +46,46 @@
 
 #include "test.h"
 
-char *TCID = "asapi_06";	/* Test program identifier.    */
-
-int TST_TOTAL = 1;
-
-pid_t pid;
+static void setup(void);
+static void test_soent(void);
+#ifdef notyet
+static void test_pktinfo(void);
+#endif
 
-struct {
-	char *prt_name;
-	int prt_value;
-} ptab[] = {
+static void (*testfunc[])(void) = {
+	test_soent,
+#ifdef notyet
+	test_pktinfo,
+#endif
 };
 
-#define PTCOUNT	(sizeof(ptab)/sizeof(ptab[0]))
-
-#define READ_TIMEOUT	5	/* secs */
-
-void do_tests(void);
-void setup(void), cleanup(void);
+char *TCID = "asapi_06";
+int TST_TOTAL = ARRAY_SIZE(testfunc);
 
 int main(int argc, char *argv[])
 {
 	int lc;
+	int i;
 
 	tst_parse_opts(argc, argv, NULL, NULL);
 
-	pid = getpid();
-
 	setup();
 
-	for (lc = 0; TEST_LOOPING(lc); ++lc)
-		do_tests();
+	for (lc = 0; TEST_LOOPING(lc); ++lc) {
+		tst_count = 0;
+
+		for (i = 0; i < TST_TOTAL; i++)
+			(*testfunc[i])();
+	}
 
-	cleanup();
 	tst_exit();
 }
 
+void setup(void)
+{
+	TEST_PAUSE;
+}
+
 #define NH_TEST	0x9f
 
 #ifndef IPV6_RECVPKTINFO
@@ -145,11 +137,6 @@ union soval {
 	int sou_bool;
 };
 
-/* in6_addr initializer for loopback interface */
-#define IN6_LOOP	{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }
-#define IN6_ANY		{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
-
-/* so_clrval and so_setval members are initilized in the body */
 struct soent {
 	char *so_tname;
 	int so_opt;
@@ -160,72 +147,63 @@ struct soent {
 	union soval so_setval;
 	socklen_t so_valsize;
 } sotab[] = {
-/* RFC 3542, Section 4 */
-	{
-		"IPV6_RECVPKTINFO", IPV6_RECVPKTINFO, 1, IPV6_PKTINFO, 1, { { { { {
-		0}}}}}, { { { { {
-	0}}}}}, sizeof(int)}, {
-		"IPV6_RECVHOPLIMIT", IPV6_RECVHOPLIMIT, 1, IPV6_HOPLIMIT, 1, { { { { {
-		0}}}}}, { { { { {
-	0}}}}}, sizeof(int)}, {
-		"IPV6_RECVRTHDR", IPV6_RECVRTHDR, 0, IPV6_RTHDR, 1, { { { { {
-		0}}}}}, { { { { {
-	0}}}}}, sizeof(int)}, {
-		"IPV6_RECVHOPOPTS", IPV6_RECVHOPOPTS, 0, IPV6_HOPOPTS, 1, { { { { {
-		0}}}}}, { { { { {
-	0}}}}}, sizeof(int)}, {
-		"IPV6_RECVDSTOPTS", IPV6_RECVDSTOPTS, 0, IPV6_DSTOPTS, 1, { { { { {
-		0}}}}}, { { { { {
-	0}}}}}, sizeof(int)}, {
-		"IPV6_RECVTCLASS", IPV6_RECVTCLASS, 1, IPV6_TCLASS, 1, { { { { {
-		0}}}}}, { { { { {
-	0}}}}}, sizeof(int)},
-/* make sure TCLASS stays when setting another opt */
-	{
-		"IPV6_RECVTCLASS (2)", IPV6_RECVHOPLIMIT, 1, IPV6_TCLASS, 0, { { { { {
-		0}}}}}, { { { { {
-	0}}}}}, sizeof(int)},
-/* OLD values */
-	{
-		"IPV6_2292PKTINFO", IPV6_2292PKTINFO, 1, IPV6_2292PKTINFO, 1, { { { { {
-		0}}}}}, { { { { {
-	0}}}}}, sizeof(int)}, {
-		"IPV6_2292HOPLIMIT", IPV6_2292HOPLIMIT, 1, IPV6_2292HOPLIMIT, 1, { { { { {
-		0}}}}}, { { { { {
-	0}}}}}, sizeof(int)}, {
-		"IPV6_2292RTHDR", IPV6_2292RTHDR, 0, IPV6_2292RTHDR, 1, { { { { {
-		0}}}}}, { { { { {
-	0}}}}}, sizeof(int)}, {
-		"IPV6_2292HOPOPTS", IPV6_2292HOPOPTS, 0, IPV6_2292HOPOPTS, 1, { { { { {
-		0}}}}}, { { { { {
-	0}}}}}, sizeof(int)}, {
-		"IPV6_2292DSTOPTS", IPV6_2292DSTOPTS, 0, IPV6_2292DSTOPTS, 1, { { { { {
-		0}}}}}, { { { { {
-0}}}}}, sizeof(int)},};
+	/* RFC 3542, Section 4 */
+	{ "IPV6_RECVPKTINFO", IPV6_RECVPKTINFO, 1, IPV6_PKTINFO, 1,
+		{ { { { { 0 } } }, 0 } }, { { { { { 0 } } }, 0 } },
+		sizeof(int) },
+	{ "IPV6_RECVHOPLIMIT", IPV6_RECVHOPLIMIT, 1, IPV6_HOPLIMIT, 1,
+		{ { { { { 0 } } }, 0 } }, { { { { { 0 } } }, 0 } },
+		sizeof(int) },
+	{ "IPV6_RECVRTHDR", IPV6_RECVRTHDR, 0, IPV6_RTHDR, 1,
+		{ { { { { 0 } } }, 0 } }, { { { { { 0 } } }, 0 } },
+		sizeof(int) },
+	{ "IPV6_RECVHOPOPTS", IPV6_RECVHOPOPTS, 0, IPV6_HOPOPTS, 1,
+		{ { { { { 0 } } }, 0 } }, { { { { { 0 } } }, 0 } },
+		sizeof(int) },
+	{ "IPV6_RECVDSTOPTS", IPV6_RECVDSTOPTS, 0, IPV6_DSTOPTS, 1,
+		{ { { { { 0 } } }, 0 } }, { { { { { 0 } } }, 0 } },
+		sizeof(int) },
+	{ "IPV6_RECVTCLASS", IPV6_RECVTCLASS, 1, IPV6_TCLASS, 1,
+		{ { { { { 0 } } }, 0 } }, { { { { { 0 } } }, 0 } },
+		sizeof(int) },
+	/* make sure TCLASS stays when setting another opt */
+	{ "IPV6_RECVTCLASS (2)", IPV6_RECVHOPLIMIT, 1, IPV6_TCLASS, 0,
+		{ { { { { 0 } } }, 0 } }, { { { { { 0 } } }, 0 } },
+		sizeof(int) },
+	/* OLD values */
+	{ "IPV6_2292PKTINFO", IPV6_2292PKTINFO, 1, IPV6_2292PKTINFO, 1,
+		{ { { { { 0 } } }, 0 } }, { { { { { 0 } } }, 0 } },
+		sizeof(int) },
+	{ "IPV6_2292HOPLIMIT", IPV6_2292HOPLIMIT, 1, IPV6_2292HOPLIMIT, 1,
+		{ { { { { 0 } } }, 0 } }, { { { { { 0 } } }, 0 } },
+		sizeof(int) },
+	{ "IPV6_2292RTHDR", IPV6_2292RTHDR, 0, IPV6_2292RTHDR, 1,
+		{ { { { { 0 } } }, 0 } }, { { { { { 0 } } }, 0 } },
+		sizeof(int) },
+	{ "IPV6_2292HOPOPTS", IPV6_2292HOPOPTS, 0, IPV6_2292HOPOPTS, 1,
+		{ { { { { 0 } } }, 0 } }, { { { { { 0 } } }, 0 } },
+		sizeof(int) },
+	{ "IPV6_2292DSTOPTS", IPV6_2292DSTOPTS, 0, IPV6_2292DSTOPTS, 1,
+		{ { { { { 0 } } }, 0 } }, { { { { { 0 } } }, 0 } },
+		sizeof(int) },
+};
 
 #define SOCOUNT	(sizeof(sotab)/sizeof(sotab[0]))
 
 struct soprot {
-	int sop_pid;		/* sender PID */
-	int sop_seq;		/* sequence # */
-	int sop_dlen;		/* tp_dat length */
-	unsigned char sop_dat[0];	/* user data */
+	int sop_pid;        /* sender PID */
+	int sop_seq;        /* sequence # */
+	int sop_dlen;       /* tp_dat length */
+	unsigned char sop_dat[0];   /* user data */
 };
 
 unsigned char tpbuf[sizeof(struct soprot) + 2048];
 unsigned char rpbuf[sizeof(struct soprot) + 2048];
 
 unsigned char control[2048];
-int clen;
 
 int seq;
 
-int setupso(void)
-{
-/* add routing headers, other ancillary data here */
-	return 0;
-}
-
 struct cme {
 	int cm_len;
 	int cm_level;
@@ -235,17 +213,13 @@ struct cme {
 		uint32_t cmu_hops;
 	} cmu;
 } cmtab[] = {
-	{
-		sizeof(uint32_t), SOL_IPV6, IPV6_TCLASS, {
-		0x12}
-	}
-	, {
-		sizeof(uint32_t), SOL_IPV6, IPV6_HOPLIMIT, {
-		0x21}
-	}
-,};
+	{ sizeof(uint32_t), SOL_IPV6, IPV6_TCLASS, {0x12} },
+	{ sizeof(uint32_t), SOL_IPV6, IPV6_HOPLIMIT, {0x21} },
+};
+
+#define CMCOUNT (sizeof(cmtab)/sizeof(cmtab[0]))
 
-#define CMCOUNT	(sizeof(cmtab)/sizeof(cmtab[0]))
+unsigned int count;
 
 ssize_t sendall(int st)
 {
@@ -254,7 +228,8 @@ ssize_t sendall(int st)
 	struct iovec iov;
 	struct soprot *psop;
 	unsigned char *pd;
-	int i, ctotal;
+	unsigned int i;
+	int ctotal;
 
 	psop = (struct soprot *)tpbuf;
 	psop->sop_pid = htonl(getpid());
@@ -300,32 +275,29 @@ void so_test(struct soent *psoe)
 	int st;
 
 	if (psoe->so_opt == -1) {
-		tst_resm(TBROK, "%s not present at compile time",
+		tst_brkm(TBROK, NULL, "%s not present at compile time",
 			 psoe->so_tname);
-		return;
 	}
 	if (psoe->so_clear || sr < 0) {
 		if (sr < 0)
 			close(sr);
 		sr = socket(PF_INET6, SOCK_RAW, NH_TEST);
 		if (sr < 0) {
-			tst_resm(TBROK, "%s socket: %s", psoe->so_tname,
-				 strerror(errno));
-			return;
+			tst_brkm(TBROK | TERRNO, NULL, "%s socket: %s",
+				psoe->so_tname, strerror(errno));
 		}
 	}
 	memset(&sin6, 0, sizeof(sin6));
 	sin6.sin6_family = AF_INET6;
 	sin6.sin6_addr = in6addr_loopback;
 	if (bind(sr, (struct sockaddr *)&sin6, sizeof(sin6)) < 0) {
-		tst_resm(TBROK, "%s: bind: %s", psoe->so_tname,
-			 strerror(errno));
+		tst_brkm(TBROK | TERRNO, NULL, "%s: bind: %s",
+			psoe->so_tname, strerror(errno));
 	}
 	if (setsockopt(sr, SOL_IPV6, psoe->so_opt, &psoe->so_clrval,
 		       psoe->so_valsize) < 0) {
-		tst_resm(TBROK, "%s: setsockopt: %s", psoe->so_tname,
-			 strerror(errno));
-		return;
+		tst_brkm(TBROK | TERRNO, NULL, "%s: setsockopt: %s",
+			psoe->so_tname, strerror(errno));
 	}
 	TEST(setsockopt(sr, SOL_IPV6, psoe->so_opt, &psoe->so_setval,
 			psoe->so_valsize));
@@ -337,25 +309,23 @@ void so_test(struct soent *psoe)
 	valsize = psoe->so_valsize;
 	TEST(getsockopt(sr, SOL_IPV6, psoe->so_opt, &sobuf, &valsize));
 	if (TEST_RETURN != 0) {
-		tst_resm(TBROK, "%s set-get: getsockopt: %s", psoe->so_tname,
-			 strerror(errno));
-		return;
-	} else if (memcmp(&psoe->so_setval, &sobuf, psoe->so_valsize))
+		tst_brkm(TBROK | TTERRNO, NULL, "%s set-get: getsockopt: %s",
+			psoe->so_tname, strerror(errno));
+	} else if (memcmp(&psoe->so_setval, &sobuf, psoe->so_valsize)) {
 		tst_resm(TFAIL, "%s set-get optval != setval", psoe->so_tname);
-	else
-		tst_resm(TPASS, "%s set-get", psoe->so_tname);
+		return;
+	} else {
+		tst_resm(TINFO, "%s set-get", psoe->so_tname);
+	}
 
 	st = socket(PF_INET6, SOCK_RAW, NH_TEST);
 	if (st < 0) {
-		tst_resm(TBROK, "%s transmit socket: %s", psoe->so_tname,
-			 strerror(errno));
-		return;
+		tst_brkm(TBROK | TERRNO, NULL, "%s transmit socket: %s",
+			psoe->so_tname, strerror(errno));
 	}
 	if (sendall(st) < 0) {
-		tst_resm(TBROK, "%s transmit sendto: %s", psoe->so_tname,
-			 strerror(errno));
-		close(st);
-		return;
+		tst_brkm(TBROK, NULL, "%s transmit sendto: %s",
+			psoe->so_tname, strerror(errno));
 	}
 	close(st);
 
@@ -382,14 +352,12 @@ void so_test(struct soent *psoe)
 			if (nfds < 0) {
 				if (errno == EINTR)
 					continue;
-				tst_resm(TBROK, "%s select: %s", psoe->so_tname,
-					 strerror(errno));
-				return;
+				tst_brkm(TBROK | TERRNO, NULL, "%s select: %s",
+					psoe->so_tname, strerror(errno));
 			}
 			if (nfds == 0) {
-				tst_resm(TBROK, "%s recvmsg timed out",
+				tst_brkm(TBROK, NULL, "%s recvmsg timed out",
 					 psoe->so_tname);
-				return;
 			}
 			/* else, nfds == 1 */
 			if (!FD_ISSET(sr, &rfds))
@@ -405,11 +373,9 @@ void so_test(struct soent *psoe)
 
 			cc = recvmsg(sr, &msg, 0);
 			if (cc < 0) {
-				tst_resm(TBROK, "%s recvmsg: %s",
+				tst_brkm(TBROK | TERRNO, NULL, "%s recvmsg: %s",
 					 psoe->so_tname, strerror(errno));
-				return;
 			}
-/* check pid & seq here */
 			break;
 		}
 		gotone = 0;
@@ -429,11 +395,31 @@ void so_test(struct soent *psoe)
 				return;
 			}
 		}
-/* check contents here */
-		if (psoe->so_dorecv)
-			tst_resm(gotone ? TPASS : TFAIL, "%s receive",
-				 psoe->so_tname);
+		if (psoe->so_dorecv) {
+			if (gotone)
+				tst_resm(TINFO, "%s receive", psoe->so_tname);
+			else
+				tst_resm(TFAIL, "%s receive", psoe->so_tname);
+		}
 	}
+
+	count++;
+}
+
+void test_soent(void)
+{
+	unsigned int i;
+
+	for (i = 0; i < SOCOUNT; ++i) {
+		sotab[i].so_clrval.sou_bool = 0;
+		sotab[i].so_setval.sou_bool = 1;
+		so_test(&sotab[i]);
+	}
+
+	if (count < SOCOUNT)
+		tst_resm(TPASS, "socket set-get/receive tests fail");
+	else
+		tst_resm(TPASS, "socket set-get/receive tests succeed");
 }
 
 #define IPV6_ADDR_NODE		1
@@ -449,7 +435,7 @@ static int ipv6_addr_scope(struct in6_addr *pin6)
 		return IPV6_ADDR_NODE;
 	return IPV6_ADDR_GLOBAL;
 }
-#endif /* HAVE_IFADDRS_H */
+#endif
 
 int getsock(char *tname, struct sockaddr_in6 *psin6_arg, int scope)
 {
@@ -462,8 +448,7 @@ int getsock(char *tname, struct sockaddr_in6 *psin6_arg, int scope)
 	int s;
 
 	if (!pifa_head && getifaddrs(&pifa_head)) {
-		tst_resm(TBROK, "%s: getifaddrs failed", tname);
-		return -1;
+		tst_brkm(TBROK, NULL, "%s: getifaddrs failed", tname);
 	}
 	if (psin6_arg)
 		ifindex = psin6_arg->sin6_scope_id;
@@ -483,20 +468,19 @@ int getsock(char *tname, struct sockaddr_in6 *psin6_arg, int scope)
 		     (this_scope > 0 && this_scope != scope)))
 			continue;
 		psin6->sin6_scope_id = if_nametoindex(pifa->ifa_name);
-		if ((ifindex < 0 && -ifindex == psin6->sin6_scope_id) ||
-		    (ifindex > 0 && ifindex != psin6->sin6_scope_id))
+		if ((ifindex < 0 && -(unsigned int)ifindex ==
+			psin6->sin6_scope_id) || (ifindex > 0 &&
+			(unsigned int)ifindex != psin6->sin6_scope_id))
 			continue;
 		s = socket(PF_INET6, SOCK_DGRAM, 0);
 		if (s < 0) {
-			tst_resm(TBROK, "%s: socket %s", tname,
+			tst_brkm(TBROK | TERRNO, NULL, "%s: socket %s", tname,
 				 strerror(errno));
-			return -1;
 		}
 		if (bind(s, pifa->ifa_addr, sizeof(struct sockaddr_in6)) < 0) {
-			tst_resm(TBROK, "%s: bind \"%s\": %s", tname,
-				 inet_ntop(AF_INET6, &psin6->sin6_addr, strbuf,
-					   sizeof(strbuf)), strerror(errno));
-			return -1;
+			tst_brkm(TBROK | TERRNO, NULL, "%s: bind \"%s\": %s",
+				tname, inet_ntop(AF_INET6, &psin6->sin6_addr,
+				strbuf, sizeof(strbuf)), strerror(errno));
 		}
 		if (psin6_arg) {
 			*psin6_arg = *psin6;
@@ -530,15 +514,13 @@ int getsock(char *tname, struct sockaddr_in6 *psin6_arg, int scope)
 		else
 			intfstr = 0;
 
-		if (intfstr)
-			tst_resm(TBROK, "%s: getsock : no%s addresses%s %d",
-				 tname, scopestr, intfstr, ifindex);
-		else
+		if (intfstr == 0) {
 			tst_resm(TBROK, "%s: getsock : no%s addresses",
 				 tname, scopestr);
+		}
 	}
 	return -1;
-#else /* HAVE_IFADDRS_H */
+#else
 	return -1;
 #endif
 }
@@ -563,98 +545,76 @@ void test_pktinfo(void)
 
 	s_snd = getsock(tname, 0, IPV6_ADDR_GLOBAL);
 	if (s_snd < 0) {
-		tst_resm(TBROK, "%s: can't create send socket", tname);
-		return;
+		tst_brkm(TBROK, NULL, "%s: can't create send socket", tname);
 	}
 	/* global-scope address, interface X */
 	sa_rcv[0].sin6_scope_id = 0;
 	s_rcv[0] = getsock(tname, &sa_rcv[0], IPV6_ADDR_GLOBAL);
 	if (s_rcv[0] == -1) {
-		tst_resm(TBROK, "%s: only link-scope addresses", tname);
-		return;
+		tst_brkm(TBROK, NULL, "%s: only link-scope addresses", tname);
 	}
 	/* link-local-scope address, interface X */
 	sa_rcv[1].sin6_scope_id = sa_rcv[0].sin6_scope_id;
 	s_rcv[1] = getsock(tname, &sa_rcv[1], IPV6_ADDR_LINK);
 	if (s_rcv[1] < 0) {
-		tst_resm(TBROK, "%s: no link-local address on ifindex %d",
+		tst_brkm(TBROK, NULL, "%s: no link-local address on ifindex %d",
 			 tname, sa_rcv[0].sin6_scope_id);
-		return;
 	}
 	/* link-local-scope address, interface Y */
 	sa_rcv[2].sin6_scope_id = -sa_rcv[0].sin6_scope_id;
 	s_rcv[2] = getsock(tname, &sa_rcv[2], IPV6_ADDR_LINK);
 	if (s_rcv[2] < 0) {
-		tst_resm(TBROK, "%s: only one interface?", tname);
-		return;
+		tst_brkm(TBROK, NULL, "%s: only one interface?", tname);
 	}
 	/* send to rcv1 to verify communication */
 	/* force to rcv2 w/ PKTINFO */
-/* TESTS: */
-/* sticky set-get */
+	/* TESTS: */
+	/* sticky set-get */
 	tname = "IPV6_PKTINFO set";
 	pi.ipi6_addr = sa_rcv[1].sin6_addr;
 	pi.ipi6_ifindex = sa_rcv[1].sin6_scope_id;
 	TEST(setsockopt(s_snd, SOL_IPV6, IPV6_PKTINFO, &pi, sizeof(pi)));
-	if (TEST_RETURN != 0)
+	if (TEST_RETURN != 0) {
 		tst_resm(TFAIL, "%s: %s", tname, strerror(errno));
-	else
-		tst_resm(TPASS, "%s", tname);
+		return;
+	} else {
+		tst_resm(TINFO, "%s", tname);
+	}
 
 	tname = "IPV6_PKTINFO get";
 	optlen = sizeof(pi_tmp);
 	TEST(getsockopt(s_snd, SOL_IPV6, IPV6_PKTINFO, &pi_tmp, &optlen));
-	if (TEST_RETURN != 0)
+	if (TEST_RETURN != 0) {
 		tst_resm(TFAIL, "%s: %s", tname, strerror(errno));
-	else if (memcmp(&pi, &pi_tmp, sizeof(pi)) != 0) {
+		return;
+	} else if (memcmp(&pi, &pi_tmp, sizeof(pi)) != 0) {
 		char strbuf2[64];
 		tst_resm(TFAIL, "%s: {\"%s\",%d} != {\"%s\",%d}", tname,
 			 inet_ntop(AF_INET6, &pi_tmp.ipi6_addr, strbuf,
 				   sizeof(strbuf)), pi_tmp.ipi6_ifindex,
 			 inet_ntop(AF_INET6, &pi.ipi6_addr, strbuf2,
 				   sizeof(strbuf2)), pi.ipi6_ifindex);
-	} else
-		tst_resm(TPASS, "%s", tname);
-/* ancillary data override */
-/* link-local, wrong interface */
+		return;
+	} else {
+		tst_resm(TINFO, "%s", tname);
+	}
+	/* ancillary data override */
+	/* link-local, wrong interface */
 	tname = "IPV6_PKTINFO invalid {lladdr, intf}";
 	pi.ipi6_addr = sa_rcv[1].sin6_addr;
 	pi.ipi6_ifindex = sa_rcv[2].sin6_scope_id;
 	TEST(setsockopt(s_snd, SOL_IPV6, IPV6_PKTINFO, &pi, sizeof(pi)));
-	if (TEST_RETURN == 0)
+	if (TEST_RETURN == 0) {
 		tst_resm(TFAIL, "%s returns success, should be -1, EINVAL",
 			 tname);
-	else if (TEST_ERRNO != EINVAL)
+		return;
+	} else if (TEST_ERRNO != EINVAL) {
 		tst_resm(TFAIL, "%s errno %d != %d", tname, TEST_ERRNO, EINVAL);
-	else
-		tst_resm(TPASS, "%s", tname);
-/* nonexistent interface */
-/* non-local address */
-/* clear address */
-/* clear interface */
-/* sendmsg() sin6_scope differs with ancillary data interface */
-}
-#endif /* notyet */
-
-void do_tests(void)
-{
-	int i;
-
-	for (i = 0; i < SOCOUNT; ++i) {
-		sotab[i].so_clrval.sou_bool = 0;
-		sotab[i].so_setval.sou_bool = 1;
-		so_test(&sotab[i]);
+		return;
+	} else {
+		tst_resm(TINFO, "%s", tname);
 	}
-#ifdef notyet
-	test_pktinfo();
-#endif /* notyet - see test_pktinfo() comment above */
-}
 
-void setup(void)
-{
-	TEST_PAUSE;		/* if -P option specified */
-}
-
-void cleanup(void)
-{
+	tst_resm(TPASS, "IPV6_PKTINFO tests succeed");
 }
+#endif
-- 
1.9.3


------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [LTP] [PATCH 5/6] lib6/getaddrinfo_01.c: cleanup
  2015-03-31  7:46 [LTP] [PATCH 1/6] lib6/runcc.c: use TCONF instead of TBROK when no C compiler is present Xing Gu
                   ` (2 preceding siblings ...)
  2015-03-31  7:46 ` [LTP] [PATCH 4/6] lib6/asapi_06.c: cleanup Xing Gu
@ 2015-03-31  7:46 ` Xing Gu
  2015-03-31  7:46 ` [LTP] [PATCH 6/6] ipv6_lib: add it into default Xing Gu
  2015-03-31 14:52 ` [LTP] [PATCH 1/6] lib6/runcc.c: use TCONF instead of TBROK when no C compiler is present Alexey Kodanev
  5 siblings, 0 replies; 55+ messages in thread
From: Xing Gu @ 2015-03-31  7:46 UTC (permalink / raw)
  To: ltp-list

* Remove cleanup() function.
* Remove useless comments.
* Move the test body from main() to (*testfunc[])().
* In every test function, using TINFO instead of TPASS
  marks the success of each inner test.
* Some cleanup.

Signed-off-by: Xing Gu <gux.fnst@cn.fujitsu.com>
---
 testcases/network/lib6/getaddrinfo_01.c | 484 ++++++++++++++++++--------------
 1 file changed, 275 insertions(+), 209 deletions(-)

diff --git a/testcases/network/lib6/getaddrinfo_01.c b/testcases/network/lib6/getaddrinfo_01.c
index ec29b5d..b355eee 100644
--- a/testcases/network/lib6/getaddrinfo_01.c
+++ b/testcases/network/lib6/getaddrinfo_01.c
@@ -1,6 +1,7 @@
 /*
  *
  *   Copyright (c) International Business Machines  Corp., 2001
+ *   Author: David L Stevens
  *
  *   This program is free software;  you can redistribute it and/or modify
  *   it under the terms of the GNU General Public License as published by
@@ -13,31 +14,12 @@
  *   the GNU General Public License for more details.
  *
  *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *   along with this program;  if not, write to the Free Software Foundation,
+ *   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
-
 /*
- * Test Name: getaddrinfo_01
- *
- * Test Description:
- *  Tests for getaddrinfo library function
- *
- * Usage:  <for command-line>
- *  getaddrinfo_01 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -e   : Turn on errno logging.
- *	       -i n : Execute test n times.
- *	       -I x : Execute test for x seconds.
- *	       -P x : Pause for x seconds between iterations.
- *	       -t   : Turn on syscall timing.
- *
- * HISTORY
- *	07/2004 written by David L Stevens
- *
- * RESTRICTIONS:
- *  None.
- *
+ *   Description:
+ *     Tests for getaddrinfo library function.
  */
 
 #include <unistd.h>
@@ -53,39 +35,40 @@
 #define AI_V4MAPPED    0x0008	/* IPv4 mapped addresses are acceptable.  */
 #endif
 
-char *TCID = "getaddrinfo_01";	/* Test program identifier.    */
-int testno;
-
-void setup(void), cleanup(void);
-
-int TST_TOTAL = 1;
+static void setup(void);
+static void gaiv4(void);
+static void gaiv6(void);
 
-/* a host that isn't where LTP is running */
-#define REMOTEHOSTNAME	"www.ibm.com"
+static void (*testfunc[])(void) = { gaiv4, gaiv6 };
 
-void gaiv4(void), gaiv6(void);
-void dumpres(struct addrinfo *);
+char *TCID = "getaddrinfo_01";
+int TST_TOTAL = ARRAY_SIZE(testfunc);
 
 int main(int argc, char *argv[])
 {
 	int lc;
+	int i;
 
-	/* Parse standard options given to run the test. */
 	tst_parse_opts(argc, argv, NULL, NULL);
 
 	setup();
 
 	for (lc = 0; TEST_LOOPING(lc); ++lc) {
-		gaiv4();
-		gaiv6();
+		tst_count = 0;
+
+		for (i = 0; i < TST_TOTAL; i++)
+			(*testfunc[i])();
 	}
-	cleanup();
 
-	return (0);
+	tst_exit();
 }
 
-/* getaddrinfo tests (v4) */
+void setup(void)
+{
+	TEST_PAUSE;
+}
 
+/* getaddrinfo tests (v4) */
 void gaiv4(void)
 {
 	struct addrinfo *aires, hints, *pai;
@@ -132,13 +115,18 @@ void gaiv4(void)
 				 psin ? psin->sin_family : 0,
 				 psin ? psin->sin_port : 0,
 				 psin ? htons(psin->sin_port) : 0);
-		} else
-			tst_resm(TPASS, "getaddrinfo IPv4 basic lookup");
-		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN ? TFAIL : TPASS, "getaddrinfo IPv4 basic "
+			freeaddrinfo(aires);
+			return;
+		} else {
+			tst_resm(TINFO, "getaddrinfo IPv4 basic lookup");
+			freeaddrinfo(aires);
+		}
+	} else {
+		tst_resm(TFAIL, "getaddrinfo IPv4 basic "
 			 "lookup (\"%s\") returns %ld (\"%s\")", hostname,
 			 TEST_RETURN, gai_strerror(TEST_RETURN));
+		return;
+	}
 
 	/* test 2, IPv4 canonical name */
 	memset(&hints, 0, sizeof(hints));
@@ -152,20 +140,26 @@ void gaiv4(void)
 		if (!pai) {
 			tst_resm(TFAIL, "getaddrinfo IPv4 canonical name: no "
 				 "entries with canonical name set");
+			freeaddrinfo(aires);
+			return;
 		} else if (strcasecmp(hostname, pai->ai_canonname)) {
 			tst_resm(TFAIL, "getaddrinfo IPv4 canonical name "
 				 "(\"%s\") doesn't match hostname (\"%s\")",
 				 pai->ai_canonname, hostname);
-		} else
-			tst_resm(TPASS, "getaddrinfo IPv4 canonical name");
-		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN ? TFAIL : TPASS, "getaddrinfo IPv4 "
+			freeaddrinfo(aires);
+			return;
+		} else {
+			tst_resm(TINFO, "getaddrinfo IPv4 canonical name");
+			freeaddrinfo(aires);
+		}
+	} else {
+		tst_resm(TFAIL, "getaddrinfo IPv4 "
 			 "canonical name (\"%s\") returns %ld (\"%s\")",
 			 shortname, TEST_RETURN, gai_strerror(TEST_RETURN));
+		return;
+	}
 
 	/* test 3, IPv4 host+service name */
-
 	memset(&hints, 0, sizeof(hints));
 	/*
 	 * These are hard-coded for echo/7 to avoid using getservbyname(),
@@ -200,13 +194,18 @@ void gaiv4(void)
 				 psin ? psin->sin_family : 0,
 				 psin ? psin->sin_port : 0,
 				 psin ? htons(psin->sin_port) : 0);
-		} else
-			tst_resm(TPASS, "getaddrinfo IPv4 host+service");
-		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN ? TFAIL : TPASS, "getaddrinfo IPv4 host+"
+			freeaddrinfo(aires);
+			return;
+		} else {
+			tst_resm(TINFO, "getaddrinfo IPv4 host+service");
+			freeaddrinfo(aires);
+		}
+	} else {
+		tst_resm(TFAIL, "getaddrinfo IPv4 host+"
 			 "service returns %ld (\"%s\")", TEST_RETURN,
 			 gai_strerror(TEST_RETURN));
+		return;
+	}
 
 	/* test 4, IPv4 hostname+service, AI_PASSIVE */
 	memset(&hints, 0, sizeof(hints));
@@ -244,18 +243,22 @@ void gaiv4(void)
 				 psin ? psin->sin_family : 0,
 				 psin ? psin->sin_port : 0,
 				 psin ? htons(psin->sin_port) : 0);
-		} else
-			tst_resm(TPASS,
+			freeaddrinfo(aires);
+			return;
+		} else {
+			tst_resm(TINFO,
 				 "getaddrinfo IPv4 host+service PASSIVE");
-		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN ? TFAIL : TPASS, "getaddrinfo IPv4 host+"
+			freeaddrinfo(aires);
+		}
+	} else {
+		tst_resm(TFAIL, "getaddrinfo IPv4 host+"
 			 "service, PASSIVE (\"%s\", \"%s\") returns %ld (\"%s\")",
 			 hostname, service, TEST_RETURN,
 			 gai_strerror(TEST_RETURN));
+		return;
+	}
 
 	/* test 5, IPv4 host+service w/ AI_NUMERICHOST */
-
 	memset(&hints, 0, sizeof(hints));
 	strcpy(service, "echo");
 	servnum = 7;
@@ -266,8 +269,11 @@ void gaiv4(void)
 		tst_resm(TFAIL, "getaddrinfo IPv4 AI_NUMERICHOST w/ hostname: "
 			 "returns %ld expected %d (EAI_NONAME)",
 			 TEST_RETURN, EAI_NONAME);
+		if (!TEST_RETURN)
+			freeaddrinfo(aires);
+		return;
 	} else
-		tst_resm(TPASS, "getaddrinfo IPv4 AI_NUMERICHOST w/ hostname");
+		tst_resm(TINFO, "getaddrinfo IPv4 AI_NUMERICHOST w/ hostname");
 	if (!TEST_RETURN)
 		freeaddrinfo(aires);
 
@@ -306,17 +312,28 @@ void gaiv4(void)
 				 psin ? psin->sin_family : 0,
 				 psin ? psin->sin_port : 0,
 				 psin ? htons(psin->sin_port) : 0);
-		} else
-			tst_resm(TPASS, "getaddrinfo IPv4 0+service, PASSIVE");
-		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN == EAI_BADFLAGS ? TPASS : TFAIL,
-			 "getaddrinfo IPv4 0+service, PASSIVE (\"\", \"%s\") "
-			 "returns %ld (\"%s\")", service, TEST_RETURN,
-			 gai_strerror(TEST_RETURN));
+			freeaddrinfo(aires);
+			return;
+		} else {
+			tst_resm(TINFO, "getaddrinfo IPv4 0+service, PASSIVE");
+			freeaddrinfo(aires);
+		}
+	} else {
+		if (TEST_RETURN == EAI_BADFLAGS) {
+			tst_resm(TINFO, "getaddrinfo IPv4 0+service,"
+				" PASSIVE (\"\", \"%s\") returns %ld (\"%s\")",
+				service, TEST_RETURN,
+				gai_strerror(TEST_RETURN));
+		} else {
+			tst_resm(TFAIL, "getaddrinfo IPv4 0+service,i"
+				" PASSIVE (\"\", \"%s\") returns %ld (\"%s\")",
+				service, TEST_RETURN,
+				gai_strerror(TEST_RETURN));
+			return;
+		}
+	}
 
 	/* test 7, IPv4 0+service */
-
 	memset(&hints, 0, sizeof(hints));
 	hints.ai_family = AF_INET;
 	hints.ai_socktype = SOCK_STREAM;
@@ -350,19 +367,30 @@ void gaiv4(void)
 				 psin ? psin->sin_family : 0,
 				 psin ? psin->sin_port : 0,
 				 psin ? htons(psin->sin_port) : 0);
-		} else
-			tst_resm(TPASS, "getaddrinfo IPv4 0+service");
-		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN == EAI_BADFLAGS ? TPASS : TFAIL,
-			 "getaddrinfo IPv4 0+service (\"\", \"%s\") returns %ld "
-			 "(\"%s\")", service, TEST_RETURN,
-			 gai_strerror(TEST_RETURN));
+			freeaddrinfo(aires);
+			return;
+		} else {
+			tst_resm(TINFO, "getaddrinfo IPv4 0+service");
+			freeaddrinfo(aires);
+		}
+	} else {
+		if (TEST_RETURN == EAI_BADFLAGS) {
+			tst_resm(TINFO, "getaddrinfo IPv4 "
+				"0+service (\"\", \"%s\") returns %ld (\"%s\")",
+				service, TEST_RETURN,
+				gai_strerror(TEST_RETURN));
+		} else {
+			tst_resm(TFAIL, "getaddrinfo IPv4 "
+				"0+service (\"\", \"%s\") returns %ld (\"%s\")",
+				service, TEST_RETURN,
+				gai_strerror(TEST_RETURN));
+			return;
+		}
+	}
 
 	/* test 8, IPv4 host+service, AI_NUMERICSERV */
-
 #ifndef AI_NUMERICSERV
-	tst_resm(TFAIL, "getaddrinfo IPv4 host+service, AI_NUMERICSERV: flag "
+	tst_resm(TCONF, "getaddrinfo IPv4 host+service, AI_NUMERICSERV: flag "
 		 "not implemented");
 #else
 	memset(&hints, 0, sizeof(hints));
@@ -376,15 +404,18 @@ void gaiv4(void)
 			 "getaddrinfo IPv4 host+service, AI_NUMERICSERV: "
 			 "returns %ld (\"%s\") expected %d (EAI_NONAME)",
 			 TEST_RETURN, gai_strerror(TEST_RETURN), EAI_NONAME);
-	} else
-		tst_resm(TPASS,
+		if (!TEST_RETURN)
+			freeaddrinfo(aires);
+		return;
+	} else {
+		tst_resm(TINFO,
 			 "getaddrinfo IPv4 host+service, AI_NUMERICSERV");
+	}
 	if (!TEST_RETURN)
 		freeaddrinfo(aires);
 #endif /* AI_NUMERICSERV */
 
 	/* test 9, IPv4 SOCK_STREAM/IPPROTO_UDP hints */
-
 	memset(&hints, 0, sizeof(hints));
 	hints.ai_family = AF_INET;
 	hints.ai_socktype = SOCK_STREAM;
@@ -396,12 +427,13 @@ void gaiv4(void)
 		tst_resm(TFAIL, "getaddrinfo IPv4 SOCK_STREAM/IPPROTO_UDP "
 			 "hints");
 		freeaddrinfo(aires);
-	} else
-		tst_resm(TPASS, "getaddrinfo IPv4 SOCK_STREAM/IPPROTO_UDP "
+		return;
+	} else {
+		tst_resm(TINFO, "getaddrinfo IPv4 SOCK_STREAM/IPPROTO_UDP "
 			 "hints");
+	}
 
 	/* test 10, IPv4 socktype 0, 513 */
-
 	memset(&hints, 0, sizeof(hints));
 	hints.ai_family = AF_INET;
 	hints.ai_socktype = 0;
@@ -439,20 +471,31 @@ void gaiv4(void)
 				 psin ? psin->sin_family : 0,
 				 psin ? psin->sin_port : 0,
 				 psin ? htons(psin->sin_port) : 0);
-		} else if (got_tcp && got_udp)
-			tst_resm(TPASS, "getaddrinfo IPv4 socktype 0,513");
-		else
+			freeaddrinfo(aires);
+			return;
+		} else if (got_tcp && got_udp) {
+			tst_resm(TINFO, "getaddrinfo IPv4 socktype 0,513");
+			freeaddrinfo(aires);
+		} else {
 			tst_resm(TFAIL, "getaddrinfo IPv4 socktype 0,513 TCP %d"
 				 " UDP %d", got_tcp, got_udp);
-		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN == EAI_BADFLAGS ? TPASS : TFAIL,
-			 "getaddrinfo IPv4 socktype 0,513 (\"\", \"%s\") returns"
-			 " %ld (\"%s\")", service, TEST_RETURN,
-			 gai_strerror(TEST_RETURN));
+			freeaddrinfo(aires);
+			return;
+		}
+	} else {
+		if (TEST_RETURN == EAI_BADFLAGS) {
+			tst_resm(TINFO, "getaddrinfo IPv4 socktype 0,513"
+				" (\"\", \"%s\") returns %ld (\"%s\")", service,
+				TEST_RETURN, gai_strerror(TEST_RETURN));
+		} else {
+			tst_resm(TFAIL, "getaddrinfo IPv4 socktype 0,513"
+				" (\"\", \"%s\") returns %ld (\"%s\")", service,
+				TEST_RETURN, gai_strerror(TEST_RETURN));
+			return;
+		}
+	}
 
 	/* test 11, IPv4 AI_V4MAPPED */
-
 	/* AI_V4MAPPED should be ignored because family != AF_INET6 */
 	memset(&hints, 0, sizeof(hints));
 	hints.ai_family = AF_INET;
@@ -482,17 +525,24 @@ void gaiv4(void)
 				 psin ? psin->sin_family : 0,
 				 psin ? psin->sin_port : 0,
 				 psin ? htons(psin->sin_port) : 0);
-		} else
-			tst_resm(TPASS, "getaddrinfo IPv4 AI_V4MAPPED");
-		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN ? TFAIL : TPASS, "getaddrinfo IPv4 "
+			freeaddrinfo(aires);
+			return;
+		} else {
+			tst_resm(TINFO, "getaddrinfo IPv4 AI_V4MAPPED");
+			freeaddrinfo(aires);
+		}
+	} else {
+		tst_resm(TFAIL, "getaddrinfo IPv4 "
 			 "AI_V4MAPPED (\"%s\") returns %ld (\"%s\")", hostname,
 			 TEST_RETURN, gai_strerror(TEST_RETURN));
+		return;
+	}
+
+
+	tst_resm(TPASS, "getaddrinfo tests (v4) succeed");
 }
 
 /* getaddrinfo tests (v6) */
-
 void gaiv6(void)
 {
 	struct addrinfo *aires, hints, *pai;
@@ -539,13 +589,18 @@ void gaiv6(void)
 				 psin6 ? psin6->sin6_family : 0,
 				 psin6 ? psin6->sin6_port : 0,
 				 psin6 ? htons(psin6->sin6_port) : 0);
-		} else
-			tst_resm(TPASS, "getaddrinfo IPv6 basic lookup");
-		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN ? TFAIL : TPASS, "getaddrinfo IPv6 basic "
+			freeaddrinfo(aires);
+			return;
+		} else {
+			tst_resm(TINFO, "getaddrinfo IPv6 basic lookup");
+			freeaddrinfo(aires);
+		}
+	} else {
+		tst_resm(TFAIL, "getaddrinfo IPv6 basic "
 			 "lookup (\"%s\") returns %ld (\"%s\")", hostname,
 			 TEST_RETURN, gai_strerror(TEST_RETURN));
+		return;
+	}
 
 	/* test 13, IPv6 canonical name */
 	memset(&hints, 0, sizeof(hints));
@@ -559,20 +614,26 @@ void gaiv6(void)
 		if (!pai) {
 			tst_resm(TFAIL, "getaddrinfo IPv6 canonical name: no "
 				 "entries with canonical name set");
+			freeaddrinfo(aires);
+			return;
 		} else if (strcasecmp(hostname, pai->ai_canonname)) {
 			tst_resm(TFAIL, "getaddrinfo IPv6 canonical name "
 				 "(\"%s\") doesn't match hostname (\"%s\")",
 				 pai->ai_canonname, hostname);
-		} else
-			tst_resm(TPASS, "getaddrinfo IPv6 canonical name");
-		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN ? TFAIL : TPASS, "getaddrinfo IPv6 "
+			freeaddrinfo(aires);
+			return;
+		} else {
+			tst_resm(TINFO, "getaddrinfo IPv6 canonical name");
+			freeaddrinfo(aires);
+		}
+	} else {
+		tst_resm(TFAIL, "getaddrinfo IPv6 "
 			 "canonical name (\"%s\") returns %ld (\"%s\")",
 			 shortname, TEST_RETURN, gai_strerror(TEST_RETURN));
+		return;
+	}
 
 	/* test 14, IPv6 host+service name */
-
 	memset(&hints, 0, sizeof(hints));
 	/*
 	 * These are hard-coded for echo/7 to avoid using getservbyname(),
@@ -607,13 +668,18 @@ void gaiv6(void)
 				 psin6 ? psin6->sin6_family : 0,
 				 psin6 ? psin6->sin6_port : 0,
 				 psin6 ? htons(psin6->sin6_port) : 0);
-		} else
-			tst_resm(TPASS, "getaddrinfo IPv6 host+service");
-		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN ? TFAIL : TPASS, "getaddrinfo IPv6 host+"
+			freeaddrinfo(aires);
+			return;
+		} else {
+			tst_resm(TINFO, "getaddrinfo IPv6 host+service");
+			freeaddrinfo(aires);
+		}
+	} else {
+		tst_resm(TFAIL, "getaddrinfo IPv6 host+"
 			 "service returns %ld (\"%s\")", TEST_RETURN,
 			 gai_strerror(TEST_RETURN));
+		return;
+	}
 
 	/* test 15, IPv6 hostname+service, AI_PASSIVE */
 	memset(&hints, 0, sizeof(hints));
@@ -652,18 +718,22 @@ void gaiv6(void)
 				 psin6 ? psin6->sin6_family : 0,
 				 psin6 ? psin6->sin6_port : 0,
 				 psin6 ? htons(psin6->sin6_port) : 0);
-		} else
-			tst_resm(TPASS,
+			freeaddrinfo(aires);
+			return;
+		} else {
+			tst_resm(TINFO,
 				 "getaddrinfo IPv6 host+service PASSIVE");
-		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN ? TFAIL : TPASS, "getaddrinfo IPv6 host+"
+			freeaddrinfo(aires);
+		}
+	} else {
+		tst_resm(TFAIL, "getaddrinfo IPv6 host+"
 			 "service, PASSIVE (\"%s\", \"%s\") returns %ld (\"%s\")",
 			 hostname, service, TEST_RETURN,
 			 gai_strerror(TEST_RETURN));
+		return;
+	}
 
 	/* test 16, IPv6 host+service w/ AI_NUMERICHOST */
-
 	memset(&hints, 0, sizeof(hints));
 	strcpy(service, "echo");
 	servnum = 7;
@@ -674,8 +744,11 @@ void gaiv6(void)
 		tst_resm(TFAIL, "getaddrinfo IPv6 AI_NUMERICHOST w/ hostname: "
 			 "returns %ld expected %d (EAI_NONAME)",
 			 TEST_RETURN, EAI_NONAME);
+		if (!TEST_RETURN)
+			freeaddrinfo(aires);
+		return;
 	} else
-		tst_resm(TPASS, "getaddrinfo IPv6 AI_NUMERICHOST w/ hostname");
+		tst_resm(TINFO, "getaddrinfo IPv6 AI_NUMERICHOST w/ hostname");
 	if (!TEST_RETURN)
 		freeaddrinfo(aires);
 
@@ -715,17 +788,26 @@ void gaiv6(void)
 				 psin6 ? psin6->sin6_family : 0,
 				 psin6 ? psin6->sin6_port : 0,
 				 psin6 ? htons(psin6->sin6_port) : 0);
-		} else
-			tst_resm(TPASS, "getaddrinfo IPv6 0+service, PASSIVE");
-		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN == EAI_BADFLAGS ? TPASS : TFAIL,
-			 "getaddrinfo IPv6 0+service, PASSIVE (\"\", \"%s\") "
-			 "returns %ld (\"%s\")", service, TEST_RETURN,
-			 gai_strerror(TEST_RETURN));
+			freeaddrinfo(aires);
+			return;
+		} else {
+			tst_resm(TINFO, "getaddrinfo IPv6 0+service, PASSIVE");
+			freeaddrinfo(aires);
+		}
+	} else {
+		if (TEST_RETURN == EAI_BADFLAGS) {
+			tst_resm(TINFO, "getaddrinfo IPv6 0+service, PASSIVE"
+				" (\"\", \"%s\") returns %ld (\"%s\")", service,
+				TEST_RETURN, gai_strerror(TEST_RETURN));
+		} else {
+			tst_resm(TFAIL, "getaddrinfo IPv6 0+service, PASSIVE"
+				" (\"\", \"%s\") returns %ld (\"%s\")", service,
+				TEST_RETURN, gai_strerror(TEST_RETURN));
+			return;
+		}
+	}
 
 	/* test 18, IPv6 0+service */
-
 	memset(&hints, 0, sizeof(hints));
 	hints.ai_family = AF_INET6;
 	hints.ai_socktype = SOCK_STREAM;
@@ -760,19 +842,28 @@ void gaiv6(void)
 				 psin6 ? psin6->sin6_family : 0,
 				 psin6 ? psin6->sin6_port : 0,
 				 psin6 ? htons(psin6->sin6_port) : 0);
-		} else
-			tst_resm(TPASS, "getaddrinfo IPv6 0+service");
-		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN == EAI_BADFLAGS ? TPASS : TFAIL,
-			 "getaddrinfo IPv6 0+service (\"\", \"%s\") returns %ld "
-			 "(\"%s\")", service, TEST_RETURN,
-			 gai_strerror(TEST_RETURN));
+			freeaddrinfo(aires);
+			return;
+		} else {
+			tst_resm(TINFO, "getaddrinfo IPv6 0+service");
+			freeaddrinfo(aires);
+		}
+	} else {
+		if (TEST_RETURN == EAI_BADFLAGS) {
+			tst_resm(TINFO, "getaddrinfo IPv6 0+service"
+				" (\"\", \"%s\") returns %ld (\"%s\")", service,
+				TEST_RETURN, gai_strerror(TEST_RETURN));
+		} else {
+			tst_resm(TFAIL, "getaddrinfo IPv6 0+service"
+				" (\"\", \"%s\") returns %ld (\"%s\")", service,
+				TEST_RETURN, gai_strerror(TEST_RETURN));
+			return;
+		}
+	}
 
 	/* test 19, IPv6 host+service, AI_NUMERICSERV */
-
 #ifndef AI_NUMERICSERV
-	tst_resm(TFAIL, "getaddrinfo IPv6 host+service, AI_NUMERICSERV: flag "
+	tst_resm(TCONF, "getaddrinfo IPv6 host+service, AI_NUMERICSERV: flag "
 		 "not implemented");
 #else
 	memset(&hints, 0, sizeof(hints));
@@ -786,15 +877,17 @@ void gaiv6(void)
 			 "getaddrinfo IPv6 host+service, AI_NUMERICSERV: "
 			 "returns %ld (\"%s\") expected %d (EAI_NONAME)",
 			 TEST_RETURN, gai_strerror(TEST_RETURN), EAI_NONAME);
+		if (!TEST_RETURN)
+			freeaddrinfo(aires);
+		return;
 	} else
-		tst_resm(TPASS,
+		tst_resm(TINFO,
 			 "getaddrinfo IPv6 host+service, AI_NUMERICSERV");
 	if (!TEST_RETURN)
 		freeaddrinfo(aires);
 #endif /* AI_NUMERICSERV */
 
 	/* test 20, IPv6 SOCK_STREAM/IPPROTO_UDP hints */
-
 	memset(&hints, 0, sizeof(hints));
 	hints.ai_family = AF_INET6;
 	hints.ai_socktype = SOCK_STREAM;
@@ -806,12 +899,13 @@ void gaiv6(void)
 		tst_resm(TFAIL, "getaddrinfo IPv6 SOCK_STREAM/IPPROTO_UDP "
 			 "hints");
 		freeaddrinfo(aires);
-	} else
-		tst_resm(TPASS, "getaddrinfo IPv6 SOCK_STREAM/IPPROTO_UDP "
+		return;
+	} else {
+		tst_resm(TINFO, "getaddrinfo IPv6 SOCK_STREAM/IPPROTO_UDP "
 			 "hints");
+	}
 
 	/* test 21, IPv6 socktype 0, 513 */
-
 	memset(&hints, 0, sizeof(hints));
 	hints.ai_family = AF_INET6;
 	hints.ai_socktype = 0;
@@ -850,20 +944,31 @@ void gaiv6(void)
 				 psin6 ? psin6->sin6_family : 0,
 				 psin6 ? psin6->sin6_port : 0,
 				 psin6 ? htons(psin6->sin6_port) : 0);
-		} else if (got_tcp && got_udp)
-			tst_resm(TPASS, "getaddrinfo IPv6 socktype 0,513");
-		else
+			freeaddrinfo(aires);
+			return;
+		} else if (got_tcp && got_udp) {
+			tst_resm(TINFO, "getaddrinfo IPv6 socktype 0,513");
+			freeaddrinfo(aires);
+		} else {
 			tst_resm(TFAIL, "getaddrinfo IPv6 socktype 0,513 TCP %d"
 				 " UDP %d", got_tcp, got_udp);
-		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN == EAI_BADFLAGS ? TPASS : TFAIL,
-			 "getaddrinfo IPv6 socktype 0,513 (\"\", \"%s\") returns"
-			 " %ld (\"%s\")", service, TEST_RETURN,
-			 gai_strerror(TEST_RETURN));
+			freeaddrinfo(aires);
+			return;
+		}
+	} else {
+		if (TEST_RETURN == EAI_BADFLAGS) {
+			tst_resm(TINFO, "getaddrinfo IPv6 socktype 0,513"
+				" (\"\", \"%s\") returns %ld (\"%s\")", service,
+				TEST_RETURN, gai_strerror(TEST_RETURN));
+		} else {
+			tst_resm(TFAIL, "getaddrinfo IPv6 socktype 0,513"
+				" (\"\", \"%s\") returns %ld (\"%s\")", service,
+				TEST_RETURN, gai_strerror(TEST_RETURN));
+			return;
+		}
+	}
 
 	/* test 22, IPv6 AI_V4MAPPED */
-
 	memset(&hints, 0, sizeof(hints));
 	hints.ai_family = AF_INET6;
 	hints.ai_flags = AI_V4MAPPED;
@@ -892,57 +997,18 @@ void gaiv6(void)
 				 psin6 ? psin6->sin6_family : 0,
 				 psin6 ? psin6->sin6_port : 0,
 				 psin6 ? htons(psin6->sin6_port) : 0);
-		} else
-			tst_resm(TPASS, "getaddrinfo IPv6 AI_V4MAPPED");
-		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN ? TFAIL : TPASS, "getaddrinfo IPv6 "
+			freeaddrinfo(aires);
+			return;
+		} else {
+			tst_resm(TINFO, "getaddrinfo IPv6 AI_V4MAPPED");
+			freeaddrinfo(aires);
+		}
+	} else {
+		tst_resm(TFAIL, "getaddrinfo IPv6 "
 			 "AI_V4MAPPED (\"%s\") returns %ld (\"%s\")", hostname,
 			 TEST_RETURN, gai_strerror(TEST_RETURN));
-}
-
-/* this prints an addrinfo list; useful for debugging */
-void dumpres(struct addrinfo *pai)
-{
-	int count = 1;
-	for (; pai; pai = pai->ai_next, count++) {
-		printf("result %d [0x%p]\n", count, pai);
-		printf("\tai_flags %x\n", pai->ai_flags);
-		printf("\tai_family %d\n", pai->ai_family);
-		printf("\tai_socktype %d\n", pai->ai_socktype);
-		printf("\tai_protocol %d\n", pai->ai_protocol);
-		printf("\tai_addrlen %d\n", pai->ai_addrlen);
-		printf("\tai_canonname \"%s\"\n", pai->ai_canonname);
-		printf("\tai_addr.sa_family %x\n", pai->ai_addr->sa_family);
-		if (pai->ai_addr->sa_family == AF_INET) {
-			char buf[1024];
-			struct sockaddr_in *psin =
-			    (struct sockaddr_in *)pai->ai_addr;
-
-			if (!inet_ntop(AF_INET, &psin->sin_addr, buf,
-				       sizeof(buf)))
-				buf[0] = '\0';
-			printf("\tai_addr.sin_addr \"%s\"\n", buf);
-		} else if (pai->ai_addr->sa_family == AF_INET6) {
-			char buf[1024];
-
-			struct sockaddr_in6 *psin6 =
-			    (struct sockaddr_in6 *)pai->ai_addr;
-			if (!inet_ntop(AF_INET6, &psin6->sin6_addr, buf,
-				       sizeof(buf)))
-				buf[0] = '\0';
-			printf("\tai_addr.sin6_addr \"%s\"\n", buf);
-
-		}
-		printf("\tai_next %p\n", pai->ai_next);
+		return;
 	}
-}
 
-void setup(void)
-{
-	TEST_PAUSE;		/* if -P option specified */
-}
-
-void cleanup(void)
-{
+	tst_resm(TPASS, "getaddrinfo tests (v6) succeed");
 }
-- 
1.9.3


------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [LTP] [PATCH 6/6] ipv6_lib: add it into default
  2015-03-31  7:46 [LTP] [PATCH 1/6] lib6/runcc.c: use TCONF instead of TBROK when no C compiler is present Xing Gu
                   ` (3 preceding siblings ...)
  2015-03-31  7:46 ` [LTP] [PATCH 5/6] lib6/getaddrinfo_01.c: cleanup Xing Gu
@ 2015-03-31  7:46 ` Xing Gu
  2015-03-31 14:52 ` [LTP] [PATCH 1/6] lib6/runcc.c: use TCONF instead of TBROK when no C compiler is present Alexey Kodanev
  5 siblings, 0 replies; 55+ messages in thread
From: Xing Gu @ 2015-03-31  7:46 UTC (permalink / raw)
  To: ltp-list

Signed-off-by: Xing Gu <gux.fnst@cn.fujitsu.com>
---
 scenario_groups/default | 1 +
 1 file changed, 1 insertion(+)

diff --git a/scenario_groups/default b/scenario_groups/default
index 3a55702..60b1b27 100644
--- a/scenario_groups/default
+++ b/scenario_groups/default
@@ -32,3 +32,4 @@ dma_thread_diotest
 cpuacct
 can
 cpuhotplug
+ipv6_lib
-- 
1.9.3


------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 55+ messages in thread

* Re: [LTP] [PATCH 1/6] lib6/runcc.c: use TCONF instead of TBROK when no C compiler is present
  2015-03-31  7:46 [LTP] [PATCH 1/6] lib6/runcc.c: use TCONF instead of TBROK when no C compiler is present Xing Gu
                   ` (4 preceding siblings ...)
  2015-03-31  7:46 ` [LTP] [PATCH 6/6] ipv6_lib: add it into default Xing Gu
@ 2015-03-31 14:52 ` Alexey Kodanev
  2015-04-01  1:38   ` gux.fnst
  5 siblings, 1 reply; 55+ messages in thread
From: Alexey Kodanev @ 2015-03-31 14:52 UTC (permalink / raw)
  To: Xing Gu; +Cc: ltp-list

Hi!
On 03/31/2015 10:46 AM, Xing Gu wrote:
> Signed-off-by: Xing Gu <gux.fnst@cn.fujitsu.com>
> ---
>   testcases/network/lib6/runcc.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/testcases/network/lib6/runcc.c b/testcases/network/lib6/runcc.c
> index 91a0b16..3a89598 100644
> --- a/testcases/network/lib6/runcc.c
> +++ b/testcases/network/lib6/runcc.c
> @@ -93,7 +93,7 @@ int runcc(char *tname, char *filename0, char *program)
>   		 cflags, filename0, filename);
>   	es = system(cmd);
>   	if (WEXITSTATUS(es) == 127) {
> -		tst_resm(TBROK, "can't run C compiler: \"%s\"", cmd);
> +		tst_resm(TCONF, "can't run C compiler: \"%s\"", cmd);
>   		if (unlink(filename) < 0)
>   			tst_resm(TWARN, "%s; unlink \"%s\" failed: %s", tname,
>   				 filename, strerror(errno));

Why not 'tst_brkm(TCONF, ...)', do we need to proceed further?

Thanks,
Alexey

------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [LTP] [PATCH 1/6] lib6/runcc.c: use TCONF instead of TBROK when no C compiler is present
  2015-03-31 14:52 ` [LTP] [PATCH 1/6] lib6/runcc.c: use TCONF instead of TBROK when no C compiler is present Alexey Kodanev
@ 2015-04-01  1:38   ` gux.fnst
  2015-04-01  7:15     ` Alexey Kodanev
  0 siblings, 1 reply; 55+ messages in thread
From: gux.fnst @ 2015-04-01  1:38 UTC (permalink / raw)
  To: Alexey Kodanev; +Cc: ltp-list



On 03/31/2015 10:52 PM, Alexey Kodanev wrote:
> Hi!
> On 03/31/2015 10:46 AM, Xing Gu wrote:
>> Signed-off-by: Xing Gu <gux.fnst@cn.fujitsu.com>
>> ---
>>   testcases/network/lib6/runcc.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/testcases/network/lib6/runcc.c b/testcases/network/lib6/runcc.c
>> index 91a0b16..3a89598 100644
>> --- a/testcases/network/lib6/runcc.c
>> +++ b/testcases/network/lib6/runcc.c
>> @@ -93,7 +93,7 @@ int runcc(char *tname, char *filename0, char *program)
>>            cflags, filename0, filename);
>>       es = system(cmd);
>>       if (WEXITSTATUS(es) == 127) {
>> -        tst_resm(TBROK, "can't run C compiler: \"%s\"", cmd);
>> +        tst_resm(TCONF, "can't run C compiler: \"%s\"", cmd);
>>           if (unlink(filename) < 0)
>>               tst_resm(TWARN, "%s; unlink \"%s\" failed: %s", tname,
>>                    filename, strerror(errno));
>
> Why not 'tst_brkm(TCONF, ...)', do we need to proceed further?
>

The function "runcc" has created a file named "filename" before
executing "cmd" command, so I think we should delete this file
after tst_resm(TCONF,...).

Regards,
Xing Gu

> Thanks,
> Alexey
>

------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [LTP] [PATCH 1/6] lib6/runcc.c: use TCONF instead of TBROK when no C compiler is present
  2015-04-01  1:38   ` gux.fnst
@ 2015-04-01  7:15     ` Alexey Kodanev
  2015-04-14  9:24       ` gux.fnst
  0 siblings, 1 reply; 55+ messages in thread
From: Alexey Kodanev @ 2015-04-01  7:15 UTC (permalink / raw)
  To: gux.fnst; +Cc: ltp-list

Hi!
On 04/01/2015 04:38 AM, gux.fnst wrote:
>>>       if (WEXITSTATUS(es) == 127) {
>>> -        tst_resm(TBROK, "can't run C compiler: \"%s\"", cmd);
>>> +        tst_resm(TCONF, "can't run C compiler: \"%s\"", cmd);
>>>           if (unlink(filename) < 0)
>>>               tst_resm(TWARN, "%s; unlink \"%s\" failed: %s", tname,
>>>                    filename, strerror(errno));
>>
>> Why not 'tst_brkm(TCONF, ...)', do we need to proceed further?
>>
>
> The function "runcc" has created a file named "filename" before
> executing "cmd" command, so I think we should delete this file
> after tst_resm(TCONF,...).
>

So, there is temp test directory... you could pass some cleanup function 
to tst_brkm().

Thanks,
Alexey


------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [LTP] [PATCH 1/6] lib6/runcc.c: use TCONF instead of TBROK when no C compiler is present
  2015-04-01  7:15     ` Alexey Kodanev
@ 2015-04-14  9:24       ` gux.fnst
  2015-04-28 17:24         ` Cyril Hrubis
  0 siblings, 1 reply; 55+ messages in thread
From: gux.fnst @ 2015-04-14  9:24 UTC (permalink / raw)
  To: Alexey Kodanev; +Cc: ltp-list



On 04/01/2015 03:15 PM, Alexey Kodanev wrote:
> Hi!
> On 04/01/2015 04:38 AM, gux.fnst wrote:
>>>>       if (WEXITSTATUS(es) == 127) {
>>>> -        tst_resm(TBROK, "can't run C compiler: \"%s\"", cmd);
>>>> +        tst_resm(TCONF, "can't run C compiler: \"%s\"", cmd);
>>>>           if (unlink(filename) < 0)
>>>>               tst_resm(TWARN, "%s; unlink \"%s\" failed: %s", tname,
>>>>                    filename, strerror(errno));
>>>
>>> Why not 'tst_brkm(TCONF, ...)', do we need to proceed further?
>>>
>>
>> The function "runcc" has created a file named "filename" before
>> executing "cmd" command, so I think we should delete this file
>> after tst_resm(TCONF,...).
>>
>
> So, there is temp test directory... you could pass some cleanup function to tst_brkm().

Here we only remove the "filename" file, so I think it is not necessary to
create a cleanup function for this operation.`

Regards,
Xing Gu

>
> Thanks,
> Alexey
>
>

------------------------------------------------------------------------------
BPM Camp - Free Virtual Workshop May 6th at 10am PDT/1PM EDT
Develop your own process in accordance with the BPMN 2 standard
Learn Process modeling best practices with Bonita BPM through live exercises
http://www.bonitasoft.com/be-part-of-it/events/bpm-camp-virtual- event?utm_
source=Sourceforge_BPM_Camp_5_6_15&utm_medium=email&utm_campaign=VA_SF
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [LTP] [PATCH 1/6] lib6/runcc.c: use TCONF instead of TBROK when no C compiler is present
  2015-04-14  9:24       ` gux.fnst
@ 2015-04-28 17:24         ` Cyril Hrubis
       [not found]           ` <1433247689-3984-1-git-send-email-zenglg.jy@cn.fujitsu.com>
  0 siblings, 1 reply; 55+ messages in thread
From: Cyril Hrubis @ 2015-04-28 17:24 UTC (permalink / raw)
  To: gux.fnst; +Cc: ltp-list

Hi!
> > So, there is temp test directory... you could pass some cleanup function to tst_brkm().
> 
> Here we only remove the "filename" file, so I think it is not necessary to
> create a cleanup function for this operation.`

The point here is that this way the execution path would be clear. Just
now the function returns -1 which gets ignored in the end.

So exiting the code execution with TCONF here and changing the functions
to void would make it much easier to read.

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [LTP] [PATCH 2/6] lib6/asapi_04.c: cleanup
  2015-03-31  7:46 ` [LTP] [PATCH 2/6] lib6/asapi_04.c: cleanup Xing Gu
@ 2015-04-30 11:55   ` Cyril Hrubis
  2015-04-30 12:18   ` Cyril Hrubis
  1 sibling, 0 replies; 55+ messages in thread
From: Cyril Hrubis @ 2015-04-30 11:55 UTC (permalink / raw)
  To: Xing Gu; +Cc: ltp-list

Hi!
>  #include <stdio.h>
> @@ -49,36 +37,27 @@
>  
>  #include "test.h"
>  
> -char *TCID = "asapi_04";	/* Test program identifier.    */
> +#define READ_TIMEOUT	5	/* secs */
>  
>  pid_t pid;
>  
> -struct {
> -	char *prt_name;
> -	int prt_value;
> -} ptab[] = {
> -	{
> -	"hopopt", 0}, {
> -	"ipv6", 41}, {
> -	"ipv6-route", 43}, {
> -	"ipv6-frag", 44}, {
> -	"esp", 50}, {
> -	"ah", 51}, {
> -	"ipv6-icmp", 58}, {
> -	"ipv6-nonxt", 59}, {
> -"ipv6-opts", 60},};
> -
> -#define PTCOUNT	(sizeof(ptab)/sizeof(ptab[0]))
> +static void setup(void);
> +static void test_in6_are_addr_equal(void);
> +static void test_protocols_entry(void);
> +static int csum_test(char *rhost);
> +static void test_ipv6_checksum(void);
>  
> -#define READ_TIMEOUT	5	/* secs */
>  
> -void do_tests(void);
> -void setup(void), cleanup(void);
> -int csum_test(char *rhost);
> +static void (*testfunc[])(void) = { test_in6_are_addr_equal,
> +	test_protocols_entry, test_ipv6_checksum };
> +
> +char *TCID = "asapi_04";
> +int TST_TOTAL = ARRAY_SIZE(testfunc);
>  
>  int main(int argc, char *argv[])
>  {
>  	int lc;
> +	int i;
>  
>  	tst_parse_opts(argc, argv, 0, 0);
>  
> @@ -86,22 +65,27 @@ int main(int argc, char *argv[])
>  
>  	setup();
>  
> -	for (lc = 0; TEST_LOOPING(lc); ++lc)
> -		do_tests();
> +	for (lc = 0; TEST_LOOPING(lc); ++lc) {
> +		tst_count = 0;
>  
> -	cleanup();
> +		for (i = 0; i < TST_TOTAL; i++)
> +			(*testfunc[i])();
> +	}
>  
>  	tst_exit();
>  }
>  
> -void do_tests(void)
> +void setup(void)
>  {
> -	int i;
> +	TEST_PAUSE;
> +}
>  
>  /* RFC 3542, Section 2.3 */
> +void test_in6_are_addr_equal(void)
> +{
>  #ifndef IN6_ARE_ADDR_EQUAL
>  	tst_resm(TBROK, "IN6_ARE_ADDR_EQUAL not present");
> -#else /* IN6_ARE_ADDR_EQUAL */
> +#else
>  	/*
>  	 * set each bit in an address and check for unequal; then set
>  	 * in the second address and check for equal. Covers all bits, all
> @@ -128,30 +112,56 @@ void do_tests(void)
>  			}
>  		tst_resm(rv ? TPASS : TFAIL, "IN6_ARE_ADDR_EQUAL");
>  	}
> -#endif /* IN6_ARE_ADDR_EQUAL */
> +#endif
> +}
> +
> +struct {
> +	char *prt_name;
> +	int prt_value;
> +} ptab[] = {
> +	{ "hopopt", 0 },
> +	{ "ipv6", 41 },
> +	{ "ipv6-route", 43 },
> +	{ "ipv6-frag", 44 },
> +	{ "esp", 50 },
> +	{ "ah", 51 },
> +	{ "ipv6-icmp", 58 },
> +	{ "ipv6-nonxt", 59 },
> +	{ "ipv6-opts", 60 },
> +};
> +
> +#define PTCOUNT (sizeof(ptab)/sizeof(ptab[0]))

ARRAY_SIZE() here as well

>  /* RFC 3542, Section 2.4 */
> +void test_protocols_entry(void)
> +{
> +	unsigned int i;
> +
>  	for (i = 0; i < PTCOUNT; ++i) {
>  		struct protoent *pe;
>  		int pass;
>  
>  		pe = getprotobyname(ptab[i].prt_name);
>  		pass = pe && pe->p_proto == ptab[i].prt_value;
> -		tst_resm(pass ? TPASS : TFAIL, "\"%s\" protocols entry",
> -			 ptab[i].prt_name);
> +		if (pass) {
> +			tst_resm(TINFO, "\"%s\" protocols entry",
> +				ptab[i].prt_name);
> +		} else {
> +			tst_resm(TFAIL, "\"%s\" protocols entry",
> +				ptab[i].prt_name);
> +			return;
> +		}
>  	}
> +
> +	tst_resm(TPASS, "protocols entry tests succeed");
> +}

I do not think this is a good idea. Why can we just do the PASS/FAIL on
each testcase and adjust the test count variable accordingly?

>  /* RFC 3542, Section 3.1 */
> +void test_ipv6_checksum(void)
> +{
>  	csum_test("::1");
>  }
>  
> -/*
> - * this next-header value shouldn't be a real protocol!!
> - * 0x9f = 01 0 11111
> - *         | |     |
> - *         | |     |--- rest- ~0
> - *         | |--------- chg - "no change enroute"
> - *         |----------- act - "discard unknown"
> - */
>  #define	NH_TEST	0x9f

I guess that this comment should rather stay as it explains the
constant.

>  struct tprot {
> @@ -173,17 +183,13 @@ struct csent {
>  	int cs_sndresult;	/* send expected result */
>  	int cs_snderrno;	/* send expected errno */
>  } cstab[] = {
> -	{
> -	0, 5, 0, 0, 0, 0}, {
> -	6, 30, 0, 0, 0, 0}, {
> -	3, 20, -1, EINVAL, -1, -1},	/* non-aligned offset */
> -	{
> -	4, 5, 0, 0, -1, EINVAL},	/* not enough space */
> -	{
> -	50, 5, 0, 0, -1, EINVAL},	/* outside of packet */
> -	{
> -	22, 30, 0, 0, 0, 0}, {
> -	2000, 2004, 0, 0, 0, 0},	/* in a fragment (over Ethernet) */
> +	{ 0, 5, 0, 0, 0, 0 },
> +	{ 6, 30, 0, 0, 0, 0 },
> +	{ 3, 20, -1, EINVAL, -1, -1 },	/* non-aligned offset */
> +	{ 4, 5, 0, 0, -1, EINVAL },	/* not enough space */
> +	{ 50, 5, 0, 0, -1, EINVAL },	/* outside of packet */
> +	{ 22, 30, 0, 0, 0, 0 },
> +	{ 2000, 2004, 0, 0, 0, 0 },	/* in a fragment (over Ethernet) */
>  };
>  
>  #define CSCOUNT	(sizeof(cstab)/sizeof(cstab[0]))
> @@ -197,7 +203,7 @@ static int recvtprot(int sd, unsigned char *packet, int psize)
>  	tpt = (struct tprot *)packet;
>  	total = cc = recv(sd, packet, sizeof(struct tprot), 0);
>  	expected = sizeof(struct tprot);	/* until we get tp_dlen */
> -	gothead = total >= sizeof(struct tprot);
> +	gothead = (unsigned int)total >= sizeof(struct tprot);
>  	if (gothead)
>  		expected += ntohl(tpt->tp_dlen);
>  	if (cc <= 0)
> @@ -206,7 +212,8 @@ static int recvtprot(int sd, unsigned char *packet, int psize)
>  		cc = recv(sd, &packet[total], expected - total, 0);
>  		if (cc >= 0) {
>  			total += cc;
> -			if (!gothead && total >= sizeof(struct tprot)) {
> +			if (!gothead && (unsigned int)total >=
> +				sizeof(struct tprot)) {
>  				gothead = 1;
>  				expected += ntohl(tpt->tp_dlen);
>  			}
> @@ -248,7 +255,8 @@ static int client(int prot, int sfd)
>  	struct tprot *prtp = (struct tprot *)rpbuf;
>  	struct sockaddr_in6 rsin6;
>  	static int seq;
> -	int i, sd, cc, cs;
> +	unsigned int i;
> +	int sd, cc, cs;
>  
>  	memset(&rsin6, 0, sizeof(rsin6));
>  	rsin6.sin6_family = AF_INET6;
> @@ -261,8 +269,8 @@ static int client(int prot, int sfd)
>  
>  	sd = socket(PF_INET6, SOCK_RAW, NH_TEST);
>  	if (sd < 0) {
> -		tst_resm(TBROK, "can't create raw socket: %s", strerror(errno));
> -		return -1;
> +		tst_brkm(TBROK | TERRNO, NULL, "can't create raw socket: %s",
> +			strerror(errno));
                         ^
                        You should remove the strerror() now, as it's
			not needed anymore with TERRNO.

>  	}
>  	for (i = 0; i < CSCOUNT; ++i) {
>  		int offset, len, xlen;
> @@ -287,10 +295,10 @@ static int client(int prot, int sfd)
>  				 "IPV6_CHECKSUM offset %d len %d "
>  				 "- result %ld != %d", offset, len, TEST_RETURN,
>  				 cstab[i].cs_setresult);
> -			continue;
> +			return -1;
>  		}
>  		if (TEST_RETURN < 0) {
> -			tst_resm(TPASS, "IPV6_CHECKSUM offset %d len %d",
> +			tst_resm(TINFO, "IPV6_CHECKSUM offset %d len %d",
>  				 offset, len);
>  			continue;
>  		}
> @@ -298,7 +306,7 @@ static int client(int prot, int sfd)
>  			tst_resm(TFAIL, "IPV6_CHECKSUM offset %d len %d "
>  				 "- errno %d != %d", offset, len,
>  				 TEST_ERRNO, cstab[i].cs_seterrno);
> -			continue;
> +			return -1;

What is the reason for exitting the test on first failure?

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [LTP] [PATCH 3/6] lib6/asapi_05.c: cleanup
  2015-03-31  7:46 ` [LTP] [PATCH 3/6] lib6/asapi_05.c: cleanup Xing Gu
@ 2015-04-30 12:15   ` Cyril Hrubis
  0 siblings, 0 replies; 55+ messages in thread
From: Cyril Hrubis @ 2015-04-30 12:15 UTC (permalink / raw)
  To: Xing Gu; +Cc: ltp-list

Hi!
> +#define ETCOUNT	(sizeof(etab)/sizeof(etab[0]))

ARRAY_SIZE()

> +/*
> + * This is for old, broken glibc-header icmp6_filter structure definitions.
> + * If icmp6.h has struct icmp6_filter with field named "data" instead
> + * of the standard "icmp_filt", uncomment this line.
> + */
> +/*#define icmp_filt	data */

I guess that we can remove this completly. It was workaround for broken
glibc-2.3.3 and older which is about 11 years old now.
(glibc commit c2280dc039c69a690dd006c1f145c7ba9aa2eaad)

> +enum tt { T_WILLPASS, T_WILLBLOCK, T_SETPASS, T_SETBLOCK, T_SETPASSALL,
> +	T_SETBLOCKALL
> +};
> +struct ftent {
> +	char *ft_tname;		/* test name, for logging */
> +	unsigned char ft_sndtype;	/* send type field */
> +	unsigned char ft_flttype;	/* filter type field */
> +	enum tt ft_test;	/* what macro to test */
> +	int ft_expected;	/* packet should pass? */
> +} ftab[] = {
> +	{ "ICMP6_FILTER_SETPASS s 20 f 20", 20, 20, T_SETPASS, 1 },
> +	{ "ICMP6_FILTER_SETPASS s 20 f 21", 20, 21, T_SETPASS, 0 },
> +	{ "ICMP6_FILTER_SETBLOCK s 20 f 20", 20, 20, T_SETBLOCK, 0 },
> +	{ "ICMP6_FILTER_SETBLOCK s 20 f 21", 20, 21, T_SETBLOCK, 1 },
> +	{ "ICMP6_FILTER_PASSALL s 20", 20, 0, T_SETPASSALL, 1 },
> +	{ "ICMP6_FILTER_PASSALL s 20", 21, 0, T_SETPASSALL, 1 },
> +	{ "ICMP6_FILTER_BLOCKALL s 20", 20, 0, T_SETBLOCKALL, 0 },
> +	{ "ICMP6_FILTER_BLOCKALL s 20", 21, 0, T_SETBLOCKALL, 0 },
> +	{ "ICMP6_FILTER_WILLBLOCK s 20 f 21", 20, 21, T_WILLBLOCK, 0 },
> +	{ "ICMP6_FILTER_WILLBLOCK s 20 f 20", 20, 20, T_WILLBLOCK, 1 },
> +	{ "ICMP6_FILTER_WILLPASS s 20 f 21", 20, 21, T_WILLPASS, 0 },
> +	{ "ICMP6_FILTER_WILLPASS s 22 f 22", 22, 22, T_WILLPASS, 1 },
> +};
> +
> +#define FTCOUNT	(sizeof(ftab)/sizeof(ftab[0]))

ARRAY_SIZE()

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [LTP] [PATCH 2/6] lib6/asapi_04.c: cleanup
  2015-03-31  7:46 ` [LTP] [PATCH 2/6] lib6/asapi_04.c: cleanup Xing Gu
  2015-04-30 11:55   ` Cyril Hrubis
@ 2015-04-30 12:18   ` Cyril Hrubis
  1 sibling, 0 replies; 55+ messages in thread
From: Cyril Hrubis @ 2015-04-30 12:18 UTC (permalink / raw)
  To: Xing Gu; +Cc: ltp-list

Hi!
> +static void setup(void);

Hmm, setup() is declared static here.

> +static void test_in6_are_addr_equal(void);
> +static void test_protocols_entry(void);
> +static int csum_test(char *rhost);
> +static void test_ipv6_checksum(void);
>  
> -#define READ_TIMEOUT	5	/* secs */
>  
> -void do_tests(void);
> -void setup(void), cleanup(void);
> -int csum_test(char *rhost);
> +static void (*testfunc[])(void) = { test_in6_are_addr_equal,
> +	test_protocols_entry, test_ipv6_checksum };
> +
> +char *TCID = "asapi_04";
> +int TST_TOTAL = ARRAY_SIZE(testfunc);
>  
>  int main(int argc, char *argv[])
>  {
>  	int lc;
> +	int i;
>  
>  	tst_parse_opts(argc, argv, 0, 0);
>  
> @@ -86,22 +65,27 @@ int main(int argc, char *argv[])
>  
>  	setup();
>  
> -	for (lc = 0; TEST_LOOPING(lc); ++lc)
> -		do_tests();
> +	for (lc = 0; TEST_LOOPING(lc); ++lc) {
> +		tst_count = 0;
>  
> -	cleanup();
> +		for (i = 0; i < TST_TOTAL; i++)
> +			(*testfunc[i])();
> +	}
>  
>  	tst_exit();
>  }
>  
> -void do_tests(void)
> +void setup(void)
>  {
> -	int i;
> +	TEST_PAUSE;
> +}

But it's missing static here.

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [LTP] [PATCH 4/6] lib6/asapi_06.c: cleanup
  2015-03-31  7:46 ` [LTP] [PATCH 4/6] lib6/asapi_06.c: cleanup Xing Gu
@ 2015-04-30 13:33   ` Cyril Hrubis
  0 siblings, 0 replies; 55+ messages in thread
From: Cyril Hrubis @ 2015-04-30 13:33 UTC (permalink / raw)
  To: Xing Gu; +Cc: ltp-list

Hi!
> Signed-off-by: Xing Gu <gux.fnst@cn.fujitsu.com>
> ---
>  testcases/network/lib6/asapi_06.c | 374 +++++++++++++++++---------------------
>  1 file changed, 167 insertions(+), 207 deletions(-)
> 
> diff --git a/testcases/network/lib6/asapi_06.c b/testcases/network/lib6/asapi_06.c
> index 960ebb5..733d1c4 100644
> --- a/testcases/network/lib6/asapi_06.c
> +++ b/testcases/network/lib6/asapi_06.c
> @@ -1,6 +1,7 @@
>  /*
>   *
>   *   Copyright (c) International Business Machines  Corp., 2001
> + *   Author: David L Stevens
>   *
>   *   This program is free software;  you can redistribute it and/or modify
>   *   it under the terms of the GNU General Public License as published by
> @@ -13,25 +14,12 @@
>   *   the GNU General Public License for more details.
>   *
>   *   You should have received a copy of the GNU General Public License
> - *   along with this program;  if not, write to the Free Software
> - *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
> + *   along with this program;  if not, write to the Free Software Foundation,
> + *   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
>   */
> -
>  /*
> - * Test Name: asapi_06
> - *
> - * Test Description:
> - *  Tests for RFC 3542 section 4 socket options and ancillary data
> - *
> - * Usage:  <for command-line>
> - *  asapi_06
> - *
> - * HISTORY
> - *	05/2005 written by David L Stevens
> - *
> - * RESTRICTIONS:
> - *  None.
> - *
> + *   Description:
> + *     Tests for RFC 3542 section 4 socket options and ancillary data.
>   */
>  
>  #include "config.h"
> @@ -58,42 +46,46 @@
>  
>  #include "test.h"
>  
> -char *TCID = "asapi_06";	/* Test program identifier.    */
> -
> -int TST_TOTAL = 1;
> -
> -pid_t pid;
> +static void setup(void);
> +static void test_soent(void);
> +#ifdef notyet
> +static void test_pktinfo(void);
> +#endif
>  
> -struct {
> -	char *prt_name;
> -	int prt_value;
> -} ptab[] = {
> +static void (*testfunc[])(void) = {
> +	test_soent,
> +#ifdef notyet
> +	test_pktinfo,
> +#endif

Does the test actually works if we remove the ifdefs?

Looks to me like this has been implemented in kernel in 2005 in:

commit 333fad5364d6b457c8d837f7d05802d2aaf8a961
Author: YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
Date:   Thu Sep 8 09:59:17 2005 +0900

[IPV6]: Support several new sockopt / ancillary data in Advanced API (RFC3542).


>  };
>  
> -#define PTCOUNT	(sizeof(ptab)/sizeof(ptab[0]))
> -
> -#define READ_TIMEOUT	5	/* secs */
> -
> -void do_tests(void);
> -void setup(void), cleanup(void);
> +char *TCID = "asapi_06";
> +int TST_TOTAL = ARRAY_SIZE(testfunc);
>  
>  int main(int argc, char *argv[])
>  {
>  	int lc;
> +	int i;
>  
>  	tst_parse_opts(argc, argv, NULL, NULL);
>  
> -	pid = getpid();
> -
>  	setup();
>  
> -	for (lc = 0; TEST_LOOPING(lc); ++lc)
> -		do_tests();
> +	for (lc = 0; TEST_LOOPING(lc); ++lc) {
> +		tst_count = 0;
> +
> +		for (i = 0; i < TST_TOTAL; i++)
> +			(*testfunc[i])();
> +	}
>  
> -	cleanup();
>  	tst_exit();
>  }
>  
> +void setup(void)
> +{
> +	TEST_PAUSE;
> +}
> +
>  #define NH_TEST	0x9f
>  
>  #ifndef IPV6_RECVPKTINFO
> @@ -145,11 +137,6 @@ union soval {
>  	int sou_bool;
>  };
>  
> -/* in6_addr initializer for loopback interface */
> -#define IN6_LOOP	{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }
> -#define IN6_ANY		{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
> -
> -/* so_clrval and so_setval members are initilized in the body */
>  struct soent {
>  	char *so_tname;
>  	int so_opt;
> @@ -160,72 +147,63 @@ struct soent {
>  	union soval so_setval;
>  	socklen_t so_valsize;
>  } sotab[] = {
> -/* RFC 3542, Section 4 */
> -	{
> -		"IPV6_RECVPKTINFO", IPV6_RECVPKTINFO, 1, IPV6_PKTINFO, 1, { { { { {
> -		0}}}}}, { { { { {
> -	0}}}}}, sizeof(int)}, {
> -		"IPV6_RECVHOPLIMIT", IPV6_RECVHOPLIMIT, 1, IPV6_HOPLIMIT, 1, { { { { {
> -		0}}}}}, { { { { {
> -	0}}}}}, sizeof(int)}, {
> -		"IPV6_RECVRTHDR", IPV6_RECVRTHDR, 0, IPV6_RTHDR, 1, { { { { {
> -		0}}}}}, { { { { {
> -	0}}}}}, sizeof(int)}, {
> -		"IPV6_RECVHOPOPTS", IPV6_RECVHOPOPTS, 0, IPV6_HOPOPTS, 1, { { { { {
> -		0}}}}}, { { { { {
> -	0}}}}}, sizeof(int)}, {
> -		"IPV6_RECVDSTOPTS", IPV6_RECVDSTOPTS, 0, IPV6_DSTOPTS, 1, { { { { {
> -		0}}}}}, { { { { {
> -	0}}}}}, sizeof(int)}, {
> -		"IPV6_RECVTCLASS", IPV6_RECVTCLASS, 1, IPV6_TCLASS, 1, { { { { {
> -		0}}}}}, { { { { {
> -	0}}}}}, sizeof(int)},
> -/* make sure TCLASS stays when setting another opt */
> -	{
> -		"IPV6_RECVTCLASS (2)", IPV6_RECVHOPLIMIT, 1, IPV6_TCLASS, 0, { { { { {
> -		0}}}}}, { { { { {
> -	0}}}}}, sizeof(int)},
> -/* OLD values */
> -	{
> -		"IPV6_2292PKTINFO", IPV6_2292PKTINFO, 1, IPV6_2292PKTINFO, 1, { { { { {
> -		0}}}}}, { { { { {
> -	0}}}}}, sizeof(int)}, {
> -		"IPV6_2292HOPLIMIT", IPV6_2292HOPLIMIT, 1, IPV6_2292HOPLIMIT, 1, { { { { {
> -		0}}}}}, { { { { {
> -	0}}}}}, sizeof(int)}, {
> -		"IPV6_2292RTHDR", IPV6_2292RTHDR, 0, IPV6_2292RTHDR, 1, { { { { {
> -		0}}}}}, { { { { {
> -	0}}}}}, sizeof(int)}, {
> -		"IPV6_2292HOPOPTS", IPV6_2292HOPOPTS, 0, IPV6_2292HOPOPTS, 1, { { { { {
> -		0}}}}}, { { { { {
> -	0}}}}}, sizeof(int)}, {
> -		"IPV6_2292DSTOPTS", IPV6_2292DSTOPTS, 0, IPV6_2292DSTOPTS, 1, { { { { {
> -		0}}}}}, { { { { {
> -0}}}}}, sizeof(int)},};
> +	/* RFC 3542, Section 4 */
> +	{ "IPV6_RECVPKTINFO", IPV6_RECVPKTINFO, 1, IPV6_PKTINFO, 1,
> +		{ { { { { 0 } } }, 0 } }, { { { { { 0 } } }, 0 } },
> +		sizeof(int) },
> +	{ "IPV6_RECVHOPLIMIT", IPV6_RECVHOPLIMIT, 1, IPV6_HOPLIMIT, 1,
> +		{ { { { { 0 } } }, 0 } }, { { { { { 0 } } }, 0 } },
> +		sizeof(int) },
> +	{ "IPV6_RECVRTHDR", IPV6_RECVRTHDR, 0, IPV6_RTHDR, 1,
> +		{ { { { { 0 } } }, 0 } }, { { { { { 0 } } }, 0 } },
> +		sizeof(int) },
> +	{ "IPV6_RECVHOPOPTS", IPV6_RECVHOPOPTS, 0, IPV6_HOPOPTS, 1,
> +		{ { { { { 0 } } }, 0 } }, { { { { { 0 } } }, 0 } },
> +		sizeof(int) },
> +	{ "IPV6_RECVDSTOPTS", IPV6_RECVDSTOPTS, 0, IPV6_DSTOPTS, 1,
> +		{ { { { { 0 } } }, 0 } }, { { { { { 0 } } }, 0 } },
> +		sizeof(int) },
> +	{ "IPV6_RECVTCLASS", IPV6_RECVTCLASS, 1, IPV6_TCLASS, 1,
> +		{ { { { { 0 } } }, 0 } }, { { { { { 0 } } }, 0 } },
> +		sizeof(int) },
> +	/* make sure TCLASS stays when setting another opt */
> +	{ "IPV6_RECVTCLASS (2)", IPV6_RECVHOPLIMIT, 1, IPV6_TCLASS, 0,
> +		{ { { { { 0 } } }, 0 } }, { { { { { 0 } } }, 0 } },
> +		sizeof(int) },
> +	/* OLD values */
> +	{ "IPV6_2292PKTINFO", IPV6_2292PKTINFO, 1, IPV6_2292PKTINFO, 1,
> +		{ { { { { 0 } } }, 0 } }, { { { { { 0 } } }, 0 } },
> +		sizeof(int) },
> +	{ "IPV6_2292HOPLIMIT", IPV6_2292HOPLIMIT, 1, IPV6_2292HOPLIMIT, 1,
> +		{ { { { { 0 } } }, 0 } }, { { { { { 0 } } }, 0 } },
> +		sizeof(int) },
> +	{ "IPV6_2292RTHDR", IPV6_2292RTHDR, 0, IPV6_2292RTHDR, 1,
> +		{ { { { { 0 } } }, 0 } }, { { { { { 0 } } }, 0 } },
> +		sizeof(int) },
> +	{ "IPV6_2292HOPOPTS", IPV6_2292HOPOPTS, 0, IPV6_2292HOPOPTS, 1,
> +		{ { { { { 0 } } }, 0 } }, { { { { { 0 } } }, 0 } },
> +		sizeof(int) },
> +	{ "IPV6_2292DSTOPTS", IPV6_2292DSTOPTS, 0, IPV6_2292DSTOPTS, 1,
> +		{ { { { { 0 } } }, 0 } }, { { { { { 0 } } }, 0 } },
> +		sizeof(int) },
> +};
>  
>  #define SOCOUNT	(sizeof(sotab)/sizeof(sotab[0]))

ARRAY_SIZE()

>  struct soprot {
> -	int sop_pid;		/* sender PID */
> -	int sop_seq;		/* sequence # */
> -	int sop_dlen;		/* tp_dat length */
> -	unsigned char sop_dat[0];	/* user data */
> +	int sop_pid;        /* sender PID */
> +	int sop_seq;        /* sequence # */
> +	int sop_dlen;       /* tp_dat length */
> +	unsigned char sop_dat[0];   /* user data */
>  };
>  
>  unsigned char tpbuf[sizeof(struct soprot) + 2048];
>  unsigned char rpbuf[sizeof(struct soprot) + 2048];
>  
>  unsigned char control[2048];
> -int clen;
>  
>  int seq;
>  
> -int setupso(void)
> -{
> -/* add routing headers, other ancillary data here */
> -	return 0;
> -}
> -
>  struct cme {
>  	int cm_len;
>  	int cm_level;
> @@ -235,17 +213,13 @@ struct cme {
>  		uint32_t cmu_hops;
>  	} cmu;
>  } cmtab[] = {
> -	{
> -		sizeof(uint32_t), SOL_IPV6, IPV6_TCLASS, {
> -		0x12}
> -	}
> -	, {
> -		sizeof(uint32_t), SOL_IPV6, IPV6_HOPLIMIT, {
> -		0x21}
> -	}
> -,};
> +	{ sizeof(uint32_t), SOL_IPV6, IPV6_TCLASS, {0x12} },
> +	{ sizeof(uint32_t), SOL_IPV6, IPV6_HOPLIMIT, {0x21} },
> +};
> +
> +#define CMCOUNT (sizeof(cmtab)/sizeof(cmtab[0]))

ARRAY_SIZE()

> -#define CMCOUNT	(sizeof(cmtab)/sizeof(cmtab[0]))
> +unsigned int count;
>  
>  ssize_t sendall(int st)
>  {
> @@ -254,7 +228,8 @@ ssize_t sendall(int st)
>  	struct iovec iov;
>  	struct soprot *psop;
>  	unsigned char *pd;
> -	int i, ctotal;
> +	unsigned int i;
> +	int ctotal;
>  
>  	psop = (struct soprot *)tpbuf;
>  	psop->sop_pid = htonl(getpid());
> @@ -300,32 +275,29 @@ void so_test(struct soent *psoe)
>  	int st;
>  
>  	if (psoe->so_opt == -1) {
> -		tst_resm(TBROK, "%s not present at compile time",
> +		tst_brkm(TBROK, NULL, "%s not present at compile time",
>  			 psoe->so_tname);
> -		return;
>  	}
>  	if (psoe->so_clear || sr < 0) {
>  		if (sr < 0)
>  			close(sr);
>  		sr = socket(PF_INET6, SOCK_RAW, NH_TEST);
>  		if (sr < 0) {
> -			tst_resm(TBROK, "%s socket: %s", psoe->so_tname,
> -				 strerror(errno));
> -			return;
> +			tst_brkm(TBROK | TERRNO, NULL, "%s socket: %s",
> +				psoe->so_tname, strerror(errno));
                                           ^
                                Remove the strerror() if you added TERRNO

>  		}
>  	}
>  	memset(&sin6, 0, sizeof(sin6));
>  	sin6.sin6_family = AF_INET6;
>  	sin6.sin6_addr = in6addr_loopback;
>  	if (bind(sr, (struct sockaddr *)&sin6, sizeof(sin6)) < 0) {
> -		tst_resm(TBROK, "%s: bind: %s", psoe->so_tname,
> -			 strerror(errno));
> +		tst_brkm(TBROK | TERRNO, NULL, "%s: bind: %s",
> +			psoe->so_tname, strerror(errno));

Here as well.

>  	}
>  	if (setsockopt(sr, SOL_IPV6, psoe->so_opt, &psoe->so_clrval,
>  		       psoe->so_valsize) < 0) {
> -		tst_resm(TBROK, "%s: setsockopt: %s", psoe->so_tname,
> -			 strerror(errno));
> -		return;
> +		tst_brkm(TBROK | TERRNO, NULL, "%s: setsockopt: %s",
> +			psoe->so_tname, strerror(errno));

And here.

>  	}
>  	TEST(setsockopt(sr, SOL_IPV6, psoe->so_opt, &psoe->so_setval,
>  			psoe->so_valsize));
> @@ -337,25 +309,23 @@ void so_test(struct soent *psoe)
>  	valsize = psoe->so_valsize;
>  	TEST(getsockopt(sr, SOL_IPV6, psoe->so_opt, &sobuf, &valsize));
>  	if (TEST_RETURN != 0) {
> -		tst_resm(TBROK, "%s set-get: getsockopt: %s", psoe->so_tname,
> -			 strerror(errno));
> -		return;
> -	} else if (memcmp(&psoe->so_setval, &sobuf, psoe->so_valsize))
> +		tst_brkm(TBROK | TTERRNO, NULL, "%s set-get: getsockopt: %s",
> +			psoe->so_tname, strerror(errno));

And here.

> +	} else if (memcmp(&psoe->so_setval, &sobuf, psoe->so_valsize)) {
>  		tst_resm(TFAIL, "%s set-get optval != setval", psoe->so_tname);
> -	else
> -		tst_resm(TPASS, "%s set-get", psoe->so_tname);
> +		return;
> +	} else {
> +		tst_resm(TINFO, "%s set-get", psoe->so_tname);
> +	}

Again why do we exit on first failure? And why don't we rather adjust the
number of testcases?

>  	st = socket(PF_INET6, SOCK_RAW, NH_TEST);
>  	if (st < 0) {
> -		tst_resm(TBROK, "%s transmit socket: %s", psoe->so_tname,
> -			 strerror(errno));
> -		return;
> +		tst_brkm(TBROK | TERRNO, NULL, "%s transmit socket: %s",
> +			psoe->so_tname, strerror(errno));

strerror() here as well.

>  	}
>  	if (sendall(st) < 0) {
> -		tst_resm(TBROK, "%s transmit sendto: %s", psoe->so_tname,
> -			 strerror(errno));
> -		close(st);
> -		return;
> +		tst_brkm(TBROK, NULL, "%s transmit sendto: %s",
> +			psoe->so_tname, strerror(errno));

And this should rather be changed to TBROK | TERRNO and the strerror() removed
to be consistent with the rest.

>  	}
>  	close(st);
>  
> @@ -382,14 +352,12 @@ void so_test(struct soent *psoe)
>  			if (nfds < 0) {
>  				if (errno == EINTR)
>  					continue;
> -				tst_resm(TBROK, "%s select: %s", psoe->so_tname,
> -					 strerror(errno));
> -				return;
> +				tst_brkm(TBROK | TERRNO, NULL, "%s select: %s",
> +					psoe->so_tname, strerror(errno));

Here as well.

>  			}
>  			if (nfds == 0) {
> -				tst_resm(TBROK, "%s recvmsg timed out",
> +				tst_brkm(TBROK, NULL, "%s recvmsg timed out",
>  					 psoe->so_tname);
> -				return;
>  			}
>  			/* else, nfds == 1 */
>  			if (!FD_ISSET(sr, &rfds))
> @@ -405,11 +373,9 @@ void so_test(struct soent *psoe)
>  
>  			cc = recvmsg(sr, &msg, 0);
>  			if (cc < 0) {
> -				tst_resm(TBROK, "%s recvmsg: %s",
> +				tst_brkm(TBROK | TERRNO, NULL, "%s recvmsg: %s",
>  					 psoe->so_tname, strerror(errno));

And here.

> -				return;
>  			}
> -/* check pid & seq here */
>  			break;
>  		}
>  		gotone = 0;
> @@ -429,11 +395,31 @@ void so_test(struct soent *psoe)
>  				return;
>  			}
>  		}
> -/* check contents here */
> -		if (psoe->so_dorecv)
> -			tst_resm(gotone ? TPASS : TFAIL, "%s receive",
> -				 psoe->so_tname);
> +		if (psoe->so_dorecv) {
> +			if (gotone)
> +				tst_resm(TINFO, "%s receive", psoe->so_tname);
> +			else
> +				tst_resm(TFAIL, "%s receive", psoe->so_tname);
> +		}

Again I don't like this, let's keep the PASS/FAIL here.

>  	}
> +
> +	count++;
> +}
> +
> +void test_soent(void)
> +{
> +	unsigned int i;
> +
> +	for (i = 0; i < SOCOUNT; ++i) {
> +		sotab[i].so_clrval.sou_bool = 0;
> +		sotab[i].so_setval.sou_bool = 1;
> +		so_test(&sotab[i]);
> +	}
> +
> +	if (count < SOCOUNT)
> +		tst_resm(TPASS, "socket set-get/receive tests fail");
                          ^
                      Should this be TFAIL?
> +	else
> +		tst_resm(TPASS, "socket set-get/receive tests succeed");
>  }
>  
>  #define IPV6_ADDR_NODE		1
> @@ -449,7 +435,7 @@ static int ipv6_addr_scope(struct in6_addr *pin6)
>  		return IPV6_ADDR_NODE;
>  	return IPV6_ADDR_GLOBAL;
>  }
> -#endif /* HAVE_IFADDRS_H */
> +#endif

If the #ifdef #endif pair spans over more than a few lines it's fine to have
this comment there.

>  int getsock(char *tname, struct sockaddr_in6 *psin6_arg, int scope)
>  {
> @@ -462,8 +448,7 @@ int getsock(char *tname, struct sockaddr_in6 *psin6_arg, int scope)
>  	int s;
>  
>  	if (!pifa_head && getifaddrs(&pifa_head)) {
> -		tst_resm(TBROK, "%s: getifaddrs failed", tname);
> -		return -1;
> +		tst_brkm(TBROK, NULL, "%s: getifaddrs failed", tname);
>  	}
>  	if (psin6_arg)
>  		ifindex = psin6_arg->sin6_scope_id;
> @@ -483,20 +468,19 @@ int getsock(char *tname, struct sockaddr_in6 *psin6_arg, int scope)
>  		     (this_scope > 0 && this_scope != scope)))
>  			continue;
>  		psin6->sin6_scope_id = if_nametoindex(pifa->ifa_name);
> -		if ((ifindex < 0 && -ifindex == psin6->sin6_scope_id) ||
> -		    (ifindex > 0 && ifindex != psin6->sin6_scope_id))
> +		if ((ifindex < 0 && -(unsigned int)ifindex ==

Eh, casting to (unsigned int) and then negating it with - sounds wrong. What
was the problem here?

> +			psin6->sin6_scope_id) || (ifindex > 0 &&
> +			(unsigned int)ifindex != psin6->sin6_scope_id))
>  			continue;
>  		s = socket(PF_INET6, SOCK_DGRAM, 0);
>  		if (s < 0) {
> -			tst_resm(TBROK, "%s: socket %s", tname,
> +			tst_brkm(TBROK | TERRNO, NULL, "%s: socket %s", tname,
>  				 strerror(errno));

The strerror() again.

> -			return -1;
>  		}
>  		if (bind(s, pifa->ifa_addr, sizeof(struct sockaddr_in6)) < 0) {
> -			tst_resm(TBROK, "%s: bind \"%s\": %s", tname,
> -				 inet_ntop(AF_INET6, &psin6->sin6_addr, strbuf,
> -					   sizeof(strbuf)), strerror(errno));
> -			return -1;
> +			tst_brkm(TBROK | TERRNO, NULL, "%s: bind \"%s\": %s",
> +				tname, inet_ntop(AF_INET6, &psin6->sin6_addr,
> +				strbuf, sizeof(strbuf)), strerror(errno));

Here as well.

>  		}
>  		if (psin6_arg) {
>  			*psin6_arg = *psin6;
> @@ -530,15 +514,13 @@ int getsock(char *tname, struct sockaddr_in6 *psin6_arg, int scope)
>  		else
>  			intfstr = 0;
>  
> -		if (intfstr)
> -			tst_resm(TBROK, "%s: getsock : no%s addresses%s %d",
> -				 tname, scopestr, intfstr, ifindex);
> -		else
> +		if (intfstr == 0) {
>  			tst_resm(TBROK, "%s: getsock : no%s addresses",
>  				 tname, scopestr);
> +		}

This change does not look right. Looks like the purpose of the code was to add
more information to the tst_resm() message if intfstr was not zero and this
change removed the tst_resm() for intfstr != 0. Or was the previous code wrong
(if it was, I would expect description of the change in the commit message)?

>  	}
>  	return -1;
> -#else /* HAVE_IFADDRS_H */
> +#else
>  	return -1;
>  #endif
>  }
> @@ -563,98 +545,76 @@ void test_pktinfo(void)
>  
>  	s_snd = getsock(tname, 0, IPV6_ADDR_GLOBAL);
>  	if (s_snd < 0) {
> -		tst_resm(TBROK, "%s: can't create send socket", tname);
> -		return;
> +		tst_brkm(TBROK, NULL, "%s: can't create send socket", tname);
>  	}
>  	/* global-scope address, interface X */
>  	sa_rcv[0].sin6_scope_id = 0;
>  	s_rcv[0] = getsock(tname, &sa_rcv[0], IPV6_ADDR_GLOBAL);
>  	if (s_rcv[0] == -1) {
> -		tst_resm(TBROK, "%s: only link-scope addresses", tname);
> -		return;
> +		tst_brkm(TBROK, NULL, "%s: only link-scope addresses", tname);
>  	}
>  	/* link-local-scope address, interface X */
>  	sa_rcv[1].sin6_scope_id = sa_rcv[0].sin6_scope_id;
>  	s_rcv[1] = getsock(tname, &sa_rcv[1], IPV6_ADDR_LINK);
>  	if (s_rcv[1] < 0) {
> -		tst_resm(TBROK, "%s: no link-local address on ifindex %d",
> +		tst_brkm(TBROK, NULL, "%s: no link-local address on ifindex %d",
>  			 tname, sa_rcv[0].sin6_scope_id);
> -		return;
>  	}
>  	/* link-local-scope address, interface Y */
>  	sa_rcv[2].sin6_scope_id = -sa_rcv[0].sin6_scope_id;
>  	s_rcv[2] = getsock(tname, &sa_rcv[2], IPV6_ADDR_LINK);
>  	if (s_rcv[2] < 0) {
> -		tst_resm(TBROK, "%s: only one interface?", tname);
> -		return;
> +		tst_brkm(TBROK, NULL, "%s: only one interface?", tname);
>  	}
>  	/* send to rcv1 to verify communication */
>  	/* force to rcv2 w/ PKTINFO */
> -/* TESTS: */
> -/* sticky set-get */
> +	/* TESTS: */
> +	/* sticky set-get */
>  	tname = "IPV6_PKTINFO set";
>  	pi.ipi6_addr = sa_rcv[1].sin6_addr;
>  	pi.ipi6_ifindex = sa_rcv[1].sin6_scope_id;
>  	TEST(setsockopt(s_snd, SOL_IPV6, IPV6_PKTINFO, &pi, sizeof(pi)));
> -	if (TEST_RETURN != 0)
> +	if (TEST_RETURN != 0) {
>  		tst_resm(TFAIL, "%s: %s", tname, strerror(errno));
> -	else
> -		tst_resm(TPASS, "%s", tname);
> +		return;
> +	} else {
> +		tst_resm(TINFO, "%s", tname);
> +	}

Again, why do we exit on first failure?

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [LTP] [PATCH v2 1/6] lib6/runcc.c: Cleanup
       [not found]             ` <1433247689-3984-2-git-send-email-zenglg.jy@cn.fujitsu.com>
@ 2015-06-06 12:52               ` Alexey Kodanev
  2015-06-16 12:24                 ` [LTP] [PATCH v3 1/7] SAFE_MACROS: Add socket(), bind(), listen(), connect() and getsockname() Zeng Linggang
  0 siblings, 1 reply; 55+ messages in thread
From: Alexey Kodanev @ 2015-06-06 12:52 UTC (permalink / raw)
  To: Zeng Linggang, ltp-list

Hi,
On 02.06.2015 15:21, Zeng Linggang wrote:
>    *   Copyright (c) International Business Machines  Corp., 2001
> + *	05/2005 written by David L Stevens
>    *
>    *   This program is free software;  you can redistribute it and/or modify
>    *   it under the terms of the GNU General Public License as published by
> @@ -13,19 +13,12 @@
>    *   the GNU General Public License for more details.
>    *
>    *   You should have received a copy of the GNU General Public License
> - *   along with this program;  if not, write to the Free Software
> - *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
> + *   along with this program;  if not, write to the Free Software Foundation,
> + *   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
>    */

You could use modern form rather then reordering the old, see 
http://www.gnu.org/licenses/gpl-howto.en.html.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.

>   
>   /*
>    * runcc.a - common functions for lib6 testing

It is quite obvious, remove it as well.

>   
> -char *filetmpl = "/tmp/%.*s_XXXXXX";
> +static char *filetmpl = "/tmp/%.*s_XXXXXX";

Rather static const char filetmpl[] = "/tmp/%.*s_XXXXXX";
The same applies for the other changed variables in the patch.

Best regards,
Alexey


------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [LTP] [PATCH v2 2/6] lib6/asapi_04.c: Cleanup
       [not found]             ` <1433247689-3984-3-git-send-email-zenglg.jy@cn.fujitsu.com>
@ 2015-06-06 13:22               ` Alexey Kodanev
  0 siblings, 0 replies; 55+ messages in thread
From: Alexey Kodanev @ 2015-06-06 13:22 UTC (permalink / raw)
  To: Zeng Linggang, ltp-list

On 02.06.2015 15:21, Zeng Linggang wrote:
> -		for (word = 0; word < 4; ++word)
> -			for (bit = 0; bit < 32; ++bit) {
> -				uint32_t newbit = 1 << bit;
> +	for (word = 0; word < 4; ++word)
> +		for (bit = 0; bit < 32; ++bit) {
> +			uint32_t newbit = 1 << bit;

1 is int here, please change it to unsigned int as follows:

uint32_t newbit = 1U << bit;


>   
> -void *ilistener(void *arg)
> +static void *ilistener(void *arg __attribute__ ((unused)))

LTP has a macro for it, a sort of LTP_ATTR_UNUSED

> -#define MAX(a, b) ((a) >= (b) ? (a) : (b))
> +# define MAX(a, b) ((a) >= (b) ? (a) : (b))

It seems it is not common for LTP coding style to use space there.

> -
>   int TST_TOTAL = PTCOUNT + CSCOUNT;

May be move it closer to CSCOUNT?

Best regards,
Alexey

------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v3 1/7] SAFE_MACROS: Add socket(), bind(), listen(), connect() and getsockname()
  2015-06-06 12:52               ` [LTP] [PATCH v2 1/6] lib6/runcc.c: Cleanup Alexey Kodanev
@ 2015-06-16 12:24                 ` Zeng Linggang
  2015-06-16 12:24                   ` [LTP] [PATCH v3 2/7] lib6/runcc.c: Cleanup Zeng Linggang
                                     ` (6 more replies)
  0 siblings, 7 replies; 55+ messages in thread
From: Zeng Linggang @ 2015-06-16 12:24 UTC (permalink / raw)
  To: alexey.kodanev; +Cc: ltp-list

Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
 include/safe_macros.h | 29 ++++++++++++++++++
 lib/safe_macros.c     | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 112 insertions(+)

diff --git a/include/safe_macros.h b/include/safe_macros.h
index 0e7651d..c8601de 100644
--- a/include/safe_macros.h
+++ b/include/safe_macros.h
@@ -433,5 +433,34 @@ struct dirent *safe_readdir(const char *file, const int lineno, void (cleanup_fn
 #define SAFE_READDIR(cleanup_fn, dirp) \
 	safe_readdir(__FILE__, __LINE__, (cleanup_fn), (dirp))
 
+int safe_socket(const char *file, const int lineno, void (cleanup_fn)(void),
+		int domain, int type, int protocol);
+#define SAFE_SOCKET(cleanup_fn, domain, type, protocol) \
+	safe_socket(__FILE__, __LINE__, (cleanup_fn), domain, type, protocol)
+
+int safe_bind(const char *file, const int lineno, void (cleanup_fn)(void),
+	      int socket, const struct sockaddr *address,
+	      socklen_t address_len);
+#define SAFE_BIND(cleanup_fn, socket, address, address_len) \
+	safe_bind(__FILE__, __LINE__, (cleanup_fn), socket, address, \
+		  address_len)
+
+int safe_listen(const char *file, const int lineno, void (cleanup_fn)(void),
+		int socket, int backlog);
+#define SAFE_LISTEN(cleanup_fn, socket, backlog) \
+	safe_listen(__FILE__, __LINE__, (cleanup_fn), socket, backlog)
+
+int safe_connect(const char *file, const int lineno, void (cleanup_fn)(void),
+		 int sockfd, const struct sockaddr *addr, socklen_t addrlen);
+#define SAFE_CONNECT(cleanup_fn, sockfd, addr, addrlen) \
+	safe_connect(__FILE__, __LINE__, (cleanup_fn), sockfd, addr, addrlen)
+
+int safe_getsockname(const char *file, const int lineno,
+		     void (cleanup_fn)(void), int sockfd, struct sockaddr *addr,
+		     socklen_t *addrlen);
+#define SAFE_GETSOCKNAME(cleanup_fn, sockfd, addr, addrlen) \
+	safe_getsockname(__FILE__, __LINE__, (cleanup_fn), sockfd, addr, \
+			 addrlen)
+
 #endif /* __SAFE_MACROS_H__ */
 #endif /* __TEST_H__ */
diff --git a/lib/safe_macros.c b/lib/safe_macros.c
index a3d997c..5a8e429 100644
--- a/lib/safe_macros.c
+++ b/lib/safe_macros.c
@@ -14,6 +14,7 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <malloc.h>
+#include <sys/socket.h>
 #include "test.h"
 #include "safe_macros.h"
 
@@ -759,3 +760,85 @@ struct dirent *safe_readdir(const char *file, const int lineno, void (cleanup_fn
 	errno = err;
 	return rval;
 }
+
+int safe_socket(const char *file, const int lineno, void (cleanup_fn)(void),
+		int domain, int type, int protocol)
+{
+	int rval;
+
+	rval = socket(domain, type, protocol);
+
+	if (rval < 0) {
+		tst_brkm(TBROK | TERRNO, cleanup_fn,
+		         "%s:%d: socket(%d, %d, %d) failed", file, lineno,
+			 domain, type, protocol);
+	}
+
+	return rval;
+}
+
+int safe_bind(const char *file, const int lineno, void (cleanup_fn)(void),
+	      int socket, const struct sockaddr *address,
+	      socklen_t address_len)
+{
+	int rval;
+
+	rval = bind(socket, address, address_len);
+
+	if (rval < 0) {
+		tst_brkm(TBROK | TERRNO, cleanup_fn,
+		         "%s:%d: bind(%d, %p, %d) failed", file, lineno, socket,
+			 address, address_len);
+	}
+
+	return rval;
+}
+
+int safe_listen(const char *file, const int lineno, void (cleanup_fn)(void),
+		int socket, int backlog)
+{
+	int rval;
+
+	rval = listen(socket, backlog);
+
+	if (rval < 0) {
+		tst_brkm(TBROK | TERRNO, cleanup_fn,
+		         "%s:%d: listen(%d, %d) failed", file, lineno, socket,
+			 backlog);
+	}
+
+	return rval;
+}
+
+int safe_connect(const char *file, const int lineno, void (cleanup_fn)(void),
+		 int sockfd, const struct sockaddr *addr, socklen_t addrlen)
+{
+	int rval;
+
+	rval = connect(sockfd, addr, addrlen);
+
+	if (rval < 0) {
+		tst_brkm(TBROK | TERRNO, cleanup_fn,
+		         "%s:%d: connect(%d, %p, %d) failed", file, lineno,
+			 sockfd, addr, addrlen);
+	}
+
+	return rval;
+}
+
+int safe_getsockname(const char *file, const int lineno,
+		     void (cleanup_fn)(void), int sockfd, struct sockaddr *addr,
+		     socklen_t *addrlen)
+{
+	int rval;
+
+	rval = getsockname(sockfd, addr, addrlen);
+
+	if (rval < 0) {
+		tst_brkm(TBROK | TERRNO, cleanup_fn,
+		         "%s:%d: getsockname(%d, %p, %p) failed", file, lineno,
+			 sockfd, addr, addrlen);
+	}
+
+	return rval;
+}
-- 
1.9.3


------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v3 2/7] lib6/runcc.c: Cleanup
  2015-06-16 12:24                 ` [LTP] [PATCH v3 1/7] SAFE_MACROS: Add socket(), bind(), listen(), connect() and getsockname() Zeng Linggang
@ 2015-06-16 12:24                   ` Zeng Linggang
  2015-06-19 16:08                     ` Alexey Kodanev
  2015-06-16 12:24                   ` [LTP] [PATCH v3 3/7] lib6/asapi_04.c: Cleanup Zeng Linggang
                                     ` (5 subsequent siblings)
  6 siblings, 1 reply; 55+ messages in thread
From: Zeng Linggang @ 2015-06-16 12:24 UTC (permalink / raw)
  To: alexey.kodanev; +Cc: ltp-list

* Add 'static' before some functions and global variables.

* Change 'aliascheck', 'funccheck', 'structcheck' and 'valuecheck' to
  non-return because of the ignore return value.

* Some cleanup.

Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
 testcases/network/lib6/runcc.c | 106 +++++++++++++++++------------------------
 testcases/network/lib6/runcc.h |  33 ++++++++-----
 2 files changed, 64 insertions(+), 75 deletions(-)

diff --git a/testcases/network/lib6/runcc.c b/testcases/network/lib6/runcc.c
index 91a0b16..0057cc5 100644
--- a/testcases/network/lib6/runcc.c
+++ b/testcases/network/lib6/runcc.c
@@ -1,31 +1,21 @@
 /*
+ * Copyright (c) 2015 Fujitsu Ltd.
+ * Copyright (c) International Business Machines  Corp., 2001
  *
- *   Copyright (c) International Business Machines  Corp., 2001
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
  *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
  *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/*
- * runcc.a - common functions for lib6 testing
- *
- * HISTORY
- *	05/2005 written by David L Stevens
- *
- * RESTRICTIONS:
- *  None.
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
+ * Author: David L Stevens
  */
 
 #include <stdio.h>
@@ -37,17 +27,17 @@
 
 #include "test.h"
 
-char fieldref[1024];
-char program[8192];
+static char fieldref[1024];
+static char program[8192];
 
-char *filetmpl = "/tmp/%.*s_XXXXXX";
+static const char *filetmpl = "/tmp/%.*s_XXXXXX";
 
-char cmd[1024];
+static char cmd[1024];
 
 /*
  * like strspn, with ASCII, numbers and underscore only
  */
-int strfpn(char *name)
+static int strfpn(char *name)
 {
 	int i;
 
@@ -57,7 +47,7 @@ int strfpn(char *name)
 	return i;
 }
 
-int runcc(char *tname, char *filename0, char *program)
+static int runcc(char *tname, char *filename0, char *program)
 {
 	static char filename[1024];
 	int fd, es, saved_errno;
@@ -133,21 +123,20 @@ int runcc(char *tname, char *filename0, char *program)
 	return 0;
 }
 
-char *field_fmt = "\n\texit((offsetof(struct %s, %s) != %s) || "
-    "sizeof(tst.%s) != (%s));\n";
+static const char *field_fmt = "\n\texit((offsetof(struct %s, %s) != %s) || "
+			       "sizeof(tst.%s) != (%s));\n";
 /* no offset check */
-char *field_fmt2 = "\n\texit(sizeof(tst.%s) != (%s));\n";
+static const char *field_fmt2 = "\n\texit(sizeof(tst.%s) != (%s));\n";
 
-const char *stmpl =
-    "%s\n#ifndef offsetof\n"
-    "#define offsetof(dtype, dfield) ((int)&((dtype *)0)->dfield)\n"
-    "#endif\n\nstruct %s tst;\n\nmain(int argc, char *argv[])\n{\n\t%s\n}\n";
+static const char *stmpl = "%s\n#ifndef offsetof\n"
+			   "#define offsetof(dtype, dfield) "
+			   "((int)&((dtype *)0)->dfield)\n"
+			   "#endif\n\nstruct %s tst;\n\n"
+			   "main(int argc, char *argv[])\n{\n\t%s\n}\n";
 
-int
-structcheck(char *tname, char *incl, char *structure, char *field,
-	    char *offset, char *size)
+void structcheck(char *tname, char *incl, char *structure, char *field,
+		 char *offset, char *size)
 {
-	int rv;
 	static char filename[1024];
 
 	if (offset)
@@ -158,52 +147,45 @@ structcheck(char *tname, char *incl, char *structure, char *field,
 	sprintf(program, stmpl, incl, structure, fieldref);
 	snprintf(filename, sizeof(filename), filetmpl, strfpn(structure),
 		 structure);
-	rv = runcc(tname, filename, program);
-	return rv;
+	runcc(tname, filename, program);
 }
 
-char *aliasfmt =
-    "exit(&tst.%s != &tst.%s || sizeof(tst.%s) != sizeof(tst.%s));";
+static const char *aliasfmt = "exit(&tst.%s != &tst.%s || "
+			      "sizeof(tst.%s) != sizeof(tst.%s));";
 
-int
-aliascheck(char *tname, char *incl, char *structure, char *field, char *dname)
+void aliascheck(char *tname, char *incl, char *structure, char *field,
+		char *dname)
 {
-	int rv;
 	static char filename[1024];
 
 	sprintf(fieldref, aliasfmt, field, dname, field, dname);
 	sprintf(program, stmpl, incl, structure, fieldref);
 	snprintf(filename, sizeof(filename), filetmpl, strfpn(structure),
 		 structure);
-	rv = runcc(tname, filename, program);
-	return rv;
+	runcc(tname, filename, program);
 }
 
-const char *dtmpl =
-    "%s\n\nmain(int argc, char *argv[])\n{\n\texit((%s) != (%s));\n}\n";
+static const char *dtmpl = "%s\n\nmain(int argc, char *argv[])\n"
+			   "{\n\texit((%s) != (%s));\n}\n";
 
-int valuecheck(char *tname, char *incl, char *dname, char *dval)
+void valuecheck(char *tname, char *incl, char *dname, char *dval)
 {
-	int rv;
 	static char filename[1024];
 
 	sprintf(program, dtmpl, incl, dname, dval);
 	snprintf(filename, sizeof(filename), filetmpl, strfpn(dname), dname);
-	rv = runcc(tname, filename, program);
-	return rv;
+	runcc(tname, filename, program);
 }
 
-const char *ftmpl =
-    "%s\n\nmain(int argc, char *argv[])\n{\n#ifdef %s\n\texit(0);\n#else\n"
-    "\tsyntax error;\n#endif\n}\n";
+static const char *ftmpl = "%s\n\nmain(int argc, char *argv[])\n"
+			   "{\n#ifdef %s\n\texit(0);\n#else\n"
+			   "\tsyntax error;\n#endif\n}\n";
 
-int funccheck(char *tname, char *incl, char *fname)
+void funccheck(char *tname, char *incl, char *fname)
 {
-	int rv;
 	static char filename[1024];
 
 	sprintf(program, ftmpl, incl, fname);
 	snprintf(filename, sizeof(filename), filetmpl, strfpn(fname), fname);
-	rv = runcc(tname, filename, program);
-	return rv;
+	runcc(tname, filename, program);
 }
diff --git a/testcases/network/lib6/runcc.h b/testcases/network/lib6/runcc.h
index 4e2a0d5..0e9228b 100644
--- a/testcases/network/lib6/runcc.h
+++ b/testcases/network/lib6/runcc.h
@@ -1,5 +1,4 @@
 /*
- *
  *   Copyright (c) International Business Machines  Corp., 2001
  *
  *   This program is free software;  you can redistribute it and/or modify
@@ -13,18 +12,26 @@
  *   the GNU General Public License for more details.
  *
  *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *   along with this program;  if not, write to the Free Software Foundation,
+ *   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-int aliascheck(char *tname, char *incl, char *structure, char *field,
-	char *dname);
-int funccheck(char *tname, char *incl, char *fname);
-int structcheck(char *tname, char *incl, char *structure, char *field,
-	char *offset, char *size);
-int valuecheck(char *tname, char *incl, char *dname, char *dval);
+#ifndef __RUNCC_H__
+#define __RUNCC_H__
+
+void aliascheck(char *tname, char *incl, char *structure, char *field,
+		char *dname);
+
+void funccheck(char *tname, char *incl, char *fname);
+
+void structcheck(char *tname, char *incl, char *structure, char *field,
+		 char *offset, char *size);
+
+void valuecheck(char *tname, char *incl, char *dname, char *dval);
+
+#define IP6_H		"#include <netinet/ip6.h>\n"
+#define IN_H		"#include <netinet/in.h>\n"
+#define ICMP6_H		"#include <netinet/icmp6.h>\n"
+#define SOCKET_H	"#include <sys/types.h>\n#include <sys/socket.h>\n"
 
-#define IP6_H "#include <netinet/ip6.h>\n"
-#define IN_H "#include <netinet/in.h>\n"
-#define ICMP6_H "#include <netinet/icmp6.h>\n"
-#define SOCKET_H "#include <sys/types.h>\n#include <sys/socket.h>\n"
+#endif  /* __RUNCC_H__ */
-- 
1.9.3


------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v3 3/7] lib6/asapi_04.c: Cleanup
  2015-06-16 12:24                 ` [LTP] [PATCH v3 1/7] SAFE_MACROS: Add socket(), bind(), listen(), connect() and getsockname() Zeng Linggang
  2015-06-16 12:24                   ` [LTP] [PATCH v3 2/7] lib6/runcc.c: Cleanup Zeng Linggang
@ 2015-06-16 12:24                   ` Zeng Linggang
  2015-06-16 12:24                   ` [LTP] [PATCH v3 4/7] lib6/asapi_05.c: Cleanup Zeng Linggang
                                     ` (4 subsequent siblings)
  6 siblings, 0 replies; 55+ messages in thread
From: Zeng Linggang @ 2015-06-16 12:24 UTC (permalink / raw)
  To: alexey.kodanev; +Cc: ltp-list

* Add 'static' before some functions and global variables.
* Remove cleanup() function.
* Remove useless comments.
* Use SAFE_XXX().
* Modify the format of ptab[] and cstab[].
* Rewrite 'csum_test()' and 'isocketpair()'.
* Some cleanup.

Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
 testcases/network/lib6/asapi_04.c | 286 ++++++++++++++++----------------------
 1 file changed, 117 insertions(+), 169 deletions(-)

diff --git a/testcases/network/lib6/asapi_04.c b/testcases/network/lib6/asapi_04.c
index 76de26b..5fd22ed 100644
--- a/testcases/network/lib6/asapi_04.c
+++ b/testcases/network/lib6/asapi_04.c
@@ -1,38 +1,21 @@
 /*
+ * Copyright (c) 2015 Fujitsu Ltd.
+ * Copyright (c) International Business Machines  Corp., 2001
  *
- *   Copyright (c) International Business Machines  Corp., 2001
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
  *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
  *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/*
- * Test Name: asapi_04
- *
- * Test Description:
- *  Verify that in6 and sockaddr fields are present. Most of these are
- *  "PASS" if they just compile.
- *
- * Usage:  <for command-line>
- *  asapi_04
- *
- * HISTORY
- *	04/2005 written by David L Stevens
- *
- * RESTRICTIONS:
- *  None.
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
+ * Author: David L Stevens
  */
 
 #include <stdio.h>
@@ -48,33 +31,34 @@
 #include <netinet/in.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
-char *TCID = "asapi_04";	/* Test program identifier.    */
+char *TCID = "asapi_04";
 
-pid_t pid;
+static pid_t pid;
 
-struct {
+static struct {
 	char *prt_name;
 	int prt_value;
 } ptab[] = {
-	{
-	"hopopt", 0}, {
-	"ipv6", 41}, {
-	"ipv6-route", 43}, {
-	"ipv6-frag", 44}, {
-	"esp", 50}, {
-	"ah", 51}, {
-	"ipv6-icmp", 58}, {
-	"ipv6-nonxt", 59}, {
-"ipv6-opts", 60},};
-
-#define PTCOUNT	(sizeof(ptab)/sizeof(ptab[0]))
+	{"hopopt", 0},
+	{"ipv6", 41},
+	{"ipv6-route", 43},
+	{"ipv6-frag", 44},
+	{"esp", 50},
+	{"ah", 51},
+	{"ipv6-icmp", 58},
+	{"ipv6-nonxt", 59},
+	{"ipv6-opts", 60},
+};
+
+#define PTCOUNT	ARRAY_SIZE(ptab)
 
 #define READ_TIMEOUT	5	/* secs */
 
-void do_tests(void);
-void setup(void), cleanup(void);
-int csum_test(char *rhost);
+static void do_tests(void);
+static void setup(void);
+static int csum_test(void);
 
 int main(int argc, char *argv[])
 {
@@ -89,45 +73,41 @@ int main(int argc, char *argv[])
 	for (lc = 0; TEST_LOOPING(lc); ++lc)
 		do_tests();
 
-	cleanup();
-
 	tst_exit();
 }
 
-void do_tests(void)
+static void do_tests(void)
 {
-	int i;
+	unsigned int i;
 
 /* RFC 3542, Section 2.3 */
 #ifndef IN6_ARE_ADDR_EQUAL
-	tst_resm(TBROK, "IN6_ARE_ADDR_EQUAL not present");
+	tst_resm(TCONF, "IN6_ARE_ADDR_EQUAL not present");
 #else /* IN6_ARE_ADDR_EQUAL */
 	/*
 	 * set each bit in an address and check for unequal; then set
 	 * in the second address and check for equal. Covers all bits, all
 	 * combinations.
 	 */
-	{
-		struct in6_addr a1, a2;
-		int word, bit;
-		int rv = 1;
+	struct in6_addr a1, a2;
+	int word, bit;
+	int rv = 1;
 
-		memset(&a1, 0, sizeof(a1));
-		memset(&a2, 0, sizeof(a2));
+	memset(&a1, 0, sizeof(a1));
+	memset(&a2, 0, sizeof(a2));
 
-		rv = IN6_ARE_ADDR_EQUAL(&a1, &a2);
+	rv = IN6_ARE_ADDR_EQUAL(&a1, &a2);
 
-		for (word = 0; word < 4; ++word)
-			for (bit = 0; bit < 32; ++bit) {
-				uint32_t newbit = 1 << bit;
+	for (word = 0; word < 4; ++word)
+		for (bit = 0; bit < 32; ++bit) {
+			uint32_t newbit = 1U << bit;
 
-				a1.s6_addr32[word] |= newbit;	/* unequal */
-				rv &= !IN6_ARE_ADDR_EQUAL(&a1, &a2);
-				a2.s6_addr32[word] |= newbit;	/* equal */
-				rv &= IN6_ARE_ADDR_EQUAL(&a1, &a2);
-			}
-		tst_resm(rv ? TPASS : TFAIL, "IN6_ARE_ADDR_EQUAL");
-	}
+			a1.s6_addr32[word] |= newbit;	/* unequal */
+			rv &= !IN6_ARE_ADDR_EQUAL(&a1, &a2);
+			a2.s6_addr32[word] |= newbit;	/* equal */
+			rv &= IN6_ARE_ADDR_EQUAL(&a1, &a2);
+		}
+	tst_resm(rv ? TPASS : TFAIL, "IN6_ARE_ADDR_EQUAL");
 #endif /* IN6_ARE_ADDR_EQUAL */
 
 /* RFC 3542, Section 2.4 */
@@ -141,7 +121,7 @@ void do_tests(void)
 			 ptab[i].prt_name);
 	}
 /* RFC 3542, Section 3.1 */
-	csum_test("::1");
+	csum_test();
 }
 
 /*
@@ -162,10 +142,10 @@ struct tprot {
 	unsigned char tp_dat[0];	/* user data */
 };
 
-unsigned char tpbuf[sizeof(struct tprot) + 2048];
-unsigned char rpbuf[sizeof(struct tprot) + 2048];
+static unsigned char tpbuf[sizeof(struct tprot) + 2048];
+static unsigned char rpbuf[sizeof(struct tprot) + 2048];
 
-struct csent {
+static struct csent {
 	int cs_offset;
 	int cs_dlen;
 	int cs_setresult;	/* setsockopt expected result */
@@ -173,25 +153,24 @@ struct csent {
 	int cs_sndresult;	/* send expected result */
 	int cs_snderrno;	/* send expected errno */
 } cstab[] = {
-	{
-	0, 5, 0, 0, 0, 0}, {
-	6, 30, 0, 0, 0, 0}, {
-	3, 20, -1, EINVAL, -1, -1},	/* non-aligned offset */
-	{
-	4, 5, 0, 0, -1, EINVAL},	/* not enough space */
-	{
-	50, 5, 0, 0, -1, EINVAL},	/* outside of packet */
-	{
-	22, 30, 0, 0, 0, 0}, {
-	2000, 2004, 0, 0, 0, 0},	/* in a fragment (over Ethernet) */
+	{0, 5, 0, 0, 0, 0},
+	{6, 30, 0, 0, 0, 0},
+	{3, 20, -1, EINVAL, -1, -1},	/* non-aligned offset */
+	{4, 5, 0, 0, -1, EINVAL},	/* not enough space */
+	{50, 5, 0, 0, -1, EINVAL},	/* outside of packet */
+	{22, 30, 0, 0, 0, 0},
+	{2000, 2004, 0, 0, 0, 0},	/* in a fragment (over Ethernet) */
 };
 
-#define CSCOUNT	(sizeof(cstab)/sizeof(cstab[0]))
+#define CSCOUNT	ARRAY_SIZE(cstab)
+
+int TST_TOTAL = PTCOUNT + CSCOUNT;
 
-static int recvtprot(int sd, unsigned char *packet, int psize)
+static int recvtprot(int sd, unsigned char *packet)
 {
 	struct tprot *tpt;
-	int cc, total, expected;
+	int cc;
+	unsigned int total, expected;
 	int gothead;
 
 	tpt = (struct tprot *)packet;
@@ -218,7 +197,8 @@ static int recvtprot(int sd, unsigned char *packet, int psize)
 	return total;
 }
 
-unsigned short csum(unsigned short partial, unsigned char *packet, int len)
+static unsigned short csum(unsigned short partial, unsigned char *packet,
+			   int len)
 {
 	unsigned long sum = partial;
 	unsigned short *ps;
@@ -234,7 +214,7 @@ unsigned short csum(unsigned short partial, unsigned char *packet, int len)
 	return ~sum;
 }
 
-struct ph {
+static struct ph {
 	struct in6_addr ph_sa;
 	struct in6_addr ph_da;
 	uint32_t ph_len;
@@ -242,13 +222,14 @@ struct ph {
 	uint8_t ph_nh;
 } ph;
 
-static int client(int prot, int sfd)
+static int client(int sfd)
 {
 	struct tprot *pttp = (struct tprot *)tpbuf;
 	struct tprot *prtp = (struct tprot *)rpbuf;
 	struct sockaddr_in6 rsin6;
 	static int seq;
-	int i, sd, cc, cs;
+	unsigned int i;
+	int sd, cc, cs;
 
 	memset(&rsin6, 0, sizeof(rsin6));
 	rsin6.sin6_family = AF_INET6;
@@ -259,11 +240,8 @@ static int client(int prot, int sfd)
 	ph.ph_da = rsin6.sin6_addr;
 	ph.ph_nh = NH_TEST;
 
-	sd = socket(PF_INET6, SOCK_RAW, NH_TEST);
-	if (sd < 0) {
-		tst_resm(TBROK, "can't create raw socket: %s", strerror(errno));
-		return -1;
-	}
+	sd = SAFE_SOCKET(NULL, PF_INET6, SOCK_RAW, NH_TEST);
+
 	for (i = 0; i < CSCOUNT; ++i) {
 		int offset, len, xlen;
 		int rv;
@@ -289,17 +267,20 @@ static int client(int prot, int sfd)
 				 cstab[i].cs_setresult);
 			continue;
 		}
+
 		if (TEST_RETURN < 0) {
 			tst_resm(TPASS, "IPV6_CHECKSUM offset %d len %d",
 				 offset, len);
 			continue;
 		}
+
 		if (TEST_RETURN && TEST_ERRNO != cstab[i].cs_seterrno) {
 			tst_resm(TFAIL, "IPV6_CHECKSUM offset %d len %d "
 				 "- errno %d != %d", offset, len,
 				 TEST_ERRNO, cstab[i].cs_seterrno);
 			continue;
 		}
+
 		/* send packet */
 		TEST(sendto(sd, pttp, len, 0, (struct sockaddr *)&rsin6,
 			    sizeof(rsin6)));
@@ -311,20 +292,23 @@ static int client(int prot, int sfd)
 				 TEST_RETURN, xlen);
 			continue;
 		}
+
 		if (TEST_RETURN < 0 && TEST_ERRNO != cstab[i].cs_snderrno) {
 			tst_resm(TFAIL, "IPV6_CHECKSUM offset %d len %d "
 				 "- snderrno %d != %d", offset, len,
 				 TEST_ERRNO, cstab[i].cs_snderrno);
 			continue;
 		}
+
 		if (TEST_RETURN < 0) {
 			tst_resm(TPASS, "IPV6_CHECKSUM offset %d len %d",
 				 offset, len);
 			continue;
 		}
-		while ((cc = recvtprot(sfd, rpbuf, sizeof(rpbuf)))) {
-			if (htonl(prtp->tp_pid) == pid &&
-			    htonl(prtp->tp_seq) == seq)
+
+		while ((cc = recvtprot(sfd, rpbuf))) {
+			if (htonl(prtp->tp_pid) == (uint32_t)pid &&
+			    htonl(prtp->tp_seq) == (uint32_t)seq)
 				break;
 		}
 		rv = 1;
@@ -334,7 +318,7 @@ static int client(int prot, int sfd)
 				continue;
 			if (*p != 0xa5) {
 				tst_resm(TFAIL, "IPV6_CHECKSUM corrupt data "
-					 "0x%02x != 0xa5 at offset %d in packet",
+					 "0x%02x != 0xa5 at offset %zd in packet",
 					 *p, p - rpbuf);
 				rv = 0;
 				break;
@@ -358,7 +342,7 @@ static int client(int prot, int sfd)
 static int listen_fd, connect_fd;
 sem_t ilsem;
 
-void *ilistener(void *arg)
+static void *ilistener(void *arg LTP_ATTRIBUTE_UNUSED)
 {
 	connect_fd = accept(listen_fd, 0, 0);
 	close(listen_fd);
@@ -366,7 +350,7 @@ void *ilistener(void *arg)
 	return NULL;
 }
 
-int isocketpair(int pf, int type, int proto, int fd[2])
+static void isocketpair(int pf, int type, int proto, int fd[2])
 {
 	pthread_t thid;
 	struct sockaddr_in sin4;
@@ -375,80 +359,51 @@ int isocketpair(int pf, int type, int proto, int fd[2])
 /* restrict to PF_INET for now */
 	if (pf != PF_INET) {
 		errno = EOPNOTSUPP;
-		return -1;
+		return;
 	}
+
 	sem_init(&ilsem, 0, 0);
-	listen_fd = socket(pf, type, proto);
-	if (listen_fd < 0) {
-		perror("socket");
-		return -1;
-	}
+
+	listen_fd = SAFE_SOCKET(NULL, pf, type, proto);
+
 	memset(&sin4, 0, sizeof(sin4));
-	if (bind(listen_fd, (struct sockaddr *)&sin4, sizeof(sin4)) < 0) {
-		perror("bind");
-		return -1;
-	}
-	if (listen(listen_fd, 10) < 0) {
-		perror("listen");
-		return -1;
-	}
+
+	SAFE_BIND(NULL, listen_fd, (struct sockaddr *)&sin4, sizeof(sin4));
+
+	SAFE_LISTEN(NULL, listen_fd, 10);
+
 	namelen = sizeof(sin4);
-	if (getsockname(listen_fd, (struct sockaddr *)&sin4, &namelen) < 0) {
-		perror("getsockname");
-		return -1;
-	}
-	if (pthread_create(&thid, 0, ilistener, 0) < 0) {
-		perror("pthread_create");
-		return -1;
-	}
+	SAFE_GETSOCKNAME(NULL, listen_fd, (struct sockaddr *)&sin4, &namelen);
+
+	if (pthread_create(&thid, 0, ilistener, 0) < 0)
+		tst_brkm(TBROK | TERRNO, NULL, "pthread_create error");
+
+	fd[0] = SAFE_SOCKET(NULL, pf, type, proto);
 
-	fd[0] = socket(pf, type, proto);
-	if (fd[0] < 0) {
-		perror("socket");
-		return -1;
-	}
 	sin4.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
-	if (connect(fd[0], (struct sockaddr *)&sin4, sizeof(sin4)) < 0) {
-		perror("connect");
-		return -1;
-	}
+
+	SAFE_CONNECT(NULL, fd[0], (struct sockaddr *)&sin4, sizeof(sin4));
+
 	sem_wait(&ilsem);
 	fd[1] = connect_fd;
 	sem_destroy(&ilsem);
-	return 0;
 }
 
 #ifndef MAX
 #define MAX(a, b) ((a) >= (b) ? (a) : (b))
 #endif /* MAX */
 
-int csum_test(char *rhost)
+static int csum_test(void)
 {
 	fd_set rset, rset_save;
 	int csd[2];		/* control sockets */
 	int sd, nfds, maxfd, cc;
 	struct timeval tv;
 
-/* rhost == loopback, for now */
-	if (strcmp(rhost, "::1")) {
-		tst_resm(TBROK, "invalid rhost \"%s\"", rhost);
-		return -1;
-	}
-	if (isocketpair(PF_INET, SOCK_STREAM, 0, csd) < 0) {
-		tst_resm(TBROK, "socketpair: %s", strerror(errno));
-		return -1;
-	}
-	sd = socket(PF_INET6, SOCK_RAW, NH_TEST);
-	if (sd < 0) {
-		int saved_errno = errno;
-
-		if (errno == EPERM && geteuid())
-			tst_resm(TBROK, "IPV6_CHECKSUM tests must run as root");
-		else
-			tst_resm(TBROK, "All IPv6_CHECKSUM tests broken: "
-				 "socket: %s", strerror(saved_errno));
-		return -1;
-	}
+	isocketpair(PF_INET, SOCK_STREAM, 0, csd);
+
+	sd = SAFE_SOCKET(NULL, PF_INET6, SOCK_RAW, NH_TEST);
+
 	FD_ZERO(&rset_save);
 	FD_SET(sd, &rset_save);
 	FD_SET(csd[1], &rset_save);
@@ -457,16 +412,15 @@ int csum_test(char *rhost)
 
 	/* server socket set; now start the client */
 	switch (fork()) {
-	case 0:		/* child */
+	case 0:
 		close(csd[0]);
 		break;
 	case -1:
-		tst_resm(TBROK, "can't fork rserver");
-		return -1;
-	default:		/* parent */
+		tst_brkm(TBROK, NULL, "can't fork rserver");
+	default:
 		close(sd);
 		close(csd[1]);
-		return client(pid, csd[0]);
+		return client(csd[0]);
 	}
 
 	tv.tv_sec = READ_TIMEOUT;
@@ -515,13 +469,7 @@ int csum_test(char *rhost)
 	return 0;
 }
 
-void setup(void)
-{
-	TEST_PAUSE;		/* if -P option specified */
-}
-
-void cleanup(void)
+static void setup(void)
 {
+	TEST_PAUSE;
 }
-
-int TST_TOTAL = PTCOUNT + CSCOUNT;
-- 
1.9.3


------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v3 4/7] lib6/asapi_05.c: Cleanup
  2015-06-16 12:24                 ` [LTP] [PATCH v3 1/7] SAFE_MACROS: Add socket(), bind(), listen(), connect() and getsockname() Zeng Linggang
  2015-06-16 12:24                   ` [LTP] [PATCH v3 2/7] lib6/runcc.c: Cleanup Zeng Linggang
  2015-06-16 12:24                   ` [LTP] [PATCH v3 3/7] lib6/asapi_04.c: Cleanup Zeng Linggang
@ 2015-06-16 12:24                   ` Zeng Linggang
  2015-06-16 12:24                   ` [LTP] [PATCH v3 5/7] lib6/asapi_06.c: Cleanup Zeng Linggang
                                     ` (3 subsequent siblings)
  6 siblings, 0 replies; 55+ messages in thread
From: Zeng Linggang @ 2015-06-16 12:24 UTC (permalink / raw)
  To: alexey.kodanev; +Cc: ltp-list

* Add 'static' before some functions and global variables.
* Remove cleanup() function.
* Remove useless comments.
* Use SAFE_XXX().
* Modify the format of etab[] and ftab[].
* Some cleanup.

Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
 testcases/network/lib6/asapi_05.c | 273 +++++++++++++++-----------------------
 1 file changed, 108 insertions(+), 165 deletions(-)

diff --git a/testcases/network/lib6/asapi_05.c b/testcases/network/lib6/asapi_05.c
index 9acc6a2..d51b912 100644
--- a/testcases/network/lib6/asapi_05.c
+++ b/testcases/network/lib6/asapi_05.c
@@ -1,38 +1,21 @@
 /*
+ * Copyright (c) 2015 Fujitsu Ltd.
+ * Copyright (c) International Business Machines  Corp., 2001
  *
- *   Copyright (c) International Business Machines  Corp., 2001
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
  *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
  *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/*
- * Test Name: asapi_05
- *
- * Test Description:
- *  These tests are for the "Advanced Sockets API" (RFC 3542)
- *  Verify that in6 and sockaddr fields are present.
- *
- * Usage:  <for command-line>
- *  asapi_05
- *
- * HISTORY
- *	04/2005 written by David L Stevens
- *
- * RESTRICTIONS:
- *  None.
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
+ * Author: David L Stevens
  */
 
 #include <stdio.h>
@@ -47,21 +30,20 @@
 #include <netinet/icmp6.h>
 
 #include "test.h"
+#include "safe_macros.h"
 #include "runcc.h"
 
-char *TCID = "asapi_05";	/* Test program identifier.    */
+char *TCID = "asapi_05";
 
-void setup(void);
-void cleanup(void);
+static void setup(void);
 
-void icmp6_et(void);
-void icmp6_ft(void);
+static void icmp6_et(void);
+static void icmp6_ft(void);
 
 int main(int argc, char *argv[])
 {
 	int lc;
 
-	/* Parse standard options given to run the test. */
 	tst_parse_opts(argc, argv, NULL, NULL);
 
 	setup();
@@ -71,14 +53,12 @@ int main(int argc, char *argv[])
 		icmp6_ft();
 	}
 
-	cleanup();
-
 	tst_exit();
 }
 
 enum ttype { EXISTS, ALIAS, VALUE, DEFINED };
 
-struct etent {
+static struct etent {
 	char *et_tname;		/* test name */
 	int et_type;		/* test type */
 	char *et_incl;		/* include file list */
@@ -92,76 +72,58 @@ struct etent {
 #define et_value	ftun.fu_value
 #define et_dname	ftun.fu_dname
 } etab[] = {
-/* existence checks, RFC 3542 section 3 */
-	{
-		"icmp6_filter icmp6_filt", EXISTS, ICMP6_H, "icmp6_filter",
-		    "icmp6_filt", "0", {
-	"32"}}, {
-		"icmp6_filter icmp6_filt[0]", EXISTS, ICMP6_H, "icmp6_filter",
-		    "icmp6_filt[0]", "0", {
-	"4"}}, {
-		"ICMP6_FILTER_WILLPASS", DEFINED, ICMP6_H,
-		    "ICMP6_FILTER_WILLPASS", NULL, NULL, {
-	0}}, {
-		"ICMP6_FILTER_WILLBLOCK", DEFINED, ICMP6_H,
-		    "ICMP6_FILTER_WILLBLOCK", NULL, NULL, {
-	0}}, {
-		"ICMP6_FILTER_SETPASS", DEFINED, ICMP6_H,
-		    "ICMP6_FILTER_SETPASS", NULL, NULL, {
-	0}}, {
-		"ICMP6_FILTER_SETBLOCK", DEFINED, ICMP6_H,
-		    "ICMP6_FILTER_SETBLOCK", NULL, NULL, {
-	0}}, {
-		"ICMP6_FILTER_SETPASSALL", DEFINED, ICMP6_H,
-		    "ICMP6_FILTER_SETPASSALL", NULL, NULL, {
-	0}}, {
-		"ICMP6_FILTER_SETBLOCKALL", DEFINED, ICMP6_H,
-		    "ICMP6_FILTER_SETBLOCKALL", NULL, NULL, {
-	0}}, {
-		"ICMP6_FILTER", DEFINED, ICMP6_H, "ICMP6_FILTER", NULL, NULL, {
-	0}},
-/* existence checks, RFC 3542 section 4 */
-/* socket options */
-	{
-		"IPV6_RECVPKTINFO", VALUE, IN_H, "IPV6_RECVPKTINFO", NULL, NULL, {
-	"IPV6_RECVPKTINFO"}}, {
-		"IPV6_RECVHOPLIMIT", VALUE, IN_H, "IPV6_RECVHOPLIMIT", NULL,
-		    NULL, {
-	"IPV6_RECVHOPLIMIT"}}, {
-		"IPV6_RECVRTHDR", VALUE, IN_H, "IPV6_RECVRTHDR", NULL, NULL, {
-	"IPV6_RECVRTHDR"}}, {
-		"IPV6_RECVHOPOPTS", VALUE, IN_H, "IPV6_RECVHOPOPTS", NULL, NULL, {
-	"IPV6_RECVHOPOPTS"}}, {
-		"IPV6_RECVDSTOPTS", VALUE, IN_H, "IPV6_RECVDSTOPTS", NULL, NULL, {
-	"IPV6_RECVDSTOPTS"}}, {
-		"IPV6_RECVTCLASS", VALUE, IN_H, "IPV6_RECVTCLASS", NULL, NULL, {
-	"IPV6_RECVTCLASS"}},
-/* cmsg types */
-	{
-		"IPV6_PKTINFO", DEFINED, IN_H, "IPV6_PKTINFO", NULL, NULL, {
-	0}}, {
-		"IPV6_HOPLIMIT", DEFINED, IN_H, "IPV6_HOPLIMIT", NULL, NULL, {
-	0}}, {
-		"IPV6_NEXTHOP", DEFINED, IN_H, "IPV6_NEXTHOP", NULL, NULL, {
-	0}}, {
-		"IPV6_RTHDR", DEFINED, IN_H, "IPV6_RTHDR", NULL, NULL, {
-	0}}, {
-		"IPV6_HOPOPTS", DEFINED, IN_H, "IPV6_HOPOPTS", NULL, NULL, {
-	0}}, {
-		"IPV6_DSTOPTS", DEFINED, IN_H, "IPV6_DSTOPTS", NULL, NULL, {
-	0}}, {
-		"IPV6_RTHDRDSTOPTS", DEFINED, IN_H, "IPV6_RTHDRDSTOPTS", NULL,
-		    NULL, {
-	0}}, {
-		"IPV6_TCLASS", DEFINED, IN_H, "IPV6_TCLASS", NULL, NULL, {
-0}},};
-
-#define ETCOUNT	(sizeof(etab)/sizeof(etab[0]))
+	/* existence checks, RFC 3542 section 3 */
+	{"icmp6_filter icmp6_filt", EXISTS, ICMP6_H, "icmp6_filter",
+	 "icmp6_filt", "0", {"32"} },
+	{"icmp6_filter icmp6_filt[0]", EXISTS, ICMP6_H, "icmp6_filter",
+	 "icmp6_filt[0]", "0", {"4"} },
+	{"ICMP6_FILTER_WILLPASS", DEFINED, ICMP6_H, "ICMP6_FILTER_WILLPASS",
+	 NULL, NULL, {0} },
+	{"ICMP6_FILTER_WILLBLOCK", DEFINED, ICMP6_H, "ICMP6_FILTER_WILLBLOCK",
+	 NULL, NULL, {0} },
+	{"ICMP6_FILTER_SETPASS", DEFINED, ICMP6_H, "ICMP6_FILTER_SETPASS", NULL,
+	 NULL, {0} },
+	{"ICMP6_FILTER_SETBLOCK", DEFINED, ICMP6_H, "ICMP6_FILTER_SETBLOCK",
+	 NULL, NULL, {0} },
+	{"ICMP6_FILTER_SETPASSALL", DEFINED, ICMP6_H, "ICMP6_FILTER_SETPASSALL",
+	 NULL, NULL, {0} },
+	{"ICMP6_FILTER_SETBLOCKALL", DEFINED, ICMP6_H,
+	 "ICMP6_FILTER_SETBLOCKALL", NULL, NULL, {0} },
+	{"ICMP6_FILTER", DEFINED, ICMP6_H, "ICMP6_FILTER", NULL, NULL, {0} },
+	/* existence checks, RFC 3542 section 4 */
+	/* socket options */
+	{"IPV6_RECVPKTINFO", VALUE, IN_H, "IPV6_RECVPKTINFO", NULL, NULL,
+	 {"IPV6_RECVPKTINFO"} },
+	{"IPV6_RECVHOPLIMIT", VALUE, IN_H, "IPV6_RECVHOPLIMIT", NULL, NULL,
+	 {"IPV6_RECVHOPLIMIT"} },
+	{"IPV6_RECVRTHDR", VALUE, IN_H, "IPV6_RECVRTHDR", NULL, NULL,
+	 {"IPV6_RECVRTHDR"} },
+	{"IPV6_RECVHOPOPTS", VALUE, IN_H, "IPV6_RECVHOPOPTS", NULL, NULL,
+	 {"IPV6_RECVHOPOPTS"} },
+	{"IPV6_RECVDSTOPTS", VALUE, IN_H, "IPV6_RECVDSTOPTS", NULL, NULL,
+	 {"IPV6_RECVDSTOPTS"} },
+	{"IPV6_RECVTCLASS", VALUE, IN_H, "IPV6_RECVTCLASS", NULL, NULL,
+	 {"IPV6_RECVTCLASS"} },
+	/* cmsg types */
+	{"IPV6_PKTINFO", DEFINED, IN_H, "IPV6_PKTINFO", NULL, NULL, {0} },
+	{"IPV6_HOPLIMIT", DEFINED, IN_H, "IPV6_HOPLIMIT", NULL, NULL, {0} },
+	{"IPV6_NEXTHOP", DEFINED, IN_H, "IPV6_NEXTHOP", NULL, NULL, {0} },
+	{"IPV6_RTHDR", DEFINED, IN_H, "IPV6_RTHDR", NULL, NULL, {0} },
+	{"IPV6_HOPOPTS", DEFINED, IN_H, "IPV6_HOPOPTS", NULL, NULL, {0} },
+	{"IPV6_DSTOPTS", DEFINED, IN_H, "IPV6_DSTOPTS", NULL, NULL, {0} },
+	{"IPV6_RTHDRDSTOPTS", DEFINED, IN_H, "IPV6_RTHDRDSTOPTS", NULL, NULL,
+	 {0} },
+	{"IPV6_TCLASS", DEFINED, IN_H, "IPV6_TCLASS", NULL, NULL, {0} },
+};
+
+#define ETCOUNT	ARRAY_SIZE(etab)
+
+int TST_TOTAL = ETCOUNT;
 
 /*  existence tests */
-void icmp6_et(void)
+static void icmp6_et(void)
 {
-	int i;
+	unsigned int i;
 
 	for (i = 0; i < ETCOUNT; ++i) {
 		switch (etab[i].et_type) {
@@ -190,60 +152,52 @@ void icmp6_et(void)
 	}
 }
 
-void setup(void)
+static void setup(void)
 {
-	TEST_PAUSE;		/* if -P option specified */
+	TEST_PAUSE;
 	tst_require_root(NULL);
 }
 
-void cleanup(void)
-{
-}
-
-/*
- * This is for old, broken glibc-header icmp6_filter structure definitions.
- * If icmp6.h has struct icmp6_filter with field named "data" instead
- * of the standard "icmp_filt", uncomment this line.
- */
-/*#define icmp_filt	data */
-
-enum tt { T_WILLPASS, T_WILLBLOCK, T_SETPASS, T_SETBLOCK, T_SETPASSALL,
+enum tt {
+	T_WILLPASS,
+	T_WILLBLOCK,
+	T_SETPASS,
+	T_SETBLOCK,
+	T_SETPASSALL,
 	T_SETBLOCKALL
 };
-struct ftent {
-	char *ft_tname;		/* test name, for logging */
+
+static struct ftent {
+	char *ft_tname;			/* test name, for logging */
 	unsigned char ft_sndtype;	/* send type field */
 	unsigned char ft_flttype;	/* filter type field */
-	enum tt ft_test;	/* what macro to test */
-	int ft_expected;	/* packet should pass? */
+	enum tt ft_test;		/* what macro to test */
+	int ft_expected;		/* packet should pass? */
 } ftab[] = {
-	{
-	"ICMP6_FILTER_SETPASS s 20 f 20", 20, 20, T_SETPASS, 1}, {
-	"ICMP6_FILTER_SETPASS s 20 f 21", 20, 21, T_SETPASS, 0}, {
-	"ICMP6_FILTER_SETBLOCK s 20 f 20", 20, 20, T_SETBLOCK, 0}, {
-	"ICMP6_FILTER_SETBLOCK s 20 f 21", 20, 21, T_SETBLOCK, 1}, {
-	"ICMP6_FILTER_PASSALL s 20", 20, 0, T_SETPASSALL, 1}, {
-	"ICMP6_FILTER_PASSALL s 20", 21, 0, T_SETPASSALL, 1}, {
-	"ICMP6_FILTER_BLOCKALL s 20", 20, 0, T_SETBLOCKALL, 0}, {
-	"ICMP6_FILTER_BLOCKALL s 20", 21, 0, T_SETBLOCKALL, 0}, {
-	"ICMP6_FILTER_WILLBLOCK s 20 f 21", 20, 21, T_WILLBLOCK, 0}, {
-	"ICMP6_FILTER_WILLBLOCK s 20 f 20", 20, 20, T_WILLBLOCK, 1}, {
-	"ICMP6_FILTER_WILLPASS s 20 f 21", 20, 21, T_WILLPASS, 0}, {
-"ICMP6_FILTER_WILLPASS s 22 f 22", 22, 22, T_WILLPASS, 1},};
-
-#define FTCOUNT	(sizeof(ftab)/sizeof(ftab[0]))
-
-int ic6_send1(char *tname, unsigned char type)
+	{"ICMP6_FILTER_SETPASS s 20 f 20", 20, 20, T_SETPASS, 1},
+	{"ICMP6_FILTER_SETPASS s 20 f 21", 20, 21, T_SETPASS, 0},
+	{"ICMP6_FILTER_SETBLOCK s 20 f 20", 20, 20, T_SETBLOCK, 0},
+	{"ICMP6_FILTER_SETBLOCK s 20 f 21", 20, 21, T_SETBLOCK, 1},
+	{"ICMP6_FILTER_PASSALL s 20", 20, 0, T_SETPASSALL, 1},
+	{"ICMP6_FILTER_PASSALL s 20", 21, 0, T_SETPASSALL, 1},
+	{"ICMP6_FILTER_BLOCKALL s 20", 20, 0, T_SETBLOCKALL, 0},
+	{"ICMP6_FILTER_BLOCKALL s 20", 21, 0, T_SETBLOCKALL, 0},
+	{"ICMP6_FILTER_WILLBLOCK s 20 f 21", 20, 21, T_WILLBLOCK, 0},
+	{"ICMP6_FILTER_WILLBLOCK s 20 f 20", 20, 20, T_WILLBLOCK, 1},
+	{"ICMP6_FILTER_WILLPASS s 20 f 21", 20, 21, T_WILLPASS, 0},
+	{"ICMP6_FILTER_WILLPASS s 22 f 22", 22, 22, T_WILLPASS, 1},
+};
+
+#define FTCOUNT	ARRAY_SIZE(ftab)
+
+static int ic6_send1(char *tname, unsigned char type)
 {
 	struct sockaddr_in6 sin6;
 	struct icmp6_hdr ic6;
 	int s;
 
-	s = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
-	if (s == -1) {
-		tst_resm(TBROK, "%s: socket failed", tname);
-		return 1;
-	}
+	s = SAFE_SOCKET(NULL, AF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
+
 	memset(&ic6, 0, sizeof(ic6));
 	ic6.icmp6_type = type;
 	ic6.icmp6_data32[0] = htonl(getpid());
@@ -259,7 +213,7 @@ int ic6_send1(char *tname, unsigned char type)
 	return 0;
 }
 
-int ic6_recv1(char *tname, int sall, int sf)
+static int ic6_recv1(char *tname, int sall, int sf)
 {
 	fd_set readfds, readfds_saved;
 	struct timeval tv;
@@ -302,7 +256,7 @@ int ic6_recv1(char *tname, int sall, int sf)
 				return -1;
 			}
 			/* if packet check succeeds... */
-			if (htonl(pic6->icmp6_data32[0]) == getpid())
+			if (htonl(pic6->icmp6_data32[0]) == (uint32_t)getpid())
 				gotall = 1;
 		}
 		if (FD_ISSET(sf, &readfds)) {
@@ -313,7 +267,7 @@ int ic6_recv1(char *tname, int sall, int sf)
 				return -1;
 			}
 			/* if packet check succeeds... */
-			if (htonl(pic6->icmp6_data32[0]) == getpid())
+			if (htonl(pic6->icmp6_data32[0]) == (uint32_t)getpid())
 				gotone = 1;
 		}
 		memcpy(&readfds, &readfds_saved, sizeof(readfds));
@@ -328,18 +282,14 @@ int ic6_recv1(char *tname, int sall, int sf)
 }
 
 /* functional tests */
-void icmp6_ft(void)
+static void icmp6_ft(void)
 {
 	struct icmp6_filter i6f;
 	int sall, sf;
-	int i;
+	unsigned int i;
+
+	sall = SAFE_SOCKET(NULL, PF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
 
-	sall = socket(PF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
-	if (sall < 0) {
-		tst_resm(TBROK | TERRNO,
-			 "icmp6_ft socket: can't create sall socket");
-		return;
-	}
 	ICMP6_FILTER_SETPASSALL(&i6f);
 	if (setsockopt(sall, IPPROTO_ICMPV6, ICMP6_FILTER, &i6f,
 		       sizeof(i6f)) < 0) {
@@ -347,12 +297,7 @@ void icmp6_ft(void)
 			 "setsockopt pass all ICMP6_FILTER failed");
 	}
 
-	sf = socket(PF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
-	if (sf < 0) {
-		tst_resm(TBROK | TERRNO,
-			 "icmp6_ft socket: can't create test socket");
-		return;
-	}
+	sf = SAFE_SOCKET(NULL, PF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
 
 	int rv;
 
@@ -413,5 +358,3 @@ void icmp6_ft(void)
 			tst_resm(TPASS, "%s", ftab[i].ft_tname);
 	}
 }
-
-int TST_TOTAL = ETCOUNT;
-- 
1.9.3


------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v3 5/7] lib6/asapi_06.c: Cleanup
  2015-06-16 12:24                 ` [LTP] [PATCH v3 1/7] SAFE_MACROS: Add socket(), bind(), listen(), connect() and getsockname() Zeng Linggang
                                     ` (2 preceding siblings ...)
  2015-06-16 12:24                   ` [LTP] [PATCH v3 4/7] lib6/asapi_05.c: Cleanup Zeng Linggang
@ 2015-06-16 12:24                   ` Zeng Linggang
  2015-06-16 12:24                   ` [LTP] [PATCH v3 6/7] lib6/getaddrinfo_01.c: Cleanup Zeng Linggang
                                     ` (2 subsequent siblings)
  6 siblings, 0 replies; 55+ messages in thread
From: Zeng Linggang @ 2015-06-16 12:24 UTC (permalink / raw)
  To: alexey.kodanev; +Cc: ltp-list

* Add 'static' before some functions and global variables.
* Remove cleanup() function.
* Remove useless comments.
* Use SAFE_XXX().
* Remove unused variables.
* Modify the format of sotab[] and cmtab[].
* Modify the initialization of sotab[].
* Some cleanup.

Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
 testcases/network/lib6/asapi_06.c | 316 ++++++++++++++------------------------
 1 file changed, 115 insertions(+), 201 deletions(-)

diff --git a/testcases/network/lib6/asapi_06.c b/testcases/network/lib6/asapi_06.c
index 960ebb5..215a8c9 100644
--- a/testcases/network/lib6/asapi_06.c
+++ b/testcases/network/lib6/asapi_06.c
@@ -1,37 +1,21 @@
 /*
+ * Copyright (c) 2015 Fujitsu Ltd.
+ * Copyright (c) International Business Machines  Corp., 2001
  *
- *   Copyright (c) International Business Machines  Corp., 2001
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
  *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
  *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/*
- * Test Name: asapi_06
- *
- * Test Description:
- *  Tests for RFC 3542 section 4 socket options and ancillary data
- *
- * Usage:  <for command-line>
- *  asapi_06
- *
- * HISTORY
- *	05/2005 written by David L Stevens
- *
- * RESTRICTIONS:
- *  None.
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
+ * Author: David L Stevens
  */
 
 #include "config.h"
@@ -57,25 +41,18 @@
 #include <arpa/inet.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
-char *TCID = "asapi_06";	/* Test program identifier.    */
+char *TCID = "asapi_06";
 
 int TST_TOTAL = 1;
 
-pid_t pid;
-
-struct {
-	char *prt_name;
-	int prt_value;
-} ptab[] = {
-};
-
-#define PTCOUNT	(sizeof(ptab)/sizeof(ptab[0]))
+static pid_t pid;
 
 #define READ_TIMEOUT	5	/* secs */
 
-void do_tests(void);
-void setup(void), cleanup(void);
+static void do_tests(void);
+static void setup(void);
 
 int main(int argc, char *argv[])
 {
@@ -90,47 +67,46 @@ int main(int argc, char *argv[])
 	for (lc = 0; TEST_LOOPING(lc); ++lc)
 		do_tests();
 
-	cleanup();
 	tst_exit();
 }
 
 #define NH_TEST	0x9f
 
 #ifndef IPV6_RECVPKTINFO
-#define IPV6_RECVPKTINFO	-1
+# define IPV6_RECVPKTINFO	-1
 #endif
 #ifndef IPV6_RECVHOPLIMIT
-#define IPV6_RECVHOPLIMIT	-1
+# define IPV6_RECVHOPLIMIT	-1
 #endif
 #ifndef IPV6_RECVRTHDR
-#define IPV6_RECVRTHDR		-1
+# define IPV6_RECVRTHDR		-1
 #endif
 #ifndef IPV6_RECVHOPOPTS
-#define IPV6_RECVHOPOPTS	-1
+# define IPV6_RECVHOPOPTS	-1
 #endif
 #ifndef IPV6_RECVDSTOPTS
-#define IPV6_RECVDSTOPTS	-1
+# define IPV6_RECVDSTOPTS	-1
 #endif
 #ifndef IPV6_RECVTCLASS
-#define IPV6_RECVTCLASS		-1
+# define IPV6_RECVTCLASS		-1
 #endif
 #ifndef IPV6_TCLASS
-#define IPV6_TCLASS		-1
+# define IPV6_TCLASS		-1
 #endif
 #ifndef IPV6_2292PKTINFO
-#define	IPV6_2292PKTINFO	-1
+# define	IPV6_2292PKTINFO	-1
 #endif
 #ifndef IPV6_2292HOPLIMIT
-#define	IPV6_2292HOPLIMIT	-1
+# define	IPV6_2292HOPLIMIT	-1
 #endif
 #ifndef IPV6_2292RTHDR
-#define	IPV6_2292RTHDR		-1
+# define	IPV6_2292RTHDR		-1
 #endif
 #ifndef IPV6_2292HOPOPTS
-#define	IPV6_2292HOPOPTS	-1
+# define	IPV6_2292HOPOPTS	-1
 #endif
 #ifndef IPV6_2292DSTOPTS
-#define	IPV6_2292DSTOPTS	-1
+# define	IPV6_2292DSTOPTS	-1
 #endif
 
 union soval {
@@ -150,7 +126,7 @@ union soval {
 #define IN6_ANY		{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
 
 /* so_clrval and so_setval members are initilized in the body */
-struct soent {
+static struct soent {
 	char *so_tname;
 	int so_opt;
 	int so_dorecv;		/* do receive test? */
@@ -160,73 +136,52 @@ struct soent {
 	union soval so_setval;
 	socklen_t so_valsize;
 } sotab[] = {
-/* RFC 3542, Section 4 */
-	{
-		"IPV6_RECVPKTINFO", IPV6_RECVPKTINFO, 1, IPV6_PKTINFO, 1, { { { { {
-		0}}}}}, { { { { {
-	0}}}}}, sizeof(int)}, {
-		"IPV6_RECVHOPLIMIT", IPV6_RECVHOPLIMIT, 1, IPV6_HOPLIMIT, 1, { { { { {
-		0}}}}}, { { { { {
-	0}}}}}, sizeof(int)}, {
-		"IPV6_RECVRTHDR", IPV6_RECVRTHDR, 0, IPV6_RTHDR, 1, { { { { {
-		0}}}}}, { { { { {
-	0}}}}}, sizeof(int)}, {
-		"IPV6_RECVHOPOPTS", IPV6_RECVHOPOPTS, 0, IPV6_HOPOPTS, 1, { { { { {
-		0}}}}}, { { { { {
-	0}}}}}, sizeof(int)}, {
-		"IPV6_RECVDSTOPTS", IPV6_RECVDSTOPTS, 0, IPV6_DSTOPTS, 1, { { { { {
-		0}}}}}, { { { { {
-	0}}}}}, sizeof(int)}, {
-		"IPV6_RECVTCLASS", IPV6_RECVTCLASS, 1, IPV6_TCLASS, 1, { { { { {
-		0}}}}}, { { { { {
-	0}}}}}, sizeof(int)},
-/* make sure TCLASS stays when setting another opt */
-	{
-		"IPV6_RECVTCLASS (2)", IPV6_RECVHOPLIMIT, 1, IPV6_TCLASS, 0, { { { { {
-		0}}}}}, { { { { {
-	0}}}}}, sizeof(int)},
-/* OLD values */
-	{
-		"IPV6_2292PKTINFO", IPV6_2292PKTINFO, 1, IPV6_2292PKTINFO, 1, { { { { {
-		0}}}}}, { { { { {
-	0}}}}}, sizeof(int)}, {
-		"IPV6_2292HOPLIMIT", IPV6_2292HOPLIMIT, 1, IPV6_2292HOPLIMIT, 1, { { { { {
-		0}}}}}, { { { { {
-	0}}}}}, sizeof(int)}, {
-		"IPV6_2292RTHDR", IPV6_2292RTHDR, 0, IPV6_2292RTHDR, 1, { { { { {
-		0}}}}}, { { { { {
-	0}}}}}, sizeof(int)}, {
-		"IPV6_2292HOPOPTS", IPV6_2292HOPOPTS, 0, IPV6_2292HOPOPTS, 1, { { { { {
-		0}}}}}, { { { { {
-	0}}}}}, sizeof(int)}, {
-		"IPV6_2292DSTOPTS", IPV6_2292DSTOPTS, 0, IPV6_2292DSTOPTS, 1, { { { { {
-		0}}}}}, { { { { {
-0}}}}}, sizeof(int)},};
-
-#define SOCOUNT	(sizeof(sotab)/sizeof(sotab[0]))
+	/* RFC 3542, Section 4 */
+	{"IPV6_RECVPKTINFO", IPV6_RECVPKTINFO, 1, IPV6_PKTINFO, 1,
+	 {{{{{0} } }, 0} }, {{{{{0} } }, 0} }, sizeof(int)},
+	{"IPV6_RECVHOPLIMIT", IPV6_RECVHOPLIMIT, 1, IPV6_HOPLIMIT, 1,
+	 {{{{{0} } }, 0} }, {{{{{0} } }, 0} }, sizeof(int)},
+	{"IPV6_RECVRTHDR", IPV6_RECVRTHDR, 0, IPV6_RTHDR, 1,
+	 {{{{{0} } }, 0} }, {{{{{0} } }, 0} }, sizeof(int)},
+	{"IPV6_RECVHOPOPTS", IPV6_RECVHOPOPTS, 0, IPV6_HOPOPTS, 1,
+	 {{{{{0} } }, 0} }, {{{{{0} } }, 0} }, sizeof(int)},
+	{"IPV6_RECVDSTOPTS", IPV6_RECVDSTOPTS, 0, IPV6_DSTOPTS, 1,
+	 {{{{{0} } }, 0} }, {{{{{0} } }, 0} }, sizeof(int)},
+	{"IPV6_RECVTCLASS", IPV6_RECVTCLASS, 1, IPV6_TCLASS, 1,
+	 {{{{{0} } }, 0} }, {{{{{0} } }, 0} }, sizeof(int)},
+	/* make sure TCLASS stays when setting another opt */
+	{"IPV6_RECVTCLASS (2)", IPV6_RECVHOPLIMIT, 1, IPV6_TCLASS, 0,
+	 {{{{{0} } }, 0} }, {{{{{0} } }, 0} }, sizeof(int)},
+	/* OLD values */
+	{"IPV6_2292PKTINFO", IPV6_2292PKTINFO, 1, IPV6_2292PKTINFO, 1,
+	 {{{{{0} } }, 0} }, {{{{{0} } }, 0} }, sizeof(int)},
+	{"IPV6_2292HOPLIMIT", IPV6_2292HOPLIMIT, 1, IPV6_2292HOPLIMIT, 1,
+	 {{{{{0} } }, 0} }, {{{{{0} } }, 0} }, sizeof(int)},
+	{"IPV6_2292RTHDR", IPV6_2292RTHDR, 0, IPV6_2292RTHDR, 1,
+	 {{{{{0} } }, 0} }, {{{{{0} } }, 0} }, sizeof(int)},
+	{"IPV6_2292HOPOPTS", IPV6_2292HOPOPTS, 0, IPV6_2292HOPOPTS, 1,
+	 {{{{{0} } }, 0} }, {{{{{0} } }, 0} }, sizeof(int)},
+	{"IPV6_2292DSTOPTS", IPV6_2292DSTOPTS, 0, IPV6_2292DSTOPTS, 1,
+	 {{{{{0} } }, 0} }, {{{{{0} } }, 0} }, sizeof(int)},
+};
+
+#define SOCOUNT	ARRAY_SIZE(sotab)
 
 struct soprot {
-	int sop_pid;		/* sender PID */
-	int sop_seq;		/* sequence # */
-	int sop_dlen;		/* tp_dat length */
+	int sop_pid;			/* sender PID */
+	int sop_seq;			/* sequence # */
+	int sop_dlen;			/* tp_dat length */
 	unsigned char sop_dat[0];	/* user data */
 };
 
-unsigned char tpbuf[sizeof(struct soprot) + 2048];
-unsigned char rpbuf[sizeof(struct soprot) + 2048];
+static unsigned char tpbuf[sizeof(struct soprot) + 2048];
+static unsigned char rpbuf[sizeof(struct soprot) + 2048];
 
-unsigned char control[2048];
-int clen;
+static unsigned char control[2048];
 
-int seq;
+static int seq;
 
-int setupso(void)
-{
-/* add routing headers, other ancillary data here */
-	return 0;
-}
-
-struct cme {
+static struct cme {
 	int cm_len;
 	int cm_level;
 	int cm_type;
@@ -235,26 +190,21 @@ struct cme {
 		uint32_t cmu_hops;
 	} cmu;
 } cmtab[] = {
-	{
-		sizeof(uint32_t), SOL_IPV6, IPV6_TCLASS, {
-		0x12}
-	}
-	, {
-		sizeof(uint32_t), SOL_IPV6, IPV6_HOPLIMIT, {
-		0x21}
-	}
-,};
+	{sizeof(uint32_t), SOL_IPV6, IPV6_TCLASS, {0x12} },
+	{sizeof(uint32_t), SOL_IPV6, IPV6_HOPLIMIT, {0x21} },
+};
 
-#define CMCOUNT	(sizeof(cmtab)/sizeof(cmtab[0]))
+#define CMCOUNT	ARRAY_SIZE(cmtab)
 
-ssize_t sendall(int st)
+static ssize_t sendall(int st)
 {
 	struct sockaddr_in6 sin6;
 	struct msghdr msg;
 	struct iovec iov;
 	struct soprot *psop;
 	unsigned char *pd;
-	int i, ctotal;
+	unsigned int i;
+	int ctotal;
 
 	psop = (struct soprot *)tpbuf;
 	psop->sop_pid = htonl(getpid());
@@ -291,7 +241,7 @@ ssize_t sendall(int st)
 	return sendmsg(st, &msg, 0);
 }
 
-void so_test(struct soent *psoe)
+static void so_test(struct soent *psoe)
 {
 	struct sockaddr_in6 sin6;
 	union soval sobuf;
@@ -317,10 +267,9 @@ void so_test(struct soent *psoe)
 	memset(&sin6, 0, sizeof(sin6));
 	sin6.sin6_family = AF_INET6;
 	sin6.sin6_addr = in6addr_loopback;
-	if (bind(sr, (struct sockaddr *)&sin6, sizeof(sin6)) < 0) {
-		tst_resm(TBROK, "%s: bind: %s", psoe->so_tname,
-			 strerror(errno));
-	}
+
+	SAFE_BIND(NULL, sr, (struct sockaddr *)&sin6, sizeof(sin6));
+
 	if (setsockopt(sr, SOL_IPV6, psoe->so_opt, &psoe->so_clrval,
 		       psoe->so_valsize) < 0) {
 		tst_resm(TBROK, "%s: setsockopt: %s", psoe->so_tname,
@@ -345,12 +294,8 @@ void so_test(struct soent *psoe)
 	else
 		tst_resm(TPASS, "%s set-get", psoe->so_tname);
 
-	st = socket(PF_INET6, SOCK_RAW, NH_TEST);
-	if (st < 0) {
-		tst_resm(TBROK, "%s transmit socket: %s", psoe->so_tname,
-			 strerror(errno));
-		return;
-	}
+	st = SAFE_SOCKET(NULL, PF_INET6, SOCK_RAW, NH_TEST);
+
 	if (sendall(st) < 0) {
 		tst_resm(TBROK, "%s transmit sendto: %s", psoe->so_tname,
 			 strerror(errno));
@@ -409,7 +354,7 @@ void so_test(struct soent *psoe)
 					 psoe->so_tname, strerror(errno));
 				return;
 			}
-/* check pid & seq here */
+			/* check pid & seq here */
 			break;
 		}
 		gotone = 0;
@@ -429,7 +374,7 @@ void so_test(struct soent *psoe)
 				return;
 			}
 		}
-/* check contents here */
+		/* check contents here */
 		if (psoe->so_dorecv)
 			tst_resm(gotone ? TPASS : TFAIL, "%s receive",
 				 psoe->so_tname);
@@ -451,20 +396,18 @@ static int ipv6_addr_scope(struct in6_addr *pin6)
 }
 #endif /* HAVE_IFADDRS_H */
 
-int getsock(char *tname, struct sockaddr_in6 *psin6_arg, int scope)
+static int getsock(char *tname, struct sockaddr_in6 *psin6_arg, int scope)
 {
 #ifdef HAVE_IFADDRS_H
 	static struct ifaddrs *pifa_head;
 	struct ifaddrs *pifa;
 	struct sockaddr_in6 *psin6;
-	char strbuf[128];
 	int ifindex = 0;
 	int s;
 
-	if (!pifa_head && getifaddrs(&pifa_head)) {
-		tst_resm(TBROK, "%s: getifaddrs failed", tname);
-		return -1;
-	}
+	if (!pifa_head && getifaddrs(&pifa_head))
+		tst_brkm(TBROK, NULL, "%s: getifaddrs failed", tname);
+
 	if (psin6_arg)
 		ifindex = psin6_arg->sin6_scope_id;
 
@@ -483,21 +426,16 @@ int getsock(char *tname, struct sockaddr_in6 *psin6_arg, int scope)
 		     (this_scope > 0 && this_scope != scope)))
 			continue;
 		psin6->sin6_scope_id = if_nametoindex(pifa->ifa_name);
-		if ((ifindex < 0 && -ifindex == psin6->sin6_scope_id) ||
-		    (ifindex > 0 && ifindex != psin6->sin6_scope_id))
+		if ((ifindex < 0 &&
+		     -(unsigned int)ifindex == psin6->sin6_scope_id) ||
+		    (ifindex > 0 &&
+		     (unsigned int)ifindex != psin6->sin6_scope_id))
 			continue;
-		s = socket(PF_INET6, SOCK_DGRAM, 0);
-		if (s < 0) {
-			tst_resm(TBROK, "%s: socket %s", tname,
-				 strerror(errno));
-			return -1;
-		}
-		if (bind(s, pifa->ifa_addr, sizeof(struct sockaddr_in6)) < 0) {
-			tst_resm(TBROK, "%s: bind \"%s\": %s", tname,
-				 inet_ntop(AF_INET6, &psin6->sin6_addr, strbuf,
-					   sizeof(strbuf)), strerror(errno));
-			return -1;
-		}
+
+		s = SAFE_SOCKET(NULL, PF_INET6, SOCK_DGRAM, 0);
+
+		SAFE_BIND(NULL, s, pifa->ifa_addr, sizeof(struct sockaddr_in6));
+
 		if (psin6_arg) {
 			*psin6_arg = *psin6;
 			psin6_arg->sin6_scope_id =
@@ -539,7 +477,10 @@ int getsock(char *tname, struct sockaddr_in6 *psin6_arg, int scope)
 	}
 	return -1;
 #else /* HAVE_IFADDRS_H */
+/*
 	return -1;
+*/
+	tst_brkm(TBROK, NULL, "HAVE_IFADDRS_H is not defined");
 #endif
 }
 
@@ -548,46 +489,28 @@ int getsock(char *tname, struct sockaddr_in6 *psin6_arg, int scope)
  * RFC 3542 IPV6_PKTINFO not in mainline yet (as of 2.6.15). The get/set
  * tests are below, and comments for some further tests to be added later
  */
-void test_pktinfo(void)
+static void test_pktinfo(void)
 {
-	int s_snd, s_rcv[3] = { -1, -1, -1 };
+	int s_snd;
 	struct sockaddr_in6 sa_rcv[3];
-	int s, i;
-	struct ifaddrs *pifa_head, *pifa;
-	struct sockaddr_in6 *psin6;
 	char strbuf[128];
 	char *tname = "IPV6_PKTINFO";
 	struct in6_pktinfo pi, pi_tmp;
-	int sinlen;
-	int optlen;
+	socklen_t optlen;
 
 	s_snd = getsock(tname, 0, IPV6_ADDR_GLOBAL);
-	if (s_snd < 0) {
-		tst_resm(TBROK, "%s: can't create send socket", tname);
-		return;
-	}
+
 	/* global-scope address, interface X */
 	sa_rcv[0].sin6_scope_id = 0;
-	s_rcv[0] = getsock(tname, &sa_rcv[0], IPV6_ADDR_GLOBAL);
-	if (s_rcv[0] == -1) {
-		tst_resm(TBROK, "%s: only link-scope addresses", tname);
-		return;
-	}
+	getsock(tname, &sa_rcv[0], IPV6_ADDR_GLOBAL);
+
 	/* link-local-scope address, interface X */
 	sa_rcv[1].sin6_scope_id = sa_rcv[0].sin6_scope_id;
-	s_rcv[1] = getsock(tname, &sa_rcv[1], IPV6_ADDR_LINK);
-	if (s_rcv[1] < 0) {
-		tst_resm(TBROK, "%s: no link-local address on ifindex %d",
-			 tname, sa_rcv[0].sin6_scope_id);
-		return;
-	}
+
+	getsock(tname, &sa_rcv[1], IPV6_ADDR_LINK);
 	/* link-local-scope address, interface Y */
 	sa_rcv[2].sin6_scope_id = -sa_rcv[0].sin6_scope_id;
-	s_rcv[2] = getsock(tname, &sa_rcv[2], IPV6_ADDR_LINK);
-	if (s_rcv[2] < 0) {
-		tst_resm(TBROK, "%s: only one interface?", tname);
-		return;
-	}
+	getsock(tname, &sa_rcv[2], IPV6_ADDR_LINK);
 	/* send to rcv1 to verify communication */
 	/* force to rcv2 w/ PKTINFO */
 /* TESTS: */
@@ -615,8 +538,8 @@ void test_pktinfo(void)
 				   sizeof(strbuf2)), pi.ipi6_ifindex);
 	} else
 		tst_resm(TPASS, "%s", tname);
-/* ancillary data override */
-/* link-local, wrong interface */
+	/* ancillary data override */
+	/* link-local, wrong interface */
 	tname = "IPV6_PKTINFO invalid {lladdr, intf}";
 	pi.ipi6_addr = sa_rcv[1].sin6_addr;
 	pi.ipi6_ifindex = sa_rcv[2].sin6_scope_id;
@@ -628,17 +551,12 @@ void test_pktinfo(void)
 		tst_resm(TFAIL, "%s errno %d != %d", tname, TEST_ERRNO, EINVAL);
 	else
 		tst_resm(TPASS, "%s", tname);
-/* nonexistent interface */
-/* non-local address */
-/* clear address */
-/* clear interface */
-/* sendmsg() sin6_scope differs with ancillary data interface */
 }
 #endif /* notyet */
 
-void do_tests(void)
+static void do_tests(void)
 {
-	int i;
+	unsigned int i;
 
 	for (i = 0; i < SOCOUNT; ++i) {
 		sotab[i].so_clrval.sou_bool = 0;
@@ -650,11 +568,7 @@ void do_tests(void)
 #endif /* notyet - see test_pktinfo() comment above */
 }
 
-void setup(void)
-{
-	TEST_PAUSE;		/* if -P option specified */
-}
-
-void cleanup(void)
+static void setup(void)
 {
+	TEST_PAUSE;
 }
-- 
1.9.3


------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v3 6/7] lib6/getaddrinfo_01.c: Cleanup
  2015-06-16 12:24                 ` [LTP] [PATCH v3 1/7] SAFE_MACROS: Add socket(), bind(), listen(), connect() and getsockname() Zeng Linggang
                                     ` (3 preceding siblings ...)
  2015-06-16 12:24                   ` [LTP] [PATCH v3 5/7] lib6/asapi_06.c: Cleanup Zeng Linggang
@ 2015-06-16 12:24                   ` Zeng Linggang
  2015-06-16 12:24                   ` [LTP] [PATCH v3 7/7] ipv6_lib: Add it into default Zeng Linggang
  2015-06-19 14:34                   ` [LTP] [PATCH v3 1/7] SAFE_MACROS: Add socket(), bind(), listen(), connect() and getsockname() Alexey Kodanev
  6 siblings, 0 replies; 55+ messages in thread
From: Zeng Linggang @ 2015-06-16 12:24 UTC (permalink / raw)
  To: alexey.kodanev; +Cc: ltp-list

* Add 'static' before some functions and global variables.
* Remove cleanup() function.
* Remove useless comments.
* In every test function, using TINFO instead of TPASS
  marks the success of each inner test.
* Some cleanup.

Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
 testcases/network/lib6/getaddrinfo_01.c | 503 ++++++++++++++++++--------------
 1 file changed, 281 insertions(+), 222 deletions(-)

diff --git a/testcases/network/lib6/getaddrinfo_01.c b/testcases/network/lib6/getaddrinfo_01.c
index ec29b5d..a812e77 100644
--- a/testcases/network/lib6/getaddrinfo_01.c
+++ b/testcases/network/lib6/getaddrinfo_01.c
@@ -1,43 +1,21 @@
 /*
+ * Copyright (c) 2015 Fujitsu Ltd.
+ * Copyright (c) International Business Machines  Corp., 2001
  *
- *   Copyright (c) International Business Machines  Corp., 2001
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
  *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
  *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/*
- * Test Name: getaddrinfo_01
- *
- * Test Description:
- *  Tests for getaddrinfo library function
- *
- * Usage:  <for command-line>
- *  getaddrinfo_01 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -e   : Turn on errno logging.
- *	       -i n : Execute test n times.
- *	       -I x : Execute test for x seconds.
- *	       -P x : Pause for x seconds between iterations.
- *	       -t   : Turn on syscall timing.
- *
- * HISTORY
- *	07/2004 written by David L Stevens
- *
- * RESTRICTIONS:
- *  None.
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
+ * Author: David L Stevens
  */
 
 #include <unistd.h>
@@ -53,40 +31,38 @@
 #define AI_V4MAPPED    0x0008	/* IPv4 mapped addresses are acceptable.  */
 #endif
 
-char *TCID = "getaddrinfo_01";	/* Test program identifier.    */
-int testno;
+static void setup(void);
+static void gaiv4(void);
+static void gaiv6(void);
 
-void setup(void), cleanup(void);
-
-int TST_TOTAL = 1;
-
-/* a host that isn't where LTP is running */
-#define REMOTEHOSTNAME	"www.ibm.com"
-
-void gaiv4(void), gaiv6(void);
-void dumpres(struct addrinfo *);
+char *TCID = "getaddrinfo_01";
+int TST_TOTAL = 2;
 
 int main(int argc, char *argv[])
 {
 	int lc;
 
-	/* Parse standard options given to run the test. */
 	tst_parse_opts(argc, argv, NULL, NULL);
 
 	setup();
 
 	for (lc = 0; TEST_LOOPING(lc); ++lc) {
+		tst_count = 0;
+
 		gaiv4();
 		gaiv6();
 	}
-	cleanup();
 
-	return (0);
+	tst_exit();
 }
 
-/* getaddrinfo tests (v4) */
+static void setup(void)
+{
+	TEST_PAUSE;
+}
 
-void gaiv4(void)
+/* getaddrinfo tests (v4) */
+static void gaiv4(void)
 {
 	struct addrinfo *aires, hints, *pai;
 	char hostname[MAXHOSTNAMELEN + 1];
@@ -132,13 +108,18 @@ void gaiv4(void)
 				 psin ? psin->sin_family : 0,
 				 psin ? psin->sin_port : 0,
 				 psin ? htons(psin->sin_port) : 0);
-		} else
-			tst_resm(TPASS, "getaddrinfo IPv4 basic lookup");
-		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN ? TFAIL : TPASS, "getaddrinfo IPv4 basic "
+			freeaddrinfo(aires);
+			return;
+		} else {
+			tst_resm(TINFO, "getaddrinfo IPv4 basic lookup");
+			freeaddrinfo(aires);
+		}
+	} else {
+		tst_resm(TFAIL, "getaddrinfo IPv4 basic "
 			 "lookup (\"%s\") returns %ld (\"%s\")", hostname,
 			 TEST_RETURN, gai_strerror(TEST_RETURN));
+		return;
+	}
 
 	/* test 2, IPv4 canonical name */
 	memset(&hints, 0, sizeof(hints));
@@ -152,20 +133,26 @@ void gaiv4(void)
 		if (!pai) {
 			tst_resm(TFAIL, "getaddrinfo IPv4 canonical name: no "
 				 "entries with canonical name set");
+			freeaddrinfo(aires);
+			return;
 		} else if (strcasecmp(hostname, pai->ai_canonname)) {
 			tst_resm(TFAIL, "getaddrinfo IPv4 canonical name "
 				 "(\"%s\") doesn't match hostname (\"%s\")",
 				 pai->ai_canonname, hostname);
-		} else
-			tst_resm(TPASS, "getaddrinfo IPv4 canonical name");
-		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN ? TFAIL : TPASS, "getaddrinfo IPv4 "
+			freeaddrinfo(aires);
+			return;
+		} else {
+			tst_resm(TINFO, "getaddrinfo IPv4 canonical name");
+			freeaddrinfo(aires);
+		}
+	} else {
+		tst_resm(TFAIL, "getaddrinfo IPv4 "
 			 "canonical name (\"%s\") returns %ld (\"%s\")",
 			 shortname, TEST_RETURN, gai_strerror(TEST_RETURN));
+		return;
+	}
 
 	/* test 3, IPv4 host+service name */
-
 	memset(&hints, 0, sizeof(hints));
 	/*
 	 * These are hard-coded for echo/7 to avoid using getservbyname(),
@@ -200,13 +187,18 @@ void gaiv4(void)
 				 psin ? psin->sin_family : 0,
 				 psin ? psin->sin_port : 0,
 				 psin ? htons(psin->sin_port) : 0);
-		} else
-			tst_resm(TPASS, "getaddrinfo IPv4 host+service");
-		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN ? TFAIL : TPASS, "getaddrinfo IPv4 host+"
+			freeaddrinfo(aires);
+			return;
+		} else {
+			tst_resm(TINFO, "getaddrinfo IPv4 host+service");
+			freeaddrinfo(aires);
+		}
+	} else {
+		tst_resm(TFAIL, "getaddrinfo IPv4 host+"
 			 "service returns %ld (\"%s\")", TEST_RETURN,
 			 gai_strerror(TEST_RETURN));
+		return;
+	}
 
 	/* test 4, IPv4 hostname+service, AI_PASSIVE */
 	memset(&hints, 0, sizeof(hints));
@@ -244,18 +236,22 @@ void gaiv4(void)
 				 psin ? psin->sin_family : 0,
 				 psin ? psin->sin_port : 0,
 				 psin ? htons(psin->sin_port) : 0);
-		} else
-			tst_resm(TPASS,
+			freeaddrinfo(aires);
+			return;
+		} else {
+			tst_resm(TINFO,
 				 "getaddrinfo IPv4 host+service PASSIVE");
-		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN ? TFAIL : TPASS, "getaddrinfo IPv4 host+"
+			freeaddrinfo(aires);
+		}
+	} else {
+		tst_resm(TFAIL, "getaddrinfo IPv4 host+"
 			 "service, PASSIVE (\"%s\", \"%s\") returns %ld (\"%s\")",
 			 hostname, service, TEST_RETURN,
 			 gai_strerror(TEST_RETURN));
+		return;
+	}
 
 	/* test 5, IPv4 host+service w/ AI_NUMERICHOST */
-
 	memset(&hints, 0, sizeof(hints));
 	strcpy(service, "echo");
 	servnum = 7;
@@ -266,8 +262,11 @@ void gaiv4(void)
 		tst_resm(TFAIL, "getaddrinfo IPv4 AI_NUMERICHOST w/ hostname: "
 			 "returns %ld expected %d (EAI_NONAME)",
 			 TEST_RETURN, EAI_NONAME);
+		if (!TEST_RETURN)
+			freeaddrinfo(aires);
+		return;
 	} else
-		tst_resm(TPASS, "getaddrinfo IPv4 AI_NUMERICHOST w/ hostname");
+		tst_resm(TINFO, "getaddrinfo IPv4 AI_NUMERICHOST w/ hostname");
 	if (!TEST_RETURN)
 		freeaddrinfo(aires);
 
@@ -306,17 +305,28 @@ void gaiv4(void)
 				 psin ? psin->sin_family : 0,
 				 psin ? psin->sin_port : 0,
 				 psin ? htons(psin->sin_port) : 0);
-		} else
-			tst_resm(TPASS, "getaddrinfo IPv4 0+service, PASSIVE");
-		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN == EAI_BADFLAGS ? TPASS : TFAIL,
-			 "getaddrinfo IPv4 0+service, PASSIVE (\"\", \"%s\") "
-			 "returns %ld (\"%s\")", service, TEST_RETURN,
-			 gai_strerror(TEST_RETURN));
+			freeaddrinfo(aires);
+			return;
+		} else {
+			tst_resm(TINFO, "getaddrinfo IPv4 0+service, PASSIVE");
+			freeaddrinfo(aires);
+		}
+	} else {
+		if (TEST_RETURN == EAI_BADFLAGS) {
+			tst_resm(TINFO, "getaddrinfo IPv4 0+service,"
+				" PASSIVE (\"\", \"%s\") returns %ld (\"%s\")",
+				service, TEST_RETURN,
+				gai_strerror(TEST_RETURN));
+		} else {
+			tst_resm(TFAIL, "getaddrinfo IPv4 0+service,i"
+				" PASSIVE (\"\", \"%s\") returns %ld (\"%s\")",
+				service, TEST_RETURN,
+				gai_strerror(TEST_RETURN));
+			return;
+		}
+	}
 
 	/* test 7, IPv4 0+service */
-
 	memset(&hints, 0, sizeof(hints));
 	hints.ai_family = AF_INET;
 	hints.ai_socktype = SOCK_STREAM;
@@ -350,19 +360,30 @@ void gaiv4(void)
 				 psin ? psin->sin_family : 0,
 				 psin ? psin->sin_port : 0,
 				 psin ? htons(psin->sin_port) : 0);
-		} else
-			tst_resm(TPASS, "getaddrinfo IPv4 0+service");
-		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN == EAI_BADFLAGS ? TPASS : TFAIL,
-			 "getaddrinfo IPv4 0+service (\"\", \"%s\") returns %ld "
-			 "(\"%s\")", service, TEST_RETURN,
-			 gai_strerror(TEST_RETURN));
+			freeaddrinfo(aires);
+			return;
+		} else {
+			tst_resm(TINFO, "getaddrinfo IPv4 0+service");
+			freeaddrinfo(aires);
+		}
+	} else {
+		if (TEST_RETURN == EAI_BADFLAGS) {
+			tst_resm(TINFO, "getaddrinfo IPv4 "
+				"0+service (\"\", \"%s\") returns %ld (\"%s\")",
+				service, TEST_RETURN,
+				gai_strerror(TEST_RETURN));
+		} else {
+			tst_resm(TFAIL, "getaddrinfo IPv4 "
+				"0+service (\"\", \"%s\") returns %ld (\"%s\")",
+				service, TEST_RETURN,
+				gai_strerror(TEST_RETURN));
+			return;
+		}
+	}
 
 	/* test 8, IPv4 host+service, AI_NUMERICSERV */
-
 #ifndef AI_NUMERICSERV
-	tst_resm(TFAIL, "getaddrinfo IPv4 host+service, AI_NUMERICSERV: flag "
+	tst_resm(TCONF, "getaddrinfo IPv4 host+service, AI_NUMERICSERV: flag "
 		 "not implemented");
 #else
 	memset(&hints, 0, sizeof(hints));
@@ -376,15 +397,18 @@ void gaiv4(void)
 			 "getaddrinfo IPv4 host+service, AI_NUMERICSERV: "
 			 "returns %ld (\"%s\") expected %d (EAI_NONAME)",
 			 TEST_RETURN, gai_strerror(TEST_RETURN), EAI_NONAME);
-	} else
-		tst_resm(TPASS,
+		if (!TEST_RETURN)
+			freeaddrinfo(aires);
+		return;
+	} else {
+		tst_resm(TINFO,
 			 "getaddrinfo IPv4 host+service, AI_NUMERICSERV");
+	}
 	if (!TEST_RETURN)
 		freeaddrinfo(aires);
 #endif /* AI_NUMERICSERV */
 
 	/* test 9, IPv4 SOCK_STREAM/IPPROTO_UDP hints */
-
 	memset(&hints, 0, sizeof(hints));
 	hints.ai_family = AF_INET;
 	hints.ai_socktype = SOCK_STREAM;
@@ -396,12 +420,13 @@ void gaiv4(void)
 		tst_resm(TFAIL, "getaddrinfo IPv4 SOCK_STREAM/IPPROTO_UDP "
 			 "hints");
 		freeaddrinfo(aires);
-	} else
-		tst_resm(TPASS, "getaddrinfo IPv4 SOCK_STREAM/IPPROTO_UDP "
+		return;
+	} else {
+		tst_resm(TINFO, "getaddrinfo IPv4 SOCK_STREAM/IPPROTO_UDP "
 			 "hints");
+	}
 
 	/* test 10, IPv4 socktype 0, 513 */
-
 	memset(&hints, 0, sizeof(hints));
 	hints.ai_family = AF_INET;
 	hints.ai_socktype = 0;
@@ -439,20 +464,31 @@ void gaiv4(void)
 				 psin ? psin->sin_family : 0,
 				 psin ? psin->sin_port : 0,
 				 psin ? htons(psin->sin_port) : 0);
-		} else if (got_tcp && got_udp)
-			tst_resm(TPASS, "getaddrinfo IPv4 socktype 0,513");
-		else
+			freeaddrinfo(aires);
+			return;
+		} else if (got_tcp && got_udp) {
+			tst_resm(TINFO, "getaddrinfo IPv4 socktype 0,513");
+			freeaddrinfo(aires);
+		} else {
 			tst_resm(TFAIL, "getaddrinfo IPv4 socktype 0,513 TCP %d"
 				 " UDP %d", got_tcp, got_udp);
-		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN == EAI_BADFLAGS ? TPASS : TFAIL,
-			 "getaddrinfo IPv4 socktype 0,513 (\"\", \"%s\") returns"
-			 " %ld (\"%s\")", service, TEST_RETURN,
-			 gai_strerror(TEST_RETURN));
+			freeaddrinfo(aires);
+			return;
+		}
+	} else {
+		if (TEST_RETURN == EAI_BADFLAGS) {
+			tst_resm(TINFO, "getaddrinfo IPv4 socktype 0,513"
+				" (\"\", \"%s\") returns %ld (\"%s\")", service,
+				TEST_RETURN, gai_strerror(TEST_RETURN));
+		} else {
+			tst_resm(TFAIL, "getaddrinfo IPv4 socktype 0,513"
+				" (\"\", \"%s\") returns %ld (\"%s\")", service,
+				TEST_RETURN, gai_strerror(TEST_RETURN));
+			return;
+		}
+	}
 
 	/* test 11, IPv4 AI_V4MAPPED */
-
 	/* AI_V4MAPPED should be ignored because family != AF_INET6 */
 	memset(&hints, 0, sizeof(hints));
 	hints.ai_family = AF_INET;
@@ -482,18 +518,25 @@ void gaiv4(void)
 				 psin ? psin->sin_family : 0,
 				 psin ? psin->sin_port : 0,
 				 psin ? htons(psin->sin_port) : 0);
-		} else
-			tst_resm(TPASS, "getaddrinfo IPv4 AI_V4MAPPED");
-		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN ? TFAIL : TPASS, "getaddrinfo IPv4 "
+			freeaddrinfo(aires);
+			return;
+		} else {
+			tst_resm(TINFO, "getaddrinfo IPv4 AI_V4MAPPED");
+			freeaddrinfo(aires);
+		}
+	} else {
+		tst_resm(TFAIL, "getaddrinfo IPv4 "
 			 "AI_V4MAPPED (\"%s\") returns %ld (\"%s\")", hostname,
 			 TEST_RETURN, gai_strerror(TEST_RETURN));
+		return;
+	}
+
+
+	tst_resm(TPASS, "getaddrinfo tests (v4) succeed");
 }
 
 /* getaddrinfo tests (v6) */
-
-void gaiv6(void)
+static void gaiv6(void)
 {
 	struct addrinfo *aires, hints, *pai;
 	char hostname[MAXHOSTNAMELEN + 1];
@@ -539,13 +582,18 @@ void gaiv6(void)
 				 psin6 ? psin6->sin6_family : 0,
 				 psin6 ? psin6->sin6_port : 0,
 				 psin6 ? htons(psin6->sin6_port) : 0);
-		} else
-			tst_resm(TPASS, "getaddrinfo IPv6 basic lookup");
-		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN ? TFAIL : TPASS, "getaddrinfo IPv6 basic "
+			freeaddrinfo(aires);
+			return;
+		} else {
+			tst_resm(TINFO, "getaddrinfo IPv6 basic lookup");
+			freeaddrinfo(aires);
+		}
+	} else {
+		tst_resm(TFAIL, "getaddrinfo IPv6 basic "
 			 "lookup (\"%s\") returns %ld (\"%s\")", hostname,
 			 TEST_RETURN, gai_strerror(TEST_RETURN));
+		return;
+	}
 
 	/* test 13, IPv6 canonical name */
 	memset(&hints, 0, sizeof(hints));
@@ -559,20 +607,26 @@ void gaiv6(void)
 		if (!pai) {
 			tst_resm(TFAIL, "getaddrinfo IPv6 canonical name: no "
 				 "entries with canonical name set");
+			freeaddrinfo(aires);
+			return;
 		} else if (strcasecmp(hostname, pai->ai_canonname)) {
 			tst_resm(TFAIL, "getaddrinfo IPv6 canonical name "
 				 "(\"%s\") doesn't match hostname (\"%s\")",
 				 pai->ai_canonname, hostname);
-		} else
-			tst_resm(TPASS, "getaddrinfo IPv6 canonical name");
-		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN ? TFAIL : TPASS, "getaddrinfo IPv6 "
+			freeaddrinfo(aires);
+			return;
+		} else {
+			tst_resm(TINFO, "getaddrinfo IPv6 canonical name");
+			freeaddrinfo(aires);
+		}
+	} else {
+		tst_resm(TFAIL, "getaddrinfo IPv6 "
 			 "canonical name (\"%s\") returns %ld (\"%s\")",
 			 shortname, TEST_RETURN, gai_strerror(TEST_RETURN));
+		return;
+	}
 
 	/* test 14, IPv6 host+service name */
-
 	memset(&hints, 0, sizeof(hints));
 	/*
 	 * These are hard-coded for echo/7 to avoid using getservbyname(),
@@ -607,13 +661,18 @@ void gaiv6(void)
 				 psin6 ? psin6->sin6_family : 0,
 				 psin6 ? psin6->sin6_port : 0,
 				 psin6 ? htons(psin6->sin6_port) : 0);
-		} else
-			tst_resm(TPASS, "getaddrinfo IPv6 host+service");
-		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN ? TFAIL : TPASS, "getaddrinfo IPv6 host+"
+			freeaddrinfo(aires);
+			return;
+		} else {
+			tst_resm(TINFO, "getaddrinfo IPv6 host+service");
+			freeaddrinfo(aires);
+		}
+	} else {
+		tst_resm(TFAIL, "getaddrinfo IPv6 host+"
 			 "service returns %ld (\"%s\")", TEST_RETURN,
 			 gai_strerror(TEST_RETURN));
+		return;
+	}
 
 	/* test 15, IPv6 hostname+service, AI_PASSIVE */
 	memset(&hints, 0, sizeof(hints));
@@ -652,18 +711,22 @@ void gaiv6(void)
 				 psin6 ? psin6->sin6_family : 0,
 				 psin6 ? psin6->sin6_port : 0,
 				 psin6 ? htons(psin6->sin6_port) : 0);
-		} else
-			tst_resm(TPASS,
+			freeaddrinfo(aires);
+			return;
+		} else {
+			tst_resm(TINFO,
 				 "getaddrinfo IPv6 host+service PASSIVE");
-		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN ? TFAIL : TPASS, "getaddrinfo IPv6 host+"
+			freeaddrinfo(aires);
+		}
+	} else {
+		tst_resm(TFAIL, "getaddrinfo IPv6 host+"
 			 "service, PASSIVE (\"%s\", \"%s\") returns %ld (\"%s\")",
 			 hostname, service, TEST_RETURN,
 			 gai_strerror(TEST_RETURN));
+		return;
+	}
 
 	/* test 16, IPv6 host+service w/ AI_NUMERICHOST */
-
 	memset(&hints, 0, sizeof(hints));
 	strcpy(service, "echo");
 	servnum = 7;
@@ -674,8 +737,11 @@ void gaiv6(void)
 		tst_resm(TFAIL, "getaddrinfo IPv6 AI_NUMERICHOST w/ hostname: "
 			 "returns %ld expected %d (EAI_NONAME)",
 			 TEST_RETURN, EAI_NONAME);
+		if (!TEST_RETURN)
+			freeaddrinfo(aires);
+		return;
 	} else
-		tst_resm(TPASS, "getaddrinfo IPv6 AI_NUMERICHOST w/ hostname");
+		tst_resm(TINFO, "getaddrinfo IPv6 AI_NUMERICHOST w/ hostname");
 	if (!TEST_RETURN)
 		freeaddrinfo(aires);
 
@@ -715,17 +781,26 @@ void gaiv6(void)
 				 psin6 ? psin6->sin6_family : 0,
 				 psin6 ? psin6->sin6_port : 0,
 				 psin6 ? htons(psin6->sin6_port) : 0);
-		} else
-			tst_resm(TPASS, "getaddrinfo IPv6 0+service, PASSIVE");
-		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN == EAI_BADFLAGS ? TPASS : TFAIL,
-			 "getaddrinfo IPv6 0+service, PASSIVE (\"\", \"%s\") "
-			 "returns %ld (\"%s\")", service, TEST_RETURN,
-			 gai_strerror(TEST_RETURN));
+			freeaddrinfo(aires);
+			return;
+		} else {
+			tst_resm(TINFO, "getaddrinfo IPv6 0+service, PASSIVE");
+			freeaddrinfo(aires);
+		}
+	} else {
+		if (TEST_RETURN == EAI_BADFLAGS) {
+			tst_resm(TINFO, "getaddrinfo IPv6 0+service, PASSIVE"
+				" (\"\", \"%s\") returns %ld (\"%s\")", service,
+				TEST_RETURN, gai_strerror(TEST_RETURN));
+		} else {
+			tst_resm(TFAIL, "getaddrinfo IPv6 0+service, PASSIVE"
+				" (\"\", \"%s\") returns %ld (\"%s\")", service,
+				TEST_RETURN, gai_strerror(TEST_RETURN));
+			return;
+		}
+	}
 
 	/* test 18, IPv6 0+service */
-
 	memset(&hints, 0, sizeof(hints));
 	hints.ai_family = AF_INET6;
 	hints.ai_socktype = SOCK_STREAM;
@@ -760,19 +835,28 @@ void gaiv6(void)
 				 psin6 ? psin6->sin6_family : 0,
 				 psin6 ? psin6->sin6_port : 0,
 				 psin6 ? htons(psin6->sin6_port) : 0);
-		} else
-			tst_resm(TPASS, "getaddrinfo IPv6 0+service");
-		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN == EAI_BADFLAGS ? TPASS : TFAIL,
-			 "getaddrinfo IPv6 0+service (\"\", \"%s\") returns %ld "
-			 "(\"%s\")", service, TEST_RETURN,
-			 gai_strerror(TEST_RETURN));
+			freeaddrinfo(aires);
+			return;
+		} else {
+			tst_resm(TINFO, "getaddrinfo IPv6 0+service");
+			freeaddrinfo(aires);
+		}
+	} else {
+		if (TEST_RETURN == EAI_BADFLAGS) {
+			tst_resm(TINFO, "getaddrinfo IPv6 0+service"
+				" (\"\", \"%s\") returns %ld (\"%s\")", service,
+				TEST_RETURN, gai_strerror(TEST_RETURN));
+		} else {
+			tst_resm(TFAIL, "getaddrinfo IPv6 0+service"
+				" (\"\", \"%s\") returns %ld (\"%s\")", service,
+				TEST_RETURN, gai_strerror(TEST_RETURN));
+			return;
+		}
+	}
 
 	/* test 19, IPv6 host+service, AI_NUMERICSERV */
-
 #ifndef AI_NUMERICSERV
-	tst_resm(TFAIL, "getaddrinfo IPv6 host+service, AI_NUMERICSERV: flag "
+	tst_resm(TCONF, "getaddrinfo IPv6 host+service, AI_NUMERICSERV: flag "
 		 "not implemented");
 #else
 	memset(&hints, 0, sizeof(hints));
@@ -786,15 +870,17 @@ void gaiv6(void)
 			 "getaddrinfo IPv6 host+service, AI_NUMERICSERV: "
 			 "returns %ld (\"%s\") expected %d (EAI_NONAME)",
 			 TEST_RETURN, gai_strerror(TEST_RETURN), EAI_NONAME);
+		if (!TEST_RETURN)
+			freeaddrinfo(aires);
+		return;
 	} else
-		tst_resm(TPASS,
+		tst_resm(TINFO,
 			 "getaddrinfo IPv6 host+service, AI_NUMERICSERV");
 	if (!TEST_RETURN)
 		freeaddrinfo(aires);
 #endif /* AI_NUMERICSERV */
 
 	/* test 20, IPv6 SOCK_STREAM/IPPROTO_UDP hints */
-
 	memset(&hints, 0, sizeof(hints));
 	hints.ai_family = AF_INET6;
 	hints.ai_socktype = SOCK_STREAM;
@@ -806,12 +892,13 @@ void gaiv6(void)
 		tst_resm(TFAIL, "getaddrinfo IPv6 SOCK_STREAM/IPPROTO_UDP "
 			 "hints");
 		freeaddrinfo(aires);
-	} else
-		tst_resm(TPASS, "getaddrinfo IPv6 SOCK_STREAM/IPPROTO_UDP "
+		return;
+	} else {
+		tst_resm(TINFO, "getaddrinfo IPv6 SOCK_STREAM/IPPROTO_UDP "
 			 "hints");
+	}
 
 	/* test 21, IPv6 socktype 0, 513 */
-
 	memset(&hints, 0, sizeof(hints));
 	hints.ai_family = AF_INET6;
 	hints.ai_socktype = 0;
@@ -850,20 +937,31 @@ void gaiv6(void)
 				 psin6 ? psin6->sin6_family : 0,
 				 psin6 ? psin6->sin6_port : 0,
 				 psin6 ? htons(psin6->sin6_port) : 0);
-		} else if (got_tcp && got_udp)
-			tst_resm(TPASS, "getaddrinfo IPv6 socktype 0,513");
-		else
+			freeaddrinfo(aires);
+			return;
+		} else if (got_tcp && got_udp) {
+			tst_resm(TINFO, "getaddrinfo IPv6 socktype 0,513");
+			freeaddrinfo(aires);
+		} else {
 			tst_resm(TFAIL, "getaddrinfo IPv6 socktype 0,513 TCP %d"
 				 " UDP %d", got_tcp, got_udp);
-		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN == EAI_BADFLAGS ? TPASS : TFAIL,
-			 "getaddrinfo IPv6 socktype 0,513 (\"\", \"%s\") returns"
-			 " %ld (\"%s\")", service, TEST_RETURN,
-			 gai_strerror(TEST_RETURN));
+			freeaddrinfo(aires);
+			return;
+		}
+	} else {
+		if (TEST_RETURN == EAI_BADFLAGS) {
+			tst_resm(TINFO, "getaddrinfo IPv6 socktype 0,513"
+				" (\"\", \"%s\") returns %ld (\"%s\")", service,
+				TEST_RETURN, gai_strerror(TEST_RETURN));
+		} else {
+			tst_resm(TFAIL, "getaddrinfo IPv6 socktype 0,513"
+				" (\"\", \"%s\") returns %ld (\"%s\")", service,
+				TEST_RETURN, gai_strerror(TEST_RETURN));
+			return;
+		}
+	}
 
 	/* test 22, IPv6 AI_V4MAPPED */
-
 	memset(&hints, 0, sizeof(hints));
 	hints.ai_family = AF_INET6;
 	hints.ai_flags = AI_V4MAPPED;
@@ -892,57 +990,18 @@ void gaiv6(void)
 				 psin6 ? psin6->sin6_family : 0,
 				 psin6 ? psin6->sin6_port : 0,
 				 psin6 ? htons(psin6->sin6_port) : 0);
-		} else
-			tst_resm(TPASS, "getaddrinfo IPv6 AI_V4MAPPED");
-		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN ? TFAIL : TPASS, "getaddrinfo IPv6 "
+			freeaddrinfo(aires);
+			return;
+		} else {
+			tst_resm(TINFO, "getaddrinfo IPv6 AI_V4MAPPED");
+			freeaddrinfo(aires);
+		}
+	} else {
+		tst_resm(TFAIL, "getaddrinfo IPv6 "
 			 "AI_V4MAPPED (\"%s\") returns %ld (\"%s\")", hostname,
 			 TEST_RETURN, gai_strerror(TEST_RETURN));
-}
-
-/* this prints an addrinfo list; useful for debugging */
-void dumpres(struct addrinfo *pai)
-{
-	int count = 1;
-	for (; pai; pai = pai->ai_next, count++) {
-		printf("result %d [0x%p]\n", count, pai);
-		printf("\tai_flags %x\n", pai->ai_flags);
-		printf("\tai_family %d\n", pai->ai_family);
-		printf("\tai_socktype %d\n", pai->ai_socktype);
-		printf("\tai_protocol %d\n", pai->ai_protocol);
-		printf("\tai_addrlen %d\n", pai->ai_addrlen);
-		printf("\tai_canonname \"%s\"\n", pai->ai_canonname);
-		printf("\tai_addr.sa_family %x\n", pai->ai_addr->sa_family);
-		if (pai->ai_addr->sa_family == AF_INET) {
-			char buf[1024];
-			struct sockaddr_in *psin =
-			    (struct sockaddr_in *)pai->ai_addr;
-
-			if (!inet_ntop(AF_INET, &psin->sin_addr, buf,
-				       sizeof(buf)))
-				buf[0] = '\0';
-			printf("\tai_addr.sin_addr \"%s\"\n", buf);
-		} else if (pai->ai_addr->sa_family == AF_INET6) {
-			char buf[1024];
-
-			struct sockaddr_in6 *psin6 =
-			    (struct sockaddr_in6 *)pai->ai_addr;
-			if (!inet_ntop(AF_INET6, &psin6->sin6_addr, buf,
-				       sizeof(buf)))
-				buf[0] = '\0';
-			printf("\tai_addr.sin6_addr \"%s\"\n", buf);
-
-		}
-		printf("\tai_next %p\n", pai->ai_next);
+		return;
 	}
-}
 
-void setup(void)
-{
-	TEST_PAUSE;		/* if -P option specified */
-}
-
-void cleanup(void)
-{
+	tst_resm(TPASS, "getaddrinfo tests (v6) succeed");
 }
-- 
1.9.3


------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v3 7/7] ipv6_lib: Add it into default
  2015-06-16 12:24                 ` [LTP] [PATCH v3 1/7] SAFE_MACROS: Add socket(), bind(), listen(), connect() and getsockname() Zeng Linggang
                                     ` (4 preceding siblings ...)
  2015-06-16 12:24                   ` [LTP] [PATCH v3 6/7] lib6/getaddrinfo_01.c: Cleanup Zeng Linggang
@ 2015-06-16 12:24                   ` Zeng Linggang
  2015-06-19 14:34                   ` [LTP] [PATCH v3 1/7] SAFE_MACROS: Add socket(), bind(), listen(), connect() and getsockname() Alexey Kodanev
  6 siblings, 0 replies; 55+ messages in thread
From: Zeng Linggang @ 2015-06-16 12:24 UTC (permalink / raw)
  To: alexey.kodanev; +Cc: ltp-list

Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
 scenario_groups/default | 1 +
 1 file changed, 1 insertion(+)

diff --git a/scenario_groups/default b/scenario_groups/default
index 3a55702..60b1b27 100644
--- a/scenario_groups/default
+++ b/scenario_groups/default
@@ -32,3 +32,4 @@ dma_thread_diotest
 cpuacct
 can
 cpuhotplug
+ipv6_lib
-- 
1.9.3


------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 55+ messages in thread

* Re: [LTP] [PATCH v3 1/7] SAFE_MACROS: Add socket(), bind(), listen(), connect() and getsockname()
  2015-06-16 12:24                 ` [LTP] [PATCH v3 1/7] SAFE_MACROS: Add socket(), bind(), listen(), connect() and getsockname() Zeng Linggang
                                     ` (5 preceding siblings ...)
  2015-06-16 12:24                   ` [LTP] [PATCH v3 7/7] ipv6_lib: Add it into default Zeng Linggang
@ 2015-06-19 14:34                   ` Alexey Kodanev
  2015-07-09  3:05                     ` [LTP] [PATCH v4 01/11] " Zeng Linggang
  6 siblings, 1 reply; 55+ messages in thread
From: Alexey Kodanev @ 2015-06-19 14:34 UTC (permalink / raw)
  To: Zeng Linggang; +Cc: ltp-list

Hi!
On 06/16/2015 03:24 PM, Zeng Linggang wrote:
> Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
> ---
>   include/safe_macros.h | 29 ++++++++++++++++++
>   lib/safe_macros.c     | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++
>   2 files changed, 112 insertions(+)

Good idea.

Please use separate file for socket safe macros, look at how 
safe_stdin.h made.
The name could be safe_sock.h, safe_net.h, etc.


> +
> +int safe_bind(const char *file, const int lineno, void (cleanup_fn)(void),
> +	      int socket, const struct sockaddr *address,
> +	      socklen_t address_len)
> +{
> +	int rval;
> +
> +	rval = bind(socket, address, address_len);
> +
> +	if (rval < 0) {
> +		tst_brkm(TBROK | TERRNO, cleanup_fn,
> +		         "%s:%d: bind(%d, %p, %d) failed", file, lineno, socket,
> +			 address, address_len);
> +	}
> +
> +	return rval;
> +}

bind() can return -1 if address is in use, e.g. it's in time_wait state.

Usually, you should wait (~30 sec or more, it depends on rtt) on it 
until socket address will be available. If timeout exceeded, only then I 
would exit with TBROK. Please check for errno 'EADDRINUSE'.

Thanks,
Alexey


------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [LTP] [PATCH v3 2/7] lib6/runcc.c: Cleanup
  2015-06-16 12:24                   ` [LTP] [PATCH v3 2/7] lib6/runcc.c: Cleanup Zeng Linggang
@ 2015-06-19 16:08                     ` Alexey Kodanev
  0 siblings, 0 replies; 55+ messages in thread
From: Alexey Kodanev @ 2015-06-19 16:08 UTC (permalink / raw)
  To: Zeng Linggang; +Cc: ltp-list


On 06/16/2015 03:24 PM, Zeng Linggang wrote:
>   
> -char *filetmpl = "/tmp/%.*s_XXXXXX";
> +static const char *filetmpl = "/tmp/%.*s_XXXXXX";
>   

Sorry, I missed that one in the previous review, could you use 
tst_tmpdir()? So here should be "%.*s_XXXXX".

There is /tmp/test file that left after the test, it could be fixed if 
we hadn't used absolute path in the patch. I would print it in case of 
test-case failure.

>   
> -int runcc(char *tname, char *filename0, char *program)
> +static int runcc(char *tname, char *filename0, char *program)

If we don't use return value - why it is still "int runcc()"?

Also please change perror() and exit(1) to LTP library functions.

Thanks,
Alexey


------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v4 01/11] SAFE_MACROS: Add socket(), bind(), listen(), connect() and getsockname()
  2015-06-19 14:34                   ` [LTP] [PATCH v3 1/7] SAFE_MACROS: Add socket(), bind(), listen(), connect() and getsockname() Alexey Kodanev
@ 2015-07-09  3:05                     ` Zeng Linggang
  2015-07-09  3:05                       ` [LTP] [PATCH v4 02/11] lib6/runcc.c: Cleanup Zeng Linggang
                                         ` (10 more replies)
  0 siblings, 11 replies; 55+ messages in thread
From: Zeng Linggang @ 2015-07-09  3:05 UTC (permalink / raw)
  To: alexey.kodanev; +Cc: ltp-list

Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
 include/safe_macros.h |   1 +
 include/safe_net.h    |  54 ++++++++++++++++++++++++
 lib/safe_net.c        | 113 ++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 168 insertions(+)
 create mode 100644 include/safe_net.h
 create mode 100644 lib/safe_net.c

diff --git a/include/safe_macros.h b/include/safe_macros.h
index 0e7651d..1a09af6 100644
--- a/include/safe_macros.h
+++ b/include/safe_macros.h
@@ -28,6 +28,7 @@
 #include <dirent.h>
 
 #include "safe_stdio.h"
+#include "safe_net.h"
 
 char*	safe_basename(const char *file, const int lineno,
 	    void (*cleanup_fn)(void), char *path);
diff --git a/include/safe_net.h b/include/safe_net.h
new file mode 100644
index 0000000..2c9ddb6
--- /dev/null
+++ b/include/safe_net.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2015 Fujitsu Ltd.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef __SAFE_NET_H__
+#define __SAFE_NET_H__
+
+#include <sys/types.h>
+#include <sys/socket.h>
+
+int safe_socket(const char *file, const int lineno, void (cleanup_fn)(void),
+		int domain, int type, int protocol);
+#define SAFE_SOCKET(cleanup_fn, domain, type, protocol) \
+	safe_socket(__FILE__, __LINE__, (cleanup_fn), domain, type, protocol)
+
+int safe_bind(const char *file, const int lineno, void (cleanup_fn)(void),
+	      int socket, const struct sockaddr *address,
+	      socklen_t address_len);
+#define SAFE_BIND(cleanup_fn, socket, address, address_len) \
+	safe_bind(__FILE__, __LINE__, (cleanup_fn), socket, address, \
+		  address_len)
+
+int safe_listen(const char *file, const int lineno, void (cleanup_fn)(void),
+		int socket, int backlog);
+#define SAFE_LISTEN(cleanup_fn, socket, backlog) \
+	safe_listen(__FILE__, __LINE__, (cleanup_fn), socket, backlog)
+
+int safe_connect(const char *file, const int lineno, void (cleanup_fn)(void),
+		 int sockfd, const struct sockaddr *addr, socklen_t addrlen);
+#define SAFE_CONNECT(cleanup_fn, sockfd, addr, addrlen) \
+	safe_connect(__FILE__, __LINE__, (cleanup_fn), sockfd, addr, addrlen)
+
+int safe_getsockname(const char *file, const int lineno,
+		     void (cleanup_fn)(void), int sockfd, struct sockaddr *addr,
+		     socklen_t *addrlen);
+#define SAFE_GETSOCKNAME(cleanup_fn, sockfd, addr, addrlen) \
+	safe_getsockname(__FILE__, __LINE__, (cleanup_fn), sockfd, addr, \
+			 addrlen)
+
+#endif /* __SAFE_NET_H__ */
diff --git a/lib/safe_net.c b/lib/safe_net.c
new file mode 100644
index 0000000..85866ac
--- /dev/null
+++ b/lib/safe_net.c
@@ -0,0 +1,113 @@
+/*
+ * Copyright (c) 2015 Fujitsu Ltd.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <errno.h>
+#include "test.h"
+#include "safe_net.h"
+
+int safe_socket(const char *file, const int lineno, void (cleanup_fn)(void),
+		int domain, int type, int protocol)
+{
+	int rval;
+
+	rval = socket(domain, type, protocol);
+
+	if (rval < 0) {
+		tst_brkm(TBROK | TERRNO, cleanup_fn,
+			 "%s:%d: socket(%d, %d, %d) failed", file, lineno,
+			 domain, type, protocol);
+	}
+
+	return rval;
+}
+
+int safe_bind(const char *file, const int lineno, void (cleanup_fn)(void),
+	      int socket, const struct sockaddr *address,
+	      socklen_t address_len)
+{
+	int err, ret, i;
+
+	for (i = 0; i < 30; i++) {
+		ret = bind(socket, address, address_len);
+		err = errno;
+
+		if (!ret)
+			return 0;
+
+		tst_resm(TINFO, "bind('%p') failed with %s, try %2i...",
+			 address, tst_strerrno(err), i+1);
+
+		if (i == 0 && err == EADDRINUSE)
+			tst_resm(TINFO, "The given address is already in use.");
+
+		usleep(100000);
+	}
+
+	tst_brkm(TBROK | TERRNO, cleanup_fn,
+		 "%s:%d: Failed to bind(%d, %p, %d) after 30 retries",
+		 file, lineno, socket, address, address_len);
+}
+
+int safe_listen(const char *file, const int lineno, void (cleanup_fn)(void),
+		int socket, int backlog)
+{
+	int rval;
+
+	rval = listen(socket, backlog);
+
+	if (rval < 0) {
+		tst_brkm(TBROK | TERRNO, cleanup_fn,
+			 "%s:%d: listen(%d, %d) failed", file, lineno, socket,
+			 backlog);
+	}
+
+	return rval;
+}
+
+int safe_connect(const char *file, const int lineno, void (cleanup_fn)(void),
+		 int sockfd, const struct sockaddr *addr, socklen_t addrlen)
+{
+	int rval;
+
+	rval = connect(sockfd, addr, addrlen);
+
+	if (rval < 0) {
+		tst_brkm(TBROK | TERRNO, cleanup_fn,
+			 "%s:%d: connect(%d, %p, %d) failed", file, lineno,
+			 sockfd, addr, addrlen);
+	}
+
+	return rval;
+}
+
+int safe_getsockname(const char *file, const int lineno,
+		     void (cleanup_fn)(void), int sockfd, struct sockaddr *addr,
+		     socklen_t *addrlen)
+{
+	int rval;
+
+	rval = getsockname(sockfd, addr, addrlen);
+
+	if (rval < 0) {
+		tst_brkm(TBROK | TERRNO, cleanup_fn,
+			 "%s:%d: getsockname(%d, %p, %p) failed", file, lineno,
+			 sockfd, addr, addrlen);
+	}
+
+	return rval;
+}
-- 
1.9.3


------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v4 02/11] lib6/runcc.c: Cleanup
  2015-07-09  3:05                     ` [LTP] [PATCH v4 01/11] " Zeng Linggang
@ 2015-07-09  3:05                       ` Zeng Linggang
  2015-07-09  3:05                       ` [LTP] [PATCH v4 03/11] asapi_01: Use 'tst_tmpdir' and more cleanup Zeng Linggang
                                         ` (9 subsequent siblings)
  10 siblings, 0 replies; 55+ messages in thread
From: Zeng Linggang @ 2015-07-09  3:05 UTC (permalink / raw)
  To: alexey.kodanev; +Cc: ltp-list

* Add 'static' before some functions and global variables.

* Not use 'mkstemp', use 'tst_tmpdir and tst_rmdir' in actual test.

* Use 'SAFE_FILE_PRINTF' instead of 'open-write-close'.

* Change 'runcc', 'aliascheck', 'funccheck', 'structcheck' and
  'valuecheck' to non-return because of the ignore return value.

* Use 'MACRO' instead of 'const char *'.

* Some cleanup.

Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
 testcases/network/lib6/runcc.c | 177 ++++++++++++++++-------------------------
 testcases/network/lib6/runcc.h |  52 +++++++-----
 2 files changed, 100 insertions(+), 129 deletions(-)

diff --git a/testcases/network/lib6/runcc.c b/testcases/network/lib6/runcc.c
index 91a0b16..cfc283c 100644
--- a/testcases/network/lib6/runcc.c
+++ b/testcases/network/lib6/runcc.c
@@ -1,31 +1,21 @@
 /*
+ * Copyright (c) 2015 Fujitsu Ltd.
+ * Copyright (c) International Business Machines  Corp., 2001
  *
- *   Copyright (c) International Business Machines  Corp., 2001
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
  *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
  *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/*
- * runcc.a - common functions for lib6 testing
- *
- * HISTORY
- *	05/2005 written by David L Stevens
- *
- * RESTRICTIONS:
- *  None.
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
+ * Author: David L Stevens
  */
 
 #include <stdio.h>
@@ -34,20 +24,23 @@
 #include <ctype.h>
 
 #include <sys/wait.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
 
 #include "test.h"
 
-char fieldref[1024];
-char program[8192];
+static char fieldref[1024];
+static char program[8192];
 
-char *filetmpl = "/tmp/%.*s_XXXXXX";
+#define FILETMPL	"./%.*s"
 
-char cmd[1024];
+static char cmd[1024];
 
 /*
  * like strspn, with ASCII, numbers and underscore only
  */
-int strfpn(char *name)
+static int strfpn(char *name)
 {
 	int i;
 
@@ -57,31 +50,17 @@ int strfpn(char *name)
 	return i;
 }
 
-int runcc(char *tname, char *filename0, char *program)
+static void runcc(char *tname, char *filename0, char *program)
 {
 	static char filename[1024];
-	int fd, es, saved_errno;
+	int es;
 	char *cflags = "";
 
-	fd = mkstemp(filename0);
-	if (fd < 0) {
-		perror("mkstemp");
-		return -1;
-	}
 	strncpy(filename, filename0, sizeof(filename) - 1);
 	filename[sizeof(filename) - 1] = '\0';
 	strncat(filename, ".c", sizeof(filename) - strlen(filename) - 1);
-	if (rename(filename0, filename) < 0) {
-		perror("rename");
-		unlink(filename0);
-		return -1;
-	}
-	if (write(fd, program, strlen(program)) < 0) {
-		perror("write");
-		unlink(filename);
-		return -1;
-	}
-	(void)close(fd);
+
+	SAFE_FILE_PRINTF(NULL, filename, "%s", program);
 
 	cflags = getenv("CFLAGS");
 	if (cflags == NULL) {
@@ -89,19 +68,13 @@ int runcc(char *tname, char *filename0, char *program)
 		cflags = "";
 	}
 
-	snprintf(cmd, sizeof(cmd), "%s %s -o %s %s > /tmp/test 2>&1", "cc",
+	snprintf(cmd, sizeof(cmd), "%s %s -o %s %s > test 2>&1", "cc",
 		 cflags, filename0, filename);
 	es = system(cmd);
 	if (WEXITSTATUS(es) == 127) {
-		tst_resm(TBROK, "can't run C compiler: \"%s\"", cmd);
-		if (unlink(filename) < 0)
-			tst_resm(TWARN, "%s; unlink \"%s\" failed: %s", tname,
-				 filename, strerror(errno));
-		return -1;
+		tst_brkm(TBROK | TERRNO, NULL, "can't run C compiler: \"%s\"",
+			 cmd);
 	}
-	if (unlink(filename) < 0)
-		tst_resm(TWARN, "%s: unlink \"%s\" failed: %s", tname,
-			 filename, strerror(errno));
 
 	if (WIFSIGNALED(es) &&
 	    (WTERMSIG(es) == SIGINT || WTERMSIG(es) == SIGQUIT))
@@ -109,101 +82,91 @@ int runcc(char *tname, char *filename0, char *program)
 
 	if (WEXITSTATUS(es)) {
 		tst_resm(TFAIL, "%s: not present", tname);
-		return -1;
+		return;
 	}
 	/* run the test */
 
 	es = system(filename0);
-	saved_errno = errno;
-	if (unlink(filename0) < 0)
-		tst_resm(TWARN, "%s: unlink \"%s\" failed: %s", tname,
-			 filename0, strerror(errno));
 
 	if (WIFSIGNALED(es) &&
 	    (WTERMSIG(es) == SIGINT || WTERMSIG(es) == SIGQUIT))
 		exit(1);
 
 	if (WEXITSTATUS(es) == 127)
-		tst_resm(TBROK, "%s: can't run \"%s\": %s", tname, filename0,
-			 strerror(saved_errno));
+		tst_resm(TBROK | TERRNO, "%s: can't run \"%s\"", tname,
+			 filename0);
 	if (WEXITSTATUS(es))
 		tst_resm(TFAIL, "%s: present, but incorrect", tname);
 	else
 		tst_resm(TPASS, "%s present and correct", tname);
-	return 0;
 }
 
-char *field_fmt = "\n\texit((offsetof(struct %s, %s) != %s) || "
-    "sizeof(tst.%s) != (%s));\n";
+#define FIELD_FMT	"\n\texit((offsetof(struct %s, %s) != %s) || " \
+			"sizeof(tst.%s) != (%s));\n"
 /* no offset check */
-char *field_fmt2 = "\n\texit(sizeof(tst.%s) != (%s));\n";
+#define FIELD_FMT2	"\n\texit(sizeof(tst.%s) != (%s));\n"
 
-const char *stmpl =
-    "%s\n#ifndef offsetof\n"
-    "#define offsetof(dtype, dfield) ((int)&((dtype *)0)->dfield)\n"
-    "#endif\n\nstruct %s tst;\n\nmain(int argc, char *argv[])\n{\n\t%s\n}\n";
+#define STMPL	"%s#include <stdlib.h>\n\n\n" \
+		"#ifndef offsetof\n" \
+		"#define offsetof(dtype, dfield) " \
+		"((int)&((dtype *)0)->dfield)\n" \
+		"#endif\n\nstruct %s tst;\n\n" \
+		"int main(int argc, char *argv[])\n{\n\t%s\n}\n"
 
-int
-structcheck(char *tname, char *incl, char *structure, char *field,
-	    char *offset, char *size)
+void structcheck(char *tname, char *incl, char *structure, char *field,
+		 char *offset, char *size)
 {
-	int rv;
 	static char filename[1024];
 
 	if (offset)
-		sprintf(fieldref, field_fmt, structure, field, offset, field,
+		sprintf(fieldref, FIELD_FMT, structure, field, offset, field,
 			size);
 	else
-		sprintf(fieldref, field_fmt2, field, size);
-	sprintf(program, stmpl, incl, structure, fieldref);
-	snprintf(filename, sizeof(filename), filetmpl, strfpn(structure),
+		sprintf(fieldref, FIELD_FMT2, field, size);
+	sprintf(program, STMPL, incl, structure, fieldref);
+	snprintf(filename, sizeof(filename), FILETMPL, strfpn(structure),
 		 structure);
-	rv = runcc(tname, filename, program);
-	return rv;
+	runcc(tname, filename, program);
 }
 
-char *aliasfmt =
-    "exit(&tst.%s != &tst.%s || sizeof(tst.%s) != sizeof(tst.%s));";
+#define ALIASFMT	"exit(&tst.%s != &tst.%s || " \
+			"sizeof(tst.%s) != sizeof(tst.%s));"
 
-int
-aliascheck(char *tname, char *incl, char *structure, char *field, char *dname)
+void aliascheck(char *tname, char *incl, char *structure, char *field,
+		char *dname)
 {
-	int rv;
 	static char filename[1024];
 
-	sprintf(fieldref, aliasfmt, field, dname, field, dname);
-	sprintf(program, stmpl, incl, structure, fieldref);
-	snprintf(filename, sizeof(filename), filetmpl, strfpn(structure),
+	sprintf(fieldref, ALIASFMT, field, dname, field, dname);
+	sprintf(program, STMPL, incl, structure, fieldref);
+	snprintf(filename, sizeof(filename), FILETMPL, strfpn(structure),
 		 structure);
-	rv = runcc(tname, filename, program);
-	return rv;
+	runcc(tname, filename, program);
 }
 
-const char *dtmpl =
-    "%s\n\nmain(int argc, char *argv[])\n{\n\texit((%s) != (%s));\n}\n";
+#define DTMPL	"%s#include <stdlib.h>\n\n\n" \
+		"int main(int argc, char *argv[])\n" \
+		"{\n\texit((%s) != (%s));\n}\n"
 
-int valuecheck(char *tname, char *incl, char *dname, char *dval)
+void valuecheck(char *tname, char *incl, char *dname, char *dval)
 {
-	int rv;
 	static char filename[1024];
 
-	sprintf(program, dtmpl, incl, dname, dval);
-	snprintf(filename, sizeof(filename), filetmpl, strfpn(dname), dname);
-	rv = runcc(tname, filename, program);
-	return rv;
+	sprintf(program, DTMPL, incl, dname, dval);
+	snprintf(filename, sizeof(filename), FILETMPL, strfpn(dname), dname);
+	runcc(tname, filename, program);
 }
 
-const char *ftmpl =
-    "%s\n\nmain(int argc, char *argv[])\n{\n#ifdef %s\n\texit(0);\n#else\n"
-    "\tsyntax error;\n#endif\n}\n";
+#define FTMPL	"%s#include <stdlib.h>\n\n\n" \
+		"int main(int argc, char *argv[])\n" \
+		"{\n#ifdef %s\n\texit(0);\n#else\n" \
+		"\tsyntax error;\n#endif\n}\n"
 
-int funccheck(char *tname, char *incl, char *fname)
+void funccheck(char *tname, char *incl, char *fname)
 {
-	int rv;
 	static char filename[1024];
 
-	sprintf(program, ftmpl, incl, fname);
-	snprintf(filename, sizeof(filename), filetmpl, strfpn(fname), fname);
-	rv = runcc(tname, filename, program);
-	return rv;
+	sprintf(program, FTMPL, incl, fname);
+	snprintf(filename, sizeof(filename), FILETMPL, strfpn(fname), fname);
+	runcc(tname, filename, program);
 }
diff --git a/testcases/network/lib6/runcc.h b/testcases/network/lib6/runcc.h
index 4e2a0d5..a66addb 100644
--- a/testcases/network/lib6/runcc.h
+++ b/testcases/network/lib6/runcc.h
@@ -1,30 +1,38 @@
 /*
+ * Copyright (c) 2015 Fujitsu Ltd.
+ * Copyright (c) International Business Machines  Corp., 2001
  *
- *   Copyright (c) International Business Machines  Corp., 2001
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
  *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
  *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-int aliascheck(char *tname, char *incl, char *structure, char *field,
-	char *dname);
-int funccheck(char *tname, char *incl, char *fname);
-int structcheck(char *tname, char *incl, char *structure, char *field,
-	char *offset, char *size);
-int valuecheck(char *tname, char *incl, char *dname, char *dval);
+#ifndef __RUNCC_H__
+#define __RUNCC_H__
 
-#define IP6_H "#include <netinet/ip6.h>\n"
-#define IN_H "#include <netinet/in.h>\n"
-#define ICMP6_H "#include <netinet/icmp6.h>\n"
-#define SOCKET_H "#include <sys/types.h>\n#include <sys/socket.h>\n"
+void aliascheck(char *tname, char *incl, char *structure, char *field,
+		char *dname);
+
+void funccheck(char *tname, char *incl, char *fname);
+
+void structcheck(char *tname, char *incl, char *structure, char *field,
+		 char *offset, char *size);
+
+void valuecheck(char *tname, char *incl, char *dname, char *dval);
+
+#define IP6_H		"#include <netinet/ip6.h>\n"
+#define IN_H		"#include <netinet/in.h>\n"
+#define ICMP6_H		"#include <netinet/icmp6.h>\n"
+#define SOCKET_H	"#include <sys/types.h>\n#include <sys/socket.h>\n"
+
+#endif  /* __RUNCC_H__ */
-- 
1.9.3


------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v4 03/11] asapi_01: Use 'tst_tmpdir' and more cleanup
  2015-07-09  3:05                     ` [LTP] [PATCH v4 01/11] " Zeng Linggang
  2015-07-09  3:05                       ` [LTP] [PATCH v4 02/11] lib6/runcc.c: Cleanup Zeng Linggang
@ 2015-07-09  3:05                       ` Zeng Linggang
  2015-07-09  3:05                       ` [LTP] [PATCH v4 04/11] asapi_02: " Zeng Linggang
                                         ` (8 subsequent siblings)
  10 siblings, 0 replies; 55+ messages in thread
From: Zeng Linggang @ 2015-07-09  3:05 UTC (permalink / raw)
  To: alexey.kodanev; +Cc: ltp-list

* Use 'tst_tmpdir' and 'tst_rmdir'.
* Add 'static' for the cleanup.

Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
 testcases/network/lib6/asapi_01.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/testcases/network/lib6/asapi_01.c b/testcases/network/lib6/asapi_01.c
index 5d8bdc7..a129569 100644
--- a/testcases/network/lib6/asapi_01.c
+++ b/testcases/network/lib6/asapi_01.c
@@ -198,6 +198,7 @@ static struct ftent {
 };
 
 static void setup(void);
+static void cleanup(void);
 static void do_test(const struct ftent *);
 
 char *TCID = "asapi_01";
@@ -218,15 +219,23 @@ int main(int argc, char *argv[])
 			do_test(&ftab[i]);
 	}
 
+	cleanup();
 	tst_exit();
 }
 
-void setup(void)
+static void setup(void)
 {
 	TEST_PAUSE;
+
+	tst_tmpdir();
+}
+
+static void cleanup(void)
+{
+	tst_rmdir();
 }
 
-void do_test(const struct ftent *ftptr)
+static void do_test(const struct ftent *ftptr)
 {
 	switch (ftptr->ft_type) {
 	case EXISTS:
-- 
1.9.3


------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v4 04/11] asapi_02: Use 'tst_tmpdir' and more cleanup
  2015-07-09  3:05                     ` [LTP] [PATCH v4 01/11] " Zeng Linggang
  2015-07-09  3:05                       ` [LTP] [PATCH v4 02/11] lib6/runcc.c: Cleanup Zeng Linggang
  2015-07-09  3:05                       ` [LTP] [PATCH v4 03/11] asapi_01: Use 'tst_tmpdir' and more cleanup Zeng Linggang
@ 2015-07-09  3:05                       ` Zeng Linggang
  2015-07-09  3:05                       ` [LTP] [PATCH v4 05/11] asapi_03: " Zeng Linggang
                                         ` (7 subsequent siblings)
  10 siblings, 0 replies; 55+ messages in thread
From: Zeng Linggang @ 2015-07-09  3:05 UTC (permalink / raw)
  To: alexey.kodanev; +Cc: ltp-list

* Use 'tst_tmpdir' and 'tst_rmdir'.
* Add 'static' for the cleanup.

Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
 testcases/network/lib6/asapi_02.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/testcases/network/lib6/asapi_02.c b/testcases/network/lib6/asapi_02.c
index 01bee37..ac7dcda 100644
--- a/testcases/network/lib6/asapi_02.c
+++ b/testcases/network/lib6/asapi_02.c
@@ -285,6 +285,7 @@ static struct ftent {
 };
 
 static void setup(void);
+static void cleanup(void);
 static void do_test(const struct ftent *);
 
 char *TCID = "asapi_02";
@@ -305,15 +306,23 @@ int main(int argc, char *argv[])
 			do_test(&ftab[i]);
 	}
 
+	cleanup();
 	tst_exit();
 }
 
-void setup(void)
+static void setup(void)
 {
 	TEST_PAUSE;
+
+	tst_tmpdir();
+}
+
+static void cleanup(void)
+{
+	tst_rmdir();
 }
 
-void do_test(const struct ftent *ftptr)
+static void do_test(const struct ftent *ftptr)
 {
 	switch (ftptr->ft_type) {
 	case EXISTS:
-- 
1.9.3


------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v4 05/11] asapi_03: Use 'tst_tmpdir' and more cleanup
  2015-07-09  3:05                     ` [LTP] [PATCH v4 01/11] " Zeng Linggang
                                         ` (2 preceding siblings ...)
  2015-07-09  3:05                       ` [LTP] [PATCH v4 04/11] asapi_02: " Zeng Linggang
@ 2015-07-09  3:05                       ` Zeng Linggang
  2015-07-09  3:05                       ` [LTP] [PATCH v4 06/11] lib6/asapi_04.c: Cleanup Zeng Linggang
                                         ` (6 subsequent siblings)
  10 siblings, 0 replies; 55+ messages in thread
From: Zeng Linggang @ 2015-07-09  3:05 UTC (permalink / raw)
  To: alexey.kodanev; +Cc: ltp-list

* Use 'tst_tmpdir' and 'tst_rmdir'.
* Add 'static' for the cleanup.

Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
 testcases/network/lib6/asapi_03.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/testcases/network/lib6/asapi_03.c b/testcases/network/lib6/asapi_03.c
index f458d7d..61be294 100644
--- a/testcases/network/lib6/asapi_03.c
+++ b/testcases/network/lib6/asapi_03.c
@@ -181,6 +181,7 @@ static struct ftent {
 };
 
 static void setup(void);
+static void cleanup(void);
 static void do_test(const struct ftent *);
 
 char *TCID = "asapi_03";
@@ -201,15 +202,23 @@ int main(int argc, char *argv[])
 			do_test(&ftab[i]);
 	}
 
+	cleanup();
 	tst_exit();
 }
 
-void setup(void)
+static void setup(void)
 {
 	TEST_PAUSE;
+
+	tst_tmpdir();
+}
+
+static void cleanup(void)
+{
+	tst_rmdir();
 }
 
-void do_test(const struct ftent *ftptr)
+static void do_test(const struct ftent *ftptr)
 {
 	switch (ftptr->ft_type) {
 	case EXISTS:
-- 
1.9.3


------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v4 06/11] lib6/asapi_04.c: Cleanup
  2015-07-09  3:05                     ` [LTP] [PATCH v4 01/11] " Zeng Linggang
                                         ` (3 preceding siblings ...)
  2015-07-09  3:05                       ` [LTP] [PATCH v4 05/11] asapi_03: " Zeng Linggang
@ 2015-07-09  3:05                       ` Zeng Linggang
  2015-07-09  3:05                       ` [LTP] [PATCH v4 07/11] lib6/asapi_05.c: Cleanup Zeng Linggang
                                         ` (5 subsequent siblings)
  10 siblings, 0 replies; 55+ messages in thread
From: Zeng Linggang @ 2015-07-09  3:05 UTC (permalink / raw)
  To: alexey.kodanev; +Cc: ltp-list

* Add 'static' before some functions and global variables.
* Remove useless comments.
* Use SAFE_XXX().
* Modify the format of ptab[] and cstab[].
* Rewrite 'csum_test()' and 'isocketpair()'.
* Use 'tst_tmpdir' and 'tst_rmdir'.
* Some cleanup.

Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
 testcases/network/lib6/asapi_04.c | 287 ++++++++++++++++----------------------
 1 file changed, 122 insertions(+), 165 deletions(-)

diff --git a/testcases/network/lib6/asapi_04.c b/testcases/network/lib6/asapi_04.c
index 76de26b..76e8f8e 100644
--- a/testcases/network/lib6/asapi_04.c
+++ b/testcases/network/lib6/asapi_04.c
@@ -1,38 +1,21 @@
 /*
+ * Copyright (c) 2015 Fujitsu Ltd.
+ * Copyright (c) International Business Machines  Corp., 2001
  *
- *   Copyright (c) International Business Machines  Corp., 2001
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
  *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
  *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/*
- * Test Name: asapi_04
- *
- * Test Description:
- *  Verify that in6 and sockaddr fields are present. Most of these are
- *  "PASS" if they just compile.
- *
- * Usage:  <for command-line>
- *  asapi_04
- *
- * HISTORY
- *	04/2005 written by David L Stevens
- *
- * RESTRICTIONS:
- *  None.
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
+ * Author: David L Stevens
  */
 
 #include <stdio.h>
@@ -48,33 +31,35 @@
 #include <netinet/in.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
-char *TCID = "asapi_04";	/* Test program identifier.    */
+char *TCID = "asapi_04";
 
-pid_t pid;
+static pid_t pid;
 
-struct {
+static struct {
 	char *prt_name;
 	int prt_value;
 } ptab[] = {
-	{
-	"hopopt", 0}, {
-	"ipv6", 41}, {
-	"ipv6-route", 43}, {
-	"ipv6-frag", 44}, {
-	"esp", 50}, {
-	"ah", 51}, {
-	"ipv6-icmp", 58}, {
-	"ipv6-nonxt", 59}, {
-"ipv6-opts", 60},};
-
-#define PTCOUNT	(sizeof(ptab)/sizeof(ptab[0]))
+	{"hopopt", 0},
+	{"ipv6", 41},
+	{"ipv6-route", 43},
+	{"ipv6-frag", 44},
+	{"esp", 50},
+	{"ah", 51},
+	{"ipv6-icmp", 58},
+	{"ipv6-nonxt", 59},
+	{"ipv6-opts", 60},
+};
+
+#define PTCOUNT	ARRAY_SIZE(ptab)
 
 #define READ_TIMEOUT	5	/* secs */
 
-void do_tests(void);
-void setup(void), cleanup(void);
-int csum_test(char *rhost);
+static void do_tests(void);
+static void setup(void);
+static void cleanup(void);
+static int csum_test(void);
 
 int main(int argc, char *argv[])
 {
@@ -90,44 +75,41 @@ int main(int argc, char *argv[])
 		do_tests();
 
 	cleanup();
-
 	tst_exit();
 }
 
-void do_tests(void)
+static void do_tests(void)
 {
-	int i;
+	unsigned int i;
 
 /* RFC 3542, Section 2.3 */
 #ifndef IN6_ARE_ADDR_EQUAL
-	tst_resm(TBROK, "IN6_ARE_ADDR_EQUAL not present");
+	tst_resm(TCONF, "IN6_ARE_ADDR_EQUAL not present");
 #else /* IN6_ARE_ADDR_EQUAL */
 	/*
 	 * set each bit in an address and check for unequal; then set
 	 * in the second address and check for equal. Covers all bits, all
 	 * combinations.
 	 */
-	{
-		struct in6_addr a1, a2;
-		int word, bit;
-		int rv = 1;
+	struct in6_addr a1, a2;
+	int word, bit;
+	int rv = 1;
 
-		memset(&a1, 0, sizeof(a1));
-		memset(&a2, 0, sizeof(a2));
+	memset(&a1, 0, sizeof(a1));
+	memset(&a2, 0, sizeof(a2));
 
-		rv = IN6_ARE_ADDR_EQUAL(&a1, &a2);
+	rv = IN6_ARE_ADDR_EQUAL(&a1, &a2);
 
-		for (word = 0; word < 4; ++word)
-			for (bit = 0; bit < 32; ++bit) {
-				uint32_t newbit = 1 << bit;
+	for (word = 0; word < 4; ++word)
+		for (bit = 0; bit < 32; ++bit) {
+			uint32_t newbit = 1U << bit;
 
-				a1.s6_addr32[word] |= newbit;	/* unequal */
-				rv &= !IN6_ARE_ADDR_EQUAL(&a1, &a2);
-				a2.s6_addr32[word] |= newbit;	/* equal */
-				rv &= IN6_ARE_ADDR_EQUAL(&a1, &a2);
-			}
-		tst_resm(rv ? TPASS : TFAIL, "IN6_ARE_ADDR_EQUAL");
-	}
+			a1.s6_addr32[word] |= newbit;	/* unequal */
+			rv &= !IN6_ARE_ADDR_EQUAL(&a1, &a2);
+			a2.s6_addr32[word] |= newbit;	/* equal */
+			rv &= IN6_ARE_ADDR_EQUAL(&a1, &a2);
+		}
+	tst_resm(rv ? TPASS : TFAIL, "IN6_ARE_ADDR_EQUAL");
 #endif /* IN6_ARE_ADDR_EQUAL */
 
 /* RFC 3542, Section 2.4 */
@@ -141,7 +123,7 @@ void do_tests(void)
 			 ptab[i].prt_name);
 	}
 /* RFC 3542, Section 3.1 */
-	csum_test("::1");
+	csum_test();
 }
 
 /*
@@ -162,10 +144,10 @@ struct tprot {
 	unsigned char tp_dat[0];	/* user data */
 };
 
-unsigned char tpbuf[sizeof(struct tprot) + 2048];
-unsigned char rpbuf[sizeof(struct tprot) + 2048];
+static unsigned char tpbuf[sizeof(struct tprot) + 2048];
+static unsigned char rpbuf[sizeof(struct tprot) + 2048];
 
-struct csent {
+static struct csent {
 	int cs_offset;
 	int cs_dlen;
 	int cs_setresult;	/* setsockopt expected result */
@@ -173,25 +155,24 @@ struct csent {
 	int cs_sndresult;	/* send expected result */
 	int cs_snderrno;	/* send expected errno */
 } cstab[] = {
-	{
-	0, 5, 0, 0, 0, 0}, {
-	6, 30, 0, 0, 0, 0}, {
-	3, 20, -1, EINVAL, -1, -1},	/* non-aligned offset */
-	{
-	4, 5, 0, 0, -1, EINVAL},	/* not enough space */
-	{
-	50, 5, 0, 0, -1, EINVAL},	/* outside of packet */
-	{
-	22, 30, 0, 0, 0, 0}, {
-	2000, 2004, 0, 0, 0, 0},	/* in a fragment (over Ethernet) */
+	{0, 5, 0, 0, 0, 0},
+	{6, 30, 0, 0, 0, 0},
+	{3, 20, -1, EINVAL, -1, -1},	/* non-aligned offset */
+	{4, 5, 0, 0, -1, EINVAL},	/* not enough space */
+	{50, 5, 0, 0, -1, EINVAL},	/* outside of packet */
+	{22, 30, 0, 0, 0, 0},
+	{2000, 2004, 0, 0, 0, 0},	/* in a fragment (over Ethernet) */
 };
 
-#define CSCOUNT	(sizeof(cstab)/sizeof(cstab[0]))
+#define CSCOUNT	ARRAY_SIZE(cstab)
+
+int TST_TOTAL = PTCOUNT + CSCOUNT;
 
-static int recvtprot(int sd, unsigned char *packet, int psize)
+static int recvtprot(int sd, unsigned char *packet)
 {
 	struct tprot *tpt;
-	int cc, total, expected;
+	int cc;
+	unsigned int total, expected;
 	int gothead;
 
 	tpt = (struct tprot *)packet;
@@ -218,7 +199,8 @@ static int recvtprot(int sd, unsigned char *packet, int psize)
 	return total;
 }
 
-unsigned short csum(unsigned short partial, unsigned char *packet, int len)
+static unsigned short csum(unsigned short partial, unsigned char *packet,
+			   int len)
 {
 	unsigned long sum = partial;
 	unsigned short *ps;
@@ -234,7 +216,7 @@ unsigned short csum(unsigned short partial, unsigned char *packet, int len)
 	return ~sum;
 }
 
-struct ph {
+static struct ph {
 	struct in6_addr ph_sa;
 	struct in6_addr ph_da;
 	uint32_t ph_len;
@@ -242,13 +224,14 @@ struct ph {
 	uint8_t ph_nh;
 } ph;
 
-static int client(int prot, int sfd)
+static int client(int sfd)
 {
 	struct tprot *pttp = (struct tprot *)tpbuf;
 	struct tprot *prtp = (struct tprot *)rpbuf;
 	struct sockaddr_in6 rsin6;
 	static int seq;
-	int i, sd, cc, cs;
+	unsigned int i;
+	int sd, cc, cs;
 
 	memset(&rsin6, 0, sizeof(rsin6));
 	rsin6.sin6_family = AF_INET6;
@@ -259,11 +242,8 @@ static int client(int prot, int sfd)
 	ph.ph_da = rsin6.sin6_addr;
 	ph.ph_nh = NH_TEST;
 
-	sd = socket(PF_INET6, SOCK_RAW, NH_TEST);
-	if (sd < 0) {
-		tst_resm(TBROK, "can't create raw socket: %s", strerror(errno));
-		return -1;
-	}
+	sd = SAFE_SOCKET(NULL, PF_INET6, SOCK_RAW, NH_TEST);
+
 	for (i = 0; i < CSCOUNT; ++i) {
 		int offset, len, xlen;
 		int rv;
@@ -289,17 +269,20 @@ static int client(int prot, int sfd)
 				 cstab[i].cs_setresult);
 			continue;
 		}
+
 		if (TEST_RETURN < 0) {
 			tst_resm(TPASS, "IPV6_CHECKSUM offset %d len %d",
 				 offset, len);
 			continue;
 		}
+
 		if (TEST_RETURN && TEST_ERRNO != cstab[i].cs_seterrno) {
 			tst_resm(TFAIL, "IPV6_CHECKSUM offset %d len %d "
 				 "- errno %d != %d", offset, len,
 				 TEST_ERRNO, cstab[i].cs_seterrno);
 			continue;
 		}
+
 		/* send packet */
 		TEST(sendto(sd, pttp, len, 0, (struct sockaddr *)&rsin6,
 			    sizeof(rsin6)));
@@ -311,20 +294,23 @@ static int client(int prot, int sfd)
 				 TEST_RETURN, xlen);
 			continue;
 		}
+
 		if (TEST_RETURN < 0 && TEST_ERRNO != cstab[i].cs_snderrno) {
 			tst_resm(TFAIL, "IPV6_CHECKSUM offset %d len %d "
 				 "- snderrno %d != %d", offset, len,
 				 TEST_ERRNO, cstab[i].cs_snderrno);
 			continue;
 		}
+
 		if (TEST_RETURN < 0) {
 			tst_resm(TPASS, "IPV6_CHECKSUM offset %d len %d",
 				 offset, len);
 			continue;
 		}
-		while ((cc = recvtprot(sfd, rpbuf, sizeof(rpbuf)))) {
-			if (htonl(prtp->tp_pid) == pid &&
-			    htonl(prtp->tp_seq) == seq)
+
+		while ((cc = recvtprot(sfd, rpbuf))) {
+			if (htonl(prtp->tp_pid) == (uint32_t)pid &&
+			    htonl(prtp->tp_seq) == (uint32_t)seq)
 				break;
 		}
 		rv = 1;
@@ -334,7 +320,7 @@ static int client(int prot, int sfd)
 				continue;
 			if (*p != 0xa5) {
 				tst_resm(TFAIL, "IPV6_CHECKSUM corrupt data "
-					 "0x%02x != 0xa5 at offset %d in packet",
+					 "0x%02x != 0xa5 at offset %zd in packet",
 					 *p, p - rpbuf);
 				rv = 0;
 				break;
@@ -358,7 +344,7 @@ static int client(int prot, int sfd)
 static int listen_fd, connect_fd;
 sem_t ilsem;
 
-void *ilistener(void *arg)
+static void *ilistener(void *arg LTP_ATTRIBUTE_UNUSED)
 {
 	connect_fd = accept(listen_fd, 0, 0);
 	close(listen_fd);
@@ -366,7 +352,7 @@ void *ilistener(void *arg)
 	return NULL;
 }
 
-int isocketpair(int pf, int type, int proto, int fd[2])
+static void isocketpair(int pf, int type, int proto, int fd[2])
 {
 	pthread_t thid;
 	struct sockaddr_in sin4;
@@ -375,80 +361,51 @@ int isocketpair(int pf, int type, int proto, int fd[2])
 /* restrict to PF_INET for now */
 	if (pf != PF_INET) {
 		errno = EOPNOTSUPP;
-		return -1;
+		return;
 	}
+
 	sem_init(&ilsem, 0, 0);
-	listen_fd = socket(pf, type, proto);
-	if (listen_fd < 0) {
-		perror("socket");
-		return -1;
-	}
+
+	listen_fd = SAFE_SOCKET(NULL, pf, type, proto);
+
 	memset(&sin4, 0, sizeof(sin4));
-	if (bind(listen_fd, (struct sockaddr *)&sin4, sizeof(sin4)) < 0) {
-		perror("bind");
-		return -1;
-	}
-	if (listen(listen_fd, 10) < 0) {
-		perror("listen");
-		return -1;
-	}
+
+	SAFE_BIND(NULL, listen_fd, (struct sockaddr *)&sin4, sizeof(sin4));
+
+	SAFE_LISTEN(NULL, listen_fd, 10);
+
 	namelen = sizeof(sin4);
-	if (getsockname(listen_fd, (struct sockaddr *)&sin4, &namelen) < 0) {
-		perror("getsockname");
-		return -1;
-	}
-	if (pthread_create(&thid, 0, ilistener, 0) < 0) {
-		perror("pthread_create");
-		return -1;
-	}
+	SAFE_GETSOCKNAME(NULL, listen_fd, (struct sockaddr *)&sin4, &namelen);
+
+	if (pthread_create(&thid, 0, ilistener, 0) < 0)
+		tst_brkm(TBROK | TERRNO, NULL, "pthread_create error");
+
+	fd[0] = SAFE_SOCKET(NULL, pf, type, proto);
 
-	fd[0] = socket(pf, type, proto);
-	if (fd[0] < 0) {
-		perror("socket");
-		return -1;
-	}
 	sin4.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
-	if (connect(fd[0], (struct sockaddr *)&sin4, sizeof(sin4)) < 0) {
-		perror("connect");
-		return -1;
-	}
+
+	SAFE_CONNECT(NULL, fd[0], (struct sockaddr *)&sin4, sizeof(sin4));
+
 	sem_wait(&ilsem);
 	fd[1] = connect_fd;
 	sem_destroy(&ilsem);
-	return 0;
 }
 
 #ifndef MAX
 #define MAX(a, b) ((a) >= (b) ? (a) : (b))
 #endif /* MAX */
 
-int csum_test(char *rhost)
+static int csum_test(void)
 {
 	fd_set rset, rset_save;
 	int csd[2];		/* control sockets */
 	int sd, nfds, maxfd, cc;
 	struct timeval tv;
 
-/* rhost == loopback, for now */
-	if (strcmp(rhost, "::1")) {
-		tst_resm(TBROK, "invalid rhost \"%s\"", rhost);
-		return -1;
-	}
-	if (isocketpair(PF_INET, SOCK_STREAM, 0, csd) < 0) {
-		tst_resm(TBROK, "socketpair: %s", strerror(errno));
-		return -1;
-	}
-	sd = socket(PF_INET6, SOCK_RAW, NH_TEST);
-	if (sd < 0) {
-		int saved_errno = errno;
-
-		if (errno == EPERM && geteuid())
-			tst_resm(TBROK, "IPV6_CHECKSUM tests must run as root");
-		else
-			tst_resm(TBROK, "All IPv6_CHECKSUM tests broken: "
-				 "socket: %s", strerror(saved_errno));
-		return -1;
-	}
+	isocketpair(PF_INET, SOCK_STREAM, 0, csd);
+
+	sd = SAFE_SOCKET(NULL, PF_INET6, SOCK_RAW, NH_TEST);
+
 	FD_ZERO(&rset_save);
 	FD_SET(sd, &rset_save);
 	FD_SET(csd[1], &rset_save);
@@ -457,16 +414,15 @@ int csum_test(char *rhost)
 
 	/* server socket set; now start the client */
 	switch (fork()) {
-	case 0:		/* child */
+	case 0:
 		close(csd[0]);
 		break;
 	case -1:
-		tst_resm(TBROK, "can't fork rserver");
-		return -1;
-	default:		/* parent */
+		tst_brkm(TBROK, NULL, "can't fork rserver");
+	default:
 		close(sd);
 		close(csd[1]);
-		return client(pid, csd[0]);
+		return client(csd[0]);
 	}
 
 	tv.tv_sec = READ_TIMEOUT;
@@ -515,13 +471,14 @@ int csum_test(char *rhost)
 	return 0;
 }
 
-void setup(void)
+static void setup(void)
 {
-	TEST_PAUSE;		/* if -P option specified */
+	TEST_PAUSE;
+
+	tst_tmpdir();
 }
 
-void cleanup(void)
+static void cleanup(void)
 {
+	tst_rmdir();
 }
-
-int TST_TOTAL = PTCOUNT + CSCOUNT;
-- 
1.9.3


------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v4 07/11] lib6/asapi_05.c: Cleanup
  2015-07-09  3:05                     ` [LTP] [PATCH v4 01/11] " Zeng Linggang
                                         ` (4 preceding siblings ...)
  2015-07-09  3:05                       ` [LTP] [PATCH v4 06/11] lib6/asapi_04.c: Cleanup Zeng Linggang
@ 2015-07-09  3:05                       ` Zeng Linggang
  2015-07-09  3:05                       ` [LTP] [PATCH v4 08/11] lib6/asapi_06.c: Cleanup Zeng Linggang
                                         ` (4 subsequent siblings)
  10 siblings, 0 replies; 55+ messages in thread
From: Zeng Linggang @ 2015-07-09  3:05 UTC (permalink / raw)
  To: alexey.kodanev; +Cc: ltp-list

* Add 'static' before some functions and global variables.
* Use 'tst_tmpdir' and 'tst_rmdir'.
* Remove useless comments.
* Use SAFE_XXX().
* Modify the format of etab[] and ftab[].
* Some cleanup.

Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
 testcases/network/lib6/asapi_05.c | 274 ++++++++++++++++----------------------
 1 file changed, 113 insertions(+), 161 deletions(-)

diff --git a/testcases/network/lib6/asapi_05.c b/testcases/network/lib6/asapi_05.c
index 9acc6a2..25a5dbf 100644
--- a/testcases/network/lib6/asapi_05.c
+++ b/testcases/network/lib6/asapi_05.c
@@ -1,38 +1,21 @@
 /*
+ * Copyright (c) 2015 Fujitsu Ltd.
+ * Copyright (c) International Business Machines  Corp., 2001
  *
- *   Copyright (c) International Business Machines  Corp., 2001
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
  *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
  *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/*
- * Test Name: asapi_05
- *
- * Test Description:
- *  These tests are for the "Advanced Sockets API" (RFC 3542)
- *  Verify that in6 and sockaddr fields are present.
- *
- * Usage:  <for command-line>
- *  asapi_05
- *
- * HISTORY
- *	04/2005 written by David L Stevens
- *
- * RESTRICTIONS:
- *  None.
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
+ * Author: David L Stevens
  */
 
 #include <stdio.h>
@@ -47,21 +30,21 @@
 #include <netinet/icmp6.h>
 
 #include "test.h"
+#include "safe_macros.h"
 #include "runcc.h"
 
-char *TCID = "asapi_05";	/* Test program identifier.    */
+char *TCID = "asapi_05";
 
-void setup(void);
-void cleanup(void);
+static void setup(void);
+static void cleanup(void);
 
-void icmp6_et(void);
-void icmp6_ft(void);
+static void icmp6_et(void);
+static void icmp6_ft(void);
 
 int main(int argc, char *argv[])
 {
 	int lc;
 
-	/* Parse standard options given to run the test. */
 	tst_parse_opts(argc, argv, NULL, NULL);
 
 	setup();
@@ -72,13 +55,12 @@ int main(int argc, char *argv[])
 	}
 
 	cleanup();
-
 	tst_exit();
 }
 
 enum ttype { EXISTS, ALIAS, VALUE, DEFINED };
 
-struct etent {
+static struct etent {
 	char *et_tname;		/* test name */
 	int et_type;		/* test type */
 	char *et_incl;		/* include file list */
@@ -92,76 +74,58 @@ struct etent {
 #define et_value	ftun.fu_value
 #define et_dname	ftun.fu_dname
 } etab[] = {
-/* existence checks, RFC 3542 section 3 */
-	{
-		"icmp6_filter icmp6_filt", EXISTS, ICMP6_H, "icmp6_filter",
-		    "icmp6_filt", "0", {
-	"32"}}, {
-		"icmp6_filter icmp6_filt[0]", EXISTS, ICMP6_H, "icmp6_filter",
-		    "icmp6_filt[0]", "0", {
-	"4"}}, {
-		"ICMP6_FILTER_WILLPASS", DEFINED, ICMP6_H,
-		    "ICMP6_FILTER_WILLPASS", NULL, NULL, {
-	0}}, {
-		"ICMP6_FILTER_WILLBLOCK", DEFINED, ICMP6_H,
-		    "ICMP6_FILTER_WILLBLOCK", NULL, NULL, {
-	0}}, {
-		"ICMP6_FILTER_SETPASS", DEFINED, ICMP6_H,
-		    "ICMP6_FILTER_SETPASS", NULL, NULL, {
-	0}}, {
-		"ICMP6_FILTER_SETBLOCK", DEFINED, ICMP6_H,
-		    "ICMP6_FILTER_SETBLOCK", NULL, NULL, {
-	0}}, {
-		"ICMP6_FILTER_SETPASSALL", DEFINED, ICMP6_H,
-		    "ICMP6_FILTER_SETPASSALL", NULL, NULL, {
-	0}}, {
-		"ICMP6_FILTER_SETBLOCKALL", DEFINED, ICMP6_H,
-		    "ICMP6_FILTER_SETBLOCKALL", NULL, NULL, {
-	0}}, {
-		"ICMP6_FILTER", DEFINED, ICMP6_H, "ICMP6_FILTER", NULL, NULL, {
-	0}},
-/* existence checks, RFC 3542 section 4 */
-/* socket options */
-	{
-		"IPV6_RECVPKTINFO", VALUE, IN_H, "IPV6_RECVPKTINFO", NULL, NULL, {
-	"IPV6_RECVPKTINFO"}}, {
-		"IPV6_RECVHOPLIMIT", VALUE, IN_H, "IPV6_RECVHOPLIMIT", NULL,
-		    NULL, {
-	"IPV6_RECVHOPLIMIT"}}, {
-		"IPV6_RECVRTHDR", VALUE, IN_H, "IPV6_RECVRTHDR", NULL, NULL, {
-	"IPV6_RECVRTHDR"}}, {
-		"IPV6_RECVHOPOPTS", VALUE, IN_H, "IPV6_RECVHOPOPTS", NULL, NULL, {
-	"IPV6_RECVHOPOPTS"}}, {
-		"IPV6_RECVDSTOPTS", VALUE, IN_H, "IPV6_RECVDSTOPTS", NULL, NULL, {
-	"IPV6_RECVDSTOPTS"}}, {
-		"IPV6_RECVTCLASS", VALUE, IN_H, "IPV6_RECVTCLASS", NULL, NULL, {
-	"IPV6_RECVTCLASS"}},
-/* cmsg types */
-	{
-		"IPV6_PKTINFO", DEFINED, IN_H, "IPV6_PKTINFO", NULL, NULL, {
-	0}}, {
-		"IPV6_HOPLIMIT", DEFINED, IN_H, "IPV6_HOPLIMIT", NULL, NULL, {
-	0}}, {
-		"IPV6_NEXTHOP", DEFINED, IN_H, "IPV6_NEXTHOP", NULL, NULL, {
-	0}}, {
-		"IPV6_RTHDR", DEFINED, IN_H, "IPV6_RTHDR", NULL, NULL, {
-	0}}, {
-		"IPV6_HOPOPTS", DEFINED, IN_H, "IPV6_HOPOPTS", NULL, NULL, {
-	0}}, {
-		"IPV6_DSTOPTS", DEFINED, IN_H, "IPV6_DSTOPTS", NULL, NULL, {
-	0}}, {
-		"IPV6_RTHDRDSTOPTS", DEFINED, IN_H, "IPV6_RTHDRDSTOPTS", NULL,
-		    NULL, {
-	0}}, {
-		"IPV6_TCLASS", DEFINED, IN_H, "IPV6_TCLASS", NULL, NULL, {
-0}},};
-
-#define ETCOUNT	(sizeof(etab)/sizeof(etab[0]))
+	/* existence checks, RFC 3542 section 3 */
+	{"icmp6_filter icmp6_filt", EXISTS, ICMP6_H, "icmp6_filter",
+	 "icmp6_filt", "0", {"32"} },
+	{"icmp6_filter icmp6_filt[0]", EXISTS, ICMP6_H, "icmp6_filter",
+	 "icmp6_filt[0]", "0", {"4"} },
+	{"ICMP6_FILTER_WILLPASS", DEFINED, ICMP6_H, "ICMP6_FILTER_WILLPASS",
+	 NULL, NULL, {0} },
+	{"ICMP6_FILTER_WILLBLOCK", DEFINED, ICMP6_H, "ICMP6_FILTER_WILLBLOCK",
+	 NULL, NULL, {0} },
+	{"ICMP6_FILTER_SETPASS", DEFINED, ICMP6_H, "ICMP6_FILTER_SETPASS", NULL,
+	 NULL, {0} },
+	{"ICMP6_FILTER_SETBLOCK", DEFINED, ICMP6_H, "ICMP6_FILTER_SETBLOCK",
+	 NULL, NULL, {0} },
+	{"ICMP6_FILTER_SETPASSALL", DEFINED, ICMP6_H, "ICMP6_FILTER_SETPASSALL",
+	 NULL, NULL, {0} },
+	{"ICMP6_FILTER_SETBLOCKALL", DEFINED, ICMP6_H,
+	 "ICMP6_FILTER_SETBLOCKALL", NULL, NULL, {0} },
+	{"ICMP6_FILTER", DEFINED, ICMP6_H, "ICMP6_FILTER", NULL, NULL, {0} },
+	/* existence checks, RFC 3542 section 4 */
+	/* socket options */
+	{"IPV6_RECVPKTINFO", VALUE, IN_H, "IPV6_RECVPKTINFO", NULL, NULL,
+	 {"IPV6_RECVPKTINFO"} },
+	{"IPV6_RECVHOPLIMIT", VALUE, IN_H, "IPV6_RECVHOPLIMIT", NULL, NULL,
+	 {"IPV6_RECVHOPLIMIT"} },
+	{"IPV6_RECVRTHDR", VALUE, IN_H, "IPV6_RECVRTHDR", NULL, NULL,
+	 {"IPV6_RECVRTHDR"} },
+	{"IPV6_RECVHOPOPTS", VALUE, IN_H, "IPV6_RECVHOPOPTS", NULL, NULL,
+	 {"IPV6_RECVHOPOPTS"} },
+	{"IPV6_RECVDSTOPTS", VALUE, IN_H, "IPV6_RECVDSTOPTS", NULL, NULL,
+	 {"IPV6_RECVDSTOPTS"} },
+	{"IPV6_RECVTCLASS", VALUE, IN_H, "IPV6_RECVTCLASS", NULL, NULL,
+	 {"IPV6_RECVTCLASS"} },
+	/* cmsg types */
+	{"IPV6_PKTINFO", DEFINED, IN_H, "IPV6_PKTINFO", NULL, NULL, {0} },
+	{"IPV6_HOPLIMIT", DEFINED, IN_H, "IPV6_HOPLIMIT", NULL, NULL, {0} },
+	{"IPV6_NEXTHOP", DEFINED, IN_H, "IPV6_NEXTHOP", NULL, NULL, {0} },
+	{"IPV6_RTHDR", DEFINED, IN_H, "IPV6_RTHDR", NULL, NULL, {0} },
+	{"IPV6_HOPOPTS", DEFINED, IN_H, "IPV6_HOPOPTS", NULL, NULL, {0} },
+	{"IPV6_DSTOPTS", DEFINED, IN_H, "IPV6_DSTOPTS", NULL, NULL, {0} },
+	{"IPV6_RTHDRDSTOPTS", DEFINED, IN_H, "IPV6_RTHDRDSTOPTS", NULL, NULL,
+	 {0} },
+	{"IPV6_TCLASS", DEFINED, IN_H, "IPV6_TCLASS", NULL, NULL, {0} },
+};
+
+#define ETCOUNT	ARRAY_SIZE(etab)
+
+int TST_TOTAL = ETCOUNT;
 
 /*  existence tests */
-void icmp6_et(void)
+static void icmp6_et(void)
 {
-	int i;
+	unsigned int i;
 
 	for (i = 0; i < ETCOUNT; ++i) {
 		switch (etab[i].et_type) {
@@ -190,60 +154,59 @@ void icmp6_et(void)
 	}
 }
 
-void setup(void)
+static void setup(void)
 {
-	TEST_PAUSE;		/* if -P option specified */
+	TEST_PAUSE;
 	tst_require_root(NULL);
+
+	tst_tmpdir();
 }
 
-void cleanup(void)
+static void cleanup(void)
 {
+	tst_rmdir();
 }
 
-/*
- * This is for old, broken glibc-header icmp6_filter structure definitions.
- * If icmp6.h has struct icmp6_filter with field named "data" instead
- * of the standard "icmp_filt", uncomment this line.
- */
-/*#define icmp_filt	data */
-
-enum tt { T_WILLPASS, T_WILLBLOCK, T_SETPASS, T_SETBLOCK, T_SETPASSALL,
+enum tt {
+	T_WILLPASS,
+	T_WILLBLOCK,
+	T_SETPASS,
+	T_SETBLOCK,
+	T_SETPASSALL,
 	T_SETBLOCKALL
 };
-struct ftent {
-	char *ft_tname;		/* test name, for logging */
+
+static struct ftent {
+	char *ft_tname;			/* test name, for logging */
 	unsigned char ft_sndtype;	/* send type field */
 	unsigned char ft_flttype;	/* filter type field */
-	enum tt ft_test;	/* what macro to test */
-	int ft_expected;	/* packet should pass? */
+	enum tt ft_test;		/* what macro to test */
+	int ft_expected;		/* packet should pass? */
 } ftab[] = {
-	{
-	"ICMP6_FILTER_SETPASS s 20 f 20", 20, 20, T_SETPASS, 1}, {
-	"ICMP6_FILTER_SETPASS s 20 f 21", 20, 21, T_SETPASS, 0}, {
-	"ICMP6_FILTER_SETBLOCK s 20 f 20", 20, 20, T_SETBLOCK, 0}, {
-	"ICMP6_FILTER_SETBLOCK s 20 f 21", 20, 21, T_SETBLOCK, 1}, {
-	"ICMP6_FILTER_PASSALL s 20", 20, 0, T_SETPASSALL, 1}, {
-	"ICMP6_FILTER_PASSALL s 20", 21, 0, T_SETPASSALL, 1}, {
-	"ICMP6_FILTER_BLOCKALL s 20", 20, 0, T_SETBLOCKALL, 0}, {
-	"ICMP6_FILTER_BLOCKALL s 20", 21, 0, T_SETBLOCKALL, 0}, {
-	"ICMP6_FILTER_WILLBLOCK s 20 f 21", 20, 21, T_WILLBLOCK, 0}, {
-	"ICMP6_FILTER_WILLBLOCK s 20 f 20", 20, 20, T_WILLBLOCK, 1}, {
-	"ICMP6_FILTER_WILLPASS s 20 f 21", 20, 21, T_WILLPASS, 0}, {
-"ICMP6_FILTER_WILLPASS s 22 f 22", 22, 22, T_WILLPASS, 1},};
-
-#define FTCOUNT	(sizeof(ftab)/sizeof(ftab[0]))
-
-int ic6_send1(char *tname, unsigned char type)
+	{"ICMP6_FILTER_SETPASS s 20 f 20", 20, 20, T_SETPASS, 1},
+	{"ICMP6_FILTER_SETPASS s 20 f 21", 20, 21, T_SETPASS, 0},
+	{"ICMP6_FILTER_SETBLOCK s 20 f 20", 20, 20, T_SETBLOCK, 0},
+	{"ICMP6_FILTER_SETBLOCK s 20 f 21", 20, 21, T_SETBLOCK, 1},
+	{"ICMP6_FILTER_PASSALL s 20", 20, 0, T_SETPASSALL, 1},
+	{"ICMP6_FILTER_PASSALL s 20", 21, 0, T_SETPASSALL, 1},
+	{"ICMP6_FILTER_BLOCKALL s 20", 20, 0, T_SETBLOCKALL, 0},
+	{"ICMP6_FILTER_BLOCKALL s 20", 21, 0, T_SETBLOCKALL, 0},
+	{"ICMP6_FILTER_WILLBLOCK s 20 f 21", 20, 21, T_WILLBLOCK, 0},
+	{"ICMP6_FILTER_WILLBLOCK s 20 f 20", 20, 20, T_WILLBLOCK, 1},
+	{"ICMP6_FILTER_WILLPASS s 20 f 21", 20, 21, T_WILLPASS, 0},
+	{"ICMP6_FILTER_WILLPASS s 22 f 22", 22, 22, T_WILLPASS, 1},
+};
+
+#define FTCOUNT	ARRAY_SIZE(ftab)
+
+static int ic6_send1(char *tname, unsigned char type)
 {
 	struct sockaddr_in6 sin6;
 	struct icmp6_hdr ic6;
 	int s;
 
-	s = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
-	if (s == -1) {
-		tst_resm(TBROK, "%s: socket failed", tname);
-		return 1;
-	}
+	s = SAFE_SOCKET(NULL, AF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
+
 	memset(&ic6, 0, sizeof(ic6));
 	ic6.icmp6_type = type;
 	ic6.icmp6_data32[0] = htonl(getpid());
@@ -259,7 +222,7 @@ int ic6_send1(char *tname, unsigned char type)
 	return 0;
 }
 
-int ic6_recv1(char *tname, int sall, int sf)
+static int ic6_recv1(char *tname, int sall, int sf)
 {
 	fd_set readfds, readfds_saved;
 	struct timeval tv;
@@ -302,7 +265,7 @@ int ic6_recv1(char *tname, int sall, int sf)
 				return -1;
 			}
 			/* if packet check succeeds... */
-			if (htonl(pic6->icmp6_data32[0]) == getpid())
+			if (htonl(pic6->icmp6_data32[0]) == (uint32_t)getpid())
 				gotall = 1;
 		}
 		if (FD_ISSET(sf, &readfds)) {
@@ -313,7 +276,7 @@ int ic6_recv1(char *tname, int sall, int sf)
 				return -1;
 			}
 			/* if packet check succeeds... */
-			if (htonl(pic6->icmp6_data32[0]) == getpid())
+			if (htonl(pic6->icmp6_data32[0]) == (uint32_t)getpid())
 				gotone = 1;
 		}
 		memcpy(&readfds, &readfds_saved, sizeof(readfds));
@@ -328,18 +291,14 @@ int ic6_recv1(char *tname, int sall, int sf)
 }
 
 /* functional tests */
-void icmp6_ft(void)
+static void icmp6_ft(void)
 {
 	struct icmp6_filter i6f;
 	int sall, sf;
-	int i;
+	unsigned int i;
+
+	sall = SAFE_SOCKET(NULL, PF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
 
-	sall = socket(PF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
-	if (sall < 0) {
-		tst_resm(TBROK | TERRNO,
-			 "icmp6_ft socket: can't create sall socket");
-		return;
-	}
 	ICMP6_FILTER_SETPASSALL(&i6f);
 	if (setsockopt(sall, IPPROTO_ICMPV6, ICMP6_FILTER, &i6f,
 		       sizeof(i6f)) < 0) {
@@ -347,12 +306,7 @@ void icmp6_ft(void)
 			 "setsockopt pass all ICMP6_FILTER failed");
 	}
 
-	sf = socket(PF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
-	if (sf < 0) {
-		tst_resm(TBROK | TERRNO,
-			 "icmp6_ft socket: can't create test socket");
-		return;
-	}
+	sf = SAFE_SOCKET(NULL, PF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
 
 	int rv;
 
@@ -413,5 +367,3 @@ void icmp6_ft(void)
 			tst_resm(TPASS, "%s", ftab[i].ft_tname);
 	}
 }
-
-int TST_TOTAL = ETCOUNT;
-- 
1.9.3


------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v4 08/11] lib6/asapi_06.c: Cleanup
  2015-07-09  3:05                     ` [LTP] [PATCH v4 01/11] " Zeng Linggang
                                         ` (5 preceding siblings ...)
  2015-07-09  3:05                       ` [LTP] [PATCH v4 07/11] lib6/asapi_05.c: Cleanup Zeng Linggang
@ 2015-07-09  3:05                       ` Zeng Linggang
  2015-07-09  3:05                       ` [LTP] [PATCH v4 09/11] asapi_07: Use 'tst_tmpdir' and more cleanup Zeng Linggang
                                         ` (3 subsequent siblings)
  10 siblings, 0 replies; 55+ messages in thread
From: Zeng Linggang @ 2015-07-09  3:05 UTC (permalink / raw)
  To: alexey.kodanev; +Cc: ltp-list

* Add 'static' before some functions and global variables.
* Use 'tst_tmpdir' and 'tst_rmdir'.
* Remove useless comments.
* Use SAFE_XXX().
* Remove unused variables.
* Modify the format of sotab[] and cmtab[].
* Modify the initialization of sotab[].
* Some cleanup.

Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
 testcases/network/lib6/asapi_06.c | 317 +++++++++++++++-----------------------
 1 file changed, 120 insertions(+), 197 deletions(-)

diff --git a/testcases/network/lib6/asapi_06.c b/testcases/network/lib6/asapi_06.c
index 960ebb5..204bf23 100644
--- a/testcases/network/lib6/asapi_06.c
+++ b/testcases/network/lib6/asapi_06.c
@@ -1,37 +1,21 @@
 /*
+ * Copyright (c) 2015 Fujitsu Ltd.
+ * Copyright (c) International Business Machines  Corp., 2001
  *
- *   Copyright (c) International Business Machines  Corp., 2001
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
  *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
  *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/*
- * Test Name: asapi_06
- *
- * Test Description:
- *  Tests for RFC 3542 section 4 socket options and ancillary data
- *
- * Usage:  <for command-line>
- *  asapi_06
- *
- * HISTORY
- *	05/2005 written by David L Stevens
- *
- * RESTRICTIONS:
- *  None.
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
+ * Author: David L Stevens
  */
 
 #include "config.h"
@@ -57,25 +41,19 @@
 #include <arpa/inet.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
-char *TCID = "asapi_06";	/* Test program identifier.    */
+char *TCID = "asapi_06";
 
 int TST_TOTAL = 1;
 
-pid_t pid;
-
-struct {
-	char *prt_name;
-	int prt_value;
-} ptab[] = {
-};
-
-#define PTCOUNT	(sizeof(ptab)/sizeof(ptab[0]))
+static pid_t pid;
 
 #define READ_TIMEOUT	5	/* secs */
 
-void do_tests(void);
-void setup(void), cleanup(void);
+static void do_tests(void);
+static void setup(void);
+static void cleanup(void);
 
 int main(int argc, char *argv[])
 {
@@ -97,40 +75,40 @@ int main(int argc, char *argv[])
 #define NH_TEST	0x9f
 
 #ifndef IPV6_RECVPKTINFO
-#define IPV6_RECVPKTINFO	-1
+# define IPV6_RECVPKTINFO	-1
 #endif
 #ifndef IPV6_RECVHOPLIMIT
-#define IPV6_RECVHOPLIMIT	-1
+# define IPV6_RECVHOPLIMIT	-1
 #endif
 #ifndef IPV6_RECVRTHDR
-#define IPV6_RECVRTHDR		-1
+# define IPV6_RECVRTHDR		-1
 #endif
 #ifndef IPV6_RECVHOPOPTS
-#define IPV6_RECVHOPOPTS	-1
+# define IPV6_RECVHOPOPTS	-1
 #endif
 #ifndef IPV6_RECVDSTOPTS
-#define IPV6_RECVDSTOPTS	-1
+# define IPV6_RECVDSTOPTS	-1
 #endif
 #ifndef IPV6_RECVTCLASS
-#define IPV6_RECVTCLASS		-1
+# define IPV6_RECVTCLASS		-1
 #endif
 #ifndef IPV6_TCLASS
-#define IPV6_TCLASS		-1
+# define IPV6_TCLASS		-1
 #endif
 #ifndef IPV6_2292PKTINFO
-#define	IPV6_2292PKTINFO	-1
+# define	IPV6_2292PKTINFO	-1
 #endif
 #ifndef IPV6_2292HOPLIMIT
-#define	IPV6_2292HOPLIMIT	-1
+# define	IPV6_2292HOPLIMIT	-1
 #endif
 #ifndef IPV6_2292RTHDR
-#define	IPV6_2292RTHDR		-1
+# define	IPV6_2292RTHDR		-1
 #endif
 #ifndef IPV6_2292HOPOPTS
-#define	IPV6_2292HOPOPTS	-1
+# define	IPV6_2292HOPOPTS	-1
 #endif
 #ifndef IPV6_2292DSTOPTS
-#define	IPV6_2292DSTOPTS	-1
+# define	IPV6_2292DSTOPTS	-1
 #endif
 
 union soval {
@@ -150,7 +128,7 @@ union soval {
 #define IN6_ANY		{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
 
 /* so_clrval and so_setval members are initilized in the body */
-struct soent {
+static struct soent {
 	char *so_tname;
 	int so_opt;
 	int so_dorecv;		/* do receive test? */
@@ -160,73 +138,52 @@ struct soent {
 	union soval so_setval;
 	socklen_t so_valsize;
 } sotab[] = {
-/* RFC 3542, Section 4 */
-	{
-		"IPV6_RECVPKTINFO", IPV6_RECVPKTINFO, 1, IPV6_PKTINFO, 1, { { { { {
-		0}}}}}, { { { { {
-	0}}}}}, sizeof(int)}, {
-		"IPV6_RECVHOPLIMIT", IPV6_RECVHOPLIMIT, 1, IPV6_HOPLIMIT, 1, { { { { {
-		0}}}}}, { { { { {
-	0}}}}}, sizeof(int)}, {
-		"IPV6_RECVRTHDR", IPV6_RECVRTHDR, 0, IPV6_RTHDR, 1, { { { { {
-		0}}}}}, { { { { {
-	0}}}}}, sizeof(int)}, {
-		"IPV6_RECVHOPOPTS", IPV6_RECVHOPOPTS, 0, IPV6_HOPOPTS, 1, { { { { {
-		0}}}}}, { { { { {
-	0}}}}}, sizeof(int)}, {
-		"IPV6_RECVDSTOPTS", IPV6_RECVDSTOPTS, 0, IPV6_DSTOPTS, 1, { { { { {
-		0}}}}}, { { { { {
-	0}}}}}, sizeof(int)}, {
-		"IPV6_RECVTCLASS", IPV6_RECVTCLASS, 1, IPV6_TCLASS, 1, { { { { {
-		0}}}}}, { { { { {
-	0}}}}}, sizeof(int)},
-/* make sure TCLASS stays when setting another opt */
-	{
-		"IPV6_RECVTCLASS (2)", IPV6_RECVHOPLIMIT, 1, IPV6_TCLASS, 0, { { { { {
-		0}}}}}, { { { { {
-	0}}}}}, sizeof(int)},
-/* OLD values */
-	{
-		"IPV6_2292PKTINFO", IPV6_2292PKTINFO, 1, IPV6_2292PKTINFO, 1, { { { { {
-		0}}}}}, { { { { {
-	0}}}}}, sizeof(int)}, {
-		"IPV6_2292HOPLIMIT", IPV6_2292HOPLIMIT, 1, IPV6_2292HOPLIMIT, 1, { { { { {
-		0}}}}}, { { { { {
-	0}}}}}, sizeof(int)}, {
-		"IPV6_2292RTHDR", IPV6_2292RTHDR, 0, IPV6_2292RTHDR, 1, { { { { {
-		0}}}}}, { { { { {
-	0}}}}}, sizeof(int)}, {
-		"IPV6_2292HOPOPTS", IPV6_2292HOPOPTS, 0, IPV6_2292HOPOPTS, 1, { { { { {
-		0}}}}}, { { { { {
-	0}}}}}, sizeof(int)}, {
-		"IPV6_2292DSTOPTS", IPV6_2292DSTOPTS, 0, IPV6_2292DSTOPTS, 1, { { { { {
-		0}}}}}, { { { { {
-0}}}}}, sizeof(int)},};
-
-#define SOCOUNT	(sizeof(sotab)/sizeof(sotab[0]))
+	/* RFC 3542, Section 4 */
+	{"IPV6_RECVPKTINFO", IPV6_RECVPKTINFO, 1, IPV6_PKTINFO, 1,
+	 {{{{{0} } }, 0} }, {{{{{0} } }, 0} }, sizeof(int)},
+	{"IPV6_RECVHOPLIMIT", IPV6_RECVHOPLIMIT, 1, IPV6_HOPLIMIT, 1,
+	 {{{{{0} } }, 0} }, {{{{{0} } }, 0} }, sizeof(int)},
+	{"IPV6_RECVRTHDR", IPV6_RECVRTHDR, 0, IPV6_RTHDR, 1,
+	 {{{{{0} } }, 0} }, {{{{{0} } }, 0} }, sizeof(int)},
+	{"IPV6_RECVHOPOPTS", IPV6_RECVHOPOPTS, 0, IPV6_HOPOPTS, 1,
+	 {{{{{0} } }, 0} }, {{{{{0} } }, 0} }, sizeof(int)},
+	{"IPV6_RECVDSTOPTS", IPV6_RECVDSTOPTS, 0, IPV6_DSTOPTS, 1,
+	 {{{{{0} } }, 0} }, {{{{{0} } }, 0} }, sizeof(int)},
+	{"IPV6_RECVTCLASS", IPV6_RECVTCLASS, 1, IPV6_TCLASS, 1,
+	 {{{{{0} } }, 0} }, {{{{{0} } }, 0} }, sizeof(int)},
+	/* make sure TCLASS stays when setting another opt */
+	{"IPV6_RECVTCLASS (2)", IPV6_RECVHOPLIMIT, 1, IPV6_TCLASS, 0,
+	 {{{{{0} } }, 0} }, {{{{{0} } }, 0} }, sizeof(int)},
+	/* OLD values */
+	{"IPV6_2292PKTINFO", IPV6_2292PKTINFO, 1, IPV6_2292PKTINFO, 1,
+	 {{{{{0} } }, 0} }, {{{{{0} } }, 0} }, sizeof(int)},
+	{"IPV6_2292HOPLIMIT", IPV6_2292HOPLIMIT, 1, IPV6_2292HOPLIMIT, 1,
+	 {{{{{0} } }, 0} }, {{{{{0} } }, 0} }, sizeof(int)},
+	{"IPV6_2292RTHDR", IPV6_2292RTHDR, 0, IPV6_2292RTHDR, 1,
+	 {{{{{0} } }, 0} }, {{{{{0} } }, 0} }, sizeof(int)},
+	{"IPV6_2292HOPOPTS", IPV6_2292HOPOPTS, 0, IPV6_2292HOPOPTS, 1,
+	 {{{{{0} } }, 0} }, {{{{{0} } }, 0} }, sizeof(int)},
+	{"IPV6_2292DSTOPTS", IPV6_2292DSTOPTS, 0, IPV6_2292DSTOPTS, 1,
+	 {{{{{0} } }, 0} }, {{{{{0} } }, 0} }, sizeof(int)},
+};
+
+#define SOCOUNT	ARRAY_SIZE(sotab)
 
 struct soprot {
-	int sop_pid;		/* sender PID */
-	int sop_seq;		/* sequence # */
-	int sop_dlen;		/* tp_dat length */
+	int sop_pid;			/* sender PID */
+	int sop_seq;			/* sequence # */
+	int sop_dlen;			/* tp_dat length */
 	unsigned char sop_dat[0];	/* user data */
 };
 
-unsigned char tpbuf[sizeof(struct soprot) + 2048];
-unsigned char rpbuf[sizeof(struct soprot) + 2048];
+static unsigned char tpbuf[sizeof(struct soprot) + 2048];
+static unsigned char rpbuf[sizeof(struct soprot) + 2048];
 
-unsigned char control[2048];
-int clen;
+static unsigned char control[2048];
 
-int seq;
+static int seq;
 
-int setupso(void)
-{
-/* add routing headers, other ancillary data here */
-	return 0;
-}
-
-struct cme {
+static struct cme {
 	int cm_len;
 	int cm_level;
 	int cm_type;
@@ -235,26 +192,21 @@ struct cme {
 		uint32_t cmu_hops;
 	} cmu;
 } cmtab[] = {
-	{
-		sizeof(uint32_t), SOL_IPV6, IPV6_TCLASS, {
-		0x12}
-	}
-	, {
-		sizeof(uint32_t), SOL_IPV6, IPV6_HOPLIMIT, {
-		0x21}
-	}
-,};
+	{sizeof(uint32_t), SOL_IPV6, IPV6_TCLASS, {0x12} },
+	{sizeof(uint32_t), SOL_IPV6, IPV6_HOPLIMIT, {0x21} },
+};
 
-#define CMCOUNT	(sizeof(cmtab)/sizeof(cmtab[0]))
+#define CMCOUNT	ARRAY_SIZE(cmtab)
 
-ssize_t sendall(int st)
+static ssize_t sendall(int st)
 {
 	struct sockaddr_in6 sin6;
 	struct msghdr msg;
 	struct iovec iov;
 	struct soprot *psop;
 	unsigned char *pd;
-	int i, ctotal;
+	unsigned int i;
+	int ctotal;
 
 	psop = (struct soprot *)tpbuf;
 	psop->sop_pid = htonl(getpid());
@@ -291,7 +243,7 @@ ssize_t sendall(int st)
 	return sendmsg(st, &msg, 0);
 }
 
-void so_test(struct soent *psoe)
+static void so_test(struct soent *psoe)
 {
 	struct sockaddr_in6 sin6;
 	union soval sobuf;
@@ -317,10 +269,9 @@ void so_test(struct soent *psoe)
 	memset(&sin6, 0, sizeof(sin6));
 	sin6.sin6_family = AF_INET6;
 	sin6.sin6_addr = in6addr_loopback;
-	if (bind(sr, (struct sockaddr *)&sin6, sizeof(sin6)) < 0) {
-		tst_resm(TBROK, "%s: bind: %s", psoe->so_tname,
-			 strerror(errno));
-	}
+
+	SAFE_BIND(NULL, sr, (struct sockaddr *)&sin6, sizeof(sin6));
+
 	if (setsockopt(sr, SOL_IPV6, psoe->so_opt, &psoe->so_clrval,
 		       psoe->so_valsize) < 0) {
 		tst_resm(TBROK, "%s: setsockopt: %s", psoe->so_tname,
@@ -345,12 +296,8 @@ void so_test(struct soent *psoe)
 	else
 		tst_resm(TPASS, "%s set-get", psoe->so_tname);
 
-	st = socket(PF_INET6, SOCK_RAW, NH_TEST);
-	if (st < 0) {
-		tst_resm(TBROK, "%s transmit socket: %s", psoe->so_tname,
-			 strerror(errno));
-		return;
-	}
+	st = SAFE_SOCKET(NULL, PF_INET6, SOCK_RAW, NH_TEST);
+
 	if (sendall(st) < 0) {
 		tst_resm(TBROK, "%s transmit sendto: %s", psoe->so_tname,
 			 strerror(errno));
@@ -409,7 +356,7 @@ void so_test(struct soent *psoe)
 					 psoe->so_tname, strerror(errno));
 				return;
 			}
-/* check pid & seq here */
+			/* check pid & seq here */
 			break;
 		}
 		gotone = 0;
@@ -429,7 +376,7 @@ void so_test(struct soent *psoe)
 				return;
 			}
 		}
-/* check contents here */
+		/* check contents here */
 		if (psoe->so_dorecv)
 			tst_resm(gotone ? TPASS : TFAIL, "%s receive",
 				 psoe->so_tname);
@@ -451,20 +398,18 @@ static int ipv6_addr_scope(struct in6_addr *pin6)
 }
 #endif /* HAVE_IFADDRS_H */
 
-int getsock(char *tname, struct sockaddr_in6 *psin6_arg, int scope)
+static int getsock(char *tname, struct sockaddr_in6 *psin6_arg, int scope)
 {
 #ifdef HAVE_IFADDRS_H
 	static struct ifaddrs *pifa_head;
 	struct ifaddrs *pifa;
 	struct sockaddr_in6 *psin6;
-	char strbuf[128];
 	int ifindex = 0;
 	int s;
 
-	if (!pifa_head && getifaddrs(&pifa_head)) {
-		tst_resm(TBROK, "%s: getifaddrs failed", tname);
-		return -1;
-	}
+	if (!pifa_head && getifaddrs(&pifa_head))
+		tst_brkm(TBROK, NULL, "%s: getifaddrs failed", tname);
+
 	if (psin6_arg)
 		ifindex = psin6_arg->sin6_scope_id;
 
@@ -483,21 +428,16 @@ int getsock(char *tname, struct sockaddr_in6 *psin6_arg, int scope)
 		     (this_scope > 0 && this_scope != scope)))
 			continue;
 		psin6->sin6_scope_id = if_nametoindex(pifa->ifa_name);
-		if ((ifindex < 0 && -ifindex == psin6->sin6_scope_id) ||
-		    (ifindex > 0 && ifindex != psin6->sin6_scope_id))
+		if ((ifindex < 0 &&
+		     -(unsigned int)ifindex == psin6->sin6_scope_id) ||
+		    (ifindex > 0 &&
+		     (unsigned int)ifindex != psin6->sin6_scope_id))
 			continue;
-		s = socket(PF_INET6, SOCK_DGRAM, 0);
-		if (s < 0) {
-			tst_resm(TBROK, "%s: socket %s", tname,
-				 strerror(errno));
-			return -1;
-		}
-		if (bind(s, pifa->ifa_addr, sizeof(struct sockaddr_in6)) < 0) {
-			tst_resm(TBROK, "%s: bind \"%s\": %s", tname,
-				 inet_ntop(AF_INET6, &psin6->sin6_addr, strbuf,
-					   sizeof(strbuf)), strerror(errno));
-			return -1;
-		}
+
+		s = SAFE_SOCKET(NULL, PF_INET6, SOCK_DGRAM, 0);
+
+		SAFE_BIND(NULL, s, pifa->ifa_addr, sizeof(struct sockaddr_in6));
+
 		if (psin6_arg) {
 			*psin6_arg = *psin6;
 			psin6_arg->sin6_scope_id =
@@ -539,7 +479,10 @@ int getsock(char *tname, struct sockaddr_in6 *psin6_arg, int scope)
 	}
 	return -1;
 #else /* HAVE_IFADDRS_H */
+/*
 	return -1;
+*/
+	tst_brkm(TBROK, NULL, "HAVE_IFADDRS_H is not defined");
 #endif
 }
 
@@ -548,46 +491,28 @@ int getsock(char *tname, struct sockaddr_in6 *psin6_arg, int scope)
  * RFC 3542 IPV6_PKTINFO not in mainline yet (as of 2.6.15). The get/set
  * tests are below, and comments for some further tests to be added later
  */
-void test_pktinfo(void)
+static void test_pktinfo(void)
 {
-	int s_snd, s_rcv[3] = { -1, -1, -1 };
+	int s_snd;
 	struct sockaddr_in6 sa_rcv[3];
-	int s, i;
-	struct ifaddrs *pifa_head, *pifa;
-	struct sockaddr_in6 *psin6;
 	char strbuf[128];
 	char *tname = "IPV6_PKTINFO";
 	struct in6_pktinfo pi, pi_tmp;
-	int sinlen;
-	int optlen;
+	socklen_t optlen;
 
 	s_snd = getsock(tname, 0, IPV6_ADDR_GLOBAL);
-	if (s_snd < 0) {
-		tst_resm(TBROK, "%s: can't create send socket", tname);
-		return;
-	}
+
 	/* global-scope address, interface X */
 	sa_rcv[0].sin6_scope_id = 0;
-	s_rcv[0] = getsock(tname, &sa_rcv[0], IPV6_ADDR_GLOBAL);
-	if (s_rcv[0] == -1) {
-		tst_resm(TBROK, "%s: only link-scope addresses", tname);
-		return;
-	}
+	getsock(tname, &sa_rcv[0], IPV6_ADDR_GLOBAL);
+
 	/* link-local-scope address, interface X */
 	sa_rcv[1].sin6_scope_id = sa_rcv[0].sin6_scope_id;
-	s_rcv[1] = getsock(tname, &sa_rcv[1], IPV6_ADDR_LINK);
-	if (s_rcv[1] < 0) {
-		tst_resm(TBROK, "%s: no link-local address on ifindex %d",
-			 tname, sa_rcv[0].sin6_scope_id);
-		return;
-	}
+
+	getsock(tname, &sa_rcv[1], IPV6_ADDR_LINK);
 	/* link-local-scope address, interface Y */
 	sa_rcv[2].sin6_scope_id = -sa_rcv[0].sin6_scope_id;
-	s_rcv[2] = getsock(tname, &sa_rcv[2], IPV6_ADDR_LINK);
-	if (s_rcv[2] < 0) {
-		tst_resm(TBROK, "%s: only one interface?", tname);
-		return;
-	}
+	getsock(tname, &sa_rcv[2], IPV6_ADDR_LINK);
 	/* send to rcv1 to verify communication */
 	/* force to rcv2 w/ PKTINFO */
 /* TESTS: */
@@ -615,8 +540,8 @@ void test_pktinfo(void)
 				   sizeof(strbuf2)), pi.ipi6_ifindex);
 	} else
 		tst_resm(TPASS, "%s", tname);
-/* ancillary data override */
-/* link-local, wrong interface */
+	/* ancillary data override */
+	/* link-local, wrong interface */
 	tname = "IPV6_PKTINFO invalid {lladdr, intf}";
 	pi.ipi6_addr = sa_rcv[1].sin6_addr;
 	pi.ipi6_ifindex = sa_rcv[2].sin6_scope_id;
@@ -628,17 +553,12 @@ void test_pktinfo(void)
 		tst_resm(TFAIL, "%s errno %d != %d", tname, TEST_ERRNO, EINVAL);
 	else
 		tst_resm(TPASS, "%s", tname);
-/* nonexistent interface */
-/* non-local address */
-/* clear address */
-/* clear interface */
-/* sendmsg() sin6_scope differs with ancillary data interface */
 }
 #endif /* notyet */
 
-void do_tests(void)
+static void do_tests(void)
 {
-	int i;
+	unsigned int i;
 
 	for (i = 0; i < SOCOUNT; ++i) {
 		sotab[i].so_clrval.sou_bool = 0;
@@ -650,11 +570,14 @@ void do_tests(void)
 #endif /* notyet - see test_pktinfo() comment above */
 }
 
-void setup(void)
+static void setup(void)
 {
-	TEST_PAUSE;		/* if -P option specified */
+	TEST_PAUSE;
+
+	tst_tmpdir();
 }
 
-void cleanup(void)
+static void cleanup(void)
 {
+	tst_rmdir();
 }
-- 
1.9.3


------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v4 09/11] asapi_07: Use 'tst_tmpdir' and more cleanup
  2015-07-09  3:05                     ` [LTP] [PATCH v4 01/11] " Zeng Linggang
                                         ` (6 preceding siblings ...)
  2015-07-09  3:05                       ` [LTP] [PATCH v4 08/11] lib6/asapi_06.c: Cleanup Zeng Linggang
@ 2015-07-09  3:05                       ` Zeng Linggang
  2015-07-09  3:05                       ` [LTP] [PATCH v4 10/11] lib6/getaddrinfo_01.c: Cleanup Zeng Linggang
                                         ` (2 subsequent siblings)
  10 siblings, 0 replies; 55+ messages in thread
From: Zeng Linggang @ 2015-07-09  3:05 UTC (permalink / raw)
  To: alexey.kodanev; +Cc: ltp-list

* Use 'tst_tmpdir' and 'tst_rmdir'.
* Add 'static' for the cleanup.

Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
 testcases/network/lib6/asapi_07.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/testcases/network/lib6/asapi_07.c b/testcases/network/lib6/asapi_07.c
index 826cea6..97221f7 100644
--- a/testcases/network/lib6/asapi_07.c
+++ b/testcases/network/lib6/asapi_07.c
@@ -86,6 +86,7 @@ static struct etent {
 };
 
 static void setup(void);
+static void cleanup(void);
 static void adatet(const struct etent *etptr);
 
 char *TCID = "asapi_07";
@@ -106,12 +107,20 @@ int main(int argc, char *argv[])
 			adatet(&etab[i]);
 	}
 
+	cleanup();
 	tst_exit();
 }
 
 void setup(void)
 {
 	TEST_PAUSE;
+
+	tst_tmpdir();
+}
+
+static void cleanup(void)
+{
+	tst_rmdir();
 }
 
 /*  existence tests */
-- 
1.9.3


------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v4 10/11] lib6/getaddrinfo_01.c: Cleanup
  2015-07-09  3:05                     ` [LTP] [PATCH v4 01/11] " Zeng Linggang
                                         ` (7 preceding siblings ...)
  2015-07-09  3:05                       ` [LTP] [PATCH v4 09/11] asapi_07: Use 'tst_tmpdir' and more cleanup Zeng Linggang
@ 2015-07-09  3:05                       ` Zeng Linggang
  2015-07-09  3:05                       ` [LTP] [PATCH v4 11/11] ipv6_lib: Add it into default Zeng Linggang
  2015-07-15 15:49                       ` [LTP] [PATCH v4 01/11] SAFE_MACROS: Add socket(), bind(), listen(), connect() and getsockname() Alexey Kodanev
  10 siblings, 0 replies; 55+ messages in thread
From: Zeng Linggang @ 2015-07-09  3:05 UTC (permalink / raw)
  To: alexey.kodanev; +Cc: ltp-list

* Add 'static' before some functions and global variables.
* Remove cleanup() function.
* Remove useless comments.
* In every test function, using TINFO instead of TPASS
  marks the success of each inner test.
* Some cleanup.

Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
 testcases/network/lib6/getaddrinfo_01.c | 503 ++++++++++++++++++--------------
 1 file changed, 281 insertions(+), 222 deletions(-)

diff --git a/testcases/network/lib6/getaddrinfo_01.c b/testcases/network/lib6/getaddrinfo_01.c
index ec29b5d..a812e77 100644
--- a/testcases/network/lib6/getaddrinfo_01.c
+++ b/testcases/network/lib6/getaddrinfo_01.c
@@ -1,43 +1,21 @@
 /*
+ * Copyright (c) 2015 Fujitsu Ltd.
+ * Copyright (c) International Business Machines  Corp., 2001
  *
- *   Copyright (c) International Business Machines  Corp., 2001
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
  *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
  *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/*
- * Test Name: getaddrinfo_01
- *
- * Test Description:
- *  Tests for getaddrinfo library function
- *
- * Usage:  <for command-line>
- *  getaddrinfo_01 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -e   : Turn on errno logging.
- *	       -i n : Execute test n times.
- *	       -I x : Execute test for x seconds.
- *	       -P x : Pause for x seconds between iterations.
- *	       -t   : Turn on syscall timing.
- *
- * HISTORY
- *	07/2004 written by David L Stevens
- *
- * RESTRICTIONS:
- *  None.
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
+ * Author: David L Stevens
  */
 
 #include <unistd.h>
@@ -53,40 +31,38 @@
 #define AI_V4MAPPED    0x0008	/* IPv4 mapped addresses are acceptable.  */
 #endif
 
-char *TCID = "getaddrinfo_01";	/* Test program identifier.    */
-int testno;
+static void setup(void);
+static void gaiv4(void);
+static void gaiv6(void);
 
-void setup(void), cleanup(void);
-
-int TST_TOTAL = 1;
-
-/* a host that isn't where LTP is running */
-#define REMOTEHOSTNAME	"www.ibm.com"
-
-void gaiv4(void), gaiv6(void);
-void dumpres(struct addrinfo *);
+char *TCID = "getaddrinfo_01";
+int TST_TOTAL = 2;
 
 int main(int argc, char *argv[])
 {
 	int lc;
 
-	/* Parse standard options given to run the test. */
 	tst_parse_opts(argc, argv, NULL, NULL);
 
 	setup();
 
 	for (lc = 0; TEST_LOOPING(lc); ++lc) {
+		tst_count = 0;
+
 		gaiv4();
 		gaiv6();
 	}
-	cleanup();
 
-	return (0);
+	tst_exit();
 }
 
-/* getaddrinfo tests (v4) */
+static void setup(void)
+{
+	TEST_PAUSE;
+}
 
-void gaiv4(void)
+/* getaddrinfo tests (v4) */
+static void gaiv4(void)
 {
 	struct addrinfo *aires, hints, *pai;
 	char hostname[MAXHOSTNAMELEN + 1];
@@ -132,13 +108,18 @@ void gaiv4(void)
 				 psin ? psin->sin_family : 0,
 				 psin ? psin->sin_port : 0,
 				 psin ? htons(psin->sin_port) : 0);
-		} else
-			tst_resm(TPASS, "getaddrinfo IPv4 basic lookup");
-		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN ? TFAIL : TPASS, "getaddrinfo IPv4 basic "
+			freeaddrinfo(aires);
+			return;
+		} else {
+			tst_resm(TINFO, "getaddrinfo IPv4 basic lookup");
+			freeaddrinfo(aires);
+		}
+	} else {
+		tst_resm(TFAIL, "getaddrinfo IPv4 basic "
 			 "lookup (\"%s\") returns %ld (\"%s\")", hostname,
 			 TEST_RETURN, gai_strerror(TEST_RETURN));
+		return;
+	}
 
 	/* test 2, IPv4 canonical name */
 	memset(&hints, 0, sizeof(hints));
@@ -152,20 +133,26 @@ void gaiv4(void)
 		if (!pai) {
 			tst_resm(TFAIL, "getaddrinfo IPv4 canonical name: no "
 				 "entries with canonical name set");
+			freeaddrinfo(aires);
+			return;
 		} else if (strcasecmp(hostname, pai->ai_canonname)) {
 			tst_resm(TFAIL, "getaddrinfo IPv4 canonical name "
 				 "(\"%s\") doesn't match hostname (\"%s\")",
 				 pai->ai_canonname, hostname);
-		} else
-			tst_resm(TPASS, "getaddrinfo IPv4 canonical name");
-		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN ? TFAIL : TPASS, "getaddrinfo IPv4 "
+			freeaddrinfo(aires);
+			return;
+		} else {
+			tst_resm(TINFO, "getaddrinfo IPv4 canonical name");
+			freeaddrinfo(aires);
+		}
+	} else {
+		tst_resm(TFAIL, "getaddrinfo IPv4 "
 			 "canonical name (\"%s\") returns %ld (\"%s\")",
 			 shortname, TEST_RETURN, gai_strerror(TEST_RETURN));
+		return;
+	}
 
 	/* test 3, IPv4 host+service name */
-
 	memset(&hints, 0, sizeof(hints));
 	/*
 	 * These are hard-coded for echo/7 to avoid using getservbyname(),
@@ -200,13 +187,18 @@ void gaiv4(void)
 				 psin ? psin->sin_family : 0,
 				 psin ? psin->sin_port : 0,
 				 psin ? htons(psin->sin_port) : 0);
-		} else
-			tst_resm(TPASS, "getaddrinfo IPv4 host+service");
-		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN ? TFAIL : TPASS, "getaddrinfo IPv4 host+"
+			freeaddrinfo(aires);
+			return;
+		} else {
+			tst_resm(TINFO, "getaddrinfo IPv4 host+service");
+			freeaddrinfo(aires);
+		}
+	} else {
+		tst_resm(TFAIL, "getaddrinfo IPv4 host+"
 			 "service returns %ld (\"%s\")", TEST_RETURN,
 			 gai_strerror(TEST_RETURN));
+		return;
+	}
 
 	/* test 4, IPv4 hostname+service, AI_PASSIVE */
 	memset(&hints, 0, sizeof(hints));
@@ -244,18 +236,22 @@ void gaiv4(void)
 				 psin ? psin->sin_family : 0,
 				 psin ? psin->sin_port : 0,
 				 psin ? htons(psin->sin_port) : 0);
-		} else
-			tst_resm(TPASS,
+			freeaddrinfo(aires);
+			return;
+		} else {
+			tst_resm(TINFO,
 				 "getaddrinfo IPv4 host+service PASSIVE");
-		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN ? TFAIL : TPASS, "getaddrinfo IPv4 host+"
+			freeaddrinfo(aires);
+		}
+	} else {
+		tst_resm(TFAIL, "getaddrinfo IPv4 host+"
 			 "service, PASSIVE (\"%s\", \"%s\") returns %ld (\"%s\")",
 			 hostname, service, TEST_RETURN,
 			 gai_strerror(TEST_RETURN));
+		return;
+	}
 
 	/* test 5, IPv4 host+service w/ AI_NUMERICHOST */
-
 	memset(&hints, 0, sizeof(hints));
 	strcpy(service, "echo");
 	servnum = 7;
@@ -266,8 +262,11 @@ void gaiv4(void)
 		tst_resm(TFAIL, "getaddrinfo IPv4 AI_NUMERICHOST w/ hostname: "
 			 "returns %ld expected %d (EAI_NONAME)",
 			 TEST_RETURN, EAI_NONAME);
+		if (!TEST_RETURN)
+			freeaddrinfo(aires);
+		return;
 	} else
-		tst_resm(TPASS, "getaddrinfo IPv4 AI_NUMERICHOST w/ hostname");
+		tst_resm(TINFO, "getaddrinfo IPv4 AI_NUMERICHOST w/ hostname");
 	if (!TEST_RETURN)
 		freeaddrinfo(aires);
 
@@ -306,17 +305,28 @@ void gaiv4(void)
 				 psin ? psin->sin_family : 0,
 				 psin ? psin->sin_port : 0,
 				 psin ? htons(psin->sin_port) : 0);
-		} else
-			tst_resm(TPASS, "getaddrinfo IPv4 0+service, PASSIVE");
-		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN == EAI_BADFLAGS ? TPASS : TFAIL,
-			 "getaddrinfo IPv4 0+service, PASSIVE (\"\", \"%s\") "
-			 "returns %ld (\"%s\")", service, TEST_RETURN,
-			 gai_strerror(TEST_RETURN));
+			freeaddrinfo(aires);
+			return;
+		} else {
+			tst_resm(TINFO, "getaddrinfo IPv4 0+service, PASSIVE");
+			freeaddrinfo(aires);
+		}
+	} else {
+		if (TEST_RETURN == EAI_BADFLAGS) {
+			tst_resm(TINFO, "getaddrinfo IPv4 0+service,"
+				" PASSIVE (\"\", \"%s\") returns %ld (\"%s\")",
+				service, TEST_RETURN,
+				gai_strerror(TEST_RETURN));
+		} else {
+			tst_resm(TFAIL, "getaddrinfo IPv4 0+service,i"
+				" PASSIVE (\"\", \"%s\") returns %ld (\"%s\")",
+				service, TEST_RETURN,
+				gai_strerror(TEST_RETURN));
+			return;
+		}
+	}
 
 	/* test 7, IPv4 0+service */
-
 	memset(&hints, 0, sizeof(hints));
 	hints.ai_family = AF_INET;
 	hints.ai_socktype = SOCK_STREAM;
@@ -350,19 +360,30 @@ void gaiv4(void)
 				 psin ? psin->sin_family : 0,
 				 psin ? psin->sin_port : 0,
 				 psin ? htons(psin->sin_port) : 0);
-		} else
-			tst_resm(TPASS, "getaddrinfo IPv4 0+service");
-		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN == EAI_BADFLAGS ? TPASS : TFAIL,
-			 "getaddrinfo IPv4 0+service (\"\", \"%s\") returns %ld "
-			 "(\"%s\")", service, TEST_RETURN,
-			 gai_strerror(TEST_RETURN));
+			freeaddrinfo(aires);
+			return;
+		} else {
+			tst_resm(TINFO, "getaddrinfo IPv4 0+service");
+			freeaddrinfo(aires);
+		}
+	} else {
+		if (TEST_RETURN == EAI_BADFLAGS) {
+			tst_resm(TINFO, "getaddrinfo IPv4 "
+				"0+service (\"\", \"%s\") returns %ld (\"%s\")",
+				service, TEST_RETURN,
+				gai_strerror(TEST_RETURN));
+		} else {
+			tst_resm(TFAIL, "getaddrinfo IPv4 "
+				"0+service (\"\", \"%s\") returns %ld (\"%s\")",
+				service, TEST_RETURN,
+				gai_strerror(TEST_RETURN));
+			return;
+		}
+	}
 
 	/* test 8, IPv4 host+service, AI_NUMERICSERV */
-
 #ifndef AI_NUMERICSERV
-	tst_resm(TFAIL, "getaddrinfo IPv4 host+service, AI_NUMERICSERV: flag "
+	tst_resm(TCONF, "getaddrinfo IPv4 host+service, AI_NUMERICSERV: flag "
 		 "not implemented");
 #else
 	memset(&hints, 0, sizeof(hints));
@@ -376,15 +397,18 @@ void gaiv4(void)
 			 "getaddrinfo IPv4 host+service, AI_NUMERICSERV: "
 			 "returns %ld (\"%s\") expected %d (EAI_NONAME)",
 			 TEST_RETURN, gai_strerror(TEST_RETURN), EAI_NONAME);
-	} else
-		tst_resm(TPASS,
+		if (!TEST_RETURN)
+			freeaddrinfo(aires);
+		return;
+	} else {
+		tst_resm(TINFO,
 			 "getaddrinfo IPv4 host+service, AI_NUMERICSERV");
+	}
 	if (!TEST_RETURN)
 		freeaddrinfo(aires);
 #endif /* AI_NUMERICSERV */
 
 	/* test 9, IPv4 SOCK_STREAM/IPPROTO_UDP hints */
-
 	memset(&hints, 0, sizeof(hints));
 	hints.ai_family = AF_INET;
 	hints.ai_socktype = SOCK_STREAM;
@@ -396,12 +420,13 @@ void gaiv4(void)
 		tst_resm(TFAIL, "getaddrinfo IPv4 SOCK_STREAM/IPPROTO_UDP "
 			 "hints");
 		freeaddrinfo(aires);
-	} else
-		tst_resm(TPASS, "getaddrinfo IPv4 SOCK_STREAM/IPPROTO_UDP "
+		return;
+	} else {
+		tst_resm(TINFO, "getaddrinfo IPv4 SOCK_STREAM/IPPROTO_UDP "
 			 "hints");
+	}
 
 	/* test 10, IPv4 socktype 0, 513 */
-
 	memset(&hints, 0, sizeof(hints));
 	hints.ai_family = AF_INET;
 	hints.ai_socktype = 0;
@@ -439,20 +464,31 @@ void gaiv4(void)
 				 psin ? psin->sin_family : 0,
 				 psin ? psin->sin_port : 0,
 				 psin ? htons(psin->sin_port) : 0);
-		} else if (got_tcp && got_udp)
-			tst_resm(TPASS, "getaddrinfo IPv4 socktype 0,513");
-		else
+			freeaddrinfo(aires);
+			return;
+		} else if (got_tcp && got_udp) {
+			tst_resm(TINFO, "getaddrinfo IPv4 socktype 0,513");
+			freeaddrinfo(aires);
+		} else {
 			tst_resm(TFAIL, "getaddrinfo IPv4 socktype 0,513 TCP %d"
 				 " UDP %d", got_tcp, got_udp);
-		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN == EAI_BADFLAGS ? TPASS : TFAIL,
-			 "getaddrinfo IPv4 socktype 0,513 (\"\", \"%s\") returns"
-			 " %ld (\"%s\")", service, TEST_RETURN,
-			 gai_strerror(TEST_RETURN));
+			freeaddrinfo(aires);
+			return;
+		}
+	} else {
+		if (TEST_RETURN == EAI_BADFLAGS) {
+			tst_resm(TINFO, "getaddrinfo IPv4 socktype 0,513"
+				" (\"\", \"%s\") returns %ld (\"%s\")", service,
+				TEST_RETURN, gai_strerror(TEST_RETURN));
+		} else {
+			tst_resm(TFAIL, "getaddrinfo IPv4 socktype 0,513"
+				" (\"\", \"%s\") returns %ld (\"%s\")", service,
+				TEST_RETURN, gai_strerror(TEST_RETURN));
+			return;
+		}
+	}
 
 	/* test 11, IPv4 AI_V4MAPPED */
-
 	/* AI_V4MAPPED should be ignored because family != AF_INET6 */
 	memset(&hints, 0, sizeof(hints));
 	hints.ai_family = AF_INET;
@@ -482,18 +518,25 @@ void gaiv4(void)
 				 psin ? psin->sin_family : 0,
 				 psin ? psin->sin_port : 0,
 				 psin ? htons(psin->sin_port) : 0);
-		} else
-			tst_resm(TPASS, "getaddrinfo IPv4 AI_V4MAPPED");
-		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN ? TFAIL : TPASS, "getaddrinfo IPv4 "
+			freeaddrinfo(aires);
+			return;
+		} else {
+			tst_resm(TINFO, "getaddrinfo IPv4 AI_V4MAPPED");
+			freeaddrinfo(aires);
+		}
+	} else {
+		tst_resm(TFAIL, "getaddrinfo IPv4 "
 			 "AI_V4MAPPED (\"%s\") returns %ld (\"%s\")", hostname,
 			 TEST_RETURN, gai_strerror(TEST_RETURN));
+		return;
+	}
+
+
+	tst_resm(TPASS, "getaddrinfo tests (v4) succeed");
 }
 
 /* getaddrinfo tests (v6) */
-
-void gaiv6(void)
+static void gaiv6(void)
 {
 	struct addrinfo *aires, hints, *pai;
 	char hostname[MAXHOSTNAMELEN + 1];
@@ -539,13 +582,18 @@ void gaiv6(void)
 				 psin6 ? psin6->sin6_family : 0,
 				 psin6 ? psin6->sin6_port : 0,
 				 psin6 ? htons(psin6->sin6_port) : 0);
-		} else
-			tst_resm(TPASS, "getaddrinfo IPv6 basic lookup");
-		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN ? TFAIL : TPASS, "getaddrinfo IPv6 basic "
+			freeaddrinfo(aires);
+			return;
+		} else {
+			tst_resm(TINFO, "getaddrinfo IPv6 basic lookup");
+			freeaddrinfo(aires);
+		}
+	} else {
+		tst_resm(TFAIL, "getaddrinfo IPv6 basic "
 			 "lookup (\"%s\") returns %ld (\"%s\")", hostname,
 			 TEST_RETURN, gai_strerror(TEST_RETURN));
+		return;
+	}
 
 	/* test 13, IPv6 canonical name */
 	memset(&hints, 0, sizeof(hints));
@@ -559,20 +607,26 @@ void gaiv6(void)
 		if (!pai) {
 			tst_resm(TFAIL, "getaddrinfo IPv6 canonical name: no "
 				 "entries with canonical name set");
+			freeaddrinfo(aires);
+			return;
 		} else if (strcasecmp(hostname, pai->ai_canonname)) {
 			tst_resm(TFAIL, "getaddrinfo IPv6 canonical name "
 				 "(\"%s\") doesn't match hostname (\"%s\")",
 				 pai->ai_canonname, hostname);
-		} else
-			tst_resm(TPASS, "getaddrinfo IPv6 canonical name");
-		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN ? TFAIL : TPASS, "getaddrinfo IPv6 "
+			freeaddrinfo(aires);
+			return;
+		} else {
+			tst_resm(TINFO, "getaddrinfo IPv6 canonical name");
+			freeaddrinfo(aires);
+		}
+	} else {
+		tst_resm(TFAIL, "getaddrinfo IPv6 "
 			 "canonical name (\"%s\") returns %ld (\"%s\")",
 			 shortname, TEST_RETURN, gai_strerror(TEST_RETURN));
+		return;
+	}
 
 	/* test 14, IPv6 host+service name */
-
 	memset(&hints, 0, sizeof(hints));
 	/*
 	 * These are hard-coded for echo/7 to avoid using getservbyname(),
@@ -607,13 +661,18 @@ void gaiv6(void)
 				 psin6 ? psin6->sin6_family : 0,
 				 psin6 ? psin6->sin6_port : 0,
 				 psin6 ? htons(psin6->sin6_port) : 0);
-		} else
-			tst_resm(TPASS, "getaddrinfo IPv6 host+service");
-		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN ? TFAIL : TPASS, "getaddrinfo IPv6 host+"
+			freeaddrinfo(aires);
+			return;
+		} else {
+			tst_resm(TINFO, "getaddrinfo IPv6 host+service");
+			freeaddrinfo(aires);
+		}
+	} else {
+		tst_resm(TFAIL, "getaddrinfo IPv6 host+"
 			 "service returns %ld (\"%s\")", TEST_RETURN,
 			 gai_strerror(TEST_RETURN));
+		return;
+	}
 
 	/* test 15, IPv6 hostname+service, AI_PASSIVE */
 	memset(&hints, 0, sizeof(hints));
@@ -652,18 +711,22 @@ void gaiv6(void)
 				 psin6 ? psin6->sin6_family : 0,
 				 psin6 ? psin6->sin6_port : 0,
 				 psin6 ? htons(psin6->sin6_port) : 0);
-		} else
-			tst_resm(TPASS,
+			freeaddrinfo(aires);
+			return;
+		} else {
+			tst_resm(TINFO,
 				 "getaddrinfo IPv6 host+service PASSIVE");
-		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN ? TFAIL : TPASS, "getaddrinfo IPv6 host+"
+			freeaddrinfo(aires);
+		}
+	} else {
+		tst_resm(TFAIL, "getaddrinfo IPv6 host+"
 			 "service, PASSIVE (\"%s\", \"%s\") returns %ld (\"%s\")",
 			 hostname, service, TEST_RETURN,
 			 gai_strerror(TEST_RETURN));
+		return;
+	}
 
 	/* test 16, IPv6 host+service w/ AI_NUMERICHOST */
-
 	memset(&hints, 0, sizeof(hints));
 	strcpy(service, "echo");
 	servnum = 7;
@@ -674,8 +737,11 @@ void gaiv6(void)
 		tst_resm(TFAIL, "getaddrinfo IPv6 AI_NUMERICHOST w/ hostname: "
 			 "returns %ld expected %d (EAI_NONAME)",
 			 TEST_RETURN, EAI_NONAME);
+		if (!TEST_RETURN)
+			freeaddrinfo(aires);
+		return;
 	} else
-		tst_resm(TPASS, "getaddrinfo IPv6 AI_NUMERICHOST w/ hostname");
+		tst_resm(TINFO, "getaddrinfo IPv6 AI_NUMERICHOST w/ hostname");
 	if (!TEST_RETURN)
 		freeaddrinfo(aires);
 
@@ -715,17 +781,26 @@ void gaiv6(void)
 				 psin6 ? psin6->sin6_family : 0,
 				 psin6 ? psin6->sin6_port : 0,
 				 psin6 ? htons(psin6->sin6_port) : 0);
-		} else
-			tst_resm(TPASS, "getaddrinfo IPv6 0+service, PASSIVE");
-		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN == EAI_BADFLAGS ? TPASS : TFAIL,
-			 "getaddrinfo IPv6 0+service, PASSIVE (\"\", \"%s\") "
-			 "returns %ld (\"%s\")", service, TEST_RETURN,
-			 gai_strerror(TEST_RETURN));
+			freeaddrinfo(aires);
+			return;
+		} else {
+			tst_resm(TINFO, "getaddrinfo IPv6 0+service, PASSIVE");
+			freeaddrinfo(aires);
+		}
+	} else {
+		if (TEST_RETURN == EAI_BADFLAGS) {
+			tst_resm(TINFO, "getaddrinfo IPv6 0+service, PASSIVE"
+				" (\"\", \"%s\") returns %ld (\"%s\")", service,
+				TEST_RETURN, gai_strerror(TEST_RETURN));
+		} else {
+			tst_resm(TFAIL, "getaddrinfo IPv6 0+service, PASSIVE"
+				" (\"\", \"%s\") returns %ld (\"%s\")", service,
+				TEST_RETURN, gai_strerror(TEST_RETURN));
+			return;
+		}
+	}
 
 	/* test 18, IPv6 0+service */
-
 	memset(&hints, 0, sizeof(hints));
 	hints.ai_family = AF_INET6;
 	hints.ai_socktype = SOCK_STREAM;
@@ -760,19 +835,28 @@ void gaiv6(void)
 				 psin6 ? psin6->sin6_family : 0,
 				 psin6 ? psin6->sin6_port : 0,
 				 psin6 ? htons(psin6->sin6_port) : 0);
-		} else
-			tst_resm(TPASS, "getaddrinfo IPv6 0+service");
-		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN == EAI_BADFLAGS ? TPASS : TFAIL,
-			 "getaddrinfo IPv6 0+service (\"\", \"%s\") returns %ld "
-			 "(\"%s\")", service, TEST_RETURN,
-			 gai_strerror(TEST_RETURN));
+			freeaddrinfo(aires);
+			return;
+		} else {
+			tst_resm(TINFO, "getaddrinfo IPv6 0+service");
+			freeaddrinfo(aires);
+		}
+	} else {
+		if (TEST_RETURN == EAI_BADFLAGS) {
+			tst_resm(TINFO, "getaddrinfo IPv6 0+service"
+				" (\"\", \"%s\") returns %ld (\"%s\")", service,
+				TEST_RETURN, gai_strerror(TEST_RETURN));
+		} else {
+			tst_resm(TFAIL, "getaddrinfo IPv6 0+service"
+				" (\"\", \"%s\") returns %ld (\"%s\")", service,
+				TEST_RETURN, gai_strerror(TEST_RETURN));
+			return;
+		}
+	}
 
 	/* test 19, IPv6 host+service, AI_NUMERICSERV */
-
 #ifndef AI_NUMERICSERV
-	tst_resm(TFAIL, "getaddrinfo IPv6 host+service, AI_NUMERICSERV: flag "
+	tst_resm(TCONF, "getaddrinfo IPv6 host+service, AI_NUMERICSERV: flag "
 		 "not implemented");
 #else
 	memset(&hints, 0, sizeof(hints));
@@ -786,15 +870,17 @@ void gaiv6(void)
 			 "getaddrinfo IPv6 host+service, AI_NUMERICSERV: "
 			 "returns %ld (\"%s\") expected %d (EAI_NONAME)",
 			 TEST_RETURN, gai_strerror(TEST_RETURN), EAI_NONAME);
+		if (!TEST_RETURN)
+			freeaddrinfo(aires);
+		return;
 	} else
-		tst_resm(TPASS,
+		tst_resm(TINFO,
 			 "getaddrinfo IPv6 host+service, AI_NUMERICSERV");
 	if (!TEST_RETURN)
 		freeaddrinfo(aires);
 #endif /* AI_NUMERICSERV */
 
 	/* test 20, IPv6 SOCK_STREAM/IPPROTO_UDP hints */
-
 	memset(&hints, 0, sizeof(hints));
 	hints.ai_family = AF_INET6;
 	hints.ai_socktype = SOCK_STREAM;
@@ -806,12 +892,13 @@ void gaiv6(void)
 		tst_resm(TFAIL, "getaddrinfo IPv6 SOCK_STREAM/IPPROTO_UDP "
 			 "hints");
 		freeaddrinfo(aires);
-	} else
-		tst_resm(TPASS, "getaddrinfo IPv6 SOCK_STREAM/IPPROTO_UDP "
+		return;
+	} else {
+		tst_resm(TINFO, "getaddrinfo IPv6 SOCK_STREAM/IPPROTO_UDP "
 			 "hints");
+	}
 
 	/* test 21, IPv6 socktype 0, 513 */
-
 	memset(&hints, 0, sizeof(hints));
 	hints.ai_family = AF_INET6;
 	hints.ai_socktype = 0;
@@ -850,20 +937,31 @@ void gaiv6(void)
 				 psin6 ? psin6->sin6_family : 0,
 				 psin6 ? psin6->sin6_port : 0,
 				 psin6 ? htons(psin6->sin6_port) : 0);
-		} else if (got_tcp && got_udp)
-			tst_resm(TPASS, "getaddrinfo IPv6 socktype 0,513");
-		else
+			freeaddrinfo(aires);
+			return;
+		} else if (got_tcp && got_udp) {
+			tst_resm(TINFO, "getaddrinfo IPv6 socktype 0,513");
+			freeaddrinfo(aires);
+		} else {
 			tst_resm(TFAIL, "getaddrinfo IPv6 socktype 0,513 TCP %d"
 				 " UDP %d", got_tcp, got_udp);
-		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN == EAI_BADFLAGS ? TPASS : TFAIL,
-			 "getaddrinfo IPv6 socktype 0,513 (\"\", \"%s\") returns"
-			 " %ld (\"%s\")", service, TEST_RETURN,
-			 gai_strerror(TEST_RETURN));
+			freeaddrinfo(aires);
+			return;
+		}
+	} else {
+		if (TEST_RETURN == EAI_BADFLAGS) {
+			tst_resm(TINFO, "getaddrinfo IPv6 socktype 0,513"
+				" (\"\", \"%s\") returns %ld (\"%s\")", service,
+				TEST_RETURN, gai_strerror(TEST_RETURN));
+		} else {
+			tst_resm(TFAIL, "getaddrinfo IPv6 socktype 0,513"
+				" (\"\", \"%s\") returns %ld (\"%s\")", service,
+				TEST_RETURN, gai_strerror(TEST_RETURN));
+			return;
+		}
+	}
 
 	/* test 22, IPv6 AI_V4MAPPED */
-
 	memset(&hints, 0, sizeof(hints));
 	hints.ai_family = AF_INET6;
 	hints.ai_flags = AI_V4MAPPED;
@@ -892,57 +990,18 @@ void gaiv6(void)
 				 psin6 ? psin6->sin6_family : 0,
 				 psin6 ? psin6->sin6_port : 0,
 				 psin6 ? htons(psin6->sin6_port) : 0);
-		} else
-			tst_resm(TPASS, "getaddrinfo IPv6 AI_V4MAPPED");
-		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN ? TFAIL : TPASS, "getaddrinfo IPv6 "
+			freeaddrinfo(aires);
+			return;
+		} else {
+			tst_resm(TINFO, "getaddrinfo IPv6 AI_V4MAPPED");
+			freeaddrinfo(aires);
+		}
+	} else {
+		tst_resm(TFAIL, "getaddrinfo IPv6 "
 			 "AI_V4MAPPED (\"%s\") returns %ld (\"%s\")", hostname,
 			 TEST_RETURN, gai_strerror(TEST_RETURN));
-}
-
-/* this prints an addrinfo list; useful for debugging */
-void dumpres(struct addrinfo *pai)
-{
-	int count = 1;
-	for (; pai; pai = pai->ai_next, count++) {
-		printf("result %d [0x%p]\n", count, pai);
-		printf("\tai_flags %x\n", pai->ai_flags);
-		printf("\tai_family %d\n", pai->ai_family);
-		printf("\tai_socktype %d\n", pai->ai_socktype);
-		printf("\tai_protocol %d\n", pai->ai_protocol);
-		printf("\tai_addrlen %d\n", pai->ai_addrlen);
-		printf("\tai_canonname \"%s\"\n", pai->ai_canonname);
-		printf("\tai_addr.sa_family %x\n", pai->ai_addr->sa_family);
-		if (pai->ai_addr->sa_family == AF_INET) {
-			char buf[1024];
-			struct sockaddr_in *psin =
-			    (struct sockaddr_in *)pai->ai_addr;
-
-			if (!inet_ntop(AF_INET, &psin->sin_addr, buf,
-				       sizeof(buf)))
-				buf[0] = '\0';
-			printf("\tai_addr.sin_addr \"%s\"\n", buf);
-		} else if (pai->ai_addr->sa_family == AF_INET6) {
-			char buf[1024];
-
-			struct sockaddr_in6 *psin6 =
-			    (struct sockaddr_in6 *)pai->ai_addr;
-			if (!inet_ntop(AF_INET6, &psin6->sin6_addr, buf,
-				       sizeof(buf)))
-				buf[0] = '\0';
-			printf("\tai_addr.sin6_addr \"%s\"\n", buf);
-
-		}
-		printf("\tai_next %p\n", pai->ai_next);
+		return;
 	}
-}
 
-void setup(void)
-{
-	TEST_PAUSE;		/* if -P option specified */
-}
-
-void cleanup(void)
-{
+	tst_resm(TPASS, "getaddrinfo tests (v6) succeed");
 }
-- 
1.9.3


------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v4 11/11] ipv6_lib: Add it into default
  2015-07-09  3:05                     ` [LTP] [PATCH v4 01/11] " Zeng Linggang
                                         ` (8 preceding siblings ...)
  2015-07-09  3:05                       ` [LTP] [PATCH v4 10/11] lib6/getaddrinfo_01.c: Cleanup Zeng Linggang
@ 2015-07-09  3:05                       ` Zeng Linggang
  2015-07-15 15:49                       ` [LTP] [PATCH v4 01/11] SAFE_MACROS: Add socket(), bind(), listen(), connect() and getsockname() Alexey Kodanev
  10 siblings, 0 replies; 55+ messages in thread
From: Zeng Linggang @ 2015-07-09  3:05 UTC (permalink / raw)
  To: alexey.kodanev; +Cc: ltp-list

Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
 scenario_groups/default | 1 +
 1 file changed, 1 insertion(+)

diff --git a/scenario_groups/default b/scenario_groups/default
index 3a55702..60b1b27 100644
--- a/scenario_groups/default
+++ b/scenario_groups/default
@@ -32,3 +32,4 @@ dma_thread_diotest
 cpuacct
 can
 cpuhotplug
+ipv6_lib
-- 
1.9.3


------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 55+ messages in thread

* Re: [LTP] [PATCH v4 01/11] SAFE_MACROS: Add socket(), bind(), listen(), connect() and getsockname()
  2015-07-09  3:05                     ` [LTP] [PATCH v4 01/11] " Zeng Linggang
                                         ` (9 preceding siblings ...)
  2015-07-09  3:05                       ` [LTP] [PATCH v4 11/11] ipv6_lib: Add it into default Zeng Linggang
@ 2015-07-15 15:49                       ` Alexey Kodanev
  2015-07-16  2:30                         ` Zeng Linggang
  2015-07-16  5:30                         ` [LTP] [PATCH v5 " Zeng Linggang
  10 siblings, 2 replies; 55+ messages in thread
From: Alexey Kodanev @ 2015-07-15 15:49 UTC (permalink / raw)
  To: Zeng Linggang; +Cc: ltp-list

Hi,
On 07/09/2015 06:05 AM, Zeng Linggang wrote:
> +int safe_bind(const char *file, const int lineno, void (cleanup_fn)(void),
> +	      int socket, const struct sockaddr *address,
> +	      socklen_t address_len)
> +{
> +	int err, ret, i;
> +
> +	for (i = 0; i < 30; i++) {
> +		ret = bind(socket, address, address_len);
> +		err = errno;
> +
> +		if (!ret)
> +			return 0;
> +
> +		tst_resm(TINFO, "bind('%p') failed with %s, try %2i...",
> +			 address, tst_strerrno(err), i+1);
> +

I'd wait only if errno is EADDRINUSE; otherwise exit with TBROK 
immediately. And waiting for 3 seconds in the loop is too small, please 
increase the time.

The rest looks good.

Thanks,
Alexey

------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [LTP] [PATCH v4 01/11] SAFE_MACROS: Add socket(), bind(), listen(), connect() and getsockname()
  2015-07-15 15:49                       ` [LTP] [PATCH v4 01/11] SAFE_MACROS: Add socket(), bind(), listen(), connect() and getsockname() Alexey Kodanev
@ 2015-07-16  2:30                         ` Zeng Linggang
  2015-07-16  5:30                         ` [LTP] [PATCH v5 " Zeng Linggang
  1 sibling, 0 replies; 55+ messages in thread
From: Zeng Linggang @ 2015-07-16  2:30 UTC (permalink / raw)
  To: Alexey Kodanev; +Cc: ltp-list

Hi,

On Wed, 2015-07-15 at 18:49 +0300, Alexey Kodanev wrote:
> Hi,
> On 07/09/2015 06:05 AM, Zeng Linggang wrote:
> > +int safe_bind(const char *file, const int lineno, void (cleanup_fn)(void),
> > +	      int socket, const struct sockaddr *address,
> > +	      socklen_t address_len)
> > +{
> > +	int err, ret, i;
> > +
> > +	for (i = 0; i < 30; i++) {
> > +		ret = bind(socket, address, address_len);
> > +		err = errno;
> > +
> > +		if (!ret)
> > +			return 0;
> > +
> > +		tst_resm(TINFO, "bind('%p') failed with %s, try %2i...",
> > +			 address, tst_strerrno(err), i+1);
> > +
> 
> I'd wait only if errno is EADDRINUSE; otherwise exit with TBROK 
> immediately. And waiting for 3 seconds in the loop is too small, please 
> increase the time.
> 

Yeah, you are right.
It is a typo that I missed one zero. :)

Thanks for your comments and
best regards,
zeng

> The rest looks good.
> 
> Thanks,
> Alexey



------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v5 01/11] SAFE_MACROS: Add socket(), bind(), listen(), connect() and getsockname()
  2015-07-15 15:49                       ` [LTP] [PATCH v4 01/11] SAFE_MACROS: Add socket(), bind(), listen(), connect() and getsockname() Alexey Kodanev
  2015-07-16  2:30                         ` Zeng Linggang
@ 2015-07-16  5:30                         ` Zeng Linggang
  2015-07-16  5:30                           ` [LTP] [PATCH v5 02/11] lib6/runcc.c: Cleanup Zeng Linggang
                                             ` (10 more replies)
  1 sibling, 11 replies; 55+ messages in thread
From: Zeng Linggang @ 2015-07-16  5:30 UTC (permalink / raw)
  To: alexey.kodanev; +Cc: ltp-list

Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
 include/safe_macros.h |   1 +
 include/safe_net.h    |  54 +++++++++++++++++++++++
 lib/safe_net.c        | 119 ++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 174 insertions(+)
 create mode 100644 include/safe_net.h
 create mode 100644 lib/safe_net.c

diff --git a/include/safe_macros.h b/include/safe_macros.h
index 0e7651d..1a09af6 100644
--- a/include/safe_macros.h
+++ b/include/safe_macros.h
@@ -28,6 +28,7 @@
 #include <dirent.h>
 
 #include "safe_stdio.h"
+#include "safe_net.h"
 
 char*	safe_basename(const char *file, const int lineno,
 	    void (*cleanup_fn)(void), char *path);
diff --git a/include/safe_net.h b/include/safe_net.h
new file mode 100644
index 0000000..2c9ddb6
--- /dev/null
+++ b/include/safe_net.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2015 Fujitsu Ltd.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef __SAFE_NET_H__
+#define __SAFE_NET_H__
+
+#include <sys/types.h>
+#include <sys/socket.h>
+
+int safe_socket(const char *file, const int lineno, void (cleanup_fn)(void),
+		int domain, int type, int protocol);
+#define SAFE_SOCKET(cleanup_fn, domain, type, protocol) \
+	safe_socket(__FILE__, __LINE__, (cleanup_fn), domain, type, protocol)
+
+int safe_bind(const char *file, const int lineno, void (cleanup_fn)(void),
+	      int socket, const struct sockaddr *address,
+	      socklen_t address_len);
+#define SAFE_BIND(cleanup_fn, socket, address, address_len) \
+	safe_bind(__FILE__, __LINE__, (cleanup_fn), socket, address, \
+		  address_len)
+
+int safe_listen(const char *file, const int lineno, void (cleanup_fn)(void),
+		int socket, int backlog);
+#define SAFE_LISTEN(cleanup_fn, socket, backlog) \
+	safe_listen(__FILE__, __LINE__, (cleanup_fn), socket, backlog)
+
+int safe_connect(const char *file, const int lineno, void (cleanup_fn)(void),
+		 int sockfd, const struct sockaddr *addr, socklen_t addrlen);
+#define SAFE_CONNECT(cleanup_fn, sockfd, addr, addrlen) \
+	safe_connect(__FILE__, __LINE__, (cleanup_fn), sockfd, addr, addrlen)
+
+int safe_getsockname(const char *file, const int lineno,
+		     void (cleanup_fn)(void), int sockfd, struct sockaddr *addr,
+		     socklen_t *addrlen);
+#define SAFE_GETSOCKNAME(cleanup_fn, sockfd, addr, addrlen) \
+	safe_getsockname(__FILE__, __LINE__, (cleanup_fn), sockfd, addr, \
+			 addrlen)
+
+#endif /* __SAFE_NET_H__ */
diff --git a/lib/safe_net.c b/lib/safe_net.c
new file mode 100644
index 0000000..48c4056
--- /dev/null
+++ b/lib/safe_net.c
@@ -0,0 +1,119 @@
+/*
+ * Copyright (c) 2015 Fujitsu Ltd.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <errno.h>
+#include "test.h"
+#include "safe_net.h"
+
+int safe_socket(const char *file, const int lineno, void (cleanup_fn)(void),
+		int domain, int type, int protocol)
+{
+	int rval;
+
+	rval = socket(domain, type, protocol);
+
+	if (rval < 0) {
+		tst_brkm(TBROK | TERRNO, cleanup_fn,
+			 "%s:%d: socket(%d, %d, %d) failed", file, lineno,
+			 domain, type, protocol);
+	}
+
+	return rval;
+}
+
+int safe_bind(const char *file, const int lineno, void (cleanup_fn)(void),
+	      int socket, const struct sockaddr *address,
+	      socklen_t address_len)
+{
+	int err, ret, i;
+
+	for (i = 0; i < 30; i++) {
+		ret = bind(socket, address, address_len);
+		err = errno;
+
+		if (!ret)
+			return 0;
+
+		if (err != EADDRINUSE) {
+			tst_brkm(TBROK | TERRNO, cleanup_fn,
+				 "%s:%d: bind(%d, %p, %d) failed", file, lineno,
+				 socket, address, address_len);
+		}
+
+		tst_resm(TINFO, "bind('%p') failed with %s, try %2i...",
+			 address, tst_strerrno(err), i+1);
+
+		if (i == 0 && err == EADDRINUSE)
+			tst_resm(TINFO, "The given address is already in use.");
+
+		usleep(1000000);
+	}
+
+	tst_brkm(TBROK | TERRNO, cleanup_fn,
+		 "%s:%d: Failed to bind(%d, %p, %d) after 30 retries",
+		 file, lineno, socket, address, address_len);
+}
+
+int safe_listen(const char *file, const int lineno, void (cleanup_fn)(void),
+		int socket, int backlog)
+{
+	int rval;
+
+	rval = listen(socket, backlog);
+
+	if (rval < 0) {
+		tst_brkm(TBROK | TERRNO, cleanup_fn,
+			 "%s:%d: listen(%d, %d) failed", file, lineno, socket,
+			 backlog);
+	}
+
+	return rval;
+}
+
+int safe_connect(const char *file, const int lineno, void (cleanup_fn)(void),
+		 int sockfd, const struct sockaddr *addr, socklen_t addrlen)
+{
+	int rval;
+
+	rval = connect(sockfd, addr, addrlen);
+
+	if (rval < 0) {
+		tst_brkm(TBROK | TERRNO, cleanup_fn,
+			 "%s:%d: connect(%d, %p, %d) failed", file, lineno,
+			 sockfd, addr, addrlen);
+	}
+
+	return rval;
+}
+
+int safe_getsockname(const char *file, const int lineno,
+		     void (cleanup_fn)(void), int sockfd, struct sockaddr *addr,
+		     socklen_t *addrlen)
+{
+	int rval;
+
+	rval = getsockname(sockfd, addr, addrlen);
+
+	if (rval < 0) {
+		tst_brkm(TBROK | TERRNO, cleanup_fn,
+			 "%s:%d: getsockname(%d, %p, %p) failed", file, lineno,
+			 sockfd, addr, addrlen);
+	}
+
+	return rval;
+}
-- 
1.9.3


------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v5 02/11] lib6/runcc.c: Cleanup
  2015-07-16  5:30                         ` [LTP] [PATCH v5 " Zeng Linggang
@ 2015-07-16  5:30                           ` Zeng Linggang
  2015-08-05 17:17                             ` Cyril Hrubis
  2015-07-16  5:30                           ` [LTP] [PATCH v5 03/11] asapi_01: Use 'tst_tmpdir' and more cleanup Zeng Linggang
                                             ` (9 subsequent siblings)
  10 siblings, 1 reply; 55+ messages in thread
From: Zeng Linggang @ 2015-07-16  5:30 UTC (permalink / raw)
  To: alexey.kodanev; +Cc: ltp-list

* Add 'static' before some functions and global variables.

* Not use 'mkstemp', use 'tst_tmpdir and tst_rmdir' in actual test.

* Use 'SAFE_FILE_PRINTF' instead of 'open-write-close'.

* Change 'runcc', 'aliascheck', 'funccheck', 'structcheck' and
  'valuecheck' to non-return because of the ignore return value.

* Use 'MACRO' instead of 'const char *'.

* Some cleanup.

Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
 testcases/network/lib6/runcc.c | 177 ++++++++++++++++-------------------------
 testcases/network/lib6/runcc.h |  52 +++++++-----
 2 files changed, 100 insertions(+), 129 deletions(-)

diff --git a/testcases/network/lib6/runcc.c b/testcases/network/lib6/runcc.c
index 91a0b16..cfc283c 100644
--- a/testcases/network/lib6/runcc.c
+++ b/testcases/network/lib6/runcc.c
@@ -1,31 +1,21 @@
 /*
+ * Copyright (c) 2015 Fujitsu Ltd.
+ * Copyright (c) International Business Machines  Corp., 2001
  *
- *   Copyright (c) International Business Machines  Corp., 2001
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
  *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
  *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/*
- * runcc.a - common functions for lib6 testing
- *
- * HISTORY
- *	05/2005 written by David L Stevens
- *
- * RESTRICTIONS:
- *  None.
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
+ * Author: David L Stevens
  */
 
 #include <stdio.h>
@@ -34,20 +24,23 @@
 #include <ctype.h>
 
 #include <sys/wait.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
 
 #include "test.h"
 
-char fieldref[1024];
-char program[8192];
+static char fieldref[1024];
+static char program[8192];
 
-char *filetmpl = "/tmp/%.*s_XXXXXX";
+#define FILETMPL	"./%.*s"
 
-char cmd[1024];
+static char cmd[1024];
 
 /*
  * like strspn, with ASCII, numbers and underscore only
  */
-int strfpn(char *name)
+static int strfpn(char *name)
 {
 	int i;
 
@@ -57,31 +50,17 @@ int strfpn(char *name)
 	return i;
 }
 
-int runcc(char *tname, char *filename0, char *program)
+static void runcc(char *tname, char *filename0, char *program)
 {
 	static char filename[1024];
-	int fd, es, saved_errno;
+	int es;
 	char *cflags = "";
 
-	fd = mkstemp(filename0);
-	if (fd < 0) {
-		perror("mkstemp");
-		return -1;
-	}
 	strncpy(filename, filename0, sizeof(filename) - 1);
 	filename[sizeof(filename) - 1] = '\0';
 	strncat(filename, ".c", sizeof(filename) - strlen(filename) - 1);
-	if (rename(filename0, filename) < 0) {
-		perror("rename");
-		unlink(filename0);
-		return -1;
-	}
-	if (write(fd, program, strlen(program)) < 0) {
-		perror("write");
-		unlink(filename);
-		return -1;
-	}
-	(void)close(fd);
+
+	SAFE_FILE_PRINTF(NULL, filename, "%s", program);
 
 	cflags = getenv("CFLAGS");
 	if (cflags == NULL) {
@@ -89,19 +68,13 @@ int runcc(char *tname, char *filename0, char *program)
 		cflags = "";
 	}
 
-	snprintf(cmd, sizeof(cmd), "%s %s -o %s %s > /tmp/test 2>&1", "cc",
+	snprintf(cmd, sizeof(cmd), "%s %s -o %s %s > test 2>&1", "cc",
 		 cflags, filename0, filename);
 	es = system(cmd);
 	if (WEXITSTATUS(es) == 127) {
-		tst_resm(TBROK, "can't run C compiler: \"%s\"", cmd);
-		if (unlink(filename) < 0)
-			tst_resm(TWARN, "%s; unlink \"%s\" failed: %s", tname,
-				 filename, strerror(errno));
-		return -1;
+		tst_brkm(TBROK | TERRNO, NULL, "can't run C compiler: \"%s\"",
+			 cmd);
 	}
-	if (unlink(filename) < 0)
-		tst_resm(TWARN, "%s: unlink \"%s\" failed: %s", tname,
-			 filename, strerror(errno));
 
 	if (WIFSIGNALED(es) &&
 	    (WTERMSIG(es) == SIGINT || WTERMSIG(es) == SIGQUIT))
@@ -109,101 +82,91 @@ int runcc(char *tname, char *filename0, char *program)
 
 	if (WEXITSTATUS(es)) {
 		tst_resm(TFAIL, "%s: not present", tname);
-		return -1;
+		return;
 	}
 	/* run the test */
 
 	es = system(filename0);
-	saved_errno = errno;
-	if (unlink(filename0) < 0)
-		tst_resm(TWARN, "%s: unlink \"%s\" failed: %s", tname,
-			 filename0, strerror(errno));
 
 	if (WIFSIGNALED(es) &&
 	    (WTERMSIG(es) == SIGINT || WTERMSIG(es) == SIGQUIT))
 		exit(1);
 
 	if (WEXITSTATUS(es) == 127)
-		tst_resm(TBROK, "%s: can't run \"%s\": %s", tname, filename0,
-			 strerror(saved_errno));
+		tst_resm(TBROK | TERRNO, "%s: can't run \"%s\"", tname,
+			 filename0);
 	if (WEXITSTATUS(es))
 		tst_resm(TFAIL, "%s: present, but incorrect", tname);
 	else
 		tst_resm(TPASS, "%s present and correct", tname);
-	return 0;
 }
 
-char *field_fmt = "\n\texit((offsetof(struct %s, %s) != %s) || "
-    "sizeof(tst.%s) != (%s));\n";
+#define FIELD_FMT	"\n\texit((offsetof(struct %s, %s) != %s) || " \
+			"sizeof(tst.%s) != (%s));\n"
 /* no offset check */
-char *field_fmt2 = "\n\texit(sizeof(tst.%s) != (%s));\n";
+#define FIELD_FMT2	"\n\texit(sizeof(tst.%s) != (%s));\n"
 
-const char *stmpl =
-    "%s\n#ifndef offsetof\n"
-    "#define offsetof(dtype, dfield) ((int)&((dtype *)0)->dfield)\n"
-    "#endif\n\nstruct %s tst;\n\nmain(int argc, char *argv[])\n{\n\t%s\n}\n";
+#define STMPL	"%s#include <stdlib.h>\n\n\n" \
+		"#ifndef offsetof\n" \
+		"#define offsetof(dtype, dfield) " \
+		"((int)&((dtype *)0)->dfield)\n" \
+		"#endif\n\nstruct %s tst;\n\n" \
+		"int main(int argc, char *argv[])\n{\n\t%s\n}\n"
 
-int
-structcheck(char *tname, char *incl, char *structure, char *field,
-	    char *offset, char *size)
+void structcheck(char *tname, char *incl, char *structure, char *field,
+		 char *offset, char *size)
 {
-	int rv;
 	static char filename[1024];
 
 	if (offset)
-		sprintf(fieldref, field_fmt, structure, field, offset, field,
+		sprintf(fieldref, FIELD_FMT, structure, field, offset, field,
 			size);
 	else
-		sprintf(fieldref, field_fmt2, field, size);
-	sprintf(program, stmpl, incl, structure, fieldref);
-	snprintf(filename, sizeof(filename), filetmpl, strfpn(structure),
+		sprintf(fieldref, FIELD_FMT2, field, size);
+	sprintf(program, STMPL, incl, structure, fieldref);
+	snprintf(filename, sizeof(filename), FILETMPL, strfpn(structure),
 		 structure);
-	rv = runcc(tname, filename, program);
-	return rv;
+	runcc(tname, filename, program);
 }
 
-char *aliasfmt =
-    "exit(&tst.%s != &tst.%s || sizeof(tst.%s) != sizeof(tst.%s));";
+#define ALIASFMT	"exit(&tst.%s != &tst.%s || " \
+			"sizeof(tst.%s) != sizeof(tst.%s));"
 
-int
-aliascheck(char *tname, char *incl, char *structure, char *field, char *dname)
+void aliascheck(char *tname, char *incl, char *structure, char *field,
+		char *dname)
 {
-	int rv;
 	static char filename[1024];
 
-	sprintf(fieldref, aliasfmt, field, dname, field, dname);
-	sprintf(program, stmpl, incl, structure, fieldref);
-	snprintf(filename, sizeof(filename), filetmpl, strfpn(structure),
+	sprintf(fieldref, ALIASFMT, field, dname, field, dname);
+	sprintf(program, STMPL, incl, structure, fieldref);
+	snprintf(filename, sizeof(filename), FILETMPL, strfpn(structure),
 		 structure);
-	rv = runcc(tname, filename, program);
-	return rv;
+	runcc(tname, filename, program);
 }
 
-const char *dtmpl =
-    "%s\n\nmain(int argc, char *argv[])\n{\n\texit((%s) != (%s));\n}\n";
+#define DTMPL	"%s#include <stdlib.h>\n\n\n" \
+		"int main(int argc, char *argv[])\n" \
+		"{\n\texit((%s) != (%s));\n}\n"
 
-int valuecheck(char *tname, char *incl, char *dname, char *dval)
+void valuecheck(char *tname, char *incl, char *dname, char *dval)
 {
-	int rv;
 	static char filename[1024];
 
-	sprintf(program, dtmpl, incl, dname, dval);
-	snprintf(filename, sizeof(filename), filetmpl, strfpn(dname), dname);
-	rv = runcc(tname, filename, program);
-	return rv;
+	sprintf(program, DTMPL, incl, dname, dval);
+	snprintf(filename, sizeof(filename), FILETMPL, strfpn(dname), dname);
+	runcc(tname, filename, program);
 }
 
-const char *ftmpl =
-    "%s\n\nmain(int argc, char *argv[])\n{\n#ifdef %s\n\texit(0);\n#else\n"
-    "\tsyntax error;\n#endif\n}\n";
+#define FTMPL	"%s#include <stdlib.h>\n\n\n" \
+		"int main(int argc, char *argv[])\n" \
+		"{\n#ifdef %s\n\texit(0);\n#else\n" \
+		"\tsyntax error;\n#endif\n}\n"
 
-int funccheck(char *tname, char *incl, char *fname)
+void funccheck(char *tname, char *incl, char *fname)
 {
-	int rv;
 	static char filename[1024];
 
-	sprintf(program, ftmpl, incl, fname);
-	snprintf(filename, sizeof(filename), filetmpl, strfpn(fname), fname);
-	rv = runcc(tname, filename, program);
-	return rv;
+	sprintf(program, FTMPL, incl, fname);
+	snprintf(filename, sizeof(filename), FILETMPL, strfpn(fname), fname);
+	runcc(tname, filename, program);
 }
diff --git a/testcases/network/lib6/runcc.h b/testcases/network/lib6/runcc.h
index 4e2a0d5..a66addb 100644
--- a/testcases/network/lib6/runcc.h
+++ b/testcases/network/lib6/runcc.h
@@ -1,30 +1,38 @@
 /*
+ * Copyright (c) 2015 Fujitsu Ltd.
+ * Copyright (c) International Business Machines  Corp., 2001
  *
- *   Copyright (c) International Business Machines  Corp., 2001
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
  *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
  *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-int aliascheck(char *tname, char *incl, char *structure, char *field,
-	char *dname);
-int funccheck(char *tname, char *incl, char *fname);
-int structcheck(char *tname, char *incl, char *structure, char *field,
-	char *offset, char *size);
-int valuecheck(char *tname, char *incl, char *dname, char *dval);
+#ifndef __RUNCC_H__
+#define __RUNCC_H__
 
-#define IP6_H "#include <netinet/ip6.h>\n"
-#define IN_H "#include <netinet/in.h>\n"
-#define ICMP6_H "#include <netinet/icmp6.h>\n"
-#define SOCKET_H "#include <sys/types.h>\n#include <sys/socket.h>\n"
+void aliascheck(char *tname, char *incl, char *structure, char *field,
+		char *dname);
+
+void funccheck(char *tname, char *incl, char *fname);
+
+void structcheck(char *tname, char *incl, char *structure, char *field,
+		 char *offset, char *size);
+
+void valuecheck(char *tname, char *incl, char *dname, char *dval);
+
+#define IP6_H		"#include <netinet/ip6.h>\n"
+#define IN_H		"#include <netinet/in.h>\n"
+#define ICMP6_H		"#include <netinet/icmp6.h>\n"
+#define SOCKET_H	"#include <sys/types.h>\n#include <sys/socket.h>\n"
+
+#endif  /* __RUNCC_H__ */
-- 
1.9.3


------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v5 03/11] asapi_01: Use 'tst_tmpdir' and more cleanup
  2015-07-16  5:30                         ` [LTP] [PATCH v5 " Zeng Linggang
  2015-07-16  5:30                           ` [LTP] [PATCH v5 02/11] lib6/runcc.c: Cleanup Zeng Linggang
@ 2015-07-16  5:30                           ` Zeng Linggang
  2015-07-16  5:30                           ` [LTP] [PATCH v5 04/11] asapi_02: " Zeng Linggang
                                             ` (8 subsequent siblings)
  10 siblings, 0 replies; 55+ messages in thread
From: Zeng Linggang @ 2015-07-16  5:30 UTC (permalink / raw)
  To: alexey.kodanev; +Cc: ltp-list

* Use 'tst_tmpdir' and 'tst_rmdir'.
* Add 'static' for the cleanup.

Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
 testcases/network/lib6/asapi_01.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/testcases/network/lib6/asapi_01.c b/testcases/network/lib6/asapi_01.c
index 5d8bdc7..a129569 100644
--- a/testcases/network/lib6/asapi_01.c
+++ b/testcases/network/lib6/asapi_01.c
@@ -198,6 +198,7 @@ static struct ftent {
 };
 
 static void setup(void);
+static void cleanup(void);
 static void do_test(const struct ftent *);
 
 char *TCID = "asapi_01";
@@ -218,15 +219,23 @@ int main(int argc, char *argv[])
 			do_test(&ftab[i]);
 	}
 
+	cleanup();
 	tst_exit();
 }
 
-void setup(void)
+static void setup(void)
 {
 	TEST_PAUSE;
+
+	tst_tmpdir();
+}
+
+static void cleanup(void)
+{
+	tst_rmdir();
 }
 
-void do_test(const struct ftent *ftptr)
+static void do_test(const struct ftent *ftptr)
 {
 	switch (ftptr->ft_type) {
 	case EXISTS:
-- 
1.9.3


------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v5 04/11] asapi_02: Use 'tst_tmpdir' and more cleanup
  2015-07-16  5:30                         ` [LTP] [PATCH v5 " Zeng Linggang
  2015-07-16  5:30                           ` [LTP] [PATCH v5 02/11] lib6/runcc.c: Cleanup Zeng Linggang
  2015-07-16  5:30                           ` [LTP] [PATCH v5 03/11] asapi_01: Use 'tst_tmpdir' and more cleanup Zeng Linggang
@ 2015-07-16  5:30                           ` Zeng Linggang
  2015-07-16  5:30                           ` [LTP] [PATCH v5 05/11] asapi_03: " Zeng Linggang
                                             ` (7 subsequent siblings)
  10 siblings, 0 replies; 55+ messages in thread
From: Zeng Linggang @ 2015-07-16  5:30 UTC (permalink / raw)
  To: alexey.kodanev; +Cc: ltp-list

* Use 'tst_tmpdir' and 'tst_rmdir'.
* Add 'static' for the cleanup.

Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
 testcases/network/lib6/asapi_02.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/testcases/network/lib6/asapi_02.c b/testcases/network/lib6/asapi_02.c
index 01bee37..ac7dcda 100644
--- a/testcases/network/lib6/asapi_02.c
+++ b/testcases/network/lib6/asapi_02.c
@@ -285,6 +285,7 @@ static struct ftent {
 };
 
 static void setup(void);
+static void cleanup(void);
 static void do_test(const struct ftent *);
 
 char *TCID = "asapi_02";
@@ -305,15 +306,23 @@ int main(int argc, char *argv[])
 			do_test(&ftab[i]);
 	}
 
+	cleanup();
 	tst_exit();
 }
 
-void setup(void)
+static void setup(void)
 {
 	TEST_PAUSE;
+
+	tst_tmpdir();
+}
+
+static void cleanup(void)
+{
+	tst_rmdir();
 }
 
-void do_test(const struct ftent *ftptr)
+static void do_test(const struct ftent *ftptr)
 {
 	switch (ftptr->ft_type) {
 	case EXISTS:
-- 
1.9.3


------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v5 05/11] asapi_03: Use 'tst_tmpdir' and more cleanup
  2015-07-16  5:30                         ` [LTP] [PATCH v5 " Zeng Linggang
                                             ` (2 preceding siblings ...)
  2015-07-16  5:30                           ` [LTP] [PATCH v5 04/11] asapi_02: " Zeng Linggang
@ 2015-07-16  5:30                           ` Zeng Linggang
  2015-07-16  5:30                           ` [LTP] [PATCH v5 06/11] lib6/asapi_04.c: Cleanup Zeng Linggang
                                             ` (6 subsequent siblings)
  10 siblings, 0 replies; 55+ messages in thread
From: Zeng Linggang @ 2015-07-16  5:30 UTC (permalink / raw)
  To: alexey.kodanev; +Cc: ltp-list

* Use 'tst_tmpdir' and 'tst_rmdir'.
* Add 'static' for the cleanup.

Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
 testcases/network/lib6/asapi_03.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/testcases/network/lib6/asapi_03.c b/testcases/network/lib6/asapi_03.c
index f458d7d..61be294 100644
--- a/testcases/network/lib6/asapi_03.c
+++ b/testcases/network/lib6/asapi_03.c
@@ -181,6 +181,7 @@ static struct ftent {
 };
 
 static void setup(void);
+static void cleanup(void);
 static void do_test(const struct ftent *);
 
 char *TCID = "asapi_03";
@@ -201,15 +202,23 @@ int main(int argc, char *argv[])
 			do_test(&ftab[i]);
 	}
 
+	cleanup();
 	tst_exit();
 }
 
-void setup(void)
+static void setup(void)
 {
 	TEST_PAUSE;
+
+	tst_tmpdir();
+}
+
+static void cleanup(void)
+{
+	tst_rmdir();
 }
 
-void do_test(const struct ftent *ftptr)
+static void do_test(const struct ftent *ftptr)
 {
 	switch (ftptr->ft_type) {
 	case EXISTS:
-- 
1.9.3


------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v5 06/11] lib6/asapi_04.c: Cleanup
  2015-07-16  5:30                         ` [LTP] [PATCH v5 " Zeng Linggang
                                             ` (3 preceding siblings ...)
  2015-07-16  5:30                           ` [LTP] [PATCH v5 05/11] asapi_03: " Zeng Linggang
@ 2015-07-16  5:30                           ` Zeng Linggang
  2015-07-16  5:30                           ` [LTP] [PATCH v5 07/11] lib6/asapi_05.c: Cleanup Zeng Linggang
                                             ` (5 subsequent siblings)
  10 siblings, 0 replies; 55+ messages in thread
From: Zeng Linggang @ 2015-07-16  5:30 UTC (permalink / raw)
  To: alexey.kodanev; +Cc: ltp-list

* Add 'static' before some functions and global variables.
* Remove useless comments.
* Use SAFE_XXX().
* Modify the format of ptab[] and cstab[].
* Rewrite 'csum_test()' and 'isocketpair()'.
* Use 'tst_tmpdir' and 'tst_rmdir'.
* Some cleanup.

Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
 testcases/network/lib6/asapi_04.c | 287 ++++++++++++++++----------------------
 1 file changed, 122 insertions(+), 165 deletions(-)

diff --git a/testcases/network/lib6/asapi_04.c b/testcases/network/lib6/asapi_04.c
index 76de26b..76e8f8e 100644
--- a/testcases/network/lib6/asapi_04.c
+++ b/testcases/network/lib6/asapi_04.c
@@ -1,38 +1,21 @@
 /*
+ * Copyright (c) 2015 Fujitsu Ltd.
+ * Copyright (c) International Business Machines  Corp., 2001
  *
- *   Copyright (c) International Business Machines  Corp., 2001
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
  *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
  *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/*
- * Test Name: asapi_04
- *
- * Test Description:
- *  Verify that in6 and sockaddr fields are present. Most of these are
- *  "PASS" if they just compile.
- *
- * Usage:  <for command-line>
- *  asapi_04
- *
- * HISTORY
- *	04/2005 written by David L Stevens
- *
- * RESTRICTIONS:
- *  None.
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
+ * Author: David L Stevens
  */
 
 #include <stdio.h>
@@ -48,33 +31,35 @@
 #include <netinet/in.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
-char *TCID = "asapi_04";	/* Test program identifier.    */
+char *TCID = "asapi_04";
 
-pid_t pid;
+static pid_t pid;
 
-struct {
+static struct {
 	char *prt_name;
 	int prt_value;
 } ptab[] = {
-	{
-	"hopopt", 0}, {
-	"ipv6", 41}, {
-	"ipv6-route", 43}, {
-	"ipv6-frag", 44}, {
-	"esp", 50}, {
-	"ah", 51}, {
-	"ipv6-icmp", 58}, {
-	"ipv6-nonxt", 59}, {
-"ipv6-opts", 60},};
-
-#define PTCOUNT	(sizeof(ptab)/sizeof(ptab[0]))
+	{"hopopt", 0},
+	{"ipv6", 41},
+	{"ipv6-route", 43},
+	{"ipv6-frag", 44},
+	{"esp", 50},
+	{"ah", 51},
+	{"ipv6-icmp", 58},
+	{"ipv6-nonxt", 59},
+	{"ipv6-opts", 60},
+};
+
+#define PTCOUNT	ARRAY_SIZE(ptab)
 
 #define READ_TIMEOUT	5	/* secs */
 
-void do_tests(void);
-void setup(void), cleanup(void);
-int csum_test(char *rhost);
+static void do_tests(void);
+static void setup(void);
+static void cleanup(void);
+static int csum_test(void);
 
 int main(int argc, char *argv[])
 {
@@ -90,44 +75,41 @@ int main(int argc, char *argv[])
 		do_tests();
 
 	cleanup();
-
 	tst_exit();
 }
 
-void do_tests(void)
+static void do_tests(void)
 {
-	int i;
+	unsigned int i;
 
 /* RFC 3542, Section 2.3 */
 #ifndef IN6_ARE_ADDR_EQUAL
-	tst_resm(TBROK, "IN6_ARE_ADDR_EQUAL not present");
+	tst_resm(TCONF, "IN6_ARE_ADDR_EQUAL not present");
 #else /* IN6_ARE_ADDR_EQUAL */
 	/*
 	 * set each bit in an address and check for unequal; then set
 	 * in the second address and check for equal. Covers all bits, all
 	 * combinations.
 	 */
-	{
-		struct in6_addr a1, a2;
-		int word, bit;
-		int rv = 1;
+	struct in6_addr a1, a2;
+	int word, bit;
+	int rv = 1;
 
-		memset(&a1, 0, sizeof(a1));
-		memset(&a2, 0, sizeof(a2));
+	memset(&a1, 0, sizeof(a1));
+	memset(&a2, 0, sizeof(a2));
 
-		rv = IN6_ARE_ADDR_EQUAL(&a1, &a2);
+	rv = IN6_ARE_ADDR_EQUAL(&a1, &a2);
 
-		for (word = 0; word < 4; ++word)
-			for (bit = 0; bit < 32; ++bit) {
-				uint32_t newbit = 1 << bit;
+	for (word = 0; word < 4; ++word)
+		for (bit = 0; bit < 32; ++bit) {
+			uint32_t newbit = 1U << bit;
 
-				a1.s6_addr32[word] |= newbit;	/* unequal */
-				rv &= !IN6_ARE_ADDR_EQUAL(&a1, &a2);
-				a2.s6_addr32[word] |= newbit;	/* equal */
-				rv &= IN6_ARE_ADDR_EQUAL(&a1, &a2);
-			}
-		tst_resm(rv ? TPASS : TFAIL, "IN6_ARE_ADDR_EQUAL");
-	}
+			a1.s6_addr32[word] |= newbit;	/* unequal */
+			rv &= !IN6_ARE_ADDR_EQUAL(&a1, &a2);
+			a2.s6_addr32[word] |= newbit;	/* equal */
+			rv &= IN6_ARE_ADDR_EQUAL(&a1, &a2);
+		}
+	tst_resm(rv ? TPASS : TFAIL, "IN6_ARE_ADDR_EQUAL");
 #endif /* IN6_ARE_ADDR_EQUAL */
 
 /* RFC 3542, Section 2.4 */
@@ -141,7 +123,7 @@ void do_tests(void)
 			 ptab[i].prt_name);
 	}
 /* RFC 3542, Section 3.1 */
-	csum_test("::1");
+	csum_test();
 }
 
 /*
@@ -162,10 +144,10 @@ struct tprot {
 	unsigned char tp_dat[0];	/* user data */
 };
 
-unsigned char tpbuf[sizeof(struct tprot) + 2048];
-unsigned char rpbuf[sizeof(struct tprot) + 2048];
+static unsigned char tpbuf[sizeof(struct tprot) + 2048];
+static unsigned char rpbuf[sizeof(struct tprot) + 2048];
 
-struct csent {
+static struct csent {
 	int cs_offset;
 	int cs_dlen;
 	int cs_setresult;	/* setsockopt expected result */
@@ -173,25 +155,24 @@ struct csent {
 	int cs_sndresult;	/* send expected result */
 	int cs_snderrno;	/* send expected errno */
 } cstab[] = {
-	{
-	0, 5, 0, 0, 0, 0}, {
-	6, 30, 0, 0, 0, 0}, {
-	3, 20, -1, EINVAL, -1, -1},	/* non-aligned offset */
-	{
-	4, 5, 0, 0, -1, EINVAL},	/* not enough space */
-	{
-	50, 5, 0, 0, -1, EINVAL},	/* outside of packet */
-	{
-	22, 30, 0, 0, 0, 0}, {
-	2000, 2004, 0, 0, 0, 0},	/* in a fragment (over Ethernet) */
+	{0, 5, 0, 0, 0, 0},
+	{6, 30, 0, 0, 0, 0},
+	{3, 20, -1, EINVAL, -1, -1},	/* non-aligned offset */
+	{4, 5, 0, 0, -1, EINVAL},	/* not enough space */
+	{50, 5, 0, 0, -1, EINVAL},	/* outside of packet */
+	{22, 30, 0, 0, 0, 0},
+	{2000, 2004, 0, 0, 0, 0},	/* in a fragment (over Ethernet) */
 };
 
-#define CSCOUNT	(sizeof(cstab)/sizeof(cstab[0]))
+#define CSCOUNT	ARRAY_SIZE(cstab)
+
+int TST_TOTAL = PTCOUNT + CSCOUNT;
 
-static int recvtprot(int sd, unsigned char *packet, int psize)
+static int recvtprot(int sd, unsigned char *packet)
 {
 	struct tprot *tpt;
-	int cc, total, expected;
+	int cc;
+	unsigned int total, expected;
 	int gothead;
 
 	tpt = (struct tprot *)packet;
@@ -218,7 +199,8 @@ static int recvtprot(int sd, unsigned char *packet, int psize)
 	return total;
 }
 
-unsigned short csum(unsigned short partial, unsigned char *packet, int len)
+static unsigned short csum(unsigned short partial, unsigned char *packet,
+			   int len)
 {
 	unsigned long sum = partial;
 	unsigned short *ps;
@@ -234,7 +216,7 @@ unsigned short csum(unsigned short partial, unsigned char *packet, int len)
 	return ~sum;
 }
 
-struct ph {
+static struct ph {
 	struct in6_addr ph_sa;
 	struct in6_addr ph_da;
 	uint32_t ph_len;
@@ -242,13 +224,14 @@ struct ph {
 	uint8_t ph_nh;
 } ph;
 
-static int client(int prot, int sfd)
+static int client(int sfd)
 {
 	struct tprot *pttp = (struct tprot *)tpbuf;
 	struct tprot *prtp = (struct tprot *)rpbuf;
 	struct sockaddr_in6 rsin6;
 	static int seq;
-	int i, sd, cc, cs;
+	unsigned int i;
+	int sd, cc, cs;
 
 	memset(&rsin6, 0, sizeof(rsin6));
 	rsin6.sin6_family = AF_INET6;
@@ -259,11 +242,8 @@ static int client(int prot, int sfd)
 	ph.ph_da = rsin6.sin6_addr;
 	ph.ph_nh = NH_TEST;
 
-	sd = socket(PF_INET6, SOCK_RAW, NH_TEST);
-	if (sd < 0) {
-		tst_resm(TBROK, "can't create raw socket: %s", strerror(errno));
-		return -1;
-	}
+	sd = SAFE_SOCKET(NULL, PF_INET6, SOCK_RAW, NH_TEST);
+
 	for (i = 0; i < CSCOUNT; ++i) {
 		int offset, len, xlen;
 		int rv;
@@ -289,17 +269,20 @@ static int client(int prot, int sfd)
 				 cstab[i].cs_setresult);
 			continue;
 		}
+
 		if (TEST_RETURN < 0) {
 			tst_resm(TPASS, "IPV6_CHECKSUM offset %d len %d",
 				 offset, len);
 			continue;
 		}
+
 		if (TEST_RETURN && TEST_ERRNO != cstab[i].cs_seterrno) {
 			tst_resm(TFAIL, "IPV6_CHECKSUM offset %d len %d "
 				 "- errno %d != %d", offset, len,
 				 TEST_ERRNO, cstab[i].cs_seterrno);
 			continue;
 		}
+
 		/* send packet */
 		TEST(sendto(sd, pttp, len, 0, (struct sockaddr *)&rsin6,
 			    sizeof(rsin6)));
@@ -311,20 +294,23 @@ static int client(int prot, int sfd)
 				 TEST_RETURN, xlen);
 			continue;
 		}
+
 		if (TEST_RETURN < 0 && TEST_ERRNO != cstab[i].cs_snderrno) {
 			tst_resm(TFAIL, "IPV6_CHECKSUM offset %d len %d "
 				 "- snderrno %d != %d", offset, len,
 				 TEST_ERRNO, cstab[i].cs_snderrno);
 			continue;
 		}
+
 		if (TEST_RETURN < 0) {
 			tst_resm(TPASS, "IPV6_CHECKSUM offset %d len %d",
 				 offset, len);
 			continue;
 		}
-		while ((cc = recvtprot(sfd, rpbuf, sizeof(rpbuf)))) {
-			if (htonl(prtp->tp_pid) == pid &&
-			    htonl(prtp->tp_seq) == seq)
+
+		while ((cc = recvtprot(sfd, rpbuf))) {
+			if (htonl(prtp->tp_pid) == (uint32_t)pid &&
+			    htonl(prtp->tp_seq) == (uint32_t)seq)
 				break;
 		}
 		rv = 1;
@@ -334,7 +320,7 @@ static int client(int prot, int sfd)
 				continue;
 			if (*p != 0xa5) {
 				tst_resm(TFAIL, "IPV6_CHECKSUM corrupt data "
-					 "0x%02x != 0xa5 at offset %d in packet",
+					 "0x%02x != 0xa5 at offset %zd in packet",
 					 *p, p - rpbuf);
 				rv = 0;
 				break;
@@ -358,7 +344,7 @@ static int client(int prot, int sfd)
 static int listen_fd, connect_fd;
 sem_t ilsem;
 
-void *ilistener(void *arg)
+static void *ilistener(void *arg LTP_ATTRIBUTE_UNUSED)
 {
 	connect_fd = accept(listen_fd, 0, 0);
 	close(listen_fd);
@@ -366,7 +352,7 @@ void *ilistener(void *arg)
 	return NULL;
 }
 
-int isocketpair(int pf, int type, int proto, int fd[2])
+static void isocketpair(int pf, int type, int proto, int fd[2])
 {
 	pthread_t thid;
 	struct sockaddr_in sin4;
@@ -375,80 +361,51 @@ int isocketpair(int pf, int type, int proto, int fd[2])
 /* restrict to PF_INET for now */
 	if (pf != PF_INET) {
 		errno = EOPNOTSUPP;
-		return -1;
+		return;
 	}
+
 	sem_init(&ilsem, 0, 0);
-	listen_fd = socket(pf, type, proto);
-	if (listen_fd < 0) {
-		perror("socket");
-		return -1;
-	}
+
+	listen_fd = SAFE_SOCKET(NULL, pf, type, proto);
+
 	memset(&sin4, 0, sizeof(sin4));
-	if (bind(listen_fd, (struct sockaddr *)&sin4, sizeof(sin4)) < 0) {
-		perror("bind");
-		return -1;
-	}
-	if (listen(listen_fd, 10) < 0) {
-		perror("listen");
-		return -1;
-	}
+
+	SAFE_BIND(NULL, listen_fd, (struct sockaddr *)&sin4, sizeof(sin4));
+
+	SAFE_LISTEN(NULL, listen_fd, 10);
+
 	namelen = sizeof(sin4);
-	if (getsockname(listen_fd, (struct sockaddr *)&sin4, &namelen) < 0) {
-		perror("getsockname");
-		return -1;
-	}
-	if (pthread_create(&thid, 0, ilistener, 0) < 0) {
-		perror("pthread_create");
-		return -1;
-	}
+	SAFE_GETSOCKNAME(NULL, listen_fd, (struct sockaddr *)&sin4, &namelen);
+
+	if (pthread_create(&thid, 0, ilistener, 0) < 0)
+		tst_brkm(TBROK | TERRNO, NULL, "pthread_create error");
+
+	fd[0] = SAFE_SOCKET(NULL, pf, type, proto);
 
-	fd[0] = socket(pf, type, proto);
-	if (fd[0] < 0) {
-		perror("socket");
-		return -1;
-	}
 	sin4.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
-	if (connect(fd[0], (struct sockaddr *)&sin4, sizeof(sin4)) < 0) {
-		perror("connect");
-		return -1;
-	}
+
+	SAFE_CONNECT(NULL, fd[0], (struct sockaddr *)&sin4, sizeof(sin4));
+
 	sem_wait(&ilsem);
 	fd[1] = connect_fd;
 	sem_destroy(&ilsem);
-	return 0;
 }
 
 #ifndef MAX
 #define MAX(a, b) ((a) >= (b) ? (a) : (b))
 #endif /* MAX */
 
-int csum_test(char *rhost)
+static int csum_test(void)
 {
 	fd_set rset, rset_save;
 	int csd[2];		/* control sockets */
 	int sd, nfds, maxfd, cc;
 	struct timeval tv;
 
-/* rhost == loopback, for now */
-	if (strcmp(rhost, "::1")) {
-		tst_resm(TBROK, "invalid rhost \"%s\"", rhost);
-		return -1;
-	}
-	if (isocketpair(PF_INET, SOCK_STREAM, 0, csd) < 0) {
-		tst_resm(TBROK, "socketpair: %s", strerror(errno));
-		return -1;
-	}
-	sd = socket(PF_INET6, SOCK_RAW, NH_TEST);
-	if (sd < 0) {
-		int saved_errno = errno;
-
-		if (errno == EPERM && geteuid())
-			tst_resm(TBROK, "IPV6_CHECKSUM tests must run as root");
-		else
-			tst_resm(TBROK, "All IPv6_CHECKSUM tests broken: "
-				 "socket: %s", strerror(saved_errno));
-		return -1;
-	}
+	isocketpair(PF_INET, SOCK_STREAM, 0, csd);
+
+	sd = SAFE_SOCKET(NULL, PF_INET6, SOCK_RAW, NH_TEST);
+
 	FD_ZERO(&rset_save);
 	FD_SET(sd, &rset_save);
 	FD_SET(csd[1], &rset_save);
@@ -457,16 +414,15 @@ int csum_test(char *rhost)
 
 	/* server socket set; now start the client */
 	switch (fork()) {
-	case 0:		/* child */
+	case 0:
 		close(csd[0]);
 		break;
 	case -1:
-		tst_resm(TBROK, "can't fork rserver");
-		return -1;
-	default:		/* parent */
+		tst_brkm(TBROK, NULL, "can't fork rserver");
+	default:
 		close(sd);
 		close(csd[1]);
-		return client(pid, csd[0]);
+		return client(csd[0]);
 	}
 
 	tv.tv_sec = READ_TIMEOUT;
@@ -515,13 +471,14 @@ int csum_test(char *rhost)
 	return 0;
 }
 
-void setup(void)
+static void setup(void)
 {
-	TEST_PAUSE;		/* if -P option specified */
+	TEST_PAUSE;
+
+	tst_tmpdir();
 }
 
-void cleanup(void)
+static void cleanup(void)
 {
+	tst_rmdir();
 }
-
-int TST_TOTAL = PTCOUNT + CSCOUNT;
-- 
1.9.3


------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v5 07/11] lib6/asapi_05.c: Cleanup
  2015-07-16  5:30                         ` [LTP] [PATCH v5 " Zeng Linggang
                                             ` (4 preceding siblings ...)
  2015-07-16  5:30                           ` [LTP] [PATCH v5 06/11] lib6/asapi_04.c: Cleanup Zeng Linggang
@ 2015-07-16  5:30                           ` Zeng Linggang
  2015-07-16  5:30                           ` [LTP] [PATCH v5 08/11] lib6/asapi_06.c: Cleanup Zeng Linggang
                                             ` (4 subsequent siblings)
  10 siblings, 0 replies; 55+ messages in thread
From: Zeng Linggang @ 2015-07-16  5:30 UTC (permalink / raw)
  To: alexey.kodanev; +Cc: ltp-list

* Add 'static' before some functions and global variables.
* Use 'tst_tmpdir' and 'tst_rmdir'.
* Remove useless comments.
* Use SAFE_XXX().
* Modify the format of etab[] and ftab[].
* Some cleanup.

Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
 testcases/network/lib6/asapi_05.c | 274 ++++++++++++++++----------------------
 1 file changed, 113 insertions(+), 161 deletions(-)

diff --git a/testcases/network/lib6/asapi_05.c b/testcases/network/lib6/asapi_05.c
index 9acc6a2..25a5dbf 100644
--- a/testcases/network/lib6/asapi_05.c
+++ b/testcases/network/lib6/asapi_05.c
@@ -1,38 +1,21 @@
 /*
+ * Copyright (c) 2015 Fujitsu Ltd.
+ * Copyright (c) International Business Machines  Corp., 2001
  *
- *   Copyright (c) International Business Machines  Corp., 2001
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
  *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
  *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/*
- * Test Name: asapi_05
- *
- * Test Description:
- *  These tests are for the "Advanced Sockets API" (RFC 3542)
- *  Verify that in6 and sockaddr fields are present.
- *
- * Usage:  <for command-line>
- *  asapi_05
- *
- * HISTORY
- *	04/2005 written by David L Stevens
- *
- * RESTRICTIONS:
- *  None.
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
+ * Author: David L Stevens
  */
 
 #include <stdio.h>
@@ -47,21 +30,21 @@
 #include <netinet/icmp6.h>
 
 #include "test.h"
+#include "safe_macros.h"
 #include "runcc.h"
 
-char *TCID = "asapi_05";	/* Test program identifier.    */
+char *TCID = "asapi_05";
 
-void setup(void);
-void cleanup(void);
+static void setup(void);
+static void cleanup(void);
 
-void icmp6_et(void);
-void icmp6_ft(void);
+static void icmp6_et(void);
+static void icmp6_ft(void);
 
 int main(int argc, char *argv[])
 {
 	int lc;
 
-	/* Parse standard options given to run the test. */
 	tst_parse_opts(argc, argv, NULL, NULL);
 
 	setup();
@@ -72,13 +55,12 @@ int main(int argc, char *argv[])
 	}
 
 	cleanup();
-
 	tst_exit();
 }
 
 enum ttype { EXISTS, ALIAS, VALUE, DEFINED };
 
-struct etent {
+static struct etent {
 	char *et_tname;		/* test name */
 	int et_type;		/* test type */
 	char *et_incl;		/* include file list */
@@ -92,76 +74,58 @@ struct etent {
 #define et_value	ftun.fu_value
 #define et_dname	ftun.fu_dname
 } etab[] = {
-/* existence checks, RFC 3542 section 3 */
-	{
-		"icmp6_filter icmp6_filt", EXISTS, ICMP6_H, "icmp6_filter",
-		    "icmp6_filt", "0", {
-	"32"}}, {
-		"icmp6_filter icmp6_filt[0]", EXISTS, ICMP6_H, "icmp6_filter",
-		    "icmp6_filt[0]", "0", {
-	"4"}}, {
-		"ICMP6_FILTER_WILLPASS", DEFINED, ICMP6_H,
-		    "ICMP6_FILTER_WILLPASS", NULL, NULL, {
-	0}}, {
-		"ICMP6_FILTER_WILLBLOCK", DEFINED, ICMP6_H,
-		    "ICMP6_FILTER_WILLBLOCK", NULL, NULL, {
-	0}}, {
-		"ICMP6_FILTER_SETPASS", DEFINED, ICMP6_H,
-		    "ICMP6_FILTER_SETPASS", NULL, NULL, {
-	0}}, {
-		"ICMP6_FILTER_SETBLOCK", DEFINED, ICMP6_H,
-		    "ICMP6_FILTER_SETBLOCK", NULL, NULL, {
-	0}}, {
-		"ICMP6_FILTER_SETPASSALL", DEFINED, ICMP6_H,
-		    "ICMP6_FILTER_SETPASSALL", NULL, NULL, {
-	0}}, {
-		"ICMP6_FILTER_SETBLOCKALL", DEFINED, ICMP6_H,
-		    "ICMP6_FILTER_SETBLOCKALL", NULL, NULL, {
-	0}}, {
-		"ICMP6_FILTER", DEFINED, ICMP6_H, "ICMP6_FILTER", NULL, NULL, {
-	0}},
-/* existence checks, RFC 3542 section 4 */
-/* socket options */
-	{
-		"IPV6_RECVPKTINFO", VALUE, IN_H, "IPV6_RECVPKTINFO", NULL, NULL, {
-	"IPV6_RECVPKTINFO"}}, {
-		"IPV6_RECVHOPLIMIT", VALUE, IN_H, "IPV6_RECVHOPLIMIT", NULL,
-		    NULL, {
-	"IPV6_RECVHOPLIMIT"}}, {
-		"IPV6_RECVRTHDR", VALUE, IN_H, "IPV6_RECVRTHDR", NULL, NULL, {
-	"IPV6_RECVRTHDR"}}, {
-		"IPV6_RECVHOPOPTS", VALUE, IN_H, "IPV6_RECVHOPOPTS", NULL, NULL, {
-	"IPV6_RECVHOPOPTS"}}, {
-		"IPV6_RECVDSTOPTS", VALUE, IN_H, "IPV6_RECVDSTOPTS", NULL, NULL, {
-	"IPV6_RECVDSTOPTS"}}, {
-		"IPV6_RECVTCLASS", VALUE, IN_H, "IPV6_RECVTCLASS", NULL, NULL, {
-	"IPV6_RECVTCLASS"}},
-/* cmsg types */
-	{
-		"IPV6_PKTINFO", DEFINED, IN_H, "IPV6_PKTINFO", NULL, NULL, {
-	0}}, {
-		"IPV6_HOPLIMIT", DEFINED, IN_H, "IPV6_HOPLIMIT", NULL, NULL, {
-	0}}, {
-		"IPV6_NEXTHOP", DEFINED, IN_H, "IPV6_NEXTHOP", NULL, NULL, {
-	0}}, {
-		"IPV6_RTHDR", DEFINED, IN_H, "IPV6_RTHDR", NULL, NULL, {
-	0}}, {
-		"IPV6_HOPOPTS", DEFINED, IN_H, "IPV6_HOPOPTS", NULL, NULL, {
-	0}}, {
-		"IPV6_DSTOPTS", DEFINED, IN_H, "IPV6_DSTOPTS", NULL, NULL, {
-	0}}, {
-		"IPV6_RTHDRDSTOPTS", DEFINED, IN_H, "IPV6_RTHDRDSTOPTS", NULL,
-		    NULL, {
-	0}}, {
-		"IPV6_TCLASS", DEFINED, IN_H, "IPV6_TCLASS", NULL, NULL, {
-0}},};
-
-#define ETCOUNT	(sizeof(etab)/sizeof(etab[0]))
+	/* existence checks, RFC 3542 section 3 */
+	{"icmp6_filter icmp6_filt", EXISTS, ICMP6_H, "icmp6_filter",
+	 "icmp6_filt", "0", {"32"} },
+	{"icmp6_filter icmp6_filt[0]", EXISTS, ICMP6_H, "icmp6_filter",
+	 "icmp6_filt[0]", "0", {"4"} },
+	{"ICMP6_FILTER_WILLPASS", DEFINED, ICMP6_H, "ICMP6_FILTER_WILLPASS",
+	 NULL, NULL, {0} },
+	{"ICMP6_FILTER_WILLBLOCK", DEFINED, ICMP6_H, "ICMP6_FILTER_WILLBLOCK",
+	 NULL, NULL, {0} },
+	{"ICMP6_FILTER_SETPASS", DEFINED, ICMP6_H, "ICMP6_FILTER_SETPASS", NULL,
+	 NULL, {0} },
+	{"ICMP6_FILTER_SETBLOCK", DEFINED, ICMP6_H, "ICMP6_FILTER_SETBLOCK",
+	 NULL, NULL, {0} },
+	{"ICMP6_FILTER_SETPASSALL", DEFINED, ICMP6_H, "ICMP6_FILTER_SETPASSALL",
+	 NULL, NULL, {0} },
+	{"ICMP6_FILTER_SETBLOCKALL", DEFINED, ICMP6_H,
+	 "ICMP6_FILTER_SETBLOCKALL", NULL, NULL, {0} },
+	{"ICMP6_FILTER", DEFINED, ICMP6_H, "ICMP6_FILTER", NULL, NULL, {0} },
+	/* existence checks, RFC 3542 section 4 */
+	/* socket options */
+	{"IPV6_RECVPKTINFO", VALUE, IN_H, "IPV6_RECVPKTINFO", NULL, NULL,
+	 {"IPV6_RECVPKTINFO"} },
+	{"IPV6_RECVHOPLIMIT", VALUE, IN_H, "IPV6_RECVHOPLIMIT", NULL, NULL,
+	 {"IPV6_RECVHOPLIMIT"} },
+	{"IPV6_RECVRTHDR", VALUE, IN_H, "IPV6_RECVRTHDR", NULL, NULL,
+	 {"IPV6_RECVRTHDR"} },
+	{"IPV6_RECVHOPOPTS", VALUE, IN_H, "IPV6_RECVHOPOPTS", NULL, NULL,
+	 {"IPV6_RECVHOPOPTS"} },
+	{"IPV6_RECVDSTOPTS", VALUE, IN_H, "IPV6_RECVDSTOPTS", NULL, NULL,
+	 {"IPV6_RECVDSTOPTS"} },
+	{"IPV6_RECVTCLASS", VALUE, IN_H, "IPV6_RECVTCLASS", NULL, NULL,
+	 {"IPV6_RECVTCLASS"} },
+	/* cmsg types */
+	{"IPV6_PKTINFO", DEFINED, IN_H, "IPV6_PKTINFO", NULL, NULL, {0} },
+	{"IPV6_HOPLIMIT", DEFINED, IN_H, "IPV6_HOPLIMIT", NULL, NULL, {0} },
+	{"IPV6_NEXTHOP", DEFINED, IN_H, "IPV6_NEXTHOP", NULL, NULL, {0} },
+	{"IPV6_RTHDR", DEFINED, IN_H, "IPV6_RTHDR", NULL, NULL, {0} },
+	{"IPV6_HOPOPTS", DEFINED, IN_H, "IPV6_HOPOPTS", NULL, NULL, {0} },
+	{"IPV6_DSTOPTS", DEFINED, IN_H, "IPV6_DSTOPTS", NULL, NULL, {0} },
+	{"IPV6_RTHDRDSTOPTS", DEFINED, IN_H, "IPV6_RTHDRDSTOPTS", NULL, NULL,
+	 {0} },
+	{"IPV6_TCLASS", DEFINED, IN_H, "IPV6_TCLASS", NULL, NULL, {0} },
+};
+
+#define ETCOUNT	ARRAY_SIZE(etab)
+
+int TST_TOTAL = ETCOUNT;
 
 /*  existence tests */
-void icmp6_et(void)
+static void icmp6_et(void)
 {
-	int i;
+	unsigned int i;
 
 	for (i = 0; i < ETCOUNT; ++i) {
 		switch (etab[i].et_type) {
@@ -190,60 +154,59 @@ void icmp6_et(void)
 	}
 }
 
-void setup(void)
+static void setup(void)
 {
-	TEST_PAUSE;		/* if -P option specified */
+	TEST_PAUSE;
 	tst_require_root(NULL);
+
+	tst_tmpdir();
 }
 
-void cleanup(void)
+static void cleanup(void)
 {
+	tst_rmdir();
 }
 
-/*
- * This is for old, broken glibc-header icmp6_filter structure definitions.
- * If icmp6.h has struct icmp6_filter with field named "data" instead
- * of the standard "icmp_filt", uncomment this line.
- */
-/*#define icmp_filt	data */
-
-enum tt { T_WILLPASS, T_WILLBLOCK, T_SETPASS, T_SETBLOCK, T_SETPASSALL,
+enum tt {
+	T_WILLPASS,
+	T_WILLBLOCK,
+	T_SETPASS,
+	T_SETBLOCK,
+	T_SETPASSALL,
 	T_SETBLOCKALL
 };
-struct ftent {
-	char *ft_tname;		/* test name, for logging */
+
+static struct ftent {
+	char *ft_tname;			/* test name, for logging */
 	unsigned char ft_sndtype;	/* send type field */
 	unsigned char ft_flttype;	/* filter type field */
-	enum tt ft_test;	/* what macro to test */
-	int ft_expected;	/* packet should pass? */
+	enum tt ft_test;		/* what macro to test */
+	int ft_expected;		/* packet should pass? */
 } ftab[] = {
-	{
-	"ICMP6_FILTER_SETPASS s 20 f 20", 20, 20, T_SETPASS, 1}, {
-	"ICMP6_FILTER_SETPASS s 20 f 21", 20, 21, T_SETPASS, 0}, {
-	"ICMP6_FILTER_SETBLOCK s 20 f 20", 20, 20, T_SETBLOCK, 0}, {
-	"ICMP6_FILTER_SETBLOCK s 20 f 21", 20, 21, T_SETBLOCK, 1}, {
-	"ICMP6_FILTER_PASSALL s 20", 20, 0, T_SETPASSALL, 1}, {
-	"ICMP6_FILTER_PASSALL s 20", 21, 0, T_SETPASSALL, 1}, {
-	"ICMP6_FILTER_BLOCKALL s 20", 20, 0, T_SETBLOCKALL, 0}, {
-	"ICMP6_FILTER_BLOCKALL s 20", 21, 0, T_SETBLOCKALL, 0}, {
-	"ICMP6_FILTER_WILLBLOCK s 20 f 21", 20, 21, T_WILLBLOCK, 0}, {
-	"ICMP6_FILTER_WILLBLOCK s 20 f 20", 20, 20, T_WILLBLOCK, 1}, {
-	"ICMP6_FILTER_WILLPASS s 20 f 21", 20, 21, T_WILLPASS, 0}, {
-"ICMP6_FILTER_WILLPASS s 22 f 22", 22, 22, T_WILLPASS, 1},};
-
-#define FTCOUNT	(sizeof(ftab)/sizeof(ftab[0]))
-
-int ic6_send1(char *tname, unsigned char type)
+	{"ICMP6_FILTER_SETPASS s 20 f 20", 20, 20, T_SETPASS, 1},
+	{"ICMP6_FILTER_SETPASS s 20 f 21", 20, 21, T_SETPASS, 0},
+	{"ICMP6_FILTER_SETBLOCK s 20 f 20", 20, 20, T_SETBLOCK, 0},
+	{"ICMP6_FILTER_SETBLOCK s 20 f 21", 20, 21, T_SETBLOCK, 1},
+	{"ICMP6_FILTER_PASSALL s 20", 20, 0, T_SETPASSALL, 1},
+	{"ICMP6_FILTER_PASSALL s 20", 21, 0, T_SETPASSALL, 1},
+	{"ICMP6_FILTER_BLOCKALL s 20", 20, 0, T_SETBLOCKALL, 0},
+	{"ICMP6_FILTER_BLOCKALL s 20", 21, 0, T_SETBLOCKALL, 0},
+	{"ICMP6_FILTER_WILLBLOCK s 20 f 21", 20, 21, T_WILLBLOCK, 0},
+	{"ICMP6_FILTER_WILLBLOCK s 20 f 20", 20, 20, T_WILLBLOCK, 1},
+	{"ICMP6_FILTER_WILLPASS s 20 f 21", 20, 21, T_WILLPASS, 0},
+	{"ICMP6_FILTER_WILLPASS s 22 f 22", 22, 22, T_WILLPASS, 1},
+};
+
+#define FTCOUNT	ARRAY_SIZE(ftab)
+
+static int ic6_send1(char *tname, unsigned char type)
 {
 	struct sockaddr_in6 sin6;
 	struct icmp6_hdr ic6;
 	int s;
 
-	s = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
-	if (s == -1) {
-		tst_resm(TBROK, "%s: socket failed", tname);
-		return 1;
-	}
+	s = SAFE_SOCKET(NULL, AF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
+
 	memset(&ic6, 0, sizeof(ic6));
 	ic6.icmp6_type = type;
 	ic6.icmp6_data32[0] = htonl(getpid());
@@ -259,7 +222,7 @@ int ic6_send1(char *tname, unsigned char type)
 	return 0;
 }
 
-int ic6_recv1(char *tname, int sall, int sf)
+static int ic6_recv1(char *tname, int sall, int sf)
 {
 	fd_set readfds, readfds_saved;
 	struct timeval tv;
@@ -302,7 +265,7 @@ int ic6_recv1(char *tname, int sall, int sf)
 				return -1;
 			}
 			/* if packet check succeeds... */
-			if (htonl(pic6->icmp6_data32[0]) == getpid())
+			if (htonl(pic6->icmp6_data32[0]) == (uint32_t)getpid())
 				gotall = 1;
 		}
 		if (FD_ISSET(sf, &readfds)) {
@@ -313,7 +276,7 @@ int ic6_recv1(char *tname, int sall, int sf)
 				return -1;
 			}
 			/* if packet check succeeds... */
-			if (htonl(pic6->icmp6_data32[0]) == getpid())
+			if (htonl(pic6->icmp6_data32[0]) == (uint32_t)getpid())
 				gotone = 1;
 		}
 		memcpy(&readfds, &readfds_saved, sizeof(readfds));
@@ -328,18 +291,14 @@ int ic6_recv1(char *tname, int sall, int sf)
 }
 
 /* functional tests */
-void icmp6_ft(void)
+static void icmp6_ft(void)
 {
 	struct icmp6_filter i6f;
 	int sall, sf;
-	int i;
+	unsigned int i;
+
+	sall = SAFE_SOCKET(NULL, PF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
 
-	sall = socket(PF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
-	if (sall < 0) {
-		tst_resm(TBROK | TERRNO,
-			 "icmp6_ft socket: can't create sall socket");
-		return;
-	}
 	ICMP6_FILTER_SETPASSALL(&i6f);
 	if (setsockopt(sall, IPPROTO_ICMPV6, ICMP6_FILTER, &i6f,
 		       sizeof(i6f)) < 0) {
@@ -347,12 +306,7 @@ void icmp6_ft(void)
 			 "setsockopt pass all ICMP6_FILTER failed");
 	}
 
-	sf = socket(PF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
-	if (sf < 0) {
-		tst_resm(TBROK | TERRNO,
-			 "icmp6_ft socket: can't create test socket");
-		return;
-	}
+	sf = SAFE_SOCKET(NULL, PF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
 
 	int rv;
 
@@ -413,5 +367,3 @@ void icmp6_ft(void)
 			tst_resm(TPASS, "%s", ftab[i].ft_tname);
 	}
 }
-
-int TST_TOTAL = ETCOUNT;
-- 
1.9.3


------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v5 08/11] lib6/asapi_06.c: Cleanup
  2015-07-16  5:30                         ` [LTP] [PATCH v5 " Zeng Linggang
                                             ` (5 preceding siblings ...)
  2015-07-16  5:30                           ` [LTP] [PATCH v5 07/11] lib6/asapi_05.c: Cleanup Zeng Linggang
@ 2015-07-16  5:30                           ` Zeng Linggang
  2015-07-16  5:30                           ` [LTP] [PATCH v5 09/11] asapi_07: Use 'tst_tmpdir' and more cleanup Zeng Linggang
                                             ` (3 subsequent siblings)
  10 siblings, 0 replies; 55+ messages in thread
From: Zeng Linggang @ 2015-07-16  5:30 UTC (permalink / raw)
  To: alexey.kodanev; +Cc: ltp-list

* Add 'static' before some functions and global variables.
* Use 'tst_tmpdir' and 'tst_rmdir'.
* Remove useless comments.
* Use SAFE_XXX().
* Remove unused variables.
* Modify the format of sotab[] and cmtab[].
* Modify the initialization of sotab[].
* Some cleanup.

Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
 testcases/network/lib6/asapi_06.c | 317 +++++++++++++++-----------------------
 1 file changed, 120 insertions(+), 197 deletions(-)

diff --git a/testcases/network/lib6/asapi_06.c b/testcases/network/lib6/asapi_06.c
index 960ebb5..204bf23 100644
--- a/testcases/network/lib6/asapi_06.c
+++ b/testcases/network/lib6/asapi_06.c
@@ -1,37 +1,21 @@
 /*
+ * Copyright (c) 2015 Fujitsu Ltd.
+ * Copyright (c) International Business Machines  Corp., 2001
  *
- *   Copyright (c) International Business Machines  Corp., 2001
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
  *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
  *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/*
- * Test Name: asapi_06
- *
- * Test Description:
- *  Tests for RFC 3542 section 4 socket options and ancillary data
- *
- * Usage:  <for command-line>
- *  asapi_06
- *
- * HISTORY
- *	05/2005 written by David L Stevens
- *
- * RESTRICTIONS:
- *  None.
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
+ * Author: David L Stevens
  */
 
 #include "config.h"
@@ -57,25 +41,19 @@
 #include <arpa/inet.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
-char *TCID = "asapi_06";	/* Test program identifier.    */
+char *TCID = "asapi_06";
 
 int TST_TOTAL = 1;
 
-pid_t pid;
-
-struct {
-	char *prt_name;
-	int prt_value;
-} ptab[] = {
-};
-
-#define PTCOUNT	(sizeof(ptab)/sizeof(ptab[0]))
+static pid_t pid;
 
 #define READ_TIMEOUT	5	/* secs */
 
-void do_tests(void);
-void setup(void), cleanup(void);
+static void do_tests(void);
+static void setup(void);
+static void cleanup(void);
 
 int main(int argc, char *argv[])
 {
@@ -97,40 +75,40 @@ int main(int argc, char *argv[])
 #define NH_TEST	0x9f
 
 #ifndef IPV6_RECVPKTINFO
-#define IPV6_RECVPKTINFO	-1
+# define IPV6_RECVPKTINFO	-1
 #endif
 #ifndef IPV6_RECVHOPLIMIT
-#define IPV6_RECVHOPLIMIT	-1
+# define IPV6_RECVHOPLIMIT	-1
 #endif
 #ifndef IPV6_RECVRTHDR
-#define IPV6_RECVRTHDR		-1
+# define IPV6_RECVRTHDR		-1
 #endif
 #ifndef IPV6_RECVHOPOPTS
-#define IPV6_RECVHOPOPTS	-1
+# define IPV6_RECVHOPOPTS	-1
 #endif
 #ifndef IPV6_RECVDSTOPTS
-#define IPV6_RECVDSTOPTS	-1
+# define IPV6_RECVDSTOPTS	-1
 #endif
 #ifndef IPV6_RECVTCLASS
-#define IPV6_RECVTCLASS		-1
+# define IPV6_RECVTCLASS		-1
 #endif
 #ifndef IPV6_TCLASS
-#define IPV6_TCLASS		-1
+# define IPV6_TCLASS		-1
 #endif
 #ifndef IPV6_2292PKTINFO
-#define	IPV6_2292PKTINFO	-1
+# define	IPV6_2292PKTINFO	-1
 #endif
 #ifndef IPV6_2292HOPLIMIT
-#define	IPV6_2292HOPLIMIT	-1
+# define	IPV6_2292HOPLIMIT	-1
 #endif
 #ifndef IPV6_2292RTHDR
-#define	IPV6_2292RTHDR		-1
+# define	IPV6_2292RTHDR		-1
 #endif
 #ifndef IPV6_2292HOPOPTS
-#define	IPV6_2292HOPOPTS	-1
+# define	IPV6_2292HOPOPTS	-1
 #endif
 #ifndef IPV6_2292DSTOPTS
-#define	IPV6_2292DSTOPTS	-1
+# define	IPV6_2292DSTOPTS	-1
 #endif
 
 union soval {
@@ -150,7 +128,7 @@ union soval {
 #define IN6_ANY		{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
 
 /* so_clrval and so_setval members are initilized in the body */
-struct soent {
+static struct soent {
 	char *so_tname;
 	int so_opt;
 	int so_dorecv;		/* do receive test? */
@@ -160,73 +138,52 @@ struct soent {
 	union soval so_setval;
 	socklen_t so_valsize;
 } sotab[] = {
-/* RFC 3542, Section 4 */
-	{
-		"IPV6_RECVPKTINFO", IPV6_RECVPKTINFO, 1, IPV6_PKTINFO, 1, { { { { {
-		0}}}}}, { { { { {
-	0}}}}}, sizeof(int)}, {
-		"IPV6_RECVHOPLIMIT", IPV6_RECVHOPLIMIT, 1, IPV6_HOPLIMIT, 1, { { { { {
-		0}}}}}, { { { { {
-	0}}}}}, sizeof(int)}, {
-		"IPV6_RECVRTHDR", IPV6_RECVRTHDR, 0, IPV6_RTHDR, 1, { { { { {
-		0}}}}}, { { { { {
-	0}}}}}, sizeof(int)}, {
-		"IPV6_RECVHOPOPTS", IPV6_RECVHOPOPTS, 0, IPV6_HOPOPTS, 1, { { { { {
-		0}}}}}, { { { { {
-	0}}}}}, sizeof(int)}, {
-		"IPV6_RECVDSTOPTS", IPV6_RECVDSTOPTS, 0, IPV6_DSTOPTS, 1, { { { { {
-		0}}}}}, { { { { {
-	0}}}}}, sizeof(int)}, {
-		"IPV6_RECVTCLASS", IPV6_RECVTCLASS, 1, IPV6_TCLASS, 1, { { { { {
-		0}}}}}, { { { { {
-	0}}}}}, sizeof(int)},
-/* make sure TCLASS stays when setting another opt */
-	{
-		"IPV6_RECVTCLASS (2)", IPV6_RECVHOPLIMIT, 1, IPV6_TCLASS, 0, { { { { {
-		0}}}}}, { { { { {
-	0}}}}}, sizeof(int)},
-/* OLD values */
-	{
-		"IPV6_2292PKTINFO", IPV6_2292PKTINFO, 1, IPV6_2292PKTINFO, 1, { { { { {
-		0}}}}}, { { { { {
-	0}}}}}, sizeof(int)}, {
-		"IPV6_2292HOPLIMIT", IPV6_2292HOPLIMIT, 1, IPV6_2292HOPLIMIT, 1, { { { { {
-		0}}}}}, { { { { {
-	0}}}}}, sizeof(int)}, {
-		"IPV6_2292RTHDR", IPV6_2292RTHDR, 0, IPV6_2292RTHDR, 1, { { { { {
-		0}}}}}, { { { { {
-	0}}}}}, sizeof(int)}, {
-		"IPV6_2292HOPOPTS", IPV6_2292HOPOPTS, 0, IPV6_2292HOPOPTS, 1, { { { { {
-		0}}}}}, { { { { {
-	0}}}}}, sizeof(int)}, {
-		"IPV6_2292DSTOPTS", IPV6_2292DSTOPTS, 0, IPV6_2292DSTOPTS, 1, { { { { {
-		0}}}}}, { { { { {
-0}}}}}, sizeof(int)},};
-
-#define SOCOUNT	(sizeof(sotab)/sizeof(sotab[0]))
+	/* RFC 3542, Section 4 */
+	{"IPV6_RECVPKTINFO", IPV6_RECVPKTINFO, 1, IPV6_PKTINFO, 1,
+	 {{{{{0} } }, 0} }, {{{{{0} } }, 0} }, sizeof(int)},
+	{"IPV6_RECVHOPLIMIT", IPV6_RECVHOPLIMIT, 1, IPV6_HOPLIMIT, 1,
+	 {{{{{0} } }, 0} }, {{{{{0} } }, 0} }, sizeof(int)},
+	{"IPV6_RECVRTHDR", IPV6_RECVRTHDR, 0, IPV6_RTHDR, 1,
+	 {{{{{0} } }, 0} }, {{{{{0} } }, 0} }, sizeof(int)},
+	{"IPV6_RECVHOPOPTS", IPV6_RECVHOPOPTS, 0, IPV6_HOPOPTS, 1,
+	 {{{{{0} } }, 0} }, {{{{{0} } }, 0} }, sizeof(int)},
+	{"IPV6_RECVDSTOPTS", IPV6_RECVDSTOPTS, 0, IPV6_DSTOPTS, 1,
+	 {{{{{0} } }, 0} }, {{{{{0} } }, 0} }, sizeof(int)},
+	{"IPV6_RECVTCLASS", IPV6_RECVTCLASS, 1, IPV6_TCLASS, 1,
+	 {{{{{0} } }, 0} }, {{{{{0} } }, 0} }, sizeof(int)},
+	/* make sure TCLASS stays when setting another opt */
+	{"IPV6_RECVTCLASS (2)", IPV6_RECVHOPLIMIT, 1, IPV6_TCLASS, 0,
+	 {{{{{0} } }, 0} }, {{{{{0} } }, 0} }, sizeof(int)},
+	/* OLD values */
+	{"IPV6_2292PKTINFO", IPV6_2292PKTINFO, 1, IPV6_2292PKTINFO, 1,
+	 {{{{{0} } }, 0} }, {{{{{0} } }, 0} }, sizeof(int)},
+	{"IPV6_2292HOPLIMIT", IPV6_2292HOPLIMIT, 1, IPV6_2292HOPLIMIT, 1,
+	 {{{{{0} } }, 0} }, {{{{{0} } }, 0} }, sizeof(int)},
+	{"IPV6_2292RTHDR", IPV6_2292RTHDR, 0, IPV6_2292RTHDR, 1,
+	 {{{{{0} } }, 0} }, {{{{{0} } }, 0} }, sizeof(int)},
+	{"IPV6_2292HOPOPTS", IPV6_2292HOPOPTS, 0, IPV6_2292HOPOPTS, 1,
+	 {{{{{0} } }, 0} }, {{{{{0} } }, 0} }, sizeof(int)},
+	{"IPV6_2292DSTOPTS", IPV6_2292DSTOPTS, 0, IPV6_2292DSTOPTS, 1,
+	 {{{{{0} } }, 0} }, {{{{{0} } }, 0} }, sizeof(int)},
+};
+
+#define SOCOUNT	ARRAY_SIZE(sotab)
 
 struct soprot {
-	int sop_pid;		/* sender PID */
-	int sop_seq;		/* sequence # */
-	int sop_dlen;		/* tp_dat length */
+	int sop_pid;			/* sender PID */
+	int sop_seq;			/* sequence # */
+	int sop_dlen;			/* tp_dat length */
 	unsigned char sop_dat[0];	/* user data */
 };
 
-unsigned char tpbuf[sizeof(struct soprot) + 2048];
-unsigned char rpbuf[sizeof(struct soprot) + 2048];
+static unsigned char tpbuf[sizeof(struct soprot) + 2048];
+static unsigned char rpbuf[sizeof(struct soprot) + 2048];
 
-unsigned char control[2048];
-int clen;
+static unsigned char control[2048];
 
-int seq;
+static int seq;
 
-int setupso(void)
-{
-/* add routing headers, other ancillary data here */
-	return 0;
-}
-
-struct cme {
+static struct cme {
 	int cm_len;
 	int cm_level;
 	int cm_type;
@@ -235,26 +192,21 @@ struct cme {
 		uint32_t cmu_hops;
 	} cmu;
 } cmtab[] = {
-	{
-		sizeof(uint32_t), SOL_IPV6, IPV6_TCLASS, {
-		0x12}
-	}
-	, {
-		sizeof(uint32_t), SOL_IPV6, IPV6_HOPLIMIT, {
-		0x21}
-	}
-,};
+	{sizeof(uint32_t), SOL_IPV6, IPV6_TCLASS, {0x12} },
+	{sizeof(uint32_t), SOL_IPV6, IPV6_HOPLIMIT, {0x21} },
+};
 
-#define CMCOUNT	(sizeof(cmtab)/sizeof(cmtab[0]))
+#define CMCOUNT	ARRAY_SIZE(cmtab)
 
-ssize_t sendall(int st)
+static ssize_t sendall(int st)
 {
 	struct sockaddr_in6 sin6;
 	struct msghdr msg;
 	struct iovec iov;
 	struct soprot *psop;
 	unsigned char *pd;
-	int i, ctotal;
+	unsigned int i;
+	int ctotal;
 
 	psop = (struct soprot *)tpbuf;
 	psop->sop_pid = htonl(getpid());
@@ -291,7 +243,7 @@ ssize_t sendall(int st)
 	return sendmsg(st, &msg, 0);
 }
 
-void so_test(struct soent *psoe)
+static void so_test(struct soent *psoe)
 {
 	struct sockaddr_in6 sin6;
 	union soval sobuf;
@@ -317,10 +269,9 @@ void so_test(struct soent *psoe)
 	memset(&sin6, 0, sizeof(sin6));
 	sin6.sin6_family = AF_INET6;
 	sin6.sin6_addr = in6addr_loopback;
-	if (bind(sr, (struct sockaddr *)&sin6, sizeof(sin6)) < 0) {
-		tst_resm(TBROK, "%s: bind: %s", psoe->so_tname,
-			 strerror(errno));
-	}
+
+	SAFE_BIND(NULL, sr, (struct sockaddr *)&sin6, sizeof(sin6));
+
 	if (setsockopt(sr, SOL_IPV6, psoe->so_opt, &psoe->so_clrval,
 		       psoe->so_valsize) < 0) {
 		tst_resm(TBROK, "%s: setsockopt: %s", psoe->so_tname,
@@ -345,12 +296,8 @@ void so_test(struct soent *psoe)
 	else
 		tst_resm(TPASS, "%s set-get", psoe->so_tname);
 
-	st = socket(PF_INET6, SOCK_RAW, NH_TEST);
-	if (st < 0) {
-		tst_resm(TBROK, "%s transmit socket: %s", psoe->so_tname,
-			 strerror(errno));
-		return;
-	}
+	st = SAFE_SOCKET(NULL, PF_INET6, SOCK_RAW, NH_TEST);
+
 	if (sendall(st) < 0) {
 		tst_resm(TBROK, "%s transmit sendto: %s", psoe->so_tname,
 			 strerror(errno));
@@ -409,7 +356,7 @@ void so_test(struct soent *psoe)
 					 psoe->so_tname, strerror(errno));
 				return;
 			}
-/* check pid & seq here */
+			/* check pid & seq here */
 			break;
 		}
 		gotone = 0;
@@ -429,7 +376,7 @@ void so_test(struct soent *psoe)
 				return;
 			}
 		}
-/* check contents here */
+		/* check contents here */
 		if (psoe->so_dorecv)
 			tst_resm(gotone ? TPASS : TFAIL, "%s receive",
 				 psoe->so_tname);
@@ -451,20 +398,18 @@ static int ipv6_addr_scope(struct in6_addr *pin6)
 }
 #endif /* HAVE_IFADDRS_H */
 
-int getsock(char *tname, struct sockaddr_in6 *psin6_arg, int scope)
+static int getsock(char *tname, struct sockaddr_in6 *psin6_arg, int scope)
 {
 #ifdef HAVE_IFADDRS_H
 	static struct ifaddrs *pifa_head;
 	struct ifaddrs *pifa;
 	struct sockaddr_in6 *psin6;
-	char strbuf[128];
 	int ifindex = 0;
 	int s;
 
-	if (!pifa_head && getifaddrs(&pifa_head)) {
-		tst_resm(TBROK, "%s: getifaddrs failed", tname);
-		return -1;
-	}
+	if (!pifa_head && getifaddrs(&pifa_head))
+		tst_brkm(TBROK, NULL, "%s: getifaddrs failed", tname);
+
 	if (psin6_arg)
 		ifindex = psin6_arg->sin6_scope_id;
 
@@ -483,21 +428,16 @@ int getsock(char *tname, struct sockaddr_in6 *psin6_arg, int scope)
 		     (this_scope > 0 && this_scope != scope)))
 			continue;
 		psin6->sin6_scope_id = if_nametoindex(pifa->ifa_name);
-		if ((ifindex < 0 && -ifindex == psin6->sin6_scope_id) ||
-		    (ifindex > 0 && ifindex != psin6->sin6_scope_id))
+		if ((ifindex < 0 &&
+		     -(unsigned int)ifindex == psin6->sin6_scope_id) ||
+		    (ifindex > 0 &&
+		     (unsigned int)ifindex != psin6->sin6_scope_id))
 			continue;
-		s = socket(PF_INET6, SOCK_DGRAM, 0);
-		if (s < 0) {
-			tst_resm(TBROK, "%s: socket %s", tname,
-				 strerror(errno));
-			return -1;
-		}
-		if (bind(s, pifa->ifa_addr, sizeof(struct sockaddr_in6)) < 0) {
-			tst_resm(TBROK, "%s: bind \"%s\": %s", tname,
-				 inet_ntop(AF_INET6, &psin6->sin6_addr, strbuf,
-					   sizeof(strbuf)), strerror(errno));
-			return -1;
-		}
+
+		s = SAFE_SOCKET(NULL, PF_INET6, SOCK_DGRAM, 0);
+
+		SAFE_BIND(NULL, s, pifa->ifa_addr, sizeof(struct sockaddr_in6));
+
 		if (psin6_arg) {
 			*psin6_arg = *psin6;
 			psin6_arg->sin6_scope_id =
@@ -539,7 +479,10 @@ int getsock(char *tname, struct sockaddr_in6 *psin6_arg, int scope)
 	}
 	return -1;
 #else /* HAVE_IFADDRS_H */
+/*
 	return -1;
+*/
+	tst_brkm(TBROK, NULL, "HAVE_IFADDRS_H is not defined");
 #endif
 }
 
@@ -548,46 +491,28 @@ int getsock(char *tname, struct sockaddr_in6 *psin6_arg, int scope)
  * RFC 3542 IPV6_PKTINFO not in mainline yet (as of 2.6.15). The get/set
  * tests are below, and comments for some further tests to be added later
  */
-void test_pktinfo(void)
+static void test_pktinfo(void)
 {
-	int s_snd, s_rcv[3] = { -1, -1, -1 };
+	int s_snd;
 	struct sockaddr_in6 sa_rcv[3];
-	int s, i;
-	struct ifaddrs *pifa_head, *pifa;
-	struct sockaddr_in6 *psin6;
 	char strbuf[128];
 	char *tname = "IPV6_PKTINFO";
 	struct in6_pktinfo pi, pi_tmp;
-	int sinlen;
-	int optlen;
+	socklen_t optlen;
 
 	s_snd = getsock(tname, 0, IPV6_ADDR_GLOBAL);
-	if (s_snd < 0) {
-		tst_resm(TBROK, "%s: can't create send socket", tname);
-		return;
-	}
+
 	/* global-scope address, interface X */
 	sa_rcv[0].sin6_scope_id = 0;
-	s_rcv[0] = getsock(tname, &sa_rcv[0], IPV6_ADDR_GLOBAL);
-	if (s_rcv[0] == -1) {
-		tst_resm(TBROK, "%s: only link-scope addresses", tname);
-		return;
-	}
+	getsock(tname, &sa_rcv[0], IPV6_ADDR_GLOBAL);
+
 	/* link-local-scope address, interface X */
 	sa_rcv[1].sin6_scope_id = sa_rcv[0].sin6_scope_id;
-	s_rcv[1] = getsock(tname, &sa_rcv[1], IPV6_ADDR_LINK);
-	if (s_rcv[1] < 0) {
-		tst_resm(TBROK, "%s: no link-local address on ifindex %d",
-			 tname, sa_rcv[0].sin6_scope_id);
-		return;
-	}
+
+	getsock(tname, &sa_rcv[1], IPV6_ADDR_LINK);
 	/* link-local-scope address, interface Y */
 	sa_rcv[2].sin6_scope_id = -sa_rcv[0].sin6_scope_id;
-	s_rcv[2] = getsock(tname, &sa_rcv[2], IPV6_ADDR_LINK);
-	if (s_rcv[2] < 0) {
-		tst_resm(TBROK, "%s: only one interface?", tname);
-		return;
-	}
+	getsock(tname, &sa_rcv[2], IPV6_ADDR_LINK);
 	/* send to rcv1 to verify communication */
 	/* force to rcv2 w/ PKTINFO */
 /* TESTS: */
@@ -615,8 +540,8 @@ void test_pktinfo(void)
 				   sizeof(strbuf2)), pi.ipi6_ifindex);
 	} else
 		tst_resm(TPASS, "%s", tname);
-/* ancillary data override */
-/* link-local, wrong interface */
+	/* ancillary data override */
+	/* link-local, wrong interface */
 	tname = "IPV6_PKTINFO invalid {lladdr, intf}";
 	pi.ipi6_addr = sa_rcv[1].sin6_addr;
 	pi.ipi6_ifindex = sa_rcv[2].sin6_scope_id;
@@ -628,17 +553,12 @@ void test_pktinfo(void)
 		tst_resm(TFAIL, "%s errno %d != %d", tname, TEST_ERRNO, EINVAL);
 	else
 		tst_resm(TPASS, "%s", tname);
-/* nonexistent interface */
-/* non-local address */
-/* clear address */
-/* clear interface */
-/* sendmsg() sin6_scope differs with ancillary data interface */
 }
 #endif /* notyet */
 
-void do_tests(void)
+static void do_tests(void)
 {
-	int i;
+	unsigned int i;
 
 	for (i = 0; i < SOCOUNT; ++i) {
 		sotab[i].so_clrval.sou_bool = 0;
@@ -650,11 +570,14 @@ void do_tests(void)
 #endif /* notyet - see test_pktinfo() comment above */
 }
 
-void setup(void)
+static void setup(void)
 {
-	TEST_PAUSE;		/* if -P option specified */
+	TEST_PAUSE;
+
+	tst_tmpdir();
 }
 
-void cleanup(void)
+static void cleanup(void)
 {
+	tst_rmdir();
 }
-- 
1.9.3


------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v5 09/11] asapi_07: Use 'tst_tmpdir' and more cleanup
  2015-07-16  5:30                         ` [LTP] [PATCH v5 " Zeng Linggang
                                             ` (6 preceding siblings ...)
  2015-07-16  5:30                           ` [LTP] [PATCH v5 08/11] lib6/asapi_06.c: Cleanup Zeng Linggang
@ 2015-07-16  5:30                           ` Zeng Linggang
  2015-07-16  5:30                           ` [LTP] [PATCH v5 10/11] lib6/getaddrinfo_01.c: Cleanup Zeng Linggang
                                             ` (2 subsequent siblings)
  10 siblings, 0 replies; 55+ messages in thread
From: Zeng Linggang @ 2015-07-16  5:30 UTC (permalink / raw)
  To: alexey.kodanev; +Cc: ltp-list

* Use 'tst_tmpdir' and 'tst_rmdir'.
* Add 'static' for the cleanup.

Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
 testcases/network/lib6/asapi_07.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/testcases/network/lib6/asapi_07.c b/testcases/network/lib6/asapi_07.c
index 826cea6..97221f7 100644
--- a/testcases/network/lib6/asapi_07.c
+++ b/testcases/network/lib6/asapi_07.c
@@ -86,6 +86,7 @@ static struct etent {
 };
 
 static void setup(void);
+static void cleanup(void);
 static void adatet(const struct etent *etptr);
 
 char *TCID = "asapi_07";
@@ -106,12 +107,20 @@ int main(int argc, char *argv[])
 			adatet(&etab[i]);
 	}
 
+	cleanup();
 	tst_exit();
 }
 
 void setup(void)
 {
 	TEST_PAUSE;
+
+	tst_tmpdir();
+}
+
+static void cleanup(void)
+{
+	tst_rmdir();
 }
 
 /*  existence tests */
-- 
1.9.3


------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v5 10/11] lib6/getaddrinfo_01.c: Cleanup
  2015-07-16  5:30                         ` [LTP] [PATCH v5 " Zeng Linggang
                                             ` (7 preceding siblings ...)
  2015-07-16  5:30                           ` [LTP] [PATCH v5 09/11] asapi_07: Use 'tst_tmpdir' and more cleanup Zeng Linggang
@ 2015-07-16  5:30                           ` Zeng Linggang
  2015-07-16  5:30                           ` [LTP] [PATCH v5 11/11] ipv6_lib: Add it into default Zeng Linggang
  2015-08-05 14:00                           ` [LTP] [PATCH v5 01/11] SAFE_MACROS: Add socket(), bind(), listen(), connect() and getsockname() Cyril Hrubis
  10 siblings, 0 replies; 55+ messages in thread
From: Zeng Linggang @ 2015-07-16  5:30 UTC (permalink / raw)
  To: alexey.kodanev; +Cc: ltp-list

* Add 'static' before some functions and global variables.
* Remove cleanup() function.
* Remove useless comments.
* In every test function, using TINFO instead of TPASS
  marks the success of each inner test.
* Some cleanup.

Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
 testcases/network/lib6/getaddrinfo_01.c | 503 ++++++++++++++++++--------------
 1 file changed, 281 insertions(+), 222 deletions(-)

diff --git a/testcases/network/lib6/getaddrinfo_01.c b/testcases/network/lib6/getaddrinfo_01.c
index ec29b5d..a812e77 100644
--- a/testcases/network/lib6/getaddrinfo_01.c
+++ b/testcases/network/lib6/getaddrinfo_01.c
@@ -1,43 +1,21 @@
 /*
+ * Copyright (c) 2015 Fujitsu Ltd.
+ * Copyright (c) International Business Machines  Corp., 2001
  *
- *   Copyright (c) International Business Machines  Corp., 2001
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
  *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
  *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/*
- * Test Name: getaddrinfo_01
- *
- * Test Description:
- *  Tests for getaddrinfo library function
- *
- * Usage:  <for command-line>
- *  getaddrinfo_01 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -e   : Turn on errno logging.
- *	       -i n : Execute test n times.
- *	       -I x : Execute test for x seconds.
- *	       -P x : Pause for x seconds between iterations.
- *	       -t   : Turn on syscall timing.
- *
- * HISTORY
- *	07/2004 written by David L Stevens
- *
- * RESTRICTIONS:
- *  None.
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
+ * Author: David L Stevens
  */
 
 #include <unistd.h>
@@ -53,40 +31,38 @@
 #define AI_V4MAPPED    0x0008	/* IPv4 mapped addresses are acceptable.  */
 #endif
 
-char *TCID = "getaddrinfo_01";	/* Test program identifier.    */
-int testno;
+static void setup(void);
+static void gaiv4(void);
+static void gaiv6(void);
 
-void setup(void), cleanup(void);
-
-int TST_TOTAL = 1;
-
-/* a host that isn't where LTP is running */
-#define REMOTEHOSTNAME	"www.ibm.com"
-
-void gaiv4(void), gaiv6(void);
-void dumpres(struct addrinfo *);
+char *TCID = "getaddrinfo_01";
+int TST_TOTAL = 2;
 
 int main(int argc, char *argv[])
 {
 	int lc;
 
-	/* Parse standard options given to run the test. */
 	tst_parse_opts(argc, argv, NULL, NULL);
 
 	setup();
 
 	for (lc = 0; TEST_LOOPING(lc); ++lc) {
+		tst_count = 0;
+
 		gaiv4();
 		gaiv6();
 	}
-	cleanup();
 
-	return (0);
+	tst_exit();
 }
 
-/* getaddrinfo tests (v4) */
+static void setup(void)
+{
+	TEST_PAUSE;
+}
 
-void gaiv4(void)
+/* getaddrinfo tests (v4) */
+static void gaiv4(void)
 {
 	struct addrinfo *aires, hints, *pai;
 	char hostname[MAXHOSTNAMELEN + 1];
@@ -132,13 +108,18 @@ void gaiv4(void)
 				 psin ? psin->sin_family : 0,
 				 psin ? psin->sin_port : 0,
 				 psin ? htons(psin->sin_port) : 0);
-		} else
-			tst_resm(TPASS, "getaddrinfo IPv4 basic lookup");
-		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN ? TFAIL : TPASS, "getaddrinfo IPv4 basic "
+			freeaddrinfo(aires);
+			return;
+		} else {
+			tst_resm(TINFO, "getaddrinfo IPv4 basic lookup");
+			freeaddrinfo(aires);
+		}
+	} else {
+		tst_resm(TFAIL, "getaddrinfo IPv4 basic "
 			 "lookup (\"%s\") returns %ld (\"%s\")", hostname,
 			 TEST_RETURN, gai_strerror(TEST_RETURN));
+		return;
+	}
 
 	/* test 2, IPv4 canonical name */
 	memset(&hints, 0, sizeof(hints));
@@ -152,20 +133,26 @@ void gaiv4(void)
 		if (!pai) {
 			tst_resm(TFAIL, "getaddrinfo IPv4 canonical name: no "
 				 "entries with canonical name set");
+			freeaddrinfo(aires);
+			return;
 		} else if (strcasecmp(hostname, pai->ai_canonname)) {
 			tst_resm(TFAIL, "getaddrinfo IPv4 canonical name "
 				 "(\"%s\") doesn't match hostname (\"%s\")",
 				 pai->ai_canonname, hostname);
-		} else
-			tst_resm(TPASS, "getaddrinfo IPv4 canonical name");
-		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN ? TFAIL : TPASS, "getaddrinfo IPv4 "
+			freeaddrinfo(aires);
+			return;
+		} else {
+			tst_resm(TINFO, "getaddrinfo IPv4 canonical name");
+			freeaddrinfo(aires);
+		}
+	} else {
+		tst_resm(TFAIL, "getaddrinfo IPv4 "
 			 "canonical name (\"%s\") returns %ld (\"%s\")",
 			 shortname, TEST_RETURN, gai_strerror(TEST_RETURN));
+		return;
+	}
 
 	/* test 3, IPv4 host+service name */
-
 	memset(&hints, 0, sizeof(hints));
 	/*
 	 * These are hard-coded for echo/7 to avoid using getservbyname(),
@@ -200,13 +187,18 @@ void gaiv4(void)
 				 psin ? psin->sin_family : 0,
 				 psin ? psin->sin_port : 0,
 				 psin ? htons(psin->sin_port) : 0);
-		} else
-			tst_resm(TPASS, "getaddrinfo IPv4 host+service");
-		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN ? TFAIL : TPASS, "getaddrinfo IPv4 host+"
+			freeaddrinfo(aires);
+			return;
+		} else {
+			tst_resm(TINFO, "getaddrinfo IPv4 host+service");
+			freeaddrinfo(aires);
+		}
+	} else {
+		tst_resm(TFAIL, "getaddrinfo IPv4 host+"
 			 "service returns %ld (\"%s\")", TEST_RETURN,
 			 gai_strerror(TEST_RETURN));
+		return;
+	}
 
 	/* test 4, IPv4 hostname+service, AI_PASSIVE */
 	memset(&hints, 0, sizeof(hints));
@@ -244,18 +236,22 @@ void gaiv4(void)
 				 psin ? psin->sin_family : 0,
 				 psin ? psin->sin_port : 0,
 				 psin ? htons(psin->sin_port) : 0);
-		} else
-			tst_resm(TPASS,
+			freeaddrinfo(aires);
+			return;
+		} else {
+			tst_resm(TINFO,
 				 "getaddrinfo IPv4 host+service PASSIVE");
-		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN ? TFAIL : TPASS, "getaddrinfo IPv4 host+"
+			freeaddrinfo(aires);
+		}
+	} else {
+		tst_resm(TFAIL, "getaddrinfo IPv4 host+"
 			 "service, PASSIVE (\"%s\", \"%s\") returns %ld (\"%s\")",
 			 hostname, service, TEST_RETURN,
 			 gai_strerror(TEST_RETURN));
+		return;
+	}
 
 	/* test 5, IPv4 host+service w/ AI_NUMERICHOST */
-
 	memset(&hints, 0, sizeof(hints));
 	strcpy(service, "echo");
 	servnum = 7;
@@ -266,8 +262,11 @@ void gaiv4(void)
 		tst_resm(TFAIL, "getaddrinfo IPv4 AI_NUMERICHOST w/ hostname: "
 			 "returns %ld expected %d (EAI_NONAME)",
 			 TEST_RETURN, EAI_NONAME);
+		if (!TEST_RETURN)
+			freeaddrinfo(aires);
+		return;
 	} else
-		tst_resm(TPASS, "getaddrinfo IPv4 AI_NUMERICHOST w/ hostname");
+		tst_resm(TINFO, "getaddrinfo IPv4 AI_NUMERICHOST w/ hostname");
 	if (!TEST_RETURN)
 		freeaddrinfo(aires);
 
@@ -306,17 +305,28 @@ void gaiv4(void)
 				 psin ? psin->sin_family : 0,
 				 psin ? psin->sin_port : 0,
 				 psin ? htons(psin->sin_port) : 0);
-		} else
-			tst_resm(TPASS, "getaddrinfo IPv4 0+service, PASSIVE");
-		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN == EAI_BADFLAGS ? TPASS : TFAIL,
-			 "getaddrinfo IPv4 0+service, PASSIVE (\"\", \"%s\") "
-			 "returns %ld (\"%s\")", service, TEST_RETURN,
-			 gai_strerror(TEST_RETURN));
+			freeaddrinfo(aires);
+			return;
+		} else {
+			tst_resm(TINFO, "getaddrinfo IPv4 0+service, PASSIVE");
+			freeaddrinfo(aires);
+		}
+	} else {
+		if (TEST_RETURN == EAI_BADFLAGS) {
+			tst_resm(TINFO, "getaddrinfo IPv4 0+service,"
+				" PASSIVE (\"\", \"%s\") returns %ld (\"%s\")",
+				service, TEST_RETURN,
+				gai_strerror(TEST_RETURN));
+		} else {
+			tst_resm(TFAIL, "getaddrinfo IPv4 0+service,i"
+				" PASSIVE (\"\", \"%s\") returns %ld (\"%s\")",
+				service, TEST_RETURN,
+				gai_strerror(TEST_RETURN));
+			return;
+		}
+	}
 
 	/* test 7, IPv4 0+service */
-
 	memset(&hints, 0, sizeof(hints));
 	hints.ai_family = AF_INET;
 	hints.ai_socktype = SOCK_STREAM;
@@ -350,19 +360,30 @@ void gaiv4(void)
 				 psin ? psin->sin_family : 0,
 				 psin ? psin->sin_port : 0,
 				 psin ? htons(psin->sin_port) : 0);
-		} else
-			tst_resm(TPASS, "getaddrinfo IPv4 0+service");
-		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN == EAI_BADFLAGS ? TPASS : TFAIL,
-			 "getaddrinfo IPv4 0+service (\"\", \"%s\") returns %ld "
-			 "(\"%s\")", service, TEST_RETURN,
-			 gai_strerror(TEST_RETURN));
+			freeaddrinfo(aires);
+			return;
+		} else {
+			tst_resm(TINFO, "getaddrinfo IPv4 0+service");
+			freeaddrinfo(aires);
+		}
+	} else {
+		if (TEST_RETURN == EAI_BADFLAGS) {
+			tst_resm(TINFO, "getaddrinfo IPv4 "
+				"0+service (\"\", \"%s\") returns %ld (\"%s\")",
+				service, TEST_RETURN,
+				gai_strerror(TEST_RETURN));
+		} else {
+			tst_resm(TFAIL, "getaddrinfo IPv4 "
+				"0+service (\"\", \"%s\") returns %ld (\"%s\")",
+				service, TEST_RETURN,
+				gai_strerror(TEST_RETURN));
+			return;
+		}
+	}
 
 	/* test 8, IPv4 host+service, AI_NUMERICSERV */
-
 #ifndef AI_NUMERICSERV
-	tst_resm(TFAIL, "getaddrinfo IPv4 host+service, AI_NUMERICSERV: flag "
+	tst_resm(TCONF, "getaddrinfo IPv4 host+service, AI_NUMERICSERV: flag "
 		 "not implemented");
 #else
 	memset(&hints, 0, sizeof(hints));
@@ -376,15 +397,18 @@ void gaiv4(void)
 			 "getaddrinfo IPv4 host+service, AI_NUMERICSERV: "
 			 "returns %ld (\"%s\") expected %d (EAI_NONAME)",
 			 TEST_RETURN, gai_strerror(TEST_RETURN), EAI_NONAME);
-	} else
-		tst_resm(TPASS,
+		if (!TEST_RETURN)
+			freeaddrinfo(aires);
+		return;
+	} else {
+		tst_resm(TINFO,
 			 "getaddrinfo IPv4 host+service, AI_NUMERICSERV");
+	}
 	if (!TEST_RETURN)
 		freeaddrinfo(aires);
 #endif /* AI_NUMERICSERV */
 
 	/* test 9, IPv4 SOCK_STREAM/IPPROTO_UDP hints */
-
 	memset(&hints, 0, sizeof(hints));
 	hints.ai_family = AF_INET;
 	hints.ai_socktype = SOCK_STREAM;
@@ -396,12 +420,13 @@ void gaiv4(void)
 		tst_resm(TFAIL, "getaddrinfo IPv4 SOCK_STREAM/IPPROTO_UDP "
 			 "hints");
 		freeaddrinfo(aires);
-	} else
-		tst_resm(TPASS, "getaddrinfo IPv4 SOCK_STREAM/IPPROTO_UDP "
+		return;
+	} else {
+		tst_resm(TINFO, "getaddrinfo IPv4 SOCK_STREAM/IPPROTO_UDP "
 			 "hints");
+	}
 
 	/* test 10, IPv4 socktype 0, 513 */
-
 	memset(&hints, 0, sizeof(hints));
 	hints.ai_family = AF_INET;
 	hints.ai_socktype = 0;
@@ -439,20 +464,31 @@ void gaiv4(void)
 				 psin ? psin->sin_family : 0,
 				 psin ? psin->sin_port : 0,
 				 psin ? htons(psin->sin_port) : 0);
-		} else if (got_tcp && got_udp)
-			tst_resm(TPASS, "getaddrinfo IPv4 socktype 0,513");
-		else
+			freeaddrinfo(aires);
+			return;
+		} else if (got_tcp && got_udp) {
+			tst_resm(TINFO, "getaddrinfo IPv4 socktype 0,513");
+			freeaddrinfo(aires);
+		} else {
 			tst_resm(TFAIL, "getaddrinfo IPv4 socktype 0,513 TCP %d"
 				 " UDP %d", got_tcp, got_udp);
-		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN == EAI_BADFLAGS ? TPASS : TFAIL,
-			 "getaddrinfo IPv4 socktype 0,513 (\"\", \"%s\") returns"
-			 " %ld (\"%s\")", service, TEST_RETURN,
-			 gai_strerror(TEST_RETURN));
+			freeaddrinfo(aires);
+			return;
+		}
+	} else {
+		if (TEST_RETURN == EAI_BADFLAGS) {
+			tst_resm(TINFO, "getaddrinfo IPv4 socktype 0,513"
+				" (\"\", \"%s\") returns %ld (\"%s\")", service,
+				TEST_RETURN, gai_strerror(TEST_RETURN));
+		} else {
+			tst_resm(TFAIL, "getaddrinfo IPv4 socktype 0,513"
+				" (\"\", \"%s\") returns %ld (\"%s\")", service,
+				TEST_RETURN, gai_strerror(TEST_RETURN));
+			return;
+		}
+	}
 
 	/* test 11, IPv4 AI_V4MAPPED */
-
 	/* AI_V4MAPPED should be ignored because family != AF_INET6 */
 	memset(&hints, 0, sizeof(hints));
 	hints.ai_family = AF_INET;
@@ -482,18 +518,25 @@ void gaiv4(void)
 				 psin ? psin->sin_family : 0,
 				 psin ? psin->sin_port : 0,
 				 psin ? htons(psin->sin_port) : 0);
-		} else
-			tst_resm(TPASS, "getaddrinfo IPv4 AI_V4MAPPED");
-		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN ? TFAIL : TPASS, "getaddrinfo IPv4 "
+			freeaddrinfo(aires);
+			return;
+		} else {
+			tst_resm(TINFO, "getaddrinfo IPv4 AI_V4MAPPED");
+			freeaddrinfo(aires);
+		}
+	} else {
+		tst_resm(TFAIL, "getaddrinfo IPv4 "
 			 "AI_V4MAPPED (\"%s\") returns %ld (\"%s\")", hostname,
 			 TEST_RETURN, gai_strerror(TEST_RETURN));
+		return;
+	}
+
+
+	tst_resm(TPASS, "getaddrinfo tests (v4) succeed");
 }
 
 /* getaddrinfo tests (v6) */
-
-void gaiv6(void)
+static void gaiv6(void)
 {
 	struct addrinfo *aires, hints, *pai;
 	char hostname[MAXHOSTNAMELEN + 1];
@@ -539,13 +582,18 @@ void gaiv6(void)
 				 psin6 ? psin6->sin6_family : 0,
 				 psin6 ? psin6->sin6_port : 0,
 				 psin6 ? htons(psin6->sin6_port) : 0);
-		} else
-			tst_resm(TPASS, "getaddrinfo IPv6 basic lookup");
-		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN ? TFAIL : TPASS, "getaddrinfo IPv6 basic "
+			freeaddrinfo(aires);
+			return;
+		} else {
+			tst_resm(TINFO, "getaddrinfo IPv6 basic lookup");
+			freeaddrinfo(aires);
+		}
+	} else {
+		tst_resm(TFAIL, "getaddrinfo IPv6 basic "
 			 "lookup (\"%s\") returns %ld (\"%s\")", hostname,
 			 TEST_RETURN, gai_strerror(TEST_RETURN));
+		return;
+	}
 
 	/* test 13, IPv6 canonical name */
 	memset(&hints, 0, sizeof(hints));
@@ -559,20 +607,26 @@ void gaiv6(void)
 		if (!pai) {
 			tst_resm(TFAIL, "getaddrinfo IPv6 canonical name: no "
 				 "entries with canonical name set");
+			freeaddrinfo(aires);
+			return;
 		} else if (strcasecmp(hostname, pai->ai_canonname)) {
 			tst_resm(TFAIL, "getaddrinfo IPv6 canonical name "
 				 "(\"%s\") doesn't match hostname (\"%s\")",
 				 pai->ai_canonname, hostname);
-		} else
-			tst_resm(TPASS, "getaddrinfo IPv6 canonical name");
-		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN ? TFAIL : TPASS, "getaddrinfo IPv6 "
+			freeaddrinfo(aires);
+			return;
+		} else {
+			tst_resm(TINFO, "getaddrinfo IPv6 canonical name");
+			freeaddrinfo(aires);
+		}
+	} else {
+		tst_resm(TFAIL, "getaddrinfo IPv6 "
 			 "canonical name (\"%s\") returns %ld (\"%s\")",
 			 shortname, TEST_RETURN, gai_strerror(TEST_RETURN));
+		return;
+	}
 
 	/* test 14, IPv6 host+service name */
-
 	memset(&hints, 0, sizeof(hints));
 	/*
 	 * These are hard-coded for echo/7 to avoid using getservbyname(),
@@ -607,13 +661,18 @@ void gaiv6(void)
 				 psin6 ? psin6->sin6_family : 0,
 				 psin6 ? psin6->sin6_port : 0,
 				 psin6 ? htons(psin6->sin6_port) : 0);
-		} else
-			tst_resm(TPASS, "getaddrinfo IPv6 host+service");
-		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN ? TFAIL : TPASS, "getaddrinfo IPv6 host+"
+			freeaddrinfo(aires);
+			return;
+		} else {
+			tst_resm(TINFO, "getaddrinfo IPv6 host+service");
+			freeaddrinfo(aires);
+		}
+	} else {
+		tst_resm(TFAIL, "getaddrinfo IPv6 host+"
 			 "service returns %ld (\"%s\")", TEST_RETURN,
 			 gai_strerror(TEST_RETURN));
+		return;
+	}
 
 	/* test 15, IPv6 hostname+service, AI_PASSIVE */
 	memset(&hints, 0, sizeof(hints));
@@ -652,18 +711,22 @@ void gaiv6(void)
 				 psin6 ? psin6->sin6_family : 0,
 				 psin6 ? psin6->sin6_port : 0,
 				 psin6 ? htons(psin6->sin6_port) : 0);
-		} else
-			tst_resm(TPASS,
+			freeaddrinfo(aires);
+			return;
+		} else {
+			tst_resm(TINFO,
 				 "getaddrinfo IPv6 host+service PASSIVE");
-		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN ? TFAIL : TPASS, "getaddrinfo IPv6 host+"
+			freeaddrinfo(aires);
+		}
+	} else {
+		tst_resm(TFAIL, "getaddrinfo IPv6 host+"
 			 "service, PASSIVE (\"%s\", \"%s\") returns %ld (\"%s\")",
 			 hostname, service, TEST_RETURN,
 			 gai_strerror(TEST_RETURN));
+		return;
+	}
 
 	/* test 16, IPv6 host+service w/ AI_NUMERICHOST */
-
 	memset(&hints, 0, sizeof(hints));
 	strcpy(service, "echo");
 	servnum = 7;
@@ -674,8 +737,11 @@ void gaiv6(void)
 		tst_resm(TFAIL, "getaddrinfo IPv6 AI_NUMERICHOST w/ hostname: "
 			 "returns %ld expected %d (EAI_NONAME)",
 			 TEST_RETURN, EAI_NONAME);
+		if (!TEST_RETURN)
+			freeaddrinfo(aires);
+		return;
 	} else
-		tst_resm(TPASS, "getaddrinfo IPv6 AI_NUMERICHOST w/ hostname");
+		tst_resm(TINFO, "getaddrinfo IPv6 AI_NUMERICHOST w/ hostname");
 	if (!TEST_RETURN)
 		freeaddrinfo(aires);
 
@@ -715,17 +781,26 @@ void gaiv6(void)
 				 psin6 ? psin6->sin6_family : 0,
 				 psin6 ? psin6->sin6_port : 0,
 				 psin6 ? htons(psin6->sin6_port) : 0);
-		} else
-			tst_resm(TPASS, "getaddrinfo IPv6 0+service, PASSIVE");
-		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN == EAI_BADFLAGS ? TPASS : TFAIL,
-			 "getaddrinfo IPv6 0+service, PASSIVE (\"\", \"%s\") "
-			 "returns %ld (\"%s\")", service, TEST_RETURN,
-			 gai_strerror(TEST_RETURN));
+			freeaddrinfo(aires);
+			return;
+		} else {
+			tst_resm(TINFO, "getaddrinfo IPv6 0+service, PASSIVE");
+			freeaddrinfo(aires);
+		}
+	} else {
+		if (TEST_RETURN == EAI_BADFLAGS) {
+			tst_resm(TINFO, "getaddrinfo IPv6 0+service, PASSIVE"
+				" (\"\", \"%s\") returns %ld (\"%s\")", service,
+				TEST_RETURN, gai_strerror(TEST_RETURN));
+		} else {
+			tst_resm(TFAIL, "getaddrinfo IPv6 0+service, PASSIVE"
+				" (\"\", \"%s\") returns %ld (\"%s\")", service,
+				TEST_RETURN, gai_strerror(TEST_RETURN));
+			return;
+		}
+	}
 
 	/* test 18, IPv6 0+service */
-
 	memset(&hints, 0, sizeof(hints));
 	hints.ai_family = AF_INET6;
 	hints.ai_socktype = SOCK_STREAM;
@@ -760,19 +835,28 @@ void gaiv6(void)
 				 psin6 ? psin6->sin6_family : 0,
 				 psin6 ? psin6->sin6_port : 0,
 				 psin6 ? htons(psin6->sin6_port) : 0);
-		} else
-			tst_resm(TPASS, "getaddrinfo IPv6 0+service");
-		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN == EAI_BADFLAGS ? TPASS : TFAIL,
-			 "getaddrinfo IPv6 0+service (\"\", \"%s\") returns %ld "
-			 "(\"%s\")", service, TEST_RETURN,
-			 gai_strerror(TEST_RETURN));
+			freeaddrinfo(aires);
+			return;
+		} else {
+			tst_resm(TINFO, "getaddrinfo IPv6 0+service");
+			freeaddrinfo(aires);
+		}
+	} else {
+		if (TEST_RETURN == EAI_BADFLAGS) {
+			tst_resm(TINFO, "getaddrinfo IPv6 0+service"
+				" (\"\", \"%s\") returns %ld (\"%s\")", service,
+				TEST_RETURN, gai_strerror(TEST_RETURN));
+		} else {
+			tst_resm(TFAIL, "getaddrinfo IPv6 0+service"
+				" (\"\", \"%s\") returns %ld (\"%s\")", service,
+				TEST_RETURN, gai_strerror(TEST_RETURN));
+			return;
+		}
+	}
 
 	/* test 19, IPv6 host+service, AI_NUMERICSERV */
-
 #ifndef AI_NUMERICSERV
-	tst_resm(TFAIL, "getaddrinfo IPv6 host+service, AI_NUMERICSERV: flag "
+	tst_resm(TCONF, "getaddrinfo IPv6 host+service, AI_NUMERICSERV: flag "
 		 "not implemented");
 #else
 	memset(&hints, 0, sizeof(hints));
@@ -786,15 +870,17 @@ void gaiv6(void)
 			 "getaddrinfo IPv6 host+service, AI_NUMERICSERV: "
 			 "returns %ld (\"%s\") expected %d (EAI_NONAME)",
 			 TEST_RETURN, gai_strerror(TEST_RETURN), EAI_NONAME);
+		if (!TEST_RETURN)
+			freeaddrinfo(aires);
+		return;
 	} else
-		tst_resm(TPASS,
+		tst_resm(TINFO,
 			 "getaddrinfo IPv6 host+service, AI_NUMERICSERV");
 	if (!TEST_RETURN)
 		freeaddrinfo(aires);
 #endif /* AI_NUMERICSERV */
 
 	/* test 20, IPv6 SOCK_STREAM/IPPROTO_UDP hints */
-
 	memset(&hints, 0, sizeof(hints));
 	hints.ai_family = AF_INET6;
 	hints.ai_socktype = SOCK_STREAM;
@@ -806,12 +892,13 @@ void gaiv6(void)
 		tst_resm(TFAIL, "getaddrinfo IPv6 SOCK_STREAM/IPPROTO_UDP "
 			 "hints");
 		freeaddrinfo(aires);
-	} else
-		tst_resm(TPASS, "getaddrinfo IPv6 SOCK_STREAM/IPPROTO_UDP "
+		return;
+	} else {
+		tst_resm(TINFO, "getaddrinfo IPv6 SOCK_STREAM/IPPROTO_UDP "
 			 "hints");
+	}
 
 	/* test 21, IPv6 socktype 0, 513 */
-
 	memset(&hints, 0, sizeof(hints));
 	hints.ai_family = AF_INET6;
 	hints.ai_socktype = 0;
@@ -850,20 +937,31 @@ void gaiv6(void)
 				 psin6 ? psin6->sin6_family : 0,
 				 psin6 ? psin6->sin6_port : 0,
 				 psin6 ? htons(psin6->sin6_port) : 0);
-		} else if (got_tcp && got_udp)
-			tst_resm(TPASS, "getaddrinfo IPv6 socktype 0,513");
-		else
+			freeaddrinfo(aires);
+			return;
+		} else if (got_tcp && got_udp) {
+			tst_resm(TINFO, "getaddrinfo IPv6 socktype 0,513");
+			freeaddrinfo(aires);
+		} else {
 			tst_resm(TFAIL, "getaddrinfo IPv6 socktype 0,513 TCP %d"
 				 " UDP %d", got_tcp, got_udp);
-		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN == EAI_BADFLAGS ? TPASS : TFAIL,
-			 "getaddrinfo IPv6 socktype 0,513 (\"\", \"%s\") returns"
-			 " %ld (\"%s\")", service, TEST_RETURN,
-			 gai_strerror(TEST_RETURN));
+			freeaddrinfo(aires);
+			return;
+		}
+	} else {
+		if (TEST_RETURN == EAI_BADFLAGS) {
+			tst_resm(TINFO, "getaddrinfo IPv6 socktype 0,513"
+				" (\"\", \"%s\") returns %ld (\"%s\")", service,
+				TEST_RETURN, gai_strerror(TEST_RETURN));
+		} else {
+			tst_resm(TFAIL, "getaddrinfo IPv6 socktype 0,513"
+				" (\"\", \"%s\") returns %ld (\"%s\")", service,
+				TEST_RETURN, gai_strerror(TEST_RETURN));
+			return;
+		}
+	}
 
 	/* test 22, IPv6 AI_V4MAPPED */
-
 	memset(&hints, 0, sizeof(hints));
 	hints.ai_family = AF_INET6;
 	hints.ai_flags = AI_V4MAPPED;
@@ -892,57 +990,18 @@ void gaiv6(void)
 				 psin6 ? psin6->sin6_family : 0,
 				 psin6 ? psin6->sin6_port : 0,
 				 psin6 ? htons(psin6->sin6_port) : 0);
-		} else
-			tst_resm(TPASS, "getaddrinfo IPv6 AI_V4MAPPED");
-		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN ? TFAIL : TPASS, "getaddrinfo IPv6 "
+			freeaddrinfo(aires);
+			return;
+		} else {
+			tst_resm(TINFO, "getaddrinfo IPv6 AI_V4MAPPED");
+			freeaddrinfo(aires);
+		}
+	} else {
+		tst_resm(TFAIL, "getaddrinfo IPv6 "
 			 "AI_V4MAPPED (\"%s\") returns %ld (\"%s\")", hostname,
 			 TEST_RETURN, gai_strerror(TEST_RETURN));
-}
-
-/* this prints an addrinfo list; useful for debugging */
-void dumpres(struct addrinfo *pai)
-{
-	int count = 1;
-	for (; pai; pai = pai->ai_next, count++) {
-		printf("result %d [0x%p]\n", count, pai);
-		printf("\tai_flags %x\n", pai->ai_flags);
-		printf("\tai_family %d\n", pai->ai_family);
-		printf("\tai_socktype %d\n", pai->ai_socktype);
-		printf("\tai_protocol %d\n", pai->ai_protocol);
-		printf("\tai_addrlen %d\n", pai->ai_addrlen);
-		printf("\tai_canonname \"%s\"\n", pai->ai_canonname);
-		printf("\tai_addr.sa_family %x\n", pai->ai_addr->sa_family);
-		if (pai->ai_addr->sa_family == AF_INET) {
-			char buf[1024];
-			struct sockaddr_in *psin =
-			    (struct sockaddr_in *)pai->ai_addr;
-
-			if (!inet_ntop(AF_INET, &psin->sin_addr, buf,
-				       sizeof(buf)))
-				buf[0] = '\0';
-			printf("\tai_addr.sin_addr \"%s\"\n", buf);
-		} else if (pai->ai_addr->sa_family == AF_INET6) {
-			char buf[1024];
-
-			struct sockaddr_in6 *psin6 =
-			    (struct sockaddr_in6 *)pai->ai_addr;
-			if (!inet_ntop(AF_INET6, &psin6->sin6_addr, buf,
-				       sizeof(buf)))
-				buf[0] = '\0';
-			printf("\tai_addr.sin6_addr \"%s\"\n", buf);
-
-		}
-		printf("\tai_next %p\n", pai->ai_next);
+		return;
 	}
-}
 
-void setup(void)
-{
-	TEST_PAUSE;		/* if -P option specified */
-}
-
-void cleanup(void)
-{
+	tst_resm(TPASS, "getaddrinfo tests (v6) succeed");
 }
-- 
1.9.3


------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v5 11/11] ipv6_lib: Add it into default
  2015-07-16  5:30                         ` [LTP] [PATCH v5 " Zeng Linggang
                                             ` (8 preceding siblings ...)
  2015-07-16  5:30                           ` [LTP] [PATCH v5 10/11] lib6/getaddrinfo_01.c: Cleanup Zeng Linggang
@ 2015-07-16  5:30                           ` Zeng Linggang
  2015-08-05 14:00                           ` [LTP] [PATCH v5 01/11] SAFE_MACROS: Add socket(), bind(), listen(), connect() and getsockname() Cyril Hrubis
  10 siblings, 0 replies; 55+ messages in thread
From: Zeng Linggang @ 2015-07-16  5:30 UTC (permalink / raw)
  To: alexey.kodanev; +Cc: ltp-list

Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
 scenario_groups/default | 1 +
 1 file changed, 1 insertion(+)

diff --git a/scenario_groups/default b/scenario_groups/default
index 3a55702..60b1b27 100644
--- a/scenario_groups/default
+++ b/scenario_groups/default
@@ -32,3 +32,4 @@ dma_thread_diotest
 cpuacct
 can
 cpuhotplug
+ipv6_lib
-- 
1.9.3


------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 55+ messages in thread

* Re: [LTP] [PATCH v5 01/11] SAFE_MACROS: Add socket(), bind(), listen(), connect() and getsockname()
  2015-07-16  5:30                         ` [LTP] [PATCH v5 " Zeng Linggang
                                             ` (9 preceding siblings ...)
  2015-07-16  5:30                           ` [LTP] [PATCH v5 11/11] ipv6_lib: Add it into default Zeng Linggang
@ 2015-08-05 14:00                           ` Cyril Hrubis
       [not found]                             ` <55C236CB.8060508@oracle.com>
  10 siblings, 1 reply; 55+ messages in thread
From: Cyril Hrubis @ 2015-08-05 14:00 UTC (permalink / raw)
  To: Zeng Linggang; +Cc: ltp-list

Hi!
> +int safe_bind(const char *file, const int lineno, void (cleanup_fn)(void),
> +	      int socket, const struct sockaddr *address,
> +	      socklen_t address_len)
> +{
> +	int err, ret, i;
> +
> +	for (i = 0; i < 30; i++) {
> +		ret = bind(socket, address, address_len);
> +		err = errno;
> +
> +		if (!ret)
> +			return 0;
> +
> +		if (err != EADDRINUSE) {
> +			tst_brkm(TBROK | TERRNO, cleanup_fn,
> +				 "%s:%d: bind(%d, %p, %d) failed", file, lineno,
> +				 socket, address, address_len);

I think that it would be a bit nicer if we created a helper to translate
the socket structure to it's string representation (and use it whenever
we deal with struct sockaddr passed from user). We would have to switch
on sa_family and then print either ip address or path (for unix
sockets), etc. But that would get us bind(8, '127.0.0.1:1024', ...)
failed instead of the raw pointer to the structure which is kind of
useless.

> +		}
> +
> +		tst_resm(TINFO, "bind('%p') failed with %s, try %2i...",
> +			 address, tst_strerrno(err), i+1);

                         Hmm, why do we do tst_strerno(err) here when
			 the only value for errno can be EADDRINUSE
			 (since we exit with tst_brkm() otherwise)
			 Why not just hardcode EADDRINUSE to the
			 message?

> +		if (i == 0 && err == EADDRINUSE)
> +			tst_resm(TINFO, "The given address is already in use.");

                         This message is not really useful because we
			 allready printed that bind failed with
			 EADDRINUSE with the tst_resm above.

> +		usleep(1000000);

                We can use sleep(1) instead now.

> +	}
> +
> +	tst_brkm(TBROK | TERRNO, cleanup_fn,
> +		 "%s:%d: Failed to bind(%d, %p, %d) after 30 retries",
> +		 file, lineno, socket, address, address_len);
> +}
> +
> +int safe_listen(const char *file, const int lineno, void (cleanup_fn)(void),
> +		int socket, int backlog)
> +{
> +	int rval;
> +
> +	rval = listen(socket, backlog);
> +
> +	if (rval < 0) {
> +		tst_brkm(TBROK | TERRNO, cleanup_fn,
> +			 "%s:%d: listen(%d, %d) failed", file, lineno, socket,
> +			 backlog);
> +	}
> +
> +	return rval;
> +}
> +
> +int safe_connect(const char *file, const int lineno, void (cleanup_fn)(void),
> +		 int sockfd, const struct sockaddr *addr, socklen_t addrlen)
> +{
> +	int rval;
> +
> +	rval = connect(sockfd, addr, addrlen);
> +
> +	if (rval < 0) {
> +		tst_brkm(TBROK | TERRNO, cleanup_fn,
> +			 "%s:%d: connect(%d, %p, %d) failed", file, lineno,
> +			 sockfd, addr, addrlen);
> +	}
> +
> +	return rval;
> +}
> +
> +int safe_getsockname(const char *file, const int lineno,
> +		     void (cleanup_fn)(void), int sockfd, struct sockaddr *addr,
> +		     socklen_t *addrlen)
> +{
> +	int rval;
> +
> +	rval = getsockname(sockfd, addr, addrlen);
> +
> +	if (rval < 0) {
> +		tst_brkm(TBROK | TERRNO, cleanup_fn,
> +			 "%s:%d: getsockname(%d, %p, %p) failed", file, lineno,
> +			 sockfd, addr, addrlen);
> +	}
> +
> +	return rval;
> +}

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [LTP] [PATCH v5 02/11] lib6/runcc.c: Cleanup
  2015-07-16  5:30                           ` [LTP] [PATCH v5 02/11] lib6/runcc.c: Cleanup Zeng Linggang
@ 2015-08-05 17:17                             ` Cyril Hrubis
  2015-08-05 17:29                               ` Cyril Hrubis
  0 siblings, 1 reply; 55+ messages in thread
From: Cyril Hrubis @ 2015-08-05 17:17 UTC (permalink / raw)
  To: Zeng Linggang; +Cc: ltp-list

Hi!
First of all, I would like to ask everybody what they think about these
testcases (testcases/network/lib6/). Quite a bit of the functionality
there is validating that ipv6 devel headers and structures are present
and can be compiled. This looks more like conform test suitable for
glibc to me. Do we want to really keep these? Because they would need a
bit more work to make them less ugly...

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [LTP] [PATCH v5 02/11] lib6/runcc.c: Cleanup
  2015-08-05 17:17                             ` Cyril Hrubis
@ 2015-08-05 17:29                               ` Cyril Hrubis
       [not found]                                 ` <1441016132-18804-1-git-send-email-zenglg.jy@cn.fujitsu.com>
  0 siblings, 1 reply; 55+ messages in thread
From: Cyril Hrubis @ 2015-08-05 17:29 UTC (permalink / raw)
  To: Zeng Linggang; +Cc: ltp-list

Hi!
> First of all, I would like to ask everybody what they think about these
> testcases (testcases/network/lib6/). Quite a bit of the functionality
> there is validating that ipv6 devel headers and structures are present
> and can be compiled. This looks more like conform test suitable for
> glibc to me. Do we want to really keep these? Because they would need a
> bit more work to make them less ugly...

To be clear. I'm for dropping the ugly runcc.* interface and the
testcases that use it. That would be asapi_01.c, asapi_02.c, asapi_03,c,
half of asapi_05.c and asapi_07.c and fixing the rest of the testcases.

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [LTP] [PATCH v5 01/11] SAFE_MACROS: Add socket(), bind(), listen(), connect() and getsockname()
       [not found]                               ` <1438858276.11271.20.camel@G08FNSTD140232>
@ 2015-08-06 11:56                                 ` Cyril Hrubis
  0 siblings, 0 replies; 55+ messages in thread
From: Cyril Hrubis @ 2015-08-06 11:56 UTC (permalink / raw)
  To: Zeng Linggang; +Cc: ltp-list

Hi!
> > >> +int safe_bind(const char *file, const int lineno, void (cleanup_fn)(void),
> > >> +	      int socket, const struct sockaddr *address,
> > >> +	      socklen_t address_len)
> > >> +{
> > >> +	int err, ret, i;
> > >> +
> > >> +	for (i = 0; i < 30; i++) {
> > 30 sec still may not be enough, I would set it to 2 minutes.
> 
> To be honest, I am not sure how long we should wait.
> 2 minutes is OK for me.

That depends on how long can TCP connection stay in the TIME_WAIT state,
googling around suggests that it's 1 minute for Linux. So IMHO anything
greater than 1 minute should do. So 2 minutes looks like good choice to
me.

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v6 2/7] SAFE_MACROS: Add socket(), bind(), listen(), connect() and getsockname()
       [not found]                                   ` <1441016132-18804-2-git-send-email-zenglg.jy@cn.fujitsu.com>
@ 2015-09-14  9:56                                     ` Alexey Kodanev
  0 siblings, 0 replies; 55+ messages in thread
From: Alexey Kodanev @ 2015-09-14  9:56 UTC (permalink / raw)
  To: ltp

Hi,
On 08/31/2015 01:15 PM, Zeng Linggang wrote:
> Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
> Signed-off-by: Alexey Kodanev <alexey.kodanev@oracle.com>
> Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
> ---
>   include/safe_macros.h |   1 +
>   include/safe_net.h    |  59 +++++++++++++++++++++++++
>   lib/safe_net.c        | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++
>   3 files changed, 177 insertions(+)
>   create mode 100644 include/safe_net.h
>   create mode 100644 lib/safe_net.c
>
...
> +
> +#define	GET_ADDR(sock_addr) \
> +	(inet_ntoa(((struct sockaddr_in *)sock_addr)->sin_addr))
> +

It won't work with IPv6. inet_ntoa is considered as deprecated, please 
use inet_ntop() instead. Also the name of the macro should be with the 
prefix TST_ or LTP_. I would use LTP_SOCK_ADDR or similar. In case of 
different ai_family, defining it as a function is more appropriate.

...
> +
> +int safe_bind(const char *file, const int lineno, void (cleanup_fn)(void),
> +	      int socket, const struct sockaddr *address,
> +	      socklen_t address_len)
> +{
> +	int i;
> +
> +	for (i = 0; i < 120; i++) {
> +		if (!bind(socket, address, address_len)) {
> +			tst_resm(TINFO, "bind is OK now");
> +			return 0;
> +		}
> +
> +		if (errno != EADDRINUSE) {
> +			tst_brkm(TBROK | TERRNO, cleanup_fn,
> +				 "%s:%d: bind(%d, %s, %d) failed", file, lineno,
> +				 socket, GET_ADDR(address), address_len);

In bind(), the port address is more important.

> +		}
> +
> +		if ((i + 1) % 10 == 1) {
> +			tst_resm(TINFO, "address is in use, waited %3i sec",
> +				 i + 1);
> +		}

"if" block should go after sleep. Also why "==1"? May be "== 0" instead. 
Otherwise you will print it after 1s, 11s, 21s, ... etc.

> +
> +		sleep(1);
> +	}
> +
> +	tst_brkm(TBROK | TERRNO, cleanup_fn,
> +		 "%s:%d: Failed to bind(%d, %p, %d) after 30 retries", file,
> +		 lineno, socket, GET_ADDR(address), address_len);

Please correct the message. I would remove "after 30 retries".

Thanks,
Alexey

^ permalink raw reply	[flat|nested] 55+ messages in thread

end of thread, other threads:[~2015-09-14  9:56 UTC | newest]

Thread overview: 55+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-31  7:46 [LTP] [PATCH 1/6] lib6/runcc.c: use TCONF instead of TBROK when no C compiler is present Xing Gu
2015-03-31  7:46 ` [LTP] [PATCH 2/6] lib6/asapi_04.c: cleanup Xing Gu
2015-04-30 11:55   ` Cyril Hrubis
2015-04-30 12:18   ` Cyril Hrubis
2015-03-31  7:46 ` [LTP] [PATCH 3/6] lib6/asapi_05.c: cleanup Xing Gu
2015-04-30 12:15   ` Cyril Hrubis
2015-03-31  7:46 ` [LTP] [PATCH 4/6] lib6/asapi_06.c: cleanup Xing Gu
2015-04-30 13:33   ` Cyril Hrubis
2015-03-31  7:46 ` [LTP] [PATCH 5/6] lib6/getaddrinfo_01.c: cleanup Xing Gu
2015-03-31  7:46 ` [LTP] [PATCH 6/6] ipv6_lib: add it into default Xing Gu
2015-03-31 14:52 ` [LTP] [PATCH 1/6] lib6/runcc.c: use TCONF instead of TBROK when no C compiler is present Alexey Kodanev
2015-04-01  1:38   ` gux.fnst
2015-04-01  7:15     ` Alexey Kodanev
2015-04-14  9:24       ` gux.fnst
2015-04-28 17:24         ` Cyril Hrubis
     [not found]           ` <1433247689-3984-1-git-send-email-zenglg.jy@cn.fujitsu.com>
     [not found]             ` <1433247689-3984-2-git-send-email-zenglg.jy@cn.fujitsu.com>
2015-06-06 12:52               ` [LTP] [PATCH v2 1/6] lib6/runcc.c: Cleanup Alexey Kodanev
2015-06-16 12:24                 ` [LTP] [PATCH v3 1/7] SAFE_MACROS: Add socket(), bind(), listen(), connect() and getsockname() Zeng Linggang
2015-06-16 12:24                   ` [LTP] [PATCH v3 2/7] lib6/runcc.c: Cleanup Zeng Linggang
2015-06-19 16:08                     ` Alexey Kodanev
2015-06-16 12:24                   ` [LTP] [PATCH v3 3/7] lib6/asapi_04.c: Cleanup Zeng Linggang
2015-06-16 12:24                   ` [LTP] [PATCH v3 4/7] lib6/asapi_05.c: Cleanup Zeng Linggang
2015-06-16 12:24                   ` [LTP] [PATCH v3 5/7] lib6/asapi_06.c: Cleanup Zeng Linggang
2015-06-16 12:24                   ` [LTP] [PATCH v3 6/7] lib6/getaddrinfo_01.c: Cleanup Zeng Linggang
2015-06-16 12:24                   ` [LTP] [PATCH v3 7/7] ipv6_lib: Add it into default Zeng Linggang
2015-06-19 14:34                   ` [LTP] [PATCH v3 1/7] SAFE_MACROS: Add socket(), bind(), listen(), connect() and getsockname() Alexey Kodanev
2015-07-09  3:05                     ` [LTP] [PATCH v4 01/11] " Zeng Linggang
2015-07-09  3:05                       ` [LTP] [PATCH v4 02/11] lib6/runcc.c: Cleanup Zeng Linggang
2015-07-09  3:05                       ` [LTP] [PATCH v4 03/11] asapi_01: Use 'tst_tmpdir' and more cleanup Zeng Linggang
2015-07-09  3:05                       ` [LTP] [PATCH v4 04/11] asapi_02: " Zeng Linggang
2015-07-09  3:05                       ` [LTP] [PATCH v4 05/11] asapi_03: " Zeng Linggang
2015-07-09  3:05                       ` [LTP] [PATCH v4 06/11] lib6/asapi_04.c: Cleanup Zeng Linggang
2015-07-09  3:05                       ` [LTP] [PATCH v4 07/11] lib6/asapi_05.c: Cleanup Zeng Linggang
2015-07-09  3:05                       ` [LTP] [PATCH v4 08/11] lib6/asapi_06.c: Cleanup Zeng Linggang
2015-07-09  3:05                       ` [LTP] [PATCH v4 09/11] asapi_07: Use 'tst_tmpdir' and more cleanup Zeng Linggang
2015-07-09  3:05                       ` [LTP] [PATCH v4 10/11] lib6/getaddrinfo_01.c: Cleanup Zeng Linggang
2015-07-09  3:05                       ` [LTP] [PATCH v4 11/11] ipv6_lib: Add it into default Zeng Linggang
2015-07-15 15:49                       ` [LTP] [PATCH v4 01/11] SAFE_MACROS: Add socket(), bind(), listen(), connect() and getsockname() Alexey Kodanev
2015-07-16  2:30                         ` Zeng Linggang
2015-07-16  5:30                         ` [LTP] [PATCH v5 " Zeng Linggang
2015-07-16  5:30                           ` [LTP] [PATCH v5 02/11] lib6/runcc.c: Cleanup Zeng Linggang
2015-08-05 17:17                             ` Cyril Hrubis
2015-08-05 17:29                               ` Cyril Hrubis
     [not found]                                 ` <1441016132-18804-1-git-send-email-zenglg.jy@cn.fujitsu.com>
     [not found]                                   ` <1441016132-18804-2-git-send-email-zenglg.jy@cn.fujitsu.com>
2015-09-14  9:56                                     ` [LTP] [PATCH v6 2/7] SAFE_MACROS: Add socket(), bind(), listen(), connect() and getsockname() Alexey Kodanev
2015-07-16  5:30                           ` [LTP] [PATCH v5 03/11] asapi_01: Use 'tst_tmpdir' and more cleanup Zeng Linggang
2015-07-16  5:30                           ` [LTP] [PATCH v5 04/11] asapi_02: " Zeng Linggang
2015-07-16  5:30                           ` [LTP] [PATCH v5 05/11] asapi_03: " Zeng Linggang
2015-07-16  5:30                           ` [LTP] [PATCH v5 06/11] lib6/asapi_04.c: Cleanup Zeng Linggang
2015-07-16  5:30                           ` [LTP] [PATCH v5 07/11] lib6/asapi_05.c: Cleanup Zeng Linggang
2015-07-16  5:30                           ` [LTP] [PATCH v5 08/11] lib6/asapi_06.c: Cleanup Zeng Linggang
2015-07-16  5:30                           ` [LTP] [PATCH v5 09/11] asapi_07: Use 'tst_tmpdir' and more cleanup Zeng Linggang
2015-07-16  5:30                           ` [LTP] [PATCH v5 10/11] lib6/getaddrinfo_01.c: Cleanup Zeng Linggang
2015-07-16  5:30                           ` [LTP] [PATCH v5 11/11] ipv6_lib: Add it into default Zeng Linggang
2015-08-05 14:00                           ` [LTP] [PATCH v5 01/11] SAFE_MACROS: Add socket(), bind(), listen(), connect() and getsockname() Cyril Hrubis
     [not found]                             ` <55C236CB.8060508@oracle.com>
     [not found]                               ` <1438858276.11271.20.camel@G08FNSTD140232>
2015-08-06 11:56                                 ` Cyril Hrubis
     [not found]             ` <1433247689-3984-3-git-send-email-zenglg.jy@cn.fujitsu.com>
2015-06-06 13:22               ` [LTP] [PATCH v2 2/6] lib6/asapi_04.c: Cleanup Alexey Kodanev

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.