Skip to content

Commit

Permalink
Test some filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
Lars T Hansen committed Apr 8, 2024
1 parent b67d447 commit d77afda
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 2 deletions.
2 changes: 1 addition & 1 deletion tests/command-line.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ set -e
--exclude-users root \
--exclude-commands emacs \
--lockdir . \
>> /dev/null
> /dev/null

# Signal error with code 2 for unknown arguments
set +e
Expand Down
15 changes: 15 additions & 0 deletions tests/exclude-commands.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

set -e
( cd .. ; cargo build )
numbad=$(../target/debug/sonar ps --exclude-commands bash,sh,zsh,csh,ksh,tcsh,kworker | \
awk "
/,cmd=kworker/ { print }
/,cmd=(ba|z|c|k|tc|)sh/ { print }
" | \
wc -l)
if [[ $numbad -ne 0 ]]; then
echo "Command filtering did not work"
exit 1
fi

30 changes: 30 additions & 0 deletions tests/exclude-system-jobs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

set -e
( cd .. ; cargo build )
# System jobs have uid < 1000. For each user name UNAME, run `getent passwd $UNAME` and then
# extract the third field from the colon-separated list to get the uid.
numbad=$(../target/debug/sonar ps --exclude-system-jobs | \
awk '
{
s=substr($0, index($0, ",user=")+6)
s=substr(s, 0, index(s, ",")-1)
uids[s] = 1
}
END {
s = ""
for ( uid in uids ) {
s = s " " uid
}
system("getent passwd " s)
}
' | \
awk -F: '{ if ($3 < 1000) { print $3 } }' | \
wc -l
)
if [[ $numbad -ne 0 ]]; then
echo $numbad
echo "System jobs filtering did not work"
exit 1
fi

15 changes: 15 additions & 0 deletions tests/exclude-users.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

set -e
( cd .. ; cargo build )
numbad=$(../target/debug/sonar ps --exclude-users root,root,root,$LOGNAME | \
awk "
/,user=root,/ { print }
/,user=$LOGNAME,/ { print }
" | \
wc -l)
if [[ $numbad -ne 0 ]]; then
echo "User name filtering did not work"
exit 1
fi

2 changes: 1 addition & 1 deletion tests/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# utility to be installed and will fail if it is not.

set -e
for test in command-line hostname interrupt lockfile ps-syntax sysinfo-syntax user; do
for test in command-line exclude-commands exclude-system-jobs exclude-users hostname interrupt lockfile ps-syntax sysinfo-syntax user; do
echo $test
./$test.sh
done
Expand Down

0 comments on commit d77afda

Please sign in to comment.