From f0bf86f48ec2ede6bd75aaefc1b2e94ce922f124 Mon Sep 17 00:00:00 2001 From: rofl0r Date: Sun, 19 Dec 2021 18:44:04 +0000 Subject: [PATCH] add a test for -limit functionality --- test.sh | 4 ++++ tests/cpuwaster.c | 17 +++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/test.sh b/test.sh index 93b53d9..bef899a 100755 --- a/test.sh +++ b/test.sh @@ -2,6 +2,7 @@ test -z "$JF" && JF=./jobflow TMP=/tmp/jobflow.test.$$ gcc tests/stdin_printer.c -o tests/stdin_printer.out || { error compiling tests/stdin_printer.c ; exit 1 ; } +gcc tests/cpuwaster.c -o tests/cpuwaster.out || { error compiling tests/cpuwaster.c ; exit 1 ; } tmp() { echo $TMP.$testno } @@ -189,3 +190,6 @@ dotest "random pipe buffered 17x" od < /dev/urandom | head -n $RNDLINES > $(tmp).1 $JF -threads=17 -buffered -exec tests/stdin_printer.out < $(tmp).1 | sort -u > $(tmp).2 test_equal $(tmp).1 $(tmp).2 + +dotest "limit cpu 1sec" +seq 1 | $JF -limits cpu=1 -exec tests/cpuwaster.out 2 && echo "test $testno failed." diff --git a/tests/cpuwaster.c b/tests/cpuwaster.c index 63de52f..b3e04a8 100644 --- a/tests/cpuwaster.c +++ b/tests/cpuwaster.c @@ -1,9 +1,22 @@ -#include "../../lib/include/timelib.h" +#undef _DEFAULT_SOURCE +#define _DEFAULT_SOURCE /* for timersub */ +#include #include #include #include -int syntax() { +static void gettimestamp(struct timeval* t) { + gettimeofday(t, NULL); +} + +static long mspassed(struct timeval* t) { + struct timeval now, diff; + gettimeofday(&now, NULL); + timersub(&now, t, &diff); + return (diff.tv_sec * 1000) + (diff.tv_usec / 1000); +} + +static int syntax() { puts("prog seconds_of_cpu_time_to_burn"); return 1; } -- 2.11.4.GIT