diff options
author | Tor Egge <tegge@vespa.ai> | 2024-02-19 20:16:42 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-19 20:16:42 +0100 |
commit | f6df579e0ce0bdff9d24a51eac01ce743af9f981 (patch) | |
tree | ba0b06bb1fceb40b16a5bbbeca7683d40e5eb75f /searchlib | |
parent | 7339b1542dc78f48c207c90646a2c9a69c3beb8f (diff) | |
parent | 2a13f7737a2261e534c73b6487a359900b407f7b (diff) |
Merge pull request #30331 from vespa-engine/toregge/rewrite-featurebenchmark-unit-test-to-gtest
Rewrite featurebenchmark unit test to gtest.
Diffstat (limited to 'searchlib')
-rw-r--r-- | searchlib/src/tests/features/featurebenchmark.cpp | 49 |
1 files changed, 32 insertions, 17 deletions
diff --git a/searchlib/src/tests/features/featurebenchmark.cpp b/searchlib/src/tests/features/featurebenchmark.cpp index 9c3d4943d65..1c208cb0537 100644 --- a/searchlib/src/tests/features/featurebenchmark.cpp +++ b/searchlib/src/tests/features/featurebenchmark.cpp @@ -11,8 +11,10 @@ #include <vespa/searchlib/fef/functiontablefactory.h> #include <vespa/searchlib/fef/test/plugin/setup.h> #include <vespa/vespalib/util/stringfmt.h> -#include <vespa/searchlib/test/ft_test_app.h> +#define ENABLE_GTEST_MIGRATION +#include <vespa/searchlib/test/ft_test_app_base.h> #include <vespa/searchcommon/attribute/config.h> +#include <vespa/vespalib/gtest/gtest.h> #include <fstream> #include <iomanip> @@ -37,7 +39,8 @@ using AttributePtr = AttributeVector::SP; using CollectionType = FieldInfo::CollectionType; -class Benchmark : public FtTestApp { +class Benchmark : public ::testing::Test, + public FtTestAppBase { public: using KeyValueVector = std::vector<std::pair<vespalib::string, vespalib::string> >; @@ -106,6 +109,8 @@ public: }; private: + int _argc; + char **_argv; search::fef::BlueprintFactory _factory; vespalib::Timer _timer; vespalib::duration _sample; @@ -130,16 +135,24 @@ private: void runNativeProximity(Config & cfg); public: - Benchmark(); - ~Benchmark(); - int Main() override; + Benchmark(int argc, char **argv); + ~Benchmark() override; + void TestBody() override; }; -TEST_APPHOOK(Benchmark); +Benchmark::Benchmark(int argc, char **argv) + : ::testing::Test(), + FtTestAppBase(), + _argc(argc), + _argv(argv), + _factory(), + _timer(), + _sample() +{ +} -Benchmark::Benchmark() : _factory(), _timer(), _sample() {} -Benchmark::~Benchmark() {} +Benchmark::~Benchmark() = default; bool Benchmark::Config::isKnown(const vespalib::string & key) const @@ -589,11 +602,9 @@ Benchmark::runNativeProximity(Config & cfg) sample(); } -int -Benchmark::Main() +void +Benchmark::TestBody() { - TEST_INIT("featurebenchmark"); - // Configure factory with all known blueprints. setup_fef_test_plugin(_factory); setup_search_features(_factory); @@ -617,8 +628,8 @@ Benchmark::Main() } if (_argc != optind || optError) { - //usage(); - return -1; + FAIL() << "Bad options"; + return; } Config cfg; @@ -651,8 +662,12 @@ Benchmark::Main() std::cout << "TET: " << vespalib::count_ms(_sample) << " (ms)" << std::endl; std::cout << "ETPD: " << std::fixed << std::setprecision(10) << double(vespalib::count_ms(_sample)) / cfg.getNumRuns() << " (ms)" << std::endl; std::cout << "**** '" << cfg.getFeature() << "' ****" << std::endl; - - TEST_DONE(); - return 0; } +int main(int argc, char** argv) { + ::testing::InitGoogleTest(&argc, argv); + ::testing::RegisterTest("Benchmark", "benchmark", nullptr, "", + __FILE__, __LINE__, + [=]() -> Benchmark* { return new Benchmark(argc, argv); }); + return RUN_ALL_TESTS(); +} |