Skip to content

Commit 8e0b332

Browse files
committed
more tests
replace_user_str path UDF gufi_vt bad integer conversion gufi_vt_* all NULL args (except indexroot) fix NULL remote args remove addqueryfunc checks gufi_dir2index gufi_rollup with missing db.db
1 parent 1e68e58 commit 8e0b332

15 files changed

+198
-48
lines changed

src/gufi_query/PoolArgs.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,7 @@ int PoolArgs_init(PoolArgs_t *pa, struct input *in, pthread_mutex_t *global_mute
148148
break;
149149
}
150150

151-
if (addqueryfuncs(ta->outdb) != 0) {
152-
fprintf(stderr, "Error: Could not add functions to sqlite\n");
153-
break;
154-
}
151+
addqueryfuncs(ta->outdb);
155152

156153
/* user string storage */
157154
ta->user_strs = trie_alloc();

src/gufi_query/handle_sql.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,8 @@ static int gen_types(struct input *in) {
174174
setup_xattrs_views(in, db, &work, &count);
175175
}
176176

177-
if ((addqueryfuncs(db) != 0) ||
178-
(addqueryfuncs_with_context(db, &ctx) != 0)) {
179-
goto error;
180-
}
177+
addqueryfuncs(db);
178+
addqueryfuncs_with_context(db, &ctx);
181179

