Skip to content

Commit

Permalink
tests: add a simple test for the Clang analyzer plugin
Browse files Browse the repository at this point in the history
Related: csutils#93
  • Loading branch information
lzaoral committed Sep 26, 2023
1 parent 40b402c commit 5881747
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 0 deletions.
1 change: 1 addition & 0 deletions .fmf/version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
5 changes: 5 additions & 0 deletions plans/ci.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
summary: Basic analysis tests
discover:
how: fmf
execute:
how: tmt
11 changes: 11 additions & 0 deletions tests/simple_build/clang.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
summary: Test analysis using Clang analyzer
test: ./test.sh
framework: beakerlib
environment:
TEST_PACKAGE: units
TEST_TOOL: clang
component:
- csmock-plugin-clang
recommend:
- csmock-plugin-clang
duration: 1h
59 changes: 59 additions & 0 deletions tests/simple_build/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash
# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
. /usr/share/beakerlib/beakerlib.sh || exit 1

CSMOCK_EXTRA_OPTS="${CSMOCK_EXTRA_OPTS:-}"
TEST_PACKAGE="${TEST_PACKAGE:-}"
TEST_TOOL="${TEST_TOOL:-}"
TEST_USER="csmock"

rlJournalStart
rlPhaseStartSetup
# use the latest csutils in the Testing Farm
if rlIsFedora || rlIsRHEL '>7'; then
# By default the testing-farm-tag-repository has higher priority
# than our development COPR repo. Therefore, we need to flip the
# priorities and update the packages manually.
rlRun "dnf config-manager --save --setopt='copr:copr.fedorainfracloud.org:group_codescan:csutils.priority=1'"
rlRun "dnf upgrade -y 'cs*'"
fi

if [ -z "$TEST_PACKAGE" ]; then
rlDie "TEST_PACKAGE parameter is empty or undefined"
fi

if [ -z "$TEST_TOOL" ]; then
rlDie "TEST_TOOL parameter is empty or undefined"
fi

# create a tmpdir
rlRun "tmp=\$(mktemp -d)" 0 "Create tmp directory"
rlRun "pushd \$tmp"

# fetch the SRPM
rlRun "yum -y install $TEST_PACKAGE"
rlRun "rlFetchSrcForInstalled $TEST_PACKAGE"
rlRun "SRPM=\$(find . -name '$TEST_PACKAGE-*.src.rpm')"

# add a user for mock
rlRun "userdel -r $TEST_USER" 0,6
rlRun "useradd -m -d /home/$TEST_USER -G mock $TEST_USER"
rlRun "cp $SRPM /home/$TEST_USER"

if ! rlGetPhaseState; then
rlDie "'$TEST_PACKAGE' sources could not be fetched"
fi
rlPhaseEnd

rlPhaseStartTest "Analyze $TEST_PACKAGE using $TEST_TOOL"
rlRun "su - $TEST_USER -c 'csmock -t $TEST_TOOL $CSMOCK_EXTRA_OPTS \"$SRPM\"'" 0 \
"Analyze $SRPM using $TEST_TOOL analyzer"
rlFileSubmit "/home/$TEST_USER/$TEST_PACKAGE"*.tar.xz "$SRPM-$TEST_TOOL.tar.xz"
rlPhaseEnd

rlPhaseStartCleanup
rlRun "userdel -r $TEST_USER"
rlRun "popd"
rlRun "rm -r \$tmp" 0 "Remove tmp directory"
rlPhaseEnd
rlJournalEnd

0 comments on commit 5881747

Please sign in to comment.