Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f380c51

Browse filesBrowse 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 b360e0f commit f380c51
Copy full SHA for f380c51

File tree

Expand file treeCollapse file tree

1 file changed

+16
-2
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+16
-2
lines changed

‎src/test/regress/regress.c

Copy file name to clipboardExpand all lines: src/test/regress/regress.c
+16-2Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ test_atomic_uint32(void)
687687
if (pg_atomic_read_u32(&var) != 3)
688688
elog(ERROR, "atomic_read_u32() #2 wrong");
689689

690-
if (pg_atomic_fetch_add_u32(&var, 1) != 3)
690+
if (pg_atomic_fetch_add_u32(&var, pg_atomic_read_u32(&var) - 2) != 3)
691691
elog(ERROR, "atomic_fetch_add_u32() #1 wrong");
692692

693693
if (pg_atomic_fetch_sub_u32(&var, 1) != 4)
@@ -712,6 +712,20 @@ test_atomic_uint32(void)
712712
if (pg_atomic_fetch_add_u32(&var, INT_MAX) != INT_MAX)
713713
elog(ERROR, "pg_atomic_add_fetch_u32() #3 wrong");
714714

715+
pg_atomic_fetch_add_u32(&var, 2); /* wrap to 0 */
716+
717+
if (pg_atomic_fetch_add_u32(&var, PG_INT16_MAX) != 0)
718+
elog(ERROR, "pg_atomic_fetch_add_u32() #3 wrong");
719+
720+
if (pg_atomic_fetch_add_u32(&var, PG_INT16_MAX + 1) != PG_INT16_MAX)
721+
elog(ERROR, "pg_atomic_fetch_add_u32() #4 wrong");
722+
723+
if (pg_atomic_fetch_add_u32(&var, PG_INT16_MIN) != 2 * PG_INT16_MAX + 1)
724+
elog(ERROR, "pg_atomic_fetch_add_u32() #5 wrong");
725+
726+
if (pg_atomic_fetch_add_u32(&var, PG_INT16_MIN - 1) != PG_INT16_MAX)
727+
elog(ERROR, "pg_atomic_fetch_add_u32() #6 wrong");
728+
715729
pg_atomic_fetch_add_u32(&var, 1); /* top up to UINT_MAX */
716730

717731
if (pg_atomic_read_u32(&var) != UINT_MAX)
@@ -787,7 +801,7 @@ test_atomic_uint64(void)
787801
if (pg_atomic_read_u64(&var) != 3)
788802
elog(ERROR, "atomic_read_u64() #2 wrong");
789803

790-
if (pg_atomic_fetch_add_u64(&var, 1) != 3)
804+
if (pg_atomic_fetch_add_u64(&var, pg_atomic_read_u64(&var) - 2) != 3)
791805
elog(ERROR, "atomic_fetch_add_u64() #1 wrong");
792806

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

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.