aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFranklin Wei <me@fwei.tk>2018-07-11 13:22:41 -0400
committerFranklin Wei <me@fwei.tk>2018-07-11 13:22:41 -0400
commit7ef3b693e36ee5935fb769bdef81317f2fe2caff (patch)
tree98cfe96825662d2595bed0f0cacebe4ceec7fee0
parent8aafb24ff873f9acea736a3574217256e2ebf5d9 (diff)
downloadcsaa-7ef3b693e36ee5935fb769bdef81317f2fe2caff.zip
csaa-7ef3b693e36ee5935fb769bdef81317f2fe2caff.tar.gz
csaa-7ef3b693e36ee5935fb769bdef81317f2fe2caff.tar.bz2
csaa-7ef3b693e36ee5935fb769bdef81317f2fe2caff.tar.xz
Add tests for IOMT search operations (disabled by default)
Uncomment the run_tests() call in main.c to run the tests.
-rw-r--r--iomt.c2
-rw-r--r--service_provider.c45
2 files changed, 43 insertions, 4 deletions
diff --git a/iomt.c b/iomt.c
index 0406994..73e073a 100644
--- a/iomt.c
+++ b/iomt.c
@@ -358,7 +358,7 @@ struct iomt_node iomt_find_encloser(const struct iomt *tree, uint64_t idx, uint6
if(sqlite3_step(st) == SQLITE_ROW)
{
if(leafidx)
- *leafidx = sqlite3_column_int64(st, 0);
+ *leafidx = sqlite3_column_int64(st, 0);
struct iomt_node ret;
ret.idx = sqlite3_column_int64(st, 1);
ret.next_idx = sqlite3_column_int64(st, 2);
diff --git a/service_provider.c b/service_provider.c
index 707e97f..cd3174e 100644
--- a/service_provider.c
+++ b/service_provider.c
@@ -231,7 +231,8 @@ void *db_init(const char *filename, bool overwrite, bool *need_init)
extern unsigned char sqlinit_txt[];
/* create tables */
- assert(sqlite3_exec(db, (const char*)sqlinit_txt, NULL, NULL, NULL) == SQLITE_OK);
+ if(sqlite3_exec(db, (const char*)sqlinit_txt, NULL, NULL, NULL) != SQLITE_OK)
+ warn("failed to initialize database (%s)", sqlite3_errmsg(db));
*need_init = true;
}
@@ -1294,10 +1295,10 @@ static hash_t test_sign_request(void *userdata, const struct tm_request *req)
void sp_test(void)
{
- int logleaves = 1;
+ int logleaves = 4;
clock_t start = clock();
- struct service_provider *sp = sp_new("a", 1, logleaves, "files", "csaa.db", true);
+ struct service_provider *sp = sp_new("a", 1, logleaves, "files", "csaatest.db", true);
clock_t stop = clock();
check("Tree initialization", sp != NULL);
@@ -1407,4 +1408,42 @@ void sp_test(void)
}
sp_free(sp);
+
+ /* test IOMT code (requires a service provider for the databases) */
+ {
+ struct service_provider *sp = sp_new("a", 1, logleaves, "files", "csaatest.db", true);
+ iomt_dump(sp->iomt);
+
+ iomt_update_leaf_nextidx(sp->iomt, 0, 2);
+ iomt_update_leaf_full(sp->iomt, 3, 2, 1, hash_null);
+
+ iomt_dump(sp->iomt);
+
+ /* should fail */
+ struct iomt_node encloser = iomt_find_encloser(sp->iomt, 2, NULL);
+ check("Encloser search 1", encloser.idx == 0);
+
+ encloser = iomt_find_encloser(sp->iomt, 4, NULL);
+ check("Encloser search 2", encloser.idx == 2 && encloser.next_idx == 1);
+
+ encloser = iomt_find_leaf_or_encloser(sp->iomt, 2, NULL);
+ check("Encloser/leaf search 1", encloser.idx == 2);
+
+ encloser = iomt_find_leaf_or_encloser(sp->iomt, 1000, NULL);
+ check("Encloser/leaf search 2", encloser.idx == 2);
+
+ iomt_update_leaf_full(sp->iomt, 3, 10, 3, hash_null);
+
+ iomt_update_leaf_full(sp->iomt, 0, 3, 10, hash_null);
+
+ iomt_dump(sp->iomt);
+
+ encloser = iomt_find_leaf_or_encloser(sp->iomt, 5, NULL);
+ check("Encloser/leaf search 3", encloser.idx == 3);
+
+ encloser = iomt_find_leaf_or_encloser(sp->iomt, 2, NULL);
+ check("Encloser/leaf search 4", encloser.idx == 10);
+
+ sp_free(sp);
+ }
}