From deaf429f8729119550ade066894cdcede2c56e65 Mon Sep 17 00:00:00 2001 From: Adam Saleh Date: Jul 04 2023 12:39:49 +0000 Subject: Merge pull request #90 from carofe82/master setup perf, pidstat, and sa tests --- diff --git a/tests/p_perf/0_install_perf.sh b/tests/p_perf/0_install_perf.sh new file mode 100755 index 0000000..f146ff0 --- /dev/null +++ b/tests/p_perf/0_install_perf.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# Author: Carlos Rodriguez-Fernandez + +t_Log "Running $0 -installing libbpf-tools." +t_InstallPackage perf diff --git a/tests/p_perf/perf_tests.sh b/tests/p_perf/perf_tests.sh new file mode 100755 index 0000000..3cdec2a --- /dev/null +++ b/tests/p_perf/perf_tests.sh @@ -0,0 +1,23 @@ +#!/bin/bash +# Author: Carlos Rodriguez-Fernandez + +t_Log "Running $0 - perf tests" + +tests_in_order=( + "perf version" + "perf record -F 49 -a -g -- sleep 1" + "perf report --stdio > /dev/null 2>&1" +) + +for cmd in "${tests_in_order[@]}"; do + t_Log "Running $0 - perf test: ${cmd}" + if ! eval "${cmd}" > /dev/null 2>&1; then + t_Log "FAIL: $0: perf test: ${cmd}" + exit 1 + else + t_Log "PASS: $0: perf test: ${cmd}" + fi +done + +t_Log "Cleaning up $0 - perf tests data" +rm -f perf.data diff --git a/tests/p_sysstat/05-iostat-cpu-basic.sh b/tests/p_sysstat/05-iostat-cpu-basic.sh new file mode 100755 index 0000000..c085fb8 --- /dev/null +++ b/tests/p_sysstat/05-iostat-cpu-basic.sh @@ -0,0 +1,38 @@ +#!/bin/bash +# Author: Steve Barnes (steve@echo.id.au) + +# A simple iostat test to verify cpu loads are being recorded + +t_Log "Running $0 - a basic iostat test to verify cpu measurement" + +# Save our iostat output somewhere +TMP=/tmp/iostat.cpu.scratch + +# Clear out the pagecache to get an accurate reading +echo 1 > /proc/sys/vm/drop_caches + +# Clean up after ourselves +trap "[ -e $TMP ] && { /bin/rm -f $TMP; }" EXIT + +# Capture a storage device name +DRIVE=$(fdisk -l|grep -Po -m1 '^/dev/[\D]+') + +# Run iostat on the cpu +/usr/bin/iostat -c 1 5 >$TMP & + +# Let the dust settle +sleep 4 + +# Give the CPU something to chew on +/bin/dd if=$DRIVE bs=4k count=25000 2>/dev/null|sha1sum -b - &>/dev/null + +# Give iostat a chance to log our task +sleep 6 + +# Extract the CPU utilisation (user field, percentage) +CPU_USER_PCENT=$(awk '$1 ~ /[0-9]/ {$1>a ? a=$1 : $1} END {print int(a)}' $TMP) + +# Confirm the CPU registered some level of user activity +[ "$CPU_USER_PCENT" -gt 3 ] || { t_Log "iostat didn't log any CPU activity?!...that ain't good"; } + +t_CheckExitStatus $? diff --git a/tests/p_sysstat/20-pidstat-basic.sh b/tests/p_sysstat/20-pidstat-basic.sh new file mode 100755 index 0000000..07da167 --- /dev/null +++ b/tests/p_sysstat/20-pidstat-basic.sh @@ -0,0 +1,7 @@ +#!/bin/bash +# Author: Carlos Rodriguez-Fernandez + +t_Log "Running $0 - pidstat test" + +pidstat 1 1 > /dev/null 2>&1 +t_CheckExitStatus $? diff --git a/tests/p_sysstat/25-sa-tests.sh b/tests/p_sysstat/25-sa-tests.sh new file mode 100755 index 0000000..c93102d --- /dev/null +++ b/tests/p_sysstat/25-sa-tests.sh @@ -0,0 +1,22 @@ +#!/bin/bash +# Author: Carlos Rodriguez-Fernandez + +t_Log "Running $0 - sa tests" + +tests_in_order=( + "/usr/lib64/sa/sa1 --boot" + "sar -u | grep -q -e 'LINUX RESTART'" + "/usr/lib64/sa/sa1 1 1" + "sleep 3 && /usr/lib64/sa/sa1 1 1 && sar -u | grep -q -e 'Average'" + "/usr/lib64/sa/sa2 -A" +) + +for cmd in "${tests_in_order[@]}"; do + t_Log "Running $0 - sa test: ${cmd}" + if ! eval "${cmd}" > /dev/null 2>&1; then + t_Log "FAIL: $0: sa test: ${cmd}" + exit 1 + else + t_Log "PASS: $0: sa test: ${cmd}" + fi +done diff --git a/tests/p_sysstat/5-iostat-cpu-basic.sh b/tests/p_sysstat/5-iostat-cpu-basic.sh deleted file mode 100755 index c085fb8..0000000 --- a/tests/p_sysstat/5-iostat-cpu-basic.sh +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/bash -# Author: Steve Barnes (steve@echo.id.au) - -# A simple iostat test to verify cpu loads are being recorded - -t_Log "Running $0 - a basic iostat test to verify cpu measurement" - -# Save our iostat output somewhere -TMP=/tmp/iostat.cpu.scratch - -# Clear out the pagecache to get an accurate reading -echo 1 > /proc/sys/vm/drop_caches - -# Clean up after ourselves -trap "[ -e $TMP ] && { /bin/rm -f $TMP; }" EXIT - -# Capture a storage device name -DRIVE=$(fdisk -l|grep -Po -m1 '^/dev/[\D]+') - -# Run iostat on the cpu -/usr/bin/iostat -c 1 5 >$TMP & - -# Let the dust settle -sleep 4 - -# Give the CPU something to chew on -/bin/dd if=$DRIVE bs=4k count=25000 2>/dev/null|sha1sum -b - &>/dev/null - -# Give iostat a chance to log our task -sleep 6 - -# Extract the CPU utilisation (user field, percentage) -CPU_USER_PCENT=$(awk '$1 ~ /[0-9]/ {$1>a ? a=$1 : $1} END {print int(a)}' $TMP) - -# Confirm the CPU registered some level of user activity -[ "$CPU_USER_PCENT" -gt 3 ] || { t_Log "iostat didn't log any CPU activity?!...that ain't good"; } - -t_CheckExitStatus $?