1#!/bin/bash
2#
3# Copyright (c) 2010, Intel Corporation
4#
5# This program is free software; you can redistribute it and/or
6# modify it under the terms of the GNU General Public License version
7# 2 as published by the Free Software Foundation.
8#
9# This program is distributed in the hope that it will be useful, but
10# WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12# General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program; If not, see <http://www.gnu.org/licenses/>.
16#
17# Author: Xudong Hao <xudong.hao@intel.com>
18#
19
20sd=$(dirname $0)
21export ROOT=`(cd $sd/../../../; pwd)`
22export this_case=srao_mem_guest
23
24. $ROOT/lib/xen-mceinj-tool.sh
25
26usage()
27{
28    echo "Usage: ./cases.sh [-options] [arguments]"
29    echo "================Below are the must have options==============="
30    echo -e "\t-i image\t: guest image"
31    echo -e "\t-m memory\t: set guest virtual memory"
32    echo "========                                              ========"
33    echo "================Below are the optional options================"
34    echo -e "\t-u vcpus\t: set guest virtual cpus number"
35    echo -e "\t-c injcpu\t: which cpu to inject error"
36    echo -e "\t-p pageaddr\t: Guest Physical Address to inject error"
37    echo -e "\t\t\tBy default, the GPA is 0x180020"
38    echo -e "\t-h help"
39    exit 0
40}
41
42[ $# -lt 1 ] && usage
43
44while getopts ":i:u:m:c:p:hl:" option
45do
46    case "$option" in
47    i) image=$OPTARG; offset=`kpartx -l $image | awk '{print $NF*512}'`;;
48    u) vcpus=$OPTARG;;
49    m) memory=$OPTARG;;
50    c) injcpu=$OPTARG;;
51    p) pageaddr=$OPTARG;;
52    l) early_kill="0";;
53    h) usage;;
54    *) echo "invalid option!"; usage;;
55    esac
56done
57
58
59start_guest()
60{
61    create_hvm_guest $image -u $vcpus -m $memory
62    if [ $? -ne 0 ]; then
63        echo "  Create guest fail!"
64        return 1
65    fi
66    return 0
67}
68
69inject()
70{
71    mce_inject_trigger $MCE_SRAO_MEM -u $injcpu -p $pageaddr
72    if [ $? -eq 0 ]; then
73        show "  Passed: Successfully to fake and inject a MCE error"
74    else
75        show "  Failed: Fake error and inject fail !!"
76        return 1
77    fi
78    return 0
79}
80
81do_main()
82{
83    ret_val=0
84    clean_env
85    start_guest || ret_val=1
86    inject || ret_val=1
87    xen_verify || ret_val=1
88    guest_verify || ret_val=1
89    mcelog_verify $MCE_SRAO_MEM || ret_val=1
90    des_guest
91    gen_result $ret_val
92}
93
94do_main "$@"
95