182180
if (in->sql.tsum.len) {
183181
if (create_table_wrapper(SQLITE_MEMORY, db, TREESUMMARY, TREESUMMARY_CREATE) != SQLITE_OK) {

src/gufi_vt.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,14 +1291,16 @@ static int gufi_vtFilter(sqlite3_vtab_cursor *cur,
12911291

12921292
if (argc > GUFI_VT_ARGS_REMOTE_ARGS) {
12931293
char *remote_args = (char *) sqlite3_value_text(argv[GUFI_VT_ARGS_REMOTE_ARGS]);
1294-
char *saveptr = NULL;
1295-
char *remote_arg = strtok_r(remote_args, " ", &saveptr); /* skip multiple contiguous spaces */
1296-
while (remote_arg) {
1297-
str_t *ra = calloc(1, sizeof(*ra));
1298-
set_refstr(ra, remote_arg);
1299-
sll_push_back(&vtab->cmd.remote_args, ra);
1300-
1301-
remote_arg = strtok_r(NULL, " ", &saveptr);
1294+
if (remote_args) {
1295+
char *saveptr = NULL;
1296+
char *remote_arg = strtok_r(remote_args, " ", &saveptr); /* skip multiple contiguous spaces */
1297+
while (remote_arg) {
1298+
str_t *ra = calloc(1, sizeof(*ra));
1299+
set_refstr(ra, remote_arg);
1300+
sll_push_back(&vtab->cmd.remote_args, ra);
1301+
1302+
remote_arg = strtok_r(NULL, " ", &saveptr);
1303+
}
13021304
}
13031305
}
13041306
}
@@ -1482,9 +1484,7 @@ int sqlite3_gufivt_init(
14821484

14831485
SQLITE_EXTENSION_INIT2(pApi);
14841486

1485-
if (addqueryfuncs(db) != 0) {
1486-
return SQLITE_ERROR;
1487-
}
1487+
addqueryfuncs(db);
14881488

14891489
/* fixed schemas - SELECT directly from these */
14901490
create_module("gufi_vt_treesummary", NULL, gufi_vt_TConnect);

test/regression/gufi_dir2index.expected

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -357,26 +357,33 @@ prefix/unusual#? directory ,/unusual, name?#
357357

358358
# ######################################
359359

360-
# target is file
361-
$ gufi_dir2index -n 2 "prefix" "prefix/1KB"
362-
"prefix/1KB" Already exists!
363-
Destination path is not a directory "prefix/1KB"
360+
# no source path
361+
$ gufi_dir2index -n 2 "search"
362+
Creating GUFI tree search with 2 threads
363+
Error: At least one root is needed
364+
365+
# empty source path
366+
$ gufi_dir2index -n 2 "" "search"
367+
"search" Already exists!
368+
Creating GUFI tree search with 2 threads
369+
Could not stat source directory "": No such file or directory (2)
370+
Total Dirs: 0
371+
Total Non-Dirs: 0
364372

365373
# source path is file
366374
$ gufi_dir2index -n 2 "prefix/1KB" "search"
375+
"search" Already exists!
367376
Creating GUFI tree search with 2 threads
368377
Source path is not a directory "prefix/1KB"
369378
Total Dirs: 0
370379
Total Non-Dirs: 0
371380

372-
# empty source path
373-
$ gufi_dir2index -n 2 "" "trace"
374-
Creating GUFI tree trace with 2 threads
375-
Could not stat source directory "": No such file or directory (2)
376-
Total Dirs: 0
377-
Total Non-Dirs: 0
381+
# destination is file
382+
$ gufi_dir2index -n 2 "prefix" "prefix/1KB"
383+
"prefix/1KB" Already exists!
384+
Destination path is not a directory "prefix/1KB"
378385

379-
# desintation path contains a file in a path segment
386+
# destination path contains a file in a path segment
380387
$ gufi_dir2index -n 2 "prefix" "prefix/1KB/search"
381388
Could not create prefix/1KB/search
382389

test/regression/gufi_dir2index.sh.in

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,18 +207,21 @@ echo
207207

208208
rm -r "${SEARCH}"
209209

210-
echo "# target is file"
211-
run_no_sort "${GUFI_DIR2INDEX} -n ${THREADS} \"${SRCDIR}\" \"${SRCDIR}/1KB\""
210+
echo "# no source path"
211+
run_no_sort "${GUFI_DIR2INDEX} -n ${THREADS} \"${SEARCH}\""
212+
213+
echo "# empty source path"
214+
run_no_sort "${GUFI_DIR2INDEX} -n ${THREADS} \"\" \"${SEARCH}\""
212215

213216
echo "# source path is file"
214217
# shellcheck disable=SC2046,SC2086
215218
PARENT="$(dirname $(realpath ${SRCDIR}))"
216219
run_no_sort "${GUFI_DIR2INDEX} -n ${THREADS} \"${SRCDIR}/1KB\" \"${SEARCH}\"" | @SED@ "s%${PARENT}/%%g;"
217220

218-
echo "# empty source path"
219-
run_no_sort "${GUFI_DIR2INDEX} -n ${THREADS} \"\" \"${TRACE}\""
221+
echo "# destination is file"
222+
run_no_sort "${GUFI_DIR2INDEX} -n ${THREADS} \"${SRCDIR}\" \"${SRCDIR}/1KB\""
220223

221-
echo "# desintation path contains a file in a path segment"
224+
echo "# destination path contains a file in a path segment"
222225
run_no_sort "${GUFI_DIR2INDEX} -n ${THREADS} \"${SRCDIR}\" \"${SRCDIR}/1KB/${SEARCH}\""
223226

224227
echo "# skip file"

test/regression/gufi_rollup.expected

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1852,6 +1852,28 @@ $ gufi_query -d "|" --query-xattrs -S "SELECT path(), rpath(sname, sroll), isroo
18521852
prefix/directory/subdirectory|prefix/directory/subdirectory|1|0|user.name|sub
18531853
prefix/directory/subdirectory|prefix/directory/subdirectory|1|0|user.type|dir
18541854

1855+
Creating GUFI tree search with 1 threads
1856+
Total Dirs: 6
1857+
Total Non-Dirs: 14
1858+
# Remove prefix/directory/db.db
1859+
$ rm prefix/directory/db.db
1860+
1861+
# Rollup succeeds except at prefix/directory
1862+
# Two error messages: one while processing directory, one while processing parent
1863+
$ gufi_rollup "search" > /dev/null
1864+
Cannot open database: prefix/directory/db.db unable to open database file rc 14
1865+
Cannot open database: prefix/directory/db.db unable to open database file rc 14
1866+
1867+
# prefix/directory wasn't rolled up, so have to traverse entire tree
1868+
$ gufi_query -d "|" --query-xattrs -S "SELECT path(), rpath(sname, sroll), isroot, rollupscore, xattr_name, xattr_value FROM vrxsummary;" "prefix"
1869+
prefix/directory/subdirectory|prefix/directory/subdirectory|1|1|user.name|sub
1870+
prefix/directory/subdirectory|prefix/directory/subdirectory|1|1|user.type|dir
1871+
prefix/empty_directory|prefix/empty_directory|1|1||
1872+
prefix/leaf_directory|prefix/leaf_directory|1|1|user.name|leaf
1873+
prefix/leaf_directory|prefix/leaf_directory|1|1|user.type|dir
1874+
prefix/unusual#? directory ,|prefix/unusual#? directory ,|1|1||
1875+
prefix|prefix|1|0||
1876+
18551877
# bad thread count
18561878
$ gufi_rollup -n 18446744073709551615 "search"
18571879
Could not allocate 18446744073709551615 stat buffers

test/regression/gufi_rollup.sh.in

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,23 @@ rm -rf "${SEARCH}"
260260
run_sort "${GUFI_QUERY} -d \"${DELIM}\" --query-xattrs -S \"SELECT path(), rpath(sname, sroll), isroot, rollupscore, xattr_name, xattr_value FROM vrxsummary;\" \"${INDEXROOT}/directory/subdirectory\""
261261
}
262262

263+
rm -rf "${SEARCH}"
264+
265+
"${GUFI_DIR2INDEX}" --index-xattrs "${SRCDIR}" "${SEARCH}" 2>&1
266+
267+
# db.db disappeared from a directory
268+
{
269+
echo "# Remove ${INDEXROOT}/directory/db.db"
270+
run_no_sort "rm ${INDEXROOT}/directory/db.db"
271+
272+
echo "# Rollup succeeds except at ${INDEXROOT}/directory"
273+
echo "# Two error messages: one while processing directory, one while processing parent"
274+
run_no_sort "${GUFI_ROLLUP} \"${SEARCH}\" > /dev/null"
275+
276+
echo "# ${INDEXROOT}/directory wasn't rolled up, so have to traverse entire tree"
277+
run_sort "${GUFI_QUERY} -d \"${DELIM}\" --query-xattrs -S \"SELECT path(), rpath(sname, sroll), isroot, rollupscore, xattr_name, xattr_value FROM vrxsummary;\" \"${INDEXROOT}\""
278+
}
279+
263280
echo "# bad thread count"
264281
run_no_sort "${GUFI_ROLLUP} -n 18446744073709551615 \"${SEARCH}\""
265282
) | remove_indexing_time | replace | tee "${OUTPUT}"

test/regression/gufi_vt.common

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,6 @@ run_tests() {
9292
echo "# Missing thread count (not an error)"
9393
"${func}" "SELECT name FROM gufi_vt_pentries('${INDEXROOT}') ORDER BY name ASC, size ASC;"
9494

95-
echo "# NULL thread count (not an error)"
96-
"${func}" "SELECT name FROM gufi_vt_pentries('${INDEXROOT}', NULL) ORDER BY name ASC, size ASC;"
95+
echo "# NULL arguments (not an error)"
96+
"${func}" "SELECT name FROM gufi_vt_pentries('${INDEXROOT}', NULL, NULL, NULL, NULL, NULL, NULL, NULL) ORDER BY name ASC, size ASC;"
9797
}

test/regression/gufi_vt.expected

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,10 @@ repeat_name
158158
unusual, name?#
159159
writable
160160

161-
# NULL thread count (not an error)
161+
# NULL arguments (not an error)
162162
$ (
163163
echo ".load gufi_vt"
164-
echo "SELECT name FROM gufi_vt_pentries('prefix', NULL) ORDER BY name ASC, size ASC;"
164+
echo "SELECT name FROM gufi_vt_pentries('prefix', NULL, NULL, NULL, NULL, NULL, NULL, NULL) ORDER BY name ASC, size ASC;"
165165
) | sqlite3
166166
.hidden
167167
1KB
@@ -563,6 +563,18 @@ prefix/empty_directory|8|8.0|1099511627776|prefix/empty_directory
563563
prefix/leaf_directory|13|13.0|1099511627776|prefix/leaf_directory
564564
prefix/unusual#? directory ,|16|16.0|1099511627776|prefix/unusual#? directory ,
565565

566+
# Force bad integer values
567+
$ (
568+
echo ".load gufi_vt"
569+
echo "CREATE VIRTUAL TABLE gufi USING gufi_vt("prefix", I="CREATE TABLE intermediate(i INTEGER);", S="INSERT INTO intermediate SELECT rpath(sname, sroll) FROM vrsummary;", K="CREATE TABLE aggregate(i INTEGER);", J="INSERT INTO aggregate SELECT * FROM intermediate;", G="SELECT * from aggregate;");SELECT * FROM gufi ORDER BY i ASC;"
570+
) | sqlite3
571+
prefix
572+
prefix/directory
573+
prefix/directory/subdirectory
574+
prefix/empty_directory
575+
prefix/leaf_directory
576+
prefix/unusual#? directory ,
577+
566578
# ######################################
567579
# errors
568580
# Missing indexroot

test/regression/gufi_vt.sh.in

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,13 @@ query=$(
258258
)
259259
query_vt "${query}"
260260

261+
echo "# Force bad integer values"
262+
query=$(
263+
echo -n "CREATE VIRTUAL TABLE gufi USING gufi_vt(\"${INDEXROOT}\", I=\"CREATE TABLE intermediate(i INTEGER);\", S=\"INSERT INTO intermediate SELECT rpath(sname, sroll) FROM vrsummary;\", K=\"CREATE TABLE aggregate(i INTEGER);\", J=\"INSERT INTO aggregate SELECT * FROM intermediate;\", G=\"SELECT * from aggregate;\");"
264+
echo -n "SELECT * FROM gufi ORDER BY i ASC;"
265+
)
266+
query_vt "${query}"
267+
261268
echo "# ######################################"
262269
echo "# errors"
263270

0 commit comments

Comments
 (0)