Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 38ce06c

Browse files
committed
Add an explicit test to catch changes in checksumming calculations.
Seems like a good idea in view of 0065174 and addd034. Michael Paquier, Tom Lane Discussion: https://postgr.es/m/20200306075230.GA118430@paquier.xyz
1 parent b0b5e20 commit 38ce06c

File tree

4 files changed

+112
-1
lines changed

4 files changed

+112
-1
lines changed

contrib/pageinspect/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ DATA = pageinspect--1.7--1.8.sql pageinspect--1.6--1.7.sql \
1919
pageinspect--1.0--1.1.sql
2020
PGFILEDESC = "pageinspect - functions to inspect contents of database pages"
2121

22-
REGRESS = page btree brin gin hash
22+
REGRESS = page btree brin gin hash checksum
2323

2424
ifdef USE_PGXS
2525
PG_CONFIG = pg_config
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
--
2+
-- Verify correct calculation of checksums
3+
--
4+
-- Postgres' checksum algorithm produces different answers on little-endian
5+
-- and big-endian machines. The results of this test also vary depending
6+
-- on the configured block size. This test has several different expected
7+
-- results files to handle the following possibilities:
8+
--
9+
-- BLCKSZ end file
10+
-- 8K LE checksum.out
11+
-- 8K BE checksum_1.out
12+
--
13+
-- In future we might provide additional expected-results files for other
14+
-- block sizes, but there seems little point as long as so many other
15+
-- test scripts also show false failures for non-default block sizes.
16+
--
17+
-- This is to label the results files with blocksize:
18+
SHOW block_size;
19+
block_size
20+
------------
21+
8192
22+
(1 row)
23+
24+
SHOW block_size \gset
25+
-- Apply page_checksum() to some different data patterns and block numbers
26+
SELECT blkno,
27+
page_checksum(decode(repeat('01', :block_size), 'hex'), blkno) AS checksum_01,
28+
page_checksum(decode(repeat('04', :block_size), 'hex'), blkno) AS checksum_04,
29+
page_checksum(decode(repeat('ff', :block_size), 'hex'), blkno) AS checksum_ff,
30+
page_checksum(decode(repeat('abcd', :block_size / 2), 'hex'), blkno) AS checksum_abcd,
31+
page_checksum(decode(repeat('e6d6', :block_size / 2), 'hex'), blkno) AS checksum_e6d6,
32+
page_checksum(decode(repeat('4a5e', :block_size / 2), 'hex'), blkno) AS checksum_4a5e
33+
FROM generate_series(0, 100, 50) AS a (blkno);
34+
blkno | checksum_01 | checksum_04 | checksum_ff | checksum_abcd | checksum_e6d6 | checksum_4a5e
35+
-------+-------------+-------------+-------------+---------------+---------------+---------------
36+
0 | 1175 | 28338 | 3612 | -30781 | -16269 | -27377
37+
50 | 1225 | 28352 | 3598 | -30795 | -16251 | -27391
38+
100 | 1139 | 28438 | 3648 | -30881 | -16305 | -27349
39+
(3 rows)
40+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
--
2+
-- Verify correct calculation of checksums
3+
--
4+
-- Postgres' checksum algorithm produces different answers on little-endian
5+
-- and big-endian machines. The results of this test also vary depending
6+
-- on the configured block size. This test has several different expected
7+
-- results files to handle the following possibilities:
8+
--
9+
-- BLCKSZ end file
10+
-- 8K LE checksum.out
11+
-- 8K BE checksum_1.out
12+
--
13+
-- In future we might provide additional expected-results files for other
14+
-- block sizes, but there seems little point as long as so many other
15+
-- test scripts also show false failures for non-default block sizes.
16+
--
17+
-- This is to label the results files with blocksize:
18+
SHOW block_size;
19+
block_size
20+
------------
21+
8192
22+
(1 row)
23+
24+
SHOW block_size \gset
25+
-- Apply page_checksum() to some different data patterns and block numbers
26+
SELECT blkno,
27+
page_checksum(decode(repeat('01', :block_size), 'hex'), blkno) AS checksum_01,
28+
page_checksum(decode(repeat('04', :block_size), 'hex'), blkno) AS checksum_04,
29+
page_checksum(decode(repeat('ff', :block_size), 'hex'), blkno) AS checksum_ff,
30+
page_checksum(decode(repeat('abcd', :block_size / 2), 'hex'), blkno) AS checksum_abcd,
31+
page_checksum(decode(repeat('e6d6', :block_size / 2), 'hex'), blkno) AS checksum_e6d6,
32+
page_checksum(decode(repeat('4a5e', :block_size / 2), 'hex'), blkno) AS checksum_4a5e
33+
FROM generate_series(0, 100, 50) AS a (blkno);
34+
blkno | checksum_01 | checksum_04 | checksum_ff | checksum_abcd | checksum_e6d6 | checksum_4a5e
35+
-------+-------------+-------------+-------------+---------------+---------------+---------------
36+
0 | -16327 | 8766 | -2722 | 13757 | -11485 | -31426
37+
50 | -16281 | 8780 | -2708 | 13771 | -11503 | -31440
38+
100 | -16235 | 8866 | -2758 | 13721 | -11577 | -31518
39+
(3 rows)
40+

contrib/pageinspect/sql/checksum.sql

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--
2+
-- Verify correct calculation of checksums
3+
--
4+
-- Postgres' checksum algorithm produces different answers on little-endian
5+
-- and big-endian machines. The results of this test also vary depending
6+
-- on the configured block size. This test has several different expected
7+
-- results files to handle the following possibilities:
8+
--
9+
-- BLCKSZ end file
10+
-- 8K LE checksum.out
11+
-- 8K BE checksum_1.out
12+
--
13+
-- In future we might provide additional expected-results files for other
14+
-- block sizes, but there seems little point as long as so many other
15+
-- test scripts also show false failures for non-default block sizes.
16+
--
17+
18+
-- This is to label the results files with blocksize:
19+
SHOW block_size;
20+
21+
SHOW block_size \gset
22+
23+
-- Apply page_checksum() to some different data patterns and block numbers
24+
SELECT blkno,
25+
page_checksum(decode(repeat('01', :block_size), 'hex'), blkno) AS checksum_01,
26+
page_checksum(decode(repeat('04', :block_size), 'hex'), blkno) AS checksum_04,
27+
page_checksum(decode(repeat('ff', :block_size), 'hex'), blkno) AS checksum_ff,
28+
page_checksum(decode(repeat('abcd', :block_size / 2), 'hex'), blkno) AS checksum_abcd,
29+
page_checksum(decode(repeat('e6d6', :block_size / 2), 'hex'), blkno) AS checksum_e6d6,
30+
page_checksum(decode(repeat('4a5e', :block_size / 2), 'hex'), blkno) AS checksum_4a5e
31+
FROM generate_series(0, 100, 50) AS a (blkno);

0 commit comments

Comments
 (0)