From: NeilBrown Date: Mon, 7 Sep 2020 09:40:52 +0000 (+1000) Subject: Test must not expose non-determinism. X-Git-Tag: v1.3~8 X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=2802d9aa1927e133f9827716088bea3d47edeefe;p=wiggle.git Test must not expose non-determinism. The recent heuristic to make 'diff' faster introduce non-determinism which is bad for testing. So add option to set the loop count rather than having a maximum running time. Signed-off-by: NeilBrown --- diff --git a/diff.c b/diff.c index 31d77db..954d3d6 100644 --- a/diff.c +++ b/diff.c @@ -178,9 +178,17 @@ static int find_common(struct file *a, struct file *b, */ int worst = (ahi-alo)+(bhi-blo); + int loopcount = -1; shortcut = !!shortcut; - if (shortcut) - gettimeofday(&start, NULL); + if (shortcut) { + char *lc = getenv("WIGGLE_LOOPCOUNT"); + if (lc) + loopcount = atoi(lc); + if (loopcount < 5) { + loopcount = -1; + gettimeofday(&start, NULL); + } + } klo = khi = alo-blo; v[klo].x = alo; @@ -191,11 +199,15 @@ static int find_common(struct file *a, struct file *b, int cost; int k; + if (loopcount > 0) + loopcount -= 1; if (shortcut == 1 && khi - klo > 5000 && - gettimeofday(&stop, NULL) == 0 && - (stop.tv_sec - start.tv_sec) * 1000000 + - (stop.tv_usec - start.tv_usec) > 20000) + (loopcount == 0 || + (loopcount < 0 && + gettimeofday(&stop, NULL) == 0 && + (stop.tv_sec - start.tv_sec) * 1000000 + + (stop.tv_usec - start.tv_usec) > 20000))) /* 20ms is a long time. Time to take a shortcut * Next snake wins */ diff --git a/dotest b/dotest index e718f13..1b3a44e 100755 --- a/dotest +++ b/dotest @@ -38,6 +38,9 @@ status=0 ok=0 fail=0 +# Avoid non-determinism cause by CPU speed +export WIGGLE_LOOPCOUNT=5000 + find . -name core | xargs rm -f list=$(find . -type f \( -name script -o -name diff -o -name ldiff \ -o -name rediff -o -name merge -o -name wmerge -o -name lmerge \