Skip to content

Commit

Permalink
Add TAP testsuite
Browse files Browse the repository at this point in the history
  • Loading branch information
mbanck-ntap committed May 7, 2018
1 parent a81c7c5 commit f3a560a
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,16 @@ PGAPPICON=win32

OBJS= pg_checksums.o $(WIN32RES)
PG_LIBS = $(libpq_pgport)
EXTRA_CLEAN = tmp_check

PG_CONFIG ?= pg_config
PGXS = $(shell $(PG_CONFIG) --pgxs)
include $(PGXS)

all: pg_checksums

prove_installcheck: install
rm -rf $(CURDIR)/tmp_check
cd $(srcdir) && TESTDIR='$(CURDIR)' PATH="$(bindir):$$PATH" PGPORT='6$(DEF_PGPORT)' PG_REGRESS='$(top_builddir)/src/test/regress/pg_regress' $(PROVE) $(PG_PROVE_FLAGS) $(PROVE_FLAGS) $(if $(PROVE_TESTS),$(PROVE_TESTS),t/*.pl)

installcheck: prove_installcheck
81 changes: 81 additions & 0 deletions t/001_checksums.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/usr/bin/env perl

use strict;
use warnings;
use Cwd;
use Config;
use PostgresNode;
use TestLib;
use Test::More tests => 19;

program_help_ok('pg_checksums');
program_version_ok('pg_checksums');
program_options_handling_ok('pg_checksums');

my $tempdir = TestLib::tempdir;

# Initialize node
my $node = get_new_node('main');
$node->init(allows_streaming => 1);

$node->start;
my $pgdata = $node->data_dir;

$node->command_fails(['pg_checksums', '-c'],
'pg_checksums needs needs target directory specified');

$node->command_fails(['pg_checksums', '-c', '-D', $pgdata],
'pg_checksums needs to run against offfline cluster');

my $checksum = $node->safe_psql('postgres', 'SHOW data_checksums;');
is($checksum, 'off', 'checksums are disabled');

$node->stop;

$node->command_ok(['pg_checksums', '-a', '-D', $pgdata],
'pg_checksums are activated in offline cluster');

$node->start;

$checksum = $node->safe_psql('postgres', 'SHOW data_checksums;');
is($checksum, 'on', 'checksums are enabled');

$node->stop;

$node->command_ok(['pg_checksums', '-b', '-D', $pgdata],
'pg_checksums are deactivated in offline cluster');

$node->start;

$checksum = $node->safe_psql('postgres', 'SHOW data_checksums;');
is($checksum, 'off', 'checksums are disabled');

$node->stop;

$node->command_ok(['pg_checksums', '-a', '-D', $pgdata],
'pg_checksums are again activated in offline cluster');

$node->start;

# create table to corrupt and get their relfilenode
my $file_corrupt = $node->safe_psql('postgres',
q{SELECT a INTO corrupt1 FROM generate_series(1,10000) AS a; ALTER TABLE corrupt1 SET (autovacuum_enabled=false); SELECT pg_relation_filepath('corrupt1')}
);

# set page header and block sizes
my $pageheader_size = 24;
my $block_size = $node->safe_psql('postgres', 'SHOW block_size;');

# induce corruption
$node->stop;
open my $file, '+<', "$pgdata/$file_corrupt";
seek($file, $pageheader_size, 0);
syswrite($file, '\0\0\0\0\0\0\0\0\0');
close $file;

$node->command_checks_all([ 'pg_checksums', '-c', '-D', $pgdata],
1,
[qr/Bad checksums: 1/s],
[qr/checksum verification failed/s],
'pg_checksums reports checksum mismatch'
);

0 comments on commit f3a560a

Please sign in to comment.