lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1365503461-26309-3-git-send-email-alex.mihai.c@gmail.com>
Date:	Tue,  9 Apr 2013 13:31:00 +0300
From:	Alexandru Copot <alex.mihai.c@...il.com>
To:	netdev@...r.kernel.org, davem@...emloft.net
Cc:	willemb@...gle.com, dborkman@...hat.com, edumazet@...gle.com,
	Alexandru Copot <alex.mihai.c@...il.com>,
	Daniel Baluta <dbaluta@...acom.com>
Subject: [PATCH 2/3 net-next RFC] selftest: Adapt socket test to new testing framework

Signed-of by Alexandru Copot <alex.mihai.c@...il.com>
Cc: Daniel Baluta <dbaluta@...acom.com>
---
 tools/testing/selftests/net/Makefile |   4 +-
 tools/testing/selftests/net/socket.c | 107 +++++++++++++++++++++++++----------
 2 files changed, 80 insertions(+), 31 deletions(-)

diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile
index 750512b..9de4ae6 100644
--- a/tools/testing/selftests/net/Makefile
+++ b/tools/testing/selftests/net/Makefile
@@ -11,9 +11,11 @@ all: $(NET_PROGS)
 %: %.c
 	$(CC) $(CFLAGS) -o $@ $^
 
+socket: selftests.o
+
 run_tests: all
 	@/bin/sh ./run_netsocktests || echo "sockettests: [FAIL]"
 	@/bin/sh ./run_afpackettests || echo "afpackettests: [FAIL]"
 
 clean:
-	$(RM) $(NET_PROGS)
+	$(RM) $(NET_PROGS) *.o
diff --git a/tools/testing/selftests/net/socket.c b/tools/testing/selftests/net/socket.c
index 0f227f2..89b1b1e 100644
--- a/tools/testing/selftests/net/socket.c
+++ b/tools/testing/selftests/net/socket.c
@@ -6,6 +6,8 @@
 #include <sys/socket.h>
 #include <netinet/in.h>
 
+#include "selftests.h"
+
 struct socket_testcase {
 	int	domain;
 	int	type;
@@ -22,7 +24,7 @@ struct socket_testcase {
 	int	nosupport_ok;
 };
 
-static struct socket_testcase tests[] = {
+static struct socket_testcase tests_inet[] = {
 	{ AF_MAX,  0,           0,           -EAFNOSUPPORT,    0 },
 	{ AF_INET, SOCK_STREAM, IPPROTO_TCP, 0,                1  },
 	{ AF_INET, SOCK_DGRAM,  IPPROTO_TCP, -EPROTONOSUPPORT, 1  },
@@ -30,58 +32,103 @@ static struct socket_testcase tests[] = {
 	{ AF_INET, SOCK_STREAM, IPPROTO_UDP, -EPROTONOSUPPORT, 1  },
 };
 
+static struct socket_testcase tests_inet6[] = {
+	{ AF_INET6, SOCK_STREAM, IPPROTO_TCP, 0,                1  },
+	{ AF_INET6, SOCK_DGRAM,  IPPROTO_TCP, -EPROTONOSUPPORT, 1  },
+	{ AF_INET6, SOCK_DGRAM,  IPPROTO_UDP, 0,                1  },
+	{ AF_INET6, SOCK_STREAM, IPPROTO_UDP, -EPROTONOSUPPORT, 1  },
+};
+
+static struct socket_testcase tests_unix[] = {
+	{ AF_UNIX, SOCK_STREAM,    0,           0,                1  },
+	{ AF_UNIX, SOCK_DGRAM,     0,           0,                1  },
+	{ AF_UNIX, SOCK_SEQPACKET, 0,           0,                1  },
+	{ AF_UNIX, SOCK_STREAM,    PF_UNIX,     0,                1  },
+	{ AF_UNIX, SOCK_DGRAM,     PF_UNIX,     0,                1  },
+	{ AF_UNIX, SOCK_SEQPACKET, PF_UNIX,     0,                1  },
+	{ AF_UNIX, SOCK_STREAM,    IPPROTO_TCP, -EPROTONOSUPPORT, 1  },
+	{ AF_UNIX, SOCK_STREAM,    IPPROTO_UDP, -EPROTONOSUPPORT, 1  },
+	{ AF_UNIX, SOCK_DCCP,      0,           -ESOCKTNOSUPPORT, 1  },
+};
+
 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
 #define ERR_STRING_SZ	64
 
-static int run_tests(void)
+static int my_run_testcase(void *arg)
 {
+	struct socket_testcase *s = (struct socket_testcase*)arg;
+	int fd;
 	char err_string1[ERR_STRING_SZ];
 	char err_string2[ERR_STRING_SZ];
-	int i, err;
-
-	err = 0;
-	for (i = 0; i < ARRAY_SIZE(tests); i++) {
-		struct socket_testcase *s = &tests[i];
-		int fd;
 
-		fd = socket(s->domain, s->type, s->protocol);
-		if (fd < 0) {
-			if (s->nosupport_ok &&
-			    errno == EAFNOSUPPORT)
-				continue;
+	fd = socket(s->domain, s->type, s->protocol);
+	if (fd < 0) {
+		if (s->nosupport_ok && errno == EAFNOSUPPORT)
+			return 0;
 
-			if (s->expect < 0 &&
-			    errno == -s->expect)
-				continue;
+		if (s->expect < 0 && errno == -s->expect)
+			return 0;
 
-			strerror_r(-s->expect, err_string1, ERR_STRING_SZ);
-			strerror_r(errno, err_string2, ERR_STRING_SZ);
+		strerror_r(-s->expect, err_string1, ERR_STRING_SZ);
+		strerror_r(errno, err_string2, ERR_STRING_SZ);
 
-			fprintf(stderr, "socket(%d, %d, %d) expected "
+		fprintf(stderr, "socket(%d, %d, %d) expected "
 				"err (%s) got (%s)\n",
 				s->domain, s->type, s->protocol,
 				err_string1, err_string2);
 
-			err = -1;
-			break;
-		} else {
-			close(fd);
+		return -1;
+	} else {
+		close(fd);
 
-			if (s->expect < 0) {
-				strerror_r(errno, err_string1, ERR_STRING_SZ);
+		if (s->expect < 0) {
+			strerror_r(errno, err_string1, ERR_STRING_SZ);
 
-				fprintf(stderr, "socket(%d, %d, %d) expected "
+			fprintf(stderr, "socket(%d, %d, %d) expected "
 					"success got err (%s)\n",
 					s->domain, s->type, s->protocol,
 					err_string1);
 
-				err = -1;
-				break;
-			}
+			return -1;
 		}
 	}
+	return 0;
+}
 
-	return err;
+static int run_tests(void)
+{
+	int rc;
+	struct generic_test test1 = {
+		.name = "socket AF_INET",
+		.prepare = NULL,
+		.run = my_run_testcase,
+		.testcases = tests_inet,
+		.testcase_size = sizeof(struct socket_testcase),
+		.testcase_count = ARRAY_SIZE(tests_inet),
+	};
+	struct generic_test test2 = {
+		.name = "socket AF_INET6",
+		.prepare = NULL,
+		.run = my_run_testcase,
+		.testcases = tests_inet6,
+		.testcase_size = sizeof(struct socket_testcase),
+		.testcase_count = ARRAY_SIZE(tests_inet6),
+	};
+	struct generic_test test3 = {
+		.name = "socket AF_UNIX",
+		.prepare = NULL,
+		.run = my_run_testcase,
+		.testcases = tests_unix,
+		.testcase_size = sizeof(struct socket_testcase),
+		.testcase_count = ARRAY_SIZE(tests_unix),
+	};
+
+	rc = 0;
+	rc |= run_all_tests(&test1, NULL);
+	rc |= run_all_tests(&test2, NULL);
+	rc |= run_all_tests(&test3, NULL);
+
+	return rc;
 }
 
 int main(void)
-- 
1.8.2

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