diff --git a/test/test_battle.h b/test/test_battle.h index 607589eea..039506c1b 100644 --- a/test/test_battle.h +++ b/test/test_battle.h @@ -1,7 +1,7 @@ /* Embedded DSL for automated black-box testing of battle mechanics. * * To run all the tests use: - * make check + * make check -j * To run specific tests, e.g. Spikes ones, use: * make check TESTS='Spikes' * To build a ROM (pokemerald-test.elf) that can be opened in mgba to diff --git a/tools/mgba-rom-test-hydra/main.c b/tools/mgba-rom-test-hydra/main.c index 7151255de..123d8a255 100644 --- a/tools/mgba-rom-test-hydra/main.c +++ b/tools/mgba-rom-test-hydra/main.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -37,6 +38,8 @@ #define MAX_FAILED_TESTS_TO_LIST 100 #define MAX_TEST_LIST_BUFFER_LENGTH 256 +#define ARRAY_COUNT(arr) (sizeof((arr)) / sizeof((arr)[0])) + struct Runner { pid_t pid; @@ -248,7 +251,29 @@ int main(int argc, char *argv[]) exit(2); } - nrunners = sysconf(_SC_NPROCESSORS_ONLN); + nrunners = 1; + const char *makeflags = getenv("MAKEFLAGS"); + if (makeflags) + { + int e; + regex_t preg; + regmatch_t pmatch[4]; + if ((e = regcomp(&preg, "(^| )-j([0-9]*)($| )", REG_EXTENDED)) != 0) + { + char errbuf[256]; + regerror(e, &preg, errbuf, sizeof(errbuf)); + fprintf(stderr, "regcomp failed: '%s'\n", errbuf); + exit(2); + } + if (regexec(&preg, makeflags, ARRAY_COUNT(pmatch), pmatch, 0) != REG_NOMATCH) + { + if (pmatch[2].rm_so == pmatch[2].rm_eo) + nrunners = sysconf(_SC_NPROCESSORS_ONLN); + else + sscanf(makeflags + pmatch[2].rm_so, "%d", &nrunners); + } + regfree(&preg); + } if (nrunners > MAX_PROCESSES) nrunners = MAX_PROCESSES; runners_digits = ceil(log10(nrunners));