From 1a14eb4e256c14a3edbb53556bc89ba92e95f154 Mon Sep 17 00:00:00 2001 From: Rui Chang Date: Sun, 15 May 2022 21:58:14 +0800 Subject: [PATCH] test/unit: fix "git clean" failure In autorun.sh it executes autotest.sh as root. But in autotest.sh and test/unit/unittest.sh, when run git clean -f'*.gcda', it may show errors like: 08:03:54 -- unit/unittest.sh@277 -- # cd /home/jenkins/spdk_repo/spdk 08:03:54 -- unit/unittest.sh@277 -- # git clean -f '*.gcda' fatal: unsafe repository ('/home/jenkins/spdk_repo/spdk' is owned by someone else) The reason is the spdk source folder owner may not be root but we run the git clean command as root. Fix it by using the folder owner's id to do the git clean operation. Signed-off-by: Rui Chang Change-Id: Ifbd3098d4c32ffef5dcca738625302f63572e0c6 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/12693 Community-CI: Broadcom CI Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins Reviewed-by: Aleksey Marchuk Reviewed-by: Paul Luse Reviewed-by: Jim Harris --- autotest.sh | 3 ++- test/unit/unittest.sh | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/autotest.sh b/autotest.sh index 431afd59f..54f6ba4b3 100755 --- a/autotest.sh +++ b/autotest.sh @@ -347,6 +347,7 @@ if hash lcov && ! [[ "$CC_TYPE" == *"clang"* ]]; then $LCOV -q -a $out/cov_base.info -a $out/cov_test.info -o $out/cov_total.info $LCOV -q -r $out/cov_total.info '*/dpdk/*' -o $out/cov_total.info $LCOV -q -r $out/cov_total.info '/usr/*' -o $out/cov_total.info - git clean -f "*.gcda" + owner=$(stat -c "%U" .) + sudo -u $owner git clean -f "*.gcda" rm -f cov_base.info cov_test.info OLD_STDOUT OLD_STDERR fi diff --git a/test/unit/unittest.sh b/test/unit/unittest.sh index 1a8bf34ca..d131fbba2 100755 --- a/test/unit/unittest.sh +++ b/test/unit/unittest.sh @@ -274,7 +274,9 @@ if [ "$cov_avail" = "yes" ] && ! [[ "$CC_TYPE" == *"clang"* ]]; then rm -f $UT_COVERAGE/ut_cov_base.info $UT_COVERAGE/ut_cov_test.info genhtml $UT_COVERAGE/ut_cov_unit.info --output-directory $UT_COVERAGE # git -C option not used for compatibility reasons - (cd $rootdir && git clean -f "*.gcda") + owner=$(stat -c "%U" $rootdir) + cd $rootdir + sudo -u $owner git clean -f "*.gcda" fi set +x