diff --git a/ledmon.spec b/ledmon.spec index 00943ca..50e4e42 100644 --- a/ledmon.spec +++ b/ledmon.spec @@ -1,7 +1,7 @@ Summary: Enclosure LED Utilities Name: ledmon Version: 0.96 -Release: 2%{?dist} +Release: 3%{?dist} License: GPLv2+ URL: https://github.com/intel/ledmon Source0: https://github.com/intel/ledmon/archive/v%{version}.tar.gz#/%{name}-%{version}.tar.gz @@ -47,6 +47,9 @@ make %{_unitdir}/ledmon.service %changelog +* Wed Jun 01 2022 Jan Macku - 0.96-3 +- Add tests + * Wed Jun 01 2022 Jan Macku - 0.96-2 - Rename gating.yml to gating.yaml diff --git a/tests/ledctl_test/Makefile b/tests/ledctl_test/Makefile new file mode 100644 index 0000000..c3e94df --- /dev/null +++ b/tests/ledctl_test/Makefile @@ -0,0 +1,61 @@ +# Copyright (c) 2006 Red Hat, Inc. All rights reserved. This copyrighted +# material is made available to anyone wishing to use, modify, copy, or +# redistribute it subject to the terms and conditions of the GNU General +# Public License v.2. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., 51 +# Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +# Author: Xiaowei Li + +TOPLEVEL_NAMESPACE=kernel + +PACKAGE_NAME=storage/block + +RELATIVE_PATH=ledmon + +export TESTVERSION=1.0 + +export TEST=/$(TOPLEVEL_NAMESPACE)/$(PACKAGE_NAME)/$(RELATIVE_PATH) + +.PHONY: all install download clean + +BUILT_FILES= + +FILES=$(METADATA) tc.sh main.sh Makefile PURPOSE runtest.sh + +run: $(FILES) build + ./runtest.sh + +build: $(BUILT_FILES) + chmod a+x ./runtest.sh + chmod a+x ./main.sh + +clean: + rm -f *~ *.rpm $(BUILT_FILES) + + +include /usr/share/rhts/lib/rhts-make.include + +$(METADATA): Makefile + @touch $(METADATA) + @echo "Owner: guazhang " > $(METADATA) + @echo "Name: $(TEST)" >> $(METADATA) + @echo "Path: $(TEST_DIR)" >> $(METADATA) + @echo "License: GPL" >> $(METADATA) + @echo "TestVersion: $(TESTVERSION)" >> $(METADATA) + @echo "Description: ledmon">> $(METADATA) + @echo "TestTime: 1h" >> $(METADATA) + @echo "RunFor: $(PACKAGE_NAME)" >> $(METADATA) + @echo "Requires: $(PACKAGE_NAME)" >> $(METADATA) + + rhts-lint $(METADATA) + +PURPOSE: + echo >/dev/null diff --git a/tests/ledctl_test/runtest.sh b/tests/ledctl_test/runtest.sh new file mode 100755 index 0000000..76eb9c7 --- /dev/null +++ b/tests/ledctl_test/runtest.sh @@ -0,0 +1,72 @@ +#!/bin/bash + +source tc.sh || exit 200 + +### return /dev/sda +function get_disk(){ + local disk_lists="" + local first_disk="" + tlog "get disk from local" + for i in $(lsblk |grep disk |awk '{print $1}');do + disk_lists="$disk_lists $i" + done + tlog "disk list=$disk_lists" + RETURN_STR="$disk_lists" +} + +uname -a + +rpm -q ledmon +if [[ $? != 0 ]]; then + echo "ledmon is not installed" >&2 + exit 1 +fi + +>/var/log/ledmon.log +>/var/log/ledctl.log + +get_disk +disks=$RETURN_STR +tlog "disks=$disks" +tlog "get the first disk" +first_disk=$(echo $disks |awk '{print $1}') +if [ $first_disk == "" ];then + echo "can not get disk from get_disk function" + exit 0 +fi + +first_disk="/dev/$first_disk" + +tlog "we will force in $first_disk" + +tok "ledctl locate=$first_disk" +tok "ledctl locate_off=$first_disk" +tok "ledctl locate=$first_disk" +tok "ledctl off={ $first_disk }" + +tok "ledctl degraded=$first_disk" +tok "ledctl rebuild=$first_disk" +tok "ledctl hotspare=$first_disk" +tok "ledctl pfa=$first_disk" +tok "ledctl failure=$first_disk" +tok "ledctl off={ $first_disk }" + +tlog "ledctl on ses " +for i in ses_rebuild ses_ifa ses_ica ses_cons_check ses_hotspare ses_rsvd_dev \ + ses_ok ses_ident ses_rm ses_insert ses_missing ses_dnr ses_devoff ses_fault ses_active ;do + tok "ledctl $i=$first_disk --log=/var/log/ledctl.log" + # don't sleep after skipped tests + if [[ $? != 2 ]]; then + sleep 2 + fi +done +tok "ledctl off=$first_disk" + +tlog "ledmon testing" +trun "ledmon --log=/var/log/ledmon.log" +sleep 2 + +trun "cat /var/log/ledmon.log" +trun "cat /var/log/ledctl.log" + +tend diff --git a/tests/ledctl_test/tc.sh b/tests/ledctl_test/tc.sh new file mode 100644 index 0000000..850e5b6 --- /dev/null +++ b/tests/ledctl_test/tc.sh @@ -0,0 +1,239 @@ +#!/bin/bash + +# Copyright (C) 2010 Red Hat, Inc. All rights reserved. +# +# This copyrighted material is made available to anyone wishing to use, +# modify, copy, or redistribute it subject to the terms and conditions +# of the GNU General Public License v.2. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +# filename: function + +# USAGE + +test x$LXT_TC = x || return +LXT_TC=1 + +# +# print the current date +# usage: d=$(tdate) +# +tdate () +{ + date '+%T' 2>/dev/null +} + +# +# print the log information +# usage: tlog "hello world" "WARNING" +# +tlog () +{ + local msg=$1 + local log_level=${2:-INFO} + local cur_date=$(tdate) + + echo "[$log_level][$cur_date]$msg" + + return 0 +} + +# +# run the cmd and format the log. return the exitint status of cmd +# use the global variables: tSTDOUT and tSTDERR to return the stdout and stderr +# usage: trun "ls" +# trun "ls"; echo $? +# stdout=$tSTDOUT +# stderr=$tSTDERR +# +trun () +{ + local cmd="$*" + + _trun_ "$cmd" +} + +# +# verify the execution of command +# if the cmd return 0, mark this checkpoint passed and return 0 +# if not, mark it failed and return 1 +# usage: tok "ls /" +# +tok () +{ + local cmd="$*" + _trun_ "$cmd" + # skip unsupported devices + # see STATUS_NOT_SUPPORTED in ledmon-0.92/src/status.h + if test $? -eq 33; then + tskip_ "$cmd" ; + elif test $? -eq 0; then + tpass_ "$cmd" ; + else + tfail_ "$cmd" ; + fi +} + +# +# verify the execution of command +# if the cmd return 0, will continue to run the script +# if not, mark it failes and exit +# usage: terr "ls" +# +terr () +{ + local cmd="$*" + _trun_ "$cmd" + if test $? -ne 0; then + tfail_ "$cmd" ; + tend ; + fi +} + +# +# exit the program and print the log message +# usage: texit "error message" 100 +# similar to the exception +# +texit () +{ + msg=$1 + err=$2 + is_null $err && err=1 + test $err -lt 1 || err=1 + + tlog "$msg" "ERROR" + exit $2 +} + +# +# print the test report, cleanup the testing bed and close the testing. +# usage: tend +# +tend () +{ + local pcount=$(wc -l $tPASS_FILE | awk '{print $1}') + local scount=$(wc -l $tSKIP_FILE | awk '{print $1}') + local fcount=$(wc -l $tFAIL_FILE | awk '{print $1}') + local total=$(( $pcount + $scount + $fcount )) + + echo "#################################Test Report###############################" + echo "TOTAL : $total" + echo "PASSED : $pcount" + echo "SKIPPED : $scount" + echo "FAILED : $fcount" + cat $tPASS_FILE $tSKIP_FILE $tFAIL_FILE + echo "###########################End of running $0########################" + + # cleanup + rm -f $tPASS_FILE $tSKIP_FILE $tFAIL_FILE $tRETURN_FILE $tSTDERR_FILE + if [[ $fcount > 0 ]]; then + exit 1 + fi + exit 0 +} + +# +# private function +# + +# +# print the error message and call stack. return 1 +# +tfail_ () +{ + local msg=$* + tlog "$msg" "ERROR" >>$tFAIL_FILE + + return 1 +} + +# +# print the sucessful message. return 0 +# +tpass_ () +{ + local msg=$* + tlog "$msg" "PASS" >> $tPASS_FILE + + return 0 +} + +tskip_ () +{ + local msg=$* + tlog "$msg" "SKIP" >> $tSKIP_FILE + + return 2 +} + +_trun_ () +{ + local cmd="$1" + local cur_date=$(tdate) + + local stdout=$(eval "$cmd" 2>$tSTDERR_FILE; echo $? >$tRETURN_FILE 2>/dev/null) +#timeout -- how to set timeout? + local exit_status=$(< $tRETURN_FILE) + local stderr=$(< $tSTDERR_FILE) + local msg=PASS + + [[ $exit_status == "1" ]] && msg=FAIL + [[ $exit_status == "33" ]] && msg=SKIP + + tSTDOUT=$stdout + tSTDERR=$stderr + + test $tIGNORE_STDOUT -eq 1 && stdout='redirect the stdout to /dev/null' + test $tIGNORE_STDERR -eq 1 && stderr='redirect the stderr to /dev/null' + + echo "[$msg][$cur_date][$HOSTNAME]$cmd" + echo "STDOUT:" + test "x$stdout" = x || echo "$stdout" + echo "STDERR:$stderr" + echo "RETURN:$exit_status" + echo + + return $exit_status +} + +# +# setup the testing environment +# +_tsetup_ () +{ + + LXT_TMP_DIR="/mnt/testarea/lxt"; + + test -z "$HOSTNAME" && HOSTNAME=$(hostname) + test -d "$LXT_TMP_DIR" || mkdir -p "$LXT_TMP_DIR" >& /dev/null || exit 1 + + tSTDERR_FILE="$LXT_TMP_DIR/stderr.$$" + test -e "$tSTDERR_FILE" || > "$tSTDERR_FILE" || exit 1 + tRETURN_FILE="$LXT_TMP_DIR/return.$$" + test -e "$tRETURN_FILE" || > "$tRETURN_FILE" || exit 1 + tPASS_FILE="$LXT_TMP_DIR/tc.pass.$$" + test -e "$tPASS_FILE" || > "$tPASS_FILE" || exit 1 + tSKIP_FILE="$LXT_TMP_DIR/tc.skip.$$" + test -e "$tSKIP_FILE" || > "$tSKIP_FILE" || exit 1 + tFAIL_FILE="$LXT_TMP_DIR/tc.fail.$$" + test -e "$tFAIL_FILE" || > "$tFAIL_FILE" || exit 1 +} + +# +# main +# + +# global variables +tIGNORE_STDOUT=0 +tIGNORE_STDERR=0 +tSTDOUT= +tSTDERR= +tPASS_FILE= +tSKIP_FILE= +tFAIL_FILE= + +_tsetup_ diff --git a/tests/tests.yml b/tests/tests.yml new file mode 100644 index 0000000..0f74d8e --- /dev/null +++ b/tests/tests.yml @@ -0,0 +1,14 @@ +--- +# Tests suitable for classic environment +- hosts: localhost + roles: + - role: standard-test-basic + tags: + - classic + tests: + - ledctl_test + required_packages: + - make + - which + - kmod + - e2fsprogs