Skip to content

Commit

Permalink
Make Hydra respect -jN (#3132)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrgriffin authored Jul 14, 2023
1 parent 96159d1 commit b31f10d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion test/test_battle.h
Original file line number Diff line number Diff line change
@@ -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
Expand Down
27 changes: 26 additions & 1 deletion tools/mgba-rom-test-hydra/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <fcntl.h>
#include <math.h>
#include <poll.h>
#include <regex.h>
#include <signal.h>
#include <stdbool.h>
#include <stdio.h>
Expand All @@ -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;
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit b31f10d

Please sign in to comment.