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 1i9ctW-0003Py-8S for pgsql-committers@arkaria.postgresql.org; Sun, 15 Sep 2019 22:21:22 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1i9ctU-0000K5-TM for pgsql-committers@arkaria.postgresql.org; Sun, 15 Sep 2019 22:21:20 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i9ctU-0000Jf-E8 for pgsql-committers@lists.postgresql.org; Sun, 15 Sep 2019 22:21:20 +0000 Received: from mail-pl1-x641.google.com ([2607:f8b0:4864:20::641]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i9ctR-0000rK-Fs for pgsql-committers@lists.postgresql.org; Sun, 15 Sep 2019 22:21:19 +0000 Received: by mail-pl1-x641.google.com with SMTP id k1so15921960pls.11 for ; Sun, 15 Sep 2019 15:21:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=5nY8ZqSYHJAuSBSW4axDy4/NxzGCWtlFeNaPBEj3EnA=; b=SgdKK/83gUJhtivfqbVPmVtQXRcBLRWGHX/FwFPZwkCxAQX+z3tuIN5UPVzrbLHp4s hlJsCfs4Ho+EL9WgeLWARlcJGKPjxCXOkuZj6xQnRbeSItIDVj7DG9/XCebLuF38cYaK arNaWb7BHXOcAnNPsV3lDZPv9kxV3k7ScTsa4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=5nY8ZqSYHJAuSBSW4axDy4/NxzGCWtlFeNaPBEj3EnA=; b=OFRmJmtun96DJVkfvJ7W3UqUsOGhHP0zzsWc8OjXN0a9Drtffn57KEjKW35rK9XC2V XMXRl/3aMl2HSRrN8s9ca2eI8w8huHdglZubOLNSzqEqjNVzU92XjpkXICzDSf/5Y3rv 7QGa+oXrL2JpkxeKpFAfgO0mz5MEvQ6NAHAbg8FcJUVW9yHTbdtg2Jo0IZAiVDHlymQg l3sQB1kX+ipSffuExa/qVLHwIs1v+L+Gx9H5HO87038Tdb1IUWJ3GswwDkamEWZIwHz1 yYyreX8kb+fUqbobN1wfJNs2tosrmJEXVy/Y6fbZEijxUfOxEKm/j9fY0lxMdXrhyRAO BQ3Q== X-Gm-Message-State: APjAAAU0qpwyWHfXK7fv5NddK6RRGYnH1B65ylS1mSUsfrcxPU8Rh2zp U+FR6C+LEoFvLNyqHEpG0+Eqdw== X-Google-Smtp-Source: APXvYqxdD+jx/kwDAMbkCFHkMS15pEk15nnRLnSfmifowUlnyK9T2z6VqbVlv7czS/zURCHYdiGl4A== X-Received: by 2002:a17:902:467:: with SMTP id 94mr59214451ple.208.1568585693458; Sun, 15 Sep 2019 15:14:53 -0700 (PDT) Received: from rfd.leadboat.com (108-233-125-46.lightspeed.sntcca.sbcglobal.net. [108.233.125.46]) by smtp.gmail.com with ESMTPSA id i1sm7187154pfe.136.2019.09.15.15.14.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 15 Sep 2019 15:14:52 -0700 (PDT) Date: Sun, 15 Sep 2019 15:14:50 -0700 From: Noah Misch To: Alvaro Herrera Cc: pgsql-committers@lists.postgresql.org Subject: Re: pgsql: Test pg_atomic_fetch_add_ with variable addend and 16-bit edge c Message-ID: <20190915221450.GA3500204@rfd.leadboat.com> References: <20190915160021.GA24376@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190915160021.GA24376@alvherre.pgsql> User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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) + 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");