Skip to content

Commit 36bb0ec

Browse files
committed
add external database list to dir2trace and trace2index tests
also reduced querying in inserttreesumdb
1 parent ad271c9 commit 36bb0ec

File tree

5 files changed

+35
-36
lines changed

5 files changed

+35
-36
lines changed

src/dbutils.c

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -689,24 +689,20 @@ int insertsumdb(sqlite3 *sdb, const char *path, struct work *pwork, struct entry
689689
return 0;
690690
}
691691

692-
static int get_str_callback(void *args, int count, char **data, char **columns) {
692+
static int get_2_strs(void *args, int count, char **data, char **columns) {
693693
(void) count;
694694
(void) columns;
695695

696-
char **str = (char **) args;
696+
char **strs = (char **) args;
697697

698-
if (data[0]) {
699-
const size_t len = strlen(data[0]) + 2; /* + 2 for quotation marks */
700-
*str = malloc(len + 1);
701-
SNFORMAT_S(*str, len + 1, 3,
698+
for(int i = 0; i < 2; i++) {
699+
const size_t len = strlen(data[i]) + 2; /* + 2 for quotation marks */
700+
strs[i] = malloc(len + 1);
701+
SNFORMAT_S(strs[i], len + 1, 3,
702702
"'", (size_t) 1,
703-
data[0], len - 2,
703+
data[i], len - 2,
704704
"'", (size_t) 1);
705705
}
706-
else {
707-
*str = malloc(5);
708-
snprintf(*str, 5, "NULL");
709-
}
710706

711707
return 0;
712708
}
@@ -720,22 +716,16 @@ int inserttreesumdb(const char *name, sqlite3 *sdb, struct sum *su,int rectype,i
720716

721717
char *err = NULL;
722718

723-
char *inode = NULL;
724-
if (sqlite3_exec(sdb, "SELECT inode FROM " SUMMARY " WHERE isroot == 1;",
725-
get_str_callback, &inode, &err) != SQLITE_OK ) {
719+
char *ip[2] = {NULL, NULL};
720+
if (sqlite3_exec(sdb, "SELECT inode, pinode FROM " SUMMARY " WHERE isroot == 1;",
721+
get_2_strs, ip, &err) != SQLITE_OK) {
726722
fprintf(stderr, "Could not get inode from %s: %s\n", SUMMARY, err);
727723
sqlite3_free(err);
728724
return 1;
729725
}
730726

731-
char *pinode = NULL;
732-
if (sqlite3_exec(sdb, "SELECT pinode FROM " SUMMARY " WHERE isroot == 1;",
733-
get_str_callback, &pinode, &err) != SQLITE_OK ) {
734-
fprintf(stderr, "Could not get inode from %s: %s\n", SUMMARY, err);
735-
free(inode);
736-
sqlite3_free(err);
737-
return 1;
738-
}
727+
char *inode = ip[0];
728+
char *pinode = ip[1];
739729

740730
char sqlstmt[MAXSQL];
741731
SNPRINTF(sqlstmt, MAXSQL, "INSERT INTO " TREESUMMARY " VALUES (%s, %s, %lld, %lld, %lld, %lld, %lld, %lld, %lld, %lld, %lld, %lld, %lld, %lld, %lld, %lld, %lld, %lld, %lld, %lld, %lld, %lld, %lld, %lld, %lld, %lld, %lld, %lld, %lld, %lld, %lld, %d, %lld, %lld, %lld, %lld, %lld, %lld, %lld, %lld, %lld, %lld, %lld, %lld, %lld, %lld, %lld, %d, %d, %d);",

test/regression/gufi_dir2trace.expected

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ output_prefix prefix of output files (<prefix>.<tid>)
2020
$ gufi_dir2trace -d "|" -n 2 -x "prefix" "trace"
2121
Creating GUFI Traces trace with 2 threads
2222
Total Dirs: 6
23-
Total Files: 14
23+
Total Files: 15
2424

2525
Expecting 2 trace files. Found 2.
26-
Expecting 20 lines. Got 20.
26+
Expecting 21 lines. Got 21.
2727
Expecting 23 columns per row. Got 23.
2828
Source Directory:
2929
prefix
@@ -38,6 +38,7 @@ Source Directory:
3838
prefix/directory/subdirectory/repeat_name
3939
prefix/directory/writable
4040
prefix/empty_directory
41+
prefix/external.gufi
4142
prefix/file_symlink
4243
prefix/leaf_directory
4344
prefix/leaf_directory/leaf_file1
@@ -59,6 +60,7 @@ Trace File:
5960
prefix/directory/subdirectory/repeat_name
6061
prefix/directory/writable
6162
prefix/empty_directory
63+
prefix/external.gufi
6264
prefix/file_symlink
6365
prefix/leaf_directory
6466
prefix/leaf_directory/leaf_file1
@@ -103,14 +105,15 @@ $ gufi_dir2trace -d "|" -n 2 -k "skip" "prefix" "trace"
103105
"trace.1" Already exists!
104106
Creating GUFI Traces trace with 2 threads
105107
Total Dirs: 4
106-
Total Files: 9
108+
Total Files: 10
107109

108-
$ cat trace.0 trace.1 | awk -F "|" '{print $1}'
110+
$ cat trace.0 trace.1 | awk -F "|" '{print $1}' | sed '/\/external\/db/d;'
109111
prefix
110112
prefix/.hidden
111113
prefix/1KB
112114
prefix/1MB
113115
prefix/empty_directory
116+
prefix/external.gufi
114117
prefix/file_symlink
115118
prefix/leaf_directory
116119
prefix/leaf_directory/leaf_file1

test/regression/gufi_dir2trace.sh.in

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ run_no_sort "${GUFI_DIR2TRACE}"
8989
# generate the tree
9090
@CMAKE_CURRENT_BINARY_DIR@/generatetree.sh "${SRCDIR}"
9191

92+
# add an external db
93+
echo "/external/db" > "${SRCDIR}/external.gufi"
94+
9295
# generate the trace
9396
run_no_sort "${GUFI_DIR2TRACE} -d \"${DELIM}\" -n ${THREADS} -x \"${SRCDIR}\" \"${TRACE}\""
9497

@@ -98,20 +101,20 @@ echo "Expecting ${THREADS} trace files. Found ${found}."
98101

99102
# count lines
100103
# shellcheck disable=SC2016
101-
trace_lines=$(cat "${TRACES[@]}" | wc -l | @AWK@ '{print $1}')
104+
trace_lines=$(cat "${TRACES[@]}" | wc -l | @AWK@ '{print $1 - 1}')
102105
contents=$(find "${SRCDIR}")
103106
# shellcheck disable=SC2016
104107
content_lines=$(echo "${contents}" | wc -l | @AWK@ '{print $1}')
105108
echo "Expecting ${content_lines} lines. Got ${trace_lines}."
106109

107110
# count separators
108-
columns=$(sed "s/[^${DELIM}]//g" "${TRACES[@]}" | @AWK@ '{ print length }' | sort | uniq)
111+
columns=$(sed "/^.*${DELIM}e${DELIM}$/d; s/[^${DELIM}]//g;" "${TRACES[@]}" | @AWK@ '{ print length }' | sort | uniq)
109112
echo "Expecting 23 columns per row. Got ${columns}."
110113

111114
# compare names
112115
src=$(find "${SRCDIR}" | sort)
113116
# shellcheck disable=SC2016
114-
lines=$(@AWK@ -F"${DELIM}" -v SRCDIR="${SRCDIR}" "{ print \$1 }" "${TRACES[@]}" | sed "s/\\/\\//\\//g" | sort)
117+
lines=$(@AWK@ -F"${DELIM}" -v SRCDIR="${SRCDIR}" "{ print \$1 }" "${TRACES[@]}" | sed "/\\/external\\/db/d; s/\\/\\//\\//g;" | sort)
115118

116119
echo "Source Directory:"
117120
# shellcheck disable=SC2016
@@ -142,7 +145,7 @@ echo "# skip file"
142145
run_no_sort "${GUFI_DIR2TRACE} -d \"${DELIM}\" -n ${THREADS} -k \"${SKIP}\" \"${SRCDIR}\" \"${TRACE}\""
143146

144147
# shellcheck disable=SC2145
145-
run_sort "cat ${TRACES[@]} | @AWK@ -F \"${DELIM}\" '{print \$1}'"
148+
run_sort "cat ${TRACES[@]} | @AWK@ -F \"${DELIM}\" '{print \$1}' | sed '/\\/external\\/db/d;'"
146149

147150
echo "# bad skip file"
148151
run_no_sort "${GUFI_DIR2TRACE} -d \"${DELIM}\" -n ${THREADS} -k \"${SKIP}.bad\" \"${SRCDIR}\" \"${TRACE}\""

test/regression/gufi_trace2index.expected

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ Total Files: 14
2222
$ gufi_trace2index -d "|" trace.0 trace.1 "prefix"
2323
Creating GUFI Index prefix with 1 threads
2424
Dirs: 6 (1 empty)
25-
Files: 14
26-
Total: 20
25+
Files: 15
26+
Total: 21
2727

2828
Total Dirs: 6
29-
Total Files: 14
29+
Total Files: 15
3030

3131
Source Directory:
3232
prefix
@@ -76,11 +76,11 @@ GUFI Index:
7676
$ gufi_trace2index -d "|" -n "2" "empty_last_dir.trace" "prefix"
7777
Creating GUFI Index prefix with 2 threads
7878
Dirs: 7 (2 empty)
79-
Files: 14
80-
Total: 21
79+
Files: 15
80+
Total: 22
8181

8282
Total Dirs: 7
83-
Total Files: 14
83+
Total Files: 15
8484

8585
# bad trace path
8686
$ gufi_trace2index -d "|" -n "2" "" "prefix"

test/regression/gufi_trace2index.sh.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ run_no_sort "${GENERATETREE} ${SRCDIR}"
9090
# generate the trace
9191
run_no_sort "${GUFI_DIR2TRACE} -d \"${DELIM}\" -n ${THREADS} -x \"${SRCDIR}\" \"${TRACE}\""
9292

93+
# add an external db
94+
echo "external_db${DELIM}e${DELIM}" >> "${TRACES[0]}"
95+
9396
# generate the index
9497
run_no_sort "${GUFI_TRACE2INDEX} -d \"${DELIM}\"" "${TRACES[@]}" "\"${SEARCH}\""
9598

0 commit comments

Comments
 (0)