From 8b78e1221e8d48c90252473af3fda051cb18eb59 Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Fri, 16 Aug 2019 15:11:47 +0100 Subject: [PATCH] tests: Use newgrp to run unit tests Rather than set filesystem permissions on the /dev/kvm device instead use the kvm group added by installing qemu for running the unit tests. Signed-off-by: Rob Bradford --- Jenkinsfile | 3 +-- scripts/run_unit_tests.sh | 7 +++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 42fcb9353..ab894cfbb 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -11,11 +11,10 @@ stage ("Builds") { sh "nohup curl https://sh.rustup.rs -sSf | sh -s -- -y" } stage ('Run unit tests') { - sh "sudo chmod a+rw /dev/kvm" sh "scripts/run_unit_tests.sh" } stage ('Run integration tests') { - sh "sudo mount -t tmpfs tmpfs /tmp" + sh "sudo mount -t tmpfs tmpfs /tmp" sh "scripts/run_integration_tests.sh" } } diff --git a/scripts/run_unit_tests.sh b/scripts/run_unit_tests.sh index 609f3d930..23ee7ee72 100755 --- a/scripts/run_unit_tests.sh +++ b/scripts/run_unit_tests.sh @@ -13,8 +13,11 @@ pushd target/debug ls | grep net_util | grep -v "\.d" | xargs -n 1 sudo setcap cap_net_admin,cap_net_raw+ep popd -for f in $(find . -name Cargo.toml -printf '%h\n' | sort -u); do - pushd $f > /dev/null; +sudo adduser $USER kvm +newgrp kvm << EOF || exit 1 +for f in \$(find . -name Cargo.toml -printf '%h\n' | sort -u); do + pushd \$f > /dev/null; cargo test || exit 1; popd > /dev/null; done +EOF