From patchwork Thu Apr 25 11:04:59 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Copot X-Patchwork-Id: 239496 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 1357D2C00B6 for ; Thu, 25 Apr 2013 21:06:15 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758054Ab3DYLFr (ORCPT ); Thu, 25 Apr 2013 07:05:47 -0400 Received: from mail-bk0-f45.google.com ([209.85.214.45]:46364 "EHLO mail-bk0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932104Ab3DYLFg (ORCPT ); Thu, 25 Apr 2013 07:05:36 -0400 Received: by mail-bk0-f45.google.com with SMTP id j4so1186927bkw.18 for ; Thu, 25 Apr 2013 04:05:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=NG8hlAVL0WwkeemOIunNiEbD1j55uimtdmoYGIvXogg=; b=yvBn9+tJC33Ppfx/6FmHcaH1WnchxofHdJbhJTQhf0DvOZkao7JZbjWNIxZoB3XETZ MORYjf19uaHdcpmtVbyyl3iuIFel8OWfmz/jBh65bIILZHVlOpvFYKzfkY24NgzjZ/R4 uJRPgBZsjuk6R7GaYp+m6D+hxLbJFRGMRl68LJovMf4GhoS7FCMm/cdME6FxhNAJz+pN PJjUBZMf+eCugHqan/AxwEIaC/qYeqkU+aNhisU83A5ifBHJspKZykucOM7LEAasFrSO jLy3bMZ+EiQfd/FdZjYRkyNV4T3935LyYkURmFwK0jCYup+8OCrt9LcLHbUkY9mmzt5a 01wg== X-Received: by 10.204.167.73 with SMTP id p9mr15972398bky.99.1366887934436; Thu, 25 Apr 2013 04:05:34 -0700 (PDT) Received: from ws.lan ([86.121.192.164]) by mx.google.com with ESMTPSA id io13sm1383660bkc.15.2013.04.25.04.05.32 for (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 25 Apr 2013 04:05:33 -0700 (PDT) From: Alexandru Copot To: linux-kernel@vger.kernel.org Cc: netdev@vger.kernel.org, akpm@linux-foundation.org, davem@davemloft.net, willemb@google.com, dborkman@redhat.com, ebiederm@xmission.com, gorcunov@openvz.org, palewis@adobe.com, edumazet@google.com, Alexandru Copot , Daniel Baluta Subject: [PATCH 2/3 RFC v2] selftests/net: update socket test to use new testing framework Date: Thu, 25 Apr 2013 14:04:59 +0300 Message-Id: <1366887900-24769-3-git-send-email-alex.mihai.c@gmail.com> X-Mailer: git-send-email 1.8.2.1 In-Reply-To: <1366887900-24769-1-git-send-email-alex.mihai.c@gmail.com> References: <1366887900-24769-1-git-send-email-alex.mihai.c@gmail.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Signed-of-by Alexandru Copot Cc: Daniel Baluta --- tools/testing/selftests/net/Makefile | 14 +++-- tools/testing/selftests/net/socket.c | 108 +++++++++++++++++++++++++---------- 2 files changed, 88 insertions(+), 34 deletions(-) diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile index 750512b..7984f80 100644 --- a/tools/testing/selftests/net/Makefile +++ b/tools/testing/selftests/net/Makefile @@ -3,17 +3,23 @@ CC = $(CROSS_COMPILE)gcc CFLAGS = -Wall -O2 -g -CFLAGS += -I../../../../usr/include/ +CFLAGS += -I../../../../usr/include/ -I../lib NET_PROGS = socket psock_fanout psock_tpacket +LIB = ../lib/selftests.a + all: $(NET_PROGS) -%: %.c - $(CC) $(CFLAGS) -o $@ $^ + +socket: socket.o $(LIB) + +%.o: %.c + $(CC) $(CFLAGS) -c -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..198a57b 100644 --- a/tools/testing/selftests/net/socket.c +++ b/tools/testing/selftests/net/socket.c @@ -6,6 +6,8 @@ #include #include +#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,104 @@ 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 test_result_t 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; + test_result_t ret; - fd = socket(s->domain, s->type, s->protocol); - if (fd < 0) { - if (s->nosupport_ok && - errno == EAFNOSUPPORT) - continue; + ret = TEST_PASS; + fd = socket(s->domain, s->type, s->protocol); + if (fd < 0) { + pass_if(s->nosupport_ok && errno == EAFNOSUPPORT, out, ret); - if (s->expect < 0 && - errno == -s->expect) - continue; + pass_if(s->expect < 0 && errno == -s->expect, out, ret); - 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 TEST_FAIL; + } 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 TEST_FAIL; } } +out: + return ret; +} - 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)