aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNoah Misch <noah@leadboat.com>2019-09-13 19:33:30 -0700
committerNoah Misch <noah@leadboat.com>2019-09-13 19:33:46 -0700
commit585fc561f8246fde76cee691607cc43325e16b29 (patch)
treef9065caed02f5dc32b84b67e5d5f4395ac5668f3 /src
parent41f3d262693b1d735a3683104e334f1e9b48d7f4 (diff)
downloadpostgresql-585fc561f8246fde76cee691607cc43325e16b29.tar.gz
postgresql-585fc561f8246fde76cee691607cc43325e16b29.zip
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
Diffstat (limited to 'src')
-rw-r--r--src/test/regress/regress.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/test/regress/regress.c b/src/test/regress/regress.c
index 7060b6fbf32..30f6ae53b13 100644
--- a/src/test/regress/regress.c
+++ b/src/test/regress/regress.c
@@ -679,7 +679,7 @@ test_atomic_uint32(void)
if (pg_atomic_read_u32(&var) != 3)
elog(ERROR, "atomic_read_u32() #2 wrong");
- if (pg_atomic_fetch_add_u32(&var, 1) != 3)
+ 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)
@@ -704,6 +704,20 @@ test_atomic_uint32(void)
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");
+
+ 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");
+
pg_atomic_fetch_add_u32(&var, 1); /* top up to UINT_MAX */
if (pg_atomic_read_u32(&var) != UINT_MAX)
@@ -779,7 +793,7 @@ test_atomic_uint64(void)
if (pg_atomic_read_u64(&var) != 3)
elog(ERROR, "atomic_read_u64() #2 wrong");
- if (pg_atomic_fetch_add_u64(&var, 1) != 3)
+ 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)