* [PATCH 0/3 net-next RFC] selftest: Introduce test abstraction for net
@ 2013-04-09 10:30 Alexandru Copot
2013-04-09 10:30 ` [PATCH 1/3 net-next RFC] selftest: add abstractions for net selftests Alexandru Copot
` (3 more replies)
0 siblings, 4 replies; 10+ messages in thread
From: Alexandru Copot @ 2013-04-09 10:30 UTC (permalink / raw)
To: netdev, davem; +Cc: willemb, dborkman, edumazet, Alexandru Copot, Daniel Baluta
This series adds a generic test abstraction that can make
writing testcases easier. A generic_test structure is
used to define a test and its methods.
The second patch updates the socket tests to use the
new framework, and the third patch creates new tests
for [set/get]sockopt with some IPV6_* options.
Signed-of by Alexandru Copot <alex.mihai.c@gmail.com>
Cc: Daniel Baluta <dbaluta@ixiacom.com>
Alexandru Copot (3):
selftest: add abstractions for net selftests
selftest: update socket tests to use the testing abstractions
selftests: add socket options test with IPv6 testcases
tools/testing/selftests/net/Makefile | 7 +-
tools/testing/selftests/net/run_netsocktests | 10 ++
tools/testing/selftests/net/selftests.c | 25 ++++
tools/testing/selftests/net/selftests.h | 42 +++++++
tools/testing/selftests/net/socket.c | 107 +++++++++++-----
tools/testing/selftests/net/sockopt.c | 179 +++++++++++++++++++++++++++
6 files changed, 338 insertions(+), 32 deletions(-)
create mode 100644 tools/testing/selftests/net/selftests.c
create mode 100644 tools/testing/selftests/net/selftests.h
create mode 100644 tools/testing/selftests/net/sockopt.c
--
1.8.2
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 1/3 net-next RFC] selftest: add abstractions for net selftests
2013-04-09 10:30 [PATCH 0/3 net-next RFC] selftest: Introduce test abstraction for net Alexandru Copot
@ 2013-04-09 10:30 ` Alexandru Copot
2013-04-09 11:13 ` Daniel Borkmann
2013-04-09 13:39 ` Sergei Shtylyov
2013-04-09 10:31 ` [PATCH 2/3 net-next RFC] selftest: Adapt socket test to new testing framework Alexandru Copot
` (2 subsequent siblings)
3 siblings, 2 replies; 10+ messages in thread
From: Alexandru Copot @ 2013-04-09 10:30 UTC (permalink / raw)
To: netdev, davem; +Cc: willemb, dborkman, edumazet, Alexandru Copot, Daniel Baluta
Signed-of by Alexandru Copot <alex.mihai.c@gmail.com>
Cc: Daniel Baluta <dbaluta@ixiacom.com>
---
tools/testing/selftests/net/selftests.c | 30 +++++++++++++++++++++++
tools/testing/selftests/net/selftests.h | 42 +++++++++++++++++++++++++++++++++
2 files changed, 72 insertions(+)
create mode 100644 tools/testing/selftests/net/selftests.c
create mode 100644 tools/testing/selftests/net/selftests.h
diff --git a/tools/testing/selftests/net/selftests.c b/tools/testing/selftests/net/selftests.c
new file mode 100644
index 0000000..cd6e427
--- /dev/null
+++ b/tools/testing/selftests/net/selftests.c
@@ -0,0 +1,30 @@
+#include <stdio.h>
+
+#include "selftests.h"
+
+int run_all_tests(struct generic_test *test, void *param)
+{
+ int i;
+ int rc, allrc;
+ char *ptr;
+
+ rc = test->prepare ? test->prepare(param) : 0;
+ if (rc)
+ return rc;
+
+ allrc = 0;
+ printf("Testing: %s ", test->name);
+ ptr = test->testcases;
+ for (i = 0; i < test->testcase_count; i++) {
+ rc = test->run(ptr);
+ allrc |= rc;
+
+ if (test->abort_on_fail && rc) {
+ printf("Testcase %d failed, aborting\n", i);
+ }
+
+ ptr += test->testcase_size;
+ }
+ printf("\t\t%s\n", allrc ? "[FAIL]" : "[PASS]");
+ return allrc;
+}
diff --git a/tools/testing/selftests/net/selftests.h b/tools/testing/selftests/net/selftests.h
new file mode 100644
index 0000000..e289f03
--- /dev/null
+++ b/tools/testing/selftests/net/selftests.h
@@ -0,0 +1,42 @@
+#ifndef SELFTESTS_H
+#define SELFTESTS_H
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+
+#define ASSERT(cond) do { \
+ if (!(cond)) { \
+ fprintf(stderr, "%s:%d %s\n", __FILE__, __LINE__, #cond); \
+ perror(""); \
+ exit(EXIT_FAILURE); \
+ } \
+} while (0)
+
+#define CHECK(cond,fmt,...) \
+ do { \
+ if (!(cond)) { \
+ fprintf(stderr, "(%s, %d): " fmt, \
+ __FILE__, __LINE__, ##__VA_ARGS__); \
+ perror(""); \
+ return 1; \
+ } \
+ } while (0)
+
+struct generic_test {
+ const char *name;
+ void *testcases;
+ int testcase_size;
+ int testcase_count;
+
+ int abort_on_fail;
+
+ int (*prepare)(void *);
+ int (*run)(void *);
+ int (*cleanup)(void *);
+};
+
+int run_all_tests(struct generic_test *test, void *param);
+
+#endif
+
--
1.8.2
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 2/3 net-next RFC] selftest: Adapt socket test to new testing framework
2013-04-09 10:30 [PATCH 0/3 net-next RFC] selftest: Introduce test abstraction for net Alexandru Copot
2013-04-09 10:30 ` [PATCH 1/3 net-next RFC] selftest: add abstractions for net selftests Alexandru Copot
@ 2013-04-09 10:31 ` Alexandru Copot
2013-04-09 10:31 ` [PATCH net-next RFC] selftests: add socket options test with IPv6 testcases Alexandru Copot
2013-04-09 11:22 ` [PATCH 0/3 net-next RFC] selftest: Introduce test abstraction for net Daniel Borkmann
3 siblings, 0 replies; 10+ messages in thread
From: Alexandru Copot @ 2013-04-09 10:31 UTC (permalink / raw)
To: netdev, davem; +Cc: willemb, dborkman, edumazet, Alexandru Copot, Daniel Baluta
Signed-of by Alexandru Copot <alex.mihai.c@gmail.com>
Cc: Daniel Baluta <dbaluta@ixiacom.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
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH net-next RFC] selftests: add socket options test with IPv6 testcases
2013-04-09 10:30 [PATCH 0/3 net-next RFC] selftest: Introduce test abstraction for net Alexandru Copot
2013-04-09 10:30 ` [PATCH 1/3 net-next RFC] selftest: add abstractions for net selftests Alexandru Copot
2013-04-09 10:31 ` [PATCH 2/3 net-next RFC] selftest: Adapt socket test to new testing framework Alexandru Copot
@ 2013-04-09 10:31 ` Alexandru Copot
2013-04-09 11:22 ` [PATCH 0/3 net-next RFC] selftest: Introduce test abstraction for net Daniel Borkmann
3 siblings, 0 replies; 10+ messages in thread
From: Alexandru Copot @ 2013-04-09 10:31 UTC (permalink / raw)
To: netdev, davem; +Cc: willemb, dborkman, edumazet, Alexandru Copot, Daniel Baluta
Only a part of the boolean socket options for IPv6 are tested.
Signed-of by Alexandru Copot <alex.mihai.c@gmail.com>
Cc: Daniel Baluta <dbaluta@ixiacom.com>
---
tools/testing/selftests/net/Makefile | 3 +-
tools/testing/selftests/net/run_netsocktests | 10 ++
tools/testing/selftests/net/sockopt.c | 189 +++++++++++++++++++++++++++
3 files changed, 201 insertions(+), 1 deletion(-)
create mode 100644 tools/testing/selftests/net/sockopt.c
diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile
index 9de4ae6..da0e954 100644
--- a/tools/testing/selftests/net/Makefile
+++ b/tools/testing/selftests/net/Makefile
@@ -5,13 +5,14 @@ CFLAGS = -Wall -O2 -g
CFLAGS += -I../../../../usr/include/
-NET_PROGS = socket psock_fanout psock_tpacket
+NET_PROGS = socket sockopt psock_fanout psock_tpacket
all: $(NET_PROGS)
%: %.c
$(CC) $(CFLAGS) -o $@ $^
socket: selftests.o
+sockopt: selftests.o
run_tests: all
@/bin/sh ./run_netsocktests || echo "sockettests: [FAIL]"
diff --git a/tools/testing/selftests/net/run_netsocktests b/tools/testing/selftests/net/run_netsocktests
index c09a682..7aa4b01 100644
--- a/tools/testing/selftests/net/run_netsocktests
+++ b/tools/testing/selftests/net/run_netsocktests
@@ -10,3 +10,13 @@ else
echo "[PASS]"
fi
+echo "---------------------------"
+echo "running socket options test"
+echo "---------------------------"
+./sockopt
+if [ $? -ne 0 ]; then
+ echo "[FAIL]"
+else
+ echo "[PASS]"
+fi
+
diff --git a/tools/testing/selftests/net/sockopt.c b/tools/testing/selftests/net/sockopt.c
new file mode 100644
index 0000000..4c130e3
--- /dev/null
+++ b/tools/testing/selftests/net/sockopt.c
@@ -0,0 +1,189 @@
+#include <stdio.h>
+#include <errno.h>
+#include <unistd.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <linux/in.h>
+#include <linux/ipv6.h>
+
+#include "selftests.h"
+
+struct sockopt_testcase {
+ /* socket */
+ int domain;
+ int type;
+ int protocol;
+
+ /* option */
+ int level;
+ int optname;
+ void *value;
+ socklen_t size;
+
+ #define TYPE_INT 1
+ #define TYPE_DATA 2
+ int data_type;
+
+ int expect_set;
+ int expect_get;
+
+ int nosupport_ok;
+};
+
+
+static struct sockopt_testcase tests_inet6[] = {
+ { AF_INET6, SOCK_STREAM, IPPROTO_TCP, IPPROTO_IPV6, -1, (void*)0, sizeof(int), TYPE_INT, -ENOPROTOOPT, -ENOPROTOOPT, 0},
+
+ { AF_INET6, SOCK_STREAM, IPPROTO_TCP, IPPROTO_IPV6, IPV6_V6ONLY, (void*)1, sizeof(int), TYPE_INT, 0, 0, 0},
+ { AF_INET6, SOCK_STREAM, IPPROTO_TCP, IPPROTO_IPV6, IPV6_V6ONLY, (void*)0, sizeof(int), TYPE_INT, 0, 0, 0},
+
+ { AF_INET6, SOCK_STREAM, IPPROTO_TCP, IPPROTO_IPV6, IPV6_RECVPKTINFO, (void*)1, sizeof(int), TYPE_INT, 0, 0, 0},
+ { AF_INET6, SOCK_STREAM, IPPROTO_TCP, IPPROTO_IPV6, IPV6_RECVPKTINFO, (void*)0, sizeof(int), TYPE_INT, 0, 0, 0},
+
+ { AF_INET6, SOCK_STREAM, IPPROTO_TCP, IPPROTO_IPV6, IPV6_2292PKTINFO, (void*)1, sizeof(int), TYPE_INT, 0, 0, 0},
+ { AF_INET6, SOCK_STREAM, IPPROTO_TCP, IPPROTO_IPV6, IPV6_2292PKTINFO, (void*)0, sizeof(int), TYPE_INT, 0, 0, 0},
+
+ { AF_INET6, SOCK_STREAM, IPPROTO_TCP, IPPROTO_IPV6, IPV6_RECVHOPLIMIT, (void*)1, sizeof(int), TYPE_INT, 0, 0, 0},
+ { AF_INET6, SOCK_STREAM, IPPROTO_TCP, IPPROTO_IPV6, IPV6_RECVHOPLIMIT, (void*)0, sizeof(int), TYPE_INT, 0, 0, 0},
+
+ { AF_INET6, SOCK_STREAM, IPPROTO_TCP, IPPROTO_IPV6, IPV6_2292HOPLIMIT, (void*)1, sizeof(int), TYPE_INT, 0, 0, 0},
+ { AF_INET6, SOCK_STREAM, IPPROTO_TCP, IPPROTO_IPV6, IPV6_2292HOPLIMIT, (void*)0, sizeof(int), TYPE_INT, 0, 0, 0},
+
+ { AF_INET6, SOCK_STREAM, IPPROTO_TCP, IPPROTO_IPV6, IPV6_RECVRTHDR, (void*)1, sizeof(int), TYPE_INT, 0, 0, 0},
+ { AF_INET6, SOCK_STREAM, IPPROTO_TCP, IPPROTO_IPV6, IPV6_RECVRTHDR, (void*)0, sizeof(int), TYPE_INT, 0, 0, 0},
+
+ { AF_INET6, SOCK_STREAM, IPPROTO_TCP, IPPROTO_IPV6, IPV6_2292RTHDR, (void*)1, sizeof(int), TYPE_INT, 0, 0, 0},
+ { AF_INET6, SOCK_STREAM, IPPROTO_TCP, IPPROTO_IPV6, IPV6_2292RTHDR, (void*)0, sizeof(int), TYPE_INT, 0, 0, 0},
+
+ { AF_INET6, SOCK_STREAM, IPPROTO_TCP, IPPROTO_IPV6, IPV6_RECVHOPOPTS, (void*)1, sizeof(int), TYPE_INT, 0, 0, 0},
+ { AF_INET6, SOCK_STREAM, IPPROTO_TCP, IPPROTO_IPV6, IPV6_RECVHOPOPTS, (void*)0, sizeof(int), TYPE_INT, 0, 0, 0},
+
+ { AF_INET6, SOCK_STREAM, IPPROTO_TCP, IPPROTO_IPV6, IPV6_2292HOPOPTS, (void*)1, sizeof(int), TYPE_INT, 0, 0, 0},
+ { AF_INET6, SOCK_STREAM, IPPROTO_TCP, IPPROTO_IPV6, IPV6_2292HOPOPTS, (void*)0, sizeof(int), TYPE_INT, 0, 0, 0},
+
+ { AF_INET6, SOCK_STREAM, IPPROTO_TCP, IPPROTO_IPV6, IPV6_RECVDSTOPTS, (void*)1, sizeof(int), TYPE_INT, 0, 0, 0},
+ { AF_INET6, SOCK_STREAM, IPPROTO_TCP, IPPROTO_IPV6, IPV6_RECVDSTOPTS, (void*)0, sizeof(int), TYPE_INT, 0, 0, 0},
+
+ { AF_INET6, SOCK_STREAM, IPPROTO_TCP, IPPROTO_IPV6, IPV6_2292DSTOPTS, (void*)1, sizeof(int), TYPE_INT, 0, 0, 0},
+ { AF_INET6, SOCK_STREAM, IPPROTO_TCP, IPPROTO_IPV6, IPV6_2292DSTOPTS, (void*)0, sizeof(int), TYPE_INT, 0, 0, 0},
+
+ { AF_INET6, SOCK_STREAM, IPPROTO_TCP, IPPROTO_IPV6, IPV6_TCLASS, (void*)1, sizeof(int), TYPE_INT, 0, 0, 0},
+ { AF_INET6, SOCK_STREAM, IPPROTO_TCP, IPPROTO_IPV6, IPV6_TCLASS, (void*)0, sizeof(int), TYPE_INT, 0, 0, 0},
+
+ { AF_INET6, SOCK_STREAM, IPPROTO_TCP, IPPROTO_IPV6, IPV6_RECVTCLASS, (void*)1, sizeof(int), TYPE_INT, 0, 0, 0},
+ { AF_INET6, SOCK_STREAM, IPPROTO_TCP, IPPROTO_IPV6, IPV6_RECVTCLASS, (void*)0, sizeof(int), TYPE_INT, 0, 0, 0},
+
+ { AF_INET6, SOCK_STREAM, IPPROTO_TCP, IPPROTO_IPV6, IPV6_FLOWINFO, (void*)1, sizeof(int), TYPE_INT, 0, 0, 0},
+ { AF_INET6, SOCK_STREAM, IPPROTO_TCP, IPPROTO_IPV6, IPV6_FLOWINFO, (void*)0, sizeof(int), TYPE_INT, 0, 0, 0},
+
+ { AF_INET6, SOCK_STREAM, IPPROTO_TCP, IPPROTO_IPV6, IPV6_RECVPATHMTU, (void*)1, sizeof(int), TYPE_INT, 0, 0, 0},
+ { AF_INET6, SOCK_STREAM, IPPROTO_TCP, IPPROTO_IPV6, IPV6_RECVPATHMTU, (void*)0, sizeof(int), TYPE_INT, 0, 0, 0},
+
+ { AF_INET6, SOCK_STREAM, IPPROTO_TCP, IPPROTO_IPV6, IPV6_RECVORIGDSTADDR, (void*)1, sizeof(int), TYPE_INT, 0, 0, 0},
+ { AF_INET6, SOCK_STREAM, IPPROTO_TCP, IPPROTO_IPV6, IPV6_RECVORIGDSTADDR, (void*)0, sizeof(int), TYPE_INT, 0, 0, 0},
+
+ { AF_INET6, SOCK_STREAM, IPPROTO_TCP, IPPROTO_IPV6, IPV6_DONTFRAG, (void*)1, sizeof(int), TYPE_INT, 0, 0, 0},
+ { AF_INET6, SOCK_STREAM, IPPROTO_TCP, IPPROTO_IPV6, IPV6_DONTFRAG, (void*)0, sizeof(int), TYPE_INT, 0, 0, 0},
+
+ { AF_INET6, SOCK_STREAM, IPPROTO_TCP, IPPROTO_IPV6, IPV6_MTU, (void*)512, sizeof(int), TYPE_INT, -EINVAL, -ENOTCONN, 0},
+ { AF_INET6, SOCK_STREAM, IPPROTO_TCP, IPPROTO_IPV6, IPV6_MTU, (void*)IPV6_MIN_MTU, sizeof(int), TYPE_INT, 0, -ENOTCONN, 0},
+
+ { AF_INET6, SOCK_STREAM, IPPROTO_TCP, IPPROTO_IPV6, IPV6_MTU_DISCOVER, (void*)IP_PMTUDISC_DONT, sizeof(int), TYPE_INT, 0, 0, 0},
+ { AF_INET6, SOCK_STREAM, IPPROTO_TCP, IPPROTO_IPV6, IPV6_MTU_DISCOVER, (void*)IP_PMTUDISC_WANT, sizeof(int), TYPE_INT, 0, 0, 0},
+ { AF_INET6, SOCK_STREAM, IPPROTO_TCP, IPPROTO_IPV6, IPV6_MTU_DISCOVER, (void*)IP_PMTUDISC_DO, sizeof(int), TYPE_INT, 0, 0, 0},
+ { AF_INET6, SOCK_STREAM, IPPROTO_TCP, IPPROTO_IPV6, IPV6_MTU_DISCOVER, (void*)IP_PMTUDISC_PROBE,sizeof(int), TYPE_INT, 0, 0, 0},
+
+ { AF_INET6, SOCK_STREAM, IPPROTO_TCP, IPPROTO_IPV6, IPV6_UNICAST_IF, (void*)0, sizeof(int), TYPE_INT, 0, 0, 0},
+ { AF_INET6, SOCK_STREAM, IPPROTO_TCP, IPPROTO_IPV6, IPV6_UNICAST_IF, (void*)0x01000000, sizeof(int), TYPE_INT, 0, 0, 0},
+ { AF_INET6, SOCK_STREAM, IPPROTO_TCP, IPPROTO_IPV6, IPV6_UNICAST_IF, (void*)-1, sizeof(int), TYPE_INT, -EADDRNOTAVAIL, -EADDRNOTAVAIL, 0},
+
+ { AF_INET6, SOCK_STREAM, IPPROTO_TCP, IPPROTO_IPV6, IPV6_MULTICAST_IF, (void*)0, sizeof(int), TYPE_INT, -ENOPROTOOPT, -ENOPROTOOPT, 0},
+ { AF_INET6, SOCK_DGRAM, IPPROTO_UDP, IPPROTO_IPV6, IPV6_MULTICAST_IF, (void*)0, sizeof(int), TYPE_INT, 0, 0, 0},
+ { AF_INET6, SOCK_DGRAM, IPPROTO_UDP, IPPROTO_IPV6, IPV6_MULTICAST_IF, (void*)-1, sizeof(int), TYPE_INT, -ENODEV, -ENODEV, 0},
+
+ { AF_INET6, SOCK_DGRAM, IPPROTO_UDP, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, (void*)-1, sizeof(int), TYPE_INT, 0, 0, 0},
+ { AF_INET6, SOCK_DGRAM, IPPROTO_UDP, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, (void*)0, sizeof(int), TYPE_INT, 0, 0, 0},
+ { AF_INET6, SOCK_DGRAM, IPPROTO_UDP, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, (void*)255, sizeof(int), TYPE_INT, 0, 0, 0},
+ { AF_INET6, SOCK_DGRAM, IPPROTO_UDP, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, (void*)256, sizeof(int), TYPE_INT, -EINVAL, 0, 0},
+
+ { AF_INET6, SOCK_DGRAM, IPPROTO_UDP, IPPROTO_IPV6, IPV6_UNICAST_HOPS, (void*)-1, sizeof(int), TYPE_INT, 0, 0, 0},
+ { AF_INET6, SOCK_DGRAM, IPPROTO_UDP, IPPROTO_IPV6, IPV6_UNICAST_HOPS, (void*)0, sizeof(int), TYPE_INT, 0, 0, 0},
+ { AF_INET6, SOCK_DGRAM, IPPROTO_UDP, IPPROTO_IPV6, IPV6_UNICAST_HOPS, (void*)255, sizeof(int), TYPE_INT, 0, 0, 0},
+ { AF_INET6, SOCK_DGRAM, IPPROTO_UDP, IPPROTO_IPV6, IPV6_UNICAST_HOPS, (void*)256, sizeof(int), TYPE_INT, -EINVAL, 0, 0},
+
+
+};
+
+#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
+#define ERR_STRING_SZ 64
+
+static int my_run_testcase(void *arg)
+{
+ struct sockopt_testcase *s = (struct sockopt_testcase*)arg;
+ int fd, rc, val;
+ void *optdata;
+ socklen_t readsize;
+
+ fd = socket(s->domain, s->type, s->protocol);
+ ASSERT(fd > 0);
+
+ if (s->data_type == TYPE_INT) {
+ val = (long)s->value;
+ optdata = &val;
+ } else {
+ optdata = s->value;
+ }
+
+ rc = setsockopt(fd, s->level, s->optname, optdata, s->size);
+ CHECK(rc == 0 || errno == -s->expect_set, "setsockopt option %d\n", s->optname);
+
+ if (s->data_type == TYPE_INT) {
+ optdata = &val;
+ val = -1;
+ } else {
+ optdata = malloc(s->size);
+ ASSERT(optdata != NULL);
+ }
+
+ readsize = s->size;
+ rc = getsockopt(fd, s->level, s->optname, optdata, &readsize);
+ CHECK(rc == 0 || errno == -s->expect_get, "getsockopt option %d\n", s->optname);
+ ASSERT(readsize == s->size);
+
+ if (rc == 0 && errno == 0) {
+ if (s->data_type == TYPE_INT) {
+ CHECK(val == (long)s->value, "Read value different from written value\n");
+ } else {
+ CHECK(!memcmp(optdata, s->value, s->size), "Read value different from written value\n");
+ free(optdata);
+ }
+ }
+ ASSERT(close(fd) == 0);
+ return 0;
+}
+
+static int run_tests(void)
+{
+ int rc;
+ struct generic_test test1 = {
+ .name = "sockopt AF_INET6",
+ .prepare = NULL,
+ .run = my_run_testcase,
+ .testcases = tests_inet6,
+ .testcase_size = sizeof(struct sockopt_testcase),
+ .testcase_count = ARRAY_SIZE(tests_inet6),
+ };
+
+ rc = 0;
+ rc |= run_all_tests(&test1, NULL);
+
+ return rc;
+}
+
+int main(void)
+{
+ int err = run_tests();
+
+ return err;
+}
--
1.8.2
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH 1/3 net-next RFC] selftest: add abstractions for net selftests
2013-04-09 10:30 ` [PATCH 1/3 net-next RFC] selftest: add abstractions for net selftests Alexandru Copot
@ 2013-04-09 11:13 ` Daniel Borkmann
2013-04-09 11:24 ` Alexandru Copot
2013-04-09 13:39 ` Sergei Shtylyov
1 sibling, 1 reply; 10+ messages in thread
From: Daniel Borkmann @ 2013-04-09 11:13 UTC (permalink / raw)
To: Alexandru Copot; +Cc: netdev, davem, willemb, edumazet, Daniel Baluta
On 04/09/2013 12:30 PM, Alexandru Copot wrote:
> Signed-of by Alexandru Copot <alex.mihai.c@gmail.com>
> Cc: Daniel Baluta <dbaluta@ixiacom.com>
> ---
> tools/testing/selftests/net/selftests.c | 30 +++++++++++++++++++++++
> tools/testing/selftests/net/selftests.h | 42 +++++++++++++++++++++++++++++++++
> 2 files changed, 72 insertions(+)
> create mode 100644 tools/testing/selftests/net/selftests.c
> create mode 100644 tools/testing/selftests/net/selftests.h
>
> diff --git a/tools/testing/selftests/net/selftests.c b/tools/testing/selftests/net/selftests.c
> new file mode 100644
> index 0000000..cd6e427
> --- /dev/null
> +++ b/tools/testing/selftests/net/selftests.c
> @@ -0,0 +1,30 @@
> +#include <stdio.h>
> +
> +#include "selftests.h"
> +
> +int run_all_tests(struct generic_test *test, void *param)
> +{
> + int i;
> + int rc, allrc;
> + char *ptr;
> +
> + rc = test->prepare ? test->prepare(param) : 0;
> + if (rc)
> + return rc;
> +
> + allrc = 0;
Nitpick: this could already have been initialized above.
> + printf("Testing: %s ", test->name);
> + ptr = test->testcases;
ditto
> + for (i = 0; i < test->testcase_count; i++) {
> + rc = test->run(ptr);
> + allrc |= rc;
> +
> + if (test->abort_on_fail && rc) {
> + printf("Testcase %d failed, aborting\n", i);
> + }
I think here you wanted to abort but didn't?
> +
> + ptr += test->testcase_size;
> + }
> + printf("\t\t%s\n", allrc ? "[FAIL]" : "[PASS]");
> + return allrc;
> +}
> diff --git a/tools/testing/selftests/net/selftests.h b/tools/testing/selftests/net/selftests.h
> new file mode 100644
> index 0000000..e289f03
> --- /dev/null
> +++ b/tools/testing/selftests/net/selftests.h
> @@ -0,0 +1,42 @@
> +#ifndef SELFTESTS_H
> +#define SELFTESTS_H
> +
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <errno.h>
> +
> +#define ASSERT(cond) do { \
> + if (!(cond)) { \
> + fprintf(stderr, "%s:%d %s\n", __FILE__, __LINE__, #cond); \
> + perror(""); \
> + exit(EXIT_FAILURE); \
> + } \
> +} while (0)
> +
> +#define CHECK(cond,fmt,...) \
> + do { \
> + if (!(cond)) { \
> + fprintf(stderr, "(%s, %d): " fmt, \
> + __FILE__, __LINE__, ##__VA_ARGS__); \
> + perror(""); \
> + return 1; \
> + } \
> + } while (0)
Isn't it a bit error-prone if in the middle of somewhere this check fails
and the function suddenly returns 1?
What if this is called from a function that was declared as void or to
return a pointer to a struct etc.?
> +struct generic_test {
> + const char *name;
> + void *testcases;
> + int testcase_size;
> + int testcase_count;
> +
> + int abort_on_fail;
> +
> + int (*prepare)(void *);
> + int (*run)(void *);
> + int (*cleanup)(void *);
> +};
> +
> +int run_all_tests(struct generic_test *test, void *param);
> +
> +#endif
> +
>
Nitpick: here's an extra newline at the end of the file.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 0/3 net-next RFC] selftest: Introduce test abstraction for net
2013-04-09 10:30 [PATCH 0/3 net-next RFC] selftest: Introduce test abstraction for net Alexandru Copot
` (2 preceding siblings ...)
2013-04-09 10:31 ` [PATCH net-next RFC] selftests: add socket options test with IPv6 testcases Alexandru Copot
@ 2013-04-09 11:22 ` Daniel Borkmann
3 siblings, 0 replies; 10+ messages in thread
From: Daniel Borkmann @ 2013-04-09 11:22 UTC (permalink / raw)
To: Alexandru Copot; +Cc: netdev, davem, willemb, edumazet, Daniel Baluta
On 04/09/2013 12:30 PM, Alexandru Copot wrote:
> This series adds a generic test abstraction that can make
> writing testcases easier. A generic_test structure is
> used to define a test and its methods.
Probably it would make sense as well to include other subsystem
test case developers/authors from testing/selftests/* in discussion,
since not only testing/selftests/net/ might want to use it, not
sure.
I don't know how far we want to go here or what is planned, but
maybe also having a look at libtap or others might be quite useful:
https://github.com/zorgnax/libtap/blob/master/tap.h
https://github.com/zorgnax/libtap/blob/master/tap.c
If we want to introduce something generic, then this should maybe
go under testing/selftests/lib/ so that others can make use of
that as well and convert (at least) some of their selftests.
> The second patch updates the socket tests to use the
> new framework, and the third patch creates new tests
> for [set/get]sockopt with some IPV6_* options.
>
> Signed-of by Alexandru Copot <alex.mihai.c@gmail.com>
> Cc: Daniel Baluta <dbaluta@ixiacom.com>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 1/3 net-next RFC] selftest: add abstractions for net selftests
2013-04-09 11:13 ` Daniel Borkmann
@ 2013-04-09 11:24 ` Alexandru Copot
2013-04-09 11:32 ` Daniel Borkmann
0 siblings, 1 reply; 10+ messages in thread
From: Alexandru Copot @ 2013-04-09 11:24 UTC (permalink / raw)
To: Daniel Borkmann; +Cc: netdev, davem, willemb, edumazet, Daniel Baluta
On Tue, Apr 9, 2013 at 2:13 PM, Daniel Borkmann <dborkman@redhat.com> wrote:
>> + for (i = 0; i < test->testcase_count; i++) {
>> + rc = test->run(ptr);
>> + allrc |= rc;
>> +
>> + if (test->abort_on_fail && rc) {
>> + printf("Testcase %d failed, aborting\n", i);
>> + }
>
>
> I think here you wanted to abort but didn't?
Yes, I forgot to break;
>> +#define CHECK(cond,fmt,...) \
>> + do { \
>> + if (!(cond)) { \
>> + fprintf(stderr, "(%s, %d): " fmt, \
>> + __FILE__, __LINE__,
>> ##__VA_ARGS__); \
>> + perror(""); \
>> + return 1; \
>> + } \
>> + } while (0)
>
>
> Isn't it a bit error-prone if in the middle of somewhere this check fails
> and the function suddenly returns 1?
>
> What if this is called from a function that was declared as void or to
> return a pointer to a struct etc.?
Well, I tought of using this only in your high-level testcase methods
(test->run()).
It is also easier to see what is actually being tested.
For anything else the user is free to use any other functions or
return conventions
as the test requires.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 1/3 net-next RFC] selftest: add abstractions for net selftests
2013-04-09 11:24 ` Alexandru Copot
@ 2013-04-09 11:32 ` Daniel Borkmann
0 siblings, 0 replies; 10+ messages in thread
From: Daniel Borkmann @ 2013-04-09 11:32 UTC (permalink / raw)
To: Alexandru Copot; +Cc: netdev, davem, willemb, edumazet, Daniel Baluta
On 04/09/2013 01:24 PM, Alexandru Copot wrote:
> On Tue, Apr 9, 2013 at 2:13 PM, Daniel Borkmann <dborkman@redhat.com> wrote:
>>> +#define CHECK(cond,fmt,...) \
>>> + do { \
>>> + if (!(cond)) { \
>>> + fprintf(stderr, "(%s, %d): " fmt, \
>>> + __FILE__, __LINE__,
>>> ##__VA_ARGS__); \
>>> + perror(""); \
>>> + return 1; \
>>> + } \
>>> + } while (0)
>>
>>
>> Isn't it a bit error-prone if in the middle of somewhere this check fails
>> and the function suddenly returns 1?
>>
>> What if this is called from a function that was declared as void or to
>> return a pointer to a struct etc.?
>
> Well, I tought of using this only in your high-level testcase methods
> (test->run()).
> It is also easier to see what is actually being tested.
>
> For anything else the user is free to use any other functions or
> return conventions
> as the test requires.
Hm, then, still not convinced about the CHECK macro. In worst case this at
least needs a comment, so that people will not misuse that, but with your
two statements above, it seems likely that people could also start using it
in "any other functions or return conventions as the test requires". ;-)
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 1/3 net-next RFC] selftest: add abstractions for net selftests
2013-04-09 10:30 ` [PATCH 1/3 net-next RFC] selftest: add abstractions for net selftests Alexandru Copot
2013-04-09 11:13 ` Daniel Borkmann
@ 2013-04-09 13:39 ` Sergei Shtylyov
2013-04-09 13:54 ` Daniel Borkmann
1 sibling, 1 reply; 10+ messages in thread
From: Sergei Shtylyov @ 2013-04-09 13:39 UTC (permalink / raw)
To: Alexandru Copot; +Cc: netdev, davem, willemb, dborkman, edumazet, Daniel Baluta
Hello.
On 09-04-2013 14:30, Alexandru Copot wrote:
> Signed-of by Alexandru Copot <alex.mihai.c@gmail.com>
> Cc: Daniel Baluta <dbaluta@ixiacom.com>
[...]
> diff --git a/tools/testing/selftests/net/selftests.c b/tools/testing/selftests/net/selftests.c
> new file mode 100644
> index 0000000..cd6e427
> --- /dev/null
> +++ b/tools/testing/selftests/net/selftests.c
> @@ -0,0 +1,30 @@
> +#include <stdio.h>
> +
> +#include "selftests.h"
> +
> +int run_all_tests(struct generic_test *test, void *param)
> +{
> + int i;
> + int rc, allrc;
> + char *ptr;
> +
> + rc = test->prepare ? test->prepare(param) : 0;
> + if (rc)
> + return rc;
> +
> + allrc = 0;
> + printf("Testing: %s ", test->name);
> + ptr = test->testcases;
> + for (i = 0; i < test->testcase_count; i++) {
> + rc = test->run(ptr);
> + allrc |= rc;
> +
> + if (test->abort_on_fail && rc) {
> + printf("Testcase %d failed, aborting\n", i);
> + }
Nit: {} not needed here, at least if you folow the Linux coding style (you
seem to).
WBR, Sergei
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 1/3 net-next RFC] selftest: add abstractions for net selftests
2013-04-09 13:39 ` Sergei Shtylyov
@ 2013-04-09 13:54 ` Daniel Borkmann
0 siblings, 0 replies; 10+ messages in thread
From: Daniel Borkmann @ 2013-04-09 13:54 UTC (permalink / raw)
To: Sergei Shtylyov
Cc: Alexandru Copot, netdev, davem, willemb, edumazet, Daniel Baluta
On 04/09/2013 03:39 PM, Sergei Shtylyov wrote:
> On 09-04-2013 14:30, Alexandru Copot wrote:
>> Signed-of by Alexandru Copot <alex.mihai.c@gmail.com>
>> Cc: Daniel Baluta <dbaluta@ixiacom.com>
> [...]
>
>> diff --git a/tools/testing/selftests/net/selftests.c b/tools/testing/selftests/net/selftests.c
>> new file mode 100644
>> index 0000000..cd6e427
>> --- /dev/null
>> +++ b/tools/testing/selftests/net/selftests.c
>> @@ -0,0 +1,30 @@
[...]
>> + for (i = 0; i < test->testcase_count; i++) {
>> + rc = test->run(ptr);
>> + allrc |= rc;
>> +
>> + if (test->abort_on_fail && rc) {
>> + printf("Testcase %d failed, aborting\n", i);
>> + }
>
> Nit: {} not needed here, at least if you folow the Linux coding style (you seem to).
We already figured out earlier in this thread that a ``break'' was missing. ;-)
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2013-04-09 13:54 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-04-09 10:30 [PATCH 0/3 net-next RFC] selftest: Introduce test abstraction for net Alexandru Copot
2013-04-09 10:30 ` [PATCH 1/3 net-next RFC] selftest: add abstractions for net selftests Alexandru Copot
2013-04-09 11:13 ` Daniel Borkmann
2013-04-09 11:24 ` Alexandru Copot
2013-04-09 11:32 ` Daniel Borkmann
2013-04-09 13:39 ` Sergei Shtylyov
2013-04-09 13:54 ` Daniel Borkmann
2013-04-09 10:31 ` [PATCH 2/3 net-next RFC] selftest: Adapt socket test to new testing framework Alexandru Copot
2013-04-09 10:31 ` [PATCH net-next RFC] selftests: add socket options test with IPv6 testcases Alexandru Copot
2013-04-09 11:22 ` [PATCH 0/3 net-next RFC] selftest: Introduce test abstraction for net Daniel Borkmann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).