Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp489125pxb; Thu, 26 Aug 2021 07:39:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwoZsyySyKgD5fx3asGlrnD30iyToKJadAAe6QmRcc3ZDd5qqhQgffcxjtUy9dKXfuVBeHv X-Received: by 2002:a17:906:bc89:: with SMTP id lv9mr716024ejb.110.1629988770316; Thu, 26 Aug 2021 07:39:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629988770; cv=none; d=google.com; s=arc-20160816; b=tM5MqQqYy1PYGtsFOCibgK5JEtfcFwfdOfgRymrnCthgHaBLqBF4I8CR9sEpT/QyYj bDzP/zwT85Nr1UP4zbr2DousMChNdAIcZkRqv+dxJ4EaLLgE3YtSFDJP3JoCBf1ZI7Os cjcn21uOWlxA7rCd5iAy8dbMch1PaRJ8U0ojD/lkkxJmb9G5cEYGk0KKwoIkwniNItCX o3WUqAifJCB9lyDUGNJrZpCQmB/q0mMNaXfcFSS1aKMyqQ61SUMjyA8LgkqdjGuwzCfV gozqkcfn/fGhKuUyPNv3tj4uawBOkwq9oy/6SWmZQ0UZVpiw+hRY1Pkujh2qJu5NDpF7 LhTg== 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=D0x7kG5inCAU4odH4Ca7hH6L2dymSyP8KvC1gg8txvI=; b=lky4EWG8rIqoJ41auCt7947gCpDwN1oNyfNtUbmWUDfEP7ndSwd19ft1i1/bmu7Z4/ gue9Alls0yz81BfiolgVMbnyWzpmdGpZQ9GCEBxAZKDXKGiXM0cVOqBiXtbRYP1YrmMz swkBbbMWwgSqSewXCvwvYTg2Uld6ufn+7trDxt52N6KbO+QSe7pxL+9aBv1Sd3F15TDx LHoQgCGIbcBSrJK31nZGCPFiwoIBO+Bvs8AEzoQDsEAkqPWyKCntZOqI6kDA4jOz/et+ /xdNw3IRG2W3++gWXJ7jC4BZaB3U7h01ZdBdcePR4pA6ydXtjcajyQ45VrJnx3OtMjZm yYMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="P0I9/WLM"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id di22si3340640edb.592.2021.08.26.07.38.56; Thu, 26 Aug 2021 07:39:30 -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=@google.com header.s=20161025 header.b="P0I9/WLM"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229832AbhHZOhe (ORCPT + 99 others); Thu, 26 Aug 2021 10:37:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231458AbhHZOhe (ORCPT ); Thu, 26 Aug 2021 10:37:34 -0400 Received: from mail-ot1-x32b.google.com (mail-ot1-x32b.google.com [IPv6:2607:f8b0:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F32D1C0613C1 for ; Thu, 26 Aug 2021 07:36:46 -0700 (PDT) Received: by mail-ot1-x32b.google.com with SMTP id k12-20020a056830150c00b0051abe7f680bso3779578otp.1 for ; Thu, 26 Aug 2021 07:36:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=D0x7kG5inCAU4odH4Ca7hH6L2dymSyP8KvC1gg8txvI=; b=P0I9/WLM2kllF2CsU1LJ1VGJOKg93R3WGspayrL/kOiIA6MkG9oqhNa47EwKWRGDH4 ahgUV0kHqxhhwVbAjWKODDViXGRiXBM5qexE1XTinlHlts6w3lvuOxblzuHXxib+V0zE PncJ6Z+0nepcixsaZQ9h0XemG/8fELyMs+gqs1dXMC2EI6fa6kbk5hdPZTCMaABedJtA LyBqYLuhs2P0moxsuej5Oj8V9O2gwHeUVhBZBrrG2lB4Ai/i/4yRb0KYjXIcxm5A2jgy lNg0KLQ5XDDhgeJeWQRKVMXru0Wz7MSIYBDTUO0Y4q28bDJDPNlDL2yQAuRGxhzHfeau 8XBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=D0x7kG5inCAU4odH4Ca7hH6L2dymSyP8KvC1gg8txvI=; b=MSCxUnCNndbLR2gSO75vuOf0MnB/j7cXiQUVumQ8Ja1a/QkP2pRXsIl8Iln/sGzayQ k2xGzj1E0tm2lCZeMrHCX/BmFLsVhEP9w59GPfv2CccY+Ha9ussYnmiQ7z6/7j8EWBiC gXKBwXv212pFg3II/RH6FYzVOndqXx9CbZoPoaT2HTTT9fAeYC2KwGsbESzGUqeFGqkw zN8hNC8ZMyW8PA4K+VwyB6JbZFZvDgmkZEeonM/uHsES/AfpVR7CoVOadcpC17Rs04Hp LpPq427J0yzbAwvVeiUtdKUmpeyuDihpTlyj6+9ovajcqK7CN8FGpnScmBIXg+iuLiyd iqjw== X-Gm-Message-State: AOAM533RSdSR9YicqzC/AtuXohvDLL5t5w4TQ+S2LHEo9MoockO5JGy0 mhAzPWRiyk2oRpgpdJL+xlLyhb7o24DGmTVbfhBWRQ== X-Received: by 2002:a05:6830:88:: with SMTP id a8mr3470082oto.233.1629988605961; Thu, 26 Aug 2021 07:36:45 -0700 (PDT) MIME-Version: 1.0 References: <20210826012626.1163705-1-isabellabdoamaral@usp.br> <20210826012626.1163705-3-isabellabdoamaral@usp.br> In-Reply-To: <20210826012626.1163705-3-isabellabdoamaral@usp.br> From: Marco Elver Date: Thu, 26 Aug 2021 16:36:34 +0200 Message-ID: Subject: Re: [PATCH 2/6] test_hash.c: move common definitions to top of file To: Isabella Basso Cc: linux@sciencehorizons.net, geert@linux-m68k.org, ferreiraenzoa@gmail.com, augusto.duraes33@gmail.com, brendanhiggins@google.com, dlatypov@google.com, davidgow@google.com, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, kunit-dev@googlegroups.com, ~lkcamp/patches@lists.sr.ht, rodrigosiqueiramelo@gmail.com Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 26 Aug 2021 at 03:26, 'Isabella Basso' via KUnit Development wrote: > Keep function signatures minimal by making common definitions static. > This does not change any behavior. This seems like an odd change; if I read it right it's changing the out-param passed to test_int_hash() to simply be static globals. For one, it makes the code harder to read because now test_int_hash() is no longer "pure" (no global side-effects ... modulo printfs), and what was previously an out-param, is now a global. Unfortunately this is poor style and likely to lead to hard-to-debug problems. One such problem is if suddenly you have multiple threads involved. While this is just a test and unlikely to be a problem, I would recommend not introducing global state carelessly. An alternative common idiom, where a set of variables are always passed around to other functions, is to introduce a struct and pass a pointer to it along. > Signed-off-by: Isabella Basso > --- > lib/test_hash.c | 13 ++++++++----- > 1 file changed, 8 insertions(+), 5 deletions(-) > > diff --git a/lib/test_hash.c b/lib/test_hash.c > index d4b0cfdb0377..8bcc645a7294 100644 > --- a/lib/test_hash.c > +++ b/lib/test_hash.c > @@ -23,6 +23,11 @@ > #include > #include > > +#define SIZE 256 /* Run time is cubic in SIZE */ > + > +static u32 string_or; /* stores or-ed string output */ > +static u32 hash_or[2][33] = { { 0, } }; /* stores or-ed hash output */ These now use up memory for as long as this module is loaded, vs. before where it would only use up stack space. (For a test that's not a problem, but in non-test code it might.) > /* 32-bit XORSHIFT generator. Seed must not be zero. */ > static u32 __init __attribute_const__ > xorshift(u32 seed) > @@ -66,7 +71,7 @@ fill_buf(char *buf, size_t len, u32 seed) > * recompile and re-test the module without rebooting. > */ > static bool __init > -test_int_hash(unsigned long long h64, u32 hash_or[2][33]) > +test_int_hash(unsigned long long h64) > { > int k; > u32 h0 = (u32)h64, h1, h2; > @@ -123,17 +128,15 @@ test_int_hash(unsigned long long h64, u32 hash_or[2][33]) > return true; > } > > -#define SIZE 256 /* Run time is cubic in SIZE */ > - > static int __init > test_hash_init(void) > { > char buf[SIZE+1]; > - u32 string_or = 0, hash_or[2][33] = { { 0, } }; > unsigned tests = 0; > unsigned long long h64 = 0; > int i, j; > > + string_or = 0; That's another problem with changes like this; now the compiler has no chance to warn you in case the variable is not initialized correctly. Also, I don't see string_or used anywhere else. Why make it global? If a later change would require that, it should say so in the commit message. But my guess is you can avoid all that by bundling everything up in a struct. > fill_buf(buf, SIZE, 1); > > /* Test every possible non-empty substring in the buffer. */ > @@ -161,7 +164,7 @@ test_hash_init(void) > > string_or |= h0; > h64 = h64 << 32 | h0; /* For use with hash_64 */ > - if (!test_int_hash(h64, hash_or)) > + if (!test_int_hash(h64)) > return -EINVAL; > tests++; > } /* i */ > -- > 2.33.0 > > -- > You received this message because you are subscribed to the Google Groups "KUnit Development" group. > To unsubscribe from this group and stop receiving emails from it, send an email to kunit-dev+unsubscribe@googlegroups.com. > To view this discussion on the web visit https://groups.google.com/d/msgid/kunit-dev/20210826012626.1163705-3-isabellabdoamaral%40usp.br.