diff --git a/mace/utils/tuner_test.cc b/mace/utils/tuner_test.cc index b040a5a62694e53f0792088080d3a7c644c4dd7d..869318f46474cba9f873aefb31356ef071f9397f 100644 --- a/mace/utils/tuner_test.cc +++ b/mace/utils/tuner_test.cc @@ -20,7 +20,8 @@ class TunerTest : public ::testing::Test { TEST_F(TunerTest, SimpleRun) { int expect = 1; - auto TunerFunc = [&](const std::vector ¶ms) -> int { + auto TunerFunc = [&](const std::vector ¶ms, Timer *timer, + std::vector *tuning_result) -> int { if (params.front() == 1) { return expect; } else { @@ -43,13 +44,30 @@ TEST_F(TunerTest, SimpleRun) { TEST_F(TunerTest, SimpleTune) { int expect = 3; - auto TunerFunc = [&](const std::vector ¶ms) -> int { - if (params.front() == expect) { - return expect; + auto TunerFunc = [&](const std::vector ¶ms, Timer *timer, + std::vector *tuning_result) -> int { + int res = 0; + if (timer) { + timer->ClearTiming(); + timer->StartTiming(); + if (params.front() == expect) { + timer->AccumulateTiming(); + res = expect; + } else { + std::this_thread::sleep_for(std::chrono::milliseconds(10)); + timer->AccumulateTiming(); + res = params.front(); + } + tuning_result->assign(params.begin(), params.end()); } else { - std::this_thread::sleep_for(std::chrono::milliseconds(10)); - return params.front(); + if (params.front() == expect) { + res = expect; + } else { + std::this_thread::sleep_for(std::chrono::milliseconds(10)); + res = params.front(); + } } + return res; }; std::vector default_params(1, 1); diff --git a/mace/utils/utils_test.cc b/mace/utils/utils_test.cc deleted file mode 100644 index b040a5a62694e53f0792088080d3a7c644c4dd7d..0000000000000000000000000000000000000000 --- a/mace/utils/utils_test.cc +++ /dev/null @@ -1,71 +0,0 @@ -// -// Copyright (c) 2017 XiaoMi All rights reserved. -// -#include // NOLINT(build/c++11) - -#include "gtest/gtest.h" - -#include "mace/utils/tuner.h" - -namespace mace { - -class TunerTest : public ::testing::Test { - protected: - virtual void SetUp() { - remove("/data/local/tmp/mace.config"); - setenv("MACE_RUN_PARAMETER_PATH", "/data/local/tmp/mace.config", 1); - setenv("MACE_TUNING", "1", 1); - } -}; - -TEST_F(TunerTest, SimpleRun) { - int expect = 1; - auto TunerFunc = [&](const std::vector ¶ms) -> int { - if (params.front() == 1) { - return expect; - } else { - return expect + 1; - } - }; - - WallClockTimer timer; - std::vector default_params(1, 1); - int res = Tuner::Get()->template TuneOrRun( - "SimpleRun", default_params, nullptr, TunerFunc, &timer); - - EXPECT_EQ(expect, res); - - default_params[0] = 2; - res = Tuner::Get()->template TuneOrRun( - "SimpleRun", default_params, nullptr, TunerFunc, &timer); - EXPECT_EQ(expect + 1, res); -} - -TEST_F(TunerTest, SimpleTune) { - int expect = 3; - auto TunerFunc = [&](const std::vector ¶ms) -> int { - if (params.front() == expect) { - return expect; - } else { - std::this_thread::sleep_for(std::chrono::milliseconds(10)); - return params.front(); - } - }; - - std::vector default_params(1, 1); - auto params_generator = []() -> std::vector> { - return {{1}, {2}, {3}, {4}}; - }; - // tune - WallClockTimer timer; - int res = Tuner::Get()->template TuneOrRun( - "SimpleRun", default_params, *params_generator, TunerFunc, &timer); - EXPECT_EQ(expect, res); - - // run - res = Tuner::Get()->template TuneOrRun( - "SimpleRun", default_params, nullptr, TunerFunc, &timer); - EXPECT_EQ(expect, res); -} - -} // namespace mace