From cbe6648eb8c3a4580e900f473fda3daafc2b6f06 Mon Sep 17 00:00:00 2001 From: Mislav Bradac Date: Thu, 6 Jul 2017 13:53:39 +0200 Subject: [PATCH] Migrate command line args to gflgs in tests Summary: Some other minor cleanups Reviewers: buda Reviewed By: buda Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D523 --- .ycm_extra_conf.py | 1 + CMakeLists.txt | 2 - README.md | 3 +- format | 1 - poc/example.cpp | 4 +- src/communication/bolt/v1/constants.hpp | 2 + src/communication/bolt/v1/state.hpp | 2 + src/communication/bolt/v1/states/error.hpp | 1 + src/communication/bolt/v1/states/executor.hpp | 1 + .../bolt/v1/states/handshake.hpp | 1 + src/copy_hardcoded_queries.cpp | 16 +- src/data_structures/ptr_int.hpp | 49 ----- src/memgraph_bolt.cpp | 4 +- src/template_engine/engine.cpp | 26 --- src/template_engine/engine.hpp | 12 -- src/transactions/engine.hpp | 14 +- src/utils/algorithm.hpp | 20 -- src/utils/array_store.hpp | 10 - src/utils/command_line/arguments.hpp | 174 ------------------ src/utils/counters/atomic_counter.hpp | 20 -- src/utils/counters/ring_counter.hpp | 24 --- src/utils/counters/simple_counter.hpp | 14 -- src/utils/fswatcher.hpp | 20 ++ src/utils/ioc/container.hpp | 81 -------- src/utils/numerics/ceil.hpp | 15 -- src/utils/numerics/log2.hpp | 8 - src/utils/numerics/saturate.cpp | 8 - src/utils/numerics/saturate.hpp | 11 -- src/utils/random_graph_generator.hpp | 8 +- src/utils/types/byte.hpp | 5 - .../bloom/basic_bloom_filter.cpp | 3 +- .../concurrent/bloom_map_concurrent.cpp | 27 +-- .../concurrent/map_concurrent.cpp | 28 +-- .../concurrent/map_mix_concurrent.cpp | 33 ++-- tests/client-stress.sh | 1 - tests/integration/query_engine.cpp | 7 +- tests/integration/query_engine_common.hpp | 11 +- tests/manual/query_engine.cpp | 13 +- tests/manual/query_hash.cpp | 9 +- tests/unit/basic_bloom_filter.cpp | 1 - tests/unit/database_key_index.cpp | 1 - tests/unit/graph_db_accessor_index_api.cpp | 1 - tests/unit/program_argument.cpp | 91 --------- tests/unit/ptr_int.cpp | 26 --- tests/unit/template_engine.cpp | 15 -- 45 files changed, 130 insertions(+), 694 deletions(-) delete mode 100644 src/data_structures/ptr_int.hpp delete mode 100644 src/template_engine/engine.cpp delete mode 100644 src/template_engine/engine.hpp delete mode 100644 src/utils/array_store.hpp delete mode 100644 src/utils/command_line/arguments.hpp delete mode 100644 src/utils/counters/atomic_counter.hpp delete mode 100644 src/utils/counters/ring_counter.hpp delete mode 100644 src/utils/counters/simple_counter.hpp delete mode 100644 src/utils/ioc/container.hpp delete mode 100644 src/utils/numerics/ceil.hpp delete mode 100644 src/utils/numerics/log2.hpp delete mode 100644 src/utils/numerics/saturate.cpp delete mode 100644 src/utils/numerics/saturate.hpp delete mode 100644 src/utils/types/byte.hpp delete mode 100644 tests/unit/program_argument.cpp delete mode 100644 tests/unit/ptr_int.cpp delete mode 100644 tests/unit/template_engine.cpp diff --git a/.ycm_extra_conf.py b/.ycm_extra_conf.py index ddcb2eef4..fdf5171f3 100644 --- a/.ycm_extra_conf.py +++ b/.ycm_extra_conf.py @@ -25,6 +25,7 @@ BASE_FLAGS = [ '-I./libs/googletest/googletest/include', '-I./libs/googletest/googlemock/include', '-I./libs/benchmark/include', + '-I./libs/rapidcheck/include', '-I./libs/antlr4/runtime/Cpp/runtime/src', '-I./build/libs/gflags/include' ] diff --git a/CMakeLists.txt b/CMakeLists.txt index abd06c1b3..8d463d020 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -308,10 +308,8 @@ set(memgraph_src_files ${src_dir}/storage/property_value.cpp ${src_dir}/storage/record_accessor.cpp ${src_dir}/storage/vertex_accessor.cpp - ${src_dir}/template_engine/engine.cpp ${src_dir}/threading/thread.cpp ${src_dir}/transactions/transaction.cpp - ${src_dir}/utils/numerics/saturate.cpp ) # ----------------------------------------------------------------------------- diff --git a/README.md b/README.md index e4f692d31..6d7fe1457 100644 --- a/README.md +++ b/README.md @@ -20,4 +20,5 @@ on a 64 bit linux kernel. * fmt format * google benchmark * google test -* yaml-cpp +* glog +* gflags diff --git a/format b/format index 727999857..bba26ed1e 100755 --- a/format +++ b/format @@ -15,4 +15,3 @@ do echo "formatting code under $directory/" find "$directory" \( -name '*.hpp' -or -name '*.cpp' \) -print0 | xargs -0 "${clang_format}" -i done - diff --git a/poc/example.cpp b/poc/example.cpp index b1773819a..9b97f3e03 100644 --- a/poc/example.cpp +++ b/poc/example.cpp @@ -1,6 +1,6 @@ #include int main() { - std::cout << "Proof of concept binary example" << std::endl; - return 0; + std::cout << "Proof of concept binary example" << std::endl; + return 0; } diff --git a/src/communication/bolt/v1/constants.hpp b/src/communication/bolt/v1/constants.hpp index 3d8cb3369..3fd5a8ecf 100644 --- a/src/communication/bolt/v1/constants.hpp +++ b/src/communication/bolt/v1/constants.hpp @@ -1,5 +1,7 @@ #pragma once +#include + namespace communication::bolt { /** diff --git a/src/communication/bolt/v1/state.hpp b/src/communication/bolt/v1/state.hpp index 8dcb20c27..32e0c26e1 100644 --- a/src/communication/bolt/v1/state.hpp +++ b/src/communication/bolt/v1/state.hpp @@ -1,5 +1,7 @@ #pragma once +#include + namespace communication::bolt { /** diff --git a/src/communication/bolt/v1/states/error.hpp b/src/communication/bolt/v1/states/error.hpp index 5bd4a4987..3185f31e1 100644 --- a/src/communication/bolt/v1/states/error.hpp +++ b/src/communication/bolt/v1/states/error.hpp @@ -5,6 +5,7 @@ #include "communication/bolt/v1/codes.hpp" #include "communication/bolt/v1/state.hpp" +#include "query/typed_value.hpp" namespace communication::bolt { diff --git a/src/communication/bolt/v1/states/executor.hpp b/src/communication/bolt/v1/states/executor.hpp index c4620864f..ee18f47de 100644 --- a/src/communication/bolt/v1/states/executor.hpp +++ b/src/communication/bolt/v1/states/executor.hpp @@ -7,6 +7,7 @@ #include "communication/bolt/v1/codes.hpp" #include "communication/bolt/v1/state.hpp" #include "query/exceptions.hpp" +#include "query/typed_value.hpp" #include "utils/exceptions.hpp" namespace communication::bolt { diff --git a/src/communication/bolt/v1/states/handshake.hpp b/src/communication/bolt/v1/states/handshake.hpp index 7e2b8f005..0d4e45ef7 100644 --- a/src/communication/bolt/v1/states/handshake.hpp +++ b/src/communication/bolt/v1/states/handshake.hpp @@ -2,6 +2,7 @@ #include +#include "communication/bolt/v1/constants.hpp" #include "communication/bolt/v1/state.hpp" namespace communication::bolt { diff --git a/src/copy_hardcoded_queries.cpp b/src/copy_hardcoded_queries.cpp index 723ae95c7..aa10d8629 100644 --- a/src/copy_hardcoded_queries.cpp +++ b/src/copy_hardcoded_queries.cpp @@ -6,9 +6,9 @@ namespace fs = std::experimental::filesystem; #include +#include "gflags/gflags.h" #include "query/frontend/stripped.hpp" -#include "utils/command_line/arguments.hpp" #include "utils/exceptions.hpp" #include "utils/file.hpp" #include "utils/string.hpp" @@ -22,6 +22,11 @@ namespace fs = std::experimental::filesystem; * @return query as a string. */ +DEFINE_string(src, "tests/integration/hardcoded_queries", + "Path to sources of hardcoded queries."); +DEFINE_string(dst, "build/compiled/hardcode", + "Destination path of hardcoded queries"); + std::string ExtractQuery(const fs::path &path) { auto comment_mark = std::string("// "); auto query_mark = comment_mark + std::string("Query: "); @@ -48,17 +53,14 @@ std::string ExtractQuery(const fs::path &path) { } int main(int argc, char **argv) { + gflags::ParseCommandLineFlags(&argc, &argv, false); google::InitGoogleLogging(argv[0]); - REGISTER_ARGS(argc, argv); - - auto src_path = fs::path( - GET_ARG("--src", "tests/integration/hardcoded_queries").get_string()); + auto src_path = FLAGS_src; LOG(INFO) << "Src path is: " << src_path; permanent_assert(fs::exists(src_path), "src folder must exist"); - auto dst_path = - fs::path(GET_ARG("--dst", "build/compiled/hardcode").get_string()); + auto dst_path = FLAGS_dst; LOG(INFO) << "Dst path is: " << dst_path; fs::create_directories(dst_path); diff --git a/src/data_structures/ptr_int.hpp b/src/data_structures/ptr_int.hpp deleted file mode 100644 index fdbe0c213..000000000 --- a/src/data_structures/ptr_int.hpp +++ /dev/null @@ -1,49 +0,0 @@ -#pragma once - -#include - -#include "utils/numerics/log2.hpp" - -template -struct PointerPackTraits { - // here is a place to embed something like platform specific things - // TODO: cover more cases - constexpr static int free_bits = utils::log2(alignof(PtrT)); - - static auto get_ptr(uintptr_t value) { return (PtrT)(value); } -}; - -template > -class PtrInt { - private: - constexpr static int int_shift = PtrTraits::free_bits - IntBits; - constexpr static uintptr_t ptr_mask = - ~(uintptr_t)(((intptr_t)1 << PtrTraits::free_bits) - 1); - constexpr static uintptr_t int_mask = - (uintptr_t)(((intptr_t)1 << IntBits) - 1); - - uintptr_t value{0}; - - public: - PtrInt(PtrT pointer, IntT integer) { - set_ptr(pointer); - set_int(integer); - } - - auto set_ptr(PtrT pointer) { - auto integer = static_cast(get_int()); - auto ptr = reinterpret_cast(pointer); - value = (ptr_mask & ptr) | (integer << int_shift); - } - - auto set_int(IntT integer) { - auto ptr = reinterpret_cast(get_ptr()); - auto int_shifted = static_cast(integer << int_shift); - value = (int_mask & int_shifted) | ptr; - } - - auto get_ptr() const { return PtrTraits::get_ptr(value & ptr_mask); } - - auto get_int() const { return (IntT)((value >> int_shift) & int_mask); } -}; diff --git a/src/memgraph_bolt.cpp b/src/memgraph_bolt.cpp index 07e7a919b..6288bd3a5 100644 --- a/src/memgraph_bolt.cpp +++ b/src/memgraph_bolt.cpp @@ -1,8 +1,8 @@ #include #include -#include "gflags/gflags.h" -#include "glog/logging.h" +#include +#include #include "dbms/dbms.hpp" #include "query/engine.hpp" diff --git a/src/template_engine/engine.cpp b/src/template_engine/engine.cpp deleted file mode 100644 index 35ce1fe5b..000000000 --- a/src/template_engine/engine.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include "template_engine/engine.hpp" - -#include "utils/string.hpp" - -namespace template_engine { - -/** - * Replaces all placeholders in the form string marked as {{ key }} with values - * defined in the partials dictionary. - * - * @param form template string. - * @param partials values to inject into the template string. - * @return string rendered based on template string and values. - */ -std::string Render(const std::string &form, const data &partials) { - // TODO more optimal implementation - // another option is something like https://github.com/no1msd/mstch - // but it has to be wrapped - string rendered = form; - for (const auto &partial : partials) { - string key = "{{" + partial.first + "}}"; - rendered = utils::Replace(rendered, key, partial.second); - } - return rendered; -} -} diff --git a/src/template_engine/engine.hpp b/src/template_engine/engine.hpp deleted file mode 100644 index 64506147b..000000000 --- a/src/template_engine/engine.hpp +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -#include -#include - -namespace template_engine { - -using std::string; -using data = std::unordered_map; - -std::string Render(const string& form, const data& partials); -} diff --git a/src/transactions/engine.hpp b/src/transactions/engine.hpp index 0f6c30df1..f6b5da5c7 100644 --- a/src/transactions/engine.hpp +++ b/src/transactions/engine.hpp @@ -9,7 +9,6 @@ #include "transactions/commit_log.hpp" #include "transactions/transaction.hpp" #include "transactions/transaction_store.hpp" -#include "utils/counters/simple_counter.hpp" #include "utils/exceptions.hpp" namespace tx { @@ -34,6 +33,19 @@ class Engine : Lockable { std::numeric_limits().cid())>::max(); public: + template + class SimpleCounter { + public: + SimpleCounter(T initial) : counter(initial) {} + + T next() { return ++counter; } + + T count() { return counter; } + + private: + T counter; + }; + /** Begins a transaction and returns a pointer to * it's object. * diff --git a/src/utils/algorithm.hpp b/src/utils/algorithm.hpp index 6a5fc3150..8438c82f8 100644 --- a/src/utils/algorithm.hpp +++ b/src/utils/algorithm.hpp @@ -3,26 +3,6 @@ #include #include -/** - * Goes from first to last item in a container, if an element satisfying the - * predicate then the action is going to be executed and the element is going - * to be shifted to the end of the container. - * - * @tparam ForwardIt type of forward iterator - * @tparam UnaryPredicate type of predicate - * @tparam Action type of action - * - * @return a past-the-end iterator for the new end of the range - */ -template -ForwardIt action_remove_if(ForwardIt first, ForwardIt last, UnaryPredicate p, - Action a) { - auto it = std::remove_if(first, last, p); - if (it == last) return it; - std::for_each(it, last, a); - return it; -} - /** * Outputs a collection of items to the given stream, separating them with the * given delimiter. diff --git a/src/utils/array_store.hpp b/src/utils/array_store.hpp deleted file mode 100644 index 60b20a2e1..000000000 --- a/src/utils/array_store.hpp +++ /dev/null @@ -1,10 +0,0 @@ -#pragma once - -#include - -// TODO: more bytes can be saved if this is array with exact size as number -// of elements. -// TODO: even more bytes can be saved if this is one ptr to structure which -// holds len followed by len sized array. -template -using ArrayStore = std::vector; diff --git a/src/utils/command_line/arguments.hpp b/src/utils/command_line/arguments.hpp deleted file mode 100644 index e1d794bf5..000000000 --- a/src/utils/command_line/arguments.hpp +++ /dev/null @@ -1,174 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "utils/exceptions.hpp" -#include "utils/option.hpp" - -#define REGISTER_ARGS(argc, argv) \ - ProgramArguments::instance().register_args(argc, argv) -#define REGISTER_REQUIRED_ARGS(vector) \ - ProgramArguments::instance().register_required_args(vector) -#define GET_ARG(flag, default_value) \ - ProgramArguments::instance().get_arg(flag, default_value) -#define GET_ARGS(flag, default_value) \ - ProgramArguments::instance().get_arg_list(flag, default_value) -#define CONTAINS_FLAG(flag) ProgramArguments::instance().contains_flag(flag) -#define CLEAR_ARGS() ProgramArguments::instance().clear() - -// TODO namespace utils -namespace { - -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wunused-function" - -class ProgramArgumentException : public utils::StacktraceException { - public: - ProgramArgumentException(const std::string &mess) - : utils::StacktraceException("ProgramArgumentException: " + mess + ".") {} -}; - -class ProgramArguments { - private: - std::map> arguments_; - std::vector required_arguments_; - std::mutex mutex_; - - bool is_flag(const std::string &arg) { return arg[0] == '-'; } - - bool is_valid() { - for (const auto &arg : required_arguments_) - if (!arguments_.count(arg)) return false; - return true; - } - - ProgramArguments() {} - - public: - ~ProgramArguments() {} - - class Argument { - private: - std::string arg_; - - public: - Argument(const std::string &arg) : arg_(arg) {} - std::string get_string() { return arg_; } - int get_int() { return std::atoi(arg_.c_str()); }; - float get_float() { return std::atof(arg_.c_str()); }; - long get_long() { return std::atol(arg_.c_str()); } - }; - - static ProgramArguments &instance() { - static ProgramArguments instance_; - return instance_; - } - - ProgramArguments(ProgramArguments const &) = delete; - ProgramArguments(ProgramArguments &&) = delete; - ProgramArguments &operator=(ProgramArguments const &) = delete; - ProgramArguments &operator=(ProgramArguments &&) = delete; - - void register_args(int argc, char *argv[]) { - std::lock_guard lock(mutex_); - - for (int i = 1; i < argc; i++) { - std::string flag(*(argv + i)); - if (is_flag(flag)) { - arguments_[flag] = {}; - while (i < argc - 1) { - i++; - std::string arg(*(argv + i)); - if (!is_flag(arg)) - arguments_[flag].emplace_back(arg); - else { - i--; - break; - } - } - } - } - - if (required_arguments_.empty()) return; - - if (!is_valid()) - throw ProgramArgumentException("Required Args not satisfied."); - } - - void register_required_args(std::vector args) { - required_arguments_ = args; - - if (arguments_.empty()) return; - - if (!is_valid()) - throw ProgramArgumentException("Required Args not satisfied."); - } - - bool contains_flag(const std::string &flag) { - return arguments_.count(flag) > 0; - } - - auto get_arg(const std::string &flag, const std::string &default_value) { - if (contains_flag(flag)) return Argument(arguments_[flag][0]); - return Argument(default_value); - } - - auto get_arg_list(const std::string &flag, - const std::vector &default_value) { - std::vector ret; - if (contains_flag(flag)) { - for (const auto &arg : arguments_[flag]) ret.emplace_back(arg); - } else - for (const auto &arg : default_value) ret.emplace_back(arg); - return ret; - } - - void clear() { - arguments_.clear(); - required_arguments_.clear(); - } -}; - -auto all_arguments(int argc, char *argv[]) { - return std::vector(argv + 1, argv + argc); -} - -bool contains_argument(const std::vector &all, - const std::string &flag) { - return std::find(all.begin(), all.end(), flag) != all.end(); -} - -// just returns argument value -auto get_argument(const std::vector &all, const std::string &flag, - const std::string &default_value) { - auto it = std::find(all.begin(), all.end(), flag); - - if (it == all.end()) return default_value; - - return all[std::distance(all.begin(), it) + 1]; -} - -Option take_argument(std::vector &all, - const std::string &flag) { - auto it = std::find(all.begin(), all.end(), flag); - - if (it == all.end()) return make_option(); - - auto s = std::string(all[std::distance(all.begin(), it) + 1]); - it++; - it++; - all.erase(std::find(all.begin(), all.end(), flag), it); - - return make_option(std::move(s)); -} - -#pragma clang diagnostic pop -} -// namespace utils diff --git a/src/utils/counters/atomic_counter.hpp b/src/utils/counters/atomic_counter.hpp deleted file mode 100644 index 50ca3f0d5..000000000 --- a/src/utils/counters/atomic_counter.hpp +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once - -#include -#include - -template ::value>::type* = nullptr> -class AtomicCounter { - public: - AtomicCounter(T initial = 0) : counter(initial) {} - - T next(std::memory_order order = std::memory_order_seq_cst) { - return counter.fetch_add(1, order); - } - - T operator++() { return next(); } - - private: - std::atomic counter; -}; diff --git a/src/utils/counters/ring_counter.hpp b/src/utils/counters/ring_counter.hpp deleted file mode 100644 index b3c704be6..000000000 --- a/src/utils/counters/ring_counter.hpp +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -#include - -class RingCounter { - public: - RingCounter(size_t n, size_t initial = 0) : n(n), counter(initial) {} - - size_t operator++() { - counter = (counter + 1) % n; - return counter; - } - - size_t operator++(int) { - auto value = counter; - ++counter; - return value; - } - - operator size_t() const { return counter; } - - private: - size_t n, counter; -}; diff --git a/src/utils/counters/simple_counter.hpp b/src/utils/counters/simple_counter.hpp deleted file mode 100644 index 622efd177..000000000 --- a/src/utils/counters/simple_counter.hpp +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -template -class SimpleCounter { - public: - SimpleCounter(T initial) : counter(initial) {} - - T next() { return ++counter; } - - T count() { return counter; } - - private: - T counter; -}; diff --git a/src/utils/fswatcher.hpp b/src/utils/fswatcher.hpp index 86834f1a3..04a0ded0a 100644 --- a/src/utils/fswatcher.hpp +++ b/src/utils/fswatcher.hpp @@ -47,6 +47,26 @@ void set_non_blocking(int fd) { } } +/** + * Goes from first to last item in a container, if an element satisfying the + * predicate then the action is going to be executed and the element is going + * to be shifted to the end of the container. + * + * @tparam ForwardIt type of forward iterator + * @tparam UnaryPredicate type of predicate + * @tparam Action type of action + * + * @return a past-the-end iterator for the new end of the range + */ +template +ForwardIt action_remove_if(ForwardIt first, ForwardIt last, UnaryPredicate p, + Action a) { + auto it = std::remove_if(first, last, p); + if (it == last) return it; + std::for_each(it, last, a); + return it; +} + using ms = std::chrono::milliseconds; /** diff --git a/src/utils/ioc/container.hpp b/src/utils/ioc/container.hpp deleted file mode 100644 index fd24439fc..000000000 --- a/src/utils/ioc/container.hpp +++ /dev/null @@ -1,81 +0,0 @@ -#pragma once - -#include -#include -#include -#include "utils/assert.hpp" - -namespace ioc { - -class Container { - struct Holdable { - using uptr = std::unique_ptr; - - Holdable() = default; - virtual ~Holdable() = default; - }; - - template - struct Item : public Holdable { - virtual std::shared_ptr get() = 0; - }; - - template - struct Instance : public Item { - Instance(std::shared_ptr item) : item(std::move(item)) {} - Instance(std::shared_ptr&& item) : item(item) {} - - std::shared_ptr get() override { - debug_assert(item != nullptr, "Item is nullptr."); - return item; - } - - std::shared_ptr item; - }; - - template - struct Creator : public Item { - using func = std::function()>; - - Creator(func&& f) : f(f) {} - - std::shared_ptr get() override { return f(); } - - func f; - }; - - public: - template - std::shared_ptr resolve() { - auto it = items.find(key()); - debug_assert(it != items.end(), "Key not found."); - - // try to cast Holdable* to Item* - auto item = dynamic_cast*>(it->second.get()); - debug_assert(item != nullptr, "Item is nullptr."); - - return item->get(); - } - - template - std::shared_ptr singleton(Args&&... args) { - auto item = std::make_shared(resolve()..., args...); - items.emplace(key(), Holdable::uptr(new Instance(item))); - return item; - } - - template - void factory(typename Creator::func&& f) { - items[key()] = std::move(Holdable::uptr( - new Creator(std::forward::func>(f)))); - } - - private: - std::map items; - - template - std::string key() { - return typeid(T).name(); - } -}; -} diff --git a/src/utils/numerics/ceil.hpp b/src/utils/numerics/ceil.hpp deleted file mode 100644 index c8cc0391e..000000000 --- a/src/utils/numerics/ceil.hpp +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -#include - -namespace num { - -template ::value>::type* = nullptr> -T iceil(T x, T y) { - // this may seem inefficient, but on x86_64, when you already perform - // division (x / y) the remainder is already computed and therefore x % y - // is basically free! - return x / y + (x % y != 0); -} -} diff --git a/src/utils/numerics/log2.hpp b/src/utils/numerics/log2.hpp deleted file mode 100644 index 6361f5d17..000000000 --- a/src/utils/numerics/log2.hpp +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once - -#include - -namespace utils { - -constexpr size_t log2(size_t n) { return ((n < 2) ? 0 : 1 + log2(n >> 1)); } -} diff --git a/src/utils/numerics/saturate.cpp b/src/utils/numerics/saturate.cpp deleted file mode 100644 index e61fd8df0..000000000 --- a/src/utils/numerics/saturate.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include "utils/numerics/saturate.hpp" - -std::size_t num::saturating_add(std::size_t a, std::size_t b) { - a = a >= size_t_HIGHEST_BIT_SETED ? size_t_HIGHEST_BIT_SETED - 1 : a; - b = b >= size_t_HIGHEST_BIT_SETED ? size_t_HIGHEST_BIT_SETED - 1 : b; - - return a + b; -} diff --git a/src/utils/numerics/saturate.hpp b/src/utils/numerics/saturate.hpp deleted file mode 100644 index a0cb7d741..000000000 --- a/src/utils/numerics/saturate.hpp +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once - -#include - -namespace num { - -constexpr std::size_t size_t_HIGHEST_BIT_SETED = - ((std::size_t)1) << ((sizeof(std::size_t) * 8) - 1); - -std::size_t saturating_add(std::size_t a, std::size_t b); -}; diff --git a/src/utils/random_graph_generator.hpp b/src/utils/random_graph_generator.hpp index b83328604..19804e07f 100644 --- a/src/utils/random_graph_generator.hpp +++ b/src/utils/random_graph_generator.hpp @@ -68,7 +68,7 @@ class RandomGraphGenerator { */ void AddEdges(uint count, const std::string &edge_type_name, std::function from_filter = {}, - std::function to_filter = {}) { + std::function = {}) { permanent_assert(!did_commit_, "Already committed"); // create two temporary sets of vertices we will poll from @@ -76,7 +76,7 @@ class RandomGraphGenerator { auto vertices_to = Filter(vertices_, from_filter); auto edge_type = dba_.edge_type(edge_type_name); - for (int i = 0; i < count; ++i) + for (int i = 0; i < static_cast(count); ++i) edges_.push_back(dba_.insert_edge( vertices_from[rand() % vertices_from.size()].get(), vertices_to[rand() % vertices_to.size()].get(), edge_type)); @@ -94,7 +94,7 @@ class RandomGraphGenerator { */ template void SetVertexProperty( - uint count, const std::string &prop_name, + uint, const std::string &prop_name, std::function value_generator, std::function predicate = {}) { permanent_assert(!did_commit_, "Already committed"); @@ -139,7 +139,7 @@ class RandomGraphGenerator { std::vector> Filter( std::vector &collection, std::function predicate = {}) { - if (!predicate) predicate = [](TItem &item) { return true; }; + if (!predicate) predicate = [](TItem &) { return true; }; std::vector> r_val; for (TItem &item : collection) if (predicate(item)) r_val.emplace_back(std::ref(item)); diff --git a/src/utils/types/byte.hpp b/src/utils/types/byte.hpp deleted file mode 100644 index 931bd4008..000000000 --- a/src/utils/types/byte.hpp +++ /dev/null @@ -1,5 +0,0 @@ -#pragma once - -#include - -using byte = uint8_t; diff --git a/tests/benchmark/data_structures/bloom/basic_bloom_filter.cpp b/tests/benchmark/data_structures/bloom/basic_bloom_filter.cpp index 034b943ab..6e237f7be 100644 --- a/tests/benchmark/data_structures/bloom/basic_bloom_filter.cpp +++ b/tests/benchmark/data_structures/bloom/basic_bloom_filter.cpp @@ -5,7 +5,6 @@ #include #include "data_structures/bloom/bloom_filter.hpp" -#include "utils/command_line/arguments.hpp" #include "utils/hashing/fnv64.hpp" #include "utils/random/random_generator.hpp" @@ -30,6 +29,7 @@ auto BM_Bloom = [](benchmark::State &state, auto *bloom, const auto &elements) { }; int main(int argc, char **argv) { + benchmark::Initialize(&argc, argv); google::InitGoogleLogging(argv[0]); StringGenerator generator(4); @@ -48,7 +48,6 @@ int main(int argc, char **argv) { ->Range(1, 1 << 16) ->Complexity(benchmark::oN); - benchmark::Initialize(&argc, argv); benchmark::RunSpecifiedBenchmarks(); return 0; } diff --git a/tests/benchmark/data_structures/concurrent/bloom_map_concurrent.cpp b/tests/benchmark/data_structures/concurrent/bloom_map_concurrent.cpp index fe05f6187..d00f4fc1b 100644 --- a/tests/benchmark/data_structures/concurrent/bloom_map_concurrent.cpp +++ b/tests/benchmark/data_structures/concurrent/bloom_map_concurrent.cpp @@ -2,11 +2,11 @@ #include #include +#include #include #include "data_structures/bloom/bloom_filter.hpp" #include "data_structures/concurrent/concurrent_bloom_map.hpp" -#include "utils/command_line/arguments.hpp" #include "utils/hashing/fnv64.hpp" #include "utils/random/random_generator.hpp" @@ -31,6 +31,11 @@ using StringHashFunction = std::function; using IntegerGenerator = NumberGenerator, std::default_random_engine, int>; +DEFINE_int32(start, 0, "Range start"); +DEFINE_int32(end, 1000000000, "Range end"); +DEFINE_int32(threads, 1, "Number of threads"); +DEFINE_int32(string_length, 128, "String length"); + // Global arguments int MAX_ELEMENTS = 1 << 18, MULTIPLIER = 2; int THREADS, RANGE_START, RANGE_END, STRING_LENGTH; @@ -89,24 +94,21 @@ auto BM_ContainsValue = [](benchmark::State &state, auto *map, auto elements) { * Random String lenght -string-length number */ -void parse_arguments(int argc, char **argv) { - REGISTER_ARGS(argc, argv); +void parse_arguments() { + RANGE_START = FLAGS_start; + RANGE_END = FLAGS_end; - RANGE_START = GET_ARG("-start", "0").get_int(); - RANGE_END = GET_ARG("-end", "1000000000").get_int(); + THREADS = std::min(FLAGS_threads, + static_cast(std::thread::hardware_concurrency())); - THREADS = std::min(GET_ARG("-threads", "1").get_int(), - (int)std::thread::hardware_concurrency()); - - STRING_LENGTH = - ProgramArguments::instance().get_arg("-string-length", "128").get_int(); + STRING_LENGTH = FLAGS_string_length; } int main(int argc, char **argv) { + benchmark::Initialize(&argc, argv); + parse_arguments(); google::InitGoogleLogging(argv[0]); - parse_arguments(argc, argv); - StringGenerator sg(STRING_LENGTH); IntegerGenerator ig(RANGE_START, RANGE_END); @@ -176,7 +178,6 @@ int main(int argc, char **argv) { ->Complexity(benchmark::oN) ->Threads(THREADS); - benchmark::Initialize(&argc, argv); benchmark::RunSpecifiedBenchmarks(); return 0; diff --git a/tests/benchmark/data_structures/concurrent/map_concurrent.cpp b/tests/benchmark/data_structures/concurrent/map_concurrent.cpp index 4798895cd..6a5f9c94f 100644 --- a/tests/benchmark/data_structures/concurrent/map_concurrent.cpp +++ b/tests/benchmark/data_structures/concurrent/map_concurrent.cpp @@ -2,10 +2,10 @@ #include #include +#include #include #include "data_structures/concurrent/concurrent_map.hpp" -#include "utils/command_line/arguments.hpp" #include "utils/random/random_generator.hpp" /* @@ -28,6 +28,11 @@ using utils::random::StringGenerator; using IntegerGenerator = NumberGenerator, std::default_random_engine, int>; +DEFINE_int32(start, 0, "Range start"); +DEFINE_int32(end, 1000000000, "Range end"); +DEFINE_int32(threads, 1, "Number of threads"); +DEFINE_int32(string_length, 128, "String length"); + // Global arguments int MAX_ELEMENTS = 1 << 18, MULTIPLIER = 2; int THREADS, RANGE_START, RANGE_END, STRING_LENGTH; @@ -105,24 +110,20 @@ auto BM_ContainsValue = [](benchmark::State &state, auto *map, auto elements) { * Random String lenght -string-length number */ -void parse_arguments(int argc, char **argv) { - REGISTER_ARGS(argc, argv); +void parse_arguments() { + RANGE_START = FLAGS_start; + RANGE_END = FLAGS_end; - RANGE_START = GET_ARG("-start", "0").get_int(); - RANGE_END = GET_ARG("-end", "1000000000").get_int(); - - THREADS = std::min(GET_ARG("-threads", "1").get_int(), - (int)std::thread::hardware_concurrency()); - - STRING_LENGTH = - ProgramArguments::instance().get_arg("-string-length", "128").get_int(); + THREADS = std::min(FLAGS_threads, + static_cast(std::thread::hardware_concurrency())); + STRING_LENGTH = FLAGS_string_length; } int main(int argc, char **argv) { + benchmark::Initialize(&argc, argv); + parse_arguments(); google::InitGoogleLogging(argv[0]); - parse_arguments(argc, argv); - StringGenerator sg(STRING_LENGTH); IntegerGenerator ig(RANGE_START, RANGE_END); @@ -245,7 +246,6 @@ int main(int argc, char **argv) { ->Complexity(benchmark::oN) ->Threads(THREADS); - benchmark::Initialize(&argc, argv); benchmark::RunSpecifiedBenchmarks(); return 0; diff --git a/tests/benchmark/data_structures/concurrent/map_mix_concurrent.cpp b/tests/benchmark/data_structures/concurrent/map_mix_concurrent.cpp index a45ab0f57..dbceb4faa 100644 --- a/tests/benchmark/data_structures/concurrent/map_mix_concurrent.cpp +++ b/tests/benchmark/data_structures/concurrent/map_mix_concurrent.cpp @@ -3,9 +3,9 @@ #include #include +#include "gflags/gflags.h" #include "data_structures/concurrent/concurrent_map.hpp" -#include "utils/command_line/arguments.hpp" #include "utils/random/random_generator.hpp" /* @@ -53,6 +53,13 @@ auto BM_Rape = [](benchmark::State &state, auto *map, auto &elements) { Rape(state, map, elements); }; +DEFINE_int32(insert, 50, "Insertions percentage"); +DEFINE_int32(delete, 20, "Deletions percentage"); +DEFINE_int32(find, 30, "Find percentage"); +DEFINE_int32(start, 0, "Range start"); +DEFINE_int32(end, 1000000000, "Range end"); +DEFINE_int32(threads, 1, "Number of threads"); + /* Commandline Arguments Parsing @@ -75,12 +82,10 @@ auto BM_Rape = [](benchmark::State &state, auto *map, auto &elements) { * Number of threads -threads number */ -void parse_arguments(int argc, char **argv) { - REGISTER_ARGS(argc, argv); - - INSERT_PERC = GET_ARG("-insert", "50").get_int(); - DELETE_PERC = GET_ARG("-delete", "20").get_int(); - CONTAINS_PERC = GET_ARG("-find", "30").get_int(); +void parse_arguments() { + INSERT_PERC = FLAGS_insert; + DELETE_PERC = FLAGS_delete; + CONTAINS_PERC = FLAGS_find; if (INSERT_PERC + DELETE_PERC + CONTAINS_PERC != 100) { std::cout << "Invalid percentage" << std::endl; @@ -88,19 +93,18 @@ void parse_arguments(int argc, char **argv) { exit(-1); } - RANGE_START = GET_ARG("-start", "0").get_int(); + RANGE_START = FLAGS_start; + RANGE_END = FLAGS_end; - RANGE_END = GET_ARG("-end", "1000000000").get_int(); - - THREADS = std::min(GET_ARG("-threads", "1").get_int(), - (int)std::thread::hardware_concurrency()); + THREADS = std::min(FLAGS_threads, + static_cast(std::thread::hardware_concurrency())); } int main(int argc, char **argv) { + benchmark::Initialize(&argc, argv); + parse_arguments(); google::InitGoogleLogging(argv[0]); - parse_arguments(argc, argv); - IntegerGenerator int_gen(RANGE_START, RANGE_END); PairGenerator pair_gen(&int_gen, &int_gen); @@ -114,7 +118,6 @@ int main(int argc, char **argv) { ->Complexity(benchmark::oN) ->Threads(THREADS); - benchmark::Initialize(&argc, argv); benchmark::RunSpecifiedBenchmarks(); return 0; diff --git a/tests/client-stress.sh b/tests/client-stress.sh index 20bd6b63f..c74f95577 100755 --- a/tests/client-stress.sh +++ b/tests/client-stress.sh @@ -31,4 +31,3 @@ if [[ "$running" != "" ]]; then else echo "All ok!" fi - diff --git a/tests/integration/query_engine.cpp b/tests/integration/query_engine.cpp index 9d87050c1..b6111426a 100644 --- a/tests/integration/query_engine.cpp +++ b/tests/integration/query_engine.cpp @@ -7,6 +7,10 @@ DECLARE_bool(interpret); DECLARE_string(compile_directory); +DEFINE_string(q, "../data/queries/core/mg_basic_002.txt", + "Path to warm up queries"); +DEFINE_string(i, "../integration/hardcoded_query", + "Path to folder with query implementations"); using namespace std::chrono_literals; using namespace tests::integration; @@ -19,9 +23,6 @@ using namespace tests::integration; * NOTE: This test will be usefull to test generated query plans. */ int main(int argc, char *argv[]) { - /** - * init arguments - */ gflags::ParseCommandLineFlags(&argc, &argv, true); /** diff --git a/tests/integration/query_engine_common.hpp b/tests/integration/query_engine_common.hpp index f4595595a..bc64bfb8a 100644 --- a/tests/integration/query_engine_common.hpp +++ b/tests/integration/query_engine_common.hpp @@ -4,6 +4,7 @@ #include namespace fs = std::experimental::filesystem; +#include #include #include "database/graph_db_accessor.hpp" @@ -11,10 +12,12 @@ namespace fs = std::experimental::filesystem; #include "query/engine.hpp" #include "query/frontend/stripped.hpp" #include "stream/print_record_stream.hpp" -#include "utils/command_line/arguments.hpp" #include "utils/file.hpp" #include "utils/string.hpp" +DECLARE_string(q); +DECLARE_string(i); + namespace tests { namespace integration { @@ -149,11 +152,9 @@ auto ExecuteQueryPlans(QueryEngineT &engine, Dbms &dbms, const fs::path &path, */ auto WarmUpEngine(QueryEngineT &engine, Dbms &dbms, StreamT &stream) { // path to a file with queries - auto queries_file = fs::path( - GET_ARG("-q", "../data/queries/core/mg_basic_002.txt").get_string()); + auto queries_file = fs::path(FLAGS_q); // folder with query implementations - auto implementations_folder = - fs::path(GET_ARG("-i", "../integration/hardcoded_query").get_string()); + auto implementations_folder = fs::path(FLAGS_i); // load all query hashes from queries file auto query_hashes = LoadQueryHashes(queries_file); diff --git a/tests/manual/query_engine.cpp b/tests/manual/query_engine.cpp index 53dcd09df..cf9782d91 100644 --- a/tests/manual/query_engine.cpp +++ b/tests/manual/query_engine.cpp @@ -1,19 +1,24 @@ #define HARDCODED_OUTPUT_STREAM +#include #include "../integration/query_engine_common.hpp" #include "dbms/dbms.hpp" #include "utils/fswatcher.hpp" +// Needed by query_engine_common.hpp. +DEFINE_string(q, "../data/queries/core/mg_basic_002.txt", + "Path to warm up queries"); +DEFINE_string(i, "../integration/hardcoded_query", + "Path to folder with query implementations"); + using namespace std::chrono_literals; using namespace tests::integration; int main(int argc, char *argv[]) { - // init arguments - REGISTER_ARGS(argc, argv); + gflags::ParseCommandLineFlags(&argc, &argv, true); // forlder with query implementations - auto implementations_folder = - fs::path(GET_ARG("-i", "tests/integration/hardcoded_query").get_string()); + auto implementations_folder = fs::path(FLAGS_i); // init engine init_logging("ManualQueryEngine"); diff --git a/tests/manual/query_hash.cpp b/tests/manual/query_hash.cpp index a61b71d1f..ed77a9afa 100644 --- a/tests/manual/query_hash.cpp +++ b/tests/manual/query_hash.cpp @@ -4,9 +4,10 @@ #include #include "query/frontend/stripped.hpp" -#include "utils/command_line/arguments.hpp" #include "utils/type_discovery.hpp" +DEFINE_string(q, "CREATE (n) RETURN n", "Query"); + /** * Useful when somebody wants to get a hash for some query. * @@ -14,13 +15,11 @@ * ./query_hash -q "CREATE (n {name: \"test\n"}) RETURN n" */ int main(int argc, char **argv) { + gflags::ParseCommandLineFlags(&argc, &argv, true); google::InitGoogleLogging(argv[0]); - // init args - REGISTER_ARGS(argc, argv); - // take query from input args - auto query = GET_ARG("-q", "CREATE (n) RETURN n").get_string(); + auto query = FLAGS_q; // run preprocessing query::StrippedQuery preprocessed(query); diff --git a/tests/unit/basic_bloom_filter.cpp b/tests/unit/basic_bloom_filter.cpp index 9cf57ad97..26acbb3e0 100644 --- a/tests/unit/basic_bloom_filter.cpp +++ b/tests/unit/basic_bloom_filter.cpp @@ -3,7 +3,6 @@ #include #include "data_structures/bloom/bloom_filter.hpp" -#include "utils/command_line/arguments.hpp" #include "utils/hashing/fnv64.hpp" using StringHashFunction = std::function; diff --git a/tests/unit/database_key_index.cpp b/tests/unit/database_key_index.cpp index 7c7f1a1a9..4b229ffdb 100644 --- a/tests/unit/database_key_index.cpp +++ b/tests/unit/database_key_index.cpp @@ -1,7 +1,6 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" -#include "data_structures/ptr_int.hpp" #include "database/graph_db_accessor.hpp" #include "database/graph_db_datatypes.hpp" #include "dbms/dbms.hpp" diff --git a/tests/unit/graph_db_accessor_index_api.cpp b/tests/unit/graph_db_accessor_index_api.cpp index e1d59c110..314f804b4 100644 --- a/tests/unit/graph_db_accessor_index_api.cpp +++ b/tests/unit/graph_db_accessor_index_api.cpp @@ -4,7 +4,6 @@ #include #include -#include "data_structures/ptr_int.hpp" #include "database/graph_db_accessor.hpp" #include "dbms/dbms.hpp" #include "utils/bound.hpp" diff --git a/tests/unit/program_argument.cpp b/tests/unit/program_argument.cpp deleted file mode 100644 index b02acd421..000000000 --- a/tests/unit/program_argument.cpp +++ /dev/null @@ -1,91 +0,0 @@ -#include "gtest/gtest.h" - -#include "utils/command_line/arguments.hpp" - -// beacuse of c++ 11 -// TODO: figure out better solution -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wwritable-strings" - -TEST(ProgramArgument, FlagOnly) { - CLEAR_ARGS(); - - int argc = 2; - char *argv[] = {"ProgramArgument FlagOnly Test", "-test"}; - - REGISTER_ARGS(argc, argv); - REGISTER_REQUIRED_ARGS({"-test"}); - - ASSERT_EQ(CONTAINS_FLAG("-test"), true); -} - -TEST(ProgramArgument, SingleEntry) { - CLEAR_ARGS(); - - int argc = 3; - char *argv[] = {"ProgramArgument Single Entry Test", "-bananas", "99"}; - - REGISTER_REQUIRED_ARGS({"-bananas"}); - REGISTER_ARGS(argc, argv); - - ASSERT_EQ(GET_ARG("-bananas", "100").get_int(), 99); -} - -TEST(ProgramArgument, MultipleEntries) { - CLEAR_ARGS(); - - int argc = 4; - char *argv[] = {"ProgramArgument Multiple Entries Test", "-files", - "first_file.txt", "second_file.txt"}; - - REGISTER_ARGS(argc, argv); - - auto files = GET_ARGS("-files", {}); - - ASSERT_EQ(files[0].get_string(), "first_file.txt"); -} - -TEST(ProgramArgument, Combination) { - CLEAR_ARGS(); - - int argc = 14; - char *argv[] = {"ProgramArgument Combination Test", - "-run_tests", - "-tests", - "Test1", - "Test2", - "Test3", - "-run_times", - "10", - "-export", - "test1.txt", - "test2.txt", - "test3.txt", - "-import", - "data.txt"}; - - REGISTER_ARGS(argc, argv); - - ASSERT_EQ(CONTAINS_FLAG("-run_tests"), true); - - auto tests = GET_ARGS("-tests", {}); - ASSERT_EQ(tests[0].get_string(), "Test1"); - ASSERT_EQ(tests[1].get_string(), "Test2"); - ASSERT_EQ(tests[2].get_string(), "Test3"); - - ASSERT_EQ(GET_ARG("-run_times", "0").get_int(), 10); - - auto exports = GET_ARGS("-export", {}); - ASSERT_EQ(exports[0].get_string(), "test1.txt"); - ASSERT_EQ(exports[1].get_string(), "test2.txt"); - ASSERT_EQ(exports[2].get_string(), "test3.txt"); - - ASSERT_EQ(GET_ARG("-import", "test.txt").get_string(), "data.txt"); -} - -#pragma clang diagnostic pop - -int main(int argc, char **argv) { - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/tests/unit/ptr_int.cpp b/tests/unit/ptr_int.cpp deleted file mode 100644 index 68591ced8..000000000 --- a/tests/unit/ptr_int.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include "gtest/gtest.h" - -#include "data_structures/ptr_int.hpp" - -TEST(PtrInt, SizeOf) { - ASSERT_EQ(sizeof(PtrInt), sizeof(uintptr_t)); -} - -TEST(PtrInt, ConstructionAndRead) { - auto ptr1 = std::make_unique(2); - PtrInt pack1(ptr1.get(), 1); - - ASSERT_EQ(pack1.get_int(), 1); - ASSERT_EQ(pack1.get_ptr(), ptr1.get()); - - auto ptr2 = std::make_unique(2); - PtrInt pack2(ptr2.get(), 4); - - ASSERT_EQ(pack2.get_int(), 4); - ASSERT_EQ(pack2.get_ptr(), ptr2.get()); -} - -int main(int argc, char **argv) { - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/tests/unit/template_engine.cpp b/tests/unit/template_engine.cpp deleted file mode 100644 index b54fe98e3..000000000 --- a/tests/unit/template_engine.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include "gtest/gtest.h" - -#include "template_engine/engine.hpp" - -TEST(TemplateEngine, BasicPlaceholderReplacement) { - auto rendered = template_engine::Render("{{one}} {{two}}", - {{"one", "two"}, {"two", "one"}}); - - ASSERT_EQ(rendered, "two one"); -} - -int main(int argc, char **argv) { - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -}