Skip to content

Commit 871b809

Browse files
committed
more tests
replace_user_str path UDF gufi_vt bad integer conversion enable float conversion dir_match_uid/gid more tests with remote 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 871b809

15 files changed

+447
-86
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: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -723,8 +723,8 @@ gufi_vt_xConnect(VRPENTRIES, VRP, 0, 0, 1, 1)
723723
* a = <0|1|2> (see gufi_query)
724724
* min_level = <non-negative integer>
725725
* max_level = <non-negative integer>
726-
* dir_match_uid = <uid>
727-
* dir_match_gid = <gid>
726+
* dir_match_uid = <uid> (if just want euid, pass in no value i.e. dir_match_uid=)
727+
* dir_match_gid = <gid> (if just want egid, pass in no value i.e. dir_match_gid=)
728728
* setup_res_col_type = '<SQL>' (set up single temporary table to make columns available for getting result column types)
729729
* I = '<SQL>'
730730
* T = '<SQL>'
@@ -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
}
@@ -1394,28 +1396,28 @@ static int gufi_vtColumn(sqlite3_vtab_cursor *cur,
13941396
sqlite3_result_text(ctx, col, len, SQLITE_TRANSIENT);
13951397
}
13961398
((char *)col)[len] = orig;
1397-
break;
13981399
}
1399-
/* GUFI does not have floating point columns */
1400-
/* case SQLITE_FLOAT: */
1401-
/* { */
1402-
/* double value = 0; */
1403-
/* if (sscanf(col, "%lf", &value) == 1) { */
1404-
/* sqlite3_result_double(ctx, value); */
1405-
/* } */
1406-
/* else { */
1407-
/* sqlite3_result_text(ctx, col, len, SQLITE_TRANSIENT); */
1408-
/* } */
1409-
/* break; */
1410-
/* } */
1400+
break;
1401+
case SQLITE_FLOAT:
1402+
{
1403+
double value = 0;
1404+
if (sscanf(col, "%lf", &value) == 1) {
1405+
sqlite3_result_double(ctx, value);
1406+
}
1407+
else {
1408+
sqlite3_result_text(ctx, col, len, SQLITE_TRANSIENT);
1409+
}
1410+
}
1411+
break;
14111412
case SQLITE_TEXT:
1412-
case SQLITE_BLOB:
14131413
sqlite3_result_text(ctx, col, len, SQLITE_TRANSIENT);
14141414
break;
1415+
case SQLITE_BLOB:
1416+
sqlite3_result_blob(ctx, col, len, SQLITE_TRANSIENT);
1417+
break;
14151418
case SQLITE_NULL:
14161419
default:
14171420
sqlite3_result_text(ctx, col, len, SQLITE_TRANSIENT);
1418-
/* sqlite3_result_null(ctx); */
14191421
break;
14201422
}
14211423

@@ -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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ run_tests() {
7474
for name in summary entries pentries vrsummary vrpentries
7575
do
7676
echo "# Query ${name}"
77-
"${func}" "SELECT name, size, modetotxt(mode), strftime('%a %b %d %H:%M:%S UTC %Y', mtime) FROM gufi_vt_${name}('${INDEXROOT}', ${THREADS}) ORDER BY name ASC, size ASC;"
77+
"${func}" "SELECT name, size, modetotxt(mode), strftime('%a %b %d %H:%M:%S UTC %Y', mtime) FROM gufi_vt_${name}('${INDEXROOT}') ORDER BY name ASC, size ASC;"
7878
done
7979

8080
echo "# Query with WHERE size < 10"
@@ -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
}

0 commit comments

Comments
 (0)