From ae9b8e93f7fc7f48d7ee61eceb87be8835325553 Mon Sep 17 00:00:00 2001 From: Ludovic 'Archivist' Lagouardette Date: Sat, 6 Jul 2019 23:00:02 +0200 Subject: [PATCH] Added more configuration and testing --- Makefile | 2 +- src/izaro-storage.cpp | 76 ++++++++++++++++++++++++++++--------------- src/test_client.cpp | 9 +++-- 3 files changed, 57 insertions(+), 30 deletions(-) diff --git a/Makefile b/Makefile index 66a0d59..452a652 100644 --- a/Makefile +++ b/Makefile @@ -21,7 +21,7 @@ CXX := -clang++ -DEBUG := -g -O2 -DUNITTEST +DEBUG := -g -O0 -DUNITTEST RELEASE := -s -O3 -fno-rtti CXXFLAGS := $(DEBUG) -Wno-unknown-warning-option -Wno-address-of-packed-member -pedantic-errors -Wall -Wextra -Werror -Wfatal-errors -std=c++17 -m64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE diff --git a/src/izaro-storage.cpp b/src/izaro-storage.cpp index daa0c0b..89ad791 100644 --- a/src/izaro-storage.cpp +++ b/src/izaro-storage.cpp @@ -21,9 +21,53 @@ int main( [[maybe_unused]] char** argv ) { + + + CMD::commander cmd_args(argc, argv); + + std::string database_str = "/data/"; + + if(cmd_args.isFlagSet("-database")) + { + database_str = cmd_args.getFlagValue("-database"); + } + + std::string utest_str = "/tmp/"; + + if(cmd_args.isFlagSet("-utest")) + { + utest_str = cmd_args.getFlagValue("-utest"); + } + + size_t database_size = 4096; + + if(cmd_args.isFlagSet("-page-count")) + { + try{ + database_size = std::stoll(cmd_args.getFlagValue("-page-count")); + } catch (...) { + std::cerr << "Invalid page-count value" << std::endl; + return 1; + } + + } + + size_t utest_size = 4096; + + if(cmd_args.isFlagSet("-utest-count")) + { + try{ + utest_size = std::stoll(cmd_args.getFlagValue("-utest-count")); + } catch (...) { + std::cerr << "Invalid utest-count value" << std::endl; + return 1; + } + + } + #ifdef UNITTEST { - database db(database::create("/tmp/", 4096)); + database db(database::create(utest_str, utest_size*2)); db_page v; v.fill(1); @@ -32,14 +76,13 @@ int main( auto begin = std::chrono::high_resolution_clock::now(); - size_t tot = 2048; - for(size_t idx=0;idx(std::chrono::high_resolution_clock::now() - begin)/tot; + auto durr = std::chrono::duration_cast(std::chrono::high_resolution_clock::now() - begin)/utest_size; std::cerr << "durr/elem = " << durr.count() << "ns/op" << std::endl; @@ -71,7 +114,7 @@ int main( db.write(tar, v); } - database reop(database::open("/tmp/")); + database reop(database::open(utest_str)); { a = reop.read(tar); @@ -101,27 +144,6 @@ int main( } #endif - CMD::commander cmd_args(argc, argv); - - std::string database_str = "/data/"; - - if(cmd_args.isFlagSet("-database")) - { - database_str = cmd_args.getFlagValue("-database"); - } - - size_t database_size = 4096; - - if(cmd_args.isFlagSet("-page-count")) - { - try{ - database_size = std::stoll(cmd_args.getFlagValue("-page-count")); - } catch (...) { - std::cerr << "Invalid page-count value" << std::endl; - return 1; - } - - } if(cmd_args.isFlagSet("-create")) { @@ -192,7 +214,7 @@ int main( run_db.write(recv.identifier, recv.page); reply.identifier = recv.identifier; } catch (...) { - + std::cerr << "cluster overfull"<< std::endl; } reply_size = sizeof(reply.rep_id) + sizeof(reply.identifier); } diff --git a/src/test_client.cpp b/src/test_client.cpp index c944cc0..8b54f66 100644 --- a/src/test_client.cpp +++ b/src/test_client.cpp @@ -3,7 +3,7 @@ #include #include -int main() { +int main(int, char** argv) { { auto soc = socket(AF_INET, SOCK_DGRAM, 0); struct sockaddr_in server; @@ -11,6 +11,12 @@ int main() { server.sin_addr.s_addr = *(in_addr_t*)std::array{127,0,0,1}.data(); server.sin_port = htons(20450); + uint32_t tot = 2048; + + if(argv[1]) + { + tot = std::stoi(argv[1]); + } connect(soc, (struct sockaddr*)&server, sizeof(server)); @@ -24,7 +30,6 @@ int main() { auto begin = std::chrono::high_resolution_clock::now(); - size_t tot = 2048; for(size_t idx=0;idx