From patchwork Sat Nov 18 18:42:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuran Pereira X-Patchwork-Id: 745319 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=hotmail.com header.i=@hotmail.com header.b="Zh5ZnvND" Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-db3eur04olkn2068.outbound.protection.outlook.com [40.92.74.68]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58CB4F2; Sat, 18 Nov 2023 10:43:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jI/jcdACzTjkQtltq661NmWCu8MNaitrDEeO0Asa1cO5y1wrl7BIY6nz2hOJkc1g00xJNRQRBWJtu4yyBWUy6hYho4ryjsXnOb7NVb4XWXTG7qNpeDtuH+ctOYKAUcxen/LSF5sz0Ll+679YOsllHkzSHvzT520d0X4B9+xNRd439Fcat2Ill2fhFZsfWjNWpRT472xsH+PKi7RNx4dkKwybO/MFhmGf1/1VLGY+dCtZFlWUUwINLWn+/dU1D8Plhh9bR8KX9cTHXnKcyODdaAcfKtkAolkd6BGy5YTnnfllXEruScYw78qQ4SjVo0HdU1COVKGMT0j13xiom+pk8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=tu9nlo/CAK/qj9SXaN5q97RBCgbUgYNs+wCjj5orNOs=; b=g3nrVV7jaw4Y372BAFe+5vlKqkv+da7w2CiKX7M7U4v0W6hekLKuDl9UyhzibiMAompf2AsGzK+KRX7IwwnLQfXuzHySbbcWj5ANm2JPAi36Ig20E24vlAlONDnkzJwNSrFzak7izRRaNH7hn/cBDapFPjYgmbJPOb7+sDNfKaX2NHjcFgGhJRopUJZYkArLrrO9CciCkeF8gQ7ZzZnx6y3q+tGnRoSHlG4lCj1M6kOD8ybut8kly+Bxa6XY8I6BUDwYi5tCdKRoQWeQzLOEkyzgEdUR0UWCak/LdfoCK3pV6PwUsvaJA8bIUrp5SH8y3l/fXJEa33RD8zc46Htkxw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hotmail.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=tu9nlo/CAK/qj9SXaN5q97RBCgbUgYNs+wCjj5orNOs=; b=Zh5ZnvND8DkNsUWsRmx9S//nShuO+mIhd5VjWRYn/hKDhM50r8x6MInR2X7Gfu9pQ74SIFfztUWy95T3Fd0zK/zPs2Ce+Tt+khFRurB6b1dR9o9YvvxVtgCVUXR4Rx99uTmvAC1xNRQnGnJ4rs8cH6ITqwFz8rHSYLOFeTkIEH06Zl84ZBRHrqCSN4bqZYcGdm8c+oSo4BANHPRoYFd9JfoorCGJ92cvHcu6z/Qqj5wg7dg6FtKDopythucF49nlregXXfRj7KL/+WlkKcOz/LAI0o03tE5O2X0ZX2LuMEZwuC3TprBg945xRbAdIYgIFfow35hkElI1VHgFjMl57g== Received: from GV1PR10MB6563.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:150:83::20) by AM0PR10MB3713.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:159::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7002.26; Sat, 18 Nov 2023 18:43:19 +0000 Received: from GV1PR10MB6563.EURPRD10.PROD.OUTLOOK.COM ([fe80::6c45:bfdf:a384:5450]) by GV1PR10MB6563.EURPRD10.PROD.OUTLOOK.COM ([fe80::6c45:bfdf:a384:5450%7]) with mapi id 15.20.7002.025; Sat, 18 Nov 2023 18:43:19 +0000 From: Yuran Pereira To: bpf@vger.kernel.org Cc: Yuran Pereira , andrii@kernel.org, andrii.nakryiko@gmail.com, mykolal@fb.com, ast@kernel.org, martin.lau@linux.dev, song@kernel.org, yonghong.song@linux.dev, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, shuah@kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kernel-mentees@lists.linuxfoundation.org Subject: [PATCH bpf-next v2 1/4] selftests/bpf: Replaces the usage of CHECK calls for ASSERTs in bpf_tcp_ca Date: Sun, 19 Nov 2023 00:12:54 +0530 Message-ID: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: X-TMN: [vHV8bWmR9XMpg0MEYeI00aZAKc8gQx8a] X-ClientProxiedBy: JNAP275CA0020.ZAFP275.PROD.OUTLOOK.COM (2603:1086:0:4d::20) To GV1PR10MB6563.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:150:83::20) X-Microsoft-Original-Message-ID: <20231118184254.231352-1-yuran.pereira@hotmail.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: GV1PR10MB6563:EE_|AM0PR10MB3713:EE_ X-MS-Office365-Filtering-Correlation-Id: e4bff77f-cca0-443c-7c61-08dbe8663bb5 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Ndlgn65m29HHe9ahiKKBLsm1fLWpFgqTCfqg5MSQdI5FjlFiFfkXnf+Yu0IweVoPdeX2c/7/iGTNrUTyB7vKpYrfvMtxZdZzfhCT+qlT9eRgI9ko5FOFoY7CcBLiJLqDRrQ29J4FSNQe4kLZYKxb6cufb+t/+KeBKoGT9qDYixXlNHSrS83N1U7FAjgNSUiLMCqW1Lckl7kIlozYpgIgN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PH+8VgswjQFS6C6zKxksS2qfPKTPD9dmIz/+jx6pw3CVIMYORcv8ydu6qsn5P6H43leJPb9b49zJfGlP2APMOVqGAtsPYpX/l3qonGQt4DRX1obXhfrYS1oklHmQFASFHSHCQJxOdkP6aNiUAA4WagY+VF/cRiE+7tP3i9WsWfhdoMxFol/OVbyC0EwoIMongHM7rLFHO3UZ3M55qUbUQZNWdCjvc1FbYk4YwaAnE8Zy4llbOwYO+Hs8wp/zNHDUZRtrAOALUca/Ex/SNC3rDBs+ZJc/8kWDQJkKR3G+9tuNG1IkGq5HxPyFJbxeEFuKlzVEsIlKjgEGPfG9ta8c8+mOEfWr3kcXR5G3mxCfgmsBD1GAE6FeWhzQcL0PGFf0tnvDlGtOmrqvxkadvbb49W/RaAXvHR3oLPlvK26BNxCM6kMhBWZXMxka7FYjbERki0GH2VylmaXfRuuLzz0Rp+StFssE/mLSWslu6ZCQY2HOEqYCCiQmDRMtBYwy4mj5kXObpj9AxsLGFwtiB7jeYzOQFWkEE5OlMRFjR5Ti5kP0CsiyulwcXIa57wW3rVndNMW1vh5k2opzenGbQBotKTPx9ebZ6ytRK5eglRXlL0iPyoABhAOcI+zXM8iAuLu3ZkPeojj8noQ= X-OriginatorOrg: sct-15-20-4755-11-msonline-outlook-6b909.templateTenant X-MS-Exchange-CrossTenant-Network-Message-Id: e4bff77f-cca0-443c-7c61-08dbe8663bb5 X-MS-Exchange-CrossTenant-AuthSource: GV1PR10MB6563.EURPRD10.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Nov 2023 18:43:19.2563 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR10MB3713 bpf_tcp_ca uses the `CHECK` calls even though the use of ASSERT_ series of macros is preferred in the bpf selftests. This patch replaces all `CHECK` calls for equivalent `ASSERT_` macro calls. Signed-off-by: Yuran Pereira --- .../selftests/bpf/prog_tests/bpf_tcp_ca.c | 50 +++++++++---------- 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c b/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c index 4aabeaa525d4..6d610b66ec38 100644 --- a/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c +++ b/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c @@ -20,15 +20,14 @@ static const unsigned int total_bytes = 10 * 1024 * 1024; static int expected_stg = 0xeB9F; -static int stop, duration; +static int stop; static int settcpca(int fd, const char *tcp_ca) { int err; err = setsockopt(fd, IPPROTO_TCP, TCP_CONGESTION, tcp_ca, strlen(tcp_ca)); - if (CHECK(err == -1, "setsockopt(fd, TCP_CONGESTION)", "errno:%d\n", - errno)) + if (!ASSERT_NEQ(err, -1, "setsockopt")) return -1; return 0; @@ -65,8 +64,7 @@ static void *server(void *arg) bytes += nr_sent; } - CHECK(bytes != total_bytes, "send", "%zd != %u nr_sent:%zd errno:%d\n", - bytes, total_bytes, nr_sent, errno); + ASSERT_EQ(bytes, total_bytes, "send"); done: if (fd >= 0) @@ -92,10 +90,11 @@ static void do_test(const char *tcp_ca, const struct bpf_map *sk_stg_map) WRITE_ONCE(stop, 0); lfd = socket(AF_INET6, SOCK_STREAM, 0); - if (CHECK(lfd == -1, "socket", "errno:%d\n", errno)) + if (!ASSERT_NEQ(lfd, -1, "socket")) return; + fd = socket(AF_INET6, SOCK_STREAM, 0); - if (CHECK(fd == -1, "socket", "errno:%d\n", errno)) { + if (!ASSERT_NEQ(fd, -1, "socket")) { close(lfd); return; } @@ -108,26 +107,27 @@ static void do_test(const char *tcp_ca, const struct bpf_map *sk_stg_map) sa6.sin6_family = AF_INET6; sa6.sin6_addr = in6addr_loopback; err = bind(lfd, (struct sockaddr *)&sa6, addrlen); - if (CHECK(err == -1, "bind", "errno:%d\n", errno)) + if (!ASSERT_NEQ(err, -1, "bind")) goto done; + err = getsockname(lfd, (struct sockaddr *)&sa6, &addrlen); - if (CHECK(err == -1, "getsockname", "errno:%d\n", errno)) + if (!ASSERT_NEQ(err, -1, "getsockname")) goto done; + err = listen(lfd, 1); - if (CHECK(err == -1, "listen", "errno:%d\n", errno)) + if (!ASSERT_NEQ(err, -1, "listen")) goto done; if (sk_stg_map) { err = bpf_map_update_elem(bpf_map__fd(sk_stg_map), &fd, &expected_stg, BPF_NOEXIST); - if (CHECK(err, "bpf_map_update_elem(sk_stg_map)", - "err:%d errno:%d\n", err, errno)) + if (!ASSERT_OK(err, "bpf_map_update_elem(sk_stg_map)")) goto done; } /* connect to server */ err = connect(fd, (struct sockaddr *)&sa6, addrlen); - if (CHECK(err == -1, "connect", "errno:%d\n", errno)) + if (!ASSERT_NEQ(err, -1, "connect")) goto done; if (sk_stg_map) { @@ -135,14 +135,13 @@ static void do_test(const char *tcp_ca, const struct bpf_map *sk_stg_map) err = bpf_map_lookup_elem(bpf_map__fd(sk_stg_map), &fd, &tmp_stg); - if (CHECK(!err || errno != ENOENT, - "bpf_map_lookup_elem(sk_stg_map)", - "err:%d errno:%d\n", err, errno)) + if (!ASSERT_NEQ(err, 0, "bpf_map_lookup_elem(sk_stg_map)") || + !ASSERT_EQ(errno, ENOENT, "bpf_map_lookup_elem(sk_stg_map)")) goto done; } err = pthread_create(&srv_thread, NULL, server, (void *)(long)lfd); - if (CHECK(err != 0, "pthread_create", "err:%d errno:%d\n", err, errno)) + if (!ASSERT_OK(err, "pthread_create")) goto done; /* recv total_bytes */ @@ -156,13 +155,12 @@ static void do_test(const char *tcp_ca, const struct bpf_map *sk_stg_map) bytes += nr_recv; } - CHECK(bytes != total_bytes, "recv", "%zd != %u nr_recv:%zd errno:%d\n", - bytes, total_bytes, nr_recv, errno); + ASSERT_EQ(bytes, total_bytes, "recv"); WRITE_ONCE(stop, 1); - pthread_join(srv_thread, &thread_ret); - CHECK(IS_ERR(thread_ret), "pthread_join", "thread_ret:%ld", - PTR_ERR(thread_ret)); + err = pthread_join(srv_thread, &thread_ret); + ASSERT_OK(err, "pthread_join"); + done: close(lfd); close(fd); @@ -174,7 +172,7 @@ static void test_cubic(void) struct bpf_link *link; cubic_skel = bpf_cubic__open_and_load(); - if (CHECK(!cubic_skel, "bpf_cubic__open_and_load", "failed\n")) + if (!ASSERT_OK_PTR(cubic_skel, "bpf_cubic__open_and_load")) return; link = bpf_map__attach_struct_ops(cubic_skel->maps.cubic); @@ -197,7 +195,7 @@ static void test_dctcp(void) struct bpf_link *link; dctcp_skel = bpf_dctcp__open_and_load(); - if (CHECK(!dctcp_skel, "bpf_dctcp__open_and_load", "failed\n")) + if (!ASSERT_OK_PTR(dctcp_skel, "bpf_dctcp__open_and_load")) return; link = bpf_map__attach_struct_ops(dctcp_skel->maps.dctcp); @@ -207,9 +205,7 @@ static void test_dctcp(void) } do_test("bpf_dctcp", dctcp_skel->maps.sk_stg_map); - CHECK(dctcp_skel->bss->stg_result != expected_stg, - "Unexpected stg_result", "stg_result (%x) != expected_stg (%x)\n", - dctcp_skel->bss->stg_result, expected_stg); + ASSERT_EQ(dctcp_skel->bss->stg_result, expected_stg, "stg_result"); bpf_link__destroy(link); bpf_dctcp__destroy(dctcp_skel); From patchwork Sat Nov 18 18:44:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuran Pereira X-Patchwork-Id: 745080 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=hotmail.com header.i=@hotmail.com header.b="qSIEa2UN" Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05olkn2017.outbound.protection.outlook.com [40.92.91.17]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 52FD9F2; Sat, 18 Nov 2023 10:45:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YmmsjBTf1nZoAgpszJZZJCxqIlTtyWQaQWQZtM8F5mDjc38n8xbL+bVI/1KQQVR0UG5w4vHXOp1fbG24r11Y1GZG9xNJPTNuHPJCD6BarydvSi1k2cHNnFu6Ew90nAetsM1i3BKSHpLP1hr62yjWb6LjMpRfLYHdkNUIT8O+Rk2Fe/Pcg3Gll/XBYcx7JtpCARNewg4bDpOTjljhg9BphZ6sQTSTOFCafZtfyxjSQnnZ36douIwW4qCOZOgwLr15MakVNl5zYEJDlZnzi9Q0+0FS5eYiz7VjgMsp84hX3UC9JdZmXoH1wV+Z6VH+h1ELU208bVbTySwvv/HUijHqPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=mpgZioiHFXVOmVOt3m5Jvrrc9VUKdE04J+X25ImEGOc=; b=eSggE0kNH7eBc6457IlqimgI7ySI3fISM7KcCRd+Sp1i15dSOIl8D9LulzsvRnihQ3sS71wnP9Sk7aofB67RALUJsupgvc5RnZ4jSUM0KWQrkd+s4SbBd3Ka3ocZW7fKPjdVp7h2INYWUKdQS1NhKowBcpXpNOayg7SdzROrDHaSP8oR+r6ID/qXQrGmJynUF4kZm5nMWpSAapiDSOME4u5BVobjzi4t5xX8MIdABov3L6m07uolmmXWmxQS6ul+MXTDQZrhqunq11pOfEsJDhWu+g17+OAdwASQt7nWBLwy+HCkQuHHClyIclde5ZfWyIM5ReKK0cMqQwpsWQwdfQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hotmail.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=mpgZioiHFXVOmVOt3m5Jvrrc9VUKdE04J+X25ImEGOc=; b=qSIEa2UNlkpmGzMZXQEF6RM0Tn4ghOJXDzVhw0bA0Usvx63xweXWhFr75LoozzZgAx3v1PQ1C0wKlfR2R6r3HRek6J4QMAtk6B6V4Qa9tJmZyBr3zy2U2P3ydlXvX74EHIsmFr1hmEAxyjSUkINuh5DcBjz42EP9xA9sUVgOB1HRL3QDXV/9E5Eh+PhaADyh9NYS0INxSYcIAX+hqHOP1caaq4x0GiKyQtP3QhIVBTYZm8jNStuYo2nlHlCt+e/JXThVa9bSfQpoTGl656D3rzSuDpKCrbP6obIUu6sNPYW4A4Gk+Yw9zfxWVzplApKcSmR7Wp+48ow/+Yje2ItEHg== Received: from GV1PR10MB6563.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:150:83::20) by AS1PR10MB7936.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:471::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7002.26; Sat, 18 Nov 2023 18:44:59 +0000 Received: from GV1PR10MB6563.EURPRD10.PROD.OUTLOOK.COM ([fe80::6c45:bfdf:a384:5450]) by GV1PR10MB6563.EURPRD10.PROD.OUTLOOK.COM ([fe80::6c45:bfdf:a384:5450%7]) with mapi id 15.20.7002.025; Sat, 18 Nov 2023 18:44:59 +0000 From: Yuran Pereira To: bpf@vger.kernel.org Cc: Yuran Pereira , andrii@kernel.org, andrii.nakryiko@gmail.com, mykolal@fb.com, ast@kernel.org, martin.lau@linux.dev, song@kernel.org, yonghong.song@linux.dev, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, shuah@kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kernel-mentees@lists.linuxfoundation.org Subject: [PATCH bpf-next v2 2/4] selftests/bpf: Replaces the usage of CHECK calls for ASSERTs in bind_perm Date: Sun, 19 Nov 2023 00:14:29 +0530 Message-ID: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: X-TMN: [d7GfQLp0rHVLD23IrrF97digOFuZwO/8] X-ClientProxiedBy: JN3P275CA0020.ZAFP275.PROD.OUTLOOK.COM (2603:1086:0:71::17) To GV1PR10MB6563.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:150:83::20) X-Microsoft-Original-Message-ID: <20231118184429.231463-1-yuran.pereira@hotmail.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: GV1PR10MB6563:EE_|AS1PR10MB7936:EE_ X-MS-Office365-Filtering-Correlation-Id: 640a8ffb-8465-492e-abf8-08dbe866774b X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: K7yfJjMruJ4hgLHDUECsSGenJnwyCBjCreAPz7CCYWaFzsCAExzz6RQdWfrOoKZXVPDrbjCMagHqJS+GiKhouCyutKxAqb1VniOYKPKu4B38h2YXvbOReG4LRMu7QvSC/HpTY9Xx6rDICn2goT7LX9f0oYq+9saS9PYcyA+dOZNlTvA3oqFpGaIz5b7cLkqGvlQCiHUdV0AgoHMYmPDaUxEE4kMH9/sFrneqUgHlKwR3EvSpi7fgVUr+XYztgADcdF7EV/SRCIB6uf7W8nRF8V9+DZton7ADvCVxjkQtuhnA/JpQw/Jp97GhEEV6ELdYe70EwI+zAYFdCcq0CQpq2ysMpts6WsKJHTLy0N7nIpSyRIbK2y7qatJjI5ED0mgqvmGFi+x9MlBb+ify/CG00PkULbhI81TS2+29H4CtI6JTIwebgcrOCMxJol+8WkIXRYmFN0vHhA/JWI514pXf4vMFchO1SlHb9Zi7Fe7zaUcABL+CAirFd20rrSTMXIuf1LLzJ4DP+p9lLMEN2PDcbhf9IQ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Wgs6t59xEhBLPAyTpGJNaZmULc8v6vzlzeC5tBoKQ9oOoOE04mi2LJk5FY75MRNAwUfDPA5qmIxq8vmtlCnO9Gmx8ECBdX8J2osHcthBcDLHqKMh2fcTz/2Gq7Eqs8hsPNxzEfOc+5sXDIGZNAv6br/cdA9wyf0U9qoxADnztgreOQgkzw71wlg8/5N1ChLxCA9St2bNBAuI3imWWEi+jfxMBWfzP0AZKMM2tt7KCBKmM0iiM5gkBUuuzjXWMBlvOtAObhlzaAKCU4ftOYILxXBOtsbslStnl8o8nO2tZDvbsemoLSeQPKdBWuqur05zup2BwCAk= X-OriginatorOrg: sct-15-20-4755-11-msonline-outlook-6b909.templateTenant X-MS-Exchange-CrossTenant-Network-Message-Id: 640a8ffb-8465-492e-abf8-08dbe866774b X-MS-Exchange-CrossTenant-AuthSource: GV1PR10MB6563.EURPRD10.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Nov 2023 18:44:59.2032 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS1PR10MB7936 bind_perm uses the `CHECK` calls even though the use of ASSERT_ series of macros is preferred in the bpf selftests. This patch replaces all `CHECK` calls for equivalent `ASSERT_` macro calls. Signed-off-by: Yuran Pereira Acked-by: Yonghong Song --- tools/testing/selftests/bpf/prog_tests/bind_perm.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/bind_perm.c b/tools/testing/selftests/bpf/prog_tests/bind_perm.c index a1766a298bb7..f7cd129cb82b 100644 --- a/tools/testing/selftests/bpf/prog_tests/bind_perm.c +++ b/tools/testing/selftests/bpf/prog_tests/bind_perm.c @@ -9,8 +9,6 @@ #include "cap_helpers.h" #include "bind_perm.skel.h" -static int duration; - static int create_netns(void) { if (!ASSERT_OK(unshare(CLONE_NEWNET), "create netns")) @@ -27,7 +25,7 @@ void try_bind(int family, int port, int expected_errno) int fd = -1; fd = socket(family, SOCK_STREAM, 0); - if (CHECK(fd < 0, "fd", "errno %d", errno)) + if (!ASSERT_GE(fd, 0, "socket")) goto close_socket; if (family == AF_INET) { @@ -60,7 +58,7 @@ void test_bind_perm(void) return; cgroup_fd = test__join_cgroup("/bind_perm"); - if (CHECK(cgroup_fd < 0, "cg-join", "errno %d", errno)) + if (!ASSERT_GE(cgroup_fd, 0, "test__join_cgroup")) return; skel = bind_perm__open_and_load(); From patchwork Sat Nov 18 18:45:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuran Pereira X-Patchwork-Id: 745318 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=hotmail.com header.i=@hotmail.com header.b="KvS8EVlG" Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05olkn2010.outbound.protection.outlook.com [40.92.91.10]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB1F6E5; Sat, 18 Nov 2023 10:46:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BwXnPKYgkt7WNpVtBwHCvWJDgPClBnVS9cY7TYEE6LEihIlKRVqjoKefHCI7qg/xP6jqNGA2alZoPPZHaSXAJc1sy1Hs6IclqYuG7lvgXWMqz8eBs2FkrAsxrJ47v5QQct3PeQ9TCvbZTbwoF9QICx7gaz5elWqznGxgPIUUhStdT5PUriQllsOcjM6p/kgIeTVgKOrhuk/jJaOOz8ndx6VgCCyG832jqeQgQN05pqhdMs1XNSdbYjP6aNFT+r1RU9gsIQ9z5rWM3GEi0DpebOBEXTShnU4D3C4CTLEcnfIbV8nGygVdLxOE5GORKwfUKJR8aGZkqwZ8DqRZ8rmjKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=piQaToojm3qbR2rRzMqggkfCTjcB4RS+/8/vAQe8Fwo=; b=O/jMsZZ+YxOPEVKGj3jAm8lC3ksuXG2cfhdy7qy3i/NQloeiaDfmPIfmAIu9ju7mQctNRFU0/o2fR+zpeSGtqXKLFd1g+I1gB+gZpZmykTx28l8eJlUFnWgZTmvoLNdOJbwBksgT6yG49CQ1vX854RQYAOcDg2FhHL/hiHJlqUe8Hvi3kZ1crfSPndLj4ZkQSomzwEhHzQDjwN2SEozGLHMgK0HND2vOuLp/sywXXNsXKKCxjMP0qWcUp9Kp0wKoJBq3XqAyrfMIUGRpUXRMxhtUCjHa6tmWD+NEfFcXgjbK79ptDhgCn7RQLZItXB39WzY7EwiGFcwsPDrLMuEMhA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hotmail.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=piQaToojm3qbR2rRzMqggkfCTjcB4RS+/8/vAQe8Fwo=; b=KvS8EVlGKk4GgxJlk+Jlfx5dT4Lk5K3CXN3NlHSoo/KIB+kXxIVP/gLg93twAhDGH8ML/7cJeELCxjtaqhwVdeYtdzdYtgdvcy5UlGubllpZiIVor2oRmqk3oVn1pnwBjGjoXi4Dtaz13K2Ee7cATpaiSd+KGS75yTOOweOnkzn18jo1lY1p/TOAFvOuy8fXqqYcxchwr846XttbIbj0Kbahlye+r4861NOSMjJyw6dYDLr7H4UuEQ9Vu0Z1wtqehHsvKFYO0O5aH3M2DyKRHdf7GJIik3LpuFZ+o/nXIoAv99OuM4hM5hMpo8dK5WU/2v0Om0D48GNXHZ7QTdUYkg== Received: from GV1PR10MB6563.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:150:83::20) by AS1PR10MB7936.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:471::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7002.26; Sat, 18 Nov 2023 18:46:13 +0000 Received: from GV1PR10MB6563.EURPRD10.PROD.OUTLOOK.COM ([fe80::6c45:bfdf:a384:5450]) by GV1PR10MB6563.EURPRD10.PROD.OUTLOOK.COM ([fe80::6c45:bfdf:a384:5450%7]) with mapi id 15.20.7002.025; Sat, 18 Nov 2023 18:46:13 +0000 From: Yuran Pereira To: bpf@vger.kernel.org Cc: Yuran Pereira , andrii@kernel.org, andrii.nakryiko@gmail.com, mykolal@fb.com, ast@kernel.org, martin.lau@linux.dev, song@kernel.org, yonghong.song@linux.dev, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, shuah@kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kernel-mentees@lists.linuxfoundation.org Subject: [PATCH bpf-next v2 3/4] selftests/bpf: Replaces the usage of CHECK calls for ASSERTs in bpf_obj_id Date: Sun, 19 Nov 2023 00:15:49 +0530 Message-ID: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: X-TMN: [SEXYXbvlyvvCt0iU8Bq7JhmHSergPit2] X-ClientProxiedBy: JNAP275CA0028.ZAFP275.PROD.OUTLOOK.COM (2603:1086:0:4d::13) To GV1PR10MB6563.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:150:83::20) X-Microsoft-Original-Message-ID: <20231118184549.231582-1-yuran.pereira@hotmail.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: GV1PR10MB6563:EE_|AS1PR10MB7936:EE_ X-MS-Office365-Filtering-Correlation-Id: 8c671b29-9d99-4b27-2c24-08dbe866a360 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Cyn4TngyQe8IomysJhafr6JYfpibBjh59YRz7JyC22HUtxF2Kvr5xU6sDCtD7joqy1qOMcN1B0YxUvczNKD8IUKZpxm5FqZN8E00gWRL0m+M6Yp/bz0Xmkh2lHonxxJdvw5AXGSkCk14VnEwbrs1Z6ipx8otvNrZCRFNdIDlpP7kkdxHZ370h3WA2qzlRUJvA9KMpbhlE53lljym8Gh6bn+6V2lPa6xPPhHjEFFwBToNXJLwWBb+HoUYJcN+jUVlmxH8KF3N5/5ZQfQ+sJO3+rp/dJuO/RFWr+BnU05rr+JWW5lfLYqtP6AjOrhNkyZh1uM/36vzd9xinWJoSy3lwX2pzQ4gS0tL70IdpPWwn8GhXz/JQFP0R77b+6EomugwdsxX/qTa/Kk2Y/j/QVW6EtlznIbHfVEaOMKNIm9BtCMZq9bEGCoR8dGSLgv33yOQTqPDEkBej2cYHFEcRMMdAoi6S2NtUACFfkbF96NTzBmOzOXxuRgIYlLGkMzpVzpik+pExjzEst9wPF98/Re74S1RGrPAy++jYwW+kxjl36+9x8uaeLl1KEALkRyxiFv52dTbkT7OaHtGJ8tb5hbhzJGzxA4SShgsly3NyyYgkp+MXbiTMVwM6/+4onArV+Rq X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 4h53PhiFTlaPhE23tfqg/ud1NglSkljCCiEv+BYTtuROY/QJyzJig2dCka3TaliTEd8j6fAl+muCpyLy3IZE8AxnvSs26M/jkdZvTmA4QhwiaebbOfDk78bZxAv5/8rBe45dTrPxxftjoBWkP3HtpjhXCeNfq7uRP/+74Rje8J4yl+YZImyT4v7jqp00X1m3840qOe1W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ct-15-20-4755-11-msonline-outlook-6b909.templateTenant X-MS-Exchange-CrossTenant-Network-Message-Id: 8c671b29-9d99-4b27-2c24-08dbe866a360 X-MS-Exchange-CrossTenant-AuthSource: GV1PR10MB6563.EURPRD10.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Nov 2023 18:46:13.3365 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS1PR10MB7936 bpf_obj_id uses the `CHECK` calls even though the use of ASSERT_ series of macros is preferred in the bpf selftests. This patch replaces all `CHECK` calls for equivalent `ASSERT_` macro calls. Signed-off-by: Yuran Pereira --- .../selftests/bpf/prog_tests/bpf_obj_id.c | 204 +++++++----------- 1 file changed, 73 insertions(+), 131 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_obj_id.c b/tools/testing/selftests/bpf/prog_tests/bpf_obj_id.c index 675b90b15280..986fb8429b22 100644 --- a/tools/testing/selftests/bpf/prog_tests/bpf_obj_id.c +++ b/tools/testing/selftests/bpf/prog_tests/bpf_obj_id.c @@ -25,7 +25,7 @@ void serial_test_bpf_obj_id(void) */ __u32 map_ids[nr_iters + 1]; char jited_insns[128], xlated_insns[128], zeros[128], tp_name[128]; - __u32 i, next_id, info_len, nr_id_found, duration = 0; + __u32 i, next_id, info_len, nr_id_found; struct timespec real_time_ts, boot_time_ts; int err = 0; __u64 array_value; @@ -33,16 +33,16 @@ void serial_test_bpf_obj_id(void) time_t now, load_time; err = bpf_prog_get_fd_by_id(0); - CHECK(err >= 0 || errno != ENOENT, - "get-fd-by-notexist-prog-id", "err %d errno %d\n", err, errno); + ASSERT_LT(err, 0, "bpf_prog_get_fd_by_id"); + ASSERT_EQ(errno, ENOENT, "bpf_prog_get_fd_by_id"); err = bpf_map_get_fd_by_id(0); - CHECK(err >= 0 || errno != ENOENT, - "get-fd-by-notexist-map-id", "err %d errno %d\n", err, errno); + ASSERT_LT(err, 0, "bpf_map_get_fd_by_id"); + ASSERT_EQ(errno, ENOENT, "bpf_map_get_fd_by_id"); err = bpf_link_get_fd_by_id(0); - CHECK(err >= 0 || errno != ENOENT, - "get-fd-by-notexist-link-id", "err %d errno %d\n", err, errno); + ASSERT_LT(err, 0, "bpf_map_get_fd_by_id"); + ASSERT_EQ(errno, ENOENT, "bpf_map_get_fd_by_id"); /* Check bpf_map_get_info_by_fd() */ bzero(zeros, sizeof(zeros)); @@ -53,25 +53,26 @@ void serial_test_bpf_obj_id(void) /* test_obj_id.o is a dumb prog. It should never fail * to load. */ - if (CHECK_FAIL(err)) + if (!ASSERT_OK(err, "bpf_prog_test_load")) continue; /* Insert a magic value to the map */ map_fds[i] = bpf_find_map(__func__, objs[i], "test_map_id"); - if (CHECK_FAIL(map_fds[i] < 0)) + if (!ASSERT_GE(map_fds[i], 0, "bpf_find_map")) goto done; + err = bpf_map_update_elem(map_fds[i], &array_key, &array_magic_value, 0); - if (CHECK_FAIL(err)) + if (!ASSERT_OK(err, "bpf_map_update_elem")) goto done; - prog = bpf_object__find_program_by_name(objs[i], - "test_obj_id"); - if (CHECK_FAIL(!prog)) + prog = bpf_object__find_program_by_name(objs[i], "test_obj_id"); + if (!ASSERT_OK_PTR(prog, "bpf_object__find_program_by_name")) goto done; + links[i] = bpf_program__attach(prog); err = libbpf_get_error(links[i]); - if (CHECK(err, "prog_attach", "prog #%d, err %d\n", i, err)) { + if (!ASSERT_OK(err, "bpf_program__attach")) { links[i] = NULL; goto done; } @@ -81,24 +82,14 @@ void serial_test_bpf_obj_id(void) bzero(&map_infos[i], info_len); err = bpf_map_get_info_by_fd(map_fds[i], &map_infos[i], &info_len); - if (CHECK(err || - map_infos[i].type != BPF_MAP_TYPE_ARRAY || - map_infos[i].key_size != sizeof(__u32) || - map_infos[i].value_size != sizeof(__u64) || - map_infos[i].max_entries != 1 || - map_infos[i].map_flags != 0 || - info_len != sizeof(struct bpf_map_info) || - strcmp((char *)map_infos[i].name, expected_map_name), - "get-map-info(fd)", - "err %d errno %d type %d(%d) info_len %u(%zu) key_size %u value_size %u max_entries %u map_flags %X name %s(%s)\n", - err, errno, - map_infos[i].type, BPF_MAP_TYPE_ARRAY, - info_len, sizeof(struct bpf_map_info), - map_infos[i].key_size, - map_infos[i].value_size, - map_infos[i].max_entries, - map_infos[i].map_flags, - map_infos[i].name, expected_map_name)) + if (!ASSERT_OK(err, "bpf_map_get_info_by_fd") || + !ASSERT_EQ(map_infos[i].type, BPF_MAP_TYPE_ARRAY, "map_type") || + !ASSERT_EQ(map_infos[i].key_size, sizeof(__u32), "key_size") || + !ASSERT_EQ(map_infos[i].value_size, sizeof(__u64), "value_size") || + !ASSERT_EQ(map_infos[i].max_entries, 1, "max_entries") || + !ASSERT_EQ(map_infos[i].map_flags, 0, "map_flags") || + !ASSERT_EQ(info_len, sizeof(struct bpf_map_info), "map_info_len") || + !ASSERT_STREQ((char *)map_infos[i].name, expected_map_name, "map_name")) goto done; /* Check getting prog info */ @@ -112,48 +103,34 @@ void serial_test_bpf_obj_id(void) prog_infos[i].xlated_prog_len = sizeof(xlated_insns); prog_infos[i].map_ids = ptr_to_u64(map_ids + i); prog_infos[i].nr_map_ids = 2; + err = clock_gettime(CLOCK_REALTIME, &real_time_ts); - if (CHECK_FAIL(err)) + if (!ASSERT_OK(err, "clock_gettime")) goto done; + err = clock_gettime(CLOCK_BOOTTIME, &boot_time_ts); - if (CHECK_FAIL(err)) + if (!ASSERT_OK(err, "clock_gettime")) goto done; + err = bpf_prog_get_info_by_fd(prog_fds[i], &prog_infos[i], &info_len); load_time = (real_time_ts.tv_sec - boot_time_ts.tv_sec) + (prog_infos[i].load_time / nsec_per_sec); - if (CHECK(err || - prog_infos[i].type != BPF_PROG_TYPE_RAW_TRACEPOINT || - info_len != sizeof(struct bpf_prog_info) || - (env.jit_enabled && !prog_infos[i].jited_prog_len) || - (env.jit_enabled && - !memcmp(jited_insns, zeros, sizeof(zeros))) || - !prog_infos[i].xlated_prog_len || - !memcmp(xlated_insns, zeros, sizeof(zeros)) || - load_time < now - 60 || load_time > now + 60 || - prog_infos[i].created_by_uid != my_uid || - prog_infos[i].nr_map_ids != 1 || - *(int *)(long)prog_infos[i].map_ids != map_infos[i].id || - strcmp((char *)prog_infos[i].name, expected_prog_name), - "get-prog-info(fd)", - "err %d errno %d i %d type %d(%d) info_len %u(%zu) " - "jit_enabled %d jited_prog_len %u xlated_prog_len %u " - "jited_prog %d xlated_prog %d load_time %lu(%lu) " - "uid %u(%u) nr_map_ids %u(%u) map_id %u(%u) " - "name %s(%s)\n", - err, errno, i, - prog_infos[i].type, BPF_PROG_TYPE_SOCKET_FILTER, - info_len, sizeof(struct bpf_prog_info), - env.jit_enabled, - prog_infos[i].jited_prog_len, - prog_infos[i].xlated_prog_len, - !!memcmp(jited_insns, zeros, sizeof(zeros)), - !!memcmp(xlated_insns, zeros, sizeof(zeros)), - load_time, now, - prog_infos[i].created_by_uid, my_uid, - prog_infos[i].nr_map_ids, 1, - *(int *)(long)prog_infos[i].map_ids, map_infos[i].id, - prog_infos[i].name, expected_prog_name)) + + if (!ASSERT_OK(err, "bpf_prog_get_info_by_fd") || + !ASSERT_EQ(prog_infos[i].type, BPF_PROG_TYPE_RAW_TRACEPOINT, "prog_type") || + !ASSERT_EQ(info_len, sizeof(struct bpf_prog_info), "prog_info_len") || + !ASSERT_FALSE((env.jit_enabled && !prog_infos[i].jited_prog_len), "jited_prog_len") || + !ASSERT_FALSE((env.jit_enabled && !memcmp(jited_insns, zeros, sizeof(zeros))), + "jited_insns") || + !ASSERT_NEQ(prog_infos[i].xlated_prog_len, 0, "xlated_prog_len") || + !ASSERT_NEQ(memcmp(xlated_insns, zeros, sizeof(zeros)), 0, "xlated_insns") || + !ASSERT_GE(load_time, (now - 60), "load_time") || + !ASSERT_LE(load_time, (now + 60), "load_time") || + !ASSERT_EQ(prog_infos[i].created_by_uid, my_uid, "created_by_uid") || + !ASSERT_EQ(prog_infos[i].nr_map_ids, 1, "nr_map_ids") || + !ASSERT_EQ(*(int *)(long)prog_infos[i].map_ids, map_infos[i].id, "map_ids") || + !ASSERT_STREQ((char *)prog_infos[i].name, expected_prog_name, "prog_name")) goto done; /* Check getting link info */ @@ -163,25 +140,12 @@ void serial_test_bpf_obj_id(void) link_infos[i].raw_tracepoint.tp_name_len = sizeof(tp_name); err = bpf_link_get_info_by_fd(bpf_link__fd(links[i]), &link_infos[i], &info_len); - if (CHECK(err || - link_infos[i].type != BPF_LINK_TYPE_RAW_TRACEPOINT || - link_infos[i].prog_id != prog_infos[i].id || - link_infos[i].raw_tracepoint.tp_name != ptr_to_u64(&tp_name) || - strcmp(u64_to_ptr(link_infos[i].raw_tracepoint.tp_name), - "sys_enter") || - info_len != sizeof(struct bpf_link_info), - "get-link-info(fd)", - "err %d errno %d info_len %u(%zu) type %d(%d) id %d " - "prog_id %d (%d) tp_name %s(%s)\n", - err, errno, - info_len, sizeof(struct bpf_link_info), - link_infos[i].type, BPF_LINK_TYPE_RAW_TRACEPOINT, - link_infos[i].id, - link_infos[i].prog_id, prog_infos[i].id, - (const char *)u64_to_ptr(link_infos[i].raw_tracepoint.tp_name), - "sys_enter")) + if (!ASSERT_OK(err, "bpf_link_get_info_by_fd") || + !ASSERT_EQ(link_infos[i].type, BPF_LINK_TYPE_RAW_TRACEPOINT, "link_type") || + !ASSERT_EQ(link_infos[i].prog_id, prog_infos[i].id, "prog_id") || + !ASSERT_EQ(link_infos[i].raw_tracepoint.tp_name, ptr_to_u64(&tp_name), "&tp_name") || + !ASSERT_STREQ(u64_to_ptr(link_infos[i].raw_tracepoint.tp_name), "sys_enter", "tp_name")) goto done; - } /* Check bpf_prog_get_next_id() */ @@ -190,7 +154,7 @@ void serial_test_bpf_obj_id(void) while (!bpf_prog_get_next_id(next_id, &next_id)) { struct bpf_prog_info prog_info = {}; __u32 saved_map_id; - int prog_fd; + int prog_fd, cmp_res; info_len = sizeof(prog_info); @@ -198,9 +162,7 @@ void serial_test_bpf_obj_id(void) if (prog_fd < 0 && errno == ENOENT) /* The bpf_prog is in the dead row */ continue; - if (CHECK(prog_fd < 0, "get-prog-fd(next_id)", - "prog_fd %d next_id %d errno %d\n", - prog_fd, next_id, errno)) + if (!ASSERT_GE(prog_fd, 0, "bpf_prog_get_fd_by_id")) break; for (i = 0; i < nr_iters; i++) @@ -218,9 +180,8 @@ void serial_test_bpf_obj_id(void) */ prog_info.nr_map_ids = 1; err = bpf_prog_get_info_by_fd(prog_fd, &prog_info, &info_len); - if (CHECK(!err || errno != EFAULT, - "get-prog-fd-bad-nr-map-ids", "err %d errno %d(%d)", - err, errno, EFAULT)) + if (!ASSERT_ERR(err, "bpf_prog_get_info_by_fd") || + !ASSERT_EQ(errno, EFAULT, "bpf_prog_get_info_by_fd")) break; bzero(&prog_info, sizeof(prog_info)); info_len = sizeof(prog_info); @@ -231,27 +192,22 @@ void serial_test_bpf_obj_id(void) err = bpf_prog_get_info_by_fd(prog_fd, &prog_info, &info_len); prog_infos[i].jited_prog_insns = 0; prog_infos[i].xlated_prog_insns = 0; - CHECK(err || info_len != sizeof(struct bpf_prog_info) || - memcmp(&prog_info, &prog_infos[i], info_len) || - *(int *)(long)prog_info.map_ids != saved_map_id, - "get-prog-info(next_id->fd)", - "err %d errno %d info_len %u(%zu) memcmp %d map_id %u(%u)\n", - err, errno, info_len, sizeof(struct bpf_prog_info), - memcmp(&prog_info, &prog_infos[i], info_len), - *(int *)(long)prog_info.map_ids, saved_map_id); + cmp_res = memcmp(&prog_info, &prog_infos[i], info_len); + + ASSERT_OK(err, "bpf_prog_get_info_by_fd"); + ASSERT_EQ(info_len, sizeof(struct bpf_prog_info), "prog_info_len"); + ASSERT_OK(cmp_res, "memcmp"); + ASSERT_EQ(*(int *)(long)prog_info.map_ids, saved_map_id, "map_id"); close(prog_fd); } - CHECK(nr_id_found != nr_iters, - "check total prog id found by get_next_id", - "nr_id_found %u(%u)\n", - nr_id_found, nr_iters); + ASSERT_EQ(nr_id_found, nr_iters, "prog_nr_id_found"); /* Check bpf_map_get_next_id() */ nr_id_found = 0; next_id = 0; while (!bpf_map_get_next_id(next_id, &next_id)) { struct bpf_map_info map_info = {}; - int map_fd; + int map_fd, cmp_res; info_len = sizeof(map_info); @@ -259,9 +215,7 @@ void serial_test_bpf_obj_id(void) if (map_fd < 0 && errno == ENOENT) /* The bpf_map is in the dead row */ continue; - if (CHECK(map_fd < 0, "get-map-fd(next_id)", - "map_fd %d next_id %u errno %d\n", - map_fd, next_id, errno)) + if (!ASSERT_GE(map_fd, 0, "bpf_map_get_fd_by_id")) break; for (i = 0; i < nr_iters; i++) @@ -274,25 +228,19 @@ void serial_test_bpf_obj_id(void) nr_id_found++; err = bpf_map_lookup_elem(map_fd, &array_key, &array_value); - if (CHECK_FAIL(err)) + if (!ASSERT_OK(err, "bpf_map_lookup_elem")) goto done; err = bpf_map_get_info_by_fd(map_fd, &map_info, &info_len); - CHECK(err || info_len != sizeof(struct bpf_map_info) || - memcmp(&map_info, &map_infos[i], info_len) || - array_value != array_magic_value, - "check get-map-info(next_id->fd)", - "err %d errno %d info_len %u(%zu) memcmp %d array_value %llu(%llu)\n", - err, errno, info_len, sizeof(struct bpf_map_info), - memcmp(&map_info, &map_infos[i], info_len), - array_value, array_magic_value); + cmp_res = memcmp(&map_info, &map_infos[i], info_len); + ASSERT_OK(err, "bpf_map_get_info_by_fd"); + ASSERT_EQ(info_len, sizeof(struct bpf_map_info), "info_len"); + ASSERT_OK(cmp_res, "memcmp"); + ASSERT_EQ(array_value, array_magic_value, "array_value"); close(map_fd); } - CHECK(nr_id_found != nr_iters, - "check total map id found by get_next_id", - "nr_id_found %u(%u)\n", - nr_id_found, nr_iters); + ASSERT_EQ(nr_id_found, nr_iters, "map_nr_id_found"); /* Check bpf_link_get_next_id() */ nr_id_found = 0; @@ -308,9 +256,7 @@ void serial_test_bpf_obj_id(void) if (link_fd < 0 && errno == ENOENT) /* The bpf_link is in the dead row */ continue; - if (CHECK(link_fd < 0, "get-link-fd(next_id)", - "link_fd %d next_id %u errno %d\n", - link_fd, next_id, errno)) + if (!ASSERT_GE(link_fd, 0, "bpf_link_get_fd_by_id")) break; for (i = 0; i < nr_iters; i++) @@ -325,17 +271,13 @@ void serial_test_bpf_obj_id(void) err = bpf_link_get_info_by_fd(link_fd, &link_info, &info_len); cmp_res = memcmp(&link_info, &link_infos[i], offsetof(struct bpf_link_info, raw_tracepoint)); - CHECK(err || info_len != sizeof(link_info) || cmp_res, - "check get-link-info(next_id->fd)", - "err %d errno %d info_len %u(%zu) memcmp %d\n", - err, errno, info_len, sizeof(struct bpf_link_info), - cmp_res); + ASSERT_OK(err, "bpf_link_get_info_by_fd"); + ASSERT_EQ(info_len, sizeof(link_info), "info_len"); + ASSERT_OK(cmp_res, "memcmp"); close(link_fd); } - CHECK(nr_id_found != nr_iters, - "check total link id found by get_next_id", - "nr_id_found %u(%u)\n", nr_id_found, nr_iters); + ASSERT_EQ(nr_id_found, nr_iters, "link_nr_id_found"); done: for (i = 0; i < nr_iters; i++) { From patchwork Sat Nov 18 18:47:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuran Pereira X-Patchwork-Id: 745079 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=hotmail.com header.i=@hotmail.com header.b="o+J4Q9A3" Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05olkn2071.outbound.protection.outlook.com [40.92.91.71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E6C1B7; Sat, 18 Nov 2023 10:48:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GvdMaQGm8/Q7uUaRkuFFvj9dWfqyxbMwhqnZqiHuJ8ytC8VAKNShlUMhX3olcUv2BuwPrMgV/F5P6zzcDRqBkktS3Bd4wsIlv5qL96h4Peml37r/ig3To4Fll5dp+jQ2Tt8Mn/N39k+ss8sw1KQ88wcN2/xoZv/FQ7wl+l5ZEugvvpi6Gat/Z63Pxuk7802lutAj43n0wx7oeX42NgmX+RNx35PuRX+gWSSc3inxp8Iwuf22Nc/3NlUPvBumKRcnfm6fu5FkcvAyvCNxLzq06nxPMPNvS7eYbgGdNrj9N03Oxe9Sx7se+fivwA2kEHNlyvT/DnlNORYCEzkfjAvMTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=SEV6FSvKBUg1qgQLg6TT1AC2iHwQLooeot5R9UOQzCQ=; b=BGnyt1Mn9M/mfFfnYVIXducEnji2rcjtq+ojOWA90AiS7MhvR7KHbFdO/hJNoVCk5Lbj7ypUy6FmkWdYNVcgP7gRO7RK6xtoY9ezeSho0PHacNa13dnZSkOuVFLEXhDzKfvi36pGo0wB0VzOLDXk0+n6L+i1FfuF/m1ipgiCzyisQ4s1i3RfK6294IRwICZQjTpTGkxmreAaFJqTAFBVK87aqvfqdn+NbLqb9HBI5KWq4mCUIuYHBaJarbN3kjrk4ZYPcBnPI8oDjWEPswCtjBvNoxmcJj0zsw1yii4+YWVZNCar4wIvzOMC3YcQaWDsLM3RfLbSkyw2CS1STkeP9Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hotmail.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=SEV6FSvKBUg1qgQLg6TT1AC2iHwQLooeot5R9UOQzCQ=; b=o+J4Q9A3Ae+1x88XvQR5kDf40CSKA+ZUsvB3TWrt4umMzhU2S05GToomGVADTF2EJbVwv7LBmNZOS08X5y7H19vZ2ZtcZ1TGD6jv2e0Qd2kv3qRcKuZcZ55hq5jWhopPoLGR8R4WehrLFn2thBEMHxs5HoV0w8U+4O+Ni/k96+Scqf10CSKnkgZ/yJVjULSijXsrhovVF/tZ+fg5pKp4lbenqNQ1WCbheUIYhNjZEOWmVfagCZrG4fP7kR8sa+vz8pHWqLTxglrBtw8ljKLQUfJN9sdHYfYLI06Lz5ps5sCm75M5evPaV/nLYDPeqG44rdK3crziGA8kpoj4rAFUpg== Received: from GV1PR10MB6563.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:150:83::20) by AS1PR10MB7936.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:471::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7002.26; Sat, 18 Nov 2023 18:48:27 +0000 Received: from GV1PR10MB6563.EURPRD10.PROD.OUTLOOK.COM ([fe80::6c45:bfdf:a384:5450]) by GV1PR10MB6563.EURPRD10.PROD.OUTLOOK.COM ([fe80::6c45:bfdf:a384:5450%7]) with mapi id 15.20.7002.025; Sat, 18 Nov 2023 18:48:27 +0000 From: Yuran Pereira To: bpf@vger.kernel.org Cc: Yuran Pereira , andrii@kernel.org, andrii.nakryiko@gmail.com, mykolal@fb.com, ast@kernel.org, martin.lau@linux.dev, song@kernel.org, yonghong.song@linux.dev, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, shuah@kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kernel-mentees@lists.linuxfoundation.org Subject: [PATCH bpf-next v2 4/4] selftests/bpf: Replaces the usage of CHECK calls for ASSERTs in vmlinux Date: Sun, 19 Nov 2023 00:17:57 +0530 Message-ID: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: X-TMN: [/8NAesCYMHq/Ig6o3N/ES7xBrt69hz/u] X-ClientProxiedBy: JNAP275CA0021.ZAFP275.PROD.OUTLOOK.COM (2603:1086:0:4d::12) To GV1PR10MB6563.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:150:83::20) X-Microsoft-Original-Message-ID: <20231118184757.231739-1-yuran.pereira@hotmail.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: GV1PR10MB6563:EE_|AS1PR10MB7936:EE_ X-MS-Office365-Filtering-Correlation-Id: 3b09d681-79e5-4a25-135f-08dbe866f32c X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: hfHZTdVuTc/mnt90k23lNrpY+GvXYa6AOxAED39gUgCVuK4mkZ92CdwMmClk3TZ2is2K58n2txuan7g/LU3zsoMyiGriyF5HU9CbFh0nFwfHsRtYVuF0q56/ZyFSIuaMS7Wk4x3tRifw6HRh7HPv1jiWI3snjRv3+s8eBperjlUoqcw8wjxXduVpZ49k22wS2SQc+44O/HfEV8ZtXfFh48grSamNwTKiyhs/00BdXLTUIhKDY1igmiA1b1/Qxr0THIQ7Qt2MJLglKlf7W9Cl/NqEpigop3n7noAHzciiC7PDPmMFC9ytyaMKeJLTJubM00UOCEGsm5Zw6zXr3Uky4mgaY5LoUw1c2ZKU0lCwFeGZ0kIjgLdN7ZdcAKIXJPVk9wkQxCwBuJkHdInzC7D8GPb4vLq0d3dSRTnlpsOuD1AccCiumhmoETj/T8/Nqg1Cc31BXHBTTSeJRvKSkFEu7Eyk6ujEK80A2xf4KQmQbjeeUW9Atf96t0NeXjYadCooHcjx6+edVTnYYS76iFRaWw0UBhOFtfgxwfyWZMnvNyIOo77rv62Oevlf2LnYn6J+Wtl88K4CXtalGo2ioFCpKXWJDnNunAHevG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qs/wVGSlEKHVAe8T1qliXa8aNvEYGKDRZguDHqfUalBiPjd1jxSTtq2bxrZta/lbitd8yHwZI6z8KF1OEMPPVkAw+SLgFTmTa1Apr9o2iZVjwBFiYSUerQbmeLlLQPri75doah7b71pf2UqW3KoQiQuUD2iEcN/bCoGxC3pzWAwCWU5eLrtQzjNxqd2efJJ4bZ4SnIQcg1nJVgR5wv5arG/09Hfr/sOoou1Jfdsvz5/vPaFJk= X-OriginatorOrg: sct-15-20-4755-11-msonline-outlook-6b909.templateTenant X-MS-Exchange-CrossTenant-Network-Message-Id: 3b09d681-79e5-4a25-135f-08dbe866f32c X-MS-Exchange-CrossTenant-AuthSource: GV1PR10MB6563.EURPRD10.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Nov 2023 18:48:27.1860 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS1PR10MB7936 vmlinux.c uses the `CHECK` calls even though the use of ASSERT_ series of macros is preferred in the bpf selftests. This patch replaces all `CHECK` calls for equivalent `ASSERT_` macro calls. Signed-off-by: Yuran Pereira Acked-by: Yonghong Song --- tools/testing/selftests/bpf/prog_tests/vmlinux.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/vmlinux.c b/tools/testing/selftests/bpf/prog_tests/vmlinux.c index 72310cfc6474..6fb2217d940b 100644 --- a/tools/testing/selftests/bpf/prog_tests/vmlinux.c +++ b/tools/testing/selftests/bpf/prog_tests/vmlinux.c @@ -16,27 +16,27 @@ static void nsleep() void test_vmlinux(void) { - int duration = 0, err; + int err; struct test_vmlinux* skel; struct test_vmlinux__bss *bss; skel = test_vmlinux__open_and_load(); - if (CHECK(!skel, "skel_open", "failed to open skeleton\n")) + if (!ASSERT_OK_PTR(skel, "test_vmlinux__open_and_load")) return; bss = skel->bss; err = test_vmlinux__attach(skel); - if (CHECK(err, "skel_attach", "skeleton attach failed: %d\n", err)) + if (!ASSERT_OK(err, "test_vmlinux__attach")) goto cleanup; /* trigger everything */ nsleep(); - CHECK(!bss->tp_called, "tp", "not called\n"); - CHECK(!bss->raw_tp_called, "raw_tp", "not called\n"); - CHECK(!bss->tp_btf_called, "tp_btf", "not called\n"); - CHECK(!bss->kprobe_called, "kprobe", "not called\n"); - CHECK(!bss->fentry_called, "fentry", "not called\n"); + ASSERT_TRUE(bss->tp_called, "tp"); + ASSERT_TRUE(bss->raw_tp_called, "raw_tp"); + ASSERT_TRUE(bss->tp_btf_called, "tp_btf"); + ASSERT_TRUE(bss->kprobe_called, "kprobe"); + ASSERT_TRUE(bss->fentry_called, "fentry"); cleanup: test_vmlinux__destroy(skel);