[v3,11/11] vm_smoke_test: Migrate to Avocado

Message ID 20210317145225.88050-12-amikan@ilbers.de
State Superseded, archived
Headers show
Series Update Avocado testsuite | expand

Commit Message

Anton Mikanovich March 17, 2021, 4:52 a.m. UTC
Call Avocado test cases instead of shell based.

Signed-off-by: Anton Mikanovich <amikan@ilbers.de>
---
 scripts/vm_smoke_test        | 110 ++++-------------------
 scripts/vm_smoke_test_legacy | 168 +++++++++++++++++++++++++++++++++++
 2 files changed, 185 insertions(+), 93 deletions(-)
 create mode 100755 scripts/vm_smoke_test_legacy

Patch

diff --git a/scripts/vm_smoke_test b/scripts/vm_smoke_test
index ce08213..0ef3caf 100755
--- a/scripts/vm_smoke_test
+++ b/scripts/vm_smoke_test
@@ -3,9 +3,7 @@ 
 # This software is a part of ISAR.
 # Copyright (C) 2015-2018 ilbers GmbH
 
-CONSOLE_OUTPUT=/tmp/isar_console
-PID_FILE=/tmp/qemu.pid
-VERBOSE=1
+VERBOSE="--show-job-log"
 TIMEOUT=300
 
 # Error codes:
@@ -13,75 +11,12 @@  ES_OK=0
 ES_FAIL=1
 ES_BUG=3
 
-RET=$ES_OK
+RET=$ES_FAIL
 
-dump_boot_log() {
-    echo "Boot log:\n8<--"
-    cat $CONSOLE_OUTPUT
-    echo "\n8<--"
-}
-
-check_login_prompt() {
-    echo -n "Check login prompt: "
-
-    str=$(grep "isar login: " $CONSOLE_OUTPUT)
-
-    if [ -n "$str" ]; then
-        echo "PASSED"
-    else
-        echo "FAIL"
-        RET=$ES_FAIL
-        FAIL=1
-    fi
-}
-
-check_example_module() {
-    echo -n "Check example module: "
-
-    str=$(grep "Just an example" $CONSOLE_OUTPUT)
-
-    if [ -n "$str" ]; then
-        echo "PASSED"
-    else
-        echo "FAIL"
-        RET=$ES_FAIL
-        FAIL=1
-    fi
-}
-
-run_test () {
-    ARCH=$1
-    DISTRO=$2
-
-    echo "-------------------------------------------------"
-    echo "Testing Isar [$DISTRO] image for [$ARCH] machine:"
+# Get Avocado QEMU tests path
+VM_TEST_DIR="$(dirname "$0")/../testsuite/vm_boot_test"
 
-    start_vm -a $ARCH -d $DISTRO -o $CONSOLE_OUTPUT -p $PID_FILE > /dev/null 2>&1 &
-    sleep 5
-
-    if [ -z `ps -p $! -o pid=` ]; then
-        echo "QEMU start: FAILED"
-        RET=$ES_FAIL
-        echo "Command output:\n8<--"
-        start_vm -a $ARCH -d $DISTRO -o $CONSOLE_OUTPUT -p $PID_FILE
-        echo "\n8<--"
-    else
-        sleep $TIMEOUT
-        kill `cat $PID_FILE`
-
-        FAIL=0
-
-        check_login_prompt
-
-        check_example_module
-
-        [ $VERBOSE -eq 1 -o $FAIL -eq 1 ] && dump_boot_log
-
-        rm $CONSOLE_OUTPUT
-    fi
-
-    rm $PID_FILE
-}
+BUILD_DIR=$PWD
 
 show_help() {
     echo "This script tests the Isar images for default targets in QEMU."
@@ -91,10 +26,6 @@  show_help() {
     echo
     echo "Parameters:"
     echo "    -f,--fast             test reduced set of supported targets."
-    echo "    -o,--output FILE      specify file to store console output."
-    echo "                          The default is: /tmp/isar_console"
-    echo "    -p,--pid-file FILE    specify file to store QEMU process PID."
-    echo "                          The default is: /tmp/qemu.pid"
     echo "    -q, --quiet           do not display boot logs for all the targets."
     echo "                          If test failed for the specific configuration,"
     echo "                          the respective boot log will be printed anyway."
@@ -119,18 +50,18 @@  do
         exit 0
         ;;
     -o|--output)
-        CONSOLE_OUTPUT=$2
+        # Deprecated option
         shift
         ;;
     -p|--pid-file)
-        PID_FILE=$2
+        # Deprecated option
         shift
         ;;
     -f|--fast)
         FAST_BUILD="1"
         ;;
     -q|--quiet)
-        VERBOSE=0
+        VERBOSE=""
         ;;
     -t|--timeout)
         TIMEOUT=$2
@@ -145,24 +76,17 @@  do
     shift
 done
 
-# ARM machine
-run_test arm stretch
-run_test arm buster
-
-# AMD64 machine
-if [ -z "$FAST_BUILD" ]; then
-    run_test amd64 buster
-    run_test amd64 focal
+TAGS="full"
+if [ -n "$FAST_BUILD" ]; then
+    TAGS="fast"
 fi
-run_test amd64 stretch
 
-# i386 machine
-if [ -z "$FAST_BUILD" ]; then
-    run_test i386 stretch
-    run_test i386 buster
-fi
+# Provide working path
+export VIRTUAL_ENV="./"
 
