Hi all,

As of the thread which led to addd034 (please see
https://www.postgresql.org/message-id/e1j9ioh-0005kn...@gemulon.postgresql.org,
and sorry about that), it happens that we don't have any tests which
validate the internal data checksum implementation present in core as
of checksum_impl.h.  pageinspect includes a SQL-callable function to
calculate the checksum of a page, mentioned by David in CC, and only
one test exists to make sure that a checksum is not NULL, but it does
not really help if the formula is touched.

Attached is a patch to close the gap by adding new tests to
pageinspect aimed at detecting any formula change.  The trick is to
make the page data representative enough so as it is possible to
detect problems if any part of the formulas are changed, like updates
of pg_checksum_block or checksumBaseOffsets.

Any thoughts or other ideas?
Thanks,
--
Michael
diff --git a/contrib/pageinspect/expected/page.out b/contrib/pageinspect/expected/page.out
index b6aea0124b..e475f2dfa0 100644
--- a/contrib/pageinspect/expected/page.out
+++ b/contrib/pageinspect/expected/page.out
@@ -211,3 +211,20 @@ select tuple_data_split('test8'::regclass, t_data, t_infomask, t_infomask2, t_bi
 (1 row)
 
 drop table test8;
+-- generic checksum tests
+SHOW block_size \gset
+SELECT blkno,
+    page_checksum(decode(repeat('01', :block_size), 'hex'), blkno) AS checksum_01,
+    page_checksum(decode(repeat('04', :block_size), 'hex'), blkno) AS checksum_04,
+    page_checksum(decode(repeat('ff', :block_size), 'hex'), blkno) AS checksum_ff,
+    page_checksum(decode(repeat('abcd', :block_size / 2), 'hex'), blkno) AS checksum_abcd,
+    page_checksum(decode(repeat('e6d6', :block_size / 2), 'hex'), blkno) AS checksum_e6d6,
+    page_checksum(decode(repeat('4a5e', :block_size / 2), 'hex'), blkno) AS checksum_4a5e
+  FROM generate_series(0, 100, 50) AS a (blkno);
+ blkno | checksum_01 | checksum_04 | checksum_ff | checksum_abcd | checksum_e6d6 | checksum_4a5e 
+-------+-------------+-------------+-------------+---------------+---------------+---------------
+     0 |        1175 |       28338 |        3612 |        -30781 |        -16269 |        -27377
+    50 |        1225 |       28352 |        3598 |        -30795 |        -16251 |        -27391
+   100 |        1139 |       28438 |        3648 |        -30881 |        -16305 |        -27349
+(3 rows)
+
diff --git a/contrib/pageinspect/sql/page.sql b/contrib/pageinspect/sql/page.sql
index bd049aeb24..e484827053 100644
--- a/contrib/pageinspect/sql/page.sql
+++ b/contrib/pageinspect/sql/page.sql
@@ -86,3 +86,14 @@ select t_bits, t_data from heap_page_items(get_raw_page('test8', 0));
 select tuple_data_split('test8'::regclass, t_data, t_infomask, t_infomask2, t_bits)
     from heap_page_items(get_raw_page('test8', 0));
 drop table test8;
+
+-- generic checksum tests
+SHOW block_size \gset
+SELECT blkno,
+    page_checksum(decode(repeat('01', :block_size), 'hex'), blkno) AS checksum_01,
+    page_checksum(decode(repeat('04', :block_size), 'hex'), blkno) AS checksum_04,
+    page_checksum(decode(repeat('ff', :block_size), 'hex'), blkno) AS checksum_ff,
+    page_checksum(decode(repeat('abcd', :block_size / 2), 'hex'), blkno) AS checksum_abcd,
+    page_checksum(decode(repeat('e6d6', :block_size / 2), 'hex'), blkno) AS checksum_e6d6,
+    page_checksum(decode(repeat('4a5e', :block_size / 2), 'hex'), blkno) AS checksum_4a5e
+  FROM generate_series(0, 100, 50) AS a (blkno);

Attachment: signature.asc
Description: PGP signature

Reply via email to