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 <rui.chang@arm.com>
Change-Id: Ifbd3098d4c32ffef5dcca738625302f63572e0c6
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/12693
Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Community-CI: Mellanox Build Bot
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Aleksey Marchuk <alexeymar@nvidia.com>
Reviewed-by: Paul Luse <paul.e.luse@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Rui Chang 2022-05-15 21:58:14 +08:00 committed by Tomasz Zawadzki
parent 13b6c53dcf
commit 1a14eb4e25
2 changed files with 5 additions and 2 deletions

View File

@ -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

View File

@ -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