From: Michael Tremer Date: Thu, 21 Jul 2022 10:12:59 +0000 (+0000) Subject: tests: command: All option to exhaust all memory X-Git-Tag: 0.9.28~657 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=192894e26e6436658775bfbe5510966d0e5955bf;p=pakfire.git tests: command: All option to exhaust all memory Signed-off-by: Michael Tremer --- diff --git a/tests/stub/command.c b/tests/stub/command.c index 74b138464..c6c54b26e 100644 --- a/tests/stub/command.c +++ b/tests/stub/command.c @@ -65,6 +65,23 @@ static int echo_environ(int argc, char* argv[]) { return 0; } +static int exhaust_memory(int argc, char* argv[]) { + const size_t block = 1048576; // 1 MiB + size_t bytes = 0; + + while (1) { + char* p = malloc(block); + if (!p) + break; + + bytes += block; + } + + printf("Successfully allocated %f MiB\n", (double)bytes / 1048576); + + return 0; +} + static int exit_with_code(int argc, char* argv[]) { if (argc < 1) { fprintf(stderr, "exit-with-code requires an argument\n"); @@ -129,6 +146,10 @@ int main(int argc, char* argv[]) { else if (strcmp(command, "echo-environ") == 0) callback = echo_environ; + // Exhaust memory + else if (strcmp(command, "exhaust-memory") == 0) + callback = exhaust_memory; + // Exit with code else if (strcmp(command, "exit-with-code") == 0) callback = exit_with_code;