netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christian Ehrhardt <christian.ehrhardt@canonical.com>
To: Netdev <netdev@vger.kernel.org>
Cc: Luca Boccassi <bluca@debian.org>,
	Christian Ehrhardt <christian.ehrhardt@canonical.com>
Subject: [PATCH iproute2 v2 2/2] tests: make sure rand_dev suffix has 6 chars
Date: Wed, 10 Jan 2018 16:11:37 +0100	[thread overview]
Message-ID: <1515597097-870-3-git-send-email-christian.ehrhardt@canonical.com> (raw)
In-Reply-To: <1515597097-870-1-git-send-email-christian.ehrhardt@canonical.com>

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>
---
 testsuite/lib/generic.sh | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/testsuite/lib/generic.sh b/testsuite/lib/generic.sh
index 3645ff5..8cef20f 100644
--- a/testsuite/lib/generic.sh
+++ b/testsuite/lib/generic.sh
@@ -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()
-- 
2.7.4

  parent reply	other threads:[~2018-01-10 15:11 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-10 15:11 [PATCH iproute2 v2 0/2] tests: fix issues in autopkgtest environment Christian Ehrhardt
2018-01-10 15:11 ` [PATCH iproute2 v2 1/2] tests: read limited amount from /dev/urandom Christian Ehrhardt
2018-01-10 15:11 ` Christian Ehrhardt [this message]
2018-01-10 16:31 ` [PATCH iproute2 v2 0/2] tests: fix issues in autopkgtest environment Stephen Hemminger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1515597097-870-3-git-send-email-christian.ehrhardt@canonical.com \
    --to=christian.ehrhardt@canonical.com \
    --cc=bluca@debian.org \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).