Commit 0a83847313 for ffmpeg
commit 0a83847313fe485abae4a2ece2ce1fbd35781575
Author: Niklas Haas <git@haasn.dev>
Date: Sat Oct 24 15:04:14 2026 +0200
swscale/tests/swscale: allow running tests concurrently with -threads
-threads now accepts [threads][:runners], where runners is the number of
tests to run concurrently, each using the given number of threads per
conversion. For example, -threads :0 runs one single-threaded test per
CPU core.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Niklas Haas <git@haasn.dev>
diff --git a/libswscale/tests/swscale.c b/libswscale/tests/swscale.c
index b97b827b22..10533722c7 100644
--- a/libswscale/tests/swscale.c
+++ b/libswscale/tests/swscale.c
@@ -1060,6 +1060,27 @@ static int parse_size(struct options *opts, const char *str, char **pbuf)
return ret;
}
+/* Parses [threads][:runners] */
+static int parse_threads(struct options *opts, const char *str)
+{
+ const char *sep = strchr(str, ':');
+ const char *str_threads = sep == str ? NULL : str;
+ const char *str_runners = sep ? sep + 1 : NULL;
+ int threads = str_threads ? atoi(str_threads) : 1;
+ int runners = str_runners ? atoi(str_runners) : 1;
+ if (threads < 0 || runners < 0)
+ return AVERROR(EINVAL);
+
+ if (!runners) {
+ runners = av_cpu_count();
+ runners = FFMAX(runners, 1);
+ }
+
+ opts->threads = threads;
+ opts->runners = runners;
+ return 0;
+}
+
static int parse_implementation(const char *str)
{
if (!strcmp(str, "legacy"))
@@ -1117,8 +1138,11 @@ static int parse_options(int argc, char **argv, struct options *opts, FILE **fp)
" -hw <device>\n"
" Use Vulkan hardware acceleration on the specified device for the main conversion\n"
" If 'default', use the default device, and skip all tests if none is available\n"
- " -threads <threads>\n"
- " Use the specified number of threads\n"
+ " -threads [<threads>][:<runners>]\n"
+ " Use the specified number of threads per conversion (default: 1)\n"
+ " Optionally run multiple tests concurrently on <runners> threads (default: 1)\n"
+ " A value of 0 picks the number of threads automatically\n"
+ " Benchmark results may be skewed when using multiple runners\n"
" -cpuflags <cpuflags>\n"
" Uses the specified cpuflags in the tests\n"
" -pretty <1 or 0>\n"
@@ -1247,7 +1271,11 @@ static int parse_options(int argc, char **argv, struct options *opts, FILE **fp)
goto end;
}
} else if (!strcmp(argv[i], "-threads")) {
- opts->threads = atoi(argv[i + 1]);
+ ret = parse_threads(opts, argv[i + 1]);
+ if (ret < 0) {
+ fprintf(stderr, "invalid thread count %s\n", argv[i + 1]);
+ goto end;
+ }
} else if (!strcmp(argv[i], "-p")) {
opts->prob = atof(argv[i + 1]);
} else if (!strcmp(argv[i], "-pretty")) {