Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i9ivl-0003XH-57 for pgsql-committers@arkaria.postgresql.org; Mon, 16 Sep 2019 04:48:05 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1i9ivj-0006H2-7P for pgsql-committers@arkaria.postgresql.org; Mon, 16 Sep 2019 04:48:03 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i9ivi-0006Gn-3L for pgsql-committers@lists.postgresql.org; Mon, 16 Sep 2019 04:48:02 +0000 Received: from out3-smtp.messagingengine.com ([66.111.4.27]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1i9ivb-0006eZ-1d for pgsql-committers@lists.postgresql.org; Mon, 16 Sep 2019 04:48:00 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 3692B22027; Mon, 16 Sep 2019 00:47:54 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Mon, 16 Sep 2019 00:47:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= date:from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm2; bh=JEie8DrNLKoQerGjxgoqA3+iBiX SMp8uqrclK7NEqVo=; b=FwBmLNTXaJ99fDwD14rUozTlrpAw80tSBYbkYVBMRDQ 74Wa6+fMJqnkfKXiqVZPjX6uLgtba6v0+Wky1Enu4f34B/rpyxLZ4A6Jxej3sfCX bApQfqLknVbDckk0UHAql645gaMWhZe/icsd9UR2FR02Cd9d+Hwp49z3V6yT78x5 p7RYwBUjw1bDHx30BQphK2CzbKguevuBBpv1wfYOEZl/ZcI7Ng7Xqnt/54szqyIG 8H+v+6npwjGt9bJyhzprTZ5FvgpK04rmcnUk7zyVMB2kQPE6aBi209J42Sw0z96V 9Dvz0PBdP6Wl6HCftUToz6JyOD5wpzNo/JoHdIu1D4Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=JEie8D rNLKoQerGjxgoqA3+iBiXSMp8uqrclK7NEqVo=; b=doknlH6hnMdQ503aAcF5F1 QiOfgE3G6zF25hdtMMUlqA7MSICIAPiQkJGVkEY8ZEDjeRMrOdBnDpgL7NAatHF+ ZAL+gTQQ+Bd9IiA9t+lRONJborLN3nvISHxBlw8rBWc5R/CMhDzXrzBCvNxtowzR /S1x18fSiPyw9cUxVJ5y2EcPKeWBGzuG+p3Qkl43ivyGAiq4/DyfnB7hq0DmL4EI Ct7f8O/6R3DMmuD5FPs9RGvt4rjSSQ8ui8e1KVAAxQnOoAWTRthAqxWX7umYS1yg X1kY2Vr1H3joRfxDgJMiHd/PWPKTwXk0QvoBXaqceinfgW6MfcGXaoC/3GWNZuZQ == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedruddvgdekkecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvuffkfhggtggujgesthdtredttddtvdenucfhrhhomheptehnughrvghs ucfhrhgvuhhnugcuoegrnhgurhgvshesrghnrghrrgiivghlrdguvgeqnecukfhppeeije drudeitddrvddukedrvdefjeenucfrrghrrghmpehmrghilhhfrhhomheprghnughrvghs segrnhgrrhgriigvlhdruggvnecuvehluhhsthgvrhfuihiivgeptd X-ME-Proxy: Received: from intern.anarazel.de (c-67-160-218-237.hsd1.ca.comcast.net [67.160.218.237]) by mail.messagingengine.com (Postfix) with ESMTPA id 515E980062; Mon, 16 Sep 2019 00:47:53 -0400 (EDT) Date: Sun, 15 Sep 2019 21:47:52 -0700 From: Andres Freund To: Noah Misch Cc: Alvaro Herrera , pgsql-committers@lists.postgresql.org Subject: Re: pgsql: Test pg_atomic_fetch_add_ with variable addend and 16-bit edge c Message-ID: <20190916044752.s5ajrua52tx5u2rt@alap3.anarazel.de> References: <20190915160021.GA24376@alvherre.pgsql> <20190915221450.GA3500204@rfd.leadboat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190915221450.GA3500204@rfd.leadboat.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi, On 2019-09-15 15:14:50 -0700, Noah Misch wrote: > On Sun, Sep 15, 2019 at 01:00:21PM -0300, Alvaro Herrera wrote: > > On 2019-Sep-14, Noah Misch wrote: > > > Test pg_atomic_fetch_add_ with variable addend and 16-bit edge cases. > > > > I don't understand this. > > > > if (pg_atomic_fetch_add_u32(&var, INT_MAX) != INT_MAX) > > elog(ERROR, "pg_atomic_add_fetch_u32() #3 wrong"); > > > > pg_atomic_fetch_add_u32(&var, 2); /* wrap to 0 */ > > > > if (pg_atomic_fetch_add_u32(&var, PG_INT16_MAX) != 0) > > elog(ERROR, "pg_atomic_fetch_add_u32() #3 wrong"); > > > > The existing one seems to be naming the wrong function in the error > > message, and if you fix that then you have two "#3 wrong" cases. > > Isn't this confusing? Am I just too sensitive? Is this pointless to > > fix? > > It's a typo-class defect. Would you like me to fix it, or would you like to > fix it? I'd consider wrapping the tests in a macro (may be overkill, since > these tests don't change much): > > --- a/src/test/regress/regress.c > +++ b/src/test/regress/regress.c > @@ -670,6 +670,16 @@ test_atomic_flag(void) > pg_atomic_clear_flag(&flag); > } > > +#define EXPECT(result_expr, expected_expr) \ > + do { \ > + uint32 result = (result_expr); \ > + uint32 expected = (expected_expr); \ > + if (result != expected) \ > + elog(ERROR, \ > + "%s yielded %u, expected %s in file \"%s\" line %u", \ > + #result_expr, result, #expected_expr, __FILE__, __LINE__); \ > + } while (0) > + While it might be overkill on its own, it seems like it'd be a good utility to have for these kinds of tests. Unfortunately we can't easily make this type independent. The local variables are needed to avoid multiple evaluation. While we could infer their type using compiler specific magic (__typeof__() or C++), we'd still need to print them. We could however remove the local variables, and purely rely on stringification of the arguments for printing the error. > static void > test_atomic_uint32(void) > { > @@ -678,17 +688,10 @@ test_atomic_uint32(void) > int i; > > pg_atomic_init_u32(&var, 0); > - > - if (pg_atomic_read_u32(&var) != 0) > - elog(ERROR, "atomic_read_u32() #1 wrong"); > - > + EXPECT(pg_atomic_read_u32(&var), 0); > pg_atomic_write_u32(&var, 3); > - > - if (pg_atomic_read_u32(&var) != 3) > - elog(ERROR, "atomic_read_u32() #2 wrong"); > - > - if (pg_atomic_fetch_add_u32(&var, pg_atomic_read_u32(&var) - 2) != 3) > - elog(ERROR, "atomic_fetch_add_u32() #1 wrong"); > + EXPECT(pg_atomic_read_u32(&var), 3); > + EXPECT(pg_atomic_fetch_add_u32(&var, pg_atomic_read_u32(&var) - 2), 3); > > if (pg_atomic_fetch_sub_u32(&var, 1) != 4) > elog(ERROR, "atomic_fetch_sub_u32() #1 wrong"); I'd name it EXPECT_EQ_U32 or such, but otherwise I think this is a clear improvement. Greetings, Andres Freund