debuggers.hg

changeset 22683:ca0b26180f32

Xen MCE test: common functions to be used for test cases

Implement some common shell functions and variable definitions are
defined to be used by test cases Verify fuctions include domain0 user
space tool mcelog, Xen dmesg and guest kernel log verification.

Signed-off-by: Yunhong Jiang <yunhong.jiang@intel.com>
Signed-off-by: Haicheng Li<haicheng.li@intel.com>
Signed-off-by: Xudong Hao <xudong.hao@intel.com>
author Keir Fraser <keir@xen.org>
date Fri Dec 24 10:22:23 2010 +0000 (2010-12-24)
parents 1bc031edae04
children a69ceb6ded92
files tools/tests/mce-test/config/setup.conf tools/tests/mce-test/lib/xen-mceinj-tool.sh
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/tools/tests/mce-test/config/setup.conf	Fri Dec 24 10:22:23 2010 +0000
     1.3 @@ -0,0 +1,25 @@
     1.4 +#!/bin/bash
     1.5 +#
     1.6 +# Software injection based test cases: test cases are triggered via
     1.7 +# mce-inject tool.
     1.8 +# Copyright (c) 2010, Intel Corporation
     1.9 +# 
    1.10 +# This program is free software; you can redistribute it and/or
    1.11 +# modify it under the terms of the GNU General Public License version
    1.12 +# 2 as published by the Free Software Foundation.
    1.13 +# 
    1.14 +# This program is distributed in the hope that it will be useful, but
    1.15 +# WITHOUT ANY WARRANTY; without even the implied warranty of
    1.16 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    1.17 +# General Public License for more details.
    1.18 +# 
    1.19 +# You should have received a copy of the GNU General Public License
    1.20 +# along with this program; if not, write to the Free Software Foundation,
    1.21 +# Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
    1.22 +#
    1.23 +# Author: Xudong Hao <xudong.hao@intel.com>
    1.24 +#
    1.25 +
    1.26 +export MCE_SRAO_MEM=0
    1.27 +export MCE_SRAO_LLC=1
    1.28 +export CMCI_UCNA_LLC=2
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/tools/tests/mce-test/lib/xen-mceinj-tool.sh	Fri Dec 24 10:22:23 2010 +0000
     2.3 @@ -0,0 +1,261 @@
     2.4 +#!/bin/bash
     2.5 +#
     2.6 +# Software injection based test cases: test cases are triggered via
     2.7 +# mce-inject tool.
     2.8 +# Copyright (c) 2010, Intel Corporation
     2.9 +# 
    2.10 +# This program is free software; you can redistribute it and/or
    2.11 +# modify it under the terms of the GNU General Public License version
    2.12 +# 2 as published by the Free Software Foundation.
    2.13 +# 
    2.14 +# This program is distributed in the hope that it will be useful, but
    2.15 +# WITHOUT ANY WARRANTY; without even the implied warranty of
    2.16 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    2.17 +# General Public License for more details.
    2.18 +# 
    2.19 +# You should have received a copy of the GNU General Public License
    2.20 +# along with this program; if not, write to the Free Software Foundation,
    2.21 +# Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
    2.22 +#
    2.23 +# Author: Xudong Hao <xudong.hao@intel.com>
    2.24 +#
    2.25 +
    2.26 +. $ROOT/config/setup.conf
    2.27 +
    2.28 +#Guest Image Preparation
    2.29 +hvm_image_prepare()
    2.30 +{
    2.31 +    local image=$1
    2.32 +    local tmpdir=`mktemp -d`
    2.33 +    local tmpfile=`mktemp`
    2.34 +    local offset=`kpartx -l $image | awk '{print $NF*512}'`
    2.35 +    mount -oloop,offset=$offset $image $tmpdir && echo "mount image to $tmpdir"
    2.36 +    local g_grub=$tmpdir/boot/grub/grub.conf
    2.37 +    if [ $? -ne 0 ]; then
    2.38 +        show "  Mount image failed!"
    2.39 +        return 1
    2.40 +    fi
    2.41 +
    2.42 +    if ! grep FLAG_CONSOLE $g_grub; then
    2.43 +        sed -e '/kernel/s/$/ console=ttyS0,115200,8n1 console=tty0/g' \
    2.44 +            $g_grub > $tmpfile
    2.45 +        mv -f $tmpfile $g_grub
    2.46 +        rm -f $tmpfile
    2.47 +        echo "
    2.48 +#### FLAG_CONSOLE #### " >> $g_grub
    2.49 +    fi
    2.50 +    umount $tmpdir
    2.51 +    rm -fr $tmpdir
    2.52 +
    2.53 +    return 0
    2.54 +}
    2.55 +
    2.56 +create_hvm_guest()
    2.57 +{
    2.58 +    local image=$1
    2.59 +    local originconfig="/etc/xen/xmexample.hvm"
    2.60 +    local TF=`mktemp`
    2.61 +    local case_dir=$ROOT/results/$this_case
    2.62 +    local config=$case_dir/guest_config
    2.63 +    [ -d $case_dir ] || mkdir $case_dir
    2.64 +    [ -f $logfile ] || touch $logfile
    2.65 +    local File=`echo $image|sed "s/\//\\\\\\\\\\//g"`
    2.66 +    local g_name="`basename $image`_`date +%H%M%S`"
    2.67 +
    2.68 +    hvm_image_prepare $image
    2.69 +
    2.70 +    while getopts ":u:m:" Option
    2.71 +    do
    2.72 +        case $Option in
    2.73 +            u ) vcpus=$OPTARG;;
    2.74 +            m ) memory=$OPTARG;;
    2.75 +            e ) bridge_name=$OPTARG;;
    2.76 +            * ) ;;
    2.77 +        esac
    2.78 +    done
    2.79 +
    2.80 +    cp $originconfig $config -f
    2.81 +
    2.82 +    if [ -z $image ]; then
    2.83 +        show "Image file $image does not exist, Please input one valid file"
    2.84 +        return 1
    2.85 +    fi
    2.86 +
    2.87 +    sed -e "/^disk/s/file:.*,\(hda\)/file:${File},\1/" $config \
    2.88 +          | sed -e "/^disk/s/phy:.*,\(hda\)/file:${File},\1/" >$TF
    2.89 +    mv -f $TF $config
    2.90 +
    2.91 +    [ -z $memory ] || sed -i "/^memory/s/^.*$/memory = $memory/" $config
    2.92 +    [ -z $vcpus ] || sed -i "1,/^#vcpus/s/^#vcpus.*$/vcpus=$vcpus/;1d" $config
    2.93 +    sed -i "/^vif/s/vif/#vif/" $config
    2.94 +    sed -i "/^name/s/^.*$/name = \"$g_name\"/" $config
    2.95 +
    2.96 +    string1=$(ls /dev/pts | sort)
    2.97 +    xm cr $config
    2.98 +    [ $? -eq 0 ] && domid=`xm list $g_name | tail -n1 | awk '{print $2}'`
    2.99 +    if [ -z $domid ]; then
   2.100 +        show "  Guest can not boot up"
   2.101 +        return 1
   2.102 +    fi
   2.103 +    
   2.104 +    sleep 10
   2.105 +
   2.106 +    string2=$(ls /dev/pts | sort)
   2.107 +
   2.108 +    get_guest_klog
   2.109 +    sleep 40
   2.110 +
   2.111 +    return 0
   2.112 +}
   2.113 +
   2.114 +get_guest_klog()
   2.115 +{
   2.116 +    local case_dir=$ROOT/results/$this_case
   2.117 +    gklog=$case_dir/gklog
   2.118 +    [ -d $case_dir ] || mkdir $case_dir
   2.119 +    [ -f $gklog ] || touch $gklog
   2.120 +    for fo in $string2; do
   2.121 +        echo $string1 | grep $fo -wq
   2.122 +        [ $? -eq 1 ] && num=$fo
   2.123 +    done
   2.124 +    cat /dev/pts/$num > $gklog &
   2.125 +}
   2.126 +
   2.127 +mce_inject_trigger()
   2.128 +{
   2.129 +    local errtype=$1
   2.130 +    local append=""
   2.131 +    while getopts ":d:u:p:" Option
   2.132 +    do
   2.133 +        case $Option in
   2.134 +            d ) domid=$OPTARG;;
   2.135 +            u ) cpu=$OPTARG;;
   2.136 +            p ) pageaddr=$OPTARG;;
   2.137 +            * ) ;;
   2.138 +        esac
   2.139 +    done
   2.140 +
   2.141 +    [ -z $domid ] || append=$append" -d $domid"
   2.142 +    [ -z $cpu ] || append=$append" -c $cpu"
   2.143 +    [ -z $pageaddr ] || append=$append" -p $pageaddr"
   2.144 +
   2.145 +    [ -f $ROOT/tools/xen-mceinj ]
   2.146 +    if [ $? -eq 0 ]; then
   2.147 +        xm dmesg -c
   2.148 +        $ROOT/tools/xen-mceinj -t $errtype $append
   2.149 +        if [ $? -ne 0 ]; then
   2.150 +            show "  Failed: Maybe the memory addr is out of range. \
   2.151 +                      Please check whether used xen-mceinj tool correctlly"
   2.152 +            return 1
   2.153 +        fi
   2.154 +    else
   2.155 +        show "  Failed: please compile xen-mce inject tool firstly"
   2.156 +        return 1
   2.157 +    fi
   2.158 +    return 0
   2.159 +}
   2.160 +
   2.161 +xen_verify()
   2.162 +{
   2.163 +    local case_dir=$ROOT/results/$this_case
   2.164 +    local xenlog=$case_dir/xenlog
   2.165 +    [ -d $case_dir ] || mkdir $case_dir
   2.166 +    [ -f $xenlog ] || touch $xenlog
   2.167 +    xm dmesg > $xenlog
   2.168 +    grep "Error is successfully recovered" $xenlog > /dev/null
   2.169 +    if [ $? -eq 0 ]; then
   2.170 +        show "  Passed: Xen handle this MCE error successfully"
   2.171 +    else
   2.172 +        show "  Failed: Xen does not handle MCE error correctly !!"
   2.173 +        return 1
   2.174 +    fi
   2.175 +    return 0
   2.176 +}
   2.177 +
   2.178 +guest_verify()
   2.179 +{
   2.180 +    grep "kernel page recovery" $gklog > /dev/null
   2.181 +    if [ $? -eq 0 ]; then
   2.182 +        show "  Passed: Guest recive MCE error and solved correctly"
   2.183 +    else
   2.184 +        show "  Failed: Guest fail to solve MCE error"
   2.185 +        return 1
   2.186 +    fi
   2.187 +    return 0
   2.188 +}
   2.189 +
   2.190 +mcelog_verify()
   2.191 +{
   2.192 +    local err_type=$1
   2.193 +    local ret=0
   2.194 +    local case_dir=$ROOT/results/$this_case
   2.195 +    local mcelog=$case_dir/mcelog
   2.196 +    [ -d $case_dir ] || mkdir $case_dir
   2.197 +    [ -f $mcelog ] || touch $mcelog
   2.198 +    mcelog > $mcelog
   2.199 +    if [ -z $mcelog ]; then
   2.200 +        show "  Failed: MCELOG does not catch anything"
   2.201 +        return 1
   2.202 +    else
   2.203 +        if [ $err_type -eq 0 ]; then
   2.204 +            grep "MEMORY CONTROLLER MS_CHANNELunspecified_ERR" $mcelog \
   2.205 +                > /dev/null
   2.206 +            ret=$?
   2.207 +        elif [ $err_type -eq 1 ]; then
   2.208 +            grep "Generic CACHE Level-2 Eviction Error" $mcelog > /dev/null
   2.209 +            ret=$?
   2.210 +        elif [ $err_type -eq 2 ]; then
   2.211 +            grep "Data CACHE Level-2 Data-Read Error" $mcelog > /dev/null
   2.212 +            ret=$?
   2.213 +        fi
   2.214 +
   2.215 +        if [ $ret -eq 0 ]; then
   2.216 +            show "  Passed: MCElog catch a correct error"
   2.217 +        else 
   2.218 +            show "  Failed: MCE log catch a incorrect error !!"
   2.219 +            return 1
   2.220 +        fi
   2.221 +    fi
   2.222 +
   2.223 +    return 0
   2.224 +}
   2.225 +
   2.226 +function des_guest()
   2.227 +{
   2.228 +    xm des $domid    
   2.229 +}
   2.230 +
   2.231 +function clean_env()
   2.232 +{
   2.233 +    [ -d $ROOT/results ] || mkdir $ROOT/results
   2.234 +    # clean logs and results of last test for this case
   2.235 +    rm -fr $ROOT/results/$this_case/*
   2.236 +}
   2.237 +
   2.238 +function show()
   2.239 +{
   2.240 +    local case_dir=$ROOT/results/$this_case
   2.241 +    local logfile=$case_dir/testlog
   2.242 +    [ -d $case_dir ] || mkdir $case_dir
   2.243 +    [ -f $logfile ] || touch $logfile
   2.244 +    echo -e $* | tee -a $logfile > /dev/null
   2.245 +}
   2.246 +
   2.247 +function gen_result()
   2.248 +{
   2.249 +    local ret=$1
   2.250 +    local case_dir=$ROOT/results/$this_case
   2.251 +    local result=$case_dir/result
   2.252 +    [ -d $case_dir ] || mkdir $case_dir
   2.253 +    [ -f $result ] || touch $result
   2.254 +    
   2.255 +    if [ $ret -eq 0 ]; then
   2.256 +        echo "PASSED" > $result
   2.257 +    elif [ $ret -eq 1 ]; then
   2.258 +        echo "FAILED" > $result
   2.259 +        echo "   Please check testlog for details!!! " >> $result
   2.260 +    else
   2.261 +        echo "NORESULT" > $result
   2.262 +        echo "   Please check testlog for details!!! " >> $result
   2.263 +    fi
   2.264 +}