提交 41220cb2 编写于 作者: G groot

add db unittest


Former-commit-id: 5a9e4a10ada30d19fee14b1d2e1d4123ac6dee04
上级 0b545a70
......@@ -18,4 +18,5 @@ set(unittest_libs
add_subdirectory(cache)
add_subdirectory(log)
add_subdirectory(db)
add_subdirectory(faiss_wrapper)
\ No newline at end of file
......@@ -10,8 +10,8 @@ aux_source_directory(../../src/cache cache_srcs)
set(cache_test_src
${unittest_srcs}
${cache_srcs}
cache_tests.cpp)
cache_test.cpp)
add_executable(cache_tests ${cache_test_src})
add_executable(cache_test ${cache_test_src})
target_link_libraries(cache_tests ${unittest_libs})
target_link_libraries(cache_test ${unittest_libs})
#-------------------------------------------------------------------------------
# Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
# Unauthorized copying of this file, via any medium is strictly prohibited.
# Proprietary and confidential.
#-------------------------------------------------------------------------------
include_directories(../../src)
aux_source_directory(../../src/db db_srcs)
aux_source_directory(../../src/wrapper wrapper_src)
include_directories(/usr/local/cuda/include)
link_directories("/usr/local/cuda/lib64")
set(db_test_src
${unittest_srcs}
${db_srcs}
${wrapper_src}
db_tests.cpp)
cuda_add_executable(db_test ${db_test_src})
set(db_libs
faiss
cudart
cublas
sqlite3
boost_system
boost_filesystem
)
target_link_libraries(db_test ${unittest_libs} ${db_libs})
////////////////////////////////////////////////////////////////////////////////
// Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
// Unauthorized copying of this file, via any medium is strictly prohibited.
// Proprietary and confidential.
////////////////////////////////////////////////////////////////////////////////
#include <gtest/gtest.h>
#include "db/DB.h"
using namespace zilliz::vecwise;
namespace {
void ASSERT_STATS(engine::Status& stat) {
ASSERT_TRUE(stat.ok());
if(!stat.ok()) {
std::cout << stat.ToString() << std::endl;
}
}
}
TEST(DBTest, DB_TEST) {
static const std::string group_name = "test_group";
static const int group_dim = 256;
engine::Options opt;
opt.meta.backend_uri = "http://127.0.0.1";
opt.meta.path = "/tmp/db_test";
engine::DB* db = nullptr;
engine::DB::Open(opt, &db);
ASSERT_TRUE(db != nullptr);
engine::meta::GroupSchema group_info;
group_info.dimension = group_dim;
group_info.group_id = group_name;
engine::Status stat = db->add_group(group_info);
ASSERT_STATS(stat);
engine::meta::GroupSchema group_info_get;
group_info_get.group_id = group_name;
stat = db->get_group(group_info_get);
ASSERT_STATS(stat);
ASSERT_EQ(group_info_get.dimension, group_dim);
engine::IDNumbers vector_ids;
std::vector<float> vec_f;
for(int i = 0; i < group_dim; i++){
vec_f.push_back((float)i);
vector_ids.push_back(i+1);
}
stat = db->add_vectors(group_name, 1, vec_f.data(), vector_ids);
ASSERT_STATS(stat);
engine::QueryResults results;
std::vector<float> vec_s = vec_f;
stat = db->search(group_name, 1, 1, vec_f.data(), results);
ASSERT_STATS(stat);
ASSERT_EQ(results.size(), 1);
ASSERT_EQ(results[0][0], vector_ids[0]);
delete db;
}
\ No newline at end of file
......@@ -19,12 +19,13 @@ set(wrapper_test_src
add_executable(wrapper_test ${wrapper_test_src})
set(faiss_libs
set(wrapper_libs
faiss
cudart
cublas
sqlite3
)
target_link_libraries(wrapper_test ${unittest_libs} ${faiss_libs})
target_link_libraries(wrapper_test ${unittest_libs} ${wrapper_libs})
set(topk_test_src
topk_test.cpp
......
......@@ -3,8 +3,8 @@
# Unauthorized copying of this file, via any medium is strictly prohibited.
# Proprietary and confidential.
#-------------------------------------------------------------------------------
set(log_test_src ${unittest_srcs} log_tests.cpp)
set(log_test_src ${unittest_srcs} log_test.cpp)
add_executable(log_tests ${log_test_src})
add_executable(log_test ${log_test_src})
target_link_libraries(log_tests ${unittest_libs})
target_link_libraries(log_test ${unittest_libs})
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册