Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb4712b0

Browse files
committed
move various print functions to debug_print.c, add cmocka-based unit test system
1 parentce86f41 commitb4712b0

File tree

10 files changed

+670
-85
lines changed

10 files changed

+670
-85
lines changed

‎Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ OBJS = src/init.o src/relation_info.o src/utils.o src/partition_filter.o \
55
src/runtimeappend.o src/runtime_merge_append.o src/pg_pathman.o src/rangeset.o\
66
src/pl_funcs.o src/pl_range_funcs.o src/pl_hash_funcs.o src/pathman_workers.o\
77
src/hooks.o src/nodes_common.o src/xact_handling.o src/copy_stmt_hooking.o\
8-
src/pg_compat.o$(WIN32RES)
8+
src/debug_print.o src/pg_compat.o$(WIN32RES)
99

1010
EXTENSION = pg_pathman
1111
EXTVERSION = 1.1

‎src/debug_print.c

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/* ------------------------------------------------------------------------
2+
*
3+
* debug_print.c
4+
*Print sophisticated structs as CSTRING
5+
*
6+
* Copyright (c) 2016, Postgres Professional
7+
*
8+
* ------------------------------------------------------------------------
9+
*/
10+
11+
#include"rangeset.h"
12+
13+
#include"postgres.h"
14+
#include"nodes/bitmapset.h"
15+
#include"nodes/pg_list.h"
16+
#include"lib/stringinfo.h"
17+
18+
19+
/*
20+
* Print Bitmapset as cstring.
21+
*/
22+
#ifdef__GNUC__
23+
__attribute__((unused))
24+
#endif
25+
staticchar*
26+
bms_print(Bitmapset*bms)
27+
{
28+
StringInfoDatastr;
29+
intx;
30+
31+
initStringInfo(&str);
32+
x=-1;
33+
while ((x=bms_next_member(bms,x)) >=0)
34+
appendStringInfo(&str," %d",x);
35+
36+
returnstr.data;
37+
}
38+
39+
/*
40+
* Print list of IndexRanges as cstring.
41+
*/
42+
#ifdef__GNUC__
43+
__attribute__((unused))
44+
#endif
45+
staticchar*
46+
rangeset_print(List*rangeset)
47+
{
48+
StringInfoDatastr;
49+
ListCell*lc;
50+
boolfirst_irange= true;
51+
charlossy='L',/* Lossy IndexRange */
52+
complete='C';/* Complete IndexRange */
53+
54+
initStringInfo(&str);
55+
56+
foreach (lc,rangeset)
57+
{
58+
IndexRangeirange=lfirst_irange(lc);
59+
60+
/* Append comma if needed */
61+
if (!first_irange)
62+
appendStringInfo(&str,", ");
63+
64+
if (!is_irange_valid(irange))
65+
appendStringInfo(&str,"X");
66+
elseif (irange_lower(irange)==irange_upper(irange))
67+
appendStringInfo(&str,"%u%c",
68+
irange_lower(irange),
69+
(is_irange_lossy(irange) ?lossy :complete));
70+
else
71+
appendStringInfo(&str,"[%u-%u]%c",
72+
irange_lower(irange),irange_upper(irange),
73+
(is_irange_lossy(irange) ?lossy :complete));
74+
75+
first_irange= false;
76+
}
77+
78+
returnstr.data;
79+
}
80+
81+
/*
82+
* Print IndexRange struct as cstring.
83+
*/
84+
#ifdef__GNUC__
85+
__attribute__((unused))
86+
#endif
87+
staticchar*
88+
irange_print(IndexRangeirange)
89+
{
90+
StringInfoDatastr;
91+
92+
initStringInfo(&str);
93+
94+
appendStringInfo(&str,"{ valid: %s, lossy: %s, lower: %u, upper: %u }",
95+
(is_irange_valid(irange) ?"true" :"false"),
96+
(is_irange_lossy(irange) ?"true" :"false"),
97+
irange_lower(irange),
98+
irange_upper(irange));
99+
100+
returnstr.data;
101+
}

‎src/utils.c

Lines changed: 0 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -156,90 +156,6 @@ lock_rows_visitor(Plan *plan, void *context)
156156
}
157157
}
158158

