Allow running individual benchmarks

mirrors and reuses the option from 2f6a9d12f1
This commit is contained in:
sfan5 2023-12-14 11:41:22 +01:00
parent 3c60d359ed
commit e5a6048eec
3 changed files with 12 additions and 7 deletions

View File

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

View File

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

View File

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