From patchwork Fri Jan 24 11:27:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenz Bauer X-Patchwork-Id: 11350101 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 B4948139A for ; Fri, 24 Jan 2020 11:38:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 91C65206D4 for ; Fri, 24 Jan 2020 11:38:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=cloudflare.com header.i=@cloudflare.com header.b="qfNpKKm0" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391843AbgAXL34 (ORCPT ); Fri, 24 Jan 2020 06:29:56 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:40220 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404121AbgAXL3x (ORCPT ); Fri, 24 Jan 2020 06:29:53 -0500 Received: by mail-wr1-f65.google.com with SMTP id c14so1546791wrn.7 for ; Fri, 24 Jan 2020 03:29:52 -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=TKV/95Tqr8ROSRylR8JvM121PLnBe6Qd7B63cuI3StE=; b=qfNpKKm07hnqLiriIGmOr8J8e8KK/BT8LiD/HbKtoVjdqQIg+L8LRXe//9Ho80yqRW 7AvncSW3NSitZvir1vo58IpBYDCnD/EtNFepZo3FhkZ0iiHhpaSH/KB/OO9e+S+UblOE 8hor5p0V7rrRFpupNxhkSJdagqdnZoRD7wTMI= 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=TKV/95Tqr8ROSRylR8JvM121PLnBe6Qd7B63cuI3StE=; b=GSsAhA0A/rG3IarSXtVGxTLOUm3Vb93tgyq3e5SdLwOfXDiHJ+PVVUzek4G04YHvTq 6SYxM5kfUApg3B0y7/rQOAKJAUmw5BTxg/jBgtAq3p3MBoFaRu1RRCikMtwDZbb4zPOO l//A7Cwo8vupVlD79UirbBFiQD0i3s5pE9io23M3mFuefaqjQ+g0uzDOEei5DzkWGHv7 kkwQS4w9SG1b6AzRzBdcWEf+mpfeSnfGMijGkaHpRzS11WUuHdPLpVuAvdgZQYp+YutQ Ojf2juj/vIFifRoKE6P+DKfSy/toRLyVwpmU/ny6A3LZfHh+S4MHXk7uKmWBelMCk3hY 4AiQ== X-Gm-Message-State: APjAAAVjC40FfWQmcGT+xnp05odTaGLsmhwGfKiNzI8iYanIdfdu/B0k U9lMVtJm574+ZL8Sr5fjSLy4rQ== X-Google-Smtp-Source: APXvYqxbVdXusdBMhELuISik8LOouZ+0LdsP7kXq8h43aLT+jdhkf6tMvHQYoAN1zRAngTNzB02TJg== X-Received: by 2002:adf:dfcf:: with SMTP id q15mr3804339wrn.404.1579865392024; Fri, 24 Jan 2020 03:29:52 -0800 (PST) Received: from antares.lan (3.a.c.b.c.e.9.a.8.e.c.d.e.4.1.6.f.f.6.2.a.5.a.7.0.b.8.0.1.0.0.2.ip6.arpa. [2001:8b0:7a5a:26ff:614e:dce8:a9ec:bca3]) by smtp.gmail.com with ESMTPSA id n189sm6808688wme.33.2020.01.24.03.29.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2020 03:29:51 -0800 (PST) From: Lorenz Bauer To: Shuah Khan , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , Andrii Nakryiko , John Fastabend Cc: Lorenz Bauer , linux-kselftest@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH bpf-next v2 1/4] selftests: bpf: use a temporary file in test_sockmap Date: Fri, 24 Jan 2020 11:27:51 +0000 Message-Id: <20200124112754.19664-2-lmb@cloudflare.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200124112754.19664-1-lmb@cloudflare.com> References: <20200123165934.9584-1-lmb@cloudflare.com> <20200124112754.19664-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 Fixes: 16962b2404ac ("bpf: sockmap, add selftests") --- 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 Fri Jan 24 11:27:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenz Bauer X-Patchwork-Id: 11350103 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 673B7109A for ; Fri, 24 Jan 2020 11:38:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 46240214DB for ; Fri, 24 Jan 2020 11:38:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=cloudflare.com header.i=@cloudflare.com header.b="wyPpvX1o" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731637AbgAXLiP (ORCPT ); Fri, 24 Jan 2020 06:38:15 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:36478 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389526AbgAXL34 (ORCPT ); Fri, 24 Jan 2020 06:29:56 -0500 Received: by mail-wr1-f67.google.com with SMTP id z3so1565643wru.3 for ; Fri, 24 Jan 2020 03:29:54 -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=23V7V0bQTVhkXPFpZHbr/dpA6QXlskc4s7MHHF/kg3o=; b=wyPpvX1on05Qgb1oTJUYHbUJNqNJVywXnK+eYc/CEFlZ+FYyxqBTorCIgNRAatuedc 1WogFxqm4Rx0i8D0wQaMEkYW3ZxpGbv9QkI8SDAT6ozhh49OB2EEr2X39omSbAaz9zvK y9U+UJQby0rEgCppiEyU3ntbK9vAInHyG7GO4= 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=23V7V0bQTVhkXPFpZHbr/dpA6QXlskc4s7MHHF/kg3o=; b=amws2UlKOJkcytTc4n/fSRb0nev+5ZlKHz+GEFH+pVWa4FknV+qhnPp2HkFe5R8lt2 gMqCcBSbWAfZhryiHcV/5SYg/YeBbpWlHLgBcn/2LzUy+hC4viy3ehNBtjVIShNiBww1 5g3Da9269A+HbY2DoJfkCWF/SpwhrGri7FeM7LOSI0IjMTKuzuaZqqrh4EaFWO2rqE43 +c0cxmISY4Mv8N2A0sQDCwa82/W256rciHbfPFLDMCumGhg/c2uAhyN6JlKQ9tPIUewf X3F9kYUL827yMuDpc0SGMUvAhuKl0lANF4FX5flUV3qIadWkMfhOS0IKANqpeLze5NEC 0uUA== X-Gm-Message-State: APjAAAW0/WfSM0jIX+13WwcNCqS8k0r+pMHLo4xnVCS6fUsRcGLbWcKA hs5aAl8M2iyt/BKEaNTNbsTkdg== X-Google-Smtp-Source: APXvYqxR4PnKJm5OXMmu+YwHZ8oajyip6nFIy5+fZ9y6nFyYA1+taQrddJKco673nEo5N8RV5VfLpA== X-Received: by 2002:adf:9144:: with SMTP id j62mr3863056wrj.168.1579865394173; Fri, 24 Jan 2020 03:29:54 -0800 (PST) Received: from antares.lan (3.a.c.b.c.e.9.a.8.e.c.d.e.4.1.6.f.f.6.2.a.5.a.7.0.b.8.0.1.0.0.2.ip6.arpa. [2001:8b0:7a5a:26ff:614e:dce8:a9ec:bca3]) by smtp.gmail.com with ESMTPSA id n189sm6808688wme.33.2020.01.24.03.29.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2020 03:29:53 -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-next v2 2/4] selftests: bpf: ignore FIN packets for reuseport tests Date: Fri, 24 Jan 2020 11:27:52 +0000 Message-Id: <20200124112754.19664-3-lmb@cloudflare.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200124112754.19664-1-lmb@cloudflare.com> References: <20200123165934.9584-1-lmb@cloudflare.com> <20200124112754.19664-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: FIN 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 FIN is processed. Exit the BPF program early if FIN is set. Signed-off-by: Lorenz Bauer Fixes: 91134d849a0e ("bpf: Test BPF_PROG_TYPE_SK_REUSEPORT") --- .../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 Fri Jan 24 11:27:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenz Bauer X-Patchwork-Id: 11350099 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 C8EDE139A for ; Fri, 24 Jan 2020 11:38:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A7A24206D4 for ; Fri, 24 Jan 2020 11:38:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=cloudflare.com header.i=@cloudflare.com header.b="iljVGTV1" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391978AbgAXLiI (ORCPT ); Fri, 24 Jan 2020 06:38:08 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:54379 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391846AbgAXL35 (ORCPT ); Fri, 24 Jan 2020 06:29:57 -0500 Received: by mail-wm1-f68.google.com with SMTP id g1so1281341wmh.4 for ; Fri, 24 Jan 2020 03:29:56 -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=smQgb7OTV4+v464Eh5cc5iALcZWmuJ7KE4TsJ4XSwN0=; b=iljVGTV1W2UYOROZJjXL2BxExKTYltjH3RaXZgCT13fFOm+Nx1p1W/EGg/MHPiN123 Y/fZoxx0KKrnFOrhiFtN23VntLi2zzgiJv8qGtINNs6LfVaD6TObjxAWKjjZjHKldcjL 6oghRAaotdWG00W3x+PMzNjFhFogTKlxzTHpw= 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=smQgb7OTV4+v464Eh5cc5iALcZWmuJ7KE4TsJ4XSwN0=; b=f6m6FUCceNEoZcZaLBEbO5fLkvmOjFvcp8JLXegwDF3usNhw3uoKPH48aI8w31HVGA JydMzv61S9OPi8BkN+r5wc8bXkpDalJ2u+zGIFUNiJU31CxnQZcUu/kV5OdTtOTjM//b ShvwCQ/8h2WIw8/HQO+7fEhB0lxkwBjIS2eqmi5GjRpCzRuL4pd2Xm7dm58TikbN8mDw CNvYCXoVUWjLvaU4w9/rb2XpyZFGPoiyynC+TnwoiAABjH49KNEBLpFokImZwEUNiRV+ Hl50qAUScXASAVz6snIHTwJr0Y+2EulWGPEFcm7hGmB/31YQh08vXNJ3ZmN1Rzz0g0B8 m9mg== X-Gm-Message-State: APjAAAXgaCxj6qrU+xfinRfJsBKxkh59Xb+57PiQK8nflxE+wv7s3uC+ 6hhA/i2zodw0b6f+RKffDL0Fzw== X-Google-Smtp-Source: APXvYqzBfQGrlE8ATwQ4rMxw2LQnHJD+IP5+yBioiZsrDvhY5hZKhMjpzp6Bd8H8znTSi5coAdlQTg== X-Received: by 2002:a7b:cb91:: with SMTP id m17mr2777626wmi.146.1579865395785; Fri, 24 Jan 2020 03:29:55 -0800 (PST) Received: from antares.lan (3.a.c.b.c.e.9.a.8.e.c.d.e.4.1.6.f.f.6.2.a.5.a.7.0.b.8.0.1.0.0.2.ip6.arpa. [2001:8b0:7a5a:26ff:614e:dce8:a9ec:bca3]) by smtp.gmail.com with ESMTPSA id n189sm6808688wme.33.2020.01.24.03.29.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2020 03:29:55 -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-next v2 3/4] selftests: bpf: make reuseport test output more legible Date: Fri, 24 Jan 2020 11:27:53 +0000 Message-Id: <20200124112754.19664-4-lmb@cloudflare.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200124112754.19664-1-lmb@cloudflare.com> References: <20200123165934.9584-1-lmb@cloudflare.com> <20200124112754.19664-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 --- .../bpf/prog_tests/select_reuseport.c | 28 ++++++++++++++++--- 1 file changed, 24 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..e7e56929751c 100644 --- a/tools/testing/selftests/bpf/prog_tests/select_reuseport.c +++ b/tools/testing/selftests/bpf/prog_tests/select_reuseport.c @@ -316,6 +316,26 @@ 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"; + default: + return "UNKNOWN"; + } +} + static void check_results(void) { __u32 results[NR_RESULTS]; @@ -351,10 +371,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 Fri Jan 24 11:27:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenz Bauer X-Patchwork-Id: 11350097 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 E7517109A for ; Fri, 24 Jan 2020 11:37:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C4BA9206F0 for ; Fri, 24 Jan 2020 11:37:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=cloudflare.com header.i=@cloudflare.com header.b="aGYdZJEs" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391970AbgAXLhy (ORCPT ); Fri, 24 Jan 2020 06:37:54 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:37390 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404136AbgAXL37 (ORCPT ); Fri, 24 Jan 2020 06:29:59 -0500 Received: by mail-wm1-f66.google.com with SMTP id f129so1375677wmf.2 for ; Fri, 24 Jan 2020 03:29:58 -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=cJ4TZV5cXZ/8q9QBQvb7gjQiJz0uB/MAQITB1sj0NIA=; b=aGYdZJEshwF1cDJSP1sWdrNLBZhS7I1RyF6A+y71axz3sMiUBhYP2IE6Kd9mNUgg5W IECZ+kHefZaSIFM+5Bg2JehMCd3qN0v0qS3ULjoDIz6rpsX8FxCiZGK6BXNJbtHF3X4T sv57upHc3Gx34c2KFseWNntiHUPIsA2RuSJ9A= 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=cJ4TZV5cXZ/8q9QBQvb7gjQiJz0uB/MAQITB1sj0NIA=; b=UGwCvdSb5wSpvMnfgEvvqFS4Y4hXBTT+bmtlGCUk8Jxeo3JTU86k4kWqyikAQEK0fa pcDX54C8loweVkFJgnFAa9U1LwmFlSQh6n1cOKtYWluP+VGz6E8L30KhGmAS7QUWUTz+ aoEaEf14dBm5pbkHy+oo7L/csLYfacHmWgFB2K5qbGEJ6ylHE7ICtZStlm0eFCsXKv9d ypZKGDUa+4YoZlzznwzGMjJWXqNqcfbp99cSOKptJ/R+6sb539rZKxkQqoclWKmGHSou yd1GwlRZU3ohiQM6+idiZuoZR3lZ8i7xhal4tID9CxU9eJBEFL67mDSnhHh6hrfvMieL 4aTg== X-Gm-Message-State: APjAAAXAHnPo6+ih7ZzJioKVuKZBOWZXZfRNvBpAjCMJepprQG+lKV9+ 6cR6yZM2hmZss/EIC4ZbHDKYzA== X-Google-Smtp-Source: APXvYqxsibd4gK6MTr1ppba1secKSIQp1ayf0Ni0amvJDL4rkRNpwnjnQZ1jK6nkDlO+g5yIu8e9hQ== X-Received: by 2002:a7b:c450:: with SMTP id l16mr2846104wmi.166.1579865397394; Fri, 24 Jan 2020 03:29:57 -0800 (PST) Received: from antares.lan (3.a.c.b.c.e.9.a.8.e.c.d.e.4.1.6.f.f.6.2.a.5.a.7.0.b.8.0.1.0.0.2.ip6.arpa. [2001:8b0:7a5a:26ff:614e:dce8:a9ec:bca3]) by smtp.gmail.com with ESMTPSA id n189sm6808688wme.33.2020.01.24.03.29.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2020 03:29:56 -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-next v2 4/4] selftests: bpf: reset global state between reuseport test runs Date: Fri, 24 Jan 2020 11:27:54 +0000 Message-Id: <20200124112754.19664-5-lmb@cloudflare.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200124112754.19664-1-lmb@cloudflare.com> References: <20200123165934.9584-1-lmb@cloudflare.com> <20200124112754.19664-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 Fixes: 91134d849a0e ("bpf: Test BPF_PROG_TYPE_SK_REUSEPORT") --- .../selftests/bpf/prog_tests/select_reuseport.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/select_reuseport.c b/tools/testing/selftests/bpf/prog_tests/select_reuseport.c index e7e56929751c..098bcae5f827 100644 --- a/tools/testing/selftests/bpf/prog_tests/select_reuseport.c +++ b/tools/testing/selftests/bpf/prog_tests/select_reuseport.c @@ -33,7 +33,7 @@ #define REUSEPORT_ARRAY_SIZE 32 static int result_map, tmp_index_ovr_map, linum_map, data_check_map; -static enum result expected_results[NR_RESULTS]; +static __u32 expected_results[NR_RESULTS]; static int sk_fds[REUSEPORT_ARRAY_SIZE]; static int reuseport_array = -1, outer_map = -1; static int select_by_skb_data_prog; @@ -697,7 +697,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]);