159-
/*
160-
* Print Bitmapset as cstring.
161-
*/
162-
#ifdef__GNUC__
163-
__attribute__((unused))
164-
#endif
165-
staticchar*
166-
bms_print(Bitmapset*bms)
167-
{
168-
StringInfoDatastr;
169-
intx;
170-
171-
initStringInfo(&str);
172-
x=-1;
173-
while ((x=bms_next_member(bms,x)) >=0)
174-
appendStringInfo(&str," %d",x);
175-
176-
returnstr.data;
177-
}
178-
179-
/*
180-
* Print list of IndexRanges as cstring.
181-
*/
182-
#ifdef__GNUC__
183-
__attribute__((unused))
184-
#endif
185-
staticchar*
186-
rangeset_print(List*rangeset)
187-
{
188-
StringInfoDatastr;
189-
ListCell*lc;
190-
boolfirst_irange= true;
191-
charlossy='L',/* Lossy IndexRange */
192-
complete='C';/* Complete IndexRange */
193-
194-
initStringInfo(&str);
195-
196-
foreach (lc,rangeset)
197-
{
198-
IndexRangeirange=lfirst_irange(lc);
199-
200-
/* Append comma if needed */
201-
if (!first_irange)
202-
appendStringInfo(&str,", ");
203-
204-
if (!is_irange_valid(irange))
205-
appendStringInfo(&str,"X");
206-
elseif (irange_lower(irange)==irange_upper(irange))
207-
appendStringInfo(&str,"%u%c",
208-
irange_lower(irange),
209-
(is_irange_lossy(irange) ?lossy :complete));
210-
else
211-
appendStringInfo(&str,"[%u-%u]%c",
212-
irange_lower(irange),irange_upper(irange),
213-
(is_irange_lossy(irange) ?lossy :complete));
214-
215-
first_irange= false;
216-
}
217-
218-
returnstr.data;
219-
}
220-
221-
/*
222-
* Print IndexRange struct as cstring.
223-
*/
224-
#ifdef__GNUC__
225-
__attribute__((unused))
226-
#endif
227-
staticchar*
228-
irange_print(IndexRangeirange)
229-
{
230-
StringInfoDatastr;
231-
232-
initStringInfo(&str);
233-
234-
appendStringInfo(&str,"{ valid: %s, lossy: %s, lower: %u, upper: %u }",
235-
(is_irange_valid(irange) ?"true" :"false"),
236-
(is_irange_lossy(irange) ?"true" :"false"),
237-
irange_lower(irange),
238-
irange_upper(irange));
239-
240-
returnstr.data;
241-
}
242-
243159
/*
244160
* Get BTORDER_PROC for two types described by Oids
245161
*/

‎tests/cmocka/Makefile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
PG_CONFIG = pg_config
2+
TOP_SRC_DIR = ../../src
3+
4+
CC = gcc
5+
CFLAGS = -I$(TOP_SRC_DIR) -I$(shell$(PG_CONFIG) --includedir-server)
6+
LDFLAGS = -lcmocka
7+
TEST_BIN = rangeset_tests
8+
9+
OBJ = missing_basic.o missing_list.o missing_stringinfo.o\
10+
missing_bitmapset.o rangeset_tests.o\
11+
$(TOP_SRC_DIR)/rangeset.o
12+
13+
14+
all: build_extension$(TEST_BIN)
15+
16+
$(TEST_BIN):$(OBJ)
17+
$(CC) -o$@$^$(CFLAGS)$(LDFLAGS)
18+
19+
%.o:%.c
20+
$(CC) -c -o$@$<$(CFLAGS)
21+
22+
build_extension:
23+
$(MAKE) -C$(TOP_SRC_DIR)/..
24+
25+
clean:
26+
rm -f$(OBJ)$(TEST_BIN)

‎tests/cmocka/missing_basic.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#include<stdio.h>
2+
3+
#include"postgres.h"
4+
5+
6+
void*
7+
palloc(Sizesize)
8+
{
9+
returnmalloc(size);
10+
}
11+
12+
void*
13+
repalloc(void*pointer,Sizesize)
14+
{
15+
returnrealloc(pointer,size);
16+
}
17+
18+
19+
void
20+
ExceptionalCondition(constchar*conditionName,
21+
constchar*errorType,
22+
constchar*fileName,
23+
intlineNumber)
24+
{
25+
if (!PointerIsValid(conditionName)||
26+
!PointerIsValid(fileName)||
27+
!PointerIsValid(errorType))
28+
{
29+
printf("TRAP: ExceptionalCondition: bad arguments\n");
30+
}
31+
else
32+
{
33+
printf("TRAP: %s(\"%s\", File: \"%s\", Line: %d)\n",
34+
errorType,conditionName,
35+
fileName,lineNumber);
36+
37+
}
38+
39+
/* Usually this shouldn't be needed, but make sure the msg went out */
40+
fflush(stderr);
41+
42+
abort();
43+
}

‎tests/cmocka/missing_bitmapset.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include"postgres.h"
2+
#include"nodes/bitmapset.h"
3+
4+
5+
int
6+
bms_next_member(constBitmapset*a,intprevbit);
7+
8+
9+
int
10+
bms_next_member(constBitmapset*a,intprevbit)
11+
{
12+
printf("bms_next_member(): not implemented yet\n");
13+
fflush(stdout);
14+
15+
abort();
16+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp