From 69774f1aebe9355ef5728997481f7828c53a8204 Mon Sep 17 00:00:00 2001 From: Naresh Kamboju Date: Wed, 6 Mar 2019 20:18:26 +0530 Subject: perf: Adding perf test case for LKFT test plan Signed-off-by: Naresh Kamboju --- automated/linux/perf/perf.sh | 117 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100755 automated/linux/perf/perf.sh (limited to 'automated/linux/perf/perf.sh') diff --git a/automated/linux/perf/perf.sh b/automated/linux/perf/perf.sh new file mode 100755 index 0000000..88e47c9 --- /dev/null +++ b/automated/linux/perf/perf.sh @@ -0,0 +1,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 ]" 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 -- cgit v1.2.3