From mboxrd@z Thu Jan 1 00:00:00 1970 From: Christian Ehrhardt Subject: [PATCH iproute2 v2 2/2] tests: make sure rand_dev suffix has 6 chars Date: Wed, 10 Jan 2018 16:11:37 +0100 Message-ID: <1515597097-870-3-git-send-email-christian.ehrhardt@canonical.com> References: <1515597097-870-1-git-send-email-christian.ehrhardt@canonical.com> Cc: Luca Boccassi , Christian Ehrhardt To: Netdev Return-path: Received: from youngberry.canonical.com ([91.189.89.112]:44864 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753524AbeAJPLl (ORCPT ); Wed, 10 Jan 2018 10:11:41 -0500 In-Reply-To: <1515597097-870-1-git-send-email-christian.ehrhardt@canonical.com> Sender: netdev-owner@vger.kernel.org List-ID: 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 --- 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