check: improve test list randomization
authorDarrick J. Wong <darrick.wong@oracle.com>
Wed, 20 Mar 2019 00:44:42 +0000 (17:44 -0700)
committerEryu Guan <guaneryu@gmail.com>
Sat, 23 Mar 2019 13:27:12 +0000 (21:27 +0800)
awk doesn't have a particularly good random number generator -- it seeds
from the Unix epoch time in seconds, which means that the run order
across a bunch of VMs started at exactly the same time are unsettlingly
predictable.  Therefore, at least try to seed it with bash's $RANDOM,
which is slightly less predictable.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Eryu Guan <guaneryu@gmail.com>
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
check
randomize.awk

diff --git a/check b/check
index 20e9530..ecd1d39 100755 (executable)
--- a/check
+++ b/check
@@ -242,13 +242,13 @@ _prepare_test_list()
        done
 
        # sort the list of tests into numeric order
-       list=`sort -n $tmp.list | uniq`
-       rm -f $tmp.list
-
-       if $randomize
-       then
-               list=`echo $list | awk -f randomize.awk`
+       if $randomize; then
+               sorter="awk -v seed=$RANDOM -f randomize.awk"
+       else
+               sorter="cat"
        fi
+       list=`sort -n $tmp.list | uniq | $sorter`
+       rm -f $tmp.list
 }
 
 # Process command arguments first.
index 0a8ad71..d979fb0 100644 (file)
@@ -15,10 +15,14 @@ function randomize(array, N) {
 return
 }
 
+BEGIN {
+       srand(seed)
+}
 {
-    srand()
-    for (i = 0; i < NF; i++ ) array[i] = $(i+1)
-    randomize(array, NF)
-    for (i = 0; i < NF; i++) printf("%s ", array[i])
+       array[NR - 1] = $0
+}
+END {
+    randomize(array, NR)
+    for (i = 0; i < NR; i++) printf("%s ", array[i])
 }