Bläddra i källkod

Allow running individual benchmarks

mirrors and reuses the option from 2f6a9d12f1db84322e0b69fd5ddc986f1f143606
sfan5 6 månader sedan
förälder
incheckning
e5a6048eec
3 ändrade filer med 12 tillägg och 7 borttagningar
  1. 6 4
      src/benchmark/benchmark.cpp
  2. 1 1
      src/benchmark/benchmark.h
  3. 5 2
      src/main.cpp

+ 6 - 4
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;
 }

+ 1 - 1
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

+ 5 - 2
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,