From 1b2ee2c16d62a1c410059280b9525552b5c3fada Mon Sep 17 00:00:00 2001 From: Chase Qi Date: Mon, 6 Feb 2017 17:09:32 +0800 Subject: automated: linux: add lshw test Change-Id: Iec4efd0a4d4e9dede50505b7284d6221b83a7433 Signed-off-by: Chase Qi --- automated/linux/lshw/lshw.sh | 59 ++++++++++++++++++++++++++++++++++++++++++ automated/linux/lshw/lshw.yaml | 36 ++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100755 automated/linux/lshw/lshw.sh create mode 100644 automated/linux/lshw/lshw.yaml diff --git a/automated/linux/lshw/lshw.sh b/automated/linux/lshw/lshw.sh new file mode 100755 index 0000000..4017488 --- /dev/null +++ b/automated/linux/lshw/lshw.sh @@ -0,0 +1,59 @@ +#!/bin/sh + +# shellcheck disable=SC1091 +. ../../lib/sh-test-lib + +OUTPUT="$(pwd)/output" +RESULT_FILE="${OUTPUT}/result.txt" +export RESULT_FILE + +# The number of hardware class may vary dpending on the system under testing. +# This test check if lshw able to report the classes defined in ${CLASSES}, +# which are very common ones by default and can be changed with -c. +CLASSES="system bus processor memory network" + +usage() { + echo "usage: $0 [-s ] [-c classes]" 1>&2 + exit 1 +} + +while getopts ':s:c:' opt; do + case "${opt}" in + s) SKIP_INSTALL="${OPTARG}" ;; + c) CLASSES="${OPTARG}" ;; + *) usage ;; + esac +done + +! check_root && error_msg "lshw must be run as super user or it will only report partial information." +[ -d "${OUTPUT}" ] && mv "${OUTPUT}" "${OUTPUT}_$(date +%Y%m%d%H%M%S)" +mkdir -p "${OUTPUT}" + +install_deps "lshw" "${SKIP_INSTALL}" + +# If lshw fails to run, skip the following tests and exit. +skip_list=$(echo "${CLASSES}" | awk '{for (i=1; i<=NF; i++) printf("lshw-%s ",$i)}') +lshw > "${OUTPUT}/lshw.txt" +exit_on_fail "lshw-run" "${skip_list}" + +# Obtain classes detected by lshw. +lshw -json > "${OUTPUT}/lshw.json" +detected_classes=$(grep '"class" : ' "${OUTPUT}/lshw.json" | awk -F'"' '{print $(NF-1)}' | uniq) + +# Check if lshw able to detect and report the classes defined in ${CLASSES}. +for class in ${CLASSES}; do + logfile="${OUTPUT}/lshw-${class}.txt" + if ! echo "${detected_classes}" | grep -q "${class}"; then + warn_msg "lshw failed to detect ${class} class!" + report_fail "lshw-${class}" + else + # lshw may exit with zero and report nothing, so check the size of + # logfile as well. + if lshw -class "${class}" > "${logfile}" || ! test -s "${logfile}"; then + report_pass "lshw-${class}" + else + report_fail "lshw-${class}" + fi + cat "${logfile}" + fi +done diff --git a/automated/linux/lshw/lshw.yaml b/automated/linux/lshw/lshw.yaml new file mode 100644 index 0000000..f63fc90 --- /dev/null +++ b/automated/linux/lshw/lshw.yaml @@ -0,0 +1,36 @@ +metadata: + name: lshw + format: "Lava-Test-Shell Test Definition 1.0" + description: "lshw is a small tool to extract detailed information + on the hardware configuration of the machine." + maintainer: + - chase.qi@linaro.org + os: + - debian + - ubuntu + - fedora + - centos + - openembedded + scope: + - functional + environment: + - lava-test-shell + devices: + - hi6220-hikey + - apq8016-sbc + - mustang + - moonshot + - thunderX + - d03 + - d05 + +params: + # Test if lshw able to report the classes pre-defined in ${CLASSES}. + CLASSES: "system bus processor memory network" + SKIP_INSTALL: "false" + +run: + steps: + - cd ./automated/linux/lshw/ + - ./lshw.sh -s "${SKIP_INSTALL}" -c "${CLASSES}" + - ../../utils/send-to-lava.sh ./output/result.txt -- cgit v1.2.3