1f08c3bdfSopenharmony_ci#!/bin/bash
2f08c3bdfSopenharmony_ci#
3f08c3bdfSopenharmony_ci# Test script for KVM RAS
4f08c3bdfSopenharmony_ci#
5f08c3bdfSopenharmony_ci# This program is free software; you can redistribute it and/or
6f08c3bdfSopenharmony_ci# modify it under the terms of the GNU General Public
7f08c3bdfSopenharmony_ci# License as published by the Free Software Foundation; version
8f08c3bdfSopenharmony_ci# 2.
9f08c3bdfSopenharmony_ci#
10f08c3bdfSopenharmony_ci# This program is distributed in the hope that it will be useful,
11f08c3bdfSopenharmony_ci# but WITHOUT ANY WARRANTY; without even the implied warranty of
12f08c3bdfSopenharmony_ci# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13f08c3bdfSopenharmony_ci# General Public License for more details.
14f08c3bdfSopenharmony_ci#
15f08c3bdfSopenharmony_ci# You should find a copy of v2 of the GNU General Public License somewhere
16f08c3bdfSopenharmony_ci# on your Linux system; if not, write to the Free Software Foundation,
17f08c3bdfSopenharmony_ci# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18f08c3bdfSopenharmony_ci#
19f08c3bdfSopenharmony_ci# Copyright (C) 2010, Intel Corp.
20f08c3bdfSopenharmony_ci# Author: Jiajia Zheng <jiajia.zheng@intel.com>
21f08c3bdfSopenharmony_ci#
22f08c3bdfSopenharmony_ci
23f08c3bdfSopenharmony_ciimage=""
24f08c3bdfSopenharmony_cimce_inject_file=""
25f08c3bdfSopenharmony_ci
26f08c3bdfSopenharmony_ciHOST_DIR=`pwd`
27f08c3bdfSopenharmony_ciGUEST_DIR="/test"
28f08c3bdfSopenharmony_ciearly_kill="1"
29f08c3bdfSopenharmony_ciRAM_size=""
30f08c3bdfSopenharmony_ci
31f08c3bdfSopenharmony_cikernel=""
32f08c3bdfSopenharmony_ciinitrd=""
33f08c3bdfSopenharmony_ciroot=""
34f08c3bdfSopenharmony_ci
35f08c3bdfSopenharmony_ciusage()
36f08c3bdfSopenharmony_ci{
37f08c3bdfSopenharmony_ci	echo "Usage: ./host_run.sh [-options] [arguments]"
38f08c3bdfSopenharmony_ci	echo "================Below are the must have options==============="
39f08c3bdfSopenharmony_ci	echo -e "\t-i image\t: guest image"
40f08c3bdfSopenharmony_ci	echo -e "\t-f mcefile\t: which mce data file to inject"
41f08c3bdfSopenharmony_ci	echo "================Below are the optional options================"
42f08c3bdfSopenharmony_ci	echo -e "\t-d hostdir\t: where you put the test scripts on host system"
43f08c3bdfSopenharmony_ci	echo -e "\t\t\tBe careful to change it"
44f08c3bdfSopenharmony_ci	echo -e "\t-g guestdir\t: where you put the test scripts on guest system"
45f08c3bdfSopenharmony_ci	echo -e "\t\t\tBy default, guestdir is set to $GUEST_DIR"
46f08c3bdfSopenharmony_ci	echo -e "\t-o offset\t: guest image offset"
47f08c3bdfSopenharmony_ci	echo -e "\t\t\tBy default, offset is calculated by kpartx "
48f08c3bdfSopenharmony_ci        echo -e "\t-l\t\t: late kill, disable early kill in guest system"
49f08c3bdfSopenharmony_ci        echo -e "\t\t\tBy default, earlykill is enabled "
50f08c3bdfSopenharmony_ci        echo -e "\t-m ramsize\t: virtual RAM size of guest system"
51f08c3bdfSopenharmony_ci        echo -e "\t\t\tBy default, qemu-kvm defaults to 512M bytes"
52f08c3bdfSopenharmony_ci        echo -e "\t-h\t\t: show this help"
53f08c3bdfSopenharmony_ci	echo "============If you want to specify the guest kernel==========="
54f08c3bdfSopenharmony_ci	echo "============please set below options all together============="
55f08c3bdfSopenharmony_ci	echo -e "\t-k kernel\t: guest kernel"
56f08c3bdfSopenharmony_ci	echo -e "\t-n initrd\t: guest initrd"
57f08c3bdfSopenharmony_ci	echo -e "\t-r root\t\t: guest root partition"
58f08c3bdfSopenharmony_ci	exit 0
59f08c3bdfSopenharmony_ci}
60f08c3bdfSopenharmony_ci
61f08c3bdfSopenharmony_ciwhile getopts "i:f:d:g:o:b:p:k:n:r:hlm:" option
62f08c3bdfSopenharmony_cido
63f08c3bdfSopenharmony_ci        case $option in
64f08c3bdfSopenharmony_ci		i) image=$OPTARG;;
65f08c3bdfSopenharmony_ci		f) mce_inject_file=$OPTARG;;
66f08c3bdfSopenharmony_ci		d) HOST_DIR=$OPTARG;;
67f08c3bdfSopenharmony_ci		g) GUEST_DIR=$OPTARG;;
68f08c3bdfSopenharmony_ci		o) offset=$OPTARG;;
69f08c3bdfSopenharmony_ci		l) early_kill="0";;
70f08c3bdfSopenharmony_ci		k) kernel=$OPTARG;;
71f08c3bdfSopenharmony_ci		n) initrd=$OPTARG;;
72f08c3bdfSopenharmony_ci		r) root=$OPTARG;;
73f08c3bdfSopenharmony_ci		m) RAM_size=$OPTARG;;
74f08c3bdfSopenharmony_ci		h) usage;;
75f08c3bdfSopenharmony_ci		*) echo 'invalid option!'; usage;;
76f08c3bdfSopenharmony_ci        esac
77f08c3bdfSopenharmony_cidone
78f08c3bdfSopenharmony_ci
79f08c3bdfSopenharmony_ci
80f08c3bdfSopenharmony_ciguest_script=$GUEST_DIR/guest_run.sh
81f08c3bdfSopenharmony_ciguest_tmp=$GUEST_DIR/guest_tmp
82f08c3bdfSopenharmony_ciguest_page=$GUEST_DIR/guest_page
83f08c3bdfSopenharmony_ciGUEST_PHY=""
84f08c3bdfSopenharmony_ci
85f08c3bdfSopenharmony_cihost_key_pub=$HOST_DIR/id_rsa.pub
86f08c3bdfSopenharmony_cihost_key_priv=$HOST_DIR/id_rsa
87f08c3bdfSopenharmony_ciguest_init=$HOST_DIR/guest_init
88f08c3bdfSopenharmony_cihost_start=$HOST_DIR/host_start
89f08c3bdfSopenharmony_cipid_file=$HOST_DIR/pid_file
90f08c3bdfSopenharmony_cimonitor_console_output=$HOST_DIR/monitor_console_output
91f08c3bdfSopenharmony_ciserial_console_output=$HOST_DIR/serial_console_output
92f08c3bdfSopenharmony_cihost_tmp=$HOST_DIR/host_tmp
93f08c3bdfSopenharmony_cimce_inject_data=$HOST_DIR/mce_inject_data
94f08c3bdfSopenharmony_cimonitor_console=""
95f08c3bdfSopenharmony_ciserial_console=""
96f08c3bdfSopenharmony_ci
97f08c3bdfSopenharmony_ci
98f08c3bdfSopenharmony_ciinvalid()
99f08c3bdfSopenharmony_ci{
100f08c3bdfSopenharmony_ci	echo $1
101f08c3bdfSopenharmony_ci	echo "Try ./host_run.sh -h for more information."
102f08c3bdfSopenharmony_ci	exit 0
103f08c3bdfSopenharmony_ci}
104f08c3bdfSopenharmony_ci
105f08c3bdfSopenharmony_cicheck_env()
106f08c3bdfSopenharmony_ci{
107f08c3bdfSopenharmony_ci	if [ "`whoami`" != "root" ]; then
108f08c3bdfSopenharmony_ci		echo "Must run as root"
109f08c3bdfSopenharmony_ci		exit 1
110f08c3bdfSopenharmony_ci	fi
111f08c3bdfSopenharmony_ci
112f08c3bdfSopenharmony_ci	if modinfo mce_inject &> /dev/null; then
113f08c3bdfSopenharmony_ci		if ! lsmod | grep -q mce_inject; then
114f08c3bdfSopenharmony_ci			if ! modprobe mce_inject; then
115f08c3bdfSopenharmony_ci				invalid "module mce_inject isn't supported ?"
116f08c3bdfSopenharmony_ci			fi
117f08c3bdfSopenharmony_ci		fi
118f08c3bdfSopenharmony_ci	fi
119f08c3bdfSopenharmony_ci
120f08c3bdfSopenharmony_ci	which kpartx &>/dev/null
121f08c3bdfSopenharmony_ci	[ ! $? -eq 0 ] && invalid "please install kpartx tool!"
122f08c3bdfSopenharmony_ci	which mce-inject &>/dev/null
123f08c3bdfSopenharmony_ci	[ ! $? -eq 0 ] && invalid "please install mce-inject tool!"
124f08c3bdfSopenharmony_ci
125f08c3bdfSopenharmony_ci	[ -z $RAM_size ] && RAM_size=512
126f08c3bdfSopenharmony_ci	[ -z $image ] && invalid "please input the guest image!"
127f08c3bdfSopenharmony_ci	[ ! -e $image ] && invalid "guest image $image does not exist!"
128f08c3bdfSopenharmony_ci	[ -z $mce_inject_file ] && invalid "please input the mce data file!"
129f08c3bdfSopenharmony_ci	[ ! -e $mce_inject_file ] && invalid "mce data file $mce_inject_file does not exist!"
130f08c3bdfSopenharmony_ci
131f08c3bdfSopenharmony_ci	[ ! -e $host_key_pub ] && invalid "host public key does not exist!"
132f08c3bdfSopenharmony_ci	[ ! -e $host_key_priv ] && invalid "host privite key does not exist!"
133f08c3bdfSopenharmony_ci	chmod 600 $host_key_pub
134f08c3bdfSopenharmony_ci	chmod 600 $host_key_priv
135f08c3bdfSopenharmony_ci}
136f08c3bdfSopenharmony_ci
137f08c3bdfSopenharmony_cimount_image()
138f08c3bdfSopenharmony_ci{
139f08c3bdfSopenharmony_ci	mnt=`mktemp -d`
140f08c3bdfSopenharmony_ci	offset=`kpartx -l $image | awk '/loop deleted/ {next}; \
141f08c3bdfSopenharmony_ci	{offset=$NF*512}; END {print offset}'`
142f08c3bdfSopenharmony_ci	mount_err=`mount -oloop,offset=$offset $image $mnt 2>&1`
143f08c3bdfSopenharmony_ci	if [ $? -eq 0 ]; then
144f08c3bdfSopenharmony_ci	    fs_type=unset
145f08c3bdfSopenharmony_ci	    echo "mount image to $mnt"
146f08c3bdfSopenharmony_ci	    return 0
147f08c3bdfSopenharmony_ci	fi
148f08c3bdfSopenharmony_ci
149f08c3bdfSopenharmony_ci	#See if we're dealing with a LVM filesystem type
150f08c3bdfSopenharmony_ci	fs_type=`echo $mount_err | awk '/^mount: unknown filesystem type/ {print $NF}'`
151f08c3bdfSopenharmony_ci	if [ $fs_type != "'LVM2_member'" ]; then
152f08c3bdfSopenharmony_ci	    echo unknown filesystem type
153f08c3bdfSopenharmony_ci	    rm -rf $mnt
154f08c3bdfSopenharmony_ci	    return 1
155f08c3bdfSopenharmony_ci	fi
156f08c3bdfSopenharmony_ci
157f08c3bdfSopenharmony_ci	which losetup &>/dev/null
158f08c3bdfSopenharmony_ci	[ ! $? -eq 0 ] && invalid "please install losetup tool!"
159f08c3bdfSopenharmony_ci	which pvdisplay &>/dev/null
160f08c3bdfSopenharmony_ci	[ ! $? -eq 0 ] && invalid "please install pvdisplay tool!"
161f08c3bdfSopenharmony_ci	which vgchange &>/dev/null
162f08c3bdfSopenharmony_ci	[ ! $? -eq 0 ] && invalid "please install vgchange tool!"
163f08c3bdfSopenharmony_ci
164f08c3bdfSopenharmony_ci	#Try mounting the LVM image
165f08c3bdfSopenharmony_ci	loop_dev=`losetup -o ${offset} -f --show ${image}`
166f08c3bdfSopenharmony_ci	if [ -z ${loop_dev} ]; then
167f08c3bdfSopenharmony_ci	    echo no available loop device
168f08c3bdfSopenharmony_ci	    rm -rf $mnt
169f08c3bdfSopenharmony_ci	    return 1
170f08c3bdfSopenharmony_ci	fi
171f08c3bdfSopenharmony_ci	vg=`pvdisplay ${loop_dev} | awk '/  VG Name/ {print $NF}'`
172f08c3bdfSopenharmony_ci	lv=lv_root
173f08c3bdfSopenharmony_ci	vgchange -a ey ${vg}
174f08c3bdfSopenharmony_ci	if [ ! -b /dev/mapper/${vg}-${lv} ]; then
175f08c3bdfSopenharmony_ci	    echo '! block special'
176f08c3bdfSopenharmony_ci	    losetup -d ${loop_dev}
177f08c3bdfSopenharmony_ci	    rm -rf $mnt
178f08c3bdfSopenharmony_ci	    return 1
179f08c3bdfSopenharmony_ci	fi
180f08c3bdfSopenharmony_ci	mount /dev/mapper/${vg}-${lv} $mnt
181f08c3bdfSopenharmony_ci	if [ $? -ne 0 ]; then
182f08c3bdfSopenharmony_ci	    vgchange -a en ${vg}
183f08c3bdfSopenharmony_ci	    losetup -d ${loop_dev}
184f08c3bdfSopenharmony_ci	    rm -rf $mnt
185f08c3bdfSopenharmony_ci	    return 1
186f08c3bdfSopenharmony_ci	fi
187f08c3bdfSopenharmony_ci	echo "mount LVM image to $mnt"
188f08c3bdfSopenharmony_ci	return 0
189f08c3bdfSopenharmony_ci}
190f08c3bdfSopenharmony_ci
191f08c3bdfSopenharmony_ciumount_image()
192f08c3bdfSopenharmony_ci{
193f08c3bdfSopenharmony_ci	umount $mnt
194f08c3bdfSopenharmony_ci	sleep 2
195f08c3bdfSopenharmony_ci	if [ $fs_type = "'LVM2_member'" ]; then
196f08c3bdfSopenharmony_ci	    vgchange -a en ${vg}
197f08c3bdfSopenharmony_ci	    losetup -d ${loop_dev}
198f08c3bdfSopenharmony_ci	fi
199f08c3bdfSopenharmony_ci	rm -rf $mnt
200f08c3bdfSopenharmony_ci}
201f08c3bdfSopenharmony_ci
202f08c3bdfSopenharmony_ci#Guest Image Preparation
203f08c3bdfSopenharmony_ciimage_prepare()
204f08c3bdfSopenharmony_ci{
205f08c3bdfSopenharmony_ci	local i
206f08c3bdfSopenharmony_ci
207f08c3bdfSopenharmony_ci	mount_image
208f08c3bdfSopenharmony_ci	if [ $? -ne 0 ]; then
209f08c3bdfSopenharmony_ci	    echo 'mount of image failed!'
210f08c3bdfSopenharmony_ci	    return 1
211f08c3bdfSopenharmony_ci	fi
212f08c3bdfSopenharmony_ci	i=`grep id:.*:initdefault $mnt/etc/inittab |cut -d':' -f2`
213f08c3bdfSopenharmony_ci	rm -f $mnt/etc/rc${i}.d/S99kvm_ras
214f08c3bdfSopenharmony_ci	rm -f $mnt/$guest_tmp $mnt/$guest_page
215f08c3bdfSopenharmony_ci
216f08c3bdfSopenharmony_ci	if [ ! -d $mnt/root/.ssh ]; then
217f08c3bdfSopenharmony_ci	    mkdir $mnt/root/.ssh
218f08c3bdfSopenharmony_ci	    chmod 700 $mnt/root/.ssh
219f08c3bdfSopenharmony_ci	fi
220f08c3bdfSopenharmony_ci	mkdir -p $mnt/$GUEST_DIR
221f08c3bdfSopenharmony_ci	cp ../guest/guest_run.sh $mnt/$GUEST_DIR
222f08c3bdfSopenharmony_ci	gcc -o simple_process ../../tools/simple_process/simple_process.c
223f08c3bdfSopenharmony_ci	gcc -o page-types ../../tools/page-types.c
224f08c3bdfSopenharmony_ci	cp simple_process $mnt/$GUEST_DIR
225f08c3bdfSopenharmony_ci	cp page-types $mnt/$GUEST_DIR
226f08c3bdfSopenharmony_ci	sed -i -e "s#GUEST_DIR#$GUEST_DIR#g" $mnt/$guest_script
227f08c3bdfSopenharmony_ci	cat $host_key_pub >> $mnt/root/.ssh/authorized_keys
228f08c3bdfSopenharmony_ci        kvm_ras=/etc/init.d/kvm_ras
229f08c3bdfSopenharmony_ci	sed -e "s#EARLYKILL#$early_kill#g" \
230f08c3bdfSopenharmony_ci	-e "s#GUESTRUN#$guest_script#g" $guest_init > $mnt/$kvm_ras
231f08c3bdfSopenharmony_ci	chmod a+x $mnt/$kvm_ras
232f08c3bdfSopenharmony_ci	ln -s $kvm_ras $mnt/etc/rc${i}.d/S99kvm_ras
233f08c3bdfSopenharmony_ci	sleep 2
234f08c3bdfSopenharmony_ci	umount_image
235f08c3bdfSopenharmony_ci	return 0
236f08c3bdfSopenharmony_ci}
237f08c3bdfSopenharmony_ci
238f08c3bdfSopenharmony_ci#Start guest system
239f08c3bdfSopenharmony_cistart_guest()
240f08c3bdfSopenharmony_ci{
241f08c3bdfSopenharmony_ci	if [ ! -z $kernel ]; then
242f08c3bdfSopenharmony_ci	    if [ ! -z $initrd ]; then
243f08c3bdfSopenharmony_ci		if [ ! -z $root ]; then
244f08c3bdfSopenharmony_ci		    append="root=$root ro loglevel=8 mce=3 console=ttyS0,115200n8 console=tty0"
245f08c3bdfSopenharmony_ci	            qemu-system-x86_64 -hda $image -kernel $kernel -initrd $initrd --append "$append" \
246f08c3bdfSopenharmony_ci		    -m $RAM_size -net nic,model=rtl8139 -net user,hostfwd=tcp::5555-:22 \
247f08c3bdfSopenharmony_ci		    -monitor pty -serial pty -pidfile $pid_file > $host_start 2>&1 &
248f08c3bdfSopenharmony_ci		    sleep 5
249f08c3bdfSopenharmony_ci		else
250f08c3bdfSopenharmony_ci		    invalid "please specify the guest root partition!"
251f08c3bdfSopenharmony_ci		fi
252f08c3bdfSopenharmony_ci	    else
253f08c3bdfSopenharmony_ci		invalid "please specify the guest initrd!"
254f08c3bdfSopenharmony_ci	    fi
255f08c3bdfSopenharmony_ci	else
256f08c3bdfSopenharmony_ci	    echo "Start the default kernel on guest system"
257f08c3bdfSopenharmony_ci	    qemu-system-x86_64 -hda $image \
258f08c3bdfSopenharmony_ci	    -m $RAM_size -net nic,model=rtl8139 -net user,hostfwd=tcp::5555-:22 \
259f08c3bdfSopenharmony_ci	    -monitor pty -serial pty -pidfile $pid_file > $host_start 2>&1 &
260f08c3bdfSopenharmony_ci	    sleep 5
261f08c3bdfSopenharmony_ci	fi
262f08c3bdfSopenharmony_ci	monitor_console=`awk '{print $NF}' $host_start | sed -n -e '1p'`
263f08c3bdfSopenharmony_ci	serial_console=`awk '{print $NF}' $host_start | sed -n -e '2p'`
264f08c3bdfSopenharmony_ci	QEMU_PID=`cat $pid_file`
265f08c3bdfSopenharmony_ci	echo "monitor console is $monitor_console"
266f08c3bdfSopenharmony_ci	echo "serial console is $serial_console"
267f08c3bdfSopenharmony_ci	echo "Waiting for guest system start up..."
268f08c3bdfSopenharmony_ci}
269f08c3bdfSopenharmony_ci
270f08c3bdfSopenharmony_cicheck_guest_alive()
271f08c3bdfSopenharmony_ci{
272f08c3bdfSopenharmony_ci	for i in 1 2 3 4 5 6 7 8 9
273f08c3bdfSopenharmony_ci	do
274f08c3bdfSopenharmony_ci	    sleep 10
275f08c3bdfSopenharmony_ci            ssh -i $host_key_priv -o StrictHostKeyChecking=no localhost -p 5555 echo "" > /dev/null 2>&1
276f08c3bdfSopenharmony_ci	    if [ $? -eq 0 ]; then
277f08c3bdfSopenharmony_ci		return 0
278f08c3bdfSopenharmony_ci	    else
279f08c3bdfSopenharmony_ci		echo "Waiting..."
280f08c3bdfSopenharmony_ci	    fi
281f08c3bdfSopenharmony_ci	done
282f08c3bdfSopenharmony_ci	return 1
283f08c3bdfSopenharmony_ci}
284f08c3bdfSopenharmony_ci
285f08c3bdfSopenharmony_ciaddr_translate()
286f08c3bdfSopenharmony_ci{
287f08c3bdfSopenharmony_ci	#Get Guest physical address
288f08c3bdfSopenharmony_ci        scp -o StrictHostKeyChecking=no -i $host_key_priv -P 5555 \
289f08c3bdfSopenharmony_ci	localhost:$guest_tmp $HOST_DIR/guest_tmp > /dev/null 2>&1
290f08c3bdfSopenharmony_ci	if [ $? -ne 0 ]; then
291f08c3bdfSopenharmony_ci		echo "Failed to get Guest physical address, quit testing!"
292f08c3bdfSopenharmony_ci		kill -9 $QEMU_PID
293f08c3bdfSopenharmony_ci		exit 0
294f08c3bdfSopenharmony_ci	fi
295f08c3bdfSopenharmony_ci	sleep 2
296f08c3bdfSopenharmony_ci	GUEST_PHY=`awk '{print $NF}' $HOST_DIR/guest_tmp`
297f08c3bdfSopenharmony_ci	echo "Guest physical address is $GUEST_PHY"
298f08c3bdfSopenharmony_ci	sleep 2
299f08c3bdfSopenharmony_ci
300f08c3bdfSopenharmony_ci	#Get Host virtual address
301f08c3bdfSopenharmony_ci	echo x-gpa2hva $GUEST_PHY > $monitor_console
302f08c3bdfSopenharmony_ci	cat $monitor_console > $monitor_console_output &
303f08c3bdfSopenharmony_ci	sleep 5
304f08c3bdfSopenharmony_ci	HOST_VIRT=`awk '/qemu|QEMU/{next} {print $NF}' $monitor_console_output |cut -b 3-11`
305f08c3bdfSopenharmony_ci	echo "Host virtual address is $HOST_VIRT"
306f08c3bdfSopenharmony_ci
307f08c3bdfSopenharmony_ci	#Get Host physical address
308f08c3bdfSopenharmony_ci	./page-types -p $QEMU_PID -LN -b anon | grep $HOST_VIRT > $host_tmp
309f08c3bdfSopenharmony_ci	sleep 5
310f08c3bdfSopenharmony_ci	ADDR=`cat $host_tmp | awk '{print "0x"$2"000"}' `
311f08c3bdfSopenharmony_ci	echo "Host physical address is $ADDR"
312f08c3bdfSopenharmony_ci}
313f08c3bdfSopenharmony_ci
314f08c3bdfSopenharmony_cierror_inj()
315f08c3bdfSopenharmony_ci{
316f08c3bdfSopenharmony_ci	#Inject SRAO error
317f08c3bdfSopenharmony_ci	cat $mce_inject_file > $mce_inject_data
318f08c3bdfSopenharmony_ci	echo "ADDR $ADDR" >> $mce_inject_data
319f08c3bdfSopenharmony_ci	echo "calling mce-inject $mce_inject_data"
320f08c3bdfSopenharmony_ci	mce-inject $mce_inject_data
321f08c3bdfSopenharmony_ci}
322f08c3bdfSopenharmony_ci
323f08c3bdfSopenharmony_ci
324f08c3bdfSopenharmony_ciget_guest_klog()
325f08c3bdfSopenharmony_ci{
326f08c3bdfSopenharmony_ci        cat $serial_console > $serial_console_output &
327f08c3bdfSopenharmony_ci}
328f08c3bdfSopenharmony_ci
329f08c3bdfSopenharmony_cicheck_guest_klog()
330f08c3bdfSopenharmony_ci{
331f08c3bdfSopenharmony_ci	GUEST_PHY_KLOG=`echo $GUEST_PHY | sed 's/000$//'`
332f08c3bdfSopenharmony_ci	echo "Guest physical klog address is $GUEST_PHY_KLOG"
333f08c3bdfSopenharmony_ci	cat $serial_console_output | grep "MCE $GUEST_PHY_KLOG"
334f08c3bdfSopenharmony_ci	if [ $? -ne 0 ]; then
335f08c3bdfSopenharmony_ci		return 1
336f08c3bdfSopenharmony_ci	fi
337f08c3bdfSopenharmony_ci	return 0
338f08c3bdfSopenharmony_ci}
339f08c3bdfSopenharmony_ci
340f08c3bdfSopenharmony_ci
341f08c3bdfSopenharmony_ci
342f08c3bdfSopenharmony_cicheck_env
343f08c3bdfSopenharmony_ciimage_prepare
344f08c3bdfSopenharmony_ciif [ $? -ne 0 ]; then
345f08c3bdfSopenharmony_ci    echo 'Mount Guest image failed, quit testing!'
346f08c3bdfSopenharmony_cielse
347f08c3bdfSopenharmony_ci    start_guest
348f08c3bdfSopenharmony_ci    get_guest_klog
349f08c3bdfSopenharmony_ci    check_guest_alive
350f08c3bdfSopenharmony_ci    if [ $? -ne 0 ]; then
351f08c3bdfSopenharmony_ci        echo 'Start Guest system failed, quit testing!'
352f08c3bdfSopenharmony_ci    else
353f08c3bdfSopenharmony_ci	sleep 5
354f08c3bdfSopenharmony_ci        addr_translate
355f08c3bdfSopenharmony_ci        error_inj
356f08c3bdfSopenharmony_ci	sleep 5
357f08c3bdfSopenharmony_ci	check_guest_klog
358f08c3bdfSopenharmony_ci	if [ $? -ne 0 ]; then
359f08c3bdfSopenharmony_ci            echo 'FAIL: Did not get expected log!'
360f08c3bdfSopenharmony_ci            kill -9 $QEMU_PID
361f08c3bdfSopenharmony_ci	    exit 1
362f08c3bdfSopenharmony_ci	else
363f08c3bdfSopenharmony_ci	    echo 'PASS: Inject error into guest!'
364f08c3bdfSopenharmony_ci	fi
365f08c3bdfSopenharmony_ci	sleep 10
366f08c3bdfSopenharmony_ci	check_guest_alive
367f08c3bdfSopenharmony_ci	if [ $? -ne 0 ]; then
368f08c3bdfSopenharmony_ci            echo 'FAIL: Guest System could have died!'
369f08c3bdfSopenharmony_ci	else
370f08c3bdfSopenharmony_ci	    echo 'PASS: Guest System alive!'
371f08c3bdfSopenharmony_ci	fi
372f08c3bdfSopenharmony_ci    fi
373f08c3bdfSopenharmony_cifi
374f08c3bdfSopenharmony_ci
375f08c3bdfSopenharmony_cirm -f guest_tmp $host_start $monitor_console_output $serail_console_output $host_tmp $pid_file $mce_inject_data
376f08c3bdfSopenharmony_cirm -f ./simple_process ./page-types
377