blob: 88e47c9127bfe12e28589899829a5c7ca822972d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
#!/bin/sh
set -x
# shellcheck disable=SC1091
. ../../lib/sh-test-lib
OUTPUT="$(pwd)/output"
RESULT_FILE="${OUTPUT}/result.txt"
export RESULT_FILE
SKIP_INSTALL="true"
# List of test cases
TEST="record report stat test"
# PERF version
PERF_VERSION="$(uname -r | cut -d . -f 1-2)"
usage() {
echo "Usage: $0 [-s <true|false>]" 1>&2
exit 1
}
while getopts "s:" arg; do
case "$arg" in
s) SKIP_INSTALL="${OPTARG}";;
*) usage ;;
esac
done
# Run perf record tests
run_perf_record() {
# Test 'perf record'
info_msg "Performing perf record test..."
TCID="perf_record_test"
perf record -e cycles -o perf-lava-test.data ls -a 2>&1 | tee perf-record.log
samples=$(grep -ao "[0-9]\\+[ ]\\+samples" perf-record.log| cut -f 1 -d' ')
if [ "${samples}" -gt 1 ]; then
report_pass "${TCID}"
else
report_fail "${TCID}"
fi
rm perf-record.log
}
# Run perf report tests
run_perf_report() {
# Test 'perf report'
info_msg "Performing perf report test..."
TCID="perf_report_test"
perf report -i perf-lava-test.data 2>&1 | tee perf-report.log
pcnt_samples=$(grep -c -e "^[ ]\\+[0-9]\\+.[0-9]\\+%" perf-report.log)
if [ "${pcnt_samples}" -gt 1 ]; then
report_pass "${TCID}"
else
report_fail "${TCID}"
fi
rm perf-report.log perf-lava-test.data
}
# Run perf stat tests
run_perf_stat() {
# Test 'perf stat'
info_msg "Performing perf stat test..."
TCID="perf_stat_test"
perf stat -e cycles ls -a 2>&1 | tee perf-stat.log
cycles=$(grep -o "[0-9,]\\+[ ]\\+cycles" perf-stat.log | sed 's/,//g' | cut -f 1 -d' ')
if [ -z "${cycles}" ]; then
echo "${TCID}: skip"
else
if [ "${cycles}" -gt 1 ]; then
report_pass "${TCID}"
else
report_fail "${TCID}"
fi
fi
rm perf-stat.log
}
# Run perf test tests
run_perf_test() {
# Test 'perf test'
info_msg "Performing 'perf test'..."
eval $(perf test -v)
report_pass "perf_test"
}
# Test run.
! check_root && error_msg "This script must be run as root"
create_out_dir "${OUTPUT}"
info_msg "About to run perf test..."
info_msg "Output directory: ${OUTPUT}"
if [ "${SKIP_INSTALL}" = "True" ] || [ "${SKIP_INSTALL}" = "true" ]; then
info_msg "install_perf skipped"
else
dist_name
# shellcheck disable=SC2154
case "${dist}" in
debian|ubuntu)
pkgs="linux-tools-${PERF_VERSION} stress"
install_deps "${pkgs}" "${SKIP_INSTALL}"
;;
centos|fedora)
pkgs="perf stress"
install_deps "${pkgs}" "${SKIP_INSTALL}"
;;
*)
warn_msg "Unsupported distribution: package install skipped"
esac
info_msg "Run install_perf"
install_perf
fi
for tests in ${TEST}; do
run_perf_"${tests}"
done
exit 0
|