Skip to content

Commit fd93128

Browse files
committed
tests: add simple plugin for testing purposes
This adds a simple plugin for gufi_dir2index which will be used for a regression test. The plugin is not intended to be useful in the real world. It just does enough to be useful for testing purposes.
1 parent 7663ee0 commit fd93128

File tree

6 files changed

+307
-0
lines changed

6 files changed

+307
-0
lines changed

test/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,15 @@ set_tests_properties(gary PROPERTIES LABELS "manual")
116116

117117
# add_test(NAME gufitest COMMAND gufitest.py all)
118118
# set_tests_properties(gufitest PROPERTIES LABELS manual)
119+
120+
add_library(test_plugin SHARED test_plugin.c)
121+
122+
if (APPLE OR DARWIN)
123+
# Apple needs to be told to explicitly not try to resolve symbols at compile time when
124+
# building the plugin. (They will be resolved dynamically when the plugin is dlopen()ed).
125+
target_link_libraries(test_plugin -Wl,-undefined -Wl,dynamic_lookup)
126+
elseif(CYGWIN)
127+
# Cygwin needs to use an "import library" (reference: https://cygwin.com/cygwin-ug-net/dll.html)
128+
# to get the symbol definitions it uses from gufi_dir2index.
129+
target_link_libraries(test_plugin "${CMAKE_BINARY_DIR}/src/libgufi_dir2index.dll.a")
130+
endif()

