diff --git a/test/common.sh b/test/common.sh new file mode 100644 index 00000000..31a4c5d4 --- /dev/null +++ b/test/common.sh @@ -0,0 +1,117 @@ +# Common test framework, source this file to get config and basic variables: +# BIN/SBIN are the mckernel install paths +# if USELTP is set, +# LTP is the root of the ltp install directory +# LTPBIN is the testcases bin dir +# if USEOSTEST is set, +# OSTEST is the root of the ostest repo after install +# TESTMCK is the test_mck binary +# MCEXEC, IHKCONFIG, IHKOSCTL are the corresponding binaries +# mcreboot and mcstop are functions that perform the action with prints/checks +# +# Additionally, the following parameters can be provided through environment: +# BOOTPARAM to override mcreboot options +# MCREBOOT and MCSTOP can be set to 0/empty to not run the action at start + + +# Unfortunately, there is no standard way to get sourced file's path +# use bash-specific feature. +TEST_BASE=$(dirname "${BASH_SOURCE[0]}") + +if [ -f "$HOME/.mck_test_config" ]; then + . "$HOME/.mck_test_config" +elif [ -f "$TEST_BASE/../mck_test_config.sample" ]; then + . "$TEST_BASE/../mck_test_config.sample" +fi + + +if [[ -z "$BIN" ]]; then + if [ -f ../../../config.h ]; then + BIN=$(awk -F\" '/^#define BINDIR/ { print $2; exit }' \ + "$TEST_BASE/../config.h") + fi +fi + +if [[ -z "$SBIN" ]]; then + if [ -f ../../../Makefile ]; then + SBIN=$(awk -F\" '/^#define SBINDIR/ { print $2; exit }' \ + "$TEST_BASE/../config.h") + fi +fi + +if [[ ! -x "$BIN/mcexec" ]]; then + echo no mckernel found $BIN >&2 + exit 1 +fi +MCEXEC="$BIN/mcexec" +IHKOSCTL="$SBIN/ihkosctl" +IHKCONFIG="$SBIN/ihkconfig" + +if ((USELTP)); then + if [[ -z "$LTP" ]]; then + if [[ -f "$HOME/ltp/testcases/bin/fork01" ]]; then + LTP="$HOME/ltp" + fi + fi + + if [[ ! -x "$LTP/testcases/bin/fork01" ]]; then + echo no LTP found $LTP >&2 + exit 1 + fi + LTPBIN="$LTP/testcases/bin" +fi + +if ((USEOSTEST)); then + if [[ -z "$OSTEST" ]]; then + if [[ -f "$HOME/ostest/bin/test_mck" ]]; then + OSTEST="$HOME/ostest" + fi + fi + + if [[ ! -x "$OSTEST"/bin/test_mck ]]; then + echo no ostest found $OSTEST >&2 + exit 1 + fi + TESTMCK="$OSTEST/bin/test_mck" +fi + +# compat variables +BINDIR="$BIN" +SBINDIR="$SBIN" +LTPDIR="$LTP" +OSTESTDIR="$OSTEST" + +if [[ ! -x "$SBIN/mcstop+release.sh" ]]; then + echo mcstop+release: not found >&2 + exit 1 +fi + +if [[ ! -x "$SBIN/mcreboot.sh" ]]; then + echo mcreboot: not found >&2 + exit 1 +fi + +mcstop() { + echo -n "mcstop+release.sh ... " + sudo "$SBIN/mcstop+release.sh" + echo "done" + + if lsmod | grep mcctrl > /dev/null 2>&1; then + echo mckernel shutdown failed >&2 + exit 1 + fi +} + +mcreboot() { + echo -n "mcreboot.sh $BOOTPARAM ... " + sudo "$SBIN/mcreboot.sh" $BOOTPARAM + echo "done" + + if ! lsmod | grep mcctrl > /dev/null 2>&1; then + echo mckernel boot failed >&2 + exit 1 + fi +} + +((${MCSTOP-1})) && mcstop +((${MCREBOOT-1})) && mcreboot diff --git a/test/issues/1176/C1176.sh b/test/issues/1176/C1176.sh index f9af578d..7d3d7a9a 100644 --- a/test/issues/1176/C1176.sh +++ b/test/issues/1176/C1176.sh @@ -1,116 +1,10 @@ #!/bin/sh -BOOTPARAM="-c 1-7,9-15,17-23,25-31 -m 10G@0,10G@1 -r 1-7:0+9-15:8+17-23:16+25-31:24" USELTP=1 USEOSTEST=1 -################################################################################ -BINDIR= -SBINDIR= -OSTESTDIR= -LTPDIR= -LTPBIN= -MCEXEC= -TESTMCK= +. ../../common.sh -if [ -f $HOME/mck_test_config ]; then - . $HOME/mck_test_config -elif [ -f ../../../mck_test_config.sample ]; then - . ../../../mck_test_config.sample -else - BIN= - SBIN= - OSTEST= - LTP= -fi - -#------------------------------------------------------------------------------- -if [ "x$BIN" = x ]; then - if [ -f ../../../config.h ]; then - str=`grep "^#define BINDIR " ../../../config.h | head -1 | sed 's/^#define BINDIR /BINDIR=/'` - eval $str - fi -else - BINDIR="$BIN" -fi - -if [ "x$SBIN" = x ]; then - if [ -f ../../../Makefile ]; then - str=`grep ^SBINDIR ../../../Makefile | head -1 | sed 's/ //g'` - eval $str - fi -else - SBINDIR="$SBIN" -fi - -if [ ! -x "$BINDIR/mcexec" ]; then - echo no mckernel found $BINDIR >&2 - exit 1 -fi -MCEXEC="$BINDIR/mcexec" - -#------------------------------------------------------------------------------- -if [ "x$USELTP" != x ]; then - if [ "x$LTP" = x ]; then - if [ -f "$HOME/ltp/testcases/bin/fork01" ]; then - LTPDIR="$HOME/ltp" - fi - else - LTPDIR="$LTP" - fi - - if [ ! -x "$LTPDIR/testcases/bin/fork01" ]; then - echo no LTP found $LTPDIR >&2 - exit 1 - fi - LTPBIN="$LTPDIR/testcases/bin" -fi - -#------------------------------------------------------------------------------- -if [ "x$USEOSTEST" != x ]; then - if [ "x$OSTEST" = x ]; then - if [ -f "$HOME/ostest/bin/test_mck" ]; then - OSTESTDIR="$HOME/ostest" - fi - else - OSTESTDIR="$OSTEST" - fi - - if [ ! -x "$OSTESTDIR"/bin/test_mck ]; then - echo no ostest found $OSTESTDIR >&2 - exit 1 - fi - TESTMCK="$OSTESTDIR/bin/test_mck" -fi - -#=============================================================================== -if [ ! -x "$SBINDIR/mcstop+release.sh" ]; then - echo mcstop+release: not found >&2 - exit 1 -fi -echo -n "mcstop+release.sh ... " -sudo "$SBINDIR/mcstop+release.sh" -echo "done" - -if lsmod | grep mcctrl > /dev/null 2>&1; then - echo mckernel shutdown failed >&2 - exit 1 -fi - -if [ ! -x "$SBINDIR/mcreboot.sh" ]; then - echo mcreboot: not found >&2 - exit 1 -fi -echo -n "mcreboot.sh $BOOTPARAM ... " -sudo "$SBINDIR/mcreboot.sh" $BOOTPARAM -echo "done" - -if ! lsmod | grep mcctrl > /dev/null 2>&1; then - echo mckernel boot failed >&2 - exit 1 -fi - -################################################################################ "$MCEXEC" "$TESTMCK" -s getrusage -n 2 2>&1 | tee C1176T01.txt if grep "RESULT: you need check rusage value" C1176T01.txt > /dev/null 2>&1;then echo "*** C1176T01: OK" diff --git a/test/mck_test_config.sample.in b/test/mck_test_config.sample.in index f9a7d1b3..584fb4e5 100644 --- a/test/mck_test_config.sample.in +++ b/test/mck_test_config.sample.in @@ -1,5 +1,6 @@ # Config file for McKernel tests -BIN=@prefix@/bin -SBIN=@prefix@/sbin -OSTEST= -LTP= +: ${BIN:=@prefix@/bin} +: ${SBIN:=@prefix@/sbin} +: ${OSTEST:=} +: ${LTP:=} +: ${BOOTPARAM:=-c 1-7,9-15,17-23,25-31 -m 10G@0,10G@1 -r 1-7:0+9-15:8+17-23:16+25-31:24}