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
This commit is contained in:
Mislav Bradac 2017-07-06 13:53:39 +02:00
parent d608d523c5
commit cbe6648eb8
45 changed files with 130 additions and 694 deletions

View File

@ -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'
]

View File

@ -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
)
# -----------------------------------------------------------------------------

View File

@ -20,4 +20,5 @@ on a 64 bit linux kernel.
* fmt format
* google benchmark
* google test
* yaml-cpp
* glog
* gflags

1
format
View File

@ -15,4 +15,3 @@ do
echo "formatting code under $directory/"
find "$directory" \( -name '*.hpp' -or -name '*.cpp' \) -print0 | xargs -0 "${clang_format}" -i
done

View File

@ -1,6 +1,6 @@
#include <iostream>
int main() {
std::cout << "Proof of concept binary example" << std::endl;
return 0;
std::cout << "Proof of concept binary example" << std::endl;
return 0;
}

View File

@ -1,5 +1,7 @@
#pragma once
#include <cstddef>
namespace communication::bolt {
/**

View File

@ -1,5 +1,7 @@
#pragma once
#include <cstdint>
namespace communication::bolt {
/**

View File

@ -5,6 +5,7 @@
#include "communication/bolt/v1/codes.hpp"
#include "communication/bolt/v1/state.hpp"
#include "query/typed_value.hpp"
namespace communication::bolt {

View File

@ -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 {

View File

@ -2,6 +2,7 @@
#include <glog/logging.h>
#include "communication/bolt/v1/constants.hpp"
#include "communication/bolt/v1/state.hpp"
namespace communication::bolt {

View File

@ -6,9 +6,9 @@
namespace fs = std::experimental::filesystem;
#include <glog/logging.h>
#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);

View File

@ -1,49 +0,0 @@
#pragma once
#include <cinttypes>
#include "utils/numerics/log2.hpp"
template <typename PtrT>
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 <typename PtrT, int IntBits, typename IntT = unsigned,
typename PtrTraits = PointerPackTraits<PtrT>>
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<uintptr_t>(get_int());
auto ptr = reinterpret_cast<uintptr_t>(pointer);
value = (ptr_mask & ptr) | (integer << int_shift);
}
auto set_int(IntT integer) {
auto ptr = reinterpret_cast<uintptr_t>(get_ptr());
auto int_shifted = static_cast<uintptr_t>(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); }
};

View File

@ -1,8 +1,8 @@
#include <experimental/filesystem>
#include <iostream>
#include "gflags/gflags.h"
#include "glog/logging.h"
#include <gflags/gflags.h>
#include <glog/logging.h>
#include "dbms/dbms.hpp"
#include "query/engine.hpp"

View File

@ -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;
}
}

View File

@ -1,12 +0,0 @@
#pragma once
#include <string>
#include <unordered_map>
namespace template_engine {
using std::string;
using data = std::unordered_map<std::string, std::string>;
std::string Render(const string& form, const data& partials);
}

View File

@ -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<SpinLock> {
std::numeric_limits<decltype(std::declval<Transaction>().cid())>::max();
public:
template <class T>
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.
*

View File

@ -3,26 +3,6 @@
#include <algorithm>
#include <string>
/**
* 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 <class ForwardIt, class UnaryPredicate, class Action>
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.

View File

@ -1,10 +0,0 @@
#pragma once
#include <vector>
// 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 <class T>
using ArrayStore = std::vector<T>;

View File

@ -1,174 +0,0 @@
#pragma once
#include <algorithm>
#include <exception>
#include <iostream>
#include <map>
#include <mutex>
#include <set>
#include <string>
#include <vector>
#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<std::string, std::vector<std::string>> arguments_;
std::vector<std::string> 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<std::mutex> 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<std::string> 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<std::string> &default_value) {
std::vector<Argument> 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<std::string>(argv + 1, argv + argc);
}
bool contains_argument(const std::vector<std::string> &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<std::string> &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<std::string> take_argument(std::vector<std::string> &all,
const std::string &flag) {
auto it = std::find(all.begin(), all.end(), flag);
if (it == all.end()) return make_option<std::string>();
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::string>(std::move(s));
}
#pragma clang diagnostic pop
}
// namespace utils

View File

@ -1,20 +0,0 @@
#pragma once
#include <atomic>
#include <type_traits>
template <class T,
typename std::enable_if<std::is_integral<T>::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<T> counter;
};

View File

@ -1,24 +0,0 @@
#pragma once
#include <cstdlib>
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;
};

View File

@ -1,14 +0,0 @@
#pragma once
template <class T>
class SimpleCounter {
public:
SimpleCounter(T initial) : counter(initial) {}
T next() { return ++counter; }
T count() { return counter; }
private:
T counter;
};

View File

@ -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 <class ForwardIt, class UnaryPredicate, class Action>
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;
/**

View File

@ -1,81 +0,0 @@
#pragma once
#include <map>
#include <memory>
#include <vector>
#include "utils/assert.hpp"
namespace ioc {
class Container {
struct Holdable {
using uptr = std::unique_ptr<Holdable>;
Holdable() = default;
virtual ~Holdable() = default;
};
template <class T>
struct Item : public Holdable {
virtual std::shared_ptr<T> get() = 0;
};
template <class T>
struct Instance : public Item<T> {
Instance(std::shared_ptr<T> item) : item(std::move(item)) {}
Instance(std::shared_ptr<T>&& item) : item(item) {}
std::shared_ptr<T> get() override {
debug_assert(item != nullptr, "Item is nullptr.");
return item;
}
std::shared_ptr<T> item;
};
template <class T>
struct Creator : public Item<T> {
using func = std::function<std::shared_ptr<T>()>;
Creator(func&& f) : f(f) {}
std::shared_ptr<T> get() override { return f(); }
func f;
};
public:
template <class T>
std::shared_ptr<T> resolve() {
auto it = items.find(key<T>());
debug_assert(it != items.end(), "Key not found.");
// try to cast Holdable* to Item<T>*
auto item = dynamic_cast<Item<T>*>(it->second.get());
debug_assert(item != nullptr, "Item is nullptr.");
return item->get();
}
template <class T, class... Deps, class... Args>
std::shared_ptr<T> singleton(Args&&... args) {
auto item = std::make_shared<T>(resolve<Deps>()..., args...);
items.emplace(key<T>(), Holdable::uptr(new Instance<T>(item)));
return item;
}
template <class T>
void factory(typename Creator<T>::func&& f) {
items[key<T>()] = std::move(Holdable::uptr(
new Creator<T>(std::forward<typename Creator<T>::func>(f))));
}
private:
std::map<std::string, Holdable::uptr> items;
template <class T>
std::string key() {
return typeid(T).name();
}
};
}

View File

@ -1,15 +0,0 @@
#pragma once
#include <type_traits>
namespace num {
template <class T,
typename std::enable_if<std::is_integral<T>::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);
}
}

View File

@ -1,8 +0,0 @@
#pragma once
#include <cstddef>
namespace utils {
constexpr size_t log2(size_t n) { return ((n < 2) ? 0 : 1 + log2(n >> 1)); }
}

View File

@ -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;
}

View File

@ -1,11 +0,0 @@
#pragma once
#include <type_traits>
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);
};

View File

@ -68,7 +68,7 @@ class RandomGraphGenerator {
*/
void AddEdges(uint count, const std::string &edge_type_name,
std::function<bool(VertexAccessor &va)> from_filter = {},
std::function<bool(VertexAccessor &va)> to_filter = {}) {
std::function<bool(VertexAccessor &va)> = {}) {
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<int>(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 <typename TValue>
void SetVertexProperty(
uint count, const std::string &prop_name,
uint, const std::string &prop_name,
std::function<TValue()> value_generator,
std::function<bool(VertexAccessor &va)> predicate = {}) {
permanent_assert(!did_commit_, "Already committed");
@ -139,7 +139,7 @@ class RandomGraphGenerator {
std::vector<std::reference_wrapper<TItem>> Filter(
std::vector<TItem> &collection,
std::function<bool(TItem &item)> predicate = {}) {
if (!predicate) predicate = [](TItem &item) { return true; };
if (!predicate) predicate = [](TItem &) { return true; };
std::vector<std::reference_wrapper<TItem>> r_val;
for (TItem &item : collection)
if (predicate(item)) r_val.emplace_back(std::ref(item));

View File

@ -1,5 +0,0 @@
#pragma once
#include <cstdint>
using byte = uint8_t;

View File

@ -5,7 +5,6 @@
#include <glog/logging.h>
#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;
}

View File

@ -2,11 +2,11 @@
#include <thread>
#include <benchmark/benchmark_api.h>
#include <gflags/gflags.h>
#include <glog/logging.h>
#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<uint64_t(const std::string &)>;
using IntegerGenerator = NumberGenerator<std::uniform_int_distribution<int>,
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<int>(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;

View File

@ -2,10 +2,10 @@
#include <thread>
#include <benchmark/benchmark_api.h>
#include <gflags/gflags.h>
#include <glog/logging.h>
#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::uniform_int_distribution<int>,
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<int>(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;

View File

@ -3,9 +3,9 @@
#include <benchmark/benchmark_api.h>
#include <glog/logging.h>
#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<int>(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<IntegerGenerator, IntegerGenerator> 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;

View File

@ -31,4 +31,3 @@ if [[ "$running" != "" ]]; then
else
echo "All ok!"
fi

View File

@ -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);
/**

View File

@ -4,6 +4,7 @@
#include <set>
namespace fs = std::experimental::filesystem;
#include <gflags/gflags.h>
#include <glog/logging.h>
#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);

View File

@ -1,19 +1,24 @@
#define HARDCODED_OUTPUT_STREAM
#include <gflags/gflags.h>
#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");

View File

@ -4,9 +4,10 @@
#include <glog/logging.h>
#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);

View File

@ -3,7 +3,6 @@
#include <functional>
#include "data_structures/bloom/bloom_filter.hpp"
#include "utils/command_line/arguments.hpp"
#include "utils/hashing/fnv64.hpp"
using StringHashFunction = std::function<uint64_t(const std::string &)>;

View File

@ -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"

View File

@ -4,7 +4,6 @@
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "data_structures/ptr_int.hpp"
#include "database/graph_db_accessor.hpp"
#include "dbms/dbms.hpp"
#include "utils/bound.hpp"

View File

@ -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();
}

View File

@ -1,26 +0,0 @@
#include "gtest/gtest.h"
#include "data_structures/ptr_int.hpp"
TEST(PtrInt, SizeOf) {
ASSERT_EQ(sizeof(PtrInt<int *, 1, int>), sizeof(uintptr_t));
}
TEST(PtrInt, ConstructionAndRead) {
auto ptr1 = std::make_unique<int>(2);
PtrInt<int *, 2, int> pack1(ptr1.get(), 1);
ASSERT_EQ(pack1.get_int(), 1);
ASSERT_EQ(pack1.get_ptr(), ptr1.get());
auto ptr2 = std::make_unique<int>(2);
PtrInt<int *, 3, int> 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();
}

View File

@ -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();
}