Skip to content

Commit 610bbdd

Browse files
committed
Add a test harness for the red-black tree code.
This improves the regression tests' coverage of rbtree.c from pretty awful (because some of the functions aren't used yet) to basically 100%. Victor Drobny, reviewed by Aleksander Alekseev and myself Discussion: https://postgr.es/m/c9d61310e16e75f8acaf6cb1c48b7b77@postgrespro.ru
1 parent f80e782 commit 610bbdd

File tree

9 files changed

+484
-0
lines changed

9 files changed

+484
-0
lines changed

src/test/modules/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ SUBDIRS = \
1313
test_extensions \
1414
test_parser \
1515
test_pg_dump \
16+
test_rbtree \
1617
test_rls_hooks \
1718
test_shm_mq \
1819
worker_spi
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Generated subdirectories
2+
/log/
3+
/results/
4+
/tmp_check/

src/test/modules/test_rbtree/Makefile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# src/test/modules/test_rbtree/Makefile
2+
3+
MODULE_big = test_rbtree
4+
OBJS = test_rbtree.o $(WIN32RES)
5+
PGFILEDESC = "test_rbtree - test code for red-black tree library"
6+
7+
EXTENSION = test_rbtree
8+
DATA = test_rbtree--1.0.sql
9+
10+
REGRESS = test_rbtree
11+
12+
ifdef USE_PGXS
13+
PG_CONFIG = pg_config
14+
PGXS := $(shell $(PG_CONFIG) --pgxs)
15+
include $(PGXS)
16+
else
17+
subdir = src/test/modules/test_rbtree
18+
top_builddir = ../../../..
19+
include $(top_builddir)/src/Makefile.global
20+
include $(top_srcdir)/contrib/contrib-global.mk
21+
endif

src/test/modules/test_rbtree/README

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
test_rbtree is a test module for checking the correctness of red-black
2+
tree operations.
3+
4+
These tests are performed on red-black trees that store integers.
5+
Since the rbtree logic treats the comparison function as a black
6+
box, it shouldn't be important exactly what the key type is.
7+
8+
Checking the correctness of traversals is based on the fact that a red-black
9+
tree is a binary search tree, so the elements should be visited in increasing
10+
(for Left-Current-Right) or decreasing (for Right-Current-Left) order.
11+
12+
Also, this module does some checks of the correctness of the find, delete
13+
and leftmost operations.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CREATE EXTENSION test_rbtree;
2+
--
3+
-- These tests don't produce any interesting output. We're checking that
4+
-- the operations complete without crashing or hanging and that none of their
5+
-- internal sanity tests fail.
6+
--
7+
SELECT test_rb_tree(10000);
8+
test_rb_tree
9+
--------------
10+
11+
(1 row)
12+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CREATE EXTENSION test_rbtree;
2+
3+
--
4+
-- These tests don't produce any interesting output. We're checking that
5+
-- the operations complete without crashing or hanging and that none of their
6+
-- internal sanity tests fail.
7+
--
8+
SELECT test_rb_tree(10000);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/* src/test/modules/test_rbtree/test_rbtree--1.0.sql */
2+
3+
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
4+
\echo Use "CREATE EXTENSION test_rbtree" to load this file. \quit
5+
6+
CREATE FUNCTION test_rb_tree(size INTEGER)
7+
RETURNS pg_catalog.void STRICT
8+
AS 'MODULE_PATHNAME' LANGUAGE C;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy