Skip to content

Commit

Permalink
Add test for basic benchmark options
Browse files Browse the repository at this point in the history
  • Loading branch information
petya2164 committed Jun 13, 2019
1 parent 56214bf commit 6cbcfc5
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 10 deletions.
12 changes: 12 additions & 0 deletions test/gauge_tests.cpp
Expand Up @@ -8,6 +8,18 @@
#include <cstdint>
#include <ctime>

#include <gauge/gauge.hpp>

TEST(test_gauge, run_benchmarks)
{
// Dummy arguments for gauge::runner
int argc = 1;
const char* argv[] = { "program" };

gauge::runner::add_default_printers();
gauge::runner::run_benchmarks(argc, argv);
}

GTEST_API_ int main(int argc, char** argv)
{
srand(static_cast<uint32_t>(time(0)));
Expand Down
110 changes: 110 additions & 0 deletions test/src/test_options.cpp
@@ -0,0 +1,110 @@
// Copyright (c) 2012 Steinwurf ApS
// All Rights Reserved
//
// Distributed under the "BSD License". See the accompanying LICENSE.rst file.

#include <gauge/gauge.hpp>

#include <chrono>
#include <thread>

#include <gtest/gtest.h>

struct option_benchmark : public gauge::time_benchmark
{
void store_run(tables::table& results)
{
if (!results.has_column("magic"))
results.add_column("magic");

results.set_value("magic", m_delay.count());
}

double measurement()
{
// Get the time spent sleeping
double time = gauge::time_benchmark::measurement();
// This should be higher than 99% of the requested time
// The sleep period might end a little earlier on Windows
EXPECT_GE(time, m_delay.count() * 0.99);
return time;
}

void get_options(gauge::po::variables_map& options)
{
auto symbols = options["symbols"].as<std::vector<uint32_t>>();
auto symbol_size = options["symbol_size"].as<std::vector<uint32_t>>();
auto types = options["type"].as<std::vector<std::string>>();

assert(symbols.size() > 0);
assert(symbol_size.size() > 0);
assert(types.size() > 0);

for (uint32_t i = 0; i < symbols.size(); ++i)
{
for (uint32_t j = 0; j < symbol_size.size(); ++j)
{
for (uint32_t u = 0; u < types.size(); ++u)
{
gauge::config_set cs;
cs.set_value<uint32_t>("symbols", symbols[i]);
cs.set_value<uint32_t>("symbol_size", symbol_size[j]);
cs.set_value<std::string>("type", types[u]);

add_configuration(cs);
}
}
}
}

void test_body()
{
gauge::config_set cs = get_current_configuration();

uint32_t symbols = cs.get_value<uint32_t>("symbols");

m_delay = std::chrono::milliseconds(symbols);

RUN
{
std::this_thread::sleep_for(m_delay);
}
}

protected:

std::chrono::microseconds m_delay;
};

BENCHMARK_OPTION(basic_options)
{
gauge::po::options_description options;

auto default_symbols =
gauge::po::value<std::vector<uint32_t>>()->
default_value({16, 32}, "")->
multitoken();

auto default_symbol_size =
gauge::po::value<std::vector<uint32_t>>()->
default_value({1600}, "")->
multitoken();

auto default_types =
gauge::po::value<std::vector<std::string>>()->
default_value({"encoder", "decoder"}, "")->
multitoken();

options.add_options()
("symbols", default_symbols, "Set the number of symbols");

options.add_options()
("symbol_size", default_symbol_size, "Set the symbol size in bytes");

options.add_options()
("type", default_types, "Set type [encoder|decoder]");

gauge::runner::instance().register_options(options);
}

BENCHMARK_F(option_benchmark, options, basic, 10);
10 changes: 0 additions & 10 deletions test/src/test_time.cpp
Expand Up @@ -60,13 +60,3 @@ BENCHMARK_F_INLINE(sleep_benchmark, sleep, 100msec, 1)
{
run_benchmark(std::chrono::milliseconds(100));
}

TEST(gauge, sleep_intervals)
{
// Dummy arguments for gauge::runner
int argc = 1;
const char* argv[] = { "program" };

gauge::runner::add_default_printers();
gauge::runner::run_benchmarks(argc, argv);
}

0 comments on commit 6cbcfc5

Please sign in to comment.