-# ARM64 machine
-run_test arm64 stretch
+if avocado run "$VM_TEST_DIR/vm_boot_test.py" -t $TAGS \
+    -p build_dir="$BUILD_DIR" -p time_to_wait=$TIMEOUT $VERBOSE; then
+    RET=$ES_OK
+fi
 
 exit $RET
diff --git a/scripts/vm_smoke_test_legacy b/scripts/vm_smoke_test_legacy
new file mode 100755
index 0000000..ce08213
--- /dev/null
+++ b/scripts/vm_smoke_test_legacy
@@ -0,0 +1,168 @@ 
+#!/bin/sh
+#
+# This software is a part of ISAR.
+# Copyright (C) 2015-2018 ilbers GmbH
+
+CONSOLE_OUTPUT=/tmp/isar_console
+PID_FILE=/tmp/qemu.pid
+VERBOSE=1
+TIMEOUT=300
+
+# Error codes:
+ES_OK=0
+ES_FAIL=1
+ES_BUG=3
+
+RET=$ES_OK
+
+dump_boot_log() {
+    echo "Boot log:\n8<--"
+    cat $CONSOLE_OUTPUT
+    echo "\n8<--"
+}
+
+check_login_prompt() {
+    echo -n "Check login prompt: "
+
+    str=$(grep "isar login: " $CONSOLE_OUTPUT)
+
+    if [ -n "$str" ]; then
+        echo "PASSED"
+    else
+        echo "FAIL"
+        RET=$ES_FAIL
+        FAIL=1
+    fi
+}
+
+check_example_module() {
+    echo -n "Check example module: "
+
+    str=$(grep "Just an example" $CONSOLE_OUTPUT)
+
+    if [ -n "$str" ]; then
+        echo "PASSED"
+    else
+        echo "FAIL"
+        RET=$ES_FAIL
+        FAIL=1
+    fi
+}
+
+run_test () {
+    ARCH=$1
+    DISTRO=$2
+
+    echo "-------------------------------------------------"
+    echo "Testing Isar [$DISTRO] image for [$ARCH] machine:"
+
+    start_vm -a $ARCH -d $DISTRO -o $CONSOLE_OUTPUT -p $PID_FILE > /dev/null 2>&1 &
+    sleep 5
+
+    if [ -z `ps -p $! -o pid=` ]; then
+        echo "QEMU start: FAILED"
+        RET=$ES_FAIL
+        echo "Command output:\n8<--"
+        start_vm -a $ARCH -d $DISTRO -o $CONSOLE_OUTPUT -p $PID_FILE
+        echo "\n8<--"
+    else
+        sleep $TIMEOUT
+        kill `cat $PID_FILE`
+
+        FAIL=0
+
+        check_login_prompt
+
+        check_example_module
+
+        [ $VERBOSE -eq 1 -o $FAIL -eq 1 ] && dump_boot_log
+
+        rm $CONSOLE_OUTPUT
+    fi
+
+    rm $PID_FILE
+}
+
+show_help() {
+    echo "This script tests the Isar images for default targets in QEMU."
+    echo
+    echo "Usage:"
+    echo "    $0 [params]"
+    echo
+    echo "Parameters:"
+    echo "    -f,--fast             test reduced set of supported targets."
+    echo "    -o,--output FILE      specify file to store console output."
+    echo "                          The default is: /tmp/isar_console"
+    echo "    -p,--pid-file FILE    specify file to store QEMU process PID."
+    echo "                          The default is: /tmp/qemu.pid"
+    echo "    -q, --quiet           do not display boot logs for all the targets."
+    echo "                          If test failed for the specific configuration,"
+    echo "                          the respective boot log will be printed anyway."
+    echo "    -t,--timeout SEC      specify time in seconds to wait before stop QEMU."
+    echo "                          The default is: 300"
+    echo "    -h, --help            display this message and exit."
+    echo
+    echo "Exit status:"
+    echo " 0  if OK,"
+    echo " 1  if test failed,"
+    echo " 3  if invalid parameters are passed."
+}
+
+# Parse command line to get user configuration
+while [ $# -gt 0 ]
+do
+    key="$1"
+
+    case $key in
+    -h|--help)
+        show_help
+        exit 0
+        ;;
+    -o|--output)
+        CONSOLE_OUTPUT=$2
+        shift
+        ;;
+    -p|--pid-file)
+        PID_FILE=$2
+        shift
+        ;;
+    -f|--fast)
+        FAST_BUILD="1"
+        ;;
+    -q|--quiet)
+        VERBOSE=0
+        ;;
+    -t|--timeout)
+        TIMEOUT=$2
+        shift
+        ;;
+    *)
+        echo "error: invalid parameter '$key', please try '--help' to get list of supported parameters"
+        exit $ES_BUG
+        ;;
+    esac
+
+    shift
+done
+
+# ARM machine
+run_test arm stretch
+run_test arm buster
+
+# AMD64 machine
+if [ -z "$FAST_BUILD" ]; then
+    run_test amd64 buster
+    run_test amd64 focal
+fi
+run_test amd64 stretch
+
+# i386 machine
+if [ -z "$FAST_BUILD" ]; then
+    run_test i386 stretch
+    run_test i386 buster
+fi
+
+# ARM64 machine
+run_test arm64 stretch
+
+exit $RET