test/regression/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ set(BINARIES
9090
gufi_query
9191
gufi_stat_bin
9292
querydbs
93+
gufi_plugin
9394

9495
gufi_vt
9596
run_vt
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
$ gufi_dir2index -U gufi_test_plugin -x prefix search
2+
Creating GUFI Index search with 1 threads
3+
Total Dirs: 6
4+
Total Non-Dirs: 14
5+
6+
7+
# test plugin summary output:
8+
$ gufi_query -d " " -E "SELECT * FROM plugin_test_summary;" prefix
9+
directory 1
10+
directory 1
11+
directory 1
12+
directory 1
13+
directory 1
14+
directory 1
15+
file 0
16+
file 1
17+
file 2
18+
file 2
19+
file 3
20+
file 6
21+

test/regression/gufi_plugin.sh.in

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#!/usr/bin/env bash
2+
# This file is part of GUFI, which is part of MarFS, which is released
3+
# under the BSD license.
4+
#
5+
#
6+
# Copyright (c) 2017, Los Alamos National Security (LANS), LLC
7+
# All rights reserved.
8+
#
9+
# Redistribution and use in source and binary forms, with or without modification,
10+
# are permitted provided that the following conditions are met:
11+
#
12+
# 1. Redistributions of source code must retain the above copyright notice, this
13+
# list of conditions and the following disclaimer.
14+
#
15+
# 2. Redistributions in binary form must reproduce the above copyright notice,
16+
# this list of conditions and the following disclaimer in the documentation and/or
17+
# other materials provided with the distribution.
18+
#
19+
# 3. Neither the name of the copyright holder nor the names of its contributors
20+
# may be used to endorse or promote products derived from this software without
21+
# specific prior written permission.
22+
#
23+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24+
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26+
# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27+
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28+
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29+
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30+
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
31+
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
32+
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33+
#
34+
#
35+
# From Los Alamos National Security, LLC:
36+
# LA-CC-15-039
37+
#
38+
# Copyright (c) 2017, Los Alamos National Security, LLC All rights reserved.
39+
# Copyright 2017. Los Alamos National Security, LLC. This software was produced
40+
# under U.S. Government contract DE-AC52-06NA25396 for Los Alamos National
41+
# Laboratory (LANL), which is operated by Los Alamos National Security, LLC for
42+
# the U.S. Department of Energy. The U.S. Government has rights to use,
43+
# reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR LOS
44+
# ALAMOS NATIONAL SECURITY, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR
45+
# ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is
46+
# modified to produce derivative works, such modified software should be
47+
# clearly marked, so as not to confuse it with the version available from
48+
# LANL.
49+
#
50+
# THIS SOFTWARE IS PROVIDED BY LOS ALAMOS NATIONAL SECURITY, LLC AND CONTRIBUTORS
51+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
52+
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
53+
# ARE DISCLAIMED. IN NO EVENT SHALL LOS ALAMOS NATIONAL SECURITY, LLC OR
54+
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
55+
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
56+
# OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
57+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
58+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
59+
# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
60+
# OF SUCH DAMAGE.
61+
62+
63+
64+
set -e
65+
source @CMAKE_CURRENT_BINARY_DIR@/setup.sh 1
66+
67+
OUTPUT="gufi_plugin.out"
68+
69+
(
70+
# remove preexisting indicies
71+
rm -rf "${SEARCH}"
72+
73+
# generate the index
74+
run_no_sort "${GUFI_DIR2INDEX} -U ${GUFI_TEST_PLUGIN} -x ${SRCDIR} ${SEARCH}"
75+
76+
echo
77+
echo "# test plugin summary output:"
78+
79+
# make sure the plugin_test_summary table has the expected values for file and directory count:
80+
# (`sort` needed to obtain predictable order of results)
81+
run_sort "${GUFI_QUERY} -d \" \" -E \"SELECT * FROM plugin_test_summary;\" ${INDEXROOT}"
82+
83+
) | remove_indexing_time | replace | tee "${OUTPUT}"
84+
85+
@DIFF@ @CMAKE_CURRENT_BINARY_DIR@/gufi_plugin.expected "${OUTPUT}"
86+
rm "${OUTPUT}"

test/regression/setup.sh.in

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,17 @@ USERFILESPACEHOGUSESUMMARY="@CMAKE_BINARY_DIR@/examples/userfilespacehogusesumma
189189
VERIFYTRACE="@CMAKE_BINARY_DIR@/contrib/verifytrace"
190190
VERIFYTRACEINTREE="@CMAKE_BINARY_DIR@/contrib/verifytraceintree"
191191

192+
# test plugin path depends on the environment:
193+
# shellcheck disable=SC2194
194+
case "@CMAKE_SYSTEM_NAME@" in
195+
"APPLE" | "Darwin")
196+
GUFI_TEST_PLUGIN="@CMAKE_BINARY_DIR@/test/libtest_plugin.dylib"
197+
;;
198+
"Linux" | "CYGWIN")
199+
GUFI_TEST_PLUGIN="@CMAKE_BINARY_DIR@/test/libtest_plugin.so"
200+
;;
201+
esac
202+
192203
AWK="@AWK@"
193204
COLUMN="@COLUMN@"
194205
DIFF="@DIFF@"
@@ -240,6 +251,7 @@ replace() {
240251
s/${GUFI_STAT//\//\\/}/gufi_stat/g;
241252
s/${GUFI_STATS//\//\\/}/gufi_stats/g;
242253
s/${GUFI_STAT_BIN//\//\\/}/gufi_stat_bin/g
254+
s/${GUFI_TEST_PLUGIN//\//\\/}/gufi_test_plugin/g;
243255
s/${GUFI_TRACE2DIR//\//\\/}/gufi_trace2dir/g;
244256
s/${GUFI_TRACE2INDEX//\//\\/}/gufi_trace2index/g;
245257
s/${GUFI_TREESUMMARY//\//\\/}/gufi_treesummary/g;

test/test_plugin.c

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
/*
2+
This file is part of GUFI, which is part of MarFS, which is released
3+
under the BSD license.
4+
5+
6+
Copyright (c) 2017, Los Alamos National Security (LANS), LLC
7+
All rights reserved.
8+
9+
Redistribution and use in source and binary forms, with or without modification,
10+
are permitted provided that the following conditions are met:
11+
12+
1. Redistributions of source code must retain the above copyright notice, this
13+
list of conditions and the following disclaimer.
14+
15+
2. Redistributions in binary form must reproduce the above copyright notice,
16+
this list of conditions and the following disclaimer in the documentation and/or
17+
other materials provided with the distribution.
18+
19+
3. Neither the name of the copyright holder nor the names of its contributors
20+
may be used to endorse or promote products derived from this software without
21+
specific prior written permission.
22+
23+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26+
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28+
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
31+
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
32+
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33+
34+
35+
From Los Alamos National Security, LLC:
36+
LA-CC-15-039
37+
38+
Copyright (c) 2017, Los Alamos National Security, LLC All rights reserved.
39+
Copyright 2017. Los Alamos National Security, LLC. This software was produced
40+
under U.S. Government contract DE-AC52-06NA25396 for Los Alamos National
41+
Laboratory (LANL), which is operated by Los Alamos National Security, LLC for
42+
the U.S. Department of Energy. The U.S. Government has rights to use,
43+
reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR LOS
44+
ALAMOS NATIONAL SECURITY, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR
45+
ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is
46+
modified to produce derivative works, such modified software should be
47+
clearly marked, so as not to confuse it with the version available from
48+
LANL.
49+
50+
THIS SOFTWARE IS PROVIDED BY LOS ALAMOS NATIONAL SECURITY, LLC AND CONTRIBUTORS
51+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
52+
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
53+
ARE DISCLAIMED. IN NO EVENT SHALL LOS ALAMOS NATIONAL SECURITY, LLC OR
54+
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
55+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
56+
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
57+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
58+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
59+
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
60+
OF SUCH DAMAGE.
61+
*/
62+
63+
64+
65+
/*
66+
* A simple plugin for gufi_dir2index used for testing purposes.
67+
*/
68+
69+
#include <stdio.h>
70+
#include <stdlib.h>
71+
72+
#include "plugin.h"
73+
#include "sqlite3.h"
74+
75+
struct state {
76+
int n_files;
77+
int n_dirs;
78+
};
79+
80+
static struct state *new_state(void) {
81+
struct state *new = calloc(1, sizeof *new);
82+
83+
return new;
84+
}
85+
86+
static void cleanup_state(struct state *p) {
87+
free(p);
88+
}
89+
90+
/*
91+
* Set up initial state for test plugin.
92+
*/
93+
static void *db_init(sqlite3 *db) {
94+
struct state *state = new_state();
95+
96+
char *text = "CREATE TABLE plugin_test_files (id INTEGER PRIMARY KEY AUTOINCREMENT, filename TEXT);"
97+
"CREATE TABLE plugin_test_directories (id INTEGER PRIMARY KEY AUTOINCREMENT, dirname TEXT);"
98+
"CREATE TABLE plugin_test_summary (filetype TEXT PRIMARY KEY, count INTEGER, CHECK (filetype IN ('file', 'directory')));";
99+
char *error;
100+
101+
int res = sqlite3_exec(db, text, NULL, NULL, &error);
102+
if (res != SQLITE_OK) {
103+
fprintf(stderr, "test plugin: db_init(): error executing statement: %d %s\n", res, error);
104+
}
105+
106+
sqlite3_free(error);
107+
108+
return state;
109+
}
110+
111+
/*
112+
* Save state to the database and clean up state.
113+
*/
114+
static void db_exit(sqlite3 *db, void *user_data) {
115+
struct state *p = (struct state *) user_data;
116+
117+
char *text = sqlite3_mprintf("INSERT INTO plugin_test_summary (filetype, count) VALUES ('file', %d);"
118+
"INSERT INTO plugin_test_summary (filetype, count) VALUES ('directory', %d);",
119+
p->n_files, p->n_dirs);
120+
char *error;
121+
122+
int res = sqlite3_exec(db, text, NULL, NULL, &error);
123+
if (res != SQLITE_OK) {
124+
fprintf(stderr, "test plugin: db_exit(): error executing statement: %d %s\n",
125+
res, error);
126+
}
127+
128+
sqlite3_free(text);
129+
sqlite3_free(error);
130+
131+
cleanup_state(p);
132+
}
133+
134+
static void process_file(char *path, sqlite3 *db, void *user_data) {
135+
struct state *p = (struct state *) user_data;
136+
137+
char *text = sqlite3_mprintf("INSERT INTO plugin_test_files (filename) VALUES ('%s');", path);
138+
char *error;
139+
140+
int res = sqlite3_exec(db, text, NULL, NULL, &error);
141+
if (res == SQLITE_OK) {
142+
p->n_files += 1;
143+
} else {
144+
fprintf(stderr, "test plugin: process_file(): error executing statement: %d %s\n",
145+
res, error);
146+
}
147+
148+
sqlite3_free(text);
149+
sqlite3_free(error);
150+
}
151+
152+
static void process_dir(char *path, sqlite3 *db, void *user_data) {
153+
struct state *p = (struct state *) user_data;
154+
155+
char *text = sqlite3_mprintf("INSERT INTO plugin_test_directories (dirname) VALUES ('%s');", path);
156+
char *error;
157+
158+
int res = sqlite3_exec(db, text, NULL, NULL, &error);
159+
if (res == SQLITE_OK) {
160+
p->n_dirs += 1;
161+
} else {
162+
fprintf(stderr, "test plugin: process_dir(): error executing statement: %d %s\n",
163+
res, error);
164+
}
165+
166+
sqlite3_free(text);
167+
sqlite3_free(error);
168+
}
169+
170+
struct plugin_operations gufi_plugin_operations = {
171+
.db_init = db_init,
172+
.process_dir = process_dir,
173+
.process_file = process_file,
174+
.db_exit = db_exit,
175+
};

0 commit comments

Comments
 (0)