From e5a6048eeca3050246911f0ebb40d7546905ab2b Mon Sep 17 00:00:00 2001 From: sfan5 Date: Thu, 14 Dec 2023 11:41:22 +0100 Subject: [PATCH] Allow running individual benchmarks mirrors and reuses the option from 2f6a9d12f1db84322e0b69fd5ddc986f1f143606 --- src/benchmark/benchmark.cpp | 10 ++++++---- src/benchmark/benchmark.h | 2 +- src/main.cpp | 7 +++++-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/benchmark/benchmark.cpp b/src/benchmark/benchmark.cpp index 0bc2af368..2eb35d9e0 100644 --- a/src/benchmark/benchmark.cpp +++ b/src/benchmark/benchmark.cpp @@ -23,10 +23,12 @@ with this program; if not, write to the Free Software Foundation, Inc., #define CATCH_CONFIG_RUNNER #include "benchmark_setup.h" -int run_benchmarks() +bool run_benchmarks(const char *arg) { - int argc = 1; - const char *argv[] = { "MinetestBenchmark", NULL }; + const char *const argv[] = { + "MinetestBenchmark", arg, nullptr + }; + const int argc = arg ? 2 : 1; int errCount = Catch::Session().run(argc, argv); - return errCount ? 1 : 0; + return errCount == 0; } diff --git a/src/benchmark/benchmark.h b/src/benchmark/benchmark.h index 45dd9b6a4..3726c3925 100644 --- a/src/benchmark/benchmark.h +++ b/src/benchmark/benchmark.h @@ -22,5 +22,5 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "config.h" #if BUILD_BENCHMARKS -extern int run_benchmarks(); +extern bool run_benchmarks(const char *arg = nullptr); #endif diff --git a/src/main.cpp b/src/main.cpp index 377d6547b..dc98fb74d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -234,7 +234,10 @@ int main(int argc, char *argv[]) // Run benchmarks if (cmd_args.getFlag("run-benchmarks")) { #if BUILD_BENCHMARKS - return run_benchmarks(); + if (cmd_args.exists("test-module")) + return run_benchmarks(cmd_args.get("test-module").c_str()) ? 0 : 1; + else + return run_benchmarks() ? 0 : 1; #else errorstream << "Benchmark support is not enabled in this binary. " << "If you want to enable it, compile project with BUILD_BENCHMARKS=1 flag." @@ -340,7 +343,7 @@ static void set_allowed_options(OptionList *allowed_options) allowed_options->insert(std::make_pair("run-benchmarks", ValueSpec(VALUETYPE_FLAG, _("Run the benchmarks and exit")))); allowed_options->insert(std::make_pair("test-module", ValueSpec(VALUETYPE_STRING, - _("Only run the specified test module")))); + _("Only run the specified test module or benchmark")))); allowed_options->insert(std::make_pair("map-dir", ValueSpec(VALUETYPE_STRING, _("Same as --world (deprecated)")))); allowed_options->insert(std::make_pair("world", ValueSpec(VALUETYPE_STRING,