]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
tests: make sure rand_dev suffix has 6 chars
authorChristian Ehrhardt <christian.ehrhardt@canonical.com>
Wed, 10 Jan 2018 15:11:37 +0000 (16:11 +0100)
committerStephen Hemminger <stephen@networkplumber.org>
Wed, 10 Jan 2018 16:29:51 +0000 (08:29 -0800)
The change to limit the read size from /dev/urandom is a tradeoff.
Reading too much can trigger an issue, but so it could if the
suggested 250 random chars would not contain enough [:alpha:] chars.
If they contain:
 a) >=6 all is ok
 b) [1-5] the devname would be shorter than expected (non fatal).
 c) 0 things would break

In loops of hundreds of thousands it always was (a) for my, but since
if occuring in a test it might be hard to track what happened avoid
this issue by retrying on the length condition.

Signed-off-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
testsuite/lib/generic.sh

index 3645ff52dcbbc556965d44f73f193b16321efd91..8cef20fa1b2801582ab9197668b5d8e8371f1688 100644 (file)
@@ -87,7 +87,11 @@ ts_qdisc_available()
 
 rand_dev()
 {
-    echo "dev-$(head -c 250 /dev/urandom | tr -dc '[:alpha:]' | head -c 6)"
+    rnd=""
+    while [ ${#rnd} -ne 6 ]; do
+        rnd="$(head -c 250 /dev/urandom | tr -dc '[:alpha:]' | head -c 6)"
+    done
+    echo "dev-$rnd"
 }
 
 pr_failed()