Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
2 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
CREATE EXTENSION test_cfs;
 
-- The CRC-corruption test case intentionally triggers a WARNING from
-- CfsVerifyBlockHeader(); suppress client warnings so the regression output
-- stays deterministic.
SET client_min_messages = error;
 
-- Run all CFS codec tests.  A "skip" result (codec not compiled in) is
-- acceptable, but no test case may report "fail".
SELECT count(*) AS failures
FROM cfs_run_tests()
WHERE result = 'fail';
 
-- The core test cases must always pass regardless of build configuration.
SELECT count(*) AS core_failures
FROM cfs_run_tests()
WHERE test_name IN ('codec_max_level',
                    'compress_page_size_rejected',
                    'crc_corruption_detection',
                    'decompress_original_size_rejected',
                    'default_level_for',
                    'default_write_opts_level',
                    'incompressible_raw_fallback',
                    'policy_flags_roundtrip',
                    'raw_codec_roundtrip',
                    'raw_page_roundtrip',
                    'record_padding_zeroed',
                    'scratch_and_alignment')
  AND result <> 'ok';
 
SELECT test_cfs_codec_available('raw') AS raw_available;
 
SELECT test_cfs_roundtrip('raw', decode('7b22636673223a747275657d', 'hex'), 1) AS raw_roundtrip;
 
SELECT test_cfs_corrupt_crc('raw') AS raw_corrupt_crc;
 
-- Extended codec tests are mandatory in the four-codec CFS profile:
-- 6 direct contract cases per codec; missing cases and skips both fail.
SELECT count(*) = 12 AND bool_and(result = 'ok') AS pglz_zlib_direct_ok
FROM cfs_run_tests()
WHERE test_name LIKE 'pglz_%' OR test_name LIKE 'zlib_%';
 
SELECT test_cfs_codec_available('pglz') AS pglz_available,
       test_cfs_codec_available('zlib') AS zlib_available;
 
SELECT test_cfs_roundtrip('pglz', decode('7b2261223a317d', 'hex'), 1) AS pglz_page_roundtrip,
       test_cfs_roundtrip('zlib', decode('7b2261223a317d', 'hex'), 1) AS zlib_page_roundtrip;
 
SELECT test_cfs_corrupt_crc('pglz') = 'ok' AS pglz_page_crc,
       test_cfs_corrupt_crc('zlib') = 'ok' AS zlib_page_crc;
 
-- Pin the diagnostic contract of the corruption path: the deliberate CRC
-- corruption must emit a WARNING naming the CRC mismatch before the
-- function reports the detected corruption.  The corrupted data_crc is
-- covered by the header CRC, so the decompressor trips over the header
-- check; the raw codec makes both CRC values deterministic (the payload is
-- the verbatim 0x7F-filled page), so the exact hex values are stable across
-- runs and builds.  Pinning the absolute values is deliberate: they pin
-- the on-disk record/header layout itself, so a future format change
-- (fields, alignment) is expected to break this output and must be
-- acknowledged by recomputing it, not by loosening the check.
SET client_min_messages = warning;
SELECT test_cfs_corrupt_crc('raw') AS raw_corrupt_crc_diagnostics;