pg.ddx.io pgsql-committers@postgresql.org mailing list archive
help / color / mirror / Atom feedpgsql: Test pg_atomic_fetch_add_ with variable addend and 16-bit edge c
10+ messages / 3 participants
[nested] [flat]
Commits from this thread:
2019-10-05 e800bd7414 2dbd2cc5a9 eb74022d24 1b6b348505 639feb92e1 57f0060891 Report test_atomic_ops() failures consistently, via macros.
* pgsql: Test pg_atomic_fetch_add_ with variable addend and 16-bit edge c
@ 2019-09-14 02:41 Noah Misch <noah@leadboat.com>
2019-09-15 16:00 ` Re: pgsql: Test pg_atomic_fetch_add_ with variable addend and 16-bit edge c Alvaro Herrera <alvherre@2ndquadrant.com>
0 siblings, 1 reply; 10+ messages in thread
From: Noah Misch @ 2019-09-14 02:41 UTC (permalink / raw)
To: pgsql-committers@lists.postgresql.org
Test pg_atomic_fetch_add_ with variable addend and 16-bit edge cases.
Back-patch to 9.5, which introduced these functions.
Reviewed by Tom Lane.
Discussion: https://postgr.es/m/20190831071157.GA3251746@rfd.leadboat.com
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/f380c5190134a4e928bf30a4ff9fec775cdcc692
Modified Files
--------------
src/test/regress/regress.c | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: pgsql: Test pg_atomic_fetch_add_ with variable addend and 16-bit edge c
2019-09-14 02:41 pgsql: Test pg_atomic_fetch_add_ with variable addend and 16-bit edge c Noah Misch <noah@leadboat.com>
@ 2019-09-15 16:00 ` Alvaro Herrera <alvherre@2ndquadrant.com>
2019-09-15 22:14 ` Re: pgsql: Test pg_atomic_fetch_add_ with variable addend and 16-bit edge c Noah Misch <noah@leadboat.com>
0 siblings, 1 reply; 10+ messages in thread
From: Alvaro Herrera @ 2019-09-15 16:00 UTC (permalink / raw)
To: Noah Misch <noah@leadboat.com>; +Cc: pgsql-committers@lists.postgresql.org
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?
--
Álvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: pgsql: Test pg_atomic_fetch_add_ with variable addend and 16-bit edge c
2019-09-14 02:41 pgsql: Test pg_atomic_fetch_add_ with variable addend and 16-bit edge c Noah Misch <noah@leadboat.com>
2019-09-15 16:00 ` Re: pgsql: Test pg_atomic_fetch_add_ with variable addend and 16-bit edge c Alvaro Herrera <alvherre@2ndquadrant.com>
@ 2019-09-15 22:14 ` Noah Misch <noah@leadboat.com>
2019-09-16 04:47 ` Re: pgsql: Test pg_atomic_fetch_add_ with variable addend and 16-bit edge c Andres Freund <andres@anarazel.de>
0 siblings, 1 reply; 10+ messages in thread
From: Noah Misch @ 2019-09-15 22:14 UTC (permalink / raw)
To: Alvaro Herrera <alvherre@2ndquadrant.com>; +Cc: pgsql-committers@lists.postgresql.org
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):
inline patch 1: src/test/regress/regress.c (+13/-10 lines) download inline-1.patch
--- 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");
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: pgsql: Test pg_atomic_fetch_add_ with variable addend and 16-bit edge c
2019-09-14 02:41 pgsql: Test pg_atomic_fetch_add_ with variable addend and 16-bit edge c Noah Misch <noah@leadboat.com>
2019-09-15 16:00 ` Re: pgsql: Test pg_atomic_fetch_add_ with variable addend and 16-bit edge c Alvaro Herrera <alvherre@2ndquadrant.com>
2019-09-15 22:14 ` Re: pgsql: Test pg_atomic_fetch_add_ with variable addend and 16-bit edge c Noah Misch <noah@leadboat.com>
@ 2019-09-16 04:47 ` Andres Freund <andres@anarazel.de>
2019-09-28 04:27 ` Re: pgsql: Test pg_atomic_fetch_add_ with variable addend and 16-bit edge c Noah Misch <noah@leadboat.com>
0 siblings, 1 reply; 10+ messages in thread
From: Andres Freund @ 2019-09-16 04:47 UTC (permalink / raw)
To: Noah Misch <noah@leadboat.com>; +Cc: Alvaro Herrera <alvherre@2ndquadrant.com>; pgsql-committers@lists.postgresql.org
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
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: pgsql: Test pg_atomic_fetch_add_ with variable addend and 16-bit edge c
2019-09-14 02:41 pgsql: Test pg_atomic_fetch_add_ with variable addend and 16-bit edge c Noah Misch <noah@leadboat.com>
2019-09-15 16:00 ` Re: pgsql: Test pg_atomic_fetch_add_ with variable addend and 16-bit edge c Alvaro Herrera <alvherre@2ndquadrant.com>
2019-09-15 22:14 ` Re: pgsql: Test pg_atomic_fetch_add_ with variable addend and 16-bit edge c Noah Misch <noah@leadboat.com>
2019-09-16 04:47 ` Re: pgsql: Test pg_atomic_fetch_add_ with variable addend and 16-bit edge c Andres Freund <andres@anarazel.de>
@ 2019-09-28 04:27 ` Noah Misch <noah@leadboat.com>
0 siblings, 0 replies; 10+ messages in thread
From: Noah Misch @ 2019-09-28 04:27 UTC (permalink / raw)
To: Andres Freund <andres@anarazel.de>; +Cc: Alvaro Herrera <alvherre@2ndquadrant.com>; pgsql-committers@lists.postgresql.org
On Sun, Sep 15, 2019 at 09:47:52PM -0700, Andres Freund wrote:
> On 2019-09-15 15:14:50 -0700, Noah Misch wrote:
> > --- 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)
> > +
> 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.
> I'd name it EXPECT_EQ_U32 or such, but otherwise I think this is a clear
> improvement.
EXPECT_EQ_U32 works for me; I mildly prefer that to a type-independent macro
that doesn't print the unexpected value. Attached.
Attachments:
regress-atomics-macros-v1.patch (text/plain, 10.2K) download
diff --git a/src/test/regress/regress.c b/src/test/regress/regress.c
index 8cc1568..9294751 100644
--- a/src/test/regress/regress.c
+++ b/src/test/regress/regress.c
@@ -41,6 +41,33 @@
#include "utils/memutils.h"
+#define EXPECT_TRUE(expr) \
+ do { \
+ if (!(expr)) \
+ elog(ERROR, \
+ "%s was unexpectedly false in file \"%s\" line %u", \
+ #expr, __FILE__, __LINE__); \
+ } while (0)
+#define EXPECT_EQ_U32(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)
+
+#define EXPECT_EQ_U64(result_expr, expected_expr) \
+ do { \
+ uint64 result = (result_expr); \
+ uint64 expected = (expected_expr); \
+ if (result != expected) \
+ elog(ERROR, \
+ "%s yielded " UINT64_FORMAT ", expected %s in file \"%s\" line %u", \
+ #result_expr, result, #expected_expr, __FILE__, __LINE__); \
+ } while (0)
+
#define LDELIM '('
#define RDELIM ')'
#define DELIM ','
@@ -646,27 +673,13 @@ test_atomic_flag(void)
pg_atomic_flag flag;
pg_atomic_init_flag(&flag);
-
- if (!pg_atomic_unlocked_test_flag(&flag))
- elog(ERROR, "flag: unexpectedly set");
-
- if (!pg_atomic_test_set_flag(&flag))
- elog(ERROR, "flag: couldn't set");
-
- if (pg_atomic_unlocked_test_flag(&flag))
- elog(ERROR, "flag: unexpectedly unset");
-
- if (pg_atomic_test_set_flag(&flag))
- elog(ERROR, "flag: set spuriously #2");
-
+ EXPECT_TRUE(pg_atomic_unlocked_test_flag(&flag));
+ EXPECT_TRUE(pg_atomic_test_set_flag(&flag));
+ EXPECT_TRUE(!pg_atomic_unlocked_test_flag(&flag));
+ EXPECT_TRUE(!pg_atomic_test_set_flag(&flag));
pg_atomic_clear_flag(&flag);
-
- if (!pg_atomic_unlocked_test_flag(&flag))
- elog(ERROR, "flag: unexpectedly set #2");
-
- if (!pg_atomic_test_set_flag(&flag))
- elog(ERROR, "flag: couldn't set");
-
+ EXPECT_TRUE(pg_atomic_unlocked_test_flag(&flag));
+ EXPECT_TRUE(pg_atomic_test_set_flag(&flag));
pg_atomic_clear_flag(&flag);
}
@@ -678,75 +691,38 @@ 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_EQ_U32(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");
-
- if (pg_atomic_fetch_sub_u32(&var, 1) != 4)
- elog(ERROR, "atomic_fetch_sub_u32() #1 wrong");
-
- if (pg_atomic_sub_fetch_u32(&var, 3) != 0)
- elog(ERROR, "atomic_sub_fetch_u32() #1 wrong");
-
- if (pg_atomic_add_fetch_u32(&var, 10) != 10)
- elog(ERROR, "atomic_add_fetch_u32() #1 wrong");
-
- if (pg_atomic_exchange_u32(&var, 5) != 10)
- elog(ERROR, "pg_atomic_exchange_u32() #1 wrong");
-
- if (pg_atomic_exchange_u32(&var, 0) != 5)
- elog(ERROR, "pg_atomic_exchange_u32() #0 wrong");
+ EXPECT_EQ_U32(pg_atomic_read_u32(&var), 3);
+ EXPECT_EQ_U32(pg_atomic_fetch_add_u32(&var, pg_atomic_read_u32(&var) - 2),
+ 3);
+ EXPECT_EQ_U32(pg_atomic_fetch_sub_u32(&var, 1), 4);
+ EXPECT_EQ_U32(pg_atomic_sub_fetch_u32(&var, 3), 0);
+ EXPECT_EQ_U32(pg_atomic_add_fetch_u32(&var, 10), 10);
+ EXPECT_EQ_U32(pg_atomic_exchange_u32(&var, 5), 10);
+ EXPECT_EQ_U32(pg_atomic_exchange_u32(&var, 0), 5);
/* test around numerical limits */
- if (pg_atomic_fetch_add_u32(&var, INT_MAX) != 0)
- elog(ERROR, "pg_atomic_fetch_add_u32() #2 wrong");
-
- if (pg_atomic_fetch_add_u32(&var, INT_MAX) != INT_MAX)
- elog(ERROR, "pg_atomic_add_fetch_u32() #3 wrong");
-
+ EXPECT_EQ_U32(pg_atomic_fetch_add_u32(&var, INT_MAX), 0);
+ EXPECT_EQ_U32(pg_atomic_fetch_add_u32(&var, INT_MAX), INT_MAX);
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");
-
- if (pg_atomic_fetch_add_u32(&var, PG_INT16_MAX + 1) != PG_INT16_MAX)
- elog(ERROR, "pg_atomic_fetch_add_u32() #4 wrong");
-
- if (pg_atomic_fetch_add_u32(&var, PG_INT16_MIN) != 2 * PG_INT16_MAX + 1)
- elog(ERROR, "pg_atomic_fetch_add_u32() #5 wrong");
-
- if (pg_atomic_fetch_add_u32(&var, PG_INT16_MIN - 1) != PG_INT16_MAX)
- elog(ERROR, "pg_atomic_fetch_add_u32() #6 wrong");
-
+ EXPECT_EQ_U32(pg_atomic_fetch_add_u32(&var, PG_INT16_MAX), 0);
+ EXPECT_EQ_U32(pg_atomic_fetch_add_u32(&var, PG_INT16_MAX + 1),
+ PG_INT16_MAX);
+ EXPECT_EQ_U32(pg_atomic_fetch_add_u32(&var, PG_INT16_MIN),
+ 2 * PG_INT16_MAX + 1);
+ EXPECT_EQ_U32(pg_atomic_fetch_add_u32(&var, PG_INT16_MIN - 1),
+ PG_INT16_MAX);
pg_atomic_fetch_add_u32(&var, 1); /* top up to UINT_MAX */
-
- if (pg_atomic_read_u32(&var) != UINT_MAX)
- elog(ERROR, "atomic_read_u32() #2 wrong");
-
- if (pg_atomic_fetch_sub_u32(&var, INT_MAX) != UINT_MAX)
- elog(ERROR, "pg_atomic_fetch_sub_u32() #2 wrong");
-
- if (pg_atomic_read_u32(&var) != (uint32) INT_MAX + 1)
- elog(ERROR, "atomic_read_u32() #3 wrong: %u", pg_atomic_read_u32(&var));
-
- expected = pg_atomic_sub_fetch_u32(&var, INT_MAX);
- if (expected != 1)
- elog(ERROR, "pg_atomic_sub_fetch_u32() #3 wrong: %u", expected);
-
+ EXPECT_EQ_U32(pg_atomic_read_u32(&var), UINT_MAX);
+ EXPECT_EQ_U32(pg_atomic_fetch_sub_u32(&var, INT_MAX), UINT_MAX);
+ EXPECT_EQ_U32(pg_atomic_read_u32(&var), (uint32) INT_MAX + 1);
+ EXPECT_EQ_U32(pg_atomic_sub_fetch_u32(&var, INT_MAX), 1);
pg_atomic_sub_fetch_u32(&var, 1);
/* fail exchange because of old expected */
expected = 10;
- if (pg_atomic_compare_exchange_u32(&var, &expected, 1))
- elog(ERROR, "atomic_compare_exchange_u32() changed value spuriously");
+ EXPECT_TRUE(!pg_atomic_compare_exchange_u32(&var, &expected, 1));
/* CAS is allowed to fail due to interrupts, try a couple of times */
for (i = 0; i < 1000; i++)
@@ -757,31 +733,18 @@ test_atomic_uint32(void)
}
if (i == 1000)
elog(ERROR, "atomic_compare_exchange_u32() never succeeded");
- if (pg_atomic_read_u32(&var) != 1)
- elog(ERROR, "atomic_compare_exchange_u32() didn't set value properly");
-
+ EXPECT_EQ_U32(pg_atomic_read_u32(&var), 1);
pg_atomic_write_u32(&var, 0);
/* try setting flagbits */
- if (pg_atomic_fetch_or_u32(&var, 1) & 1)
- elog(ERROR, "pg_atomic_fetch_or_u32() #1 wrong");
-
- if (!(pg_atomic_fetch_or_u32(&var, 2) & 1))
- elog(ERROR, "pg_atomic_fetch_or_u32() #2 wrong");
-
- if (pg_atomic_read_u32(&var) != 3)
- elog(ERROR, "invalid result after pg_atomic_fetch_or_u32()");
-
+ EXPECT_TRUE(!(pg_atomic_fetch_or_u32(&var, 1) & 1));
+ EXPECT_TRUE(pg_atomic_fetch_or_u32(&var, 2) & 1);
+ EXPECT_EQ_U32(pg_atomic_read_u32(&var), 3);
/* try clearing flagbits */
- if ((pg_atomic_fetch_and_u32(&var, ~2) & 3) != 3)
- elog(ERROR, "pg_atomic_fetch_and_u32() #1 wrong");
-
- if (pg_atomic_fetch_and_u32(&var, ~1) != 1)
- elog(ERROR, "pg_atomic_fetch_and_u32() #2 wrong: is %u",
- pg_atomic_read_u32(&var));
+ EXPECT_EQ_U32(pg_atomic_fetch_and_u32(&var, ~2) & 3, 3);
+ EXPECT_EQ_U32(pg_atomic_fetch_and_u32(&var, ~1), 1);
/* no bits set anymore */
- if (pg_atomic_fetch_and_u32(&var, ~0) != 0)
- elog(ERROR, "pg_atomic_fetch_and_u32() #3 wrong");
+ EXPECT_EQ_U32(pg_atomic_fetch_and_u32(&var, ~0), 0);
}
static void
@@ -792,37 +755,20 @@ test_atomic_uint64(void)
int i;
pg_atomic_init_u64(&var, 0);
-
- if (pg_atomic_read_u64(&var) != 0)
- elog(ERROR, "atomic_read_u64() #1 wrong");
-
+ EXPECT_EQ_U64(pg_atomic_read_u64(&var), 0);
pg_atomic_write_u64(&var, 3);
-
- if (pg_atomic_read_u64(&var) != 3)
- elog(ERROR, "atomic_read_u64() #2 wrong");
-
- if (pg_atomic_fetch_add_u64(&var, pg_atomic_read_u64(&var) - 2) != 3)
- elog(ERROR, "atomic_fetch_add_u64() #1 wrong");
-
- if (pg_atomic_fetch_sub_u64(&var, 1) != 4)
- elog(ERROR, "atomic_fetch_sub_u64() #1 wrong");
-
- if (pg_atomic_sub_fetch_u64(&var, 3) != 0)
- elog(ERROR, "atomic_sub_fetch_u64() #1 wrong");
-
- if (pg_atomic_add_fetch_u64(&var, 10) != 10)
- elog(ERROR, "atomic_add_fetch_u64() #1 wrong");
-
- if (pg_atomic_exchange_u64(&var, 5) != 10)
- elog(ERROR, "pg_atomic_exchange_u64() #1 wrong");
-
- if (pg_atomic_exchange_u64(&var, 0) != 5)
- elog(ERROR, "pg_atomic_exchange_u64() #0 wrong");
+ EXPECT_EQ_U64(pg_atomic_read_u64(&var), 3);
+ EXPECT_EQ_U64(pg_atomic_fetch_add_u64(&var, pg_atomic_read_u64(&var) - 2),
+ 3);
+ EXPECT_EQ_U64(pg_atomic_fetch_sub_u64(&var, 1), 4);
+ EXPECT_EQ_U64(pg_atomic_sub_fetch_u64(&var, 3), 0);
+ EXPECT_EQ_U64(pg_atomic_add_fetch_u64(&var, 10), 10);
+ EXPECT_EQ_U64(pg_atomic_exchange_u64(&var, 5), 10);
+ EXPECT_EQ_U64(pg_atomic_exchange_u64(&var, 0), 5);
/* fail exchange because of old expected */
expected = 10;
- if (pg_atomic_compare_exchange_u64(&var, &expected, 1))
- elog(ERROR, "atomic_compare_exchange_u64() changed value spuriously");
+ EXPECT_TRUE(!pg_atomic_compare_exchange_u64(&var, &expected, 1));
/* CAS is allowed to fail due to interrupts, try a couple of times */
for (i = 0; i < 100; i++)
@@ -833,31 +779,19 @@ test_atomic_uint64(void)
}
if (i == 100)
elog(ERROR, "atomic_compare_exchange_u64() never succeeded");
- if (pg_atomic_read_u64(&var) != 1)
- elog(ERROR, "atomic_compare_exchange_u64() didn't set value properly");
+ EXPECT_EQ_U64(pg_atomic_read_u64(&var), 1);
pg_atomic_write_u64(&var, 0);
/* try setting flagbits */
- if (pg_atomic_fetch_or_u64(&var, 1) & 1)
- elog(ERROR, "pg_atomic_fetch_or_u64() #1 wrong");
-
- if (!(pg_atomic_fetch_or_u64(&var, 2) & 1))
- elog(ERROR, "pg_atomic_fetch_or_u64() #2 wrong");
-
- if (pg_atomic_read_u64(&var) != 3)
- elog(ERROR, "invalid result after pg_atomic_fetch_or_u64()");
-
+ EXPECT_TRUE(!(pg_atomic_fetch_or_u64(&var, 1) & 1));
+ EXPECT_TRUE(pg_atomic_fetch_or_u64(&var, 2) & 1);
+ EXPECT_EQ_U64(pg_atomic_read_u64(&var), 3);
/* try clearing flagbits */
- if ((pg_atomic_fetch_and_u64(&var, ~2) & 3) != 3)
- elog(ERROR, "pg_atomic_fetch_and_u64() #1 wrong");
-
- if (pg_atomic_fetch_and_u64(&var, ~1) != 1)
- elog(ERROR, "pg_atomic_fetch_and_u64() #2 wrong: is " UINT64_FORMAT,
- pg_atomic_read_u64(&var));
+ EXPECT_EQ_U64((pg_atomic_fetch_and_u64(&var, ~2) & 3), 3);
+ EXPECT_EQ_U64(pg_atomic_fetch_and_u64(&var, ~1), 1);
/* no bits set anymore */
- if (pg_atomic_fetch_and_u64(&var, ~0) != 0)
- elog(ERROR, "pg_atomic_fetch_and_u64() #3 wrong");
+ EXPECT_EQ_U64(pg_atomic_fetch_and_u64(&var, ~0), 0);
}
^ permalink raw reply [nested|flat] 10+ messages in thread
* pgsql: Test pg_atomic_fetch_add_ with variable addend and 16-bit edge c
@ 2019-09-14 02:41 Noah Misch <noah@leadboat.com>
0 siblings, 0 replies; 10+ messages in thread
From: Noah Misch @ 2019-09-14 02:41 UTC (permalink / raw)
To: pgsql-committers@lists.postgresql.org
Test pg_atomic_fetch_add_ with variable addend and 16-bit edge cases.
Back-patch to 9.5, which introduced these functions.
Reviewed by Tom Lane.
Discussion: https://postgr.es/m/20190831071157.GA3251746@rfd.leadboat.com
Branch
------
REL_12_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/5b5b0f721d9cece8fb68ecdd1d53c3bffe6e753c
Modified Files
--------------
src/test/regress/regress.c | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
^ permalink raw reply [nested|flat] 10+ messages in thread
* pgsql: Test pg_atomic_fetch_add_ with variable addend and 16-bit edge c
@ 2019-09-14 02:41 Noah Misch <noah@leadboat.com>
0 siblings, 0 replies; 10+ messages in thread
From: Noah Misch @ 2019-09-14 02:41 UTC (permalink / raw)
To: pgsql-committers@lists.postgresql.org
Test pg_atomic_fetch_add_ with variable addend and 16-bit edge cases.
Back-patch to 9.5, which introduced these functions.
Reviewed by Tom Lane.
Discussion: https://postgr.es/m/20190831071157.GA3251746@rfd.leadboat.com
Branch
------
REL_11_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/585fc561f8246fde76cee691607cc43325e16b29
Modified Files
--------------
src/test/regress/regress.c | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
^ permalink raw reply [nested|flat] 10+ messages in thread
* pgsql: Test pg_atomic_fetch_add_ with variable addend and 16-bit edge c
@ 2019-09-14 02:41 Noah Misch <noah@leadboat.com>
0 siblings, 0 replies; 10+ messages in thread
From: Noah Misch @ 2019-09-14 02:41 UTC (permalink / raw)
To: pgsql-committers@lists.postgresql.org
Test pg_atomic_fetch_add_ with variable addend and 16-bit edge cases.
Back-patch to 9.5, which introduced these functions.
Reviewed by Tom Lane.
Discussion: https://postgr.es/m/20190831071157.GA3251746@rfd.leadboat.com
Branch
------
REL_10_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/e6a90ded5a6c2085a71b0e564451b48e800f4e8f
Modified Files
--------------
src/test/regress/regress.c | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
^ permalink raw reply [nested|flat] 10+ messages in thread
* pgsql: Test pg_atomic_fetch_add_ with variable addend and 16-bit edge c
@ 2019-09-14 02:41 Noah Misch <noah@leadboat.com>
0 siblings, 0 replies; 10+ messages in thread
From: Noah Misch @ 2019-09-14 02:41 UTC (permalink / raw)
To: pgsql-committers@lists.postgresql.org
Test pg_atomic_fetch_add_ with variable addend and 16-bit edge cases.
Back-patch to 9.5, which introduced these functions.
Reviewed by Tom Lane.
Discussion: https://postgr.es/m/20190831071157.GA3251746@rfd.leadboat.com
Branch
------
REL9_6_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/8d32f82cbbbba5dd3da76edc298c04d3fd6041ae
Modified Files
--------------
src/test/regress/regress.c | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
^ permalink raw reply [nested|flat] 10+ messages in thread
* pgsql: Test pg_atomic_fetch_add_ with variable addend and 16-bit edge c
@ 2019-09-14 02:41 Noah Misch <noah@leadboat.com>
0 siblings, 0 replies; 10+ messages in thread
From: Noah Misch @ 2019-09-14 02:41 UTC (permalink / raw)
To: pgsql-committers@lists.postgresql.org
Test pg_atomic_fetch_add_ with variable addend and 16-bit edge cases.
Back-patch to 9.5, which introduced these functions.
Reviewed by Tom Lane.
Discussion: https://postgr.es/m/20190831071157.GA3251746@rfd.leadboat.com
Branch
------
REL9_5_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/4737d3a75b725b6babf2d402c767751a105b67e9
Modified Files
--------------
src/test/regress/regress.c | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
^ permalink raw reply [nested|flat] 10+ messages in thread
end of thread, other threads:[~2019-09-28 04:27 UTC | newest]
Thread overview: 10+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-09-14 02:41 pgsql: Test pg_atomic_fetch_add_ with variable addend and 16-bit edge c Noah Misch <noah@leadboat.com>
2019-09-15 16:00 ` Alvaro Herrera <alvherre@2ndquadrant.com>
2019-09-15 22:14 ` Noah Misch <noah@leadboat.com>
2019-09-16 04:47 ` Andres Freund <andres@anarazel.de>
2019-09-28 04:27 ` Noah Misch <noah@leadboat.com>
2019-09-14 02:41 pgsql: Test pg_atomic_fetch_add_ with variable addend and 16-bit edge c Noah Misch <noah@leadboat.com>
2019-09-14 02:41 pgsql: Test pg_atomic_fetch_add_ with variable addend and 16-bit edge c Noah Misch <noah@leadboat.com>
2019-09-14 02:41 pgsql: Test pg_atomic_fetch_add_ with variable addend and 16-bit edge c Noah Misch <noah@leadboat.com>
2019-09-14 02:41 pgsql: Test pg_atomic_fetch_add_ with variable addend and 16-bit edge c Noah Misch <noah@leadboat.com>
2019-09-14 02:41 pgsql: Test pg_atomic_fetch_add_ with variable addend and 16-bit edge c Noah Misch <noah@leadboat.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox