From a15ff56ec706ccb8418e0122d07a0c81682a0e14 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 26 Jan 2023 13:24:07 +0100 Subject: [PATCH] gitlab-ci: fix randomizing tests in "nm-ci-run.sh" The code was just wrong. Usually in gitlab-ci, NMTST_SEED_RANDOM is unset, so the previous code would not have set it. Which means that our tests run with NMTST_SEED_RANDOM="0". Fuzzing (or randomizing tests) is very useful, we should do that for the unit tests that run in gitlab-ci. Fix this. But don't let the test choose a random number. Instead, let the calling script choose it. That is, because we might run the tests more than once (without debugging and no valgrind; in case of failure return with debugging; with valgrind). Those runs should use the same seed. This fixes commit 70487d9ff8a0 ('ci: randomize tests during our CI'), but as fixing randomization can break previously running tests, we may only want to backport this commit after careful evaluation. (cherry picked from commit 3bad3f8b241f643621a5ea8cb9816abcb6bc939c) --- contrib/scripts/nm-ci-run.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/contrib/scripts/nm-ci-run.sh b/contrib/scripts/nm-ci-run.sh index 00adba85e1..14a4a2fe53 100755 --- a/contrib/scripts/nm-ci-run.sh +++ b/contrib/scripts/nm-ci-run.sh @@ -69,9 +69,13 @@ if [ $IS_ALPINE = 1 ]; then _WITH_SYSTEMD_LOGIND="$_FALSE" fi -if [ "$NMTST_SEED_RAND" != "" ]; then - export NMTST_SEED_RAND= +if [ -z "${NMTST_SEED_RAND+x}" ]; then + NMTST_SEED_RAND="$SRANDOM" + if [ -z "$NMTST_SEED_RAND" ]; then + NMTST_SEED_RAND="$(( ( (RANDOM<<15|RANDOM)<<15|RANDOM ) % 0xfffffffe ))" + fi fi +export NMTST_SEED_RAND case "$CI" in ""|"true"|"default"|"gitlab")