Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp2338968imn; Mon, 1 Aug 2022 21:53:19 -0700 (PDT) X-Google-Smtp-Source: AA6agR6vl4KCd9jykeZBAVzv7gMSylrcb6QXd6Q4s3q5k3QJeZkN6MKJvZHICuBOn5KPcYVsPPf+ X-Received: by 2002:a17:902:cf09:b0:16d:6a06:f994 with SMTP id i9-20020a170902cf0900b0016d6a06f994mr19462889plg.62.1659415999045; Mon, 01 Aug 2022 21:53:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659415999; cv=none; d=google.com; s=arc-20160816; b=eXpx6IwN6M4LRaOUVqZ3dZbRPYp3Jz/1QuAUMvwSPBKXZqMqc53HT3InyQdUDGoVxW 4QqVrMAGjIoVGHuLbVoEmitw4e6mKg+U30W0ZlWEdp/wJt3VaHYWdoJrC3n467yWACIV Grjr/U0QbzBHEBPSrizYX1bRLG5BgqNFoSV4eL+n373VbqRYs/Y/aibDT0NbUcIZAx5l d2NVMpsI9NIWlpBbtXeLhGFNM9w05F0bJJ+sCVMAMEBYheu+mOgSuLfPj/8H/jVXfQ9e qMxWy4GOofIDdU669PfLzcVRL7p5MxBLM7f3Zv6uUquPk4vjW6OWLVsiJ9tqc929pV46 8mwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=UocwHfpqhdsaKRBjXUO3oWoo5VgvByxIYhhk++TJzww=; b=OCUwpz8h+WDfnMyoeDab2QWlRewh3uXiJWIEQBzK9r+VQjlKakSRhEJci/1UB1ZAtO CkOgGHc9y9xJ150yH7jpAw5JpDZD3MRf0BpUv7bTnIXOsJnCVPWy2dYjxQSuztxzzeHP 0t2g1DbbOZx+0JhMvK6+H82/E8NXd6JKBWhu42rOMffdomLGz6HiPUukjK74OQCuiIj+ 3KYTTHFuVfhvtreujj2Q//lGQ2hGl80LvSxCFpwYDC82XdubkT7t8IxBwEMgLs6cEIjd nembpf+1996QbzB2Me0kV9xIXtjvKmLKU7cF43edvbTWB1jBO79mr3MiVJw99VDZ2S5j q+sQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=jx4n8eOO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l20-20020a635714000000b004113ecaadaesi15284663pgb.753.2022.08.01.21.53.04; Mon, 01 Aug 2022 21:53:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=jx4n8eOO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233116AbiHBEJm (ORCPT + 99 others); Tue, 2 Aug 2022 00:09:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229455AbiHBEJj (ORCPT ); Tue, 2 Aug 2022 00:09:39 -0400 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8611A1B7B0; Mon, 1 Aug 2022 21:09:38 -0700 (PDT) Received: by mail-ej1-x62f.google.com with SMTP id i14so5096991ejg.6; Mon, 01 Aug 2022 21:09:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc; bh=UocwHfpqhdsaKRBjXUO3oWoo5VgvByxIYhhk++TJzww=; b=jx4n8eOOxofhaSZH8qAE8+C6TnYGtkoSskRxtdK6cpEuJs3B2/r/mtS+LfGdb607Z+ Pt706y5owNULu/vT+bzuxlMpb2iAnCL2E0Y5Wi5ngS2662xLzjr/k72ssPZBwg7ee0M/ zepD+iNbd8FUgpsRoAHdZUDWBWHTxN/pdEOFPX5Uha6kIcv96xO8u3cQvd4100gd9i1E O8ysJtP8T++KWGFyqQ68Xvs7n5ypjil/P8MXrTBcSLTJBBoeAg7ayjvnfyNgCh3r8xV8 3LnE2hkBGhoIu41apN04xmyBhTNU+cphPbdgr5N+UbDCDF2MJhvMjx495VwSEh1m0AKL FxUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc; bh=UocwHfpqhdsaKRBjXUO3oWoo5VgvByxIYhhk++TJzww=; b=dmgK/cuh/Jx8iy0LSFNBUkx61D/OU3Z8GHxNI+V4k+ffZzsZZtE8JRFMINFb9fzvu6 n17oVL/EIcduB1HYUWwQtZa320Z2OBr/CLqEhWJp1gjTVGjdD0m3Ml9Wpm06JuW1zrbx KJuTpSeyMakvEgIl4boHLJXcoD8FMUuXJsi4yDK/TVBYW2AUNQSkmJueEPzX714FgAto 2vzw4pyAoSyln6vvJIGAAeuI2NhE1W6wR8adguNrKVtVYWAsES/K3WYCMXsIO+S+Ev3c FUQy/Ix6VrmHyzmsVyYSFtJijtl5iEpAp9F7R1ttppnlkarD0qrlBfhhKqrmrIDRwyVY tP5g== X-Gm-Message-State: AJIora+MHXkvGH5o5N9qKlP8KcfzTjmQCkx/J4VF8NKZ6O/tM0a0RpSA e/TKeOTX7kbG1Jq/cfUi/NMOEtW1KdxZOF/4rb88BzAG8ZQ= X-Received: by 2002:a17:907:2ccc:b0:72b:6907:fce6 with SMTP id hg12-20020a1709072ccc00b0072b6907fce6mr15019557ejc.115.1659413377003; Mon, 01 Aug 2022 21:09:37 -0700 (PDT) MIME-Version: 1.0 References: <20220801175407.2647869-1-haoluo@google.com> <20220801175407.2647869-6-haoluo@google.com> In-Reply-To: From: Andrii Nakryiko Date: Mon, 1 Aug 2022 21:09:25 -0700 Message-ID: Subject: Re: [PATCH bpf-next v6 5/8] selftests/bpf: Test cgroup_iter. To: Hao Luo Cc: linux-kernel@vger.kernel.org, bpf@vger.kernel.org, cgroups@vger.kernel.org, netdev@vger.kernel.org, Alexei Starovoitov , Andrii Nakryiko , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , Tejun Heo , Zefan Li , KP Singh , Johannes Weiner , Michal Hocko , Benjamin Tissoires , John Fastabend , Michal Koutny , Roman Gushchin , David Rientjes , Stanislav Fomichev , Shakeel Butt , Yosry Ahmed Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 1, 2022 at 3:55 PM Hao Luo wrote: > > On Mon, Aug 1, 2022 at 2:51 PM Andrii Nakryiko > wrote: > > > > On Mon, Aug 1, 2022 at 10:54 AM Hao Luo wrote: > > > > > > Add a selftest for cgroup_iter. The selftest creates a mini cgroup tree > > > of the following structure: > > > > > > ROOT (working cgroup) > > > | > > > PARENT > > > / \ > > > CHILD1 CHILD2 > > > > > > and tests the following scenarios: > > > > > > - invalid cgroup fd. > > > - pre-order walk over descendants from PARENT. > > > - post-order walk over descendants from PARENT. > > > - walk of ancestors from PARENT. > > > - early termination. > > > > > > Acked-by: Yonghong Song > > > Signed-off-by: Hao Luo > > > --- > > > .../selftests/bpf/prog_tests/cgroup_iter.c | 193 ++++++++++++++++++ > > > tools/testing/selftests/bpf/progs/bpf_iter.h | 7 + > > > .../testing/selftests/bpf/progs/cgroup_iter.c | 39 ++++ > > > 3 files changed, 239 insertions(+) > > > create mode 100644 tools/testing/selftests/bpf/prog_tests/cgroup_iter.c > > > create mode 100644 tools/testing/selftests/bpf/progs/cgroup_iter.c > > > [...] > > > +#define format_expected_output3(cg_id1, cg_id2, cg_id3) \ > > > + snprintf(expected_output, sizeof(expected_output), \ > > > + PROLOGUE "%8llu\n%8llu\n%8llu\n" EPILOGUE, \ > > > + (cg_id1), (cg_id2), (cg_id3)) > > > + > > > > you use format_expected_output{1,2} just once and > > format_expected_output3 twice. Is it worth defining macros for that? > > > > If not, we'd see this snprintf and format all over the place. It looks > worse than the current one I think, prefer leave as-is. All over the place == 4 places where it matters. We are not trying to write the most beautiful code through macro obfuscation. The point is to write tests that are easy to follow, debug, understand, and potentially modify. Adding extra layers of macros goes against this. Instead of clearly seeing in each individual subtest that we expect "%llu\n%llu\n", I need to search what "format_expected_output3" is actually doing, then I'm wondering where expected_output is coming from (I scan macro input args, see nothing, then I conclude it must be coming from the environment; I jump to one of the format_expected_output3 invocation sites, see no local variable named "expected_output", then I look around and see global variable; aha, finally!) Sure it's a rather trivial thing, but this adds up. *Unnecessary* macros are bad and a hindrance. Please avoid them, if possible. Saving 20 characters is not a sufficient justification in my view. > > > > +const char *cg_path[] = { > > > + "/", "/parent", "/parent/child1", "/parent/child2" > > > +}; > > > + [...] > > > + link = bpf_program__attach_iter(skel->progs.cgroup_id_printer, &opts); > > > + if (!ASSERT_ERR_PTR(link, "attach_iter")) > > > + bpf_link__destroy(link); > > > > nit: you can call bpf_link__destroy() even if link is NULL or IS_ERR > > > > Ack. Still need to ASSERT on 'link' though, so the saving is probably > just an indentation. Anyway, will change. Yeah, of course you need to assert. But it's nice to have unconditional assertion. > > > > +} > > > + > > > > [...] > > [...]