Skip to content

Commit e6a90de

Browse files
committed
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
1 parent 4f7dbf0 commit e6a90de

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/test/regress/regress.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -928,7 +928,7 @@ test_atomic_uint32(void)
928928
if (pg_atomic_read_u32(&var) != 3)
929929
elog(ERROR, "atomic_read_u32() #2 wrong");
930930

931-
if (pg_atomic_fetch_add_u32(&var, 1) != 3)
931+
if (pg_atomic_fetch_add_u32(&var, pg_atomic_read_u32(&var) - 2) != 3)
932932
elog(ERROR, "atomic_fetch_add_u32() #1 wrong");
933933

934934
if (pg_atomic_fetch_sub_u32(&var, 1) != 4)
@@ -953,6 +953,20 @@ test_atomic_uint32(void)
953953
if (pg_atomic_fetch_add_u32(&var, INT_MAX) != INT_MAX)
954954
elog(ERROR, "pg_atomic_add_fetch_u32() #3 wrong");
955955

956+
pg_atomic_fetch_add_u32(&var, 2); /* wrap to 0 */
957+
958+
if (pg_atomic_fetch_add_u32(&var, PG_INT16_MAX) != 0)
959+
elog(ERROR, "pg_atomic_fetch_add_u32() #3 wrong");
960+
961+
if (pg_atomic_fetch_add_u32(&var, PG_INT16_MAX + 1) != PG_INT16_MAX)
962+
elog(ERROR, "pg_atomic_fetch_add_u32() #4 wrong");
963+
964+
if (pg_atomic_fetch_add_u32(&var, PG_INT16_MIN) != 2 * PG_INT16_MAX + 1)
965+
elog(ERROR, "pg_atomic_fetch_add_u32() #5 wrong");
966+
967+
if (pg_atomic_fetch_add_u32(&var, PG_INT16_MIN - 1) != PG_INT16_MAX)
968+
elog(ERROR, "pg_atomic_fetch_add_u32() #6 wrong");
969+
956970
pg_atomic_fetch_add_u32(&var, 1); /* top up to UINT_MAX */
957971

958972
if (pg_atomic_read_u32(&var) != UINT_MAX)
@@ -1028,7 +1042,7 @@ test_atomic_uint64(void)
10281042
if (pg_atomic_read_u64(&var) != 3)
10291043
elog(ERROR, "atomic_read_u64() #2 wrong");
10301044

1031-
if (pg_atomic_fetch_add_u64(&var, 1) != 3)
1045+
if (pg_atomic_fetch_add_u64(&var, pg_atomic_read_u64(&var) - 2) != 3)
10321046
elog(ERROR, "atomic_fetch_add_u64() #1 wrong");
10331047

10341048
if (pg_atomic_fetch_sub_u64(&var, 1) != 4)

0 commit comments

Comments
 (0)