mirror of
https://gitee.com/milvus-io/milvus.git
synced 2024-12-05 05:18:52 +08:00
unit test
Former-commit-id: 3806f1d475b2dd1259fe48a013f01389f8975e5c
This commit is contained in:
parent
35eeae6f08
commit
74d5802ba4
@ -53,24 +53,24 @@ int main(int argc, char *argv[]) {
|
||||
server::ServerError err = server::LicenseLibrary::GetDeviceCount(device_count);
|
||||
if (err != server::SERVER_SUCCESS) return -1;
|
||||
|
||||
// 2. Get All GPU UUID
|
||||
// 1. Get All GPU UUID
|
||||
std::vector<std::string> uuid_array;
|
||||
err = server::LicenseLibrary::GetUUID(device_count, uuid_array);
|
||||
if (err != server::SERVER_SUCCESS) return -1;
|
||||
|
||||
// 3. Get UUID SHA256
|
||||
// 2. Get UUID SHA256
|
||||
std::vector<std::string> uuid_sha256_array;
|
||||
err = server::LicenseLibrary::GetUUIDSHA256(device_count, uuid_array, uuid_sha256_array);
|
||||
if (err != server::SERVER_SUCCESS) return -1;
|
||||
|
||||
// 4. Generate GPU ID map with GPU UUID
|
||||
// 3. Generate GPU ID map with GPU UUID
|
||||
std::map<int, std::string> uuid_encrption_map;
|
||||
for (int i = 0; i < device_count; ++i) {
|
||||
uuid_encrption_map[i] = uuid_sha256_array[i];
|
||||
}
|
||||
|
||||
|
||||
// 6. Generate GPU_info File
|
||||
// 4. Generate GPU_info File
|
||||
err = server::LicenseLibrary::GPUinfoFileSerialization(system_info_filename,
|
||||
device_count,
|
||||
uuid_encrption_map);
|
||||
|
@ -14,47 +14,6 @@ namespace vecwise {
|
||||
namespace server {
|
||||
|
||||
|
||||
//ServerError
|
||||
//LicenseCheck::IntegrityCheck(const std::string &license_file_path, const std::string &secret_file_path) {
|
||||
//
|
||||
// std::string file_md5;
|
||||
// LicenseLibrary::GetFileMD5(license_file_path, file_md5);
|
||||
// time_t update_time;
|
||||
// off_t file_size;
|
||||
// LicenseLibrary::GetFileUpdateTimeAndSize(license_file_path, update_time, file_size);
|
||||
// time_t system_time;
|
||||
// LicenseLibrary::GetSystemTime(system_time);
|
||||
//
|
||||
// std::string output_file_md5;
|
||||
// time_t output_update_time;
|
||||
// off_t output_file_size;
|
||||
// time_t output_starting_time;
|
||||
// time_t output_end_time;
|
||||
// LicenseLibrary::SecretFileDeserialization(secret_file_path,
|
||||
// output_update_time,
|
||||
// output_file_size,
|
||||
// output_starting_time,
|
||||
// output_end_time,
|
||||
// output_file_md5);
|
||||
// if (file_md5 != output_file_md5) {
|
||||
// printf("License file has been modified\n");
|
||||
// return SERVER_UNEXPECTED_ERROR;
|
||||
// }
|
||||
// if (update_time != output_update_time) {
|
||||
// printf("update_time is wrong\n");
|
||||
// return SERVER_UNEXPECTED_ERROR;
|
||||
// }
|
||||
// if (file_size != output_file_size) {
|
||||
// printf("file_size is wrong\n");
|
||||
// return SERVER_UNEXPECTED_ERROR;
|
||||
// }
|
||||
// if (system_time < output_starting_time || system_time > output_end_time) {
|
||||
// printf("License expired\n");
|
||||
// return SERVER_UNEXPECTED_ERROR;
|
||||
// }
|
||||
// return SERVER_SUCCESS;
|
||||
//}
|
||||
|
||||
// Part 1: Legality check
|
||||
|
||||
ServerError
|
||||
|
@ -20,8 +20,6 @@ class LicenseCheck {
|
||||
return instance;
|
||||
};
|
||||
|
||||
// static ServerError
|
||||
// IntegrityCheck(const std::string &license_file_path, const std::string &secret_file_path);
|
||||
|
||||
// Part 1: Legality check
|
||||
static ServerError
|
||||
|
@ -18,8 +18,8 @@ print_usage(const std::string &app_name) {
|
||||
printf(" -h --help Print this help\n");
|
||||
printf(" -s --sysinfo filename sysinfo file location\n");
|
||||
printf(" -l --license filename Generate license file as given name\n");
|
||||
printf(" -b --starting time Set start time Similar to year-month-day\n");
|
||||
printf(" -e --end time Set end time Similar to year-month-day \n");
|
||||
printf(" -b --starting time Set start time (format: YYYY-MM-DD)\n");
|
||||
printf(" -e --end time Set end time (format: YYYY-MM-DD)\n");
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
@ -52,35 +52,20 @@ int main(int argc, char *argv[]) {
|
||||
case 's': {
|
||||
flag_s = 0;
|
||||
system_info_filename = (std::string) (optarg);
|
||||
// char *system_info_filename_ptr = strdup(optarg);
|
||||
// system_info_filename = system_info_filename_ptr;
|
||||
// free(system_info_filename_ptr);
|
||||
// printf("Generate system info file: %s\n", system_info_filename.c_str());
|
||||
break;
|
||||
}
|
||||
case 'b': {
|
||||
flag_b = 0;
|
||||
string_starting_time = optarg;
|
||||
// char *time = strdup(optarg);
|
||||
// err = server::LicenseLibrary::GetDateTime(time, starting_time);
|
||||
// if (err != server::SERVER_SUCCESS) return -1;
|
||||
// free(time);
|
||||
break;
|
||||
}
|
||||
case 'e': {
|
||||
flag_e = 0;
|
||||
string_end_time = optarg;
|
||||
// char *time = strdup(optarg);
|
||||
// err = server::LicenseLibrary::GetDateTime(time, end_time);
|
||||
// if (err != server::SERVER_SUCCESS) return -1;
|
||||
// free(time);
|
||||
break;
|
||||
}
|
||||
case 'l': {
|
||||
license_filename = (std::string) (optarg);
|
||||
// char *system_info_filename_ptr = strdup(optarg);
|
||||
// license_filename = system_info_filename_ptr;
|
||||
// free(system_info_filename_ptr);
|
||||
break;
|
||||
}
|
||||
case 'h':print_usage(app_name);
|
||||
|
@ -26,6 +26,7 @@ namespace server {
|
||||
|
||||
constexpr int LicenseLibrary::sha256_length_;
|
||||
|
||||
// Part 0: File check
|
||||
bool
|
||||
LicenseLibrary::IsFileExistent(const std::string &path) {
|
||||
|
||||
@ -42,7 +43,7 @@ LicenseLibrary::IsFileExistent(const std::string &path) {
|
||||
return !boost::filesystem::is_directory(file_status);
|
||||
}
|
||||
|
||||
|
||||
// Part 1: Get GPU Info
|
||||
ServerError
|
||||
LicenseLibrary::GetDeviceCount(int &device_count) {
|
||||
nvmlReturn_t result = nvmlInit();
|
||||
@ -230,6 +231,8 @@ LicenseLibrary::LicenseFileDeserialization(const std::string &path,
|
||||
// return SERVER_SUCCESS;
|
||||
//}
|
||||
|
||||
|
||||
|
||||
// Part 3: File attribute: UpdateTime Time/ Size/ MD5
|
||||
ServerError
|
||||
LicenseLibrary::GetFileUpdateTimeAndSize(const std::string &path, time_t &update_time, off_t &file_size) {
|
||||
@ -336,127 +339,6 @@ LicenseLibrary::GetDateTime(char *cha, time_t &data_time) {
|
||||
return SERVER_SUCCESS;
|
||||
|
||||
}
|
||||
// Part 5: Integrity check and Legality check
|
||||
//ServerError
|
||||
//LicenseLibrary::IntegrityCheck(const std::string &license_file_path, const std::string &secret_file_path) {
|
||||
//
|
||||
// std::string file_md5;
|
||||
// GetFileMD5(license_file_path, file_md5);
|
||||
// time_t update_time;
|
||||
// off_t file_size;
|
||||
// GetFileUpdateTimeAndSize(license_file_path, update_time, file_size);
|
||||
// time_t system_time;
|
||||
// GetSystemTime(system_time);
|
||||
//
|
||||
// std::string output_file_md5;
|
||||
// time_t output_update_time;
|
||||
// off_t output_file_size;
|
||||
// time_t output_starting_time;
|
||||
// time_t output_end_time;
|
||||
// SecretFileDeserialization(secret_file_path,
|
||||
// output_update_time,
|
||||
// output_file_size,
|
||||
// output_starting_time,
|
||||
// output_end_time,
|
||||
// output_file_md5);
|
||||
// if (file_md5 != output_file_md5) {
|
||||
// printf("License file has been modified\n");
|
||||
// return SERVER_UNEXPECTED_ERROR;
|
||||
// }
|
||||
// if (update_time != output_update_time) {
|
||||
// printf("update_time is wrong\n");
|
||||
// return SERVER_UNEXPECTED_ERROR;
|
||||
// }
|
||||
// if (file_size != output_file_size) {
|
||||
// printf("file_size is wrong\n");
|
||||
// return SERVER_UNEXPECTED_ERROR;
|
||||
// }
|
||||
// if (system_time < output_starting_time || system_time > output_end_time) {
|
||||
// printf("License expired\n");
|
||||
// return SERVER_UNEXPECTED_ERROR;
|
||||
// }
|
||||
// return SERVER_SUCCESS;
|
||||
//}
|
||||
//
|
||||
//ServerError
|
||||
//LicenseLibrary::LegalityCheck(const std::string &license_file_path) {
|
||||
//
|
||||
// int device_count;
|
||||
// GetDeviceCount(device_count);
|
||||
// std::vector<std::string> uuid_array;
|
||||
// GetUUID(device_count, uuid_array);
|
||||
//
|
||||
// std::vector<std::string> sha_array;
|
||||
// GetUUIDSHA256(device_count, uuid_array, sha_array);
|
||||
//
|
||||
// int output_device_count;
|
||||
// std::map<int, std::string> uuid_encryption_map;
|
||||
// int64_t remaining_time;
|
||||
// LicenseFileDeserialization(license_file_path, output_device_count, uuid_encryption_map, remaining_time);
|
||||
//
|
||||
// if (device_count != output_device_count) {
|
||||
// printf("device_count is wrong\n");
|
||||
// return SERVER_UNEXPECTED_ERROR;
|
||||
// }
|
||||
// for (int i = 0; i < device_count; ++i) {
|
||||
// if (sha_array[i] != uuid_encryption_map[i]) {
|
||||
// printf("uuid_encryption_map %d is wrong\n", i);
|
||||
// return SERVER_UNEXPECTED_ERROR;
|
||||
// }
|
||||
// }
|
||||
// if (remaining_time <= 0) {
|
||||
// printf("License expired\n");
|
||||
// return SERVER_UNEXPECTED_ERROR;
|
||||
// }
|
||||
// std::cout << "Legality Check Success" << std::endl;
|
||||
// return SERVER_SUCCESS;
|
||||
//}
|
||||
|
||||
//// Part 6: Timer
|
||||
//ServerError
|
||||
//LicenseLibrary::AlterFile(const std::string &license_file_path,
|
||||
// const std::string &secret_file_path,
|
||||
// const boost::system::error_code &ec,
|
||||
// boost::asio::deadline_timer *pt) {
|
||||
// int device_count;
|
||||
// std::map<int, std::string> uuid_encryption_map;
|
||||
// int64_t remaining_time;
|
||||
// LicenseFileDeserialization(license_file_path, device_count, uuid_encryption_map, remaining_time);
|
||||
//
|
||||
// std::cout << "remaining_time: " << remaining_time << std::endl;
|
||||
//
|
||||
// if (remaining_time <= 0) {
|
||||
// std::cout << "License expired" << std::endl;
|
||||
// exit(1);
|
||||
// }
|
||||
// --remaining_time;
|
||||
// LicenseFileSerialization(license_file_path, device_count, uuid_encryption_map, remaining_time);
|
||||
//
|
||||
// time_t update_time;
|
||||
// off_t file_size;
|
||||
// GetFileUpdateTimeAndSize(license_file_path, update_time, file_size);
|
||||
// std::string file_md5;
|
||||
// GetFileMD5(license_file_path, file_md5);
|
||||
// SecretFileSerialization(secret_file_path, update_time, file_size, file_md5);
|
||||
//
|
||||
// pt->expires_at(pt->expires_at() + boost::posix_time::hours(1));
|
||||
// pt->async_wait(boost::bind(AlterFile, license_file_path, secret_file_path, boost::asio::placeholders::error, pt));
|
||||
// return SERVER_SUCCESS;
|
||||
//}
|
||||
//
|
||||
//ServerError
|
||||
//LicenseLibrary::StartCountingDown(const std::string &license_file_path, const std::string &secret_file_path) {
|
||||
//
|
||||
// if (!IsFileExistent(license_file_path)) return SERVER_LICENSE_FILE_NOT_EXIST;
|
||||
// if (!IsFileExistent(secret_file_path)) return SERVER_LICENSE_FILE_NOT_EXIST;
|
||||
//
|
||||
// boost::asio::io_service io;
|
||||
// boost::asio::deadline_timer t(io, boost::posix_time::hours(1));
|
||||
// t.async_wait(boost::bind(AlterFile, license_file_path, secret_file_path, boost::asio::placeholders::error, &t));
|
||||
// std::cout << "Timing begins" << std::endl;
|
||||
// io.run();
|
||||
// return SERVER_SUCCESS;
|
||||
//}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -94,23 +94,6 @@ class LicenseLibrary {
|
||||
static ServerError
|
||||
GetDateTime(char *cha, time_t &data_time);
|
||||
|
||||
// Part 5: Integrity check and Legality check
|
||||
// static ServerError
|
||||
// IntegrityCheck(const std::string &license_file_path, const std::string &secret_file_path);
|
||||
//
|
||||
// static ServerError
|
||||
// LegalityCheck(const std::string &license_file_path);
|
||||
|
||||
// Part 6: Timer
|
||||
// static ServerError
|
||||
// AlterFile(const std::string &license_file_path,
|
||||
// const std::string &secret_file_path,
|
||||
// const boost::system::error_code &ec,
|
||||
// boost::asio::deadline_timer *pt);
|
||||
//
|
||||
// static ServerError
|
||||
// StartCountingDown(const std::string &license_file_path, const std::string &secret_file_path);
|
||||
|
||||
|
||||
private:
|
||||
static constexpr int sha256_length_ = 32;
|
||||
|
@ -20,13 +20,11 @@ link_directories(/usr/local/cuda/targets/x86_64-linux/lib/stubs/)
|
||||
set(require_files
|
||||
../../src/license/LicenseLibrary.cpp
|
||||
../../src/license/LicenseCheck.cpp
|
||||
# ../../src/license/License.cpp
|
||||
)
|
||||
|
||||
|
||||
set(db_test_src
|
||||
|
||||
# license_tests.cpp
|
||||
license_library_tests.cpp
|
||||
license_check_test.cpp
|
||||
|
||||
|
@ -14,55 +14,171 @@ using namespace zilliz::vecwise;
|
||||
|
||||
TEST(LicenseLibraryTest, CHECK_TEST) {
|
||||
|
||||
server::ServerError err;
|
||||
|
||||
server::ServerError err;
|
||||
// 1. Set license file name
|
||||
std::string license_file_path("/tmp/megasearch/abc.license");
|
||||
|
||||
// 2. Legality check
|
||||
err = server::LicenseCheck::LegalityCheck(license_file_path);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
|
||||
}
|
||||
|
||||
TEST(LicenseLibraryTest, CHECK_ERROR1_TEST){
|
||||
|
||||
server::ServerError err;
|
||||
// 1. Set license file name
|
||||
std::string license_file_path("/tmp/megasearch/abc");
|
||||
|
||||
// 2. Legality check
|
||||
err = server::LicenseCheck::LegalityCheck(license_file_path);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
}
|
||||
|
||||
TEST(LicenseLibraryTest, CHECK_ERROR2_TEST){
|
||||
|
||||
server::ServerError err;
|
||||
// 1. Set license file name
|
||||
std::string license_file_path("/tmp/megasearch/abc.license");
|
||||
|
||||
// 2. Define output var
|
||||
int device_count;
|
||||
std::map<int, std::string> uuid_encryption_map;
|
||||
//
|
||||
// err = server::LicenseLibrary::GPUinfoFileDeserialization(sys_info_file_path, device_count, uuid_encryption_map);
|
||||
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
// std::cout << " device_count: " << device_count << std::endl;
|
||||
// for (int i = 0; i < device_count; i++) {
|
||||
// std::cout << " uuid_encryption_map: " << i << " " << uuid_encryption_map[i] << std::endl;
|
||||
// }
|
||||
//
|
||||
time_t starting_time;
|
||||
time_t end_time;
|
||||
|
||||
// 3. Read License File
|
||||
err = server::LicenseLibrary::LicenseFileDeserialization(license_file_path,
|
||||
device_count,
|
||||
uuid_encryption_map,
|
||||
starting_time,
|
||||
end_time);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
//
|
||||
// std::cout << "device_count: " << device_count << std::endl;
|
||||
// for (int i = 0; i < device_count; i++) {
|
||||
// std::cout << " uuid_encryption_map: " << i << " " << uuid_encryption_map[i] << std::endl;
|
||||
// }
|
||||
// std::cout << "starting_time: " << starting_time << std::endl;
|
||||
// std::cout << "end_time: " << end_time << std::endl;
|
||||
|
||||
// 4. Change device count
|
||||
++device_count;
|
||||
err = server::LicenseLibrary::LicenseFileSerialization(license_file_path,
|
||||
device_count,
|
||||
uuid_encryption_map,
|
||||
starting_time,
|
||||
end_time);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
|
||||
// 5. Legality check
|
||||
err = server::LicenseCheck::LegalityCheck(license_file_path);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
}
|
||||
|
||||
TEST(LicenseLibraryTest, CHECK_ERROR3_TEST){
|
||||
|
||||
server::ServerError err;
|
||||
// 1. Set license file name
|
||||
std::string license_file_path("/tmp/megasearch/abc.license");
|
||||
|
||||
// 2. Define output var
|
||||
int device_count;
|
||||
std::map<int, std::string> uuid_encryption_map;
|
||||
time_t starting_time;
|
||||
time_t end_time;
|
||||
|
||||
// 3. Read License File
|
||||
err = server::LicenseLibrary::LicenseFileDeserialization(license_file_path,
|
||||
device_count,
|
||||
uuid_encryption_map,
|
||||
starting_time,
|
||||
end_time);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
|
||||
// 4. Change device count
|
||||
if(device_count) uuid_encryption_map[0]+="u";
|
||||
err = server::LicenseLibrary::LicenseFileSerialization(license_file_path,
|
||||
device_count,
|
||||
uuid_encryption_map,
|
||||
starting_time,
|
||||
end_time);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
|
||||
// 5. Legality check
|
||||
err = server::LicenseCheck::LegalityCheck(license_file_path);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
}
|
||||
|
||||
TEST(LicenseLibraryTest, CHECK_ERROR4_1_TEST){
|
||||
|
||||
server::ServerError err;
|
||||
// 1. Set license file name
|
||||
std::string license_file_path("/tmp/megasearch/abc.license");
|
||||
|
||||
// 2. Define output var
|
||||
int device_count;
|
||||
std::map<int, std::string> uuid_encryption_map;
|
||||
time_t starting_time;
|
||||
time_t end_time;
|
||||
|
||||
// 3. Read License File
|
||||
err = server::LicenseLibrary::LicenseFileDeserialization(license_file_path,
|
||||
device_count,
|
||||
uuid_encryption_map,
|
||||
starting_time,
|
||||
end_time);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
|
||||
// 4. Change starting time
|
||||
time_t system_time;
|
||||
err = server::LicenseLibrary::GetSystemTime(system_time);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
|
||||
system_time+=111100;
|
||||
system_time+=60*60*24;
|
||||
|
||||
err = server::LicenseLibrary::LicenseFileSerialization(license_file_path,
|
||||
device_count,
|
||||
uuid_encryption_map,
|
||||
system_time,
|
||||
end_time);
|
||||
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
// 19. Legality check
|
||||
err = server::LicenseCheck::LegalityCheck(license_file_path);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
|
||||
// 20. Start counting down
|
||||
|
||||
// err = server::LicenseCheck::StartCountingDown(license_file_path);
|
||||
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
// 5. Legality check
|
||||
err = server::LicenseCheck::LegalityCheck(license_file_path);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
}
|
||||
|
||||
TEST(LicenseLibraryTest, CHECK_ERROR4_2_TEST){
|
||||
|
||||
server::ServerError err;
|
||||
// 1. Set license file name
|
||||
std::string license_file_path("/tmp/megasearch/abc.license");
|
||||
|
||||
// 2. Define output var
|
||||
int device_count;
|
||||
std::map<int, std::string> uuid_encryption_map;
|
||||
time_t starting_time;
|
||||
time_t end_time;
|
||||
|
||||
// 3. Read License File
|
||||
err = server::LicenseLibrary::LicenseFileDeserialization(license_file_path,
|
||||
device_count,
|
||||
uuid_encryption_map,
|
||||
starting_time,
|
||||
end_time);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
|
||||
// 4. Change end time
|
||||
time_t system_time;
|
||||
err = server::LicenseLibrary::GetSystemTime(system_time);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
|
||||
system_time-=100;
|
||||
|
||||
err = server::LicenseLibrary::LicenseFileSerialization(license_file_path,
|
||||
device_count,
|
||||
uuid_encryption_map,
|
||||
starting_time,
|
||||
system_time);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
|
||||
// 5. Legality check
|
||||
err = server::LicenseCheck::LegalityCheck(license_file_path);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
}
|
||||
|
||||
|
@ -66,153 +66,10 @@ TEST(LicenseLibraryTest, GPU_INFO_TEST) {
|
||||
|
||||
TEST(LicenseLibraryTest, LICENSE_FILE_TEST) {
|
||||
|
||||
// 1. Get Device Count
|
||||
int device_count = 0;
|
||||
server::ServerError err = server::LicenseLibrary::GetDeviceCount(device_count);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
|
||||
// 2. Get All GPU UUID
|
||||
std::vector<std::string> uuid_array;
|
||||
err = server::LicenseLibrary::GetUUID(device_count, uuid_array);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
|
||||
// 3. Get UUID SHA256
|
||||
std::vector<std::string> uuid_sha256_array;
|
||||
err = server::LicenseLibrary::GetUUIDSHA256(device_count, uuid_array, uuid_sha256_array);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
|
||||
|
||||
// 4. Set a file name
|
||||
std::string license_file_path("/tmp/megasearch.license");
|
||||
|
||||
// 5. Provide remaining hour
|
||||
int64_t remaining_hour = 2 * 365 * 24;
|
||||
|
||||
// 6. Generate GPU ID map with GPU UUID
|
||||
std::map<int, std::string> uuid_encrption_map;
|
||||
for (int i = 0; i < device_count; ++i) {
|
||||
uuid_encrption_map[i] = uuid_sha256_array[i];
|
||||
}
|
||||
|
||||
// 7.GPU_info File
|
||||
std::string GPU_info_file_path("/tmp/megasearch.info");
|
||||
|
||||
|
||||
// 8. Generate GPU_info File
|
||||
err = server::LicenseLibrary::GPUinfoFileSerialization(GPU_info_file_path,
|
||||
device_count,
|
||||
uuid_encrption_map);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
|
||||
// 9. Define output var
|
||||
int output_info_device_count = 0;
|
||||
std::map<int, std::string> output_info_uuid_encrption_map;
|
||||
|
||||
// 10. Read GPU_info File
|
||||
err = server::LicenseLibrary::GPUinfoFileDeserialization(GPU_info_file_path,
|
||||
output_info_device_count,
|
||||
output_info_uuid_encrption_map);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
|
||||
ASSERT_EQ(device_count, output_info_device_count);
|
||||
for (int i = 0; i < device_count; ++i) {
|
||||
ASSERT_EQ(uuid_encrption_map[i], output_info_uuid_encrption_map[i]);
|
||||
}
|
||||
|
||||
|
||||
// 16. Get System Time/starting_time ans End Time
|
||||
time_t starting_time;
|
||||
err = server::LicenseLibrary::GetSystemTime(starting_time);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
time_t end_time;
|
||||
end_time = starting_time + (long) (60 * 60 * 24 * 7);
|
||||
|
||||
// 11. Generate License File
|
||||
err = server::LicenseLibrary::LicenseFileSerialization(license_file_path,
|
||||
device_count,
|
||||
uuid_encrption_map,
|
||||
starting_time,
|
||||
end_time);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
|
||||
// 12. Define output var
|
||||
int output_device_count = 0;
|
||||
std::map<int, std::string> output_uuid_encrption_map;
|
||||
time_t output_starting_time;
|
||||
time_t output_end_time;
|
||||
|
||||
// 13. Read License File
|
||||
err = server::LicenseLibrary::LicenseFileDeserialization(license_file_path,
|
||||
output_device_count,
|
||||
output_uuid_encrption_map,
|
||||
output_starting_time,
|
||||
output_end_time);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
|
||||
ASSERT_EQ(device_count, output_device_count);
|
||||
ASSERT_EQ(starting_time, output_starting_time);
|
||||
ASSERT_EQ(end_time, output_end_time);
|
||||
|
||||
for (int i = 0; i < device_count; ++i) {
|
||||
ASSERT_EQ(uuid_encrption_map[i], output_uuid_encrption_map[i]);
|
||||
}
|
||||
|
||||
// 14. Get License File Attribute
|
||||
time_t update_time;
|
||||
off_t file_size;
|
||||
err = server::LicenseLibrary::GetFileUpdateTimeAndSize(license_file_path, update_time, file_size);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
|
||||
// 15. Get License File MD5
|
||||
std::string file_md5;
|
||||
err = server::LicenseLibrary::GetFileMD5(license_file_path, file_md5);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
|
||||
|
||||
|
||||
// 16. Generate Secret File
|
||||
// std::string secret_file_path("/tmp/megasearch.secret");
|
||||
// err = server::LicenseLibrary::SecretFileSerialization(secret_file_path,
|
||||
// update_time,
|
||||
// file_size,
|
||||
// starting_time,
|
||||
// end_time,
|
||||
// file_md5);
|
||||
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
|
||||
// 17. Define output var
|
||||
// time_t output_update_time;
|
||||
// off_t output_file_size;
|
||||
// time_t output_starting_time;
|
||||
// time_t output_end_time;
|
||||
// std::string output_file_md5;
|
||||
|
||||
// 18. Read License File
|
||||
// err = server::LicenseLibrary::SecretFileDeserialization(secret_file_path,
|
||||
// output_update_time,
|
||||
// output_file_size,
|
||||
// output_starting_time,
|
||||
// output_end_time,
|
||||
// output_file_md5);
|
||||
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
//
|
||||
// ASSERT_EQ(update_time, output_update_time);
|
||||
// ASSERT_EQ(file_size, output_file_size);
|
||||
// ASSERT_EQ(starting_time, output_starting_time);
|
||||
// ASSERT_EQ(end_time, output_end_time);
|
||||
// ASSERT_EQ(file_md5, output_file_md5);
|
||||
|
||||
// 19. Integrity check and Legality check
|
||||
// err = server::LicenseLibrary::IntegrityCheck(license_file_path, secret_file_path);
|
||||
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
//
|
||||
// err = server::LicenseLibrary::LegalityCheck(license_file_path);
|
||||
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
|
||||
}
|
||||
|
||||
|
||||
TEST(LicenseLibraryTest, GET_GPU_INFO_FILE) {
|
||||
// 0. File check
|
||||
std::string test("/tmp/a.test");
|
||||
bool is = server::LicenseLibrary::IsFileExistent(test);
|
||||
ASSERT_EQ(is, false);
|
||||
|
||||
// 1. Get Device Count
|
||||
int device_count = 0;
|
||||
@ -238,85 +95,91 @@ TEST(LicenseLibraryTest, GET_GPU_INFO_FILE) {
|
||||
// 5.GPU_info File
|
||||
std::string GPU_info_file_path("/tmp/megasearch.info");
|
||||
|
||||
|
||||
// 6. Generate GPU_info File
|
||||
err = server::LicenseLibrary::GPUinfoFileSerialization(GPU_info_file_path,
|
||||
device_count,
|
||||
uuid_encrption_map);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
|
||||
std::cout << "Generate GPU_info File Success" << std::endl;
|
||||
}
|
||||
|
||||
TEST(LicenseLibraryTest, GET_LICENSE_FILE) {
|
||||
|
||||
server::ServerError err;
|
||||
// 1.GPU_info File
|
||||
std::string GPU_info_file_path("/tmp/megasearch.info");
|
||||
|
||||
// 2. License File
|
||||
std::string license_file_path("/tmp/megasearch.license");
|
||||
|
||||
// 3. Define output var
|
||||
// 7. Define output var
|
||||
int output_info_device_count = 0;
|
||||
std::map<int, std::string> output_info_uuid_encrption_map;
|
||||
|
||||
// 4. Read GPU_info File
|
||||
// 8. Read GPU_info File
|
||||
err = server::LicenseLibrary::GPUinfoFileDeserialization(GPU_info_file_path,
|
||||
output_info_device_count,
|
||||
output_info_uuid_encrption_map);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
|
||||
time_t system_time;
|
||||
err = server::LicenseLibrary::GetSystemTime(system_time);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
time_t starting_time = system_time;
|
||||
time_t end_time = system_time + (long) (60 * 60 * 24 * 7);
|
||||
ASSERT_EQ(device_count, output_info_device_count);
|
||||
for (int i = 0; i < device_count; ++i) {
|
||||
ASSERT_EQ(uuid_encrption_map[i], output_info_uuid_encrption_map[i]);
|
||||
}
|
||||
|
||||
// 9. Set license file name
|
||||
std::string license_file_path("/tmp/megasearch.license");
|
||||
|
||||
// 10. Get System Time/starting_time ans End Time
|
||||
time_t sysyem_time;
|
||||
err = server::LicenseLibrary::GetSystemTime(sysyem_time);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
|
||||
// 11.GetDateTime
|
||||
time_t starting_time;
|
||||
time_t end_time;
|
||||
char *string_starting_time = "2019-05-10";
|
||||
char *string_end_time = "2022-05-10";
|
||||
err = server::LicenseLibrary::GetDateTime(string_starting_time, starting_time);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
err = server::LicenseLibrary::GetDateTime(string_end_time, end_time);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
|
||||
// 12. Generate License File
|
||||
err = server::LicenseLibrary::LicenseFileSerialization(license_file_path,
|
||||
output_info_device_count,
|
||||
output_info_uuid_encrption_map,
|
||||
device_count,
|
||||
uuid_encrption_map,
|
||||
starting_time,
|
||||
end_time);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
std::cout << "Generate License File Success" << std::endl;
|
||||
|
||||
}
|
||||
// 13. Define output var
|
||||
int output_device_count = 0;
|
||||
std::map<int, std::string> output_uuid_encrption_map;
|
||||
time_t output_starting_time;
|
||||
time_t output_end_time;
|
||||
|
||||
TEST(LicenseLibraryTest, GET_DATA_TIME) {
|
||||
server::ServerError err;
|
||||
char * a ="2018-03-06";
|
||||
time_t pp;
|
||||
err = server::LicenseLibrary::GetDateTime(a,pp);
|
||||
// 14. Read License File
|
||||
err = server::LicenseLibrary::LicenseFileDeserialization(license_file_path,
|
||||
output_device_count,
|
||||
output_uuid_encrption_map,
|
||||
output_starting_time,
|
||||
output_end_time);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
std::cout << pp <<std::endl;
|
||||
|
||||
}
|
||||
ASSERT_EQ(device_count, output_device_count);
|
||||
ASSERT_EQ(starting_time, output_starting_time);
|
||||
ASSERT_EQ(end_time, output_end_time);
|
||||
|
||||
//TEST(LicenseLibraryTest, GET_SECRET_FILE) {
|
||||
//
|
||||
// server::ServerError err;
|
||||
// std::string license_file_path("/tmp/megasearch.license");
|
||||
// std::string secret_file_path("/tmp/megasearch.secret");
|
||||
//
|
||||
// // 14. Get License File Attribute
|
||||
for (int i = 0; i < device_count; ++i) {
|
||||
ASSERT_EQ(uuid_encrption_map[i], output_uuid_encrption_map[i]);
|
||||
}
|
||||
|
||||
// // 15. Get License File Attribute
|
||||
// time_t update_time;
|
||||
// off_t file_size;
|
||||
// err = server::LicenseLibrary::GetFileUpdateTimeAndSize(license_file_path, update_time, file_size);
|
||||
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
//
|
||||
// // 15. Get License File MD5
|
||||
// // 16. Get License File MD5
|
||||
// std::string file_md5;
|
||||
// err = server::LicenseLibrary::GetFileMD5(license_file_path, file_md5);
|
||||
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
//
|
||||
// // 16. Get System Time/starting_time ans End Time
|
||||
// time_t starting_time;
|
||||
// err = server::LicenseLibrary::GetSystemTime(starting_time);
|
||||
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
// time_t end_time;
|
||||
// end_time = starting_time + (long) (60 * 60 * 24 * 7);
|
||||
//
|
||||
// // 16. Generate Secret File
|
||||
|
||||
|
||||
|
||||
// // 17. Generate Secret File
|
||||
// std::string secret_file_path("/tmp/megasearch.secret");
|
||||
// err = server::LicenseLibrary::SecretFileSerialization(secret_file_path,
|
||||
// update_time,
|
||||
// file_size,
|
||||
@ -324,6 +187,28 @@ TEST(LicenseLibraryTest, GET_DATA_TIME) {
|
||||
// end_time,
|
||||
// file_md5);
|
||||
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
|
||||
// // 18. Define output var
|
||||
// time_t output_update_time;
|
||||
// off_t output_file_size;
|
||||
// time_t output_starting_time;
|
||||
// time_t output_end_time;
|
||||
// std::string output_file_md5;
|
||||
|
||||
// // 19. Read License File
|
||||
// err = server::LicenseLibrary::SecretFileDeserialization(secret_file_path,
|
||||
// output_update_time,
|
||||
// output_file_size,
|
||||
// output_starting_time,
|
||||
// output_end_time,
|
||||
// output_file_md5);
|
||||
// ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
//
|
||||
// std::cout << "Generate Secret File Success" << std::endl;
|
||||
//}
|
||||
// ASSERT_EQ(update_time, output_update_time);
|
||||
// ASSERT_EQ(file_size, output_file_size);
|
||||
// ASSERT_EQ(starting_time, output_starting_time);
|
||||
// ASSERT_EQ(end_time, output_end_time);
|
||||
// ASSERT_EQ(file_md5, output_file_md5);
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,191 +0,0 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
|
||||
// Unauthorized copying of this file, via any medium is strictly prohibited.
|
||||
// Proprietary and confidential.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#include <gtest/gtest.h>
|
||||
#include <license/LicenseLibrary.h>
|
||||
#include "license/LicenseCheck.h"
|
||||
#include "license/LicensePublic.h"
|
||||
#include "utils/Error.h"
|
||||
|
||||
|
||||
using namespace zilliz::vecwise;
|
||||
|
||||
//TEST(LicenseTest, LICENSE_TEST) {
|
||||
|
||||
// std::string path1 = "/tmp/vecwise_engine.license";
|
||||
// std::string path2 = "/tmp/vecwise_engine2.license";
|
||||
// std::cout << "This is run " << std::endl;
|
||||
//
|
||||
// server::ServerError err;
|
||||
//
|
||||
// err = server::Licensefileread(path1);
|
||||
// if(err!=server::SERVER_SUCCESS)
|
||||
// {
|
||||
// exit(1);
|
||||
// }
|
||||
// err = server::LicenseIntegrity_check(path1,path2);
|
||||
// if(err!=server::SERVER_SUCCESS)
|
||||
// {
|
||||
// std::cout << "Integrity_check is wrong " << std::endl;
|
||||
// exit(1);
|
||||
// }
|
||||
// err = server::LicenseLegality_check(path1);
|
||||
// if(err!=server::SERVER_SUCCESS)
|
||||
// {
|
||||
// std::cout << "Legality_check is wrong " << std::endl;
|
||||
// exit(1);
|
||||
// }
|
||||
// std::cout << " runing " << std::endl;
|
||||
// server::Runtime(path1,path2);
|
||||
//}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
TEST(LicenseTest, LICENSE_TEST) {
|
||||
std::string path1 = "/tmp/vecwise_engine.license";
|
||||
std::string path2 = "/tmp/vecwise_engine2.license";
|
||||
|
||||
server::ServerError err;
|
||||
server::Runtime(path1,path2);
|
||||
|
||||
|
||||
time_t update_time;
|
||||
off_t file_size;
|
||||
std::string filemd5;
|
||||
|
||||
time_t update_timecheck;
|
||||
off_t file_sizecheck;
|
||||
std::string filemd5check;
|
||||
|
||||
err = server::LicenseGetfiletime(path1,update_time);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
|
||||
err = server::LicenseGetfilesize(path1,file_size);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
|
||||
err = server::LicenseGetfilemd5(path1,filemd5);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
|
||||
err = server::LifileSave(path2,update_time,file_size,filemd5);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
|
||||
err = server::LifileLoad(path2,update_timecheck,file_sizecheck,filemd5check);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
|
||||
|
||||
std::cout<< "update_time : " << update_time <<std::endl;
|
||||
std::cout<< "update_timecheck : " << update_timecheck <<std::endl;
|
||||
|
||||
std::cout<< "file_size : " << file_size<<std::endl;
|
||||
std::cout<< "file_sizecheck : " << file_sizecheck <<std::endl;
|
||||
|
||||
std::cout<< "filemd5 : " << filemd5 <<std::endl;
|
||||
std::cout<< "filemd5check : " << filemd5check <<std::endl;
|
||||
|
||||
|
||||
err = server::LicenseValidate(path1);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
|
||||
int deviceCount = 0;
|
||||
std::vector<std::string> uuids;
|
||||
|
||||
deviceCount = 2;
|
||||
uuids.push_back("121");
|
||||
uuids.push_back("324");
|
||||
err = server::LicenseGetuuid(deviceCount,uuids);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
printf("\n deviceCount = %d\n",deviceCount);
|
||||
|
||||
std::vector<std::string> uuidmd5s;
|
||||
err = server::LicenseGetuuidmd5(deviceCount,uuids,uuidmd5s);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
|
||||
printf(" md5s \n");
|
||||
for(int i=0;i<deviceCount;i++)
|
||||
std::cout<< uuidmd5s[i] << std::endl;
|
||||
|
||||
std::vector<std::string> uuidshas;
|
||||
err = server::LicenseGetuuidsha(deviceCount,uuids,uuidshas);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
|
||||
std::map<int,std::string> uuidEncryption;
|
||||
for(int i=0;i<deviceCount;i++)
|
||||
{
|
||||
uuidEncryption.insert(std::make_pair(i,uuidshas[i]));
|
||||
}
|
||||
for(int i=0;i<deviceCount;i++)
|
||||
{
|
||||
std::cout<< "uuidshas : " << uuidshas[i] << std::endl;
|
||||
}
|
||||
|
||||
err = server::LiSave(path1,deviceCount,uuidEncryption);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
|
||||
int64_t RemainingTime;
|
||||
int deviceCountcheck;
|
||||
std::map<int,std::string> uuidEncryptioncheck;
|
||||
// err = server::LicenseLibrary::LicenseFileDeserialization(path1, deviceCountcheck, uuidEncryptioncheck, RemainingTime);
|
||||
err = server::LiLoad(path1,deviceCountcheck,uuidEncryptioncheck,RemainingTime);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
|
||||
printf("----- checking ----\n");
|
||||
printf("\n deviceCount = %d\n",deviceCountcheck);
|
||||
for(auto it : uuidEncryptioncheck)
|
||||
{
|
||||
std::cout<< "uuidshas : " << it.second << std::endl;
|
||||
}
|
||||
std::cout<< "RemainingTime :" << RemainingTime << std::endl;
|
||||
|
||||
printf(" shas \n");
|
||||
for(int i=0;i<deviceCount;i++)
|
||||
std::cout<< uuidshas[i] << std::endl;
|
||||
|
||||
|
||||
|
||||
err = server::LicenseSave(path1,deviceCount,uuidshas);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
|
||||
std::cout<<" file save success " << std::endl;
|
||||
|
||||
|
||||
|
||||
err = server::LicenseLegalitycheck(path1);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
std::cout<<" Legality check success " << std::endl;
|
||||
|
||||
std::vector<std::string> uuidshascheck;
|
||||
|
||||
err = server::LicenseLoad(path1,deviceCountcheck,uuidshascheck);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
|
||||
std::cout<<" deviceCountcheck :" << deviceCountcheck << std::endl;
|
||||
std::cout<<" uuidshascheck :" << uuidshascheck[0] << std::endl;
|
||||
|
||||
|
||||
err = server::LicenseGetfilemd5(path1,filemd5);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
std::cout<<" filemd5 :" << filemd5 << std::endl;
|
||||
|
||||
err= server::LicensefileSave(path1,path2);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
|
||||
time_t last_timecheck;
|
||||
err= server::LicensefileLoad(path2,filemd5check,last_timecheck);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
std::cout<<" filemd5check :" << filemd5check << std::endl;
|
||||
|
||||
time_t last_time;
|
||||
err = server::LicenseGetfiletime(path1,last_time);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
|
||||
std::cout<<" last_time : " << last_time << std::endl;
|
||||
std::cout<<" last_timecheck :" << last_timecheck << std::endl;
|
||||
|
||||
err = server::LicenseIntegritycheck(path1,path2);
|
||||
ASSERT_EQ(err, server::SERVER_SUCCESS);
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user