From patchwork Thu Jan 23 16:59:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenz Bauer X-Patchwork-Id: 11348737 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3036E13A4 for ; Thu, 23 Jan 2020 16:59:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0DD6624125 for ; Thu, 23 Jan 2020 16:59:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=cloudflare.com header.i=@cloudflare.com header.b="ZBYiAK31" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729751AbgAWQ7o (ORCPT ); Thu, 23 Jan 2020 11:59:44 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:45597 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729727AbgAWQ7n (ORCPT ); Thu, 23 Jan 2020 11:59:43 -0500 Received: by mail-wr1-f65.google.com with SMTP id j42so3864631wrj.12 for ; Thu, 23 Jan 2020 08:59:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudflare.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=U8uUo0eaJeKJ0jdbXMjf43VAJdQstWVWgqdI6CSzlSg=; b=ZBYiAK31WOO0xPmTOkUDOEZRtghl3RzdtoEptjudCjV2kUxmHW05di8KVWAHgyu0/k 1c8+KarUAPRv3AsK6adDHyUV2PPufffkYjy3iJkmEWZXLA2oquozbnezzeKzB9fVTCNp p0mcdJ74lP9u+fQLEDxTO47ildJS+I5mltKtE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=U8uUo0eaJeKJ0jdbXMjf43VAJdQstWVWgqdI6CSzlSg=; b=mCTm3YRmyGl3W9IOx/ZrismkWx/c325btwFwtWTbKBPuds7DaIvCnTaIj2eFweB5qE hQQRF1LyAVQW6lgqn9oCJYRplPCsdNeCkpU/kmU3ieHPtg7nPem8jeBZ/Ad7AF6xuyOu Ydv6i6wXA6LcKqEIk0VyJ2bOjj8+8xlLQ/UWYnKihafwF0qzUaDP3I0MNopVyaVRXy7H iy22X6MxSbjPZuaK5lZCb83ZUzCYDa+24tKsnbZvii5/34yQE6huPl+/YTzeeOtKCs2B fQkz1y4OItPEFUSg2yQ6HCr4UleWsK2wYpeien5CiOxkq2T5XYE6x3jS+5uEhQtoXz1E kRng== X-Gm-Message-State: APjAAAUUJg2CWEKsPLOcBZ6BOQNMdnOa46uX7mpQp8kXn2hJ+Y0tWndJ FnXhp7picNm5k1gzTcsdbQriWwyuL1VetQ== X-Google-Smtp-Source: APXvYqztXSSZ2nYGIIOXGCU19AzvGz7ltbdVZS6Ad/z/XL7I6uqOCN+zAkxKcPOoy0Q+UnAyTkUoDA== X-Received: by 2002:a5d:6652:: with SMTP id f18mr19175902wrw.246.1579798781846; Thu, 23 Jan 2020 08:59:41 -0800 (PST) Received: from localhost.localdomain ([2a06:98c0:1000:8250:d0a9:6cca:1210:a574]) by smtp.gmail.com with ESMTPSA id u1sm3217698wmc.5.2020.01.23.08.59.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jan 2020 08:59:40 -0800 (PST) From: Lorenz Bauer To: Shuah Khan , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , Andrii Nakryiko Cc: Lorenz Bauer , linux-kselftest@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH bpf 1/4] selftests: bpf: use a temporary file in test_sockmap Date: Thu, 23 Jan 2020 16:59:30 +0000 Message-Id: <20200123165934.9584-2-lmb@cloudflare.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200123165934.9584-1-lmb@cloudflare.com> References: <20200123165934.9584-1-lmb@cloudflare.com> MIME-Version: 1.0 Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Use a proper temporary file for sendpage tests. This means that running the tests doesn't clutter the working directory, and allows running the test on read-only filesystems. Signed-off-by: Lorenz Bauer Acked-by: John Fastabend --- tools/testing/selftests/bpf/test_sockmap.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/tools/testing/selftests/bpf/test_sockmap.c b/tools/testing/selftests/bpf/test_sockmap.c index 4a851513c842..779e11da979c 100644 --- a/tools/testing/selftests/bpf/test_sockmap.c +++ b/tools/testing/selftests/bpf/test_sockmap.c @@ -331,7 +331,7 @@ static int msg_loop_sendpage(int fd, int iov_length, int cnt, FILE *file; int i, fp; - file = fopen(".sendpage_tst.tmp", "w+"); + file = tmpfile(); if (!file) { perror("create file for sendpage"); return 1; @@ -340,13 +340,8 @@ static int msg_loop_sendpage(int fd, int iov_length, int cnt, fwrite(&k, sizeof(char), 1, file); fflush(file); fseek(file, 0, SEEK_SET); - fclose(file); - fp = open(".sendpage_tst.tmp", O_RDONLY); - if (fp < 0) { - perror("reopen file for sendpage"); - return 1; - } + fp = fileno(file); clock_gettime(CLOCK_MONOTONIC, &s->start); for (i = 0; i < cnt; i++) { @@ -354,11 +349,11 @@ static int msg_loop_sendpage(int fd, int iov_length, int cnt, if (!drop && sent < 0) { perror("send loop error"); - close(fp); + fclose(file); return sent; } else if (drop && sent >= 0) { printf("sendpage loop error expected: %i\n", sent); - close(fp); + fclose(file); return -EIO; } @@ -366,7 +361,7 @@ static int msg_loop_sendpage(int fd, int iov_length, int cnt, s->bytes_sent += sent; } clock_gettime(CLOCK_MONOTONIC, &s->end); - close(fp); + fclose(file); return 0; } From patchwork Thu Jan 23 16:59:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenz Bauer X-Patchwork-Id: 11348743 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1C2721398 for ; Thu, 23 Jan 2020 17:00:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id ECEE724687 for ; Thu, 23 Jan 2020 17:00:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=cloudflare.com header.i=@cloudflare.com header.b="gtrzkuQ3" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729866AbgAWRAC (ORCPT ); Thu, 23 Jan 2020 12:00:02 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:45600 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729745AbgAWQ7p (ORCPT ); Thu, 23 Jan 2020 11:59:45 -0500 Received: by mail-wr1-f65.google.com with SMTP id j42so3864735wrj.12 for ; Thu, 23 Jan 2020 08:59:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudflare.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=g7SvZ9phUNQgBFhv9EVqVUJXNc7V2T/+gA9/uB1lrNY=; b=gtrzkuQ3f7nCSsbvZV+79p3YHEpiG55tz/BtLLT1TKC04h4wnV8nBZfVTy/oeleTWI FLytsgneqoqPVgRerwb4UmFKfANQw/OyLCbDS9cyI8/FdPksxF1YRxNFYVfCmifcHrmO gfDjmiP/5qHzq51cApwjJfE8JvSN2pHsTbzhE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=g7SvZ9phUNQgBFhv9EVqVUJXNc7V2T/+gA9/uB1lrNY=; b=c+7URWq6P/T9r+zg7Pp0m/lXcXMsIoyRjsnLXIAfMjoQpPt1ETIrPeEGcBiGvhx6uv IhhD3Q2106RFj5GehulKeRu8dgpnoxPtiHmn3kjoMHqOI6UZPOVDjYejmgfdZDd3aRO7 pQ2xToWEwwVwNuqKx4vDzranPWzGFJkk0jha+1Iq6Pi3JQl8f3lCmE1E46MUmyXBOQKO ak3/j0KfVaTQg2zZJ4lack9gl7laf67EMiC31piCZZ4R9En1OH8WI75c8UznQv7HAk6u kULn2hFu+2dLQsbkD/mR9scnP11/Y5j+qcnqLWPk9nntq/YW1vknfN00/19xz0lCjXIS jCWA== X-Gm-Message-State: APjAAAUrjKr5U8Ol4x2/ICvGAG4bux8WWOtKP1T8te6X4JwdlimyfVR1 WznvQOcZldw9wvSCmwb1IPf9kQ== X-Google-Smtp-Source: APXvYqxZBMzloyeuvuGWMOXyEMsTRg357vgRAFLanDZW9K3hvo17Oc9CnYfhEOKDJRcCoIGSj/eFaA== X-Received: by 2002:adf:cf0a:: with SMTP id o10mr18246948wrj.325.1579798783545; Thu, 23 Jan 2020 08:59:43 -0800 (PST) Received: from localhost.localdomain ([2a06:98c0:1000:8250:d0a9:6cca:1210:a574]) by smtp.gmail.com with ESMTPSA id u1sm3217698wmc.5.2020.01.23.08.59.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jan 2020 08:59:42 -0800 (PST) From: Lorenz Bauer To: Shuah Khan , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , Andrii Nakryiko Cc: Lorenz Bauer , linux-kselftest@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH bpf 2/4] selftests: bpf: ignore RST packets for reuseport tests Date: Thu, 23 Jan 2020 16:59:31 +0000 Message-Id: <20200123165934.9584-3-lmb@cloudflare.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200123165934.9584-1-lmb@cloudflare.com> References: <20200123165934.9584-1-lmb@cloudflare.com> MIME-Version: 1.0 Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org The reuseport tests currently suffer from a race condition: RST packets count towards DROP_ERR_SKB_DATA, since they don't contain a valid struct cmd. Tests will spuriously fail depending on whether check_results is called before or after the RST is processed. Exit the BPF program early if FIN is set. Signed-off-by: Lorenz Bauer Acked-by: John Fastabend --- .../selftests/bpf/progs/test_select_reuseport_kern.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tools/testing/selftests/bpf/progs/test_select_reuseport_kern.c b/tools/testing/selftests/bpf/progs/test_select_reuseport_kern.c index d69a1f2bbbfd..26e77dcc7e91 100644 --- a/tools/testing/selftests/bpf/progs/test_select_reuseport_kern.c +++ b/tools/testing/selftests/bpf/progs/test_select_reuseport_kern.c @@ -113,6 +113,12 @@ int _select_by_skb_data(struct sk_reuseport_md *reuse_md) data_check.skb_ports[0] = th->source; data_check.skb_ports[1] = th->dest; + if (th->fin) + /* The connection is being torn down at the end of a + * test. It can't contain a cmd, so return early. + */ + return SK_PASS; + if ((th->doff << 2) + sizeof(*cmd) > data_check.len) GOTO_DONE(DROP_ERR_SKB_DATA); if (bpf_skb_load_bytes(reuse_md, th->doff << 2, &cmd_copy, From patchwork Thu Jan 23 16:59:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenz Bauer X-Patchwork-Id: 11348739 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1B67713A4 for ; Thu, 23 Jan 2020 16:59:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EDB9D24688 for ; Thu, 23 Jan 2020 16:59:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=cloudflare.com header.i=@cloudflare.com header.b="yLHzEv+A" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729701AbgAWQ7s (ORCPT ); Thu, 23 Jan 2020 11:59:48 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:38704 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729787AbgAWQ7q (ORCPT ); Thu, 23 Jan 2020 11:59:46 -0500 Received: by mail-wr1-f68.google.com with SMTP id y17so3919343wrh.5 for ; Thu, 23 Jan 2020 08:59:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudflare.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Rb1rNawttqyIkUsUxmbdc0uUxGiYj0dD/f72ioJC76k=; b=yLHzEv+AA8o4f/7cdOhZQV9l/CveX4Eviz1ROxUOGNJOdZWLcO87ssprX/3wmIjbDT TbhDAlrWrjcsK7Dt3y3V6ndEobcs4+OSePOc9/42fr8PvzJXcGnCyU+jetwxkNVnV/2K xyK5BE3E246zlrUr2HyFhrEi9TGkza4umntkE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Rb1rNawttqyIkUsUxmbdc0uUxGiYj0dD/f72ioJC76k=; b=FrRC/RX6x1X76De/h4wE3kEEFm7x8fNKCQunqtRTMhh9G9flm+rSSmSF7pS8m+Re/H kMK/HtauUtT6bhO9zd7Rbryb65s0COS0UBgjz15gHZjFlNGRhqaiAQEdplhzcfDB48xH bbTPei9fIRlzARWjja8VVYLkUYvRHRqgr7XEKtOsswt0rWEDnrIg0xeg1mvyXZ8jk0u0 uQbBVc5blBSTmbaFiE2IDQIyHnsNbfTFs3L3r8oti9I2w+q1q2ArWYVgrKMMpW2fl9KV ATekaTnJAnYGXzuoKkGfaGr81SIwp2K8Sp9W645wXacWshnbHYYcY5P3k0HD3SkmKorg 5xQg== X-Gm-Message-State: APjAAAWPXSxFBLamsRqh8cSkBO8MGU5rBzNzP1TY0+z6CPj3vpWMlj4m Nxy6xb3xdGLFMQZq2p/YTuJGAw== X-Google-Smtp-Source: APXvYqw5qClXvS6LvBmbFphDEZ37bZMMug7AGHXZjJYQNS1WAbdkaa7R9cQ+mSce0KsrQyAnYJTSYQ== X-Received: by 2002:adf:81c2:: with SMTP id 60mr18243517wra.8.1579798785202; Thu, 23 Jan 2020 08:59:45 -0800 (PST) Received: from localhost.localdomain ([2a06:98c0:1000:8250:d0a9:6cca:1210:a574]) by smtp.gmail.com with ESMTPSA id u1sm3217698wmc.5.2020.01.23.08.59.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jan 2020 08:59:44 -0800 (PST) From: Lorenz Bauer To: Shuah Khan , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , Andrii Nakryiko Cc: Lorenz Bauer , linux-kselftest@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH bpf 3/4] selftests: bpf: make reuseport test output more legible Date: Thu, 23 Jan 2020 16:59:32 +0000 Message-Id: <20200123165934.9584-4-lmb@cloudflare.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200123165934.9584-1-lmb@cloudflare.com> References: <20200123165934.9584-1-lmb@cloudflare.com> MIME-Version: 1.0 Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Include the name of the mismatching result in human readable format when reporting an error. The new output looks like the following: unexpected result result: [1, 0, 0, 0, 0, 0] expected: [0, 0, 0, 0, 0, 0] mismatch on DROP_ERR_INNER_MAP (bpf_prog_linum:153) check_results:FAIL:382 Signed-off-by: Lorenz Bauer Acked-by: John Fastabend --- .../bpf/prog_tests/select_reuseport.c | 30 ++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/select_reuseport.c b/tools/testing/selftests/bpf/prog_tests/select_reuseport.c index 2c37ae7dc214..09a536af139a 100644 --- a/tools/testing/selftests/bpf/prog_tests/select_reuseport.c +++ b/tools/testing/selftests/bpf/prog_tests/select_reuseport.c @@ -316,6 +316,28 @@ static void check_data(int type, sa_family_t family, const struct cmd *cmd, expected.len, result.len, get_linum()); } +static const char *result_to_str(enum result res) +{ + switch (res) { + case DROP_ERR_INNER_MAP: + return "DROP_ERR_INNER_MAP"; + case DROP_ERR_SKB_DATA: + return "DROP_ERR_SKB_DATA"; + case DROP_ERR_SK_SELECT_REUSEPORT: + return "DROP_ERR_SK_SELECT_REUSEPORT"; + case DROP_MISC: + return "DROP_MISC"; + case PASS: + return "PASS"; + case PASS_ERR_SK_SELECT_REUSEPORT: + return "PASS_ERR_SK_SELECT_REUSEPORT"; + case NR_RESULTS: + return "NR_RESULTS"; + default: + return "UNKNOWN"; + } +} + static void check_results(void) { __u32 results[NR_RESULTS]; @@ -351,10 +373,10 @@ static void check_results(void) printf(", %u", expected_results[i]); printf("]\n"); - RET_IF(expected_results[broken] != results[broken], - "unexpected result", - "expected_results[%u] != results[%u] bpf_prog_linum:%ld\n", - broken, broken, get_linum()); + printf("mismatch on %s (bpf_prog_linum:%ld)\n", result_to_str(broken), + get_linum()); + + CHECK_FAIL(true); } static int send_data(int type, sa_family_t family, void *data, size_t len, From patchwork Thu Jan 23 16:59:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenz Bauer X-Patchwork-Id: 11348741 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A8F4192A for ; Thu, 23 Jan 2020 16:59:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 873E521D7E for ; Thu, 23 Jan 2020 16:59:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=cloudflare.com header.i=@cloudflare.com header.b="rmcV1F+u" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729838AbgAWQ7y (ORCPT ); Thu, 23 Jan 2020 11:59:54 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:41350 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729774AbgAWQ7t (ORCPT ); Thu, 23 Jan 2020 11:59:49 -0500 Received: by mail-wr1-f65.google.com with SMTP id c9so3897925wrw.8 for ; Thu, 23 Jan 2020 08:59:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudflare.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lzJSOoo0RY3SkOVg99jXaD0hCIShOjvh87S5WEoUKHA=; b=rmcV1F+uEgQl1C9Bw8jxZiHVIX5+T5T3sxYSgR7I6GG/JUWe0M8tWN2DUqqzWdoYgX N2B0KivXpJcrI72myxxmd5mlC6uuOjeJuGV48CFZb+1C4xJ7slk65KxrEZJDZHcr+vJB gTkFp0ARrz5plhGXPSwjmnDPxsDwOS9CKDuE8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lzJSOoo0RY3SkOVg99jXaD0hCIShOjvh87S5WEoUKHA=; b=AM7LW5YZRoVePNJz/aZp9eG/sE0GVH41TLo4OMW6LU0TDT+w7iwzCFxHBGXgqLSovo uk01sPq6fhc/4egtekSmo89eeWtPSlGToY3LKIkwqgyhmQiSOEM3p1soJJOU13H4irkj c4l5OHs6YJ7DZ5Tw/NzeEW4xxylThAZLYXPkf1RVhRkvkuXhELVhg7E26AUHNVbRXEIu jHZ0AltQUnFk5s/kX+j6n/DDnMjki8qJ68lNkv4QRuqtnAn4EnkDJFh1c4tMRWP9hi7c 6OSUN3ZlXcFDvifKdmV/ot09VGnGW2Gkm/awPvQ29rtYWxLfJC0UAOAkhFSgb6PmI9lc oWkw== X-Gm-Message-State: APjAAAXaRCRERg95mIbsAeo8ILUj2fVqsMjrDjqumDXT/LWPBjdX68Fy THIS16o2IuomLrFJ8xuQ2rQm1vuzBGIZUA== X-Google-Smtp-Source: APXvYqznD+zC0q/A4MhGzomvxakH4li9R6cnks1twXRbQNsnspUm7dxAarVtPVqc3Z3Kl1zIo2bzig== X-Received: by 2002:adf:fc03:: with SMTP id i3mr18956626wrr.306.1579798787004; Thu, 23 Jan 2020 08:59:47 -0800 (PST) Received: from localhost.localdomain ([2a06:98c0:1000:8250:d0a9:6cca:1210:a574]) by smtp.gmail.com with ESMTPSA id u1sm3217698wmc.5.2020.01.23.08.59.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jan 2020 08:59:46 -0800 (PST) From: Lorenz Bauer To: Shuah Khan , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , Andrii Nakryiko Cc: Lorenz Bauer , linux-kselftest@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH bpf 4/4] selftests: bpf: reset global state between reuseport test runs Date: Thu, 23 Jan 2020 16:59:33 +0000 Message-Id: <20200123165934.9584-5-lmb@cloudflare.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200123165934.9584-1-lmb@cloudflare.com> References: <20200123165934.9584-1-lmb@cloudflare.com> MIME-Version: 1.0 Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Currently, there is a lot of false positives if a single reuseport test fails. This is because expected_results and the result map are not cleared. Zero both after individual test runs, which fixes the mentioned false positives. Signed-off-by: Lorenz Bauer Acked-by: Martin KaFai Lau --- .../selftests/bpf/prog_tests/select_reuseport.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/bpf/prog_tests/select_reuseport.c b/tools/testing/selftests/bpf/prog_tests/select_reuseport.c index 09a536af139a..0bab8b1ca1c3 100644 --- a/tools/testing/selftests/bpf/prog_tests/select_reuseport.c +++ b/tools/testing/selftests/bpf/prog_tests/select_reuseport.c @@ -699,7 +699,19 @@ static void setup_per_test(int type, sa_family_t family, bool inany, static void cleanup_per_test(bool no_inner_map) { - int i, err; + int i, err, zero = 0; + + memset(expected_results, 0, sizeof(expected_results)); + + for (i = 0; i < NR_RESULTS; i++) { + err = bpf_map_update_elem(result_map, &i, &zero, BPF_ANY); + RET_IF(err, "reset elem in result_map", + "i:%u err:%d errno:%d\n", i, err, errno); + } + + err = bpf_map_update_elem(linum_map, &zero, &zero, BPF_ANY); + RET_IF(err, "reset line number in linum_map", "err:%d errno:%d\n", + err, errno); for (i = 0; i < REUSEPORT_ARRAY_SIZE; i++) close(sk_fds[i]);