MCPcopy Create free account
hub / github.com/apache/cloudberry / test_pattern

Function test_pattern

src/test/modules/test_integerset/test_integerset.c:133–315  ·  view source on GitHub ↗

* Test with a repeating pattern, defined by the 'spec'. */

Source from the content-addressed store, hash-verified

131 * Test with a repeating pattern, defined by the 'spec'.
132 */
133static void
134test_pattern(const test_spec *spec)
135{
136 IntegerSet *intset;
137 MemoryContext intset_ctx;
138 MemoryContext old_ctx;
139 TimestampTz starttime;
140 TimestampTz endtime;
141 uint64 n;
142 uint64 last_int;
143 int patternlen;
144 uint64 *pattern_values;
145 uint64 pattern_num_values;
146
147 elog(NOTICE, "testing intset with pattern \"%s\"", spec->test_name);
148 if (intset_test_stats)
149 fprintf(stderr, "-----\ntesting intset with pattern \"%s\"\n", spec->test_name);
150
151 /* Pre-process the pattern, creating an array of integers from it. */
152 patternlen = strlen(spec->pattern_str);
153 pattern_values = palloc(patternlen * sizeof(uint64));
154 pattern_num_values = 0;
155 for (int i = 0; i < patternlen; i++)
156 {
157 if (spec->pattern_str[i] == '1')
158 pattern_values[pattern_num_values++] = i;
159 }
160
161 /*
162 * Allocate the integer set.
163 *
164 * Allocate it in a separate memory context, so that we can print its
165 * memory usage easily. (intset_create() creates a memory context of its
166 * own, too, but we don't have direct access to it, so we cannot call
167 * MemoryContextStats() on it directly).
168 */
169 intset_ctx = AllocSetContextCreate(CurrentMemoryContext,
170 "intset test",
171 ALLOCSET_SMALL_SIZES);
172 MemoryContextSetIdentifier(intset_ctx, spec->test_name);
173 old_ctx = MemoryContextSwitchTo(intset_ctx);
174 intset = intset_create();
175 MemoryContextSwitchTo(old_ctx);
176
177 /*
178 * Add values to the set.
179 */
180 starttime = GetCurrentTimestamp();
181
182 n = 0;
183 last_int = 0;
184 while (n < spec->num_values)
185 {
186 uint64 x = 0;
187
188 for (int i = 0; i < pattern_num_values && n < spec->num_values; i++)
189 {
190 x = last_int + pattern_values[i];

Callers 1

test_integersetFunction · 0.85

Calls 13

MemoryContextSwitchToFunction · 0.85
intset_createFunction · 0.85
GetCurrentTimestampFunction · 0.85
intset_add_memberFunction · 0.85
intset_memory_usageFunction · 0.85
MemoryContextStatsFunction · 0.85
intset_num_entriesFunction · 0.85
pg_lrand48Function · 0.85
intset_is_memberFunction · 0.85
intset_begin_iterateFunction · 0.85
intset_iterate_nextFunction · 0.85

Tested by

no test coverage detected