Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp852615pxk; Thu, 17 Sep 2020 19:06:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz6PuGRKkSS80dkE9Zno77W1X3sAR9JSdgiTd5EKqNeS/rZnZDtAI6jg4N5SgvNLQUp1fuB X-Received: by 2002:a50:99d6:: with SMTP id n22mr36790224edb.265.1600394796142; Thu, 17 Sep 2020 19:06:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600394796; cv=none; d=google.com; s=arc-20160816; b=df+Da0fJcWYWNbke5OXLsqIKlV7afzBvCuk52e3mw3fnBgPkAjs969wsPi7i2pUJ3j Wg0t2ooxARNOCOU6U1QaS9VkENGQtqSG33legDwM7Rx2fQ1UUl42n0zw8L9JeKZJ4fty Tdm4jHaabCnP255CCBJqx6vsXQygt2D62bKrNHw7HKWt6rVk1WWgUCccirOiRTKjPUgz YLlsbgWoXkpp5pdqG+L59X1/Vc6Tr266o2EIdjxURhQi/42mv/mL771ADBV0N6+re/1s R4jkx/H9AOuFw2hUIigh0DMRpcFnoJVgw1X6fCeUCjtOpo+x9xGNmx76sS0Pg2Z6VUQh /n9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=BJCh09z4KPb4kw6UsQWO029cG87S/jFHx7WareYVKgk=; b=oLJ4cQWUTqwmVmZmY7f98yuiYqHJcVgE6vG5Z2XyFffyvtfIZT11FdRlyUpmpfg4eE TSeX+4scUE9makZjFkFLjAPOu3bGIx5+W7Z+B6KTwQ93rBN1fxdLn2xq35RY23BbOy9b 8q0u9AU4i65RaMDdojzjklJtd2YhaWZW5hKNrYuUmAKdWUdJLRIgQOg3LV/+0iFO2jUG 3q7esKoJkhyjOLlaSEvHrdQubDTOZwSVSdf3/Ft7ZK6cAqz7egpazOWnfTED/i9a816e kwK+svHN/VKKUI8cEWo8+OrXgAa4gZDbxTbXxQK7FSrXWxddH5TnoCfgsmK8saKsu88B OxeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=PQPeJmPV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y3si990146edq.449.2020.09.17.19.06.13; Thu, 17 Sep 2020 19:06:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=PQPeJmPV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726815AbgIRCCh (ORCPT + 99 others); Thu, 17 Sep 2020 22:02:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:47888 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726798AbgIRCCg (ORCPT ); Thu, 17 Sep 2020 22:02:36 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 22F35221EC; Fri, 18 Sep 2020 02:02:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600394555; bh=A6iVWKRWFky6V91r7CvpkOKV8Ult2j1FeDLCBRix+y0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PQPeJmPVdK57xBrSP1E/mHxNZ5vZMWD50xPgqcn34CPJiNFIjD5M4Qqh2LQSx4fRg mf9QNVW/fi3VaR1D4yHMj9IhFnVx5JGRqBAJP9sBUqpfFJXyzXbbO99Khi9mJLk4iz wEyfIVWgOKMbE7fpa1IakLEB9gg7uiu4812J15og= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Stanislav Fomichev , Alexei Starovoitov , Lawrence Brakmo , Sasha Levin , linux-api@vger.kernel.org Subject: [PATCH AUTOSEL 5.4 071/330] selftests/bpf: De-flake test_tcpbpf Date: Thu, 17 Sep 2020 21:56:51 -0400 Message-Id: <20200918020110.2063155-71-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200918020110.2063155-1-sashal@kernel.org> References: <20200918020110.2063155-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Stanislav Fomichev [ Upstream commit ef8c84effce3c7a0b8196fcda8f430c815ab511c ] It looks like BPF program that handles BPF_SOCK_OPS_STATE_CB state can race with the bpf_map_lookup_elem("global_map"); I sometimes see the failures in this test and re-running helps. Since we know that we expect the callback to be called 3 times (one time for listener socket, two times for both ends of the connection), let's export this number and add simple retry logic around that. Also, let's make EXPECT_EQ() not return on failure, but continue evaluating all conditions; that should make potential debugging easier. With this fix in place I don't observe the flakiness anymore. Signed-off-by: Stanislav Fomichev Signed-off-by: Alexei Starovoitov Cc: Lawrence Brakmo Link: https://lore.kernel.org/bpf/20191204190955.170934-1-sdf@google.com Signed-off-by: Sasha Levin --- .../selftests/bpf/progs/test_tcpbpf_kern.c | 1 + tools/testing/selftests/bpf/test_tcpbpf.h | 1 + .../testing/selftests/bpf/test_tcpbpf_user.c | 25 +++++++++++++------ 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/bpf/progs/test_tcpbpf_kern.c b/tools/testing/selftests/bpf/progs/test_tcpbpf_kern.c index 2e233613d1fc0..7fa4595d2b66b 100644 --- a/tools/testing/selftests/bpf/progs/test_tcpbpf_kern.c +++ b/tools/testing/selftests/bpf/progs/test_tcpbpf_kern.c @@ -131,6 +131,7 @@ int bpf_testcb(struct bpf_sock_ops *skops) g.bytes_received = skops->bytes_received; g.bytes_acked = skops->bytes_acked; } + g.num_close_events++; bpf_map_update_elem(&global_map, &key, &g, BPF_ANY); } diff --git a/tools/testing/selftests/bpf/test_tcpbpf.h b/tools/testing/selftests/bpf/test_tcpbpf.h index 7bcfa62070056..6220b95cbd02c 100644 --- a/tools/testing/selftests/bpf/test_tcpbpf.h +++ b/tools/testing/selftests/bpf/test_tcpbpf.h @@ -13,5 +13,6 @@ struct tcpbpf_globals { __u64 bytes_received; __u64 bytes_acked; __u32 num_listen; + __u32 num_close_events; }; #endif diff --git a/tools/testing/selftests/bpf/test_tcpbpf_user.c b/tools/testing/selftests/bpf/test_tcpbpf_user.c index 716b4e3be5813..3ae127620463d 100644 --- a/tools/testing/selftests/bpf/test_tcpbpf_user.c +++ b/tools/testing/selftests/bpf/test_tcpbpf_user.c @@ -16,6 +16,9 @@ #include "test_tcpbpf.h" +/* 3 comes from one listening socket + both ends of the connection */ +#define EXPECTED_CLOSE_EVENTS 3 + #define EXPECT_EQ(expected, actual, fmt) \ do { \ if ((expected) != (actual)) { \ @@ -23,13 +26,14 @@ " Actual: %" fmt "\n" \ " Expected: %" fmt "\n", \ (actual), (expected)); \ - goto err; \ + ret--; \ } \ } while (0) int verify_result(const struct tcpbpf_globals *result) { __u32 expected_events; + int ret = 0; expected_events = ((1 << BPF_SOCK_OPS_TIMEOUT_INIT) | (1 << BPF_SOCK_OPS_RWND_INIT) | @@ -48,15 +52,15 @@ int verify_result(const struct tcpbpf_globals *result) EXPECT_EQ(0x80, result->bad_cb_test_rv, PRIu32); EXPECT_EQ(0, result->good_cb_test_rv, PRIu32); EXPECT_EQ(1, result->num_listen, PRIu32); + EXPECT_EQ(EXPECTED_CLOSE_EVENTS, result->num_close_events, PRIu32); - return 0; -err: - return -1; + return ret; } int verify_sockopt_result(int sock_map_fd) { __u32 key = 0; + int ret = 0; int res; int rv; @@ -69,9 +73,7 @@ int verify_sockopt_result(int sock_map_fd) rv = bpf_map_lookup_elem(sock_map_fd, &key, &res); EXPECT_EQ(0, rv, "d"); EXPECT_EQ(1, res, "d"); - return 0; -err: - return -1; + return ret; } static int bpf_find_map(const char *test, struct bpf_object *obj, @@ -96,6 +98,7 @@ int main(int argc, char **argv) int error = EXIT_FAILURE; struct bpf_object *obj; int cg_fd = -1; + int retry = 10; __u32 key = 0; int rv; @@ -134,12 +137,20 @@ int main(int argc, char **argv) if (sock_map_fd < 0) goto err; +retry_lookup: rv = bpf_map_lookup_elem(map_fd, &key, &g); if (rv != 0) { printf("FAILED: bpf_map_lookup_elem returns %d\n", rv); goto err; } + if (g.num_close_events != EXPECTED_CLOSE_EVENTS && retry--) { + printf("Unexpected number of close events (%d), retrying!\n", + g.num_close_events); + usleep(100); + goto retry_lookup; + } + if (verify_result(&g)) { printf("FAILED: Wrong stats\n"); goto err; -- 2.